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
857 struct stmpe *stmpe = data; in stmpe_irq() local
858 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
866 int base = irq_create_mapping(stmpe->domain, 0); in stmpe_irq()
873 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; in stmpe_irq()
875 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; in stmpe_irq()
877 ret = stmpe_block_read(stmpe, israddr, num, isr); in stmpe_irq()
886 status &= stmpe->ier[bank]; in stmpe_irq()
894 int nestedirq = irq_create_mapping(stmpe->domain, line); in stmpe_irq()
900 stmpe_reg_write(stmpe, israddr + i, clear); in stmpe_irq()
908 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_lock() local
910 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
915 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_sync_unlock() local
916 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
921 u8 new = stmpe->ier[i]; in stmpe_irq_sync_unlock()
922 u8 old = stmpe->oldier[i]; in stmpe_irq_sync_unlock()
927 stmpe->oldier[i] = new; in stmpe_irq_sync_unlock()
928 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new); in stmpe_irq_sync_unlock()
931 mutex_unlock(&stmpe->irq_lock); in stmpe_irq_sync_unlock()
936 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_mask() local
941 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
946 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_unmask() local
951 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
965 struct stmpe *stmpe = d->host_data; in stmpe_irq_map() local
968 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
971 irq_set_chip_data(virq, stmpe); in stmpe_irq_map()
998 static int stmpe_irq_init(struct stmpe *stmpe, struct device_node *np) in stmpe_irq_init() argument
1001 int num_irqs = stmpe->variant->num_irqs; in stmpe_irq_init()
1003 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, in stmpe_irq_init()
1004 &stmpe_irq_ops, stmpe); in stmpe_irq_init()
1005 if (!stmpe->domain) { in stmpe_irq_init()
1006 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1013 static int stmpe_chip_init(struct stmpe *stmpe) in stmpe_chip_init() argument
1015 unsigned int irq_trigger = stmpe->pdata->irq_trigger; in stmpe_chip_init()
1016 int autosleep_timeout = stmpe->pdata->autosleep_timeout; in stmpe_chip_init()
1017 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_chip_init()
1023 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], in stmpe_chip_init()
1030 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1034 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1037 ret = stmpe_disable(stmpe, ~0); in stmpe_chip_init()
1042 ret = stmpe1801_reset(stmpe); in stmpe_chip_init()
1047 if (stmpe->irq >= 0) { in stmpe_chip_init()
1069 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1070 ret = stmpe_autosleep(stmpe, autosleep_timeout); in stmpe_chip_init()
1075 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
1078 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) in stmpe_add_device() argument
1080 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, in stmpe_add_device()
1081 NULL, 0, stmpe->domain); in stmpe_add_device()
1084 static int stmpe_devices_init(struct stmpe *stmpe) in stmpe_devices_init() argument
1086 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1087 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1107 ret = stmpe_add_device(stmpe, block->cell); in stmpe_devices_init()
1113 dev_warn(stmpe->dev, in stmpe_devices_init()
1163 struct stmpe *stmpe; in stmpe_probe() local
1180 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1181 if (!stmpe) in stmpe_probe()
1184 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1185 mutex_init(&stmpe->lock); in stmpe_probe()
1187 stmpe->dev = ci->dev; in stmpe_probe()
1188 stmpe->client = ci->client; in stmpe_probe()
1189 stmpe->pdata = pdata; in stmpe_probe()
1190 stmpe->ci = ci; in stmpe_probe()
1191 stmpe->partnum = partnum; in stmpe_probe()
1192 stmpe->variant = stmpe_variant_info[partnum]; in stmpe_probe()
1193 stmpe->regs = stmpe->variant->regs; in stmpe_probe()
1194 stmpe->num_gpios = stmpe->variant->num_gpios; in stmpe_probe()
1195 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); in stmpe_probe()
1196 if (!IS_ERR(stmpe->vcc)) { in stmpe_probe()
1197 ret = regulator_enable(stmpe->vcc); in stmpe_probe()
1201 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); in stmpe_probe()
1202 if (!IS_ERR(stmpe->vio)) { in stmpe_probe()
1203 ret = regulator_enable(stmpe->vio); in stmpe_probe()
1207 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1210 ci->init(stmpe); in stmpe_probe()
1216 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", in stmpe_probe()
1221 stmpe->irq = gpio_to_irq(pdata->irq_gpio); in stmpe_probe()
1223 stmpe->irq = ci->irq; in stmpe_probe()
1226 if (stmpe->irq < 0) { in stmpe_probe()
1228 dev_info(stmpe->dev, in stmpe_probe()
1230 stmpe->variant->name); in stmpe_probe()
1231 if (!stmpe_noirq_variant_info[stmpe->partnum]) { in stmpe_probe()
1232 dev_err(stmpe->dev, in stmpe_probe()
1234 stmpe->variant->name); in stmpe_probe()
1237 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1239 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1242 ret = stmpe_chip_init(stmpe); in stmpe_probe()
1246 if (stmpe->irq >= 0) { in stmpe_probe()
1247 ret = stmpe_irq_init(stmpe, np); in stmpe_probe()
1251 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1253 "stmpe", stmpe); in stmpe_probe()
1255 dev_err(stmpe->dev, "failed to request IRQ: %d\n", in stmpe_probe()
1261 ret = stmpe_devices_init(stmpe); in stmpe_probe()
1265 dev_err(stmpe->dev, "failed to add children\n"); in stmpe_probe()
1266 mfd_remove_devices(stmpe->dev); in stmpe_probe()
1271 int stmpe_remove(struct stmpe *stmpe) in stmpe_remove() argument
1273 if (!IS_ERR(stmpe->vio)) in stmpe_remove()
1274 regulator_disable(stmpe->vio); in stmpe_remove()
1275 if (!IS_ERR(stmpe->vcc)) in stmpe_remove()
1276 regulator_disable(stmpe->vcc); in stmpe_remove()
1278 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1286 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_suspend() local
1288 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1289 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1296 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_resume() local
1298 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1299 disable_irq_wake(stmpe->irq); in stmpe_resume()