18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Device access for Dialog DA9055 PMICs. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright(c) 2012 Dialog Semiconductor Ltd. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: David Dajun Chen <dchen@diasemi.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <linux/device.h> 128c2ecf20Sopenharmony_ci#include <linux/input.h> 138c2ecf20Sopenharmony_ci#include <linux/irq.h> 148c2ecf20Sopenharmony_ci#include <linux/mutex.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/mfd/core.h> 178c2ecf20Sopenharmony_ci#include <linux/mfd/da9055/core.h> 188c2ecf20Sopenharmony_ci#include <linux/mfd/da9055/pdata.h> 198c2ecf20Sopenharmony_ci#include <linux/mfd/da9055/reg.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define DA9055_IRQ_NONKEY_MASK 0x01 228c2ecf20Sopenharmony_ci#define DA9055_IRQ_ALM_MASK 0x02 238c2ecf20Sopenharmony_ci#define DA9055_IRQ_TICK_MASK 0x04 248c2ecf20Sopenharmony_ci#define DA9055_IRQ_ADC_MASK 0x08 258c2ecf20Sopenharmony_ci#define DA9055_IRQ_BUCK_ILIM_MASK 0x08 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistatic bool da9055_register_readable(struct device *dev, unsigned int reg) 288c2ecf20Sopenharmony_ci{ 298c2ecf20Sopenharmony_ci switch (reg) { 308c2ecf20Sopenharmony_ci case DA9055_REG_STATUS_A: 318c2ecf20Sopenharmony_ci case DA9055_REG_STATUS_B: 328c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_A: 338c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_B: 348c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_C: 358c2ecf20Sopenharmony_ci case DA9055_REG_IRQ_MASK_A: 368c2ecf20Sopenharmony_ci case DA9055_REG_IRQ_MASK_B: 378c2ecf20Sopenharmony_ci case DA9055_REG_IRQ_MASK_C: 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_A: 408c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_B: 418c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_C: 428c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_D: 438c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_E: 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci case DA9055_REG_ADC_MAN: 468c2ecf20Sopenharmony_ci case DA9055_REG_ADC_CONT: 478c2ecf20Sopenharmony_ci case DA9055_REG_VSYS_MON: 488c2ecf20Sopenharmony_ci case DA9055_REG_ADC_RES_L: 498c2ecf20Sopenharmony_ci case DA9055_REG_ADC_RES_H: 508c2ecf20Sopenharmony_ci case DA9055_REG_VSYS_RES: 518c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN1_RES: 528c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN2_RES: 538c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN3_RES: 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_S: 568c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_MI: 578c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_H: 588c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_D: 598c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_MO: 608c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_Y: 618c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_H: 628c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_D: 638c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_MI: 648c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_MO: 658c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_Y: 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci case DA9055_REG_GPIO0_1: 688c2ecf20Sopenharmony_ci case DA9055_REG_GPIO2: 698c2ecf20Sopenharmony_ci case DA9055_REG_GPIO_MODE0_2: 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci case DA9055_REG_BCORE_CONT: 728c2ecf20Sopenharmony_ci case DA9055_REG_BMEM_CONT: 738c2ecf20Sopenharmony_ci case DA9055_REG_LDO1_CONT: 748c2ecf20Sopenharmony_ci case DA9055_REG_LDO2_CONT: 758c2ecf20Sopenharmony_ci case DA9055_REG_LDO3_CONT: 768c2ecf20Sopenharmony_ci case DA9055_REG_LDO4_CONT: 778c2ecf20Sopenharmony_ci case DA9055_REG_LDO5_CONT: 788c2ecf20Sopenharmony_ci case DA9055_REG_LDO6_CONT: 798c2ecf20Sopenharmony_ci case DA9055_REG_BUCK_LIM: 808c2ecf20Sopenharmony_ci case DA9055_REG_BCORE_MODE: 818c2ecf20Sopenharmony_ci case DA9055_REG_VBCORE_A: 828c2ecf20Sopenharmony_ci case DA9055_REG_VBMEM_A: 838c2ecf20Sopenharmony_ci case DA9055_REG_VLDO1_A: 848c2ecf20Sopenharmony_ci case DA9055_REG_VLDO2_A: 858c2ecf20Sopenharmony_ci case DA9055_REG_VLDO3_A: 868c2ecf20Sopenharmony_ci case DA9055_REG_VLDO4_A: 878c2ecf20Sopenharmony_ci case DA9055_REG_VLDO5_A: 888c2ecf20Sopenharmony_ci case DA9055_REG_VLDO6_A: 898c2ecf20Sopenharmony_ci case DA9055_REG_VBCORE_B: 908c2ecf20Sopenharmony_ci case DA9055_REG_VBMEM_B: 918c2ecf20Sopenharmony_ci case DA9055_REG_VLDO1_B: 928c2ecf20Sopenharmony_ci case DA9055_REG_VLDO2_B: 938c2ecf20Sopenharmony_ci case DA9055_REG_VLDO3_B: 948c2ecf20Sopenharmony_ci case DA9055_REG_VLDO4_B: 958c2ecf20Sopenharmony_ci case DA9055_REG_VLDO5_B: 968c2ecf20Sopenharmony_ci case DA9055_REG_VLDO6_B: 978c2ecf20Sopenharmony_ci return true; 988c2ecf20Sopenharmony_ci default: 998c2ecf20Sopenharmony_ci return false; 1008c2ecf20Sopenharmony_ci } 1018c2ecf20Sopenharmony_ci} 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_cistatic bool da9055_register_writeable(struct device *dev, unsigned int reg) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci switch (reg) { 1068c2ecf20Sopenharmony_ci case DA9055_REG_STATUS_A: 1078c2ecf20Sopenharmony_ci case DA9055_REG_STATUS_B: 1088c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_A: 1098c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_B: 1108c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_C: 1118c2ecf20Sopenharmony_ci case DA9055_REG_IRQ_MASK_A: 1128c2ecf20Sopenharmony_ci case DA9055_REG_IRQ_MASK_B: 1138c2ecf20Sopenharmony_ci case DA9055_REG_IRQ_MASK_C: 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_A: 1168c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_B: 1178c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_C: 1188c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_D: 1198c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_E: 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci case DA9055_REG_ADC_MAN: 1228c2ecf20Sopenharmony_ci case DA9055_REG_ADC_CONT: 1238c2ecf20Sopenharmony_ci case DA9055_REG_VSYS_MON: 1248c2ecf20Sopenharmony_ci case DA9055_REG_ADC_RES_L: 1258c2ecf20Sopenharmony_ci case DA9055_REG_ADC_RES_H: 1268c2ecf20Sopenharmony_ci case DA9055_REG_VSYS_RES: 1278c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN1_RES: 1288c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN2_RES: 1298c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN3_RES: 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_S: 1328c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_MI: 1338c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_H: 1348c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_D: 1358c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_MO: 1368c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_Y: 1378c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_H: 1388c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_D: 1398c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_MI: 1408c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_MO: 1418c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_Y: 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci case DA9055_REG_GPIO0_1: 1448c2ecf20Sopenharmony_ci case DA9055_REG_GPIO2: 1458c2ecf20Sopenharmony_ci case DA9055_REG_GPIO_MODE0_2: 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci case DA9055_REG_BCORE_CONT: 1488c2ecf20Sopenharmony_ci case DA9055_REG_BMEM_CONT: 1498c2ecf20Sopenharmony_ci case DA9055_REG_LDO1_CONT: 1508c2ecf20Sopenharmony_ci case DA9055_REG_LDO2_CONT: 1518c2ecf20Sopenharmony_ci case DA9055_REG_LDO3_CONT: 1528c2ecf20Sopenharmony_ci case DA9055_REG_LDO4_CONT: 1538c2ecf20Sopenharmony_ci case DA9055_REG_LDO5_CONT: 1548c2ecf20Sopenharmony_ci case DA9055_REG_LDO6_CONT: 1558c2ecf20Sopenharmony_ci case DA9055_REG_BUCK_LIM: 1568c2ecf20Sopenharmony_ci case DA9055_REG_BCORE_MODE: 1578c2ecf20Sopenharmony_ci case DA9055_REG_VBCORE_A: 1588c2ecf20Sopenharmony_ci case DA9055_REG_VBMEM_A: 1598c2ecf20Sopenharmony_ci case DA9055_REG_VLDO1_A: 1608c2ecf20Sopenharmony_ci case DA9055_REG_VLDO2_A: 1618c2ecf20Sopenharmony_ci case DA9055_REG_VLDO3_A: 1628c2ecf20Sopenharmony_ci case DA9055_REG_VLDO4_A: 1638c2ecf20Sopenharmony_ci case DA9055_REG_VLDO5_A: 1648c2ecf20Sopenharmony_ci case DA9055_REG_VLDO6_A: 1658c2ecf20Sopenharmony_ci case DA9055_REG_VBCORE_B: 1668c2ecf20Sopenharmony_ci case DA9055_REG_VBMEM_B: 1678c2ecf20Sopenharmony_ci case DA9055_REG_VLDO1_B: 1688c2ecf20Sopenharmony_ci case DA9055_REG_VLDO2_B: 1698c2ecf20Sopenharmony_ci case DA9055_REG_VLDO3_B: 1708c2ecf20Sopenharmony_ci case DA9055_REG_VLDO4_B: 1718c2ecf20Sopenharmony_ci case DA9055_REG_VLDO5_B: 1728c2ecf20Sopenharmony_ci case DA9055_REG_VLDO6_B: 1738c2ecf20Sopenharmony_ci return true; 1748c2ecf20Sopenharmony_ci default: 1758c2ecf20Sopenharmony_ci return false; 1768c2ecf20Sopenharmony_ci } 1778c2ecf20Sopenharmony_ci} 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic bool da9055_register_volatile(struct device *dev, unsigned int reg) 1808c2ecf20Sopenharmony_ci{ 1818c2ecf20Sopenharmony_ci switch (reg) { 1828c2ecf20Sopenharmony_ci case DA9055_REG_STATUS_A: 1838c2ecf20Sopenharmony_ci case DA9055_REG_STATUS_B: 1848c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_A: 1858c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_B: 1868c2ecf20Sopenharmony_ci case DA9055_REG_EVENT_C: 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_A: 1898c2ecf20Sopenharmony_ci case DA9055_REG_CONTROL_E: 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci case DA9055_REG_ADC_MAN: 1928c2ecf20Sopenharmony_ci case DA9055_REG_ADC_RES_L: 1938c2ecf20Sopenharmony_ci case DA9055_REG_ADC_RES_H: 1948c2ecf20Sopenharmony_ci case DA9055_REG_VSYS_RES: 1958c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN1_RES: 1968c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN2_RES: 1978c2ecf20Sopenharmony_ci case DA9055_REG_ADCIN3_RES: 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_S: 2008c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_MI: 2018c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_H: 2028c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_D: 2038c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_MO: 2048c2ecf20Sopenharmony_ci case DA9055_REG_COUNT_Y: 2058c2ecf20Sopenharmony_ci case DA9055_REG_ALARM_MI: 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci case DA9055_REG_BCORE_CONT: 2088c2ecf20Sopenharmony_ci case DA9055_REG_BMEM_CONT: 2098c2ecf20Sopenharmony_ci case DA9055_REG_LDO1_CONT: 2108c2ecf20Sopenharmony_ci case DA9055_REG_LDO2_CONT: 2118c2ecf20Sopenharmony_ci case DA9055_REG_LDO3_CONT: 2128c2ecf20Sopenharmony_ci case DA9055_REG_LDO4_CONT: 2138c2ecf20Sopenharmony_ci case DA9055_REG_LDO5_CONT: 2148c2ecf20Sopenharmony_ci case DA9055_REG_LDO6_CONT: 2158c2ecf20Sopenharmony_ci return true; 2168c2ecf20Sopenharmony_ci default: 2178c2ecf20Sopenharmony_ci return false; 2188c2ecf20Sopenharmony_ci } 2198c2ecf20Sopenharmony_ci} 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_cistatic const struct regmap_irq da9055_irqs[] = { 2228c2ecf20Sopenharmony_ci [DA9055_IRQ_NONKEY] = { 2238c2ecf20Sopenharmony_ci .reg_offset = 0, 2248c2ecf20Sopenharmony_ci .mask = DA9055_IRQ_NONKEY_MASK, 2258c2ecf20Sopenharmony_ci }, 2268c2ecf20Sopenharmony_ci [DA9055_IRQ_ALARM] = { 2278c2ecf20Sopenharmony_ci .reg_offset = 0, 2288c2ecf20Sopenharmony_ci .mask = DA9055_IRQ_ALM_MASK, 2298c2ecf20Sopenharmony_ci }, 2308c2ecf20Sopenharmony_ci [DA9055_IRQ_TICK] = { 2318c2ecf20Sopenharmony_ci .reg_offset = 0, 2328c2ecf20Sopenharmony_ci .mask = DA9055_IRQ_TICK_MASK, 2338c2ecf20Sopenharmony_ci }, 2348c2ecf20Sopenharmony_ci [DA9055_IRQ_HWMON] = { 2358c2ecf20Sopenharmony_ci .reg_offset = 0, 2368c2ecf20Sopenharmony_ci .mask = DA9055_IRQ_ADC_MASK, 2378c2ecf20Sopenharmony_ci }, 2388c2ecf20Sopenharmony_ci [DA9055_IRQ_REGULATOR] = { 2398c2ecf20Sopenharmony_ci .reg_offset = 1, 2408c2ecf20Sopenharmony_ci .mask = DA9055_IRQ_BUCK_ILIM_MASK, 2418c2ecf20Sopenharmony_ci }, 2428c2ecf20Sopenharmony_ci}; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ciconst struct regmap_config da9055_regmap_config = { 2458c2ecf20Sopenharmony_ci .reg_bits = 8, 2468c2ecf20Sopenharmony_ci .val_bits = 8, 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci .max_register = DA9055_MAX_REGISTER_CNT, 2518c2ecf20Sopenharmony_ci .readable_reg = da9055_register_readable, 2528c2ecf20Sopenharmony_ci .writeable_reg = da9055_register_writeable, 2538c2ecf20Sopenharmony_ci .volatile_reg = da9055_register_volatile, 2548c2ecf20Sopenharmony_ci}; 2558c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(da9055_regmap_config); 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_cistatic struct resource da9055_onkey_resource = { 2588c2ecf20Sopenharmony_ci .name = "ONKEY", 2598c2ecf20Sopenharmony_ci .start = DA9055_IRQ_NONKEY, 2608c2ecf20Sopenharmony_ci .end = DA9055_IRQ_NONKEY, 2618c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 2628c2ecf20Sopenharmony_ci}; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic struct resource da9055_rtc_resource[] = { 2658c2ecf20Sopenharmony_ci { 2668c2ecf20Sopenharmony_ci .name = "ALM", 2678c2ecf20Sopenharmony_ci .start = DA9055_IRQ_ALARM, 2688c2ecf20Sopenharmony_ci .end = DA9055_IRQ_ALARM, 2698c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 2708c2ecf20Sopenharmony_ci }, 2718c2ecf20Sopenharmony_ci { 2728c2ecf20Sopenharmony_ci .name = "TICK", 2738c2ecf20Sopenharmony_ci .start = DA9055_IRQ_TICK, 2748c2ecf20Sopenharmony_ci .end = DA9055_IRQ_TICK, 2758c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 2768c2ecf20Sopenharmony_ci }, 2778c2ecf20Sopenharmony_ci}; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_cistatic struct resource da9055_hwmon_resource = { 2808c2ecf20Sopenharmony_ci .name = "HWMON", 2818c2ecf20Sopenharmony_ci .start = DA9055_IRQ_HWMON, 2828c2ecf20Sopenharmony_ci .end = DA9055_IRQ_HWMON, 2838c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 2848c2ecf20Sopenharmony_ci}; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_cistatic struct resource da9055_ld05_6_resource = { 2878c2ecf20Sopenharmony_ci .name = "REGULATOR", 2888c2ecf20Sopenharmony_ci .start = DA9055_IRQ_REGULATOR, 2898c2ecf20Sopenharmony_ci .end = DA9055_IRQ_REGULATOR, 2908c2ecf20Sopenharmony_ci .flags = IORESOURCE_IRQ, 2918c2ecf20Sopenharmony_ci}; 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_cistatic const struct mfd_cell da9055_devs[] = { 2948c2ecf20Sopenharmony_ci { 2958c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-gpio", 2968c2ecf20Sopenharmony_ci .name = "da9055-gpio", 2978c2ecf20Sopenharmony_ci }, 2988c2ecf20Sopenharmony_ci { 2998c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3008c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3018c2ecf20Sopenharmony_ci .id = 1, 3028c2ecf20Sopenharmony_ci }, 3038c2ecf20Sopenharmony_ci { 3048c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3058c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3068c2ecf20Sopenharmony_ci .id = 2, 3078c2ecf20Sopenharmony_ci }, 3088c2ecf20Sopenharmony_ci { 3098c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3108c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3118c2ecf20Sopenharmony_ci .id = 3, 3128c2ecf20Sopenharmony_ci }, 3138c2ecf20Sopenharmony_ci { 3148c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3158c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3168c2ecf20Sopenharmony_ci .id = 4, 3178c2ecf20Sopenharmony_ci }, 3188c2ecf20Sopenharmony_ci { 3198c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3208c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3218c2ecf20Sopenharmony_ci .id = 5, 3228c2ecf20Sopenharmony_ci }, 3238c2ecf20Sopenharmony_ci { 3248c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3258c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3268c2ecf20Sopenharmony_ci .id = 6, 3278c2ecf20Sopenharmony_ci }, 3288c2ecf20Sopenharmony_ci { 3298c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3308c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3318c2ecf20Sopenharmony_ci .id = 7, 3328c2ecf20Sopenharmony_ci .resources = &da9055_ld05_6_resource, 3338c2ecf20Sopenharmony_ci .num_resources = 1, 3348c2ecf20Sopenharmony_ci }, 3358c2ecf20Sopenharmony_ci { 3368c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-regulator", 3378c2ecf20Sopenharmony_ci .name = "da9055-regulator", 3388c2ecf20Sopenharmony_ci .resources = &da9055_ld05_6_resource, 3398c2ecf20Sopenharmony_ci .num_resources = 1, 3408c2ecf20Sopenharmony_ci .id = 8, 3418c2ecf20Sopenharmony_ci }, 3428c2ecf20Sopenharmony_ci { 3438c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-onkey", 3448c2ecf20Sopenharmony_ci .name = "da9055-onkey", 3458c2ecf20Sopenharmony_ci .resources = &da9055_onkey_resource, 3468c2ecf20Sopenharmony_ci .num_resources = 1, 3478c2ecf20Sopenharmony_ci }, 3488c2ecf20Sopenharmony_ci { 3498c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-rtc", 3508c2ecf20Sopenharmony_ci .name = "da9055-rtc", 3518c2ecf20Sopenharmony_ci .resources = da9055_rtc_resource, 3528c2ecf20Sopenharmony_ci .num_resources = ARRAY_SIZE(da9055_rtc_resource), 3538c2ecf20Sopenharmony_ci }, 3548c2ecf20Sopenharmony_ci { 3558c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-hwmon", 3568c2ecf20Sopenharmony_ci .name = "da9055-hwmon", 3578c2ecf20Sopenharmony_ci .resources = &da9055_hwmon_resource, 3588c2ecf20Sopenharmony_ci .num_resources = 1, 3598c2ecf20Sopenharmony_ci }, 3608c2ecf20Sopenharmony_ci { 3618c2ecf20Sopenharmony_ci .of_compatible = "dlg,da9055-watchdog", 3628c2ecf20Sopenharmony_ci .name = "da9055-watchdog", 3638c2ecf20Sopenharmony_ci }, 3648c2ecf20Sopenharmony_ci}; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_cistatic const struct regmap_irq_chip da9055_regmap_irq_chip = { 3678c2ecf20Sopenharmony_ci .name = "da9055_irq", 3688c2ecf20Sopenharmony_ci .status_base = DA9055_REG_EVENT_A, 3698c2ecf20Sopenharmony_ci .mask_base = DA9055_REG_IRQ_MASK_A, 3708c2ecf20Sopenharmony_ci .ack_base = DA9055_REG_EVENT_A, 3718c2ecf20Sopenharmony_ci .num_regs = 3, 3728c2ecf20Sopenharmony_ci .irqs = da9055_irqs, 3738c2ecf20Sopenharmony_ci .num_irqs = ARRAY_SIZE(da9055_irqs), 3748c2ecf20Sopenharmony_ci}; 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ciint da9055_device_init(struct da9055 *da9055) 3778c2ecf20Sopenharmony_ci{ 3788c2ecf20Sopenharmony_ci struct da9055_pdata *pdata = dev_get_platdata(da9055->dev); 3798c2ecf20Sopenharmony_ci int ret; 3808c2ecf20Sopenharmony_ci uint8_t clear_events[3] = {0xFF, 0xFF, 0xFF}; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci if (pdata && pdata->init != NULL) 3838c2ecf20Sopenharmony_ci pdata->init(da9055); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci if (!pdata || !pdata->irq_base) 3868c2ecf20Sopenharmony_ci da9055->irq_base = -1; 3878c2ecf20Sopenharmony_ci else 3888c2ecf20Sopenharmony_ci da9055->irq_base = pdata->irq_base; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci ret = da9055_group_write(da9055, DA9055_REG_EVENT_A, 3, clear_events); 3918c2ecf20Sopenharmony_ci if (ret < 0) 3928c2ecf20Sopenharmony_ci return ret; 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci ret = regmap_add_irq_chip(da9055->regmap, da9055->chip_irq, 3958c2ecf20Sopenharmony_ci IRQF_TRIGGER_LOW | IRQF_ONESHOT, 3968c2ecf20Sopenharmony_ci da9055->irq_base, &da9055_regmap_irq_chip, 3978c2ecf20Sopenharmony_ci &da9055->irq_data); 3988c2ecf20Sopenharmony_ci if (ret < 0) 3998c2ecf20Sopenharmony_ci return ret; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci da9055->irq_base = regmap_irq_chip_get_base(da9055->irq_data); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci ret = mfd_add_devices(da9055->dev, -1, 4048c2ecf20Sopenharmony_ci da9055_devs, ARRAY_SIZE(da9055_devs), 4058c2ecf20Sopenharmony_ci NULL, da9055->irq_base, NULL); 4068c2ecf20Sopenharmony_ci if (ret) 4078c2ecf20Sopenharmony_ci goto err; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci return 0; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_cierr: 4128c2ecf20Sopenharmony_ci mfd_remove_devices(da9055->dev); 4138c2ecf20Sopenharmony_ci return ret; 4148c2ecf20Sopenharmony_ci} 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_civoid da9055_device_exit(struct da9055 *da9055) 4178c2ecf20Sopenharmony_ci{ 4188c2ecf20Sopenharmony_ci regmap_del_irq_chip(da9055->chip_irq, da9055->irq_data); 4198c2ecf20Sopenharmony_ci mfd_remove_devices(da9055->dev); 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Core support for the DA9055 PMIC"); 4238c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 4248c2ecf20Sopenharmony_ciMODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); 425