• Home
  • Raw
  • Download

Lines Matching full:stmpe

2  * ST Microelectronics MFD: stmpe's driver
24 #include "stmpe.h"
27 * struct stmpe_platform_data - STMPE platform data
31 * @autosleep: bool to enable/disable stmpe autosleep
47 static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks) in __stmpe_enable() argument
49 return stmpe->variant->enable(stmpe, blocks, true); in __stmpe_enable()
52 static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks) in __stmpe_disable() argument
54 return stmpe->variant->enable(stmpe, blocks, false); in __stmpe_disable()
57 static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg) in __stmpe_reg_read() argument
61 ret = stmpe->ci->read_byte(stmpe, reg); in __stmpe_reg_read()
63 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret); in __stmpe_reg_read()
65 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret); in __stmpe_reg_read()
70 static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val) in __stmpe_reg_write() argument
74 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val); in __stmpe_reg_write()
76 ret = stmpe->ci->write_byte(stmpe, reg, val); in __stmpe_reg_write()
78 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret); in __stmpe_reg_write()
83 static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val) in __stmpe_set_bits() argument
87 ret = __stmpe_reg_read(stmpe, reg); in __stmpe_set_bits()
94 return __stmpe_reg_write(stmpe, reg, ret); in __stmpe_set_bits()
97 static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, in __stmpe_block_read() argument
102 ret = stmpe->ci->read_block(stmpe, reg, length, values); in __stmpe_block_read()
104 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret); in __stmpe_block_read()
106 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret); in __stmpe_block_read()
107 stmpe_dump_bytes("stmpe rd: ", values, length); in __stmpe_block_read()
112 static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, in __stmpe_block_write() argument
117 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length); in __stmpe_block_write()
118 stmpe_dump_bytes("stmpe wr: ", values, length); in __stmpe_block_write()
120 ret = stmpe->ci->write_block(stmpe, reg, length, values); in __stmpe_block_write()
122 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret); in __stmpe_block_write()
128 * stmpe_enable - enable blocks on an STMPE device
129 * @stmpe: Device to work on
132 int stmpe_enable(struct stmpe *stmpe, unsigned int blocks) in stmpe_enable() argument
136 mutex_lock(&stmpe->lock); in stmpe_enable()
137 ret = __stmpe_enable(stmpe, blocks); in stmpe_enable()
138 mutex_unlock(&stmpe->lock); in stmpe_enable()
145 * stmpe_disable - disable blocks on an STMPE device
146 * @stmpe: Device to work on
149 int stmpe_disable(struct stmpe *stmpe, unsigned int blocks) in stmpe_disable() argument
153 mutex_lock(&stmpe->lock); in stmpe_disable()
154 ret = __stmpe_disable(stmpe, blocks); in stmpe_disable()
155 mutex_unlock(&stmpe->lock); in stmpe_disable()
162 * stmpe_reg_read() - read a single STMPE register
163 * @stmpe: Device to read from
166 int stmpe_reg_read(struct stmpe *stmpe, u8 reg) in stmpe_reg_read() argument
170 mutex_lock(&stmpe->lock); in stmpe_reg_read()
171 ret = __stmpe_reg_read(stmpe, reg); in stmpe_reg_read()
172 mutex_unlock(&stmpe->lock); in stmpe_reg_read()
179 * stmpe_reg_write() - write a single STMPE register
180 * @stmpe: Device to write to
184 int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val) in stmpe_reg_write() argument
188 mutex_lock(&stmpe->lock); in stmpe_reg_write()
189 ret = __stmpe_reg_write(stmpe, reg, val); in stmpe_reg_write()
190 mutex_unlock(&stmpe->lock); in stmpe_reg_write()
197 * stmpe_set_bits() - set the value of a bitfield in a STMPE register
198 * @stmpe: Device to write to
203 int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val) in stmpe_set_bits() argument
207 mutex_lock(&stmpe->lock); in stmpe_set_bits()
208 ret = __stmpe_set_bits(stmpe, reg, mask, val); in stmpe_set_bits()
209 mutex_unlock(&stmpe->lock); in stmpe_set_bits()
216 * stmpe_block_read() - read multiple STMPE registers
217 * @stmpe: Device to read from
222 int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values) in stmpe_block_read() argument
226 mutex_lock(&stmpe->lock); in stmpe_block_read()
227 ret = __stmpe_block_read(stmpe, reg, length, values); in stmpe_block_read()
228 mutex_unlock(&stmpe->lock); in stmpe_block_read()
235 * stmpe_block_write() - write multiple STMPE registers
236 * @stmpe: Device to write to
241 int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, in stmpe_block_write() argument
246 mutex_lock(&stmpe->lock); in stmpe_block_write()
247 ret = __stmpe_block_write(stmpe, reg, length, values); in stmpe_block_write()
248 mutex_unlock(&stmpe->lock); in stmpe_block_write()
255 * stmpe_set_altfunc()- set the alternate function for STMPE pins
256 * @stmpe: Device to configure
266 int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block) in stmpe_set_altfunc() argument
268 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_set_altfunc()
269 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB]; in stmpe_set_altfunc()
271 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8); in stmpe_set_altfunc()
280 mutex_lock(&stmpe->lock); in stmpe_set_altfunc()
282 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO); in stmpe_set_altfunc()
286 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs); in stmpe_set_altfunc()
290 af = variant->get_altfunc(stmpe, block); in stmpe_set_altfunc()
303 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs); in stmpe_set_altfunc()
306 mutex_unlock(&stmpe->lock); in stmpe_set_altfunc()
323 .name = "stmpe-gpio",
324 .of_compatible = "st,stmpe-gpio",
330 .name = "stmpe-gpio",
331 .of_compatible = "st,stmpe-gpio",
351 .name = "stmpe-keypad",
352 .of_compatible = "st,stmpe-keypad",
376 .name = "stmpe-pwm",
377 .of_compatible = "st,stmpe-pwm",
412 static int stmpe801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe801_enable() argument
460 .name = "stmpe-ts",
461 .of_compatible = "st,stmpe-ts",
502 static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe811_enable() argument
516 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], mask, in stmpe811_enable()
520 static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe811_get_altfunc() argument
557 * Compared to all others STMPE variant, LSB and MSB regs are located in this
588 static int stmpe1600_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1600_enable() argument
682 static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout) in stmpe_autosleep() argument
686 if (!stmpe->variant->enable_autosleep) in stmpe_autosleep()
689 mutex_lock(&stmpe->lock); in stmpe_autosleep()
690 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout); in stmpe_autosleep()
691 mutex_unlock(&stmpe->lock); in stmpe_autosleep()
697 * Both stmpe 1601/2403 support same layout for autosleep
699 static int stmpe1601_autosleep(struct stmpe *stmpe, in stmpe1601_autosleep() argument
707 dev_err(stmpe->dev, "invalid timeout\n"); in stmpe1601_autosleep()
711 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
717 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
722 static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1601_enable() argument
742 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe1601_enable()
746 static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe1601_get_altfunc() argument
823 static int stmpe1801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1801_enable() argument
833 return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask, in stmpe1801_enable()
837 static int stmpe_reset(struct stmpe *stmpe) in stmpe_reset() argument
839 u16 id_val = stmpe->variant->id_val; in stmpe_reset()
848 /* all other STMPE variant use bit 7 of SYS_CTRL register */ in stmpe_reset()
851 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], in stmpe_reset()
860 ret = __stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL]); in stmpe_reset()
945 static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe24xx_enable() argument
956 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe24xx_enable()
960 static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe24xx_get_altfunc() argument
1028 struct stmpe *stmpe = data; in stmpe_irq() local
1029 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
1038 int base = irq_create_mapping(stmpe->domain, 0); in stmpe_irq()
1045 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; in stmpe_irq()
1047 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; in stmpe_irq()
1049 ret = stmpe_block_read(stmpe, israddr, num, isr); in stmpe_irq()
1058 status &= stmpe->ier[bank]; in stmpe_irq()
1066 int nestedirq = irq_create_mapping(stmpe->domain, line); in stmpe_irq()
1072 stmpe_reg_write(stmpe, israddr + i, clear); in stmpe_irq()
1080 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_lock() local
1082 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
1087 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_sync_unlock() local
1088 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
1093 u8 new = stmpe->ier[i]; in stmpe_irq_sync_unlock()
1094 u8 old = stmpe->oldier[i]; in stmpe_irq_sync_unlock()
1099 stmpe->oldier[i] = new; in stmpe_irq_sync_unlock()
1100 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB + i], new); in stmpe_irq_sync_unlock()
1103 mutex_unlock(&stmpe->irq_lock); in stmpe_irq_sync_unlock()
1108 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_mask() local
1113 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
1118 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_unmask() local
1123 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
1127 .name = "stmpe",
1137 struct stmpe *stmpe = d->host_data; in stmpe_irq_map() local
1140 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
1143 irq_set_chip_data(virq, stmpe); in stmpe_irq_map()
1163 static int stmpe_irq_init(struct stmpe *stmpe, struct device_node *np) in stmpe_irq_init() argument
1166 int num_irqs = stmpe->variant->num_irqs; in stmpe_irq_init()
1168 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, in stmpe_irq_init()
1169 &stmpe_irq_ops, stmpe); in stmpe_irq_init()
1170 if (!stmpe->domain) { in stmpe_irq_init()
1171 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1178 static int stmpe_chip_init(struct stmpe *stmpe) in stmpe_chip_init() argument
1180 unsigned int irq_trigger = stmpe->pdata->irq_trigger; in stmpe_chip_init()
1181 int autosleep_timeout = stmpe->pdata->autosleep_timeout; in stmpe_chip_init()
1182 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_chip_init()
1188 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], in stmpe_chip_init()
1195 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1199 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1202 ret = stmpe_disable(stmpe, ~0); in stmpe_chip_init()
1206 ret = stmpe_reset(stmpe); in stmpe_chip_init()
1210 if (stmpe->irq >= 0) { in stmpe_chip_init()
1232 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1233 ret = stmpe_autosleep(stmpe, autosleep_timeout); in stmpe_chip_init()
1238 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
1241 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) in stmpe_add_device() argument
1243 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, in stmpe_add_device()
1244 NULL, 0, stmpe->domain); in stmpe_add_device()
1247 static int stmpe_devices_init(struct stmpe *stmpe) in stmpe_devices_init() argument
1249 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1250 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1270 ret = stmpe_add_device(stmpe, block->cell); in stmpe_devices_init()
1276 dev_warn(stmpe->dev, in stmpe_devices_init()
1288 pdata->id = of_alias_get_id(np, "stmpe-i2c"); in stmpe_of_probe()
1326 struct stmpe *stmpe; in stmpe_probe() local
1338 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1339 if (!stmpe) in stmpe_probe()
1342 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1343 mutex_init(&stmpe->lock); in stmpe_probe()
1345 stmpe->dev = ci->dev; in stmpe_probe()
1346 stmpe->client = ci->client; in stmpe_probe()
1347 stmpe->pdata = pdata; in stmpe_probe()
1348 stmpe->ci = ci; in stmpe_probe()
1349 stmpe->partnum = partnum; in stmpe_probe()
1350 stmpe->variant = stmpe_variant_info[partnum]; in stmpe_probe()
1351 stmpe->regs = stmpe->variant->regs; in stmpe_probe()
1352 stmpe->num_gpios = stmpe->variant->num_gpios; in stmpe_probe()
1353 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); in stmpe_probe()
1354 if (!IS_ERR(stmpe->vcc)) { in stmpe_probe()
1355 ret = regulator_enable(stmpe->vcc); in stmpe_probe()
1359 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); in stmpe_probe()
1360 if (!IS_ERR(stmpe->vio)) { in stmpe_probe()
1361 ret = regulator_enable(stmpe->vio); in stmpe_probe()
1365 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1368 ci->init(stmpe); in stmpe_probe()
1372 GPIOF_DIR_IN, "stmpe"); in stmpe_probe()
1374 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", in stmpe_probe()
1379 stmpe->irq = gpio_to_irq(pdata->irq_gpio); in stmpe_probe()
1381 stmpe->irq = ci->irq; in stmpe_probe()
1384 if (stmpe->irq < 0) { in stmpe_probe()
1386 dev_info(stmpe->dev, in stmpe_probe()
1388 stmpe->variant->name); in stmpe_probe()
1389 if (!stmpe_noirq_variant_info[stmpe->partnum]) { in stmpe_probe()
1390 dev_err(stmpe->dev, in stmpe_probe()
1392 stmpe->variant->name); in stmpe_probe()
1395 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1397 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1400 ret = stmpe_chip_init(stmpe); in stmpe_probe()
1404 if (stmpe->irq >= 0) { in stmpe_probe()
1405 ret = stmpe_irq_init(stmpe, np); in stmpe_probe()
1409 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1411 "stmpe", stmpe); in stmpe_probe()
1413 dev_err(stmpe->dev, "failed to request IRQ: %d\n", in stmpe_probe()
1419 ret = stmpe_devices_init(stmpe); in stmpe_probe()
1423 dev_err(stmpe->dev, "failed to add children\n"); in stmpe_probe()
1424 mfd_remove_devices(stmpe->dev); in stmpe_probe()
1429 int stmpe_remove(struct stmpe *stmpe) in stmpe_remove() argument
1431 if (!IS_ERR(stmpe->vio)) in stmpe_remove()
1432 regulator_disable(stmpe->vio); in stmpe_remove()
1433 if (!IS_ERR(stmpe->vcc)) in stmpe_remove()
1434 regulator_disable(stmpe->vcc); in stmpe_remove()
1436 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1444 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_suspend() local
1446 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1447 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1454 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_resume() local
1456 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1457 disable_irq_wake(stmpe->irq); in stmpe_resume()