Lines Matching full:stmpe
3 * 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",
482 .name = "stmpe-adc",
483 .of_compatible = "st,stmpe-adc",
529 static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe811_enable() argument
543 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], mask, in stmpe811_enable()
547 int stmpe811_adc_common_init(struct stmpe *stmpe) in stmpe811_adc_common_init() argument
552 adc_ctrl1 = STMPE_SAMPLE_TIME(stmpe->sample_time) | in stmpe811_adc_common_init()
553 STMPE_MOD_12B(stmpe->mod_12b) | in stmpe811_adc_common_init()
554 STMPE_REF_SEL(stmpe->ref_sel); in stmpe811_adc_common_init()
558 ret = stmpe_set_bits(stmpe, STMPE811_REG_ADC_CTRL1, in stmpe811_adc_common_init()
561 dev_err(stmpe->dev, "Could not setup ADC\n"); in stmpe811_adc_common_init()
565 ret = stmpe_set_bits(stmpe, STMPE811_REG_ADC_CTRL2, in stmpe811_adc_common_init()
566 STMPE_ADC_FREQ(0xff), STMPE_ADC_FREQ(stmpe->adc_freq)); in stmpe811_adc_common_init()
568 dev_err(stmpe->dev, "Could not setup ADC\n"); in stmpe811_adc_common_init()
576 static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe811_get_altfunc() argument
613 * Compared to all others STMPE variant, LSB and MSB regs are located in this
644 static int stmpe1600_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1600_enable() argument
738 static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout) in stmpe_autosleep() argument
742 if (!stmpe->variant->enable_autosleep) in stmpe_autosleep()
745 mutex_lock(&stmpe->lock); in stmpe_autosleep()
746 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout); in stmpe_autosleep()
747 mutex_unlock(&stmpe->lock); in stmpe_autosleep()
753 * Both stmpe 1601/2403 support same layout for autosleep
755 static int stmpe1601_autosleep(struct stmpe *stmpe, in stmpe1601_autosleep() argument
763 dev_err(stmpe->dev, "invalid timeout\n"); in stmpe1601_autosleep()
767 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
773 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
778 static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1601_enable() argument
798 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe1601_enable()
802 static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe1601_get_altfunc() argument
879 static int stmpe1801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1801_enable() argument
889 return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask, in stmpe1801_enable()
893 static int stmpe_reset(struct stmpe *stmpe) in stmpe_reset() argument
895 u16 id_val = stmpe->variant->id_val; in stmpe_reset()
904 /* all other STMPE variant use bit 7 of SYS_CTRL register */ in stmpe_reset()
907 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], in stmpe_reset()
916 ret = __stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL]); in stmpe_reset()
1001 static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe24xx_enable() argument
1012 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe24xx_enable()
1016 static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe24xx_get_altfunc() argument
1084 struct stmpe *stmpe = data; in stmpe_irq() local
1085 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
1094 int base = irq_create_mapping(stmpe->domain, 0); in stmpe_irq()
1101 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; in stmpe_irq()
1103 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; in stmpe_irq()
1105 ret = stmpe_block_read(stmpe, israddr, num, isr); in stmpe_irq()
1114 status &= stmpe->ier[bank]; in stmpe_irq()
1122 int nestedirq = irq_create_mapping(stmpe->domain, line); in stmpe_irq()
1128 stmpe_reg_write(stmpe, israddr + i, clear); in stmpe_irq()
1136 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_lock() local
1138 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
1143 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_sync_unlock() local
1144 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
1149 u8 new = stmpe->ier[i]; in stmpe_irq_sync_unlock()
1150 u8 old = stmpe->oldier[i]; in stmpe_irq_sync_unlock()
1155 stmpe->oldier[i] = new; in stmpe_irq_sync_unlock()
1156 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB + i], new); in stmpe_irq_sync_unlock()
1159 mutex_unlock(&stmpe->irq_lock); in stmpe_irq_sync_unlock()
1164 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_mask() local
1169 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
1174 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_unmask() local
1179 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
1183 .name = "stmpe",
1193 struct stmpe *stmpe = d->host_data; in stmpe_irq_map() local
1196 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
1199 irq_set_chip_data(virq, stmpe); in stmpe_irq_map()
1219 static int stmpe_irq_init(struct stmpe *stmpe, struct device_node *np) in stmpe_irq_init() argument
1222 int num_irqs = stmpe->variant->num_irqs; in stmpe_irq_init()
1224 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, in stmpe_irq_init()
1225 &stmpe_irq_ops, stmpe); in stmpe_irq_init()
1226 if (!stmpe->domain) { in stmpe_irq_init()
1227 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1234 static int stmpe_chip_init(struct stmpe *stmpe) in stmpe_chip_init() argument
1236 unsigned int irq_trigger = stmpe->pdata->irq_trigger; in stmpe_chip_init()
1237 int autosleep_timeout = stmpe->pdata->autosleep_timeout; in stmpe_chip_init()
1238 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_chip_init()
1244 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], in stmpe_chip_init()
1251 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1255 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1258 ret = stmpe_disable(stmpe, ~0); in stmpe_chip_init()
1262 ret = stmpe_reset(stmpe); in stmpe_chip_init()
1266 if (stmpe->irq >= 0) { in stmpe_chip_init()
1288 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1289 ret = stmpe_autosleep(stmpe, autosleep_timeout); in stmpe_chip_init()
1294 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
1297 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) in stmpe_add_device() argument
1299 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, in stmpe_add_device()
1300 NULL, 0, stmpe->domain); in stmpe_add_device()
1303 static int stmpe_devices_init(struct stmpe *stmpe) in stmpe_devices_init() argument
1305 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1306 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1326 ret = stmpe_add_device(stmpe, block->cell); in stmpe_devices_init()
1332 dev_warn(stmpe->dev, in stmpe_devices_init()
1344 pdata->id = of_alias_get_id(np, "stmpe-i2c"); in stmpe_of_probe()
1382 struct stmpe *stmpe; in stmpe_probe() local
1395 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1396 if (!stmpe) in stmpe_probe()
1399 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1400 mutex_init(&stmpe->lock); in stmpe_probe()
1403 stmpe->sample_time = val; in stmpe_probe()
1405 stmpe->mod_12b = val; in stmpe_probe()
1407 stmpe->ref_sel = val; in stmpe_probe()
1409 stmpe->adc_freq = val; in stmpe_probe()
1411 stmpe->dev = ci->dev; in stmpe_probe()
1412 stmpe->client = ci->client; in stmpe_probe()
1413 stmpe->pdata = pdata; in stmpe_probe()
1414 stmpe->ci = ci; in stmpe_probe()
1415 stmpe->partnum = partnum; in stmpe_probe()
1416 stmpe->variant = stmpe_variant_info[partnum]; in stmpe_probe()
1417 stmpe->regs = stmpe->variant->regs; in stmpe_probe()
1418 stmpe->num_gpios = stmpe->variant->num_gpios; in stmpe_probe()
1419 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); in stmpe_probe()
1420 if (!IS_ERR(stmpe->vcc)) { in stmpe_probe()
1421 ret = regulator_enable(stmpe->vcc); in stmpe_probe()
1425 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); in stmpe_probe()
1426 if (!IS_ERR(stmpe->vio)) { in stmpe_probe()
1427 ret = regulator_enable(stmpe->vio); in stmpe_probe()
1431 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1434 ci->init(stmpe); in stmpe_probe()
1438 GPIOF_DIR_IN, "stmpe"); in stmpe_probe()
1440 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", in stmpe_probe()
1445 stmpe->irq = gpio_to_irq(pdata->irq_gpio); in stmpe_probe()
1447 stmpe->irq = ci->irq; in stmpe_probe()
1450 if (stmpe->irq < 0) { in stmpe_probe()
1452 dev_info(stmpe->dev, in stmpe_probe()
1454 stmpe->variant->name); in stmpe_probe()
1455 if (!stmpe_noirq_variant_info[stmpe->partnum]) { in stmpe_probe()
1456 dev_err(stmpe->dev, in stmpe_probe()
1458 stmpe->variant->name); in stmpe_probe()
1461 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1463 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1466 ret = stmpe_chip_init(stmpe); in stmpe_probe()
1470 if (stmpe->irq >= 0) { in stmpe_probe()
1471 ret = stmpe_irq_init(stmpe, np); in stmpe_probe()
1475 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1477 "stmpe", stmpe); in stmpe_probe()
1479 dev_err(stmpe->dev, "failed to request IRQ: %d\n", in stmpe_probe()
1485 ret = stmpe_devices_init(stmpe); in stmpe_probe()
1489 dev_err(stmpe->dev, "failed to add children\n"); in stmpe_probe()
1490 mfd_remove_devices(stmpe->dev); in stmpe_probe()
1495 int stmpe_remove(struct stmpe *stmpe) in stmpe_remove() argument
1497 if (!IS_ERR(stmpe->vio)) in stmpe_remove()
1498 regulator_disable(stmpe->vio); in stmpe_remove()
1499 if (!IS_ERR(stmpe->vcc)) in stmpe_remove()
1500 regulator_disable(stmpe->vcc); in stmpe_remove()
1502 __stmpe_disable(stmpe, STMPE_BLOCK_ADC); in stmpe_remove()
1504 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1512 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_suspend() local
1514 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1515 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1522 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_resume() local
1524 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1525 disable_irq_wake(stmpe->irq); in stmpe_resume()