18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * twl-regulator.c -- support regulators in twl4030/twl6030 family chips 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2008 David Brownell 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/module.h> 98c2ecf20Sopenharmony_ci#include <linux/string.h> 108c2ecf20Sopenharmony_ci#include <linux/slab.h> 118c2ecf20Sopenharmony_ci#include <linux/init.h> 128c2ecf20Sopenharmony_ci#include <linux/err.h> 138c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 148c2ecf20Sopenharmony_ci#include <linux/of.h> 158c2ecf20Sopenharmony_ci#include <linux/of_device.h> 168c2ecf20Sopenharmony_ci#include <linux/regulator/driver.h> 178c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h> 188c2ecf20Sopenharmony_ci#include <linux/regulator/of_regulator.h> 198c2ecf20Sopenharmony_ci#include <linux/mfd/twl.h> 208c2ecf20Sopenharmony_ci#include <linux/delay.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * The TWL4030/TW5030/TPS659x0 family chips include power management, a 248c2ecf20Sopenharmony_ci * USB OTG transceiver, an RTC, ADC, PWM, and lots more. Some versions 258c2ecf20Sopenharmony_ci * include an audio codec, battery charger, and more voltage regulators. 268c2ecf20Sopenharmony_ci * These chips are often used in OMAP-based systems. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * This driver implements software-based resource control for various 298c2ecf20Sopenharmony_ci * voltage regulators. This is usually augmented with state machine 308c2ecf20Sopenharmony_ci * based control. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct twlreg_info { 348c2ecf20Sopenharmony_ci /* start of regulator's PM_RECEIVER control register bank */ 358c2ecf20Sopenharmony_ci u8 base; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci /* twl resource ID, for resource control state machine */ 388c2ecf20Sopenharmony_ci u8 id; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci /* voltage in mV = table[VSEL]; table_len must be a power-of-two */ 418c2ecf20Sopenharmony_ci u8 table_len; 428c2ecf20Sopenharmony_ci const u16 *table; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci /* State REMAP default configuration */ 458c2ecf20Sopenharmony_ci u8 remap; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci /* used by regulator core */ 488c2ecf20Sopenharmony_ci struct regulator_desc desc; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci /* chip specific features */ 518c2ecf20Sopenharmony_ci unsigned long features; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci /* data passed from board for external get/set voltage */ 548c2ecf20Sopenharmony_ci void *data; 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* LDO control registers ... offset is from the base of its register bank. 598c2ecf20Sopenharmony_ci * The first three registers of all power resource banks help hardware to 608c2ecf20Sopenharmony_ci * manage the various resource groups. 618c2ecf20Sopenharmony_ci */ 628c2ecf20Sopenharmony_ci/* Common offset in TWL4030/6030 */ 638c2ecf20Sopenharmony_ci#define VREG_GRP 0 648c2ecf20Sopenharmony_ci/* TWL4030 register offsets */ 658c2ecf20Sopenharmony_ci#define VREG_TYPE 1 668c2ecf20Sopenharmony_ci#define VREG_REMAP 2 678c2ecf20Sopenharmony_ci#define VREG_DEDICATED 3 /* LDO control */ 688c2ecf20Sopenharmony_ci#define VREG_VOLTAGE_SMPS_4030 9 698c2ecf20Sopenharmony_ci/* TWL6030 register offsets */ 708c2ecf20Sopenharmony_ci#define VREG_TRANS 1 718c2ecf20Sopenharmony_ci#define VREG_STATE 2 728c2ecf20Sopenharmony_ci#define VREG_VOLTAGE 3 738c2ecf20Sopenharmony_ci#define VREG_VOLTAGE_SMPS 4 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic inline int 768c2ecf20Sopenharmony_citwlreg_read(struct twlreg_info *info, unsigned slave_subgp, unsigned offset) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci u8 value; 798c2ecf20Sopenharmony_ci int status; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci status = twl_i2c_read_u8(slave_subgp, 828c2ecf20Sopenharmony_ci &value, info->base + offset); 838c2ecf20Sopenharmony_ci return (status < 0) ? status : value; 848c2ecf20Sopenharmony_ci} 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic inline int 878c2ecf20Sopenharmony_citwlreg_write(struct twlreg_info *info, unsigned slave_subgp, unsigned offset, 888c2ecf20Sopenharmony_ci u8 value) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci return twl_i2c_write_u8(slave_subgp, 918c2ecf20Sopenharmony_ci value, info->base + offset); 928c2ecf20Sopenharmony_ci} 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* generic power resource operations, which work on all regulators */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_cistatic int twlreg_grp(struct regulator_dev *rdev) 998c2ecf20Sopenharmony_ci{ 1008c2ecf20Sopenharmony_ci return twlreg_read(rdev_get_drvdata(rdev), TWL_MODULE_PM_RECEIVER, 1018c2ecf20Sopenharmony_ci VREG_GRP); 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* 1058c2ecf20Sopenharmony_ci * Enable/disable regulators by joining/leaving the P1 (processor) group. 1068c2ecf20Sopenharmony_ci * We assume nobody else is updating the DEV_GRP registers. 1078c2ecf20Sopenharmony_ci */ 1088c2ecf20Sopenharmony_ci/* definition for 4030 family */ 1098c2ecf20Sopenharmony_ci#define P3_GRP_4030 BIT(7) /* "peripherals" */ 1108c2ecf20Sopenharmony_ci#define P2_GRP_4030 BIT(6) /* secondary processor, modem, etc */ 1118c2ecf20Sopenharmony_ci#define P1_GRP_4030 BIT(5) /* CPU/Linux */ 1128c2ecf20Sopenharmony_ci/* definition for 6030 family */ 1138c2ecf20Sopenharmony_ci#define P3_GRP_6030 BIT(2) /* secondary processor, modem, etc */ 1148c2ecf20Sopenharmony_ci#define P2_GRP_6030 BIT(1) /* "peripherals" */ 1158c2ecf20Sopenharmony_ci#define P1_GRP_6030 BIT(0) /* CPU/Linux */ 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistatic int twl4030reg_is_enabled(struct regulator_dev *rdev) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci int state = twlreg_grp(rdev); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci if (state < 0) 1228c2ecf20Sopenharmony_ci return state; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci return state & P1_GRP_4030; 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci#define PB_I2C_BUSY BIT(0) 1288c2ecf20Sopenharmony_ci#define PB_I2C_BWEN BIT(1) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* Wait until buffer empty/ready to send a word on power bus. */ 1318c2ecf20Sopenharmony_cistatic int twl4030_wait_pb_ready(void) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci int ret; 1358c2ecf20Sopenharmony_ci int timeout = 10; 1368c2ecf20Sopenharmony_ci u8 val; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci do { 1398c2ecf20Sopenharmony_ci ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, 1408c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PB_CFG); 1418c2ecf20Sopenharmony_ci if (ret < 0) 1428c2ecf20Sopenharmony_ci return ret; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci if (!(val & PB_I2C_BUSY)) 1458c2ecf20Sopenharmony_ci return 0; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci mdelay(1); 1488c2ecf20Sopenharmony_ci timeout--; 1498c2ecf20Sopenharmony_ci } while (timeout); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci return -ETIMEDOUT; 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci/* Send a word over the powerbus */ 1558c2ecf20Sopenharmony_cistatic int twl4030_send_pb_msg(unsigned msg) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci u8 val; 1588c2ecf20Sopenharmony_ci int ret; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci /* save powerbus configuration */ 1618c2ecf20Sopenharmony_ci ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, 1628c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PB_CFG); 1638c2ecf20Sopenharmony_ci if (ret < 0) 1648c2ecf20Sopenharmony_ci return ret; 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci /* Enable i2c access to powerbus */ 1678c2ecf20Sopenharmony_ci ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val | PB_I2C_BWEN, 1688c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PB_CFG); 1698c2ecf20Sopenharmony_ci if (ret < 0) 1708c2ecf20Sopenharmony_ci return ret; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci ret = twl4030_wait_pb_ready(); 1738c2ecf20Sopenharmony_ci if (ret < 0) 1748c2ecf20Sopenharmony_ci return ret; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg >> 8, 1778c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PB_WORD_MSB); 1788c2ecf20Sopenharmony_ci if (ret < 0) 1798c2ecf20Sopenharmony_ci return ret; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg & 0xff, 1828c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PB_WORD_LSB); 1838c2ecf20Sopenharmony_ci if (ret < 0) 1848c2ecf20Sopenharmony_ci return ret; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci ret = twl4030_wait_pb_ready(); 1878c2ecf20Sopenharmony_ci if (ret < 0) 1888c2ecf20Sopenharmony_ci return ret; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci /* Restore powerbus configuration */ 1918c2ecf20Sopenharmony_ci return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val, 1928c2ecf20Sopenharmony_ci TWL4030_PM_MASTER_PB_CFG); 1938c2ecf20Sopenharmony_ci} 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistatic int twl4030reg_enable(struct regulator_dev *rdev) 1968c2ecf20Sopenharmony_ci{ 1978c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 1988c2ecf20Sopenharmony_ci int grp; 1998c2ecf20Sopenharmony_ci int ret; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci grp = twlreg_grp(rdev); 2028c2ecf20Sopenharmony_ci if (grp < 0) 2038c2ecf20Sopenharmony_ci return grp; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci grp |= P1_GRP_4030; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci return ret; 2108c2ecf20Sopenharmony_ci} 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistatic int twl4030reg_disable(struct regulator_dev *rdev) 2138c2ecf20Sopenharmony_ci{ 2148c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 2158c2ecf20Sopenharmony_ci int grp; 2168c2ecf20Sopenharmony_ci int ret; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci grp = twlreg_grp(rdev); 2198c2ecf20Sopenharmony_ci if (grp < 0) 2208c2ecf20Sopenharmony_ci return grp; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci grp &= ~(P1_GRP_4030 | P2_GRP_4030 | P3_GRP_4030); 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci return ret; 2278c2ecf20Sopenharmony_ci} 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_cistatic int twl4030reg_get_status(struct regulator_dev *rdev) 2308c2ecf20Sopenharmony_ci{ 2318c2ecf20Sopenharmony_ci int state = twlreg_grp(rdev); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci if (state < 0) 2348c2ecf20Sopenharmony_ci return state; 2358c2ecf20Sopenharmony_ci state &= 0x0f; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci /* assume state != WARM_RESET; we'd not be running... */ 2388c2ecf20Sopenharmony_ci if (!state) 2398c2ecf20Sopenharmony_ci return REGULATOR_STATUS_OFF; 2408c2ecf20Sopenharmony_ci return (state & BIT(3)) 2418c2ecf20Sopenharmony_ci ? REGULATOR_STATUS_NORMAL 2428c2ecf20Sopenharmony_ci : REGULATOR_STATUS_STANDBY; 2438c2ecf20Sopenharmony_ci} 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_cistatic int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) 2468c2ecf20Sopenharmony_ci{ 2478c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 2488c2ecf20Sopenharmony_ci unsigned message; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci /* We can only set the mode through state machine commands... */ 2518c2ecf20Sopenharmony_ci switch (mode) { 2528c2ecf20Sopenharmony_ci case REGULATOR_MODE_NORMAL: 2538c2ecf20Sopenharmony_ci message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); 2548c2ecf20Sopenharmony_ci break; 2558c2ecf20Sopenharmony_ci case REGULATOR_MODE_STANDBY: 2568c2ecf20Sopenharmony_ci message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_SLEEP); 2578c2ecf20Sopenharmony_ci break; 2588c2ecf20Sopenharmony_ci default: 2598c2ecf20Sopenharmony_ci return -EINVAL; 2608c2ecf20Sopenharmony_ci } 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci return twl4030_send_pb_msg(message); 2638c2ecf20Sopenharmony_ci} 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_cistatic inline unsigned int twl4030reg_map_mode(unsigned int mode) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci switch (mode) { 2688c2ecf20Sopenharmony_ci case RES_STATE_ACTIVE: 2698c2ecf20Sopenharmony_ci return REGULATOR_MODE_NORMAL; 2708c2ecf20Sopenharmony_ci case RES_STATE_SLEEP: 2718c2ecf20Sopenharmony_ci return REGULATOR_MODE_STANDBY; 2728c2ecf20Sopenharmony_ci default: 2738c2ecf20Sopenharmony_ci return REGULATOR_MODE_INVALID; 2748c2ecf20Sopenharmony_ci } 2758c2ecf20Sopenharmony_ci} 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci/* 2808c2ecf20Sopenharmony_ci * Support for adjustable-voltage LDOs uses a four bit (or less) voltage 2818c2ecf20Sopenharmony_ci * select field in its control register. We use tables indexed by VSEL 2828c2ecf20Sopenharmony_ci * to record voltages in milliVolts. (Accuracy is about three percent.) 2838c2ecf20Sopenharmony_ci * 2848c2ecf20Sopenharmony_ci * Note that VSEL values for VAUX2 changed in twl5030 and newer silicon; 2858c2ecf20Sopenharmony_ci * currently handled by listing two slightly different VAUX2 regulators, 2868c2ecf20Sopenharmony_ci * only one of which will be configured. 2878c2ecf20Sopenharmony_ci * 2888c2ecf20Sopenharmony_ci * VSEL values documented as "TI cannot support these values" are flagged 2898c2ecf20Sopenharmony_ci * in these tables as UNSUP() values; we normally won't assign them. 2908c2ecf20Sopenharmony_ci * 2918c2ecf20Sopenharmony_ci * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. 2928c2ecf20Sopenharmony_ci * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. 2938c2ecf20Sopenharmony_ci */ 2948c2ecf20Sopenharmony_ci#define UNSUP_MASK 0x8000 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci#define UNSUP(x) (UNSUP_MASK | (x)) 2978c2ecf20Sopenharmony_ci#define IS_UNSUP(info, x) \ 2988c2ecf20Sopenharmony_ci ((UNSUP_MASK & (x)) && \ 2998c2ecf20Sopenharmony_ci !((info)->features & TWL4030_ALLOW_UNSUPPORTED)) 3008c2ecf20Sopenharmony_ci#define LDO_MV(x) (~UNSUP_MASK & (x)) 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_cistatic const u16 VAUX1_VSEL_table[] = { 3048c2ecf20Sopenharmony_ci UNSUP(1500), UNSUP(1800), 2500, 2800, 3058c2ecf20Sopenharmony_ci 3000, 3000, 3000, 3000, 3068c2ecf20Sopenharmony_ci}; 3078c2ecf20Sopenharmony_cistatic const u16 VAUX2_4030_VSEL_table[] = { 3088c2ecf20Sopenharmony_ci UNSUP(1000), UNSUP(1000), UNSUP(1200), 1300, 3098c2ecf20Sopenharmony_ci 1500, 1800, UNSUP(1850), 2500, 3108c2ecf20Sopenharmony_ci UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), 3118c2ecf20Sopenharmony_ci UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 3128c2ecf20Sopenharmony_ci}; 3138c2ecf20Sopenharmony_cistatic const u16 VAUX2_VSEL_table[] = { 3148c2ecf20Sopenharmony_ci 1700, 1700, 1900, 1300, 3158c2ecf20Sopenharmony_ci 1500, 1800, 2000, 2500, 3168c2ecf20Sopenharmony_ci 2100, 2800, 2200, 2300, 3178c2ecf20Sopenharmony_ci 2400, 2400, 2400, 2400, 3188c2ecf20Sopenharmony_ci}; 3198c2ecf20Sopenharmony_cistatic const u16 VAUX3_VSEL_table[] = { 3208c2ecf20Sopenharmony_ci 1500, 1800, 2500, 2800, 3218c2ecf20Sopenharmony_ci 3000, 3000, 3000, 3000, 3228c2ecf20Sopenharmony_ci}; 3238c2ecf20Sopenharmony_cistatic const u16 VAUX4_VSEL_table[] = { 3248c2ecf20Sopenharmony_ci 700, 1000, 1200, UNSUP(1300), 3258c2ecf20Sopenharmony_ci 1500, 1800, UNSUP(1850), 2500, 3268c2ecf20Sopenharmony_ci UNSUP(2600), 2800, UNSUP(2850), UNSUP(3000), 3278c2ecf20Sopenharmony_ci UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 3288c2ecf20Sopenharmony_ci}; 3298c2ecf20Sopenharmony_cistatic const u16 VMMC1_VSEL_table[] = { 3308c2ecf20Sopenharmony_ci 1850, 2850, 3000, 3150, 3318c2ecf20Sopenharmony_ci}; 3328c2ecf20Sopenharmony_cistatic const u16 VMMC2_VSEL_table[] = { 3338c2ecf20Sopenharmony_ci UNSUP(1000), UNSUP(1000), UNSUP(1200), UNSUP(1300), 3348c2ecf20Sopenharmony_ci UNSUP(1500), UNSUP(1800), 1850, UNSUP(2500), 3358c2ecf20Sopenharmony_ci 2600, 2800, 2850, 3000, 3368c2ecf20Sopenharmony_ci 3150, 3150, 3150, 3150, 3378c2ecf20Sopenharmony_ci}; 3388c2ecf20Sopenharmony_cistatic const u16 VPLL1_VSEL_table[] = { 3398c2ecf20Sopenharmony_ci 1000, 1200, 1300, 1800, 3408c2ecf20Sopenharmony_ci UNSUP(2800), UNSUP(3000), UNSUP(3000), UNSUP(3000), 3418c2ecf20Sopenharmony_ci}; 3428c2ecf20Sopenharmony_cistatic const u16 VPLL2_VSEL_table[] = { 3438c2ecf20Sopenharmony_ci 700, 1000, 1200, 1300, 3448c2ecf20Sopenharmony_ci UNSUP(1500), 1800, UNSUP(1850), UNSUP(2500), 3458c2ecf20Sopenharmony_ci UNSUP(2600), UNSUP(2800), UNSUP(2850), UNSUP(3000), 3468c2ecf20Sopenharmony_ci UNSUP(3150), UNSUP(3150), UNSUP(3150), UNSUP(3150), 3478c2ecf20Sopenharmony_ci}; 3488c2ecf20Sopenharmony_cistatic const u16 VSIM_VSEL_table[] = { 3498c2ecf20Sopenharmony_ci UNSUP(1000), UNSUP(1200), UNSUP(1300), 1800, 3508c2ecf20Sopenharmony_ci 2800, 3000, 3000, 3000, 3518c2ecf20Sopenharmony_ci}; 3528c2ecf20Sopenharmony_cistatic const u16 VDAC_VSEL_table[] = { 3538c2ecf20Sopenharmony_ci 1200, 1300, 1800, 1800, 3548c2ecf20Sopenharmony_ci}; 3558c2ecf20Sopenharmony_cistatic const u16 VIO_VSEL_table[] = { 3568c2ecf20Sopenharmony_ci 1800, 1850, 3578c2ecf20Sopenharmony_ci}; 3588c2ecf20Sopenharmony_cistatic const u16 VINTANA2_VSEL_table[] = { 3598c2ecf20Sopenharmony_ci 2500, 2750, 3608c2ecf20Sopenharmony_ci}; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci/* 600mV to 1450mV in 12.5 mV steps */ 3638c2ecf20Sopenharmony_cistatic const struct linear_range VDD1_ranges[] = { 3648c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(600000, 0, 68, 12500) 3658c2ecf20Sopenharmony_ci}; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci/* 600mV to 1450mV in 12.5 mV steps, everything above = 1500mV */ 3688c2ecf20Sopenharmony_cistatic const struct linear_range VDD2_ranges[] = { 3698c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(600000, 0, 68, 12500), 3708c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(1500000, 69, 69, 12500) 3718c2ecf20Sopenharmony_ci}; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_cistatic int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) 3748c2ecf20Sopenharmony_ci{ 3758c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 3768c2ecf20Sopenharmony_ci int mV = info->table[index]; 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000); 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic int 3828c2ecf20Sopenharmony_citwl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) 3838c2ecf20Sopenharmony_ci{ 3848c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, 3878c2ecf20Sopenharmony_ci selector); 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_cistatic int twl4030ldo_get_voltage_sel(struct regulator_dev *rdev) 3918c2ecf20Sopenharmony_ci{ 3928c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 3938c2ecf20Sopenharmony_ci int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci if (vsel < 0) 3968c2ecf20Sopenharmony_ci return vsel; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci vsel &= info->table_len - 1; 3998c2ecf20Sopenharmony_ci return vsel; 4008c2ecf20Sopenharmony_ci} 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_cistatic const struct regulator_ops twl4030ldo_ops = { 4038c2ecf20Sopenharmony_ci .list_voltage = twl4030ldo_list_voltage, 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci .set_voltage_sel = twl4030ldo_set_voltage_sel, 4068c2ecf20Sopenharmony_ci .get_voltage_sel = twl4030ldo_get_voltage_sel, 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci .enable = twl4030reg_enable, 4098c2ecf20Sopenharmony_ci .disable = twl4030reg_disable, 4108c2ecf20Sopenharmony_ci .is_enabled = twl4030reg_is_enabled, 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci .set_mode = twl4030reg_set_mode, 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci .get_status = twl4030reg_get_status, 4158c2ecf20Sopenharmony_ci}; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistatic int 4188c2ecf20Sopenharmony_citwl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, 4198c2ecf20Sopenharmony_ci unsigned *selector) 4208c2ecf20Sopenharmony_ci{ 4218c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 4228c2ecf20Sopenharmony_ci int vsel = DIV_ROUND_UP(min_uV - 600000, 12500); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030, vsel); 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci return 0; 4278c2ecf20Sopenharmony_ci} 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_cistatic int twl4030smps_get_voltage(struct regulator_dev *rdev) 4308c2ecf20Sopenharmony_ci{ 4318c2ecf20Sopenharmony_ci struct twlreg_info *info = rdev_get_drvdata(rdev); 4328c2ecf20Sopenharmony_ci int vsel; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER, 4358c2ecf20Sopenharmony_ci VREG_VOLTAGE_SMPS_4030); 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci return vsel * 12500 + 600000; 4388c2ecf20Sopenharmony_ci} 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_cistatic const struct regulator_ops twl4030smps_ops = { 4418c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear_range, 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci .set_voltage = twl4030smps_set_voltage, 4448c2ecf20Sopenharmony_ci .get_voltage = twl4030smps_get_voltage, 4458c2ecf20Sopenharmony_ci}; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_cistatic const struct regulator_ops twl4030fixed_ops = { 4508c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci .enable = twl4030reg_enable, 4538c2ecf20Sopenharmony_ci .disable = twl4030reg_disable, 4548c2ecf20Sopenharmony_ci .is_enabled = twl4030reg_is_enabled, 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci .set_mode = twl4030reg_set_mode, 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci .get_status = twl4030reg_get_status, 4598c2ecf20Sopenharmony_ci}; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci/*----------------------------------------------------------------------*/ 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci#define TWL4030_ADJUSTABLE_LDO(label, offset, num, turnon_delay, remap_conf) \ 4648c2ecf20Sopenharmony_cistatic const struct twlreg_info TWL4030_INFO_##label = { \ 4658c2ecf20Sopenharmony_ci .base = offset, \ 4668c2ecf20Sopenharmony_ci .id = num, \ 4678c2ecf20Sopenharmony_ci .table_len = ARRAY_SIZE(label##_VSEL_table), \ 4688c2ecf20Sopenharmony_ci .table = label##_VSEL_table, \ 4698c2ecf20Sopenharmony_ci .remap = remap_conf, \ 4708c2ecf20Sopenharmony_ci .desc = { \ 4718c2ecf20Sopenharmony_ci .name = #label, \ 4728c2ecf20Sopenharmony_ci .id = TWL4030_REG_##label, \ 4738c2ecf20Sopenharmony_ci .n_voltages = ARRAY_SIZE(label##_VSEL_table), \ 4748c2ecf20Sopenharmony_ci .ops = &twl4030ldo_ops, \ 4758c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 4768c2ecf20Sopenharmony_ci .owner = THIS_MODULE, \ 4778c2ecf20Sopenharmony_ci .enable_time = turnon_delay, \ 4788c2ecf20Sopenharmony_ci .of_map_mode = twl4030reg_map_mode, \ 4798c2ecf20Sopenharmony_ci }, \ 4808c2ecf20Sopenharmony_ci } 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf, \ 4838c2ecf20Sopenharmony_ci n_volt) \ 4848c2ecf20Sopenharmony_cistatic const struct twlreg_info TWL4030_INFO_##label = { \ 4858c2ecf20Sopenharmony_ci .base = offset, \ 4868c2ecf20Sopenharmony_ci .id = num, \ 4878c2ecf20Sopenharmony_ci .remap = remap_conf, \ 4888c2ecf20Sopenharmony_ci .desc = { \ 4898c2ecf20Sopenharmony_ci .name = #label, \ 4908c2ecf20Sopenharmony_ci .id = TWL4030_REG_##label, \ 4918c2ecf20Sopenharmony_ci .ops = &twl4030smps_ops, \ 4928c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 4938c2ecf20Sopenharmony_ci .owner = THIS_MODULE, \ 4948c2ecf20Sopenharmony_ci .enable_time = turnon_delay, \ 4958c2ecf20Sopenharmony_ci .of_map_mode = twl4030reg_map_mode, \ 4968c2ecf20Sopenharmony_ci .n_voltages = n_volt, \ 4978c2ecf20Sopenharmony_ci .n_linear_ranges = ARRAY_SIZE(label ## _ranges), \ 4988c2ecf20Sopenharmony_ci .linear_ranges = label ## _ranges, \ 4998c2ecf20Sopenharmony_ci }, \ 5008c2ecf20Sopenharmony_ci } 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci#define TWL4030_FIXED_LDO(label, offset, mVolts, num, turnon_delay, \ 5038c2ecf20Sopenharmony_ci remap_conf) \ 5048c2ecf20Sopenharmony_cistatic const struct twlreg_info TWLFIXED_INFO_##label = { \ 5058c2ecf20Sopenharmony_ci .base = offset, \ 5068c2ecf20Sopenharmony_ci .id = num, \ 5078c2ecf20Sopenharmony_ci .remap = remap_conf, \ 5088c2ecf20Sopenharmony_ci .desc = { \ 5098c2ecf20Sopenharmony_ci .name = #label, \ 5108c2ecf20Sopenharmony_ci .id = TWL4030##_REG_##label, \ 5118c2ecf20Sopenharmony_ci .n_voltages = 1, \ 5128c2ecf20Sopenharmony_ci .ops = &twl4030fixed_ops, \ 5138c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 5148c2ecf20Sopenharmony_ci .owner = THIS_MODULE, \ 5158c2ecf20Sopenharmony_ci .min_uV = mVolts * 1000, \ 5168c2ecf20Sopenharmony_ci .enable_time = turnon_delay, \ 5178c2ecf20Sopenharmony_ci .of_map_mode = twl4030reg_map_mode, \ 5188c2ecf20Sopenharmony_ci }, \ 5198c2ecf20Sopenharmony_ci } 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci/* 5228c2ecf20Sopenharmony_ci * We list regulators here if systems need some level of 5238c2ecf20Sopenharmony_ci * software control over them after boot. 5248c2ecf20Sopenharmony_ci */ 5258c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VAUX1, 0x17, 1, 100, 0x08); 5268c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VAUX2_4030, 0x1b, 2, 100, 0x08); 5278c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VAUX2, 0x1b, 2, 100, 0x08); 5288c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VAUX3, 0x1f, 3, 100, 0x08); 5298c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VAUX4, 0x23, 4, 100, 0x08); 5308c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VMMC1, 0x27, 5, 100, 0x08); 5318c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VMMC2, 0x2b, 6, 100, 0x08); 5328c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VPLL1, 0x2f, 7, 100, 0x00); 5338c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VPLL2, 0x33, 8, 100, 0x08); 5348c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VSIM, 0x37, 9, 100, 0x00); 5358c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VDAC, 0x3b, 10, 100, 0x08); 5368c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08); 5378c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08); 5388c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08, 68); 5398c2ecf20Sopenharmony_ciTWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08, 69); 5408c2ecf20Sopenharmony_ci/* VUSBCP is managed *only* by the USB subchip */ 5418c2ecf20Sopenharmony_ciTWL4030_FIXED_LDO(VINTANA1, 0x3f, 1500, 11, 100, 0x08); 5428c2ecf20Sopenharmony_ciTWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08); 5438c2ecf20Sopenharmony_ciTWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08); 5448c2ecf20Sopenharmony_ciTWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08); 5458c2ecf20Sopenharmony_ciTWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08); 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci#define TWL_OF_MATCH(comp, family, label) \ 5488c2ecf20Sopenharmony_ci { \ 5498c2ecf20Sopenharmony_ci .compatible = comp, \ 5508c2ecf20Sopenharmony_ci .data = &family##_INFO_##label, \ 5518c2ecf20Sopenharmony_ci } 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci#define TWL4030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL4030, label) 5548c2ecf20Sopenharmony_ci#define TWL6030_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6030, label) 5558c2ecf20Sopenharmony_ci#define TWL6032_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWL6032, label) 5568c2ecf20Sopenharmony_ci#define TWLFIXED_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLFIXED, label) 5578c2ecf20Sopenharmony_ci#define TWLSMPS_OF_MATCH(comp, label) TWL_OF_MATCH(comp, TWLSMPS, label) 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_cistatic const struct of_device_id twl_of_match[] = { 5608c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vaux1", VAUX1), 5618c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vaux2", VAUX2_4030), 5628c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl5030-vaux2", VAUX2), 5638c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vaux3", VAUX3), 5648c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vaux4", VAUX4), 5658c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vmmc1", VMMC1), 5668c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vmmc2", VMMC2), 5678c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vpll1", VPLL1), 5688c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vpll2", VPLL2), 5698c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vsim", VSIM), 5708c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vdac", VDAC), 5718c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vintana2", VINTANA2), 5728c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vio", VIO), 5738c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vdd1", VDD1), 5748c2ecf20Sopenharmony_ci TWL4030_OF_MATCH("ti,twl4030-vdd2", VDD2), 5758c2ecf20Sopenharmony_ci TWLFIXED_OF_MATCH("ti,twl4030-vintana1", VINTANA1), 5768c2ecf20Sopenharmony_ci TWLFIXED_OF_MATCH("ti,twl4030-vintdig", VINTDIG), 5778c2ecf20Sopenharmony_ci TWLFIXED_OF_MATCH("ti,twl4030-vusb1v5", VUSB1V5), 5788c2ecf20Sopenharmony_ci TWLFIXED_OF_MATCH("ti,twl4030-vusb1v8", VUSB1V8), 5798c2ecf20Sopenharmony_ci TWLFIXED_OF_MATCH("ti,twl4030-vusb3v1", VUSB3V1), 5808c2ecf20Sopenharmony_ci {}, 5818c2ecf20Sopenharmony_ci}; 5828c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, twl_of_match); 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_cistatic int twlreg_probe(struct platform_device *pdev) 5858c2ecf20Sopenharmony_ci{ 5868c2ecf20Sopenharmony_ci int id; 5878c2ecf20Sopenharmony_ci struct twlreg_info *info; 5888c2ecf20Sopenharmony_ci const struct twlreg_info *template; 5898c2ecf20Sopenharmony_ci struct regulator_init_data *initdata; 5908c2ecf20Sopenharmony_ci struct regulation_constraints *c; 5918c2ecf20Sopenharmony_ci struct regulator_dev *rdev; 5928c2ecf20Sopenharmony_ci struct regulator_config config = { }; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci template = of_device_get_match_data(&pdev->dev); 5958c2ecf20Sopenharmony_ci if (!template) 5968c2ecf20Sopenharmony_ci return -ENODEV; 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci id = template->desc.id; 5998c2ecf20Sopenharmony_ci initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node, 6008c2ecf20Sopenharmony_ci &template->desc); 6018c2ecf20Sopenharmony_ci if (!initdata) 6028c2ecf20Sopenharmony_ci return -EINVAL; 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci info = devm_kmemdup(&pdev->dev, template, sizeof(*info), GFP_KERNEL); 6058c2ecf20Sopenharmony_ci if (!info) 6068c2ecf20Sopenharmony_ci return -ENOMEM; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci /* Constrain board-specific capabilities according to what 6098c2ecf20Sopenharmony_ci * this driver and the chip itself can actually do. 6108c2ecf20Sopenharmony_ci */ 6118c2ecf20Sopenharmony_ci c = &initdata->constraints; 6128c2ecf20Sopenharmony_ci c->valid_modes_mask &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_STANDBY; 6138c2ecf20Sopenharmony_ci c->valid_ops_mask &= REGULATOR_CHANGE_VOLTAGE 6148c2ecf20Sopenharmony_ci | REGULATOR_CHANGE_MODE 6158c2ecf20Sopenharmony_ci | REGULATOR_CHANGE_STATUS; 6168c2ecf20Sopenharmony_ci switch (id) { 6178c2ecf20Sopenharmony_ci case TWL4030_REG_VIO: 6188c2ecf20Sopenharmony_ci case TWL4030_REG_VDD1: 6198c2ecf20Sopenharmony_ci case TWL4030_REG_VDD2: 6208c2ecf20Sopenharmony_ci case TWL4030_REG_VPLL1: 6218c2ecf20Sopenharmony_ci case TWL4030_REG_VINTANA1: 6228c2ecf20Sopenharmony_ci case TWL4030_REG_VINTANA2: 6238c2ecf20Sopenharmony_ci case TWL4030_REG_VINTDIG: 6248c2ecf20Sopenharmony_ci c->always_on = true; 6258c2ecf20Sopenharmony_ci break; 6268c2ecf20Sopenharmony_ci default: 6278c2ecf20Sopenharmony_ci break; 6288c2ecf20Sopenharmony_ci } 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci config.dev = &pdev->dev; 6318c2ecf20Sopenharmony_ci config.init_data = initdata; 6328c2ecf20Sopenharmony_ci config.driver_data = info; 6338c2ecf20Sopenharmony_ci config.of_node = pdev->dev.of_node; 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); 6368c2ecf20Sopenharmony_ci if (IS_ERR(rdev)) { 6378c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "can't register %s, %ld\n", 6388c2ecf20Sopenharmony_ci info->desc.name, PTR_ERR(rdev)); 6398c2ecf20Sopenharmony_ci return PTR_ERR(rdev); 6408c2ecf20Sopenharmony_ci } 6418c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, rdev); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_REMAP, info->remap); 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ci /* NOTE: many regulators support short-circuit IRQs (presentable 6468c2ecf20Sopenharmony_ci * as REGULATOR_OVER_CURRENT notifications?) configured via: 6478c2ecf20Sopenharmony_ci * - SC_CONFIG 6488c2ecf20Sopenharmony_ci * - SC_DETECT1 (vintana2, vmmc1/2, vaux1/2/3/4) 6498c2ecf20Sopenharmony_ci * - SC_DETECT2 (vusb, vdac, vio, vdd1/2, vpll2) 6508c2ecf20Sopenharmony_ci * - IT_CONFIG 6518c2ecf20Sopenharmony_ci */ 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci return 0; 6548c2ecf20Sopenharmony_ci} 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ciMODULE_ALIAS("platform:twl4030_reg"); 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_cistatic struct platform_driver twlreg_driver = { 6598c2ecf20Sopenharmony_ci .probe = twlreg_probe, 6608c2ecf20Sopenharmony_ci /* NOTE: short name, to work around driver model truncation of 6618c2ecf20Sopenharmony_ci * "twl_regulator.12" (and friends) to "twl_regulator.1". 6628c2ecf20Sopenharmony_ci */ 6638c2ecf20Sopenharmony_ci .driver = { 6648c2ecf20Sopenharmony_ci .name = "twl4030_reg", 6658c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(twl_of_match), 6668c2ecf20Sopenharmony_ci }, 6678c2ecf20Sopenharmony_ci}; 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_cistatic int __init twlreg_init(void) 6708c2ecf20Sopenharmony_ci{ 6718c2ecf20Sopenharmony_ci return platform_driver_register(&twlreg_driver); 6728c2ecf20Sopenharmony_ci} 6738c2ecf20Sopenharmony_cisubsys_initcall(twlreg_init); 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_cistatic void __exit twlreg_exit(void) 6768c2ecf20Sopenharmony_ci{ 6778c2ecf20Sopenharmony_ci platform_driver_unregister(&twlreg_driver); 6788c2ecf20Sopenharmony_ci} 6798c2ecf20Sopenharmony_cimodule_exit(twlreg_exit) 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("TWL4030 regulator driver"); 6828c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 683