Lines Matching +full:adc +full:- +full:use +full:- +full:res

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) ST-Ericsson SA 2010
7 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
26 * struct stmpe_platform_data - STMPE platform data
28 * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*)
29 * @irq_trigger: IRQ trigger to use for the interrupt to the host
43 return stmpe->variant->enable(stmpe, blocks, true); in __stmpe_enable()
48 return stmpe->variant->enable(stmpe, blocks, false); in __stmpe_disable()
55 ret = stmpe->ci->read_byte(stmpe, reg); in __stmpe_reg_read()
57 dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret); in __stmpe_reg_read()
59 dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret); in __stmpe_reg_read()
68 dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val); in __stmpe_reg_write()
70 ret = stmpe->ci->write_byte(stmpe, reg, val); in __stmpe_reg_write()
72 dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret); in __stmpe_reg_write()
96 ret = stmpe->ci->read_block(stmpe, reg, length, values); in __stmpe_block_read()
98 dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret); in __stmpe_block_read()
100 dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret); in __stmpe_block_read()
111 dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length); in __stmpe_block_write()
114 ret = stmpe->ci->write_block(stmpe, reg, length, values); in __stmpe_block_write()
116 dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret); in __stmpe_block_write()
122 * stmpe_enable - enable blocks on an STMPE device
130 mutex_lock(&stmpe->lock); in stmpe_enable()
132 mutex_unlock(&stmpe->lock); in stmpe_enable()
139 * stmpe_disable - disable blocks on an STMPE device
147 mutex_lock(&stmpe->lock); in stmpe_disable()
149 mutex_unlock(&stmpe->lock); in stmpe_disable()
156 * stmpe_reg_read() - read a single STMPE register
164 mutex_lock(&stmpe->lock); in stmpe_reg_read()
166 mutex_unlock(&stmpe->lock); in stmpe_reg_read()
173 * stmpe_reg_write() - write a single STMPE register
182 mutex_lock(&stmpe->lock); in stmpe_reg_write()
184 mutex_unlock(&stmpe->lock); in stmpe_reg_write()
191 * stmpe_set_bits() - set the value of a bitfield in a STMPE register
201 mutex_lock(&stmpe->lock); in stmpe_set_bits()
203 mutex_unlock(&stmpe->lock); in stmpe_set_bits()
210 * stmpe_block_read() - read multiple STMPE registers
220 mutex_lock(&stmpe->lock); in stmpe_block_read()
222 mutex_unlock(&stmpe->lock); in stmpe_block_read()
229 * stmpe_block_write() - write multiple STMPE registers
240 mutex_lock(&stmpe->lock); in stmpe_block_write()
242 mutex_unlock(&stmpe->lock); in stmpe_block_write()
249 * stmpe_set_altfunc()- set the alternate function for STMPE pins
262 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_set_altfunc()
263 u8 regaddr = stmpe->regs[STMPE_IDX_GPAFR_U_MSB]; in stmpe_set_altfunc()
264 int af_bits = variant->af_bits; in stmpe_set_altfunc()
265 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8); in stmpe_set_altfunc()
266 int mask = (1 << af_bits) - 1; in stmpe_set_altfunc()
270 if (!variant->get_altfunc) in stmpe_set_altfunc()
274 mutex_lock(&stmpe->lock); in stmpe_set_altfunc()
284 af = variant->get_altfunc(stmpe, block); in stmpe_set_altfunc()
288 int regoffset = numregs - (pin / afperreg) - 1; in stmpe_set_altfunc()
300 mutex_unlock(&stmpe->lock); in stmpe_set_altfunc()
317 .name = "stmpe-gpio",
318 .of_compatible = "st,stmpe-gpio",
324 .name = "stmpe-gpio",
325 .of_compatible = "st,stmpe-gpio",
346 .name = "stmpe-keypad",
347 .of_compatible = "st,stmpe-keypad",
372 .name = "stmpe-pwm",
373 .of_compatible = "st,stmpe-pwm",
414 return -EINVAL; in stmpe801_enable()
457 .name = "stmpe-ts",
458 .of_compatible = "st,stmpe-ts",
464 * ADC (STMPE811)
480 .name = "stmpe-adc",
481 .of_compatible = "st,stmpe-adc",
541 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], mask, in stmpe811_enable()
550 adc_ctrl1 = STMPE_SAMPLE_TIME(stmpe->sample_time) | in stmpe811_adc_common_init()
551 STMPE_MOD_12B(stmpe->mod_12b) | in stmpe811_adc_common_init()
552 STMPE_REF_SEL(stmpe->ref_sel); in stmpe811_adc_common_init()
559 dev_err(stmpe->dev, "Could not setup ADC\n"); in stmpe811_adc_common_init()
564 STMPE_ADC_FREQ(0xff), STMPE_ADC_FREQ(stmpe->adc_freq)); in stmpe811_adc_common_init()
566 dev_err(stmpe->dev, "Could not setup ADC\n"); in stmpe811_adc_common_init()
648 return -EINVAL; in stmpe1600_enable()
733 return -EINVAL; in stmpe_round_timeout()
740 if (!stmpe->variant->enable_autosleep) in stmpe_autosleep()
741 return -ENOSYS; in stmpe_autosleep()
743 mutex_lock(&stmpe->lock); in stmpe_autosleep()
744 ret = stmpe->variant->enable_autosleep(stmpe, autosleep_timeout); in stmpe_autosleep()
745 mutex_unlock(&stmpe->lock); in stmpe_autosleep()
761 dev_err(stmpe->dev, "invalid timeout\n"); in stmpe1601_autosleep()
765 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
771 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], in stmpe1601_autosleep()
796 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe1601_enable()
893 u16 id_val = stmpe->variant->id_val; in stmpe_reset()
899 /* STMPE801 and STMPE610 use bit 1 of SYS_CTRL register */ in stmpe_reset()
902 /* all other STMPE variant use bit 7 of SYS_CTRL register */ in stmpe_reset()
905 ret = __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], in stmpe_reset()
914 ret = __stmpe_reg_read(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL]); in stmpe_reset()
921 return -EIO; in stmpe_reset()
1010 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe24xx_enable()
1071 * These devices can be connected in a 'no-irq' configuration - the irq pin
1073 * devices which support this configuration - the driver will fail probing
1083 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
1084 int num = DIV_ROUND_UP(variant->num_irqs, 8); in stmpe_irq()
1090 if (variant->id_val == STMPE801_ID || in stmpe_irq()
1091 variant->id_val == STMPE1600_ID) { in stmpe_irq()
1092 int base = irq_find_mapping(stmpe->domain, 0); in stmpe_irq()
1098 if (variant->id_val == STMPE1801_ID) in stmpe_irq()
1099 israddr = stmpe->regs[STMPE_IDX_ISR_LSB]; in stmpe_irq()
1101 israddr = stmpe->regs[STMPE_IDX_ISR_MSB]; in stmpe_irq()
1108 int bank = num - i - 1; in stmpe_irq()
1112 status &= stmpe->ier[bank]; in stmpe_irq()
1120 int nestedirq = irq_find_mapping(stmpe->domain, line); in stmpe_irq()
1136 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
1142 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
1143 int num = DIV_ROUND_UP(variant->num_irqs, 8); in stmpe_irq_sync_unlock()
1147 u8 new = stmpe->ier[i]; in stmpe_irq_sync_unlock()
1148 u8 old = stmpe->oldier[i]; in stmpe_irq_sync_unlock()
1153 stmpe->oldier[i] = new; in stmpe_irq_sync_unlock()
1154 stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_IER_LSB + i], new); in stmpe_irq_sync_unlock()
1157 mutex_unlock(&stmpe->irq_lock); in stmpe_irq_sync_unlock()
1163 int offset = data->hwirq; in stmpe_irq_mask()
1167 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
1173 int offset = data->hwirq; in stmpe_irq_unmask()
1177 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
1191 struct stmpe *stmpe = d->host_data; in stmpe_irq_map()
1194 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
1220 int num_irqs = stmpe->variant->num_irqs; in stmpe_irq_init()
1222 stmpe->domain = irq_domain_add_simple(np, num_irqs, base, in stmpe_irq_init()
1224 if (!stmpe->domain) { in stmpe_irq_init()
1225 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1226 return -ENOSYS; in stmpe_irq_init()
1234 unsigned int irq_trigger = stmpe->pdata->irq_trigger; in stmpe_chip_init()
1235 int autosleep_timeout = stmpe->pdata->autosleep_timeout; in stmpe_chip_init()
1236 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_chip_init()
1242 ret = stmpe_block_read(stmpe, stmpe->regs[STMPE_IDX_CHIP_ID], in stmpe_chip_init()
1248 if ((id & variant->id_mask) != variant->id_val) { in stmpe_chip_init()
1249 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1250 return -EINVAL; in stmpe_chip_init()
1253 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1255 /* Disable all modules -- subdrivers should enable what they need. */ in stmpe_chip_init()
1264 if (stmpe->irq >= 0) { in stmpe_chip_init()
1286 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1292 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
1297 return mfd_add_devices(stmpe->dev, stmpe->pdata->id, cell, 1, in stmpe_add_device()
1298 NULL, 0, stmpe->domain); in stmpe_add_device()
1303 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1304 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1305 int ret = -EINVAL; in stmpe_devices_init()
1308 for (i = 0; i < variant->num_blocks; i++) { in stmpe_devices_init()
1309 struct stmpe_variant_block *block = &variant->blocks[i]; in stmpe_devices_init()
1311 if (!(platform_blocks & block->block)) in stmpe_devices_init()
1314 for (j = 0; j < block->cell->num_resources; j++) { in stmpe_devices_init()
1315 struct resource *res = in stmpe_devices_init() local
1316 (struct resource *) &block->cell->resources[j]; in stmpe_devices_init()
1319 if (res->flags & IORESOURCE_IRQ) in stmpe_devices_init()
1320 res->start = res->end = block->irq + j; in stmpe_devices_init()
1323 platform_blocks &= ~block->block; in stmpe_devices_init()
1324 ret = stmpe_add_device(stmpe, block->cell); in stmpe_devices_init()
1330 dev_warn(stmpe->dev, in stmpe_devices_init()
1342 pdata->id = of_alias_get_id(np, "stmpe-i2c"); in stmpe_of_probe()
1343 if (pdata->id < 0) in stmpe_of_probe()
1344 pdata->id = -1; in stmpe_of_probe()
1346 of_property_read_u32(np, "st,autosleep-timeout", in stmpe_of_probe()
1347 &pdata->autosleep_timeout); in stmpe_of_probe()
1349 pdata->autosleep = (pdata->autosleep_timeout) ? true : false; in stmpe_of_probe()
1353 pdata->blocks |= STMPE_BLOCK_GPIO; in stmpe_of_probe()
1355 pdata->blocks |= STMPE_BLOCK_KEYPAD; in stmpe_of_probe()
1357 pdata->blocks |= STMPE_BLOCK_TOUCHSCREEN; in stmpe_of_probe()
1359 pdata->blocks |= STMPE_BLOCK_ADC; in stmpe_of_probe()
1361 pdata->blocks |= STMPE_BLOCK_PWM; in stmpe_of_probe()
1369 struct device_node *np = ci->dev->of_node; in stmpe_probe()
1375 pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL); in stmpe_probe()
1377 return -ENOMEM; in stmpe_probe()
1382 ci->irq = -1; in stmpe_probe()
1384 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1386 return -ENOMEM; in stmpe_probe()
1388 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1389 mutex_init(&stmpe->lock); in stmpe_probe()
1391 if (!of_property_read_u32(np, "st,sample-time", &val)) in stmpe_probe()
1392 stmpe->sample_time = val; in stmpe_probe()
1393 if (!of_property_read_u32(np, "st,mod-12b", &val)) in stmpe_probe()
1394 stmpe->mod_12b = val; in stmpe_probe()
1395 if (!of_property_read_u32(np, "st,ref-sel", &val)) in stmpe_probe()
1396 stmpe->ref_sel = val; in stmpe_probe()
1397 if (!of_property_read_u32(np, "st,adc-freq", &val)) in stmpe_probe()
1398 stmpe->adc_freq = val; in stmpe_probe()
1400 stmpe->dev = ci->dev; in stmpe_probe()
1401 stmpe->client = ci->client; in stmpe_probe()
1402 stmpe->pdata = pdata; in stmpe_probe()
1403 stmpe->ci = ci; in stmpe_probe()
1404 stmpe->partnum = partnum; in stmpe_probe()
1405 stmpe->variant = stmpe_variant_info[partnum]; in stmpe_probe()
1406 stmpe->regs = stmpe->variant->regs; in stmpe_probe()
1407 stmpe->num_gpios = stmpe->variant->num_gpios; in stmpe_probe()
1408 stmpe->vcc = devm_regulator_get_optional(ci->dev, "vcc"); in stmpe_probe()
1409 if (!IS_ERR(stmpe->vcc)) { in stmpe_probe()
1410 ret = regulator_enable(stmpe->vcc); in stmpe_probe()
1412 dev_warn(ci->dev, "failed to enable VCC supply\n"); in stmpe_probe()
1414 stmpe->vio = devm_regulator_get_optional(ci->dev, "vio"); in stmpe_probe()
1415 if (!IS_ERR(stmpe->vio)) { in stmpe_probe()
1416 ret = regulator_enable(stmpe->vio); in stmpe_probe()
1418 dev_warn(ci->dev, "failed to enable VIO supply\n"); in stmpe_probe()
1420 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1422 if (ci->init) in stmpe_probe()
1423 ci->init(stmpe); in stmpe_probe()
1425 irq_gpio = devm_gpiod_get_optional(ci->dev, "irq", GPIOD_ASIS); in stmpe_probe()
1428 dev_err(stmpe->dev, "failed to request IRQ GPIO: %d\n", ret); in stmpe_probe()
1433 stmpe->irq = gpiod_to_irq(irq_gpio); in stmpe_probe()
1434 pdata->irq_trigger = gpiod_is_active_low(irq_gpio) ? in stmpe_probe()
1437 stmpe->irq = ci->irq; in stmpe_probe()
1438 pdata->irq_trigger = IRQF_TRIGGER_NONE; in stmpe_probe()
1441 if (stmpe->irq < 0) { in stmpe_probe()
1442 /* use alternate variant info for no-irq mode, if supported */ in stmpe_probe()
1443 dev_info(stmpe->dev, in stmpe_probe()
1444 "%s configured in no-irq mode by platform data\n", in stmpe_probe()
1445 stmpe->variant->name); in stmpe_probe()
1446 if (!stmpe_noirq_variant_info[stmpe->partnum]) { in stmpe_probe()
1447 dev_err(stmpe->dev, in stmpe_probe()
1448 "%s does not support no-irq mode!\n", in stmpe_probe()
1449 stmpe->variant->name); in stmpe_probe()
1450 return -ENODEV; in stmpe_probe()
1452 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1453 } else if (pdata->irq_trigger == IRQF_TRIGGER_NONE) { in stmpe_probe()
1454 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1461 if (stmpe->irq >= 0) { in stmpe_probe()
1466 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1467 stmpe_irq, pdata->irq_trigger | IRQF_ONESHOT, in stmpe_probe()
1470 dev_err(stmpe->dev, "failed to request IRQ: %d\n", in stmpe_probe()
1480 dev_err(stmpe->dev, "failed to add children\n"); in stmpe_probe()
1481 mfd_remove_devices(stmpe->dev); in stmpe_probe()
1488 if (!IS_ERR(stmpe->vio) && regulator_is_enabled(stmpe->vio)) in stmpe_remove()
1489 regulator_disable(stmpe->vio); in stmpe_remove()
1490 if (!IS_ERR(stmpe->vcc) && regulator_is_enabled(stmpe->vcc)) in stmpe_remove()
1491 regulator_disable(stmpe->vcc); in stmpe_remove()
1495 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1502 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1503 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1512 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1513 disable_irq_wake(stmpe->irq); in stmpe_resume()