Lines Matching refs:stmpe

26 static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)  in __stmpe_enable()  argument
28 return stmpe->variant->enable(stmpe, blocks, true); in __stmpe_enable()
31 static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks) in __stmpe_disable() argument
33 return stmpe->variant->enable(stmpe, blocks, false); in __stmpe_disable()
36 static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg) in __stmpe_reg_read() argument
40 ret = stmpe->ci->read_byte(stmpe, reg); in __stmpe_reg_read()
42 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret); in __stmpe_reg_read()
44 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret); in __stmpe_reg_read()
49 static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val) in __stmpe_reg_write() argument
53 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val); in __stmpe_reg_write()
55 ret = stmpe->ci->write_byte(stmpe, reg, val); in __stmpe_reg_write()
57 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret); in __stmpe_reg_write()
62 static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val) in __stmpe_set_bits() argument
66 ret = __stmpe_reg_read(stmpe, reg); in __stmpe_set_bits()
73 return __stmpe_reg_write(stmpe, reg, ret); in __stmpe_set_bits()
76 static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, in __stmpe_block_read() argument
81 ret = stmpe->ci->read_block(stmpe, reg, length, values); in __stmpe_block_read()
83 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret); in __stmpe_block_read()
85 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret); in __stmpe_block_read()
91 static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, in __stmpe_block_write() argument
96 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length); in __stmpe_block_write()
99 ret = stmpe->ci->write_block(stmpe, reg, length, values); in __stmpe_block_write()
101 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret); in __stmpe_block_write()
111 int stmpe_enable(struct stmpe *stmpe, unsigned int blocks) in stmpe_enable() argument
115 mutex_lock(&stmpe->lock); in stmpe_enable()
116 ret = __stmpe_enable(stmpe, blocks); in stmpe_enable()
117 mutex_unlock(&stmpe->lock); in stmpe_enable()
128 int stmpe_disable(struct stmpe *stmpe, unsigned int blocks) in stmpe_disable() argument
132 mutex_lock(&stmpe->lock); in stmpe_disable()
133 ret = __stmpe_disable(stmpe, blocks); in stmpe_disable()
134 mutex_unlock(&stmpe->lock); in stmpe_disable()
145 int stmpe_reg_read(struct stmpe *stmpe, u8 reg) in stmpe_reg_read() argument
149 mutex_lock(&stmpe->lock); in stmpe_reg_read()
150 ret = __stmpe_reg_read(stmpe, reg); in stmpe_reg_read()
151 mutex_unlock(&stmpe->lock); in stmpe_reg_read()
163 int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val) in stmpe_reg_write() argument
167 mutex_lock(&stmpe->lock); in stmpe_reg_write()
168 ret = __stmpe_reg_write(stmpe, reg, val); in stmpe_reg_write()
169 mutex_unlock(&stmpe->lock); in stmpe_reg_write()
182 int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val) in stmpe_set_bits() argument
186 mutex_lock(&stmpe->lock); in stmpe_set_bits()
187 ret = __stmpe_set_bits(stmpe, reg, mask, val); in stmpe_set_bits()
188 mutex_unlock(&stmpe->lock); in stmpe_set_bits()
201 int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values) in stmpe_block_read() argument
205 mutex_lock(&stmpe->lock); in stmpe_block_read()
206 ret = __stmpe_block_read(stmpe, reg, length, values); in stmpe_block_read()
207 mutex_unlock(&stmpe->lock); in stmpe_block_read()
220 int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, in stmpe_block_write() argument
225 mutex_lock(&stmpe->lock); in stmpe_block_write()
226 ret = __stmpe_block_write(stmpe, reg, length, values); in stmpe_block_write()
227 mutex_unlock(&stmpe->lock); in stmpe_block_write()
245 int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block) in stmpe_set_altfunc() argument
247 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_set_altfunc()
248 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB]; in stmpe_set_altfunc()
250 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8); in stmpe_set_altfunc()
259 mutex_lock(&stmpe->lock); in stmpe_set_altfunc()
261 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO); in stmpe_set_altfunc()
265 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs); in stmpe_set_altfunc()
269 af = variant->get_altfunc(stmpe, block); in stmpe_set_altfunc()
282 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs); in stmpe_set_altfunc()
285 mutex_unlock(&stmpe->lock); in stmpe_set_altfunc()
366 static int stmpe801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe801_enable() argument
454 static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe811_enable() argument
468 return __stmpe_set_bits(stmpe, STMPE811_REG_SYS_CTRL2, mask, in stmpe811_enable()
472 static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe811_get_altfunc() argument
563 static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout) in stmpe_autosleep() argument
567 if (!stmpe->variant->enable_autosleep) in stmpe_autosleep()
570 mutex_lock(&stmpe->lock); in stmpe_autosleep()
571 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout); in stmpe_autosleep()
572 mutex_unlock(&stmpe->lock); in stmpe_autosleep()
580 static int stmpe1601_autosleep(struct stmpe *stmpe, in stmpe1601_autosleep() argument
588 dev_err(stmpe->dev, "invalid timeout\n"); in stmpe1601_autosleep()
592 ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2, in stmpe1601_autosleep()
598 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2, in stmpe1601_autosleep()
603 static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1601_enable() argument
623 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask, in stmpe1601_enable()
627 static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe1601_get_altfunc() argument
689 static int stmpe1801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1801_enable() argument
699 return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask, in stmpe1801_enable()
703 static int stmpe1801_reset(struct stmpe *stmpe) in stmpe1801_reset() argument
708 ret = __stmpe_set_bits(stmpe, STMPE1801_REG_SYS_CTRL, in stmpe1801_reset()
715 ret = __stmpe_reg_read(stmpe, STMPE1801_REG_SYS_CTRL); in stmpe1801_reset()
776 static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe24xx_enable() argument
787 return __stmpe_set_bits(stmpe, STMPE24XX_REG_SYS_CTRL, mask, in stmpe24xx_enable()
791 static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe24xx_get_altfunc() argument
858 struct stmpe *stmpe = data; in stmpe_irq() local
859 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
867 int base = irq_create_mapping(stmpe->domain, 0); in stmpe_irq()
874 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; in stmpe_irq()
876 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; in stmpe_irq()
878 ret = stmpe_block_read(stmpe, israddr, num, isr); in stmpe_irq()
887 status &= stmpe->ier[bank]; in stmpe_irq()
895 int nestedirq = irq_create_mapping(stmpe->domain, line); in stmpe_irq()
901 stmpe_reg_write(stmpe, israddr + i, clear); in stmpe_irq()
909 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_lock() local
911 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
916 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_sync_unlock() local
917 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
922 u8 new = stmpe->ier[i]; in stmpe_irq_sync_unlock()
923 u8 old = stmpe->oldier[i]; in stmpe_irq_sync_unlock()
928 stmpe->oldier[i] = new; in stmpe_irq_sync_unlock()
929 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new); in stmpe_irq_sync_unlock()
932 mutex_unlock(&stmpe->irq_lock); in stmpe_irq_sync_unlock()
937 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_mask() local
942 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
947 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_unmask() local
952 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
966 struct stmpe *stmpe = d->host_data; in stmpe_irq_map() local
969 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
972 irq_set_chip_data(virq, stmpe); in stmpe_irq_map()
992 static int stmpe_irq_init(struct stmpe *stmpe, struct device_node *np) in stmpe_irq_init() argument
995 int num_irqs = stmpe->variant->num_irqs; in stmpe_irq_init()
997 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, in stmpe_irq_init()
998 &stmpe_irq_ops, stmpe); in stmpe_irq_init()
999 if (!stmpe->domain) { in stmpe_irq_init()
1000 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1007 static int stmpe_chip_init(struct stmpe *stmpe) in stmpe_chip_init() argument
1009 unsigned int irq_trigger = stmpe->pdata->irq_trigger; in stmpe_chip_init()
1010 int autosleep_timeout = stmpe->pdata->autosleep_timeout; in stmpe_chip_init()
1011 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_chip_init()
1017 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], in stmpe_chip_init()
1024 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1028 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1031 ret = stmpe_disable(stmpe, ~0); in stmpe_chip_init()
1036 ret = stmpe1801_reset(stmpe); in stmpe_chip_init()
1041 if (stmpe->irq >= 0) { in stmpe_chip_init()
1063 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1064 ret = stmpe_autosleep(stmpe, autosleep_timeout); in stmpe_chip_init()
1069 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
1072 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) in stmpe_add_device() argument
1074 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, in stmpe_add_device()
1075 NULL, 0, stmpe->domain); in stmpe_add_device()
1078 static int stmpe_devices_init(struct stmpe *stmpe) in stmpe_devices_init() argument
1080 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1081 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1101 ret = stmpe_add_device(stmpe, block->cell); in stmpe_devices_init()
1107 dev_warn(stmpe->dev, in stmpe_devices_init()
1157 struct stmpe *stmpe; in stmpe_probe() local
1174 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1175 if (!stmpe) in stmpe_probe()
1178 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1179 mutex_init(&stmpe->lock); in stmpe_probe()
1181 stmpe->dev = ci->dev; in stmpe_probe()
1182 stmpe->client = ci->client; in stmpe_probe()
1183 stmpe->pdata = pdata; in stmpe_probe()
1184 stmpe->ci = ci; in stmpe_probe()
1185 stmpe->partnum = partnum; in stmpe_probe()
1186 stmpe->variant = stmpe_variant_info[partnum]; in stmpe_probe()
1187 stmpe->regs = stmpe->variant->regs; in stmpe_probe()
1188 stmpe->num_gpios = stmpe->variant->num_gpios; in stmpe_probe()
1189 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); in stmpe_probe()
1190 if (!IS_ERR(stmpe->vcc)) { in stmpe_probe()
1191 ret = regulator_enable(stmpe->vcc); in stmpe_probe()
1195 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); in stmpe_probe()
1196 if (!IS_ERR(stmpe->vio)) { in stmpe_probe()
1197 ret = regulator_enable(stmpe->vio); in stmpe_probe()
1201 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1204 ci->init(stmpe); in stmpe_probe()
1210 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", in stmpe_probe()
1215 stmpe->irq = gpio_to_irq(pdata->irq_gpio); in stmpe_probe()
1217 stmpe->irq = ci->irq; in stmpe_probe()
1220 if (stmpe->irq < 0) { in stmpe_probe()
1222 dev_info(stmpe->dev, in stmpe_probe()
1224 stmpe->variant->name); in stmpe_probe()
1225 if (!stmpe_noirq_variant_info[stmpe->partnum]) { in stmpe_probe()
1226 dev_err(stmpe->dev, in stmpe_probe()
1228 stmpe->variant->name); in stmpe_probe()
1231 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1233 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1236 ret = stmpe_chip_init(stmpe); in stmpe_probe()
1240 if (stmpe->irq >= 0) { in stmpe_probe()
1241 ret = stmpe_irq_init(stmpe, np); in stmpe_probe()
1245 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1247 "stmpe", stmpe); in stmpe_probe()
1249 dev_err(stmpe->dev, "failed to request IRQ: %d\n", in stmpe_probe()
1255 ret = stmpe_devices_init(stmpe); in stmpe_probe()
1259 dev_err(stmpe->dev, "failed to add children\n"); in stmpe_probe()
1260 mfd_remove_devices(stmpe->dev); in stmpe_probe()
1265 int stmpe_remove(struct stmpe *stmpe) in stmpe_remove() argument
1267 if (!IS_ERR(stmpe->vio)) in stmpe_remove()
1268 regulator_disable(stmpe->vio); in stmpe_remove()
1269 if (!IS_ERR(stmpe->vcc)) in stmpe_remove()
1270 regulator_disable(stmpe->vcc); in stmpe_remove()
1272 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1280 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_suspend() local
1282 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1283 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1290 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_resume() local
1292 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1293 disable_irq_wake(stmpe->irq); in stmpe_resume()