Lines Matching refs:stmpe

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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
414 static int stmpe801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe801_enable() argument
533 static int stmpe811_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe811_enable() argument
547 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], mask, in stmpe811_enable()
551 int stmpe811_adc_common_init(struct stmpe *stmpe) in stmpe811_adc_common_init() argument
556 adc_ctrl1 = STMPE_SAMPLE_TIME(stmpe->sample_time) | in stmpe811_adc_common_init()
557 STMPE_MOD_12B(stmpe->mod_12b) | in stmpe811_adc_common_init()
558 STMPE_REF_SEL(stmpe->ref_sel); in stmpe811_adc_common_init()
562 ret = stmpe_set_bits(stmpe, STMPE811_REG_ADC_CTRL1, in stmpe811_adc_common_init()
565 dev_err(stmpe->dev, "Could not setup ADC\n"); in stmpe811_adc_common_init()
569 ret = stmpe_set_bits(stmpe, STMPE811_REG_ADC_CTRL2, in stmpe811_adc_common_init()
570 STMPE_ADC_FREQ(0xff), STMPE_ADC_FREQ(stmpe->adc_freq)); in stmpe811_adc_common_init()
572 dev_err(stmpe->dev, "Could not setup ADC\n"); in stmpe811_adc_common_init()
580 static int stmpe811_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe811_get_altfunc() argument
648 static int stmpe1600_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1600_enable() argument
742 static int stmpe_autosleep(struct stmpe *stmpe, int autosleep_timeout) in stmpe_autosleep() argument
746 if (!stmpe->variant->enable_autosleep) in stmpe_autosleep()
749 mutex_lock(&stmpe->lock); in stmpe_autosleep()
750 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout); in stmpe_autosleep()
751 mutex_unlock(&stmpe->lock); in stmpe_autosleep()
759 static int stmpe1601_autosleep(struct stmpe *stmpe, in stmpe1601_autosleep() argument
767 dev_err(stmpe->dev, "invalid timeout\n"); in stmpe1601_autosleep()
771 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
777 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
782 static int stmpe1601_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1601_enable() argument
802 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe1601_enable()
806 static int stmpe1601_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe1601_get_altfunc() argument
883 static int stmpe1801_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe1801_enable() argument
893 return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask, in stmpe1801_enable()
897 static int stmpe_reset(struct stmpe *stmpe) in stmpe_reset() argument
899 u16 id_val = stmpe->variant->id_val; in stmpe_reset()
911 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], in stmpe_reset()
920 ret = __stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL]); in stmpe_reset()
1005 static int stmpe24xx_enable(struct stmpe *stmpe, unsigned int blocks, in stmpe24xx_enable() argument
1016 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe24xx_enable()
1020 static int stmpe24xx_get_altfunc(struct stmpe *stmpe, enum stmpe_block block) in stmpe24xx_get_altfunc() argument
1088 struct stmpe *stmpe = data; in stmpe_irq() local
1089 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
1098 int base = irq_find_mapping(stmpe->domain, 0); in stmpe_irq()
1105 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; in stmpe_irq()
1107 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; in stmpe_irq()
1109 ret = stmpe_block_read(stmpe, israddr, num, isr); in stmpe_irq()
1118 status &= stmpe->ier[bank]; in stmpe_irq()
1126 int nestedirq = irq_find_mapping(stmpe->domain, line); in stmpe_irq()
1132 stmpe_reg_write(stmpe, israddr + i, clear); in stmpe_irq()
1140 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_lock() local
1142 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
1147 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_sync_unlock() local
1148 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
1153 u8 new = stmpe->ier[i]; in stmpe_irq_sync_unlock()
1154 u8 old = stmpe->oldier[i]; in stmpe_irq_sync_unlock()
1159 stmpe->oldier[i] = new; in stmpe_irq_sync_unlock()
1160 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB + i], new); in stmpe_irq_sync_unlock()
1163 mutex_unlock(&stmpe->irq_lock); in stmpe_irq_sync_unlock()
1168 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_mask() local
1173 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
1178 struct stmpe *stmpe = irq_data_get_irq_chip_data(data); in stmpe_irq_unmask() local
1183 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
1197 struct stmpe *stmpe = d->host_data; in stmpe_irq_map() local
1200 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
1203 irq_set_chip_data(virq, stmpe); in stmpe_irq_map()
1223 static int stmpe_irq_init(struct stmpe *stmpe, struct device_node *np) in stmpe_irq_init() argument
1226 int num_irqs = stmpe->variant->num_irqs; in stmpe_irq_init()
1228 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, in stmpe_irq_init()
1229 &stmpe_irq_ops, stmpe); in stmpe_irq_init()
1230 if (!stmpe->domain) { in stmpe_irq_init()
1231 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1238 static int stmpe_chip_init(struct stmpe *stmpe) in stmpe_chip_init() argument
1240 unsigned int irq_trigger = stmpe->pdata->irq_trigger; in stmpe_chip_init()
1241 int autosleep_timeout = stmpe->pdata->autosleep_timeout; in stmpe_chip_init()
1242 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_chip_init()
1248 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], in stmpe_chip_init()
1255 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1259 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1262 ret = stmpe_disable(stmpe, ~0); in stmpe_chip_init()
1266 ret = stmpe_reset(stmpe); in stmpe_chip_init()
1270 if (stmpe->irq >= 0) { in stmpe_chip_init()
1292 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1293 ret = stmpe_autosleep(stmpe, autosleep_timeout); in stmpe_chip_init()
1298 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
1301 static int stmpe_add_device(struct stmpe *stmpe, const struct mfd_cell *cell) in stmpe_add_device() argument
1303 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, in stmpe_add_device()
1304 NULL, 0, stmpe->domain); in stmpe_add_device()
1307 static int stmpe_devices_init(struct stmpe *stmpe) in stmpe_devices_init() argument
1309 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1310 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1330 ret = stmpe_add_device(stmpe, block->cell); in stmpe_devices_init()
1336 dev_warn(stmpe->dev, in stmpe_devices_init()
1386 struct stmpe *stmpe; in stmpe_probe() local
1399 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1400 if (!stmpe) in stmpe_probe()
1403 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1404 mutex_init(&stmpe->lock); in stmpe_probe()
1407 stmpe->sample_time = val; in stmpe_probe()
1409 stmpe->mod_12b = val; in stmpe_probe()
1411 stmpe->ref_sel = val; in stmpe_probe()
1413 stmpe->adc_freq = val; in stmpe_probe()
1415 stmpe->dev = ci->dev; in stmpe_probe()
1416 stmpe->client = ci->client; in stmpe_probe()
1417 stmpe->pdata = pdata; in stmpe_probe()
1418 stmpe->ci = ci; in stmpe_probe()
1419 stmpe->partnum = partnum; in stmpe_probe()
1420 stmpe->variant = stmpe_variant_info[partnum]; in stmpe_probe()
1421 stmpe->regs = stmpe->variant->regs; in stmpe_probe()
1422 stmpe->num_gpios = stmpe->variant->num_gpios; in stmpe_probe()
1423 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); in stmpe_probe()
1424 if (!IS_ERR(stmpe->vcc)) { in stmpe_probe()
1425 ret = regulator_enable(stmpe->vcc); in stmpe_probe()
1429 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); in stmpe_probe()
1430 if (!IS_ERR(stmpe->vio)) { in stmpe_probe()
1431 ret = regulator_enable(stmpe->vio); in stmpe_probe()
1435 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1438 ci->init(stmpe); in stmpe_probe()
1444 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", in stmpe_probe()
1449 stmpe->irq = gpio_to_irq(pdata->irq_gpio); in stmpe_probe()
1451 stmpe->irq = ci->irq; in stmpe_probe()
1454 if (stmpe->irq < 0) { in stmpe_probe()
1456 dev_info(stmpe->dev, in stmpe_probe()
1458 stmpe->variant->name); in stmpe_probe()
1459 if (!stmpe_noirq_variant_info[stmpe->partnum]) { in stmpe_probe()
1460 dev_err(stmpe->dev, in stmpe_probe()
1462 stmpe->variant->name); in stmpe_probe()
1465 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1467 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1470 ret = stmpe_chip_init(stmpe); in stmpe_probe()
1474 if (stmpe->irq >= 0) { in stmpe_probe()
1475 ret = stmpe_irq_init(stmpe, np); in stmpe_probe()
1479 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1481 "stmpe", stmpe); in stmpe_probe()
1483 dev_err(stmpe->dev, "failed to request IRQ: %d\n", in stmpe_probe()
1489 ret = stmpe_devices_init(stmpe); in stmpe_probe()
1493 dev_err(stmpe->dev, "failed to add children\n"); in stmpe_probe()
1494 mfd_remove_devices(stmpe->dev); in stmpe_probe()
1499 void stmpe_remove(struct stmpe *stmpe) in stmpe_remove() argument
1501 if (!IS_ERR(stmpe->vio)) in stmpe_remove()
1502 regulator_disable(stmpe->vio); in stmpe_remove()
1503 if (!IS_ERR(stmpe->vcc)) in stmpe_remove()
1504 regulator_disable(stmpe->vcc); in stmpe_remove()
1506 __stmpe_disable(stmpe, STMPE_BLOCK_ADC); in stmpe_remove()
1508 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1514 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_suspend() local
1516 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1517 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1524 struct stmpe *stmpe = dev_get_drvdata(dev); in stmpe_resume() local
1526 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1527 disable_irq_wake(stmpe->irq); in stmpe_resume()