Lines Matching +full:da9062 +full:- +full:rtc

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Core, IRQ and I2C device driver for DA9061 and DA9062 PMICs
4 * Copyright (C) 2015-2017 Dialog Semiconductor
17 #include <linux/mfd/da9062/core.h>
18 #include <linux/mfd/da9062/registers.h>
83 .name = "da9061-irq",
155 .name = "da9062-irq",
185 MFD_CELL_OF("da9061-core", da9061_core_resources, NULL, 0, 0,
187 MFD_CELL_OF("da9062-regulators", da9061_regulators_resources, NULL, 0, 0,
189 MFD_CELL_OF("da9061-watchdog", da9061_wdt_resources, NULL, 0, 0,
190 "dlg,da9061-watchdog"),
191 MFD_CELL_OF("da9061-thermal", da9061_thermal_resources, NULL, 0, 0,
192 "dlg,da9061-thermal"),
193 MFD_CELL_OF("da9061-onkey", da9061_onkey_resources, NULL, 0, 0,
194 "dlg,da9061-onkey"),
198 MFD_CELL_OF("da9061-core", NULL, NULL, 0, 0, NULL),
199 MFD_CELL_OF("da9062-regulators", NULL, NULL, 0, 0, NULL),
200 MFD_CELL_OF("da9061-watchdog", NULL, NULL, 0, 0, "dlg,da9061-watchdog"),
201 MFD_CELL_OF("da9061-thermal", NULL, NULL, 0, 0, "dlg,da9061-thermal"),
202 MFD_CELL_OF("da9061-onkey", NULL, NULL, 0, 0, "dlg,da9061-onkey"),
239 MFD_CELL_OF("da9062-core", da9062_core_resources, NULL, 0, 0,
241 MFD_CELL_OF("da9062-regulators", da9062_regulators_resources, NULL, 0, 0,
243 MFD_CELL_OF("da9062-watchdog", da9062_wdt_resources, NULL, 0, 0,
244 "dlg,da9062-watchdog"),
245 MFD_CELL_OF("da9062-thermal", da9062_thermal_resources, NULL, 0, 0,
246 "dlg,da9062-thermal"),
247 MFD_CELL_OF("da9062-rtc", da9062_rtc_resources, NULL, 0, 0,
248 "dlg,da9062-rtc"),
249 MFD_CELL_OF("da9062-onkey", da9062_onkey_resources, NULL, 0, 0,
250 "dlg,da9062-onkey"),
251 MFD_CELL_OF("da9062-gpio", da9062_gpio_resources, NULL, 0, 0,
252 "dlg,da9062-gpio"),
256 MFD_CELL_OF("da9062-core", NULL, NULL, 0, 0, NULL),
257 MFD_CELL_OF("da9062-regulators", NULL, NULL, 0, 0, NULL),
258 MFD_CELL_OF("da9062-watchdog", NULL, NULL, 0, 0, "dlg,da9062-watchdog"),
259 MFD_CELL_OF("da9062-thermal", NULL, NULL, 0, 0, "dlg,da9062-thermal"),
260 MFD_CELL_OF("da9062-rtc", NULL, NULL, 0, 0, "dlg,da9062-rtc"),
261 MFD_CELL_OF("da9062-onkey", NULL, NULL, 0, 0, "dlg,da9062-onkey"),
262 MFD_CELL_OF("da9062-gpio", NULL, NULL, 0, 0, "dlg,da9062-gpio"),
265 static int da9062_clear_fault_log(struct da9062 *chip) in da9062_clear_fault_log()
270 ret = regmap_read(chip->regmap, DA9062AA_FAULT_LOG, &fault_log); in da9062_clear_fault_log()
276 dev_dbg(chip->dev, "Fault log entry detected: TWD_ERROR\n"); in da9062_clear_fault_log()
278 dev_dbg(chip->dev, "Fault log entry detected: POR\n"); in da9062_clear_fault_log()
280 dev_dbg(chip->dev, "Fault log entry detected: VDD_FAULT\n"); in da9062_clear_fault_log()
282 dev_dbg(chip->dev, "Fault log entry detected: VDD_START\n"); in da9062_clear_fault_log()
284 dev_dbg(chip->dev, "Fault log entry detected: TEMP_CRIT\n"); in da9062_clear_fault_log()
286 dev_dbg(chip->dev, "Fault log entry detected: KEY_RESET\n"); in da9062_clear_fault_log()
288 dev_dbg(chip->dev, "Fault log entry detected: NSHUTDOWN\n"); in da9062_clear_fault_log()
290 dev_dbg(chip->dev, "Fault log entry detected: WAIT_SHUT\n"); in da9062_clear_fault_log()
292 ret = regmap_write(chip->regmap, DA9062AA_FAULT_LOG, in da9062_clear_fault_log()
299 static int da9062_get_device_type(struct da9062 *chip) in da9062_get_device_type()
305 ret = regmap_read(chip->regmap, DA9062AA_DEVICE_ID, &device_id); in da9062_get_device_type()
307 dev_err(chip->dev, "Cannot read chip ID.\n"); in da9062_get_device_type()
308 return -EIO; in da9062_get_device_type()
311 dev_err(chip->dev, "Invalid device ID: 0x%02x\n", device_id); in da9062_get_device_type()
312 return -ENODEV; in da9062_get_device_type()
315 ret = regmap_read(chip->regmap, DA9062AA_VARIANT_ID, &variant_id); in da9062_get_device_type()
317 dev_err(chip->dev, "Cannot read chip variant id.\n"); in da9062_get_device_type()
318 return -EIO; in da9062_get_device_type()
328 type = "DA9062"; in da9062_get_device_type()
335 dev_info(chip->dev, in da9062_get_device_type()
336 "Device detected (device-ID: 0x%02X, var-ID: 0x%02X, %s)\n", in da9062_get_device_type()
342 dev_err(chip->dev, in da9062_get_device_type()
344 return -ENODEV; in da9062_get_device_type()
350 static u32 da9062_configure_irq_type(struct da9062 *chip, int irq, u32 *trigger) in da9062_configure_irq_type()
356 dev_err(chip->dev, "Invalid IRQ: %d\n", irq); in da9062_configure_irq_type()
357 return -EINVAL; in da9062_configure_irq_type()
369 dev_warn(chip->dev, "Unsupported IRQ type: %d\n", *trigger); in da9062_configure_irq_type()
370 return -EINVAL; in da9062_configure_irq_type()
372 return regmap_update_bits(chip->regmap, DA9062AA_CONFIG_A, in da9062_configure_irq_type()
593 struct da9062 *chip; in da9062_i2c_probe()
602 chip = devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL); in da9062_i2c_probe()
604 return -ENOMEM; in da9062_i2c_probe()
606 chip->chip_type = (uintptr_t)i2c_get_match_data(i2c); in da9062_i2c_probe()
609 chip->dev = &i2c->dev; in da9062_i2c_probe()
612 switch (chip->chip_type) { in da9062_i2c_probe()
624 dev_err(chip->dev, "Unrecognised chip type\n"); in da9062_i2c_probe()
625 return -ENODEV; in da9062_i2c_probe()
628 chip->regmap = devm_regmap_init_i2c(i2c, config); in da9062_i2c_probe()
629 if (IS_ERR(chip->regmap)) { in da9062_i2c_probe()
630 ret = PTR_ERR(chip->regmap); in da9062_i2c_probe()
631 dev_err(chip->dev, "Failed to allocate register map: %d\n", in da9062_i2c_probe()
637 if (i2c_check_functionality(i2c->adapter, I2C_FUNC_I2C)) { in da9062_i2c_probe()
638 dev_info(chip->dev, "Entering I2C mode!\n"); in da9062_i2c_probe()
639 ret = regmap_clear_bits(chip->regmap, DA9062AA_CONFIG_J, in da9062_i2c_probe()
642 dev_err(chip->dev, "Failed to set Two-Wire Bus Mode.\n"); in da9062_i2c_probe()
649 dev_warn(chip->dev, "Cannot clear fault log\n"); in da9062_i2c_probe()
656 if (i2c->irq) { in da9062_i2c_probe()
657 if (chip->chip_type == COMPAT_TYPE_DA9061) { in da9062_i2c_probe()
667 ret = da9062_configure_irq_type(chip, i2c->irq, &trigger_type); in da9062_i2c_probe()
669 dev_err(chip->dev, "Failed to configure IRQ type\n"); in da9062_i2c_probe()
673 ret = regmap_add_irq_chip(chip->regmap, i2c->irq, in da9062_i2c_probe()
675 -1, irq_chip, &chip->regmap_irq); in da9062_i2c_probe()
677 dev_err(chip->dev, "Failed to request IRQ %d: %d\n", in da9062_i2c_probe()
678 i2c->irq, ret); in da9062_i2c_probe()
682 irq_base = regmap_irq_chip_get_base(chip->regmap_irq); in da9062_i2c_probe()
685 ret = mfd_add_devices(chip->dev, PLATFORM_DEVID_NONE, cell, in da9062_i2c_probe()
689 dev_err(chip->dev, "Cannot register child devices\n"); in da9062_i2c_probe()
690 if (i2c->irq) in da9062_i2c_probe()
691 regmap_del_irq_chip(i2c->irq, chip->regmap_irq); in da9062_i2c_probe()
700 struct da9062 *chip = i2c_get_clientdata(i2c); in da9062_i2c_remove()
702 mfd_remove_devices(chip->dev); in da9062_i2c_remove()
703 regmap_del_irq_chip(i2c->irq, chip->regmap_irq); in da9062_i2c_remove()
708 { .compatible = "dlg,da9062", .data = (void *)COMPAT_TYPE_DA9062 },
715 { "da9062", COMPAT_TYPE_DA9062 },
722 .name = "da9062",
732 MODULE_DESCRIPTION("Core device driver for Dialog DA9061 and DA9062");