Lines Matching +full:vdd +full:- +full:s
1 // SPDX-License-Identifier: GPL-2.0
3 * Driver for STMicroelectronics Multi-Function eXpander (STMFX) core
6 * Author(s): Amelie Delaunay <amelie.delaunay@st.com>.
78 .of_compatible = "st,stmfx-0300-pinctrl",
79 .name = "stmfx-pinctrl",
84 .of_compatible = "st,stmfx-0300-idd",
85 .name = "stmfx-idd",
90 .of_compatible = "st,stmfx-0300-ts",
91 .name = "stmfx-ts",
122 ret = regmap_read(stmfx->map, STMFX_REG_SYS_CTRL, &sys_ctrl); in stmfx_function_enable()
134 dev_err(stmfx->dev, "ALTGPIO function already enabled\n"); in stmfx_function_enable()
135 return -EBUSY; in stmfx_function_enable()
141 dev_err(stmfx->dev, "TS in use, aGPIO[3:0] unavailable\n"); in stmfx_function_enable()
142 return -EBUSY; in stmfx_function_enable()
148 dev_err(stmfx->dev, "IDD in use, aGPIO[7:4] unavailable\n"); in stmfx_function_enable()
149 return -EBUSY; in stmfx_function_enable()
154 return regmap_update_bits(stmfx->map, STMFX_REG_SYS_CTRL, mask, mask); in stmfx_function_enable()
162 return regmap_update_bits(stmfx->map, STMFX_REG_SYS_CTRL, mask, 0); in stmfx_function_disable()
170 mutex_lock(&stmfx->lock); in stmfx_irq_bus_lock()
177 regmap_write(stmfx->map, STMFX_REG_IRQ_SRC_EN, stmfx->irq_src); in stmfx_irq_bus_sync_unlock()
179 mutex_unlock(&stmfx->lock); in stmfx_irq_bus_sync_unlock()
186 stmfx->irq_src &= ~BIT(data->hwirq % 8); in stmfx_irq_mask()
193 stmfx->irq_src |= BIT(data->hwirq % 8); in stmfx_irq_unmask()
197 .name = "stmfx-core",
211 ret = regmap_read(stmfx->map, STMFX_REG_IRQ_PENDING, &pending); in stmfx_irq_handler()
221 ret = regmap_write(stmfx->map, STMFX_REG_IRQ_ACK, ack); in stmfx_irq_handler()
228 handle_nested_irq(irq_find_mapping(stmfx->irq_domain, n)); in stmfx_irq_handler()
236 irq_set_chip_data(virq, d->host_data); in stmfx_irq_map()
261 irq_dispose_mapping(irq_find_mapping(stmfx->irq_domain, hwirq)); in stmfx_irq_exit()
263 irq_domain_remove(stmfx->irq_domain); in stmfx_irq_exit()
272 stmfx->irq_domain = irq_domain_add_simple(stmfx->dev->of_node, in stmfx_irq_init()
275 if (!stmfx->irq_domain) { in stmfx_irq_init()
276 dev_err(stmfx->dev, "Failed to create IRQ domain\n"); in stmfx_irq_init()
277 return -EINVAL; in stmfx_irq_init()
280 if (!of_property_read_bool(stmfx->dev->of_node, "drive-open-drain")) in stmfx_irq_init()
283 irqtrigger = irq_get_trigger_type(client->irq); in stmfx_irq_init()
288 ret = regmap_write(stmfx->map, STMFX_REG_IRQ_OUT_PIN, irqoutpin); in stmfx_irq_init()
292 ret = devm_request_threaded_irq(stmfx->dev, client->irq, in stmfx_irq_init()
299 stmfx->irq = client->irq; in stmfx_irq_init()
313 ret = regmap_write(stmfx->map, STMFX_REG_SYS_CTRL, in stmfx_chip_reset()
330 stmfx->vdd = devm_regulator_get_optional(&client->dev, "vdd"); in stmfx_chip_init()
331 ret = PTR_ERR_OR_ZERO(stmfx->vdd); in stmfx_chip_init()
333 if (ret == -ENODEV) in stmfx_chip_init()
334 stmfx->vdd = NULL; in stmfx_chip_init()
336 return dev_err_probe(&client->dev, ret, "Failed to get VDD regulator\n"); in stmfx_chip_init()
339 if (stmfx->vdd) { in stmfx_chip_init()
340 ret = regulator_enable(stmfx->vdd); in stmfx_chip_init()
342 dev_err(&client->dev, "VDD enable failed: %d\n", ret); in stmfx_chip_init()
347 ret = regmap_read(stmfx->map, STMFX_REG_CHIP_ID, &id); in stmfx_chip_init()
349 dev_err(&client->dev, "Error reading chip ID: %d\n", ret); in stmfx_chip_init()
355 * STMFX I2C address follows the 7-bit format (MSB), that's why in stmfx_chip_init()
356 * client->addr is shifted. in stmfx_chip_init()
360 *--------------------------------------------------------- in stmfx_chip_init()
364 if (FIELD_GET(STMFX_REG_CHIP_ID_MASK, ~id) != (client->addr << 1)) { in stmfx_chip_init()
365 dev_err(&client->dev, "Unknown chip ID: %#x\n", id); in stmfx_chip_init()
366 ret = -EINVAL; in stmfx_chip_init()
370 ret = regmap_bulk_read(stmfx->map, STMFX_REG_FW_VERSION_MSB, in stmfx_chip_init()
373 dev_err(&client->dev, "Error reading FW version: %d\n", ret); in stmfx_chip_init()
377 dev_info(&client->dev, "STMFX id: %#x, fw version: %x.%02x\n", in stmfx_chip_init()
382 dev_err(&client->dev, "Failed to reset chip: %d\n", ret); in stmfx_chip_init()
389 if (stmfx->vdd) in stmfx_chip_init()
390 return regulator_disable(stmfx->vdd); in stmfx_chip_init()
399 regmap_write(stmfx->map, STMFX_REG_IRQ_SRC_EN, 0); in stmfx_chip_exit()
400 regmap_write(stmfx->map, STMFX_REG_SYS_CTRL, 0); in stmfx_chip_exit()
402 if (stmfx->vdd) in stmfx_chip_exit()
403 return regulator_disable(stmfx->vdd); in stmfx_chip_exit()
411 struct device *dev = &client->dev; in stmfx_probe()
417 return -ENOMEM; in stmfx_probe()
421 stmfx->dev = dev; in stmfx_probe()
423 stmfx->map = devm_regmap_init_i2c(client, &stmfx_regmap_config); in stmfx_probe()
424 if (IS_ERR(stmfx->map)) { in stmfx_probe()
425 ret = PTR_ERR(stmfx->map); in stmfx_probe()
430 mutex_init(&stmfx->lock); in stmfx_probe()
434 if (ret == -ETIMEDOUT) in stmfx_probe()
435 return -EPROBE_DEFER; in stmfx_probe()
439 if (client->irq < 0) { in stmfx_probe()
440 dev_err(dev, "Failed to get IRQ: %d\n", client->irq); in stmfx_probe()
441 ret = client->irq; in stmfx_probe()
451 0, stmfx->irq_domain); in stmfx_probe()
478 ret = regmap_raw_read(stmfx->map, STMFX_REG_SYS_CTRL, in stmfx_suspend()
479 &stmfx->bkp_sysctrl, sizeof(stmfx->bkp_sysctrl)); in stmfx_suspend()
483 ret = regmap_raw_read(stmfx->map, STMFX_REG_IRQ_OUT_PIN, in stmfx_suspend()
484 &stmfx->bkp_irqoutpin, in stmfx_suspend()
485 sizeof(stmfx->bkp_irqoutpin)); in stmfx_suspend()
489 disable_irq(stmfx->irq); in stmfx_suspend()
491 if (stmfx->vdd) in stmfx_suspend()
492 return regulator_disable(stmfx->vdd); in stmfx_suspend()
502 if (stmfx->vdd) { in stmfx_resume()
503 ret = regulator_enable(stmfx->vdd); in stmfx_resume()
505 dev_err(stmfx->dev, in stmfx_resume()
506 "VDD enable failed: %d\n", ret); in stmfx_resume()
511 /* Reset STMFX - supply has been stopped during suspend */ in stmfx_resume()
514 dev_err(stmfx->dev, "Failed to reset chip: %d\n", ret); in stmfx_resume()
518 ret = regmap_raw_write(stmfx->map, STMFX_REG_SYS_CTRL, in stmfx_resume()
519 &stmfx->bkp_sysctrl, sizeof(stmfx->bkp_sysctrl)); in stmfx_resume()
523 ret = regmap_raw_write(stmfx->map, STMFX_REG_IRQ_OUT_PIN, in stmfx_resume()
524 &stmfx->bkp_irqoutpin, in stmfx_resume()
525 sizeof(stmfx->bkp_irqoutpin)); in stmfx_resume()
529 ret = regmap_raw_write(stmfx->map, STMFX_REG_IRQ_SRC_EN, in stmfx_resume()
530 &stmfx->irq_src, sizeof(stmfx->irq_src)); in stmfx_resume()
534 enable_irq(stmfx->irq); in stmfx_resume()
543 { .compatible = "st,stmfx-0300", },
550 .name = "stmfx-core",