Lines Matching +full:enable +full:- +full:mask
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
27 * struct stmpe_platform_data - STMPE platform data
29 * @blocks: bitmask of blocks to enable (use STMPE_BLOCK_*)
31 * @autosleep: bool to enable/disable stmpe autosleep
49 return stmpe->variant->enable(stmpe, blocks, true); in __stmpe_enable()
54 return stmpe->variant->enable(stmpe, blocks, false); in __stmpe_disable()
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()
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
91 ret &= ~mask; in __stmpe_set_bits()
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()
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()
128 * stmpe_enable - enable blocks on an STMPE device
130 * @blocks: Mask of blocks (enum stmpe_block values) to enable
136 mutex_lock(&stmpe->lock); in stmpe_enable()
138 mutex_unlock(&stmpe->lock); in stmpe_enable()
145 * stmpe_disable - disable blocks on an STMPE device
147 * @blocks: Mask of blocks (enum stmpe_block values) to enable
153 mutex_lock(&stmpe->lock); in stmpe_disable()
155 mutex_unlock(&stmpe->lock); in stmpe_disable()
162 * stmpe_reg_read() - read a single STMPE register
170 mutex_lock(&stmpe->lock); in stmpe_reg_read()
172 mutex_unlock(&stmpe->lock); in stmpe_reg_read()
179 * stmpe_reg_write() - write a single STMPE register
188 mutex_lock(&stmpe->lock); 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
200 * @mask: Mask of bits to set
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
226 mutex_lock(&stmpe->lock); in stmpe_block_read()
228 mutex_unlock(&stmpe->lock); in stmpe_block_read()
235 * stmpe_block_write() - write multiple STMPE registers
246 mutex_lock(&stmpe->lock); in stmpe_block_write()
248 mutex_unlock(&stmpe->lock); in stmpe_block_write()
255 * stmpe_set_altfunc()- set the alternate function for STMPE pins
258 * @block: block to enable alternate functions for
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()
270 int af_bits = variant->af_bits; in stmpe_set_altfunc()
271 int numregs = DIV_ROUND_UP(stmpe->num_gpios * af_bits, 8); in stmpe_set_altfunc()
272 int mask = (1 << af_bits) - 1; in stmpe_set_altfunc() local
276 if (!variant->get_altfunc) in stmpe_set_altfunc()
280 mutex_lock(&stmpe->lock); in stmpe_set_altfunc()
290 af = variant->get_altfunc(stmpe, block); in stmpe_set_altfunc()
294 int regoffset = numregs - (pin / afperreg) - 1; in stmpe_set_altfunc()
297 regs[regoffset] &= ~(mask << pos); 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",
413 bool enable) in stmpe801_enable() argument
418 return -EINVAL; in stmpe801_enable()
430 .enable = stmpe801_enable,
441 .enable = stmpe801_enable,
460 .name = "stmpe-ts",
461 .of_compatible = "st,stmpe-ts",
482 .name = "stmpe-adc",
483 .of_compatible = "st,stmpe-adc",
530 bool enable) in stmpe811_enable() argument
532 unsigned int mask = 0; in stmpe811_enable() local
535 mask |= STMPE811_SYS_CTRL2_GPIO_OFF; in stmpe811_enable()
538 mask |= STMPE811_SYS_CTRL2_ADC_OFF; in stmpe811_enable()
541 mask |= STMPE811_SYS_CTRL2_TSC_OFF; in stmpe811_enable()
543 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL2], mask, in stmpe811_enable()
544 enable ? 0 : mask); in stmpe811_enable()
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()
561 dev_err(stmpe->dev, "Could not setup ADC\n"); 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()
592 .enable = stmpe811_enable,
607 .enable = stmpe811_enable,
645 bool enable) in stmpe1600_enable() argument
650 return -EINVAL; in stmpe1600_enable()
663 .enable = stmpe1600_enable,
735 return -EINVAL; in stmpe_round_timeout()
742 if (!stmpe->variant->enable_autosleep) in stmpe_autosleep()
743 return -ENOSYS; 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()
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()
779 bool enable) in stmpe1601_enable() argument
781 unsigned int mask = 0; in stmpe1601_enable() local
784 mask |= STMPE1601_SYS_CTRL_ENABLE_GPIO; in stmpe1601_enable()
786 mask &= ~STMPE1601_SYS_CTRL_ENABLE_GPIO; in stmpe1601_enable()
789 mask |= STMPE1601_SYS_CTRL_ENABLE_KPC; in stmpe1601_enable()
791 mask &= ~STMPE1601_SYS_CTRL_ENABLE_KPC; in stmpe1601_enable()
794 mask |= STMPE1601_SYS_CTRL_ENABLE_SPWM; in stmpe1601_enable()
796 mask &= ~STMPE1601_SYS_CTRL_ENABLE_SPWM; in stmpe1601_enable()
798 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe1601_enable()
799 enable ? mask : 0); in stmpe1601_enable()
827 .enable = stmpe1601_enable,
880 bool enable) in stmpe1801_enable() argument
882 unsigned int mask = 0; in stmpe1801_enable() local
884 mask |= STMPE1801_MSK_INT_EN_GPIO; in stmpe1801_enable()
887 mask |= STMPE1801_MSK_INT_EN_KPC; in stmpe1801_enable()
889 return __stmpe_set_bits(stmpe, STMPE1801_REG_INT_EN_MASK_LOW, mask, in stmpe1801_enable()
890 enable ? mask : 0); in stmpe1801_enable()
895 u16 id_val = stmpe->variant->id_val; 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()
923 return -EIO; in stmpe_reset()
936 .enable = stmpe1801_enable,
1002 bool enable) in stmpe24xx_enable() argument
1004 unsigned int mask = 0; in stmpe24xx_enable() local
1007 mask |= STMPE24XX_SYS_CTRL_ENABLE_GPIO; in stmpe24xx_enable()
1010 mask |= STMPE24XX_SYS_CTRL_ENABLE_KPC; in stmpe24xx_enable()
1012 return __stmpe_set_bits(stmpe, stmpe->regs[STMPE_IDX_SYS_CTRL], mask, in stmpe24xx_enable()
1013 enable ? mask : 0); in stmpe24xx_enable()
1042 .enable = stmpe24xx_enable,
1056 .enable = stmpe24xx_enable,
1073 * These devices can be connected in a 'no-irq' configuration - the irq pin
1075 * devices which support this configuration - the driver will fail probing
1085 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq()
1086 int num = DIV_ROUND_UP(variant->num_irqs, 8); in stmpe_irq()
1092 if (variant->id_val == STMPE801_ID || in stmpe_irq()
1093 variant->id_val == STMPE1600_ID) { in stmpe_irq()
1094 int base = irq_create_mapping(stmpe->domain, 0); in stmpe_irq()
1100 if (variant->id_val == STMPE1801_ID) 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()
1110 int bank = num - i - 1; in stmpe_irq()
1114 status &= stmpe->ier[bank]; in stmpe_irq()
1122 int nestedirq = irq_create_mapping(stmpe->domain, line); in stmpe_irq()
1138 mutex_lock(&stmpe->irq_lock); in stmpe_irq_lock()
1144 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_irq_sync_unlock()
1145 int num = DIV_ROUND_UP(variant->num_irqs, 8); 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()
1165 int offset = data->hwirq; in stmpe_irq_mask()
1167 int mask = 1 << (offset % 8); in stmpe_irq_mask() local
1169 stmpe->ier[regoffset] &= ~mask; in stmpe_irq_mask()
1175 int offset = data->hwirq; in stmpe_irq_unmask()
1177 int mask = 1 << (offset % 8); in stmpe_irq_unmask() local
1179 stmpe->ier[regoffset] |= mask; in stmpe_irq_unmask()
1193 struct stmpe *stmpe = d->host_data; in stmpe_irq_map()
1196 if (stmpe->variant->id_val != STMPE801_ID) in stmpe_irq_map()
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()
1226 if (!stmpe->domain) { in stmpe_irq_init()
1227 dev_err(stmpe->dev, "Failed to create irqdomain\n"); in stmpe_irq_init()
1228 return -ENOSYS; in stmpe_irq_init()
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()
1250 if ((id & variant->id_mask) != variant->id_val) { in stmpe_chip_init()
1251 dev_err(stmpe->dev, "unknown chip id: %#x\n", id); in stmpe_chip_init()
1252 return -EINVAL; in stmpe_chip_init()
1255 dev_info(stmpe->dev, "%s detected, chip id: %#x\n", variant->name, id); in stmpe_chip_init()
1257 /* Disable all modules -- subdrivers should enable what they need. */ in stmpe_chip_init()
1266 if (stmpe->irq >= 0) { in stmpe_chip_init()
1288 if (stmpe->pdata->autosleep) { in stmpe_chip_init()
1294 return stmpe_reg_write(stmpe, stmpe->regs[STMPE_IDX_ICR_LSB], icr); in stmpe_chip_init()
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()
1305 struct stmpe_variant_info *variant = stmpe->variant; in stmpe_devices_init()
1306 unsigned int platform_blocks = stmpe->pdata->blocks; in stmpe_devices_init()
1307 int ret = -EINVAL; in stmpe_devices_init()
1310 for (i = 0; i < variant->num_blocks; i++) { in stmpe_devices_init()
1311 struct stmpe_variant_block *block = &variant->blocks[i]; in stmpe_devices_init()
1313 if (!(platform_blocks & block->block)) in stmpe_devices_init()
1316 for (j = 0; j < block->cell->num_resources; j++) { in stmpe_devices_init()
1318 (struct resource *) &block->cell->resources[j]; in stmpe_devices_init()
1321 if (res->flags & IORESOURCE_IRQ) in stmpe_devices_init()
1322 res->start = res->end = block->irq + j; in stmpe_devices_init()
1325 platform_blocks &= ~block->block; 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()
1345 if (pdata->id < 0) in stmpe_of_probe()
1346 pdata->id = -1; in stmpe_of_probe()
1348 pdata->irq_gpio = of_get_named_gpio_flags(np, "irq-gpio", 0, in stmpe_of_probe()
1349 &pdata->irq_trigger); in stmpe_of_probe()
1350 if (gpio_is_valid(pdata->irq_gpio)) in stmpe_of_probe()
1351 pdata->irq_over_gpio = 1; in stmpe_of_probe()
1353 pdata->irq_trigger = IRQF_TRIGGER_NONE; in stmpe_of_probe()
1355 of_property_read_u32(np, "st,autosleep-timeout", in stmpe_of_probe()
1356 &pdata->autosleep_timeout); in stmpe_of_probe()
1358 pdata->autosleep = (pdata->autosleep_timeout) ? true : false; in stmpe_of_probe()
1362 pdata->blocks |= STMPE_BLOCK_GPIO; in stmpe_of_probe()
1364 pdata->blocks |= STMPE_BLOCK_KEYPAD; in stmpe_of_probe()
1366 pdata->blocks |= STMPE_BLOCK_TOUCHSCREEN; in stmpe_of_probe()
1368 pdata->blocks |= STMPE_BLOCK_ADC; in stmpe_of_probe()
1370 pdata->blocks |= STMPE_BLOCK_PWM; in stmpe_of_probe()
1372 pdata->blocks |= STMPE_BLOCK_ROTATOR; in stmpe_of_probe()
1381 struct device_node *np = ci->dev->of_node; in stmpe_probe()
1386 pdata = devm_kzalloc(ci->dev, sizeof(*pdata), GFP_KERNEL); in stmpe_probe()
1388 return -ENOMEM; in stmpe_probe()
1393 ci->irq = -1; in stmpe_probe()
1395 stmpe = devm_kzalloc(ci->dev, sizeof(struct stmpe), GFP_KERNEL); in stmpe_probe()
1397 return -ENOMEM; in stmpe_probe()
1399 mutex_init(&stmpe->irq_lock); in stmpe_probe()
1400 mutex_init(&stmpe->lock); in stmpe_probe()
1402 if (!of_property_read_u32(np, "st,sample-time", &val)) in stmpe_probe()
1403 stmpe->sample_time = val; in stmpe_probe()
1404 if (!of_property_read_u32(np, "st,mod-12b", &val)) in stmpe_probe()
1405 stmpe->mod_12b = val; in stmpe_probe()
1406 if (!of_property_read_u32(np, "st,ref-sel", &val)) in stmpe_probe()
1407 stmpe->ref_sel = val; in stmpe_probe()
1408 if (!of_property_read_u32(np, "st,adc-freq", &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()
1423 dev_warn(ci->dev, "failed to enable VCC supply\n"); 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()
1429 dev_warn(ci->dev, "failed to enable VIO supply\n"); in stmpe_probe()
1431 dev_set_drvdata(stmpe->dev, stmpe); in stmpe_probe()
1433 if (ci->init) in stmpe_probe()
1434 ci->init(stmpe); in stmpe_probe()
1436 if (pdata->irq_over_gpio) { in stmpe_probe()
1437 ret = devm_gpio_request_one(ci->dev, pdata->irq_gpio, 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()
1451 /* use alternate variant info for no-irq mode, if supported */ in stmpe_probe()
1452 dev_info(stmpe->dev, in stmpe_probe()
1453 "%s configured in no-irq mode by platform data\n", 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()
1457 "%s does not support no-irq mode!\n", in stmpe_probe()
1458 stmpe->variant->name); in stmpe_probe()
1459 return -ENODEV; in stmpe_probe()
1461 stmpe->variant = stmpe_noirq_variant_info[stmpe->partnum]; in stmpe_probe()
1462 } else if (pdata->irq_trigger == IRQF_TRIGGER_NONE) { in stmpe_probe()
1463 pdata->irq_trigger = irq_get_trigger_type(stmpe->irq); in stmpe_probe()
1470 if (stmpe->irq >= 0) { in stmpe_probe()
1475 ret = devm_request_threaded_irq(ci->dev, stmpe->irq, NULL, in stmpe_probe()
1476 stmpe_irq, pdata->irq_trigger | IRQF_ONESHOT, in stmpe_probe()
1479 dev_err(stmpe->dev, "failed to request IRQ: %d\n", 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()
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()
1504 mfd_remove_devices(stmpe->dev); in stmpe_remove()
1514 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_suspend()
1515 enable_irq_wake(stmpe->irq); in stmpe_suspend()
1524 if (stmpe->irq >= 0 && device_may_wakeup(dev)) in stmpe_resume()
1525 disable_irq_wake(stmpe->irq); in stmpe_resume()