H A D | stmpe.c | 2 * ST Microelectronics MFD: stmpe's driver 24 #include "stmpe.h" 26 static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks) __stmpe_enable() argument 28 return stmpe->variant->enable(stmpe, blocks, true); __stmpe_enable() 31 static int __stmpe_disable(struct stmpe *stmpe, unsigned int blocks) __stmpe_disable() argument 33 return stmpe->variant->enable(stmpe, blocks, false); __stmpe_disable() 36 static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg) __stmpe_reg_read() argument 40 ret = stmpe->ci->read_byte(stmpe, reg); __stmpe_reg_read() 42 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret); __stmpe_reg_read() 44 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret); __stmpe_reg_read() 49 static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val) __stmpe_reg_write() argument 53 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val); __stmpe_reg_write() 55 ret = stmpe->ci->write_byte(stmpe, reg, val); __stmpe_reg_write() 57 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret); __stmpe_reg_write() 62 static int __stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val) __stmpe_set_bits() argument 66 ret = __stmpe_reg_read(stmpe, reg); __stmpe_set_bits() 73 return __stmpe_reg_write(stmpe, reg, ret); __stmpe_set_bits() 76 static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, __stmpe_block_read() argument 81 ret = stmpe->ci->read_block(stmpe, reg, length, values); __stmpe_block_read() 83 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret); __stmpe_block_read() 85 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret); __stmpe_block_read() 86 stmpe_dump_bytes("stmpe rd: ", values, length); __stmpe_block_read() 91 static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, __stmpe_block_write() argument 96 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length); __stmpe_block_write() 97 stmpe_dump_bytes("stmpe wr: ", values, length); __stmpe_block_write() 99 ret = stmpe->ci->write_block(stmpe, reg, length, values); __stmpe_block_write() 101 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret); __stmpe_block_write() 108 * @stmpe: Device to work on 111 int stmpe_enable(struct stmpe *stmpe, unsigned int blocks) stmpe_enable() argument 115 mutex_lock(&stmpe->lock); stmpe_enable() 116 ret = __stmpe_enable(stmpe, blocks); stmpe_enable() 117 mutex_unlock(&stmpe->lock); stmpe_enable() 125 * @stmpe: Device to work on 128 int stmpe_disable(struct stmpe *stmpe, unsigned int blocks) stmpe_disable() argument 132 mutex_lock(&stmpe->lock); stmpe_disable() 133 ret = __stmpe_disable(stmpe, blocks); stmpe_disable() 134 mutex_unlock(&stmpe->lock); stmpe_disable() 142 * @stmpe: Device to read from 145 int stmpe_reg_read(struct stmpe *stmpe, u8 reg) stmpe_reg_read() argument 149 mutex_lock(&stmpe->lock); stmpe_reg_read() 150 ret = __stmpe_reg_read(stmpe, reg); stmpe_reg_read() 151 mutex_unlock(&stmpe->lock); stmpe_reg_read() 159 * @stmpe: Device to write to 163 int stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val) stmpe_reg_write() argument 167 mutex_lock(&stmpe->lock); stmpe_reg_write() 168 ret = __stmpe_reg_write(stmpe, reg, val); stmpe_reg_write() 169 mutex_unlock(&stmpe->lock); stmpe_reg_write() 177 * @stmpe: Device to write to 182 int stmpe_set_bits(struct stmpe *stmpe, u8 reg, u8 mask, u8 val) stmpe_set_bits() argument 186 mutex_lock(&stmpe->lock); stmpe_set_bits() 187 ret = __stmpe_set_bits(stmpe, reg, mask, val); stmpe_set_bits() 188 mutex_unlock(&stmpe->lock); stmpe_set_bits() 196 * @stmpe: Device to read from 201 int stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values) stmpe_block_read() argument 205 mutex_lock(&stmpe->lock); stmpe_block_read() 206 ret = __stmpe_block_read(stmpe, reg, length, values); stmpe_block_read() 207 mutex_unlock(&stmpe->lock); stmpe_block_read() 215 * @stmpe: Device to write to 220 int stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length, stmpe_block_write() argument 225 mutex_lock(&stmpe->lock); stmpe_block_write() 226 ret = __stmpe_block_write(stmpe, reg, length, values); stmpe_block_write() 227 mutex_unlock(&stmpe->lock); stmpe_block_write() 235 * @stmpe: Device to configure 245 int stmpe_set_altfunc(struct stmpe *stmpe, u32 pins, enum stmpe_block block) stmpe_set_altfunc() argument 247 struct stmpe_variant_info *variant = stmpe->variant; stmpe_set_altfunc() 248 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB]; stmpe_set_altfunc() 250 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8); stmpe_set_altfunc() 259 mutex_lock(&stmpe->lock); stmpe_set_altfunc() 261 ret = __stmpe_enable(stmpe, STMPE_BLOCK_GPIO); stmpe_set_altfunc() 265 ret = __stmpe_block_read(stmpe, regaddr, numregs, regs); stmpe_set_altfunc() 269 af = variant->get_altfunc(stmpe, block); stmpe_set_altfunc() 282 ret = __stmpe_block_write(stmpe, regaddr, numregs, regs); stmpe_set_altfunc() 285 mutex_unlock(&stmpe->lock); stmpe_set_altfunc() 302 .name = "stmpe-gpio", 303 .of_compatible = "st,stmpe-gpio", 309 .name = "stmpe-gpio", 310 .of_compatible = "st,stmpe-gpio", 330 .name = "stmpe-keypad", 331 .of_compatible = "st,stmpe-keypad", 366 static int stmpe801_enable(struct stmpe *stmpe, unsigned int blocks, stmpe801_enable() argument 414 .name = "stmpe-ts", 415 .of_compatible = "st,stmpe-ts", 454 static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks, stmpe811_enable() argument 468 return __stmpe_set_bits(stmpe, STMPE811_REG_SYS_CTRL2, mask, stmpe811_enable() 472 static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) stmpe811_get_altfunc() argument 563 static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout) stmpe_autosleep() argument 567 if (!stmpe->variant->enable_autosleep) stmpe_autosleep() 570 mutex_lock(&stmpe->lock); stmpe_autosleep() 571 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout); stmpe_autosleep() 572 mutex_unlock(&stmpe->lock); stmpe_autosleep() 578 * Both stmpe 1601/2403 support same layout for autosleep 580 static int stmpe1601_autosleep(struct stmpe *stmpe, stmpe1601_autosleep() argument 588 dev_err(stmpe->dev, "invalid timeout\n"); stmpe1601_autosleep() 592 ret = __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2, stmpe1601_autosleep() 598 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL2, stmpe1601_autosleep() 603 static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks, stmpe1601_enable() argument 623 return __stmpe_set_bits(stmpe, STMPE1601_REG_SYS_CTRL, mask, stmpe1601_enable() 627 static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) stmpe1601_get_altfunc() argument 689 static int stmpe1801_enable(struct stmpe *stmpe, unsigned int blocks, stmpe1801_enable() argument 699 return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask, stmpe1801_enable() 703 static int stmpe1801_reset(struct stmpe *stmpe) stmpe1801_reset() argument 708 ret = __stmpe_set_bits(stmpe, STMPE1801_REG_SYS_CTRL, stmpe1801_reset() 715 ret = __stmpe_reg_read(stmpe, STMPE1801_REG_SYS_CTRL); stmpe1801_reset() 776 static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks, stmpe24xx_enable() argument 787 return __stmpe_set_bits(stmpe, STMPE24XX_REG_SYS_CTRL, mask, stmpe24xx_enable() 791 static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) stmpe24xx_get_altfunc() argument 857 struct stmpe *stmpe = data; stmpe_irq() local 858 struct stmpe_variant_info *variant = stmpe->variant; stmpe_irq() 866 int base = irq_create_mapping(stmpe->domain, 0); stmpe_irq() 873 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; stmpe_irq() 875 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; stmpe_irq() 877 ret = stmpe_block_read(stmpe, israddr, num, isr); stmpe_irq() 886 status &= stmpe->ier[bank]; stmpe_irq() 894 int nestedirq = irq_create_mapping(stmpe->domain, line); stmpe_irq() 900 stmpe_reg_write(stmpe, israddr + i, clear); stmpe_irq() 908 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); stmpe_irq_lock() local 910 mutex_lock(&stmpe->irq_lock); stmpe_irq_lock() 915 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); stmpe_irq_sync_unlock() local 916 struct stmpe_variant_info *variant = stmpe->variant; stmpe_irq_sync_unlock() 921 u8 new = stmpe->ier[i]; stmpe_irq_sync_unlock() 922 u8 old = stmpe->oldier[i]; stmpe_irq_sync_unlock() 927 stmpe->oldier[i] = new; stmpe_irq_sync_unlock() 928 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB] - i, new); stmpe_irq_sync_unlock() 931 mutex_unlock(&stmpe->irq_lock); stmpe_irq_sync_unlock() 936 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); stmpe_irq_mask() local 941 stmpe->ier[regoffset] &= ~mask; stmpe_irq_mask() 946 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); stmpe_irq_unmask() local 951 stmpe->ier[regoffset] |= mask; stmpe_irq_unmask() 955 .name = "stmpe", 965 struct stmpe *stmpe = d->host_data; stmpe_irq_map() local 968 if (stmpe->variant->id_val != STMPE801_ID) stmpe_irq_map() 971 irq_set_chip_data(virq, stmpe); stmpe_irq_map() 998 static int stmpe_irq_init(struct stmpe *stmpe, struct device_node *np) stmpe_irq_init() argument 1001 int num_irqs = stmpe->variant->num_irqs; stmpe_irq_init() 1003 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, stmpe_irq_init() 1004 &stmpe_irq_ops, stmpe); stmpe_irq_init() 1005 if (!stmpe->domain) { stmpe_irq_init() 1006 dev_err(stmpe->dev, "Failed to create irqdomain\n"); stmpe_irq_init() 1013 static int stmpe_chip_init(struct stmpe *stmpe) stmpe_chip_init() argument 1015 unsigned int irq_trigger = stmpe->pdata->irq_trigger; stmpe_chip_init() 1016 int autosleep_timeout = stmpe->pdata->autosleep_timeout; stmpe_chip_init() 1017 struct stmpe_variant_info *variant = stmpe->variant; stmpe_chip_init() 1023 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], stmpe_chip_init() 1030 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); stmpe_chip_init() 1034 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); stmpe_chip_init() 1037 ret = stmpe_disable(stmpe, ~0); stmpe_chip_init() 1042 ret = stmpe1801_reset(stmpe); stmpe_chip_init() 1047 if (stmpe->irq >= 0) { stmpe_chip_init() 1069 if (stmpe->pdata->autosleep) { stmpe_chip_init() 1070 ret = stmpe_autosleep(stmpe, autosleep_timeout); stmpe_chip_init() 1075 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); stmpe_chip_init() 1078 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) stmpe_add_device() argument 1080 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, stmpe_add_device() 1081 NULL, 0, stmpe->domain); stmpe_add_device() 1084 static int stmpe_devices_init(struct stmpe *stmpe) stmpe_devices_init() argument 1086 struct stmpe_variant_info *variant = stmpe->variant; stmpe_devices_init() 1087 unsigned int platform_blocks = stmpe->pdata->blocks; stmpe_devices_init() 1107 ret = stmpe_add_device(stmpe, block->cell); stmpe_devices_init() 1113 dev_warn(stmpe->dev, stmpe_devices_init() 1125 pdata->id = of_alias_get_id(np, "stmpe-i2c"); stmpe_of_probe() 1163 struct stmpe *stmpe; stmpe_probe() local 1180 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); stmpe_probe() 1181 if (!stmpe) stmpe_probe() 1184 mutex_init(&stmpe->irq_lock); stmpe_probe() 1185 mutex_init(&stmpe->lock); stmpe_probe() 1187 stmpe->dev = ci->dev; stmpe_probe() 1188 stmpe->client = ci->client; stmpe_probe() 1189 stmpe->pdata = pdata; stmpe_probe() 1190 stmpe->ci = ci; stmpe_probe() 1191 stmpe->partnum = partnum; stmpe_probe() 1192 stmpe->variant = stmpe_variant_info[partnum]; stmpe_probe() 1193 stmpe->regs = stmpe->variant->regs; stmpe_probe() 1194 stmpe->num_gpios = stmpe->variant->num_gpios; stmpe_probe() 1195 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); stmpe_probe() 1196 if (!IS_ERR(stmpe->vcc)) { stmpe_probe() 1197 ret = regulator_enable(stmpe->vcc); stmpe_probe() 1201 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); stmpe_probe() 1202 if (!IS_ERR(stmpe->vio)) { stmpe_probe() 1203 ret = regulator_enable(stmpe->vio); stmpe_probe() 1207 dev_set_drvdata(stmpe->dev, stmpe); stmpe_probe() 1210 ci->init(stmpe); stmpe_probe() 1214 GPIOF_DIR_IN, "stmpe"); stmpe_probe() 1216 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", stmpe_probe() 1221 stmpe->irq = gpio_to_irq(pdata->irq_gpio); stmpe_probe() 1223 stmpe->irq = ci->irq; stmpe_probe() 1226 if (stmpe->irq < 0) { stmpe_probe() 1228 dev_info(stmpe->dev, stmpe_probe() 1230 stmpe->variant->name); stmpe_probe() 1231 if (!stmpe_noirq_variant_info[stmpe->partnum]) { stmpe_probe() 1232 dev_err(stmpe->dev, stmpe_probe() 1234 stmpe->variant->name); stmpe_probe() 1237 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; stmpe_probe() 1239 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); stmpe_probe() 1242 ret = stmpe_chip_init(stmpe); stmpe_probe() 1246 if (stmpe->irq >= 0) { stmpe_probe() 1247 ret = stmpe_irq_init(stmpe, np); stmpe_probe() 1251 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, stmpe_probe() 1253 "stmpe", stmpe); stmpe_probe() 1255 dev_err(stmpe->dev, "failed to request IRQ: %d\n", stmpe_probe() 1261 ret = stmpe_devices_init(stmpe); stmpe_probe() 1265 dev_err(stmpe->dev, "failed to add children\n"); stmpe_probe() 1266 mfd_remove_devices(stmpe->dev); stmpe_probe() 1271 int stmpe_remove(struct stmpe *stmpe) stmpe_remove() argument 1273 if (!IS_ERR(stmpe->vio)) stmpe_remove() 1274 regulator_disable(stmpe->vio); stmpe_remove() 1275 if (!IS_ERR(stmpe->vcc)) stmpe_remove() 1276 regulator_disable(stmpe->vcc); stmpe_remove() 1278 mfd_remove_devices(stmpe->dev); stmpe_remove() 1286 struct stmpe *stmpe = dev_get_drvdata(dev); stmpe_suspend() local 1288 if (stmpe->irq >= 0 && device_may_wakeup(dev)) stmpe_suspend() 1289 enable_irq_wake(stmpe->irq); stmpe_suspend() 1296 struct stmpe *stmpe = dev_get_drvdata(dev); stmpe_resume() local 1298 if (stmpe->irq >= 0 && device_may_wakeup(dev)) stmpe_resume() 1299 disable_irq_wake(stmpe->irq); stmpe_resume()
|