197fb5e8dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2e92a4047SStephen Boyd /* 3e92a4047SStephen Boyd * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. 4e92a4047SStephen Boyd */ 5e92a4047SStephen Boyd 6e92a4047SStephen Boyd #include <linux/module.h> 7e92a4047SStephen Boyd #include <linux/delay.h> 8b6688015SMatti Vaittinen #include <linux/devm-helpers.h> 9e92a4047SStephen Boyd #include <linux/err.h> 10e92a4047SStephen Boyd #include <linux/kernel.h> 11e92a4047SStephen Boyd #include <linux/interrupt.h> 12e92a4047SStephen Boyd #include <linux/bitops.h> 13e92a4047SStephen Boyd #include <linux/slab.h> 14e92a4047SStephen Boyd #include <linux/of.h> 15e92a4047SStephen Boyd #include <linux/of_device.h> 16e92a4047SStephen Boyd #include <linux/platform_device.h> 17e92a4047SStephen Boyd #include <linux/ktime.h> 18e92a4047SStephen Boyd #include <linux/regulator/driver.h> 19e92a4047SStephen Boyd #include <linux/regmap.h> 20e92a4047SStephen Boyd #include <linux/list.h> 210caecaa8SIlia Lin #include <linux/mfd/syscon.h> 220caecaa8SIlia Lin #include <linux/io.h> 23e92a4047SStephen Boyd 24e2adfacdSStephen Boyd /* Pin control enable input pins. */ 25e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_NONE 0x00 26e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN0 0x01 27e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN1 0x02 28e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN2 0x04 29e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_EN3 0x08 30e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT 0x10 31e2adfacdSStephen Boyd 32e2adfacdSStephen Boyd /* Pin control high power mode input pins. */ 33e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_NONE 0x00 34e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN0 0x01 35e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN1 0x02 36e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN2 0x04 37e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_EN3 0x08 38e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_SLEEP_B 0x10 39e2adfacdSStephen Boyd #define SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT 0x20 40e2adfacdSStephen Boyd 41e2adfacdSStephen Boyd /* 42e2adfacdSStephen Boyd * Used with enable parameters to specify that hardware default register values 43e2adfacdSStephen Boyd * should be left unaltered. 44e2adfacdSStephen Boyd */ 45e2adfacdSStephen Boyd #define SPMI_REGULATOR_USE_HW_DEFAULT 2 46e2adfacdSStephen Boyd 47e2adfacdSStephen Boyd /* Soft start strength of a voltage switch type regulator */ 48e2adfacdSStephen Boyd enum spmi_vs_soft_start_str { 49e2adfacdSStephen Boyd SPMI_VS_SOFT_START_STR_0P05_UA = 0, 50e2adfacdSStephen Boyd SPMI_VS_SOFT_START_STR_0P25_UA, 51e2adfacdSStephen Boyd SPMI_VS_SOFT_START_STR_0P55_UA, 52e2adfacdSStephen Boyd SPMI_VS_SOFT_START_STR_0P75_UA, 53e2adfacdSStephen Boyd SPMI_VS_SOFT_START_STR_HW_DEFAULT, 54e2adfacdSStephen Boyd }; 55e2adfacdSStephen Boyd 56e2adfacdSStephen Boyd /** 57e2adfacdSStephen Boyd * struct spmi_regulator_init_data - spmi-regulator initialization data 58e2adfacdSStephen Boyd * @pin_ctrl_enable: Bit mask specifying which hardware pins should be 59e2adfacdSStephen Boyd * used to enable the regulator, if any 60e2adfacdSStephen Boyd * Value should be an ORing of 61e2adfacdSStephen Boyd * SPMI_REGULATOR_PIN_CTRL_ENABLE_* constants. If 62e2adfacdSStephen Boyd * the bit specified by 63e2adfacdSStephen Boyd * SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT is 64e2adfacdSStephen Boyd * set, then pin control enable hardware registers 65e2adfacdSStephen Boyd * will not be modified. 66e2adfacdSStephen Boyd * @pin_ctrl_hpm: Bit mask specifying which hardware pins should be 67e2adfacdSStephen Boyd * used to force the regulator into high power 68e2adfacdSStephen Boyd * mode, if any 69e2adfacdSStephen Boyd * Value should be an ORing of 70e2adfacdSStephen Boyd * SPMI_REGULATOR_PIN_CTRL_HPM_* constants. If 71e2adfacdSStephen Boyd * the bit specified by 72e2adfacdSStephen Boyd * SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT is 73e2adfacdSStephen Boyd * set, then pin control mode hardware registers 74e2adfacdSStephen Boyd * will not be modified. 75e2adfacdSStephen Boyd * @vs_soft_start_strength: This parameter sets the soft start strength for 76e2adfacdSStephen Boyd * voltage switch type regulators. Its value 77e2adfacdSStephen Boyd * should be one of SPMI_VS_SOFT_START_STR_*. If 78e2adfacdSStephen Boyd * its value is SPMI_VS_SOFT_START_STR_HW_DEFAULT, 79e2adfacdSStephen Boyd * then the soft start strength will be left at its 80e2adfacdSStephen Boyd * default hardware value. 81e2adfacdSStephen Boyd */ 82e2adfacdSStephen Boyd struct spmi_regulator_init_data { 83e2adfacdSStephen Boyd unsigned pin_ctrl_enable; 84e2adfacdSStephen Boyd unsigned pin_ctrl_hpm; 85e2adfacdSStephen Boyd enum spmi_vs_soft_start_str vs_soft_start_strength; 86e2adfacdSStephen Boyd }; 87e2adfacdSStephen Boyd 88e92a4047SStephen Boyd /* These types correspond to unique register layouts. */ 89e92a4047SStephen Boyd enum spmi_regulator_logical_type { 90e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_SMPS, 91e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_LDO, 92e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_VS, 93e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_BOOST, 94e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS, 95e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_BOOST_BYP, 96e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_LN_LDO, 97e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS, 98e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS, 99e92a4047SStephen Boyd SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO, 10042ba89c8SJeffrey Hugo SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426, 1010211f68eSJorge Ramirez SPMI_REGULATOR_LOGICAL_TYPE_HFS430, 102*27850254SIskren Chernev SPMI_REGULATOR_LOGICAL_TYPE_HFSMPS, 103e92a4047SStephen Boyd }; 104e92a4047SStephen Boyd 105e92a4047SStephen Boyd enum spmi_regulator_type { 106e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_BUCK = 0x03, 107e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_LDO = 0x04, 108e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_VS = 0x05, 109e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_BOOST = 0x1b, 110e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_FTS = 0x1c, 111e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_BOOST_BYP = 0x1f, 112e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_ULT_LDO = 0x21, 113e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_ULT_BUCK = 0x22, 114e92a4047SStephen Boyd }; 115e92a4047SStephen Boyd 116e92a4047SStephen Boyd enum spmi_regulator_subtype { 117e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_GP_CTL = 0x08, 118e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_RF_CTL = 0x09, 119e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N50 = 0x01, 120e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N150 = 0x02, 121e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N300 = 0x03, 122e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N600 = 0x04, 123e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N1200 = 0x05, 124e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N600_ST = 0x06, 125e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N1200_ST = 0x07, 126e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N900_ST = 0x14, 127e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N300_ST = 0x15, 128e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P50 = 0x08, 129e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P150 = 0x09, 130e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P300 = 0x0a, 131e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P600 = 0x0b, 132e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P1200 = 0x0c, 133e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LN = 0x10, 134e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P50 = 0x28, 135e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P150 = 0x29, 136e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P300 = 0x2a, 137e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P600 = 0x2b, 138e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P1200 = 0x2c, 139e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P450 = 0x2d, 140328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_N300_ST = 0x30, 141328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_N600_ST = 0x31, 142328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_N1200_ST = 0x32, 143328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_LVP150 = 0x3b, 144328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_LVP300 = 0x3c, 145328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_N300_ST = 0x42, 146328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_N600_ST = 0x43, 147328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_P50 = 0x46, 148328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_P150 = 0x47, 149328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_P600 = 0x49, 150328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_LVP150 = 0x4d, 151328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_LVP600 = 0x4f, 152e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV100 = 0x01, 153e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV300 = 0x02, 154e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_MV300 = 0x08, 155e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_MV500 = 0x09, 156e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_HDMI = 0x10, 157e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_OTG = 0x11, 158e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_5V_BOOST = 0x01, 159e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_FTS_CTL = 0x08, 160e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_FTS2p5_CTL = 0x09, 16142ba89c8SJeffrey Hugo SPMI_REGULATOR_SUBTYPE_FTS426_CTL = 0x0a, 162e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_BB_2A = 0x01, 163e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL1 = 0x0d, 164e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL2 = 0x0e, 165e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL3 = 0x0f, 166e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL4 = 0x10, 1670211f68eSJorge Ramirez SPMI_REGULATOR_SUBTYPE_HFS430 = 0x0a, 16800f6ebbdSRobert Marko SPMI_REGULATOR_SUBTYPE_HT_P150 = 0x35, 1693d04ae8eSRobert Marko SPMI_REGULATOR_SUBTYPE_HT_P600 = 0x3d, 170*27850254SIskren Chernev SPMI_REGULATOR_SUBTYPE_HFSMPS_510 = 0x0a, 171e92a4047SStephen Boyd }; 172e92a4047SStephen Boyd 173e92a4047SStephen Boyd enum spmi_common_regulator_registers { 174e92a4047SStephen Boyd SPMI_COMMON_REG_DIG_MAJOR_REV = 0x01, 175e92a4047SStephen Boyd SPMI_COMMON_REG_TYPE = 0x04, 176e92a4047SStephen Boyd SPMI_COMMON_REG_SUBTYPE = 0x05, 177e92a4047SStephen Boyd SPMI_COMMON_REG_VOLTAGE_RANGE = 0x40, 178e92a4047SStephen Boyd SPMI_COMMON_REG_VOLTAGE_SET = 0x41, 179e92a4047SStephen Boyd SPMI_COMMON_REG_MODE = 0x45, 180e92a4047SStephen Boyd SPMI_COMMON_REG_ENABLE = 0x46, 181e92a4047SStephen Boyd SPMI_COMMON_REG_PULL_DOWN = 0x48, 182e92a4047SStephen Boyd SPMI_COMMON_REG_SOFT_START = 0x4c, 183e92a4047SStephen Boyd SPMI_COMMON_REG_STEP_CTRL = 0x61, 184e92a4047SStephen Boyd }; 185e92a4047SStephen Boyd 18642ba89c8SJeffrey Hugo /* 18742ba89c8SJeffrey Hugo * Second common register layout used by newer devices starting with ftsmps426 18842ba89c8SJeffrey Hugo * Note that some of the registers from the first common layout remain 18942ba89c8SJeffrey Hugo * unchanged and their definition is not duplicated. 19042ba89c8SJeffrey Hugo */ 19142ba89c8SJeffrey Hugo enum spmi_ftsmps426_regulator_registers { 19242ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_LSB = 0x40, 19342ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_MSB = 0x41, 19442ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_ULS_LSB = 0x68, 19542ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_ULS_MSB = 0x69, 19642ba89c8SJeffrey Hugo }; 19742ba89c8SJeffrey Hugo 198*27850254SIskren Chernev /* 199*27850254SIskren Chernev * Third common register layout 200*27850254SIskren Chernev */ 201*27850254SIskren Chernev enum spmi_hfsmps_regulator_registers { 202*27850254SIskren Chernev SPMI_HFSMPS_REG_STEP_CTRL = 0x3c, 203*27850254SIskren Chernev SPMI_HFSMPS_REG_PULL_DOWN = 0xa0, 204*27850254SIskren Chernev }; 205*27850254SIskren Chernev 206e92a4047SStephen Boyd enum spmi_vs_registers { 207e92a4047SStephen Boyd SPMI_VS_REG_OCP = 0x4a, 208e92a4047SStephen Boyd SPMI_VS_REG_SOFT_START = 0x4c, 209e92a4047SStephen Boyd }; 210e92a4047SStephen Boyd 211e92a4047SStephen Boyd enum spmi_boost_registers { 212e92a4047SStephen Boyd SPMI_BOOST_REG_CURRENT_LIMIT = 0x4a, 213e92a4047SStephen Boyd }; 214e92a4047SStephen Boyd 215e92a4047SStephen Boyd enum spmi_boost_byp_registers { 216e92a4047SStephen Boyd SPMI_BOOST_BYP_REG_CURRENT_LIMIT = 0x4b, 217e92a4047SStephen Boyd }; 218e92a4047SStephen Boyd 2190caecaa8SIlia Lin enum spmi_saw3_registers { 2200caecaa8SIlia Lin SAW3_SECURE = 0x00, 2210caecaa8SIlia Lin SAW3_ID = 0x04, 2220caecaa8SIlia Lin SAW3_SPM_STS = 0x0C, 2230caecaa8SIlia Lin SAW3_AVS_STS = 0x10, 2240caecaa8SIlia Lin SAW3_PMIC_STS = 0x14, 2250caecaa8SIlia Lin SAW3_RST = 0x18, 2260caecaa8SIlia Lin SAW3_VCTL = 0x1C, 2270caecaa8SIlia Lin SAW3_AVS_CTL = 0x20, 2280caecaa8SIlia Lin SAW3_AVS_LIMIT = 0x24, 2290caecaa8SIlia Lin SAW3_AVS_DLY = 0x28, 2300caecaa8SIlia Lin SAW3_AVS_HYSTERESIS = 0x2C, 2310caecaa8SIlia Lin SAW3_SPM_STS2 = 0x38, 2320caecaa8SIlia Lin SAW3_SPM_PMIC_DATA_3 = 0x4C, 2330caecaa8SIlia Lin SAW3_VERSION = 0xFD0, 2340caecaa8SIlia Lin }; 2350caecaa8SIlia Lin 236e92a4047SStephen Boyd /* Used for indexing into ctrl_reg. These are offets from 0x40 */ 237e92a4047SStephen Boyd enum spmi_common_control_register_index { 238e92a4047SStephen Boyd SPMI_COMMON_IDX_VOLTAGE_RANGE = 0, 239e92a4047SStephen Boyd SPMI_COMMON_IDX_VOLTAGE_SET = 1, 240e92a4047SStephen Boyd SPMI_COMMON_IDX_MODE = 5, 241e92a4047SStephen Boyd SPMI_COMMON_IDX_ENABLE = 6, 242e92a4047SStephen Boyd }; 243e92a4047SStephen Boyd 244e92a4047SStephen Boyd /* Common regulator control register layout */ 245e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_MASK 0x80 246e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE 0x80 247e92a4047SStephen Boyd #define SPMI_COMMON_DISABLE 0x00 248e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN3_MASK 0x08 249e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN2_MASK 0x04 250e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN1_MASK 0x02 251e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN0_MASK 0x01 252e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK 0x0f 253e92a4047SStephen Boyd 254e92a4047SStephen Boyd /* Common regulator mode register layout */ 255e92a4047SStephen Boyd #define SPMI_COMMON_MODE_HPM_MASK 0x80 256e92a4047SStephen Boyd #define SPMI_COMMON_MODE_AUTO_MASK 0x40 257e92a4047SStephen Boyd #define SPMI_COMMON_MODE_BYPASS_MASK 0x20 258e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK 0x10 259e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN3_MASK 0x08 260e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN2_MASK 0x04 261e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN1_MASK 0x02 262e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN0_MASK 0x01 263e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_ALL_MASK 0x1f 264e92a4047SStephen Boyd 26542ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_BYPASS_MASK 3 26642ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_RETENTION_MASK 4 26742ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_LPM_MASK 5 26842ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_AUTO_MASK 6 26942ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_HPM_MASK 7 27042ba89c8SJeffrey Hugo 27142ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_MASK 0x07 27242ba89c8SJeffrey Hugo 273*27850254SIskren Chernev /* Third common regulator mode register values */ 274*27850254SIskren Chernev #define SPMI_HFSMPS_MODE_BYPASS_MASK 2 275*27850254SIskren Chernev #define SPMI_HFSMPS_MODE_RETENTION_MASK 3 276*27850254SIskren Chernev #define SPMI_HFSMPS_MODE_LPM_MASK 4 277*27850254SIskren Chernev #define SPMI_HFSMPS_MODE_AUTO_MASK 6 278*27850254SIskren Chernev #define SPMI_HFSMPS_MODE_HPM_MASK 7 279*27850254SIskren Chernev 280*27850254SIskren Chernev #define SPMI_HFSMPS_MODE_MASK 0x07 281*27850254SIskren Chernev 282e92a4047SStephen Boyd /* Common regulator pull down control register layout */ 283e92a4047SStephen Boyd #define SPMI_COMMON_PULL_DOWN_ENABLE_MASK 0x80 284e92a4047SStephen Boyd 285e92a4047SStephen Boyd /* LDO regulator current limit control register layout */ 286e92a4047SStephen Boyd #define SPMI_LDO_CURRENT_LIMIT_ENABLE_MASK 0x80 287e92a4047SStephen Boyd 288e92a4047SStephen Boyd /* LDO regulator soft start control register layout */ 289e92a4047SStephen Boyd #define SPMI_LDO_SOFT_START_ENABLE_MASK 0x80 290e92a4047SStephen Boyd 291e92a4047SStephen Boyd /* VS regulator over current protection control register layout */ 292e92a4047SStephen Boyd #define SPMI_VS_OCP_OVERRIDE 0x01 293e92a4047SStephen Boyd #define SPMI_VS_OCP_NO_OVERRIDE 0x00 294e92a4047SStephen Boyd 295e92a4047SStephen Boyd /* VS regulator soft start control register layout */ 296e92a4047SStephen Boyd #define SPMI_VS_SOFT_START_ENABLE_MASK 0x80 297e92a4047SStephen Boyd #define SPMI_VS_SOFT_START_SEL_MASK 0x03 298e92a4047SStephen Boyd 299e92a4047SStephen Boyd /* Boost regulator current limit control register layout */ 300e92a4047SStephen Boyd #define SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK 0x80 301e92a4047SStephen Boyd #define SPMI_BOOST_CURRENT_LIMIT_MASK 0x07 302e92a4047SStephen Boyd 303e92a4047SStephen Boyd #define SPMI_VS_OCP_DEFAULT_MAX_RETRIES 10 304e92a4047SStephen Boyd #define SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS 30 305e92a4047SStephen Boyd #define SPMI_VS_OCP_FALL_DELAY_US 90 306e92a4047SStephen Boyd #define SPMI_VS_OCP_FAULT_DELAY_US 20000 307e92a4047SStephen Boyd 308e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_STEP_MASK 0x18 309e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT 3 310e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_DELAY_MASK 0x07 311e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT 0 312e92a4047SStephen Boyd 313e92a4047SStephen Boyd /* Clock rate in kHz of the FTSMPS regulator reference clock. */ 314e92a4047SStephen Boyd #define SPMI_FTSMPS_CLOCK_RATE 19200 315e92a4047SStephen Boyd 316e92a4047SStephen Boyd /* Minimum voltage stepper delay for each step. */ 317e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_DELAY 8 3182cf7b99cSStephen Boyd #define SPMI_DEFAULT_STEP_DELAY 20 319e92a4047SStephen Boyd 320e92a4047SStephen Boyd /* 321e92a4047SStephen Boyd * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to 322e92a4047SStephen Boyd * adjust the step rate in order to account for oscillator variance. 323e92a4047SStephen Boyd */ 324e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_MARGIN_NUM 4 325e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_MARGIN_DEN 5 326e92a4047SStephen Boyd 327*27850254SIskren Chernev /* slew_rate has units of uV/us. */ 328*27850254SIskren Chernev #define SPMI_HFSMPS_SLEW_RATE_38p4 38400 329*27850254SIskren Chernev 33042ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK 0x03 33142ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT 0 33242ba89c8SJeffrey Hugo 33342ba89c8SJeffrey Hugo /* Clock rate in kHz of the FTSMPS426 regulator reference clock. */ 33442ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_CLOCK_RATE 4800 33542ba89c8SJeffrey Hugo 3360211f68eSJorge Ramirez #define SPMI_HFS430_CLOCK_RATE 1600 3370211f68eSJorge Ramirez 33842ba89c8SJeffrey Hugo /* Minimum voltage stepper delay for each step. */ 33942ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_DELAY 2 34042ba89c8SJeffrey Hugo 34142ba89c8SJeffrey Hugo /* 34242ba89c8SJeffrey Hugo * The ratio SPMI_FTSMPS426_STEP_MARGIN_NUM/SPMI_FTSMPS426_STEP_MARGIN_DEN is 34342ba89c8SJeffrey Hugo * used to adjust the step rate in order to account for oscillator variance. 34442ba89c8SJeffrey Hugo */ 34542ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_MARGIN_NUM 10 34642ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_MARGIN_DEN 11 34742ba89c8SJeffrey Hugo 34842ba89c8SJeffrey Hugo 349e92a4047SStephen Boyd /* VSET value to decide the range of ULT SMPS */ 350e92a4047SStephen Boyd #define ULT_SMPS_RANGE_SPLIT 0x60 351e92a4047SStephen Boyd 352e92a4047SStephen Boyd /** 353e92a4047SStephen Boyd * struct spmi_voltage_range - regulator set point voltage mapping description 354e92a4047SStephen Boyd * @min_uV: Minimum programmable output voltage resulting from 355e92a4047SStephen Boyd * set point register value 0x00 356e92a4047SStephen Boyd * @max_uV: Maximum programmable output voltage 357e92a4047SStephen Boyd * @step_uV: Output voltage increase resulting from the set point 358e92a4047SStephen Boyd * register value increasing by 1 359e92a4047SStephen Boyd * @set_point_min_uV: Minimum allowed voltage 360e92a4047SStephen Boyd * @set_point_max_uV: Maximum allowed voltage. This may be tweaked in order 361e92a4047SStephen Boyd * to pick which range should be used in the case of 362e92a4047SStephen Boyd * overlapping set points. 363e92a4047SStephen Boyd * @n_voltages: Number of preferred voltage set points present in this 364e92a4047SStephen Boyd * range 365e92a4047SStephen Boyd * @range_sel: Voltage range register value corresponding to this range 366e92a4047SStephen Boyd * 367e92a4047SStephen Boyd * The following relationships must be true for the values used in this struct: 368e92a4047SStephen Boyd * (max_uV - min_uV) % step_uV == 0 369e92a4047SStephen Boyd * (set_point_min_uV - min_uV) % step_uV == 0* 370e92a4047SStephen Boyd * (set_point_max_uV - min_uV) % step_uV == 0* 371e92a4047SStephen Boyd * n_voltages = (set_point_max_uV - set_point_min_uV) / step_uV + 1 372e92a4047SStephen Boyd * 373e92a4047SStephen Boyd * *Note, set_point_min_uV == set_point_max_uV == 0 is allowed in order to 374e92a4047SStephen Boyd * specify that the voltage range has meaning, but is not preferred. 375e92a4047SStephen Boyd */ 376e92a4047SStephen Boyd struct spmi_voltage_range { 377e92a4047SStephen Boyd int min_uV; 378e92a4047SStephen Boyd int max_uV; 379e92a4047SStephen Boyd int step_uV; 380e92a4047SStephen Boyd int set_point_min_uV; 381e92a4047SStephen Boyd int set_point_max_uV; 382e92a4047SStephen Boyd unsigned n_voltages; 383e92a4047SStephen Boyd u8 range_sel; 384e92a4047SStephen Boyd }; 385e92a4047SStephen Boyd 386e92a4047SStephen Boyd /* 387e92a4047SStephen Boyd * The ranges specified in the spmi_voltage_set_points struct must be listed 388e92a4047SStephen Boyd * so that range[i].set_point_max_uV < range[i+1].set_point_min_uV. 389e92a4047SStephen Boyd */ 390e92a4047SStephen Boyd struct spmi_voltage_set_points { 391e92a4047SStephen Boyd struct spmi_voltage_range *range; 392e92a4047SStephen Boyd int count; 393e92a4047SStephen Boyd unsigned n_voltages; 394e92a4047SStephen Boyd }; 395e92a4047SStephen Boyd 396e92a4047SStephen Boyd struct spmi_regulator { 397e92a4047SStephen Boyd struct regulator_desc desc; 398e92a4047SStephen Boyd struct device *dev; 399e92a4047SStephen Boyd struct delayed_work ocp_work; 400e92a4047SStephen Boyd struct regmap *regmap; 401e92a4047SStephen Boyd struct spmi_voltage_set_points *set_points; 402e92a4047SStephen Boyd enum spmi_regulator_logical_type logical_type; 403e92a4047SStephen Boyd int ocp_irq; 404e92a4047SStephen Boyd int ocp_count; 405e92a4047SStephen Boyd int ocp_max_retries; 406e92a4047SStephen Boyd int ocp_retry_delay_ms; 407e92a4047SStephen Boyd int hpm_min_load; 408e92a4047SStephen Boyd int slew_rate; 409e92a4047SStephen Boyd ktime_t vs_enable_time; 410e92a4047SStephen Boyd u16 base; 411e92a4047SStephen Boyd struct list_head node; 412e92a4047SStephen Boyd }; 413e92a4047SStephen Boyd 414e92a4047SStephen Boyd struct spmi_regulator_mapping { 415e92a4047SStephen Boyd enum spmi_regulator_type type; 416e92a4047SStephen Boyd enum spmi_regulator_subtype subtype; 417e92a4047SStephen Boyd enum spmi_regulator_logical_type logical_type; 418e92a4047SStephen Boyd u32 revision_min; 419e92a4047SStephen Boyd u32 revision_max; 4203b619e3eSRikard Falkeborn const struct regulator_ops *ops; 421e92a4047SStephen Boyd struct spmi_voltage_set_points *set_points; 422e92a4047SStephen Boyd int hpm_min_load; 423e92a4047SStephen Boyd }; 424e92a4047SStephen Boyd 425e92a4047SStephen Boyd struct spmi_regulator_data { 426e92a4047SStephen Boyd const char *name; 427e92a4047SStephen Boyd u16 base; 428e92a4047SStephen Boyd const char *supply; 429e92a4047SStephen Boyd const char *ocp; 430e92a4047SStephen Boyd u16 force_type; 431e92a4047SStephen Boyd }; 432e92a4047SStephen Boyd 433e92a4047SStephen Boyd #define SPMI_VREG(_type, _subtype, _dig_major_min, _dig_major_max, \ 434e92a4047SStephen Boyd _logical_type, _ops_val, _set_points_val, _hpm_min_load) \ 435e92a4047SStephen Boyd { \ 436e92a4047SStephen Boyd .type = SPMI_REGULATOR_TYPE_##_type, \ 437e92a4047SStephen Boyd .subtype = SPMI_REGULATOR_SUBTYPE_##_subtype, \ 438e92a4047SStephen Boyd .revision_min = _dig_major_min, \ 439e92a4047SStephen Boyd .revision_max = _dig_major_max, \ 440e92a4047SStephen Boyd .logical_type = SPMI_REGULATOR_LOGICAL_TYPE_##_logical_type, \ 441e92a4047SStephen Boyd .ops = &spmi_##_ops_val##_ops, \ 442e92a4047SStephen Boyd .set_points = &_set_points_val##_set_points, \ 443e92a4047SStephen Boyd .hpm_min_load = _hpm_min_load, \ 444e92a4047SStephen Boyd } 445e92a4047SStephen Boyd 446e92a4047SStephen Boyd #define SPMI_VREG_VS(_subtype, _dig_major_min, _dig_major_max) \ 447e92a4047SStephen Boyd { \ 448e92a4047SStephen Boyd .type = SPMI_REGULATOR_TYPE_VS, \ 449e92a4047SStephen Boyd .subtype = SPMI_REGULATOR_SUBTYPE_##_subtype, \ 450e92a4047SStephen Boyd .revision_min = _dig_major_min, \ 451e92a4047SStephen Boyd .revision_max = _dig_major_max, \ 452e92a4047SStephen Boyd .logical_type = SPMI_REGULATOR_LOGICAL_TYPE_VS, \ 453e92a4047SStephen Boyd .ops = &spmi_vs_ops, \ 454e92a4047SStephen Boyd } 455e92a4047SStephen Boyd 456e92a4047SStephen Boyd #define SPMI_VOLTAGE_RANGE(_range_sel, _min_uV, _set_point_min_uV, \ 457e92a4047SStephen Boyd _set_point_max_uV, _max_uV, _step_uV) \ 458e92a4047SStephen Boyd { \ 459e92a4047SStephen Boyd .min_uV = _min_uV, \ 460e92a4047SStephen Boyd .max_uV = _max_uV, \ 461e92a4047SStephen Boyd .set_point_min_uV = _set_point_min_uV, \ 462e92a4047SStephen Boyd .set_point_max_uV = _set_point_max_uV, \ 463e92a4047SStephen Boyd .step_uV = _step_uV, \ 464e92a4047SStephen Boyd .range_sel = _range_sel, \ 465e92a4047SStephen Boyd } 466e92a4047SStephen Boyd 467e92a4047SStephen Boyd #define DEFINE_SPMI_SET_POINTS(name) \ 468e92a4047SStephen Boyd struct spmi_voltage_set_points name##_set_points = { \ 469e92a4047SStephen Boyd .range = name##_ranges, \ 470e92a4047SStephen Boyd .count = ARRAY_SIZE(name##_ranges), \ 471e92a4047SStephen Boyd } 472e92a4047SStephen Boyd 473e92a4047SStephen Boyd /* 474e92a4047SStephen Boyd * These tables contain the physically available PMIC regulator voltage setpoint 475e92a4047SStephen Boyd * ranges. Where two ranges overlap in hardware, one of the ranges is trimmed 476e92a4047SStephen Boyd * to ensure that the setpoints available to software are monotonically 477e92a4047SStephen Boyd * increasing and unique. The set_voltage callback functions expect these 478e92a4047SStephen Boyd * properties to hold. 479e92a4047SStephen Boyd */ 480e92a4047SStephen Boyd static struct spmi_voltage_range pldo_ranges[] = { 481e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500), 482e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(3, 1500000, 1550000, 3075000, 3075000, 25000), 483e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(4, 1750000, 3100000, 4900000, 4900000, 50000), 484e92a4047SStephen Boyd }; 485e92a4047SStephen Boyd 486e92a4047SStephen Boyd static struct spmi_voltage_range nldo1_ranges[] = { 487e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500), 488e92a4047SStephen Boyd }; 489e92a4047SStephen Boyd 490e92a4047SStephen Boyd static struct spmi_voltage_range nldo2_ranges[] = { 491e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 0, 0, 1537500, 12500), 492e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 375000, 375000, 768750, 768750, 6250), 493e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 775000, 1537500, 1537500, 12500), 494e92a4047SStephen Boyd }; 495e92a4047SStephen Boyd 496e92a4047SStephen Boyd static struct spmi_voltage_range nldo3_ranges[] = { 497e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500), 498e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 375000, 0, 0, 1537500, 12500), 499e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 0, 0, 1537500, 12500), 500e92a4047SStephen Boyd }; 501e92a4047SStephen Boyd 502e92a4047SStephen Boyd static struct spmi_voltage_range ln_ldo_ranges[] = { 503e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 690000, 690000, 1110000, 1110000, 60000), 504e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 1380000, 1380000, 2220000, 2220000, 120000), 505e92a4047SStephen Boyd }; 506e92a4047SStephen Boyd 507e92a4047SStephen Boyd static struct spmi_voltage_range smps_ranges[] = { 508e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500), 509e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 1550000, 1575000, 3125000, 3125000, 25000), 510e92a4047SStephen Boyd }; 511e92a4047SStephen Boyd 512e92a4047SStephen Boyd static struct spmi_voltage_range ftsmps_ranges[] = { 513e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 0, 350000, 1275000, 1275000, 5000), 514e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 0, 1280000, 2040000, 2040000, 10000), 515e92a4047SStephen Boyd }; 516e92a4047SStephen Boyd 517e92a4047SStephen Boyd static struct spmi_voltage_range ftsmps2p5_ranges[] = { 518e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 80000, 350000, 1355000, 1355000, 5000), 519e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 160000, 1360000, 2200000, 2200000, 10000), 520e92a4047SStephen Boyd }; 521e92a4047SStephen Boyd 52242ba89c8SJeffrey Hugo static struct spmi_voltage_range ftsmps426_ranges[] = { 52342ba89c8SJeffrey Hugo SPMI_VOLTAGE_RANGE(0, 0, 320000, 1352000, 1352000, 4000), 52442ba89c8SJeffrey Hugo }; 52542ba89c8SJeffrey Hugo 526e92a4047SStephen Boyd static struct spmi_voltage_range boost_ranges[] = { 527e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000), 528e92a4047SStephen Boyd }; 529e92a4047SStephen Boyd 530e92a4047SStephen Boyd static struct spmi_voltage_range boost_byp_ranges[] = { 531e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 2500000, 2500000, 5200000, 5650000, 50000), 532e92a4047SStephen Boyd }; 533e92a4047SStephen Boyd 534e92a4047SStephen Boyd static struct spmi_voltage_range ult_lo_smps_ranges[] = { 535e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500), 536e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 750000, 0, 0, 1525000, 25000), 537e92a4047SStephen Boyd }; 538e92a4047SStephen Boyd 539e92a4047SStephen Boyd static struct spmi_voltage_range ult_ho_smps_ranges[] = { 540e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 1550000, 1550000, 2325000, 2325000, 25000), 541e92a4047SStephen Boyd }; 542e92a4047SStephen Boyd 543e92a4047SStephen Boyd static struct spmi_voltage_range ult_nldo_ranges[] = { 544e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500), 545e92a4047SStephen Boyd }; 546e92a4047SStephen Boyd 547e92a4047SStephen Boyd static struct spmi_voltage_range ult_pldo_ranges[] = { 548e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500), 549e92a4047SStephen Boyd }; 550e92a4047SStephen Boyd 551328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range pldo660_ranges[] = { 552328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 3544000, 3544000, 8000), 553328816c2SAngeloGioacchino Del Regno }; 554328816c2SAngeloGioacchino Del Regno 555328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range nldo660_ranges[] = { 556328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 320000, 320000, 1304000, 1304000, 8000), 557328816c2SAngeloGioacchino Del Regno }; 558328816c2SAngeloGioacchino Del Regno 559328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range ht_lvpldo_ranges[] = { 560328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 2000000, 2000000, 8000), 561328816c2SAngeloGioacchino Del Regno }; 562328816c2SAngeloGioacchino Del Regno 563328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range ht_nldo_ranges[] = { 564328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 312000, 312000, 1304000, 1304000, 8000), 565328816c2SAngeloGioacchino Del Regno }; 566328816c2SAngeloGioacchino Del Regno 5670211f68eSJorge Ramirez static struct spmi_voltage_range hfs430_ranges[] = { 5680211f68eSJorge Ramirez SPMI_VOLTAGE_RANGE(0, 320000, 320000, 2040000, 2040000, 8000), 5690211f68eSJorge Ramirez }; 5700211f68eSJorge Ramirez 57100f6ebbdSRobert Marko static struct spmi_voltage_range ht_p150_ranges[] = { 57200f6ebbdSRobert Marko SPMI_VOLTAGE_RANGE(0, 1616000, 1616000, 3304000, 3304000, 8000), 57300f6ebbdSRobert Marko }; 57400f6ebbdSRobert Marko 5753d04ae8eSRobert Marko static struct spmi_voltage_range ht_p600_ranges[] = { 5763d04ae8eSRobert Marko SPMI_VOLTAGE_RANGE(0, 1704000, 1704000, 1896000, 1896000, 8000), 5773d04ae8eSRobert Marko }; 5783d04ae8eSRobert Marko 579e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(pldo); 580e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo1); 581e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo2); 582e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo3); 583e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ln_ldo); 584e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(smps); 585e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ftsmps); 586e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ftsmps2p5); 58742ba89c8SJeffrey Hugo static DEFINE_SPMI_SET_POINTS(ftsmps426); 588e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(boost); 589e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(boost_byp); 590e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_lo_smps); 591e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_ho_smps); 592e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_nldo); 593e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_pldo); 594328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(pldo660); 595328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(nldo660); 596328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(ht_lvpldo); 597328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(ht_nldo); 5980211f68eSJorge Ramirez static DEFINE_SPMI_SET_POINTS(hfs430); 59900f6ebbdSRobert Marko static DEFINE_SPMI_SET_POINTS(ht_p150); 6003d04ae8eSRobert Marko static DEFINE_SPMI_SET_POINTS(ht_p600); 601e92a4047SStephen Boyd 602e92a4047SStephen Boyd static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf, 603e92a4047SStephen Boyd int len) 604e92a4047SStephen Boyd { 605e92a4047SStephen Boyd return regmap_bulk_read(vreg->regmap, vreg->base + addr, buf, len); 606e92a4047SStephen Boyd } 607e92a4047SStephen Boyd 608e92a4047SStephen Boyd static inline int spmi_vreg_write(struct spmi_regulator *vreg, u16 addr, 609e92a4047SStephen Boyd u8 *buf, int len) 610e92a4047SStephen Boyd { 611e92a4047SStephen Boyd return regmap_bulk_write(vreg->regmap, vreg->base + addr, buf, len); 612e92a4047SStephen Boyd } 613e92a4047SStephen Boyd 614e92a4047SStephen Boyd static int spmi_vreg_update_bits(struct spmi_regulator *vreg, u16 addr, u8 val, 615e92a4047SStephen Boyd u8 mask) 616e92a4047SStephen Boyd { 617e92a4047SStephen Boyd return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val); 618e92a4047SStephen Boyd } 619e92a4047SStephen Boyd 620e92a4047SStephen Boyd static int spmi_regulator_vs_enable(struct regulator_dev *rdev) 621e92a4047SStephen Boyd { 622e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 623e92a4047SStephen Boyd 624e92a4047SStephen Boyd if (vreg->ocp_irq) { 625e92a4047SStephen Boyd vreg->ocp_count = 0; 626e92a4047SStephen Boyd vreg->vs_enable_time = ktime_get(); 627e92a4047SStephen Boyd } 628e92a4047SStephen Boyd 6299d485332SAxel Lin return regulator_enable_regmap(rdev); 630e92a4047SStephen Boyd } 631e92a4047SStephen Boyd 63289a6a5e5SMatti Vaittinen static int spmi_regulator_vs_ocp(struct regulator_dev *rdev, int lim_uA, 63389a6a5e5SMatti Vaittinen int severity, bool enable) 634e2adfacdSStephen Boyd { 635e2adfacdSStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 636e2adfacdSStephen Boyd u8 reg = SPMI_VS_OCP_OVERRIDE; 637e2adfacdSStephen Boyd 63889a6a5e5SMatti Vaittinen if (lim_uA || !enable || severity != REGULATOR_SEVERITY_PROT) 63989a6a5e5SMatti Vaittinen return -EINVAL; 64089a6a5e5SMatti Vaittinen 641e2adfacdSStephen Boyd return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, ®, 1); 642e2adfacdSStephen Boyd } 643e2adfacdSStephen Boyd 644e92a4047SStephen Boyd static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, 6451b5b1968SStephen Boyd int min_uV, int max_uV) 646e92a4047SStephen Boyd { 647e92a4047SStephen Boyd const struct spmi_voltage_range *range; 648e92a4047SStephen Boyd int uV = min_uV; 649e92a4047SStephen Boyd int lim_min_uV, lim_max_uV, i, range_id, range_max_uV; 6501b5b1968SStephen Boyd int selector, voltage_sel; 651e92a4047SStephen Boyd 652e92a4047SStephen Boyd /* Check if request voltage is outside of physically settable range. */ 653e92a4047SStephen Boyd lim_min_uV = vreg->set_points->range[0].set_point_min_uV; 654e92a4047SStephen Boyd lim_max_uV = 655e92a4047SStephen Boyd vreg->set_points->range[vreg->set_points->count - 1].set_point_max_uV; 656e92a4047SStephen Boyd 657e92a4047SStephen Boyd if (uV < lim_min_uV && max_uV >= lim_min_uV) 658e92a4047SStephen Boyd uV = lim_min_uV; 659e92a4047SStephen Boyd 660e92a4047SStephen Boyd if (uV < lim_min_uV || uV > lim_max_uV) { 661e92a4047SStephen Boyd dev_err(vreg->dev, 662e92a4047SStephen Boyd "request v=[%d, %d] is outside possible v=[%d, %d]\n", 663e92a4047SStephen Boyd min_uV, max_uV, lim_min_uV, lim_max_uV); 664e92a4047SStephen Boyd return -EINVAL; 665e92a4047SStephen Boyd } 666e92a4047SStephen Boyd 667e92a4047SStephen Boyd /* Find the range which uV is inside of. */ 668e92a4047SStephen Boyd for (i = vreg->set_points->count - 1; i > 0; i--) { 669e92a4047SStephen Boyd range_max_uV = vreg->set_points->range[i - 1].set_point_max_uV; 670e92a4047SStephen Boyd if (uV > range_max_uV && range_max_uV > 0) 671e92a4047SStephen Boyd break; 672e92a4047SStephen Boyd } 673e92a4047SStephen Boyd 674e92a4047SStephen Boyd range_id = i; 675e92a4047SStephen Boyd range = &vreg->set_points->range[range_id]; 676e92a4047SStephen Boyd 677e92a4047SStephen Boyd /* 678e92a4047SStephen Boyd * Force uV to be an allowed set point by applying a ceiling function to 679e92a4047SStephen Boyd * the uV value. 680e92a4047SStephen Boyd */ 6811b5b1968SStephen Boyd voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); 6821b5b1968SStephen Boyd uV = voltage_sel * range->step_uV + range->min_uV; 683e92a4047SStephen Boyd 684e92a4047SStephen Boyd if (uV > max_uV) { 685e92a4047SStephen Boyd dev_err(vreg->dev, 686e92a4047SStephen Boyd "request v=[%d, %d] cannot be met by any set point; " 687e92a4047SStephen Boyd "next set point: %d\n", 688e92a4047SStephen Boyd min_uV, max_uV, uV); 689e92a4047SStephen Boyd return -EINVAL; 690e92a4047SStephen Boyd } 691e92a4047SStephen Boyd 6921b5b1968SStephen Boyd selector = 0; 693e92a4047SStephen Boyd for (i = 0; i < range_id; i++) 6941b5b1968SStephen Boyd selector += vreg->set_points->range[i].n_voltages; 6951b5b1968SStephen Boyd selector += (uV - range->set_point_min_uV) / range->step_uV; 696e92a4047SStephen Boyd 6971b5b1968SStephen Boyd return selector; 6981b5b1968SStephen Boyd } 6991b5b1968SStephen Boyd 7001b5b1968SStephen Boyd static int spmi_sw_selector_to_hw(struct spmi_regulator *vreg, 7011b5b1968SStephen Boyd unsigned selector, u8 *range_sel, 7021b5b1968SStephen Boyd u8 *voltage_sel) 7031b5b1968SStephen Boyd { 7041b5b1968SStephen Boyd const struct spmi_voltage_range *range, *end; 705ab953b9dSStephen Boyd unsigned offset; 7061b5b1968SStephen Boyd 7071b5b1968SStephen Boyd range = vreg->set_points->range; 7081b5b1968SStephen Boyd end = range + vreg->set_points->count; 7091b5b1968SStephen Boyd 7101b5b1968SStephen Boyd for (; range < end; range++) { 7111b5b1968SStephen Boyd if (selector < range->n_voltages) { 712ab953b9dSStephen Boyd /* 713ab953b9dSStephen Boyd * hardware selectors between set point min and real 714ab953b9dSStephen Boyd * min are invalid so we ignore them 715ab953b9dSStephen Boyd */ 716ab953b9dSStephen Boyd offset = range->set_point_min_uV - range->min_uV; 717ab953b9dSStephen Boyd offset /= range->step_uV; 718ab953b9dSStephen Boyd *voltage_sel = selector + offset; 7191b5b1968SStephen Boyd *range_sel = range->range_sel; 720e92a4047SStephen Boyd return 0; 721e92a4047SStephen Boyd } 722e92a4047SStephen Boyd 7231b5b1968SStephen Boyd selector -= range->n_voltages; 7241b5b1968SStephen Boyd } 7251b5b1968SStephen Boyd 7261b5b1968SStephen Boyd return -EINVAL; 7271b5b1968SStephen Boyd } 7281b5b1968SStephen Boyd 7291b5b1968SStephen Boyd static int spmi_hw_selector_to_sw(struct spmi_regulator *vreg, u8 hw_sel, 7301b5b1968SStephen Boyd const struct spmi_voltage_range *range) 7311b5b1968SStephen Boyd { 732ab953b9dSStephen Boyd unsigned sw_sel = 0; 733ab953b9dSStephen Boyd unsigned offset, max_hw_sel; 7341b5b1968SStephen Boyd const struct spmi_voltage_range *r = vreg->set_points->range; 735ab953b9dSStephen Boyd const struct spmi_voltage_range *end = r + vreg->set_points->count; 7361b5b1968SStephen Boyd 737ab953b9dSStephen Boyd for (; r < end; r++) { 738ab953b9dSStephen Boyd if (r == range && range->n_voltages) { 739ab953b9dSStephen Boyd /* 740ab953b9dSStephen Boyd * hardware selectors between set point min and real 741ab953b9dSStephen Boyd * min and between set point max and real max are 742ab953b9dSStephen Boyd * invalid so we return an error if they're 743ab953b9dSStephen Boyd * programmed into the hardware 744ab953b9dSStephen Boyd */ 745ab953b9dSStephen Boyd offset = range->set_point_min_uV - range->min_uV; 746ab953b9dSStephen Boyd offset /= range->step_uV; 747ab953b9dSStephen Boyd if (hw_sel < offset) 748ab953b9dSStephen Boyd return -EINVAL; 749ab953b9dSStephen Boyd 750ab953b9dSStephen Boyd max_hw_sel = range->set_point_max_uV - range->min_uV; 751ab953b9dSStephen Boyd max_hw_sel /= range->step_uV; 752ab953b9dSStephen Boyd if (hw_sel > max_hw_sel) 753ab953b9dSStephen Boyd return -EINVAL; 754ab953b9dSStephen Boyd 755ab953b9dSStephen Boyd return sw_sel + hw_sel - offset; 756ab953b9dSStephen Boyd } 7571b5b1968SStephen Boyd sw_sel += r->n_voltages; 7581b5b1968SStephen Boyd } 7591b5b1968SStephen Boyd 760ab953b9dSStephen Boyd return -EINVAL; 7611b5b1968SStephen Boyd } 7621b5b1968SStephen Boyd 763e92a4047SStephen Boyd static const struct spmi_voltage_range * 764e92a4047SStephen Boyd spmi_regulator_find_range(struct spmi_regulator *vreg) 765e92a4047SStephen Boyd { 766e92a4047SStephen Boyd u8 range_sel; 767e92a4047SStephen Boyd const struct spmi_voltage_range *range, *end; 768e92a4047SStephen Boyd 769e92a4047SStephen Boyd range = vreg->set_points->range; 770e92a4047SStephen Boyd end = range + vreg->set_points->count; 771e92a4047SStephen Boyd 772e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, &range_sel, 1); 773e92a4047SStephen Boyd 774e92a4047SStephen Boyd for (; range < end; range++) 775e92a4047SStephen Boyd if (range->range_sel == range_sel) 776e92a4047SStephen Boyd return range; 777e92a4047SStephen Boyd 778e92a4047SStephen Boyd return NULL; 779e92a4047SStephen Boyd } 780e92a4047SStephen Boyd 781e92a4047SStephen Boyd static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg, 7821b5b1968SStephen Boyd int min_uV, int max_uV) 783e92a4047SStephen Boyd { 784e92a4047SStephen Boyd const struct spmi_voltage_range *range; 785e92a4047SStephen Boyd int uV = min_uV; 7861b5b1968SStephen Boyd int i, selector; 787e92a4047SStephen Boyd 788e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 789e92a4047SStephen Boyd if (!range) 790e92a4047SStephen Boyd goto different_range; 791e92a4047SStephen Boyd 792e92a4047SStephen Boyd if (uV < range->min_uV && max_uV >= range->min_uV) 793e92a4047SStephen Boyd uV = range->min_uV; 794e92a4047SStephen Boyd 795e92a4047SStephen Boyd if (uV < range->min_uV || uV > range->max_uV) { 796e92a4047SStephen Boyd /* Current range doesn't support the requested voltage. */ 797e92a4047SStephen Boyd goto different_range; 798e92a4047SStephen Boyd } 799e92a4047SStephen Boyd 800e92a4047SStephen Boyd /* 801e92a4047SStephen Boyd * Force uV to be an allowed set point by applying a ceiling function to 802e92a4047SStephen Boyd * the uV value. 803e92a4047SStephen Boyd */ 8041b5b1968SStephen Boyd uV = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); 8051b5b1968SStephen Boyd uV = uV * range->step_uV + range->min_uV; 806e92a4047SStephen Boyd 807e92a4047SStephen Boyd if (uV > max_uV) { 808e92a4047SStephen Boyd /* 809e92a4047SStephen Boyd * No set point in the current voltage range is within the 810e92a4047SStephen Boyd * requested min_uV to max_uV range. 811e92a4047SStephen Boyd */ 812e92a4047SStephen Boyd goto different_range; 813e92a4047SStephen Boyd } 814e92a4047SStephen Boyd 8151b5b1968SStephen Boyd selector = 0; 816e92a4047SStephen Boyd for (i = 0; i < vreg->set_points->count; i++) { 817e92a4047SStephen Boyd if (uV >= vreg->set_points->range[i].set_point_min_uV 8189b2dfee3SStephen Boyd && uV <= vreg->set_points->range[i].set_point_max_uV) { 8191b5b1968SStephen Boyd selector += 820e92a4047SStephen Boyd (uV - vreg->set_points->range[i].set_point_min_uV) 821e92a4047SStephen Boyd / vreg->set_points->range[i].step_uV; 822e92a4047SStephen Boyd break; 8239b2dfee3SStephen Boyd } 824e92a4047SStephen Boyd 8251b5b1968SStephen Boyd selector += vreg->set_points->range[i].n_voltages; 826e92a4047SStephen Boyd } 827e92a4047SStephen Boyd 8281b5b1968SStephen Boyd if (selector >= vreg->set_points->n_voltages) 829e92a4047SStephen Boyd goto different_range; 830e92a4047SStephen Boyd 831b1d21a24SStephen Boyd return selector; 832e92a4047SStephen Boyd 833e92a4047SStephen Boyd different_range: 8341b5b1968SStephen Boyd return spmi_regulator_select_voltage(vreg, min_uV, max_uV); 835e92a4047SStephen Boyd } 836e92a4047SStephen Boyd 8371b5b1968SStephen Boyd static int spmi_regulator_common_map_voltage(struct regulator_dev *rdev, 8381b5b1968SStephen Boyd int min_uV, int max_uV) 8391b5b1968SStephen Boyd { 8401b5b1968SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 8411b5b1968SStephen Boyd 8421b5b1968SStephen Boyd /* 8431b5b1968SStephen Boyd * Favor staying in the current voltage range if possible. This avoids 8441b5b1968SStephen Boyd * voltage spikes that occur when changing the voltage range. 8451b5b1968SStephen Boyd */ 8461b5b1968SStephen Boyd return spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV); 8471b5b1968SStephen Boyd } 8481b5b1968SStephen Boyd 8491b5b1968SStephen Boyd static int 8501b5b1968SStephen Boyd spmi_regulator_common_set_voltage(struct regulator_dev *rdev, unsigned selector) 851e92a4047SStephen Boyd { 852e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 853e92a4047SStephen Boyd int ret; 854e92a4047SStephen Boyd u8 buf[2]; 855e92a4047SStephen Boyd u8 range_sel, voltage_sel; 856e92a4047SStephen Boyd 8571b5b1968SStephen Boyd ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); 858e92a4047SStephen Boyd if (ret) 859e92a4047SStephen Boyd return ret; 860e92a4047SStephen Boyd 861e92a4047SStephen Boyd buf[0] = range_sel; 862e92a4047SStephen Boyd buf[1] = voltage_sel; 863e92a4047SStephen Boyd return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2); 864e92a4047SStephen Boyd } 865e92a4047SStephen Boyd 86642ba89c8SJeffrey Hugo static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev, 86742ba89c8SJeffrey Hugo unsigned selector); 86842ba89c8SJeffrey Hugo 86942ba89c8SJeffrey Hugo static int spmi_regulator_ftsmps426_set_voltage(struct regulator_dev *rdev, 87042ba89c8SJeffrey Hugo unsigned selector) 87142ba89c8SJeffrey Hugo { 87242ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 87342ba89c8SJeffrey Hugo u8 buf[2]; 87442ba89c8SJeffrey Hugo int mV; 87542ba89c8SJeffrey Hugo 87642ba89c8SJeffrey Hugo mV = spmi_regulator_common_list_voltage(rdev, selector) / 1000; 87742ba89c8SJeffrey Hugo 87842ba89c8SJeffrey Hugo buf[0] = mV & 0xff; 87942ba89c8SJeffrey Hugo buf[1] = mV >> 8; 88042ba89c8SJeffrey Hugo return spmi_vreg_write(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2); 88142ba89c8SJeffrey Hugo } 88242ba89c8SJeffrey Hugo 883e92a4047SStephen Boyd static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev, 884e92a4047SStephen Boyd unsigned int old_selector, unsigned int new_selector) 885e92a4047SStephen Boyd { 886e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 887e92a4047SStephen Boyd int diff_uV; 888e92a4047SStephen Boyd 88961d7fdc4SJeffrey Hugo diff_uV = abs(spmi_regulator_common_list_voltage(rdev, new_selector) - 89061d7fdc4SJeffrey Hugo spmi_regulator_common_list_voltage(rdev, old_selector)); 891e92a4047SStephen Boyd 892e92a4047SStephen Boyd return DIV_ROUND_UP(diff_uV, vreg->slew_rate); 893e92a4047SStephen Boyd } 894e92a4047SStephen Boyd 895e92a4047SStephen Boyd static int spmi_regulator_common_get_voltage(struct regulator_dev *rdev) 896e92a4047SStephen Boyd { 897e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 898e92a4047SStephen Boyd const struct spmi_voltage_range *range; 899e92a4047SStephen Boyd u8 voltage_sel; 900e92a4047SStephen Boyd 901e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); 902e92a4047SStephen Boyd 903e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 904e92a4047SStephen Boyd if (!range) 9051b5b1968SStephen Boyd return -EINVAL; 906e92a4047SStephen Boyd 9071b5b1968SStephen Boyd return spmi_hw_selector_to_sw(vreg, voltage_sel, range); 9081b5b1968SStephen Boyd } 9091b5b1968SStephen Boyd 91042ba89c8SJeffrey Hugo static int spmi_regulator_ftsmps426_get_voltage(struct regulator_dev *rdev) 91142ba89c8SJeffrey Hugo { 91242ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 91342ba89c8SJeffrey Hugo const struct spmi_voltage_range *range; 91442ba89c8SJeffrey Hugo u8 buf[2]; 91542ba89c8SJeffrey Hugo int uV; 91642ba89c8SJeffrey Hugo 91742ba89c8SJeffrey Hugo spmi_vreg_read(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2); 91842ba89c8SJeffrey Hugo 91942ba89c8SJeffrey Hugo uV = (((unsigned int)buf[1] << 8) | (unsigned int)buf[0]) * 1000; 92042ba89c8SJeffrey Hugo range = vreg->set_points->range; 92142ba89c8SJeffrey Hugo 92242ba89c8SJeffrey Hugo return (uV - range->set_point_min_uV) / range->step_uV; 92342ba89c8SJeffrey Hugo } 92442ba89c8SJeffrey Hugo 9251b5b1968SStephen Boyd static int spmi_regulator_single_map_voltage(struct regulator_dev *rdev, 9261b5b1968SStephen Boyd int min_uV, int max_uV) 9271b5b1968SStephen Boyd { 9281b5b1968SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 9291b5b1968SStephen Boyd 9301b5b1968SStephen Boyd return spmi_regulator_select_voltage(vreg, min_uV, max_uV); 931e92a4047SStephen Boyd } 932e92a4047SStephen Boyd 933e92a4047SStephen Boyd static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev, 9341b5b1968SStephen Boyd unsigned selector) 935e92a4047SStephen Boyd { 936e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 9371b5b1968SStephen Boyd u8 sel = selector; 938e92a4047SStephen Boyd 939e92a4047SStephen Boyd /* 940e92a4047SStephen Boyd * Certain types of regulators do not have a range select register so 941e92a4047SStephen Boyd * only voltage set register needs to be written. 942e92a4047SStephen Boyd */ 943e92a4047SStephen Boyd return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &sel, 1); 944e92a4047SStephen Boyd } 945e92a4047SStephen Boyd 946e92a4047SStephen Boyd static int spmi_regulator_single_range_get_voltage(struct regulator_dev *rdev) 947e92a4047SStephen Boyd { 948e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 9491b5b1968SStephen Boyd u8 selector; 9501b5b1968SStephen Boyd int ret; 951e92a4047SStephen Boyd 9521b5b1968SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &selector, 1); 9531b5b1968SStephen Boyd if (ret) 9541b5b1968SStephen Boyd return ret; 955e92a4047SStephen Boyd 9561b5b1968SStephen Boyd return selector; 957e92a4047SStephen Boyd } 958e92a4047SStephen Boyd 959e92a4047SStephen Boyd static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev, 9601b5b1968SStephen Boyd unsigned selector) 961e92a4047SStephen Boyd { 962e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 963e92a4047SStephen Boyd int ret; 964e92a4047SStephen Boyd u8 range_sel, voltage_sel; 965e92a4047SStephen Boyd 9661b5b1968SStephen Boyd ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); 967e92a4047SStephen Boyd if (ret) 968e92a4047SStephen Boyd return ret; 969e92a4047SStephen Boyd 970e92a4047SStephen Boyd /* 971e92a4047SStephen Boyd * Calculate VSET based on range 972e92a4047SStephen Boyd * In case of range 0: voltage_sel is a 7 bit value, can be written 973e92a4047SStephen Boyd * witout any modification. 974e92a4047SStephen Boyd * In case of range 1: voltage_sel is a 5 bit value, bits[7-5] set to 975e92a4047SStephen Boyd * [011]. 976e92a4047SStephen Boyd */ 977e92a4047SStephen Boyd if (range_sel == 1) 978e92a4047SStephen Boyd voltage_sel |= ULT_SMPS_RANGE_SPLIT; 979e92a4047SStephen Boyd 9800f94bffaSJulia Lawall return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET, 981e92a4047SStephen Boyd voltage_sel, 0xff); 982e92a4047SStephen Boyd } 983e92a4047SStephen Boyd 984e92a4047SStephen Boyd static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev) 985e92a4047SStephen Boyd { 986e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 987e92a4047SStephen Boyd const struct spmi_voltage_range *range; 988e92a4047SStephen Boyd u8 voltage_sel; 989e92a4047SStephen Boyd 990e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); 991e92a4047SStephen Boyd 992e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 993e92a4047SStephen Boyd if (!range) 9941b5b1968SStephen Boyd return -EINVAL; 995e92a4047SStephen Boyd 996e92a4047SStephen Boyd if (range->range_sel == 1) 997e92a4047SStephen Boyd voltage_sel &= ~ULT_SMPS_RANGE_SPLIT; 998e92a4047SStephen Boyd 9991b5b1968SStephen Boyd return spmi_hw_selector_to_sw(vreg, voltage_sel, range); 1000e92a4047SStephen Boyd } 1001e92a4047SStephen Boyd 1002e92a4047SStephen Boyd static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev, 1003e92a4047SStephen Boyd unsigned selector) 1004e92a4047SStephen Boyd { 1005e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1006e92a4047SStephen Boyd int uV = 0; 1007e92a4047SStephen Boyd int i; 1008e92a4047SStephen Boyd 1009e92a4047SStephen Boyd if (selector >= vreg->set_points->n_voltages) 1010e92a4047SStephen Boyd return 0; 1011e92a4047SStephen Boyd 1012e92a4047SStephen Boyd for (i = 0; i < vreg->set_points->count; i++) { 10139b2dfee3SStephen Boyd if (selector < vreg->set_points->range[i].n_voltages) { 1014e92a4047SStephen Boyd uV = selector * vreg->set_points->range[i].step_uV 1015e92a4047SStephen Boyd + vreg->set_points->range[i].set_point_min_uV; 1016e92a4047SStephen Boyd break; 10179b2dfee3SStephen Boyd } 1018e92a4047SStephen Boyd 1019e92a4047SStephen Boyd selector -= vreg->set_points->range[i].n_voltages; 1020e92a4047SStephen Boyd } 1021e92a4047SStephen Boyd 1022e92a4047SStephen Boyd return uV; 1023e92a4047SStephen Boyd } 1024e92a4047SStephen Boyd 1025e92a4047SStephen Boyd static int 1026e92a4047SStephen Boyd spmi_regulator_common_set_bypass(struct regulator_dev *rdev, bool enable) 1027e92a4047SStephen Boyd { 1028e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1029e92a4047SStephen Boyd u8 mask = SPMI_COMMON_MODE_BYPASS_MASK; 1030e92a4047SStephen Boyd u8 val = 0; 1031e92a4047SStephen Boyd 1032e92a4047SStephen Boyd if (enable) 1033e92a4047SStephen Boyd val = mask; 1034e92a4047SStephen Boyd 1035e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 1036e92a4047SStephen Boyd } 1037e92a4047SStephen Boyd 1038e92a4047SStephen Boyd static int 1039e92a4047SStephen Boyd spmi_regulator_common_get_bypass(struct regulator_dev *rdev, bool *enable) 1040e92a4047SStephen Boyd { 1041e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1042e92a4047SStephen Boyd u8 val; 1043e92a4047SStephen Boyd int ret; 1044e92a4047SStephen Boyd 1045e92a4047SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &val, 1); 1046e92a4047SStephen Boyd *enable = val & SPMI_COMMON_MODE_BYPASS_MASK; 1047e92a4047SStephen Boyd 1048e92a4047SStephen Boyd return ret; 1049e92a4047SStephen Boyd } 1050e92a4047SStephen Boyd 1051e92a4047SStephen Boyd static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev) 1052e92a4047SStephen Boyd { 1053e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1054e92a4047SStephen Boyd u8 reg; 1055e92a4047SStephen Boyd 1056e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); 1057e92a4047SStephen Boyd 1058ba576a62SJeffrey Hugo reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; 1059ba576a62SJeffrey Hugo 1060ba576a62SJeffrey Hugo switch (reg) { 1061ba576a62SJeffrey Hugo case SPMI_COMMON_MODE_HPM_MASK: 1062e92a4047SStephen Boyd return REGULATOR_MODE_NORMAL; 1063ba576a62SJeffrey Hugo case SPMI_COMMON_MODE_AUTO_MASK: 1064e2adfacdSStephen Boyd return REGULATOR_MODE_FAST; 1065ba576a62SJeffrey Hugo default: 1066e92a4047SStephen Boyd return REGULATOR_MODE_IDLE; 1067e92a4047SStephen Boyd } 1068ba576a62SJeffrey Hugo } 1069e92a4047SStephen Boyd 107042ba89c8SJeffrey Hugo static unsigned int spmi_regulator_ftsmps426_get_mode(struct regulator_dev *rdev) 107142ba89c8SJeffrey Hugo { 107242ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 107342ba89c8SJeffrey Hugo u8 reg; 107442ba89c8SJeffrey Hugo 107542ba89c8SJeffrey Hugo spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); 107642ba89c8SJeffrey Hugo 107742ba89c8SJeffrey Hugo switch (reg) { 107842ba89c8SJeffrey Hugo case SPMI_FTSMPS426_MODE_HPM_MASK: 107942ba89c8SJeffrey Hugo return REGULATOR_MODE_NORMAL; 108042ba89c8SJeffrey Hugo case SPMI_FTSMPS426_MODE_AUTO_MASK: 108142ba89c8SJeffrey Hugo return REGULATOR_MODE_FAST; 108242ba89c8SJeffrey Hugo default: 108342ba89c8SJeffrey Hugo return REGULATOR_MODE_IDLE; 108442ba89c8SJeffrey Hugo } 108542ba89c8SJeffrey Hugo } 108642ba89c8SJeffrey Hugo 1087*27850254SIskren Chernev static unsigned int spmi_regulator_hfsmps_get_mode(struct regulator_dev *rdev) 1088*27850254SIskren Chernev { 1089*27850254SIskren Chernev struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1090*27850254SIskren Chernev u8 reg; 1091*27850254SIskren Chernev 1092*27850254SIskren Chernev spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); 1093*27850254SIskren Chernev 1094*27850254SIskren Chernev switch (reg) { 1095*27850254SIskren Chernev case SPMI_HFSMPS_MODE_HPM_MASK: 1096*27850254SIskren Chernev return REGULATOR_MODE_NORMAL; 1097*27850254SIskren Chernev case SPMI_HFSMPS_MODE_AUTO_MASK: 1098*27850254SIskren Chernev return REGULATOR_MODE_FAST; 1099*27850254SIskren Chernev default: 1100*27850254SIskren Chernev return REGULATOR_MODE_IDLE; 1101*27850254SIskren Chernev } 1102*27850254SIskren Chernev } 1103*27850254SIskren Chernev 1104e92a4047SStephen Boyd static int 1105e92a4047SStephen Boyd spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) 1106e92a4047SStephen Boyd { 1107e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1108e2adfacdSStephen Boyd u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; 1109ba576a62SJeffrey Hugo u8 val; 1110e92a4047SStephen Boyd 1111ba576a62SJeffrey Hugo switch (mode) { 1112ba576a62SJeffrey Hugo case REGULATOR_MODE_NORMAL: 1113e2adfacdSStephen Boyd val = SPMI_COMMON_MODE_HPM_MASK; 1114ba576a62SJeffrey Hugo break; 1115ba576a62SJeffrey Hugo case REGULATOR_MODE_FAST: 1116e2adfacdSStephen Boyd val = SPMI_COMMON_MODE_AUTO_MASK; 1117ba576a62SJeffrey Hugo break; 1118ba576a62SJeffrey Hugo default: 1119ba576a62SJeffrey Hugo val = 0; 1120ba576a62SJeffrey Hugo break; 1121ba576a62SJeffrey Hugo } 1122e92a4047SStephen Boyd 1123e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 1124e92a4047SStephen Boyd } 1125e92a4047SStephen Boyd 1126e92a4047SStephen Boyd static int 112742ba89c8SJeffrey Hugo spmi_regulator_ftsmps426_set_mode(struct regulator_dev *rdev, unsigned int mode) 112842ba89c8SJeffrey Hugo { 112942ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 113042ba89c8SJeffrey Hugo u8 mask = SPMI_FTSMPS426_MODE_MASK; 113142ba89c8SJeffrey Hugo u8 val; 113242ba89c8SJeffrey Hugo 113342ba89c8SJeffrey Hugo switch (mode) { 113442ba89c8SJeffrey Hugo case REGULATOR_MODE_NORMAL: 113542ba89c8SJeffrey Hugo val = SPMI_FTSMPS426_MODE_HPM_MASK; 113642ba89c8SJeffrey Hugo break; 113742ba89c8SJeffrey Hugo case REGULATOR_MODE_FAST: 113842ba89c8SJeffrey Hugo val = SPMI_FTSMPS426_MODE_AUTO_MASK; 113942ba89c8SJeffrey Hugo break; 114042ba89c8SJeffrey Hugo case REGULATOR_MODE_IDLE: 114142ba89c8SJeffrey Hugo val = SPMI_FTSMPS426_MODE_LPM_MASK; 114242ba89c8SJeffrey Hugo break; 114342ba89c8SJeffrey Hugo default: 114442ba89c8SJeffrey Hugo return -EINVAL; 114542ba89c8SJeffrey Hugo } 114642ba89c8SJeffrey Hugo 114742ba89c8SJeffrey Hugo return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 114842ba89c8SJeffrey Hugo } 114942ba89c8SJeffrey Hugo 115042ba89c8SJeffrey Hugo static int 1151*27850254SIskren Chernev spmi_regulator_hfsmps_set_mode(struct regulator_dev *rdev, unsigned int mode) 1152*27850254SIskren Chernev { 1153*27850254SIskren Chernev struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1154*27850254SIskren Chernev u8 mask = SPMI_HFSMPS_MODE_MASK; 1155*27850254SIskren Chernev u8 val; 1156*27850254SIskren Chernev 1157*27850254SIskren Chernev switch (mode) { 1158*27850254SIskren Chernev case REGULATOR_MODE_NORMAL: 1159*27850254SIskren Chernev val = SPMI_HFSMPS_MODE_HPM_MASK; 1160*27850254SIskren Chernev break; 1161*27850254SIskren Chernev case REGULATOR_MODE_FAST: 1162*27850254SIskren Chernev val = SPMI_HFSMPS_MODE_AUTO_MASK; 1163*27850254SIskren Chernev break; 1164*27850254SIskren Chernev case REGULATOR_MODE_IDLE: 1165*27850254SIskren Chernev val = SPMI_HFSMPS_MODE_LPM_MASK; 1166*27850254SIskren Chernev break; 1167*27850254SIskren Chernev default: 1168*27850254SIskren Chernev return -EINVAL; 1169*27850254SIskren Chernev } 1170*27850254SIskren Chernev 1171*27850254SIskren Chernev return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 1172*27850254SIskren Chernev } 1173*27850254SIskren Chernev 1174*27850254SIskren Chernev static int 1175e92a4047SStephen Boyd spmi_regulator_common_set_load(struct regulator_dev *rdev, int load_uA) 1176e92a4047SStephen Boyd { 1177e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1178e92a4047SStephen Boyd unsigned int mode; 1179e92a4047SStephen Boyd 1180e92a4047SStephen Boyd if (load_uA >= vreg->hpm_min_load) 1181e92a4047SStephen Boyd mode = REGULATOR_MODE_NORMAL; 1182e92a4047SStephen Boyd else 1183e92a4047SStephen Boyd mode = REGULATOR_MODE_IDLE; 1184e92a4047SStephen Boyd 1185e92a4047SStephen Boyd return spmi_regulator_common_set_mode(rdev, mode); 1186e92a4047SStephen Boyd } 1187e92a4047SStephen Boyd 1188e92a4047SStephen Boyd static int spmi_regulator_common_set_pull_down(struct regulator_dev *rdev) 1189e92a4047SStephen Boyd { 1190e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1191e92a4047SStephen Boyd unsigned int mask = SPMI_COMMON_PULL_DOWN_ENABLE_MASK; 1192e92a4047SStephen Boyd 1193e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_PULL_DOWN, 1194e92a4047SStephen Boyd mask, mask); 1195e92a4047SStephen Boyd } 1196e92a4047SStephen Boyd 1197*27850254SIskren Chernev static int spmi_regulator_hfsmps_set_pull_down(struct regulator_dev *rdev) 1198*27850254SIskren Chernev { 1199*27850254SIskren Chernev struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1200*27850254SIskren Chernev unsigned int mask = SPMI_COMMON_PULL_DOWN_ENABLE_MASK; 1201*27850254SIskren Chernev 1202*27850254SIskren Chernev return spmi_vreg_update_bits(vreg, SPMI_HFSMPS_REG_PULL_DOWN, 1203*27850254SIskren Chernev mask, mask); 1204*27850254SIskren Chernev } 1205*27850254SIskren Chernev 1206e92a4047SStephen Boyd static int spmi_regulator_common_set_soft_start(struct regulator_dev *rdev) 1207e92a4047SStephen Boyd { 1208e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1209e92a4047SStephen Boyd unsigned int mask = SPMI_LDO_SOFT_START_ENABLE_MASK; 1210e92a4047SStephen Boyd 1211e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_SOFT_START, 1212e92a4047SStephen Boyd mask, mask); 1213e92a4047SStephen Boyd } 1214e92a4047SStephen Boyd 1215e92a4047SStephen Boyd static int spmi_regulator_set_ilim(struct regulator_dev *rdev, int ilim_uA) 1216e92a4047SStephen Boyd { 1217e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1218e92a4047SStephen Boyd enum spmi_regulator_logical_type type = vreg->logical_type; 1219e92a4047SStephen Boyd unsigned int current_reg; 1220e92a4047SStephen Boyd u8 reg; 1221e92a4047SStephen Boyd u8 mask = SPMI_BOOST_CURRENT_LIMIT_MASK | 1222e92a4047SStephen Boyd SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK; 1223e92a4047SStephen Boyd int max = (SPMI_BOOST_CURRENT_LIMIT_MASK + 1) * 500; 1224e92a4047SStephen Boyd 1225e92a4047SStephen Boyd if (type == SPMI_REGULATOR_LOGICAL_TYPE_BOOST) 1226e92a4047SStephen Boyd current_reg = SPMI_BOOST_REG_CURRENT_LIMIT; 1227e92a4047SStephen Boyd else 1228e92a4047SStephen Boyd current_reg = SPMI_BOOST_BYP_REG_CURRENT_LIMIT; 1229e92a4047SStephen Boyd 1230e92a4047SStephen Boyd if (ilim_uA > max || ilim_uA <= 0) 1231e92a4047SStephen Boyd return -EINVAL; 1232e92a4047SStephen Boyd 1233e92a4047SStephen Boyd reg = (ilim_uA - 1) / 500; 1234e92a4047SStephen Boyd reg |= SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK; 1235e92a4047SStephen Boyd 1236e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, current_reg, reg, mask); 1237e92a4047SStephen Boyd } 1238e92a4047SStephen Boyd 1239e92a4047SStephen Boyd static int spmi_regulator_vs_clear_ocp(struct spmi_regulator *vreg) 1240e92a4047SStephen Boyd { 1241e92a4047SStephen Boyd int ret; 1242e92a4047SStephen Boyd 1243e92a4047SStephen Boyd ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, 1244e92a4047SStephen Boyd SPMI_COMMON_DISABLE, SPMI_COMMON_ENABLE_MASK); 1245e92a4047SStephen Boyd 1246e92a4047SStephen Boyd vreg->vs_enable_time = ktime_get(); 1247e92a4047SStephen Boyd 1248e92a4047SStephen Boyd ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, 1249e92a4047SStephen Boyd SPMI_COMMON_ENABLE, SPMI_COMMON_ENABLE_MASK); 1250e92a4047SStephen Boyd 1251e92a4047SStephen Boyd return ret; 1252e92a4047SStephen Boyd } 1253e92a4047SStephen Boyd 1254e92a4047SStephen Boyd static void spmi_regulator_vs_ocp_work(struct work_struct *work) 1255e92a4047SStephen Boyd { 1256e92a4047SStephen Boyd struct delayed_work *dwork = to_delayed_work(work); 1257e92a4047SStephen Boyd struct spmi_regulator *vreg 1258e92a4047SStephen Boyd = container_of(dwork, struct spmi_regulator, ocp_work); 1259e92a4047SStephen Boyd 1260e92a4047SStephen Boyd spmi_regulator_vs_clear_ocp(vreg); 1261e92a4047SStephen Boyd } 1262e92a4047SStephen Boyd 1263e92a4047SStephen Boyd static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data) 1264e92a4047SStephen Boyd { 1265e92a4047SStephen Boyd struct spmi_regulator *vreg = data; 1266e92a4047SStephen Boyd ktime_t ocp_irq_time; 1267e92a4047SStephen Boyd s64 ocp_trigger_delay_us; 1268e92a4047SStephen Boyd 1269e92a4047SStephen Boyd ocp_irq_time = ktime_get(); 1270e92a4047SStephen Boyd ocp_trigger_delay_us = ktime_us_delta(ocp_irq_time, 1271e92a4047SStephen Boyd vreg->vs_enable_time); 1272e92a4047SStephen Boyd 1273e92a4047SStephen Boyd /* 1274e92a4047SStephen Boyd * Reset the OCP count if there is a large delay between switch enable 1275e92a4047SStephen Boyd * and when OCP triggers. This is indicative of a hotplug event as 1276e92a4047SStephen Boyd * opposed to a fault. 1277e92a4047SStephen Boyd */ 1278e92a4047SStephen Boyd if (ocp_trigger_delay_us > SPMI_VS_OCP_FAULT_DELAY_US) 1279e92a4047SStephen Boyd vreg->ocp_count = 0; 1280e92a4047SStephen Boyd 1281e92a4047SStephen Boyd /* Wait for switch output to settle back to 0 V after OCP triggered. */ 1282e92a4047SStephen Boyd udelay(SPMI_VS_OCP_FALL_DELAY_US); 1283e92a4047SStephen Boyd 1284e92a4047SStephen Boyd vreg->ocp_count++; 1285e92a4047SStephen Boyd 1286e92a4047SStephen Boyd if (vreg->ocp_count == 1) { 1287e92a4047SStephen Boyd /* Immediately clear the over current condition. */ 1288e92a4047SStephen Boyd spmi_regulator_vs_clear_ocp(vreg); 1289e92a4047SStephen Boyd } else if (vreg->ocp_count <= vreg->ocp_max_retries) { 1290e92a4047SStephen Boyd /* Schedule the over current clear task to run later. */ 1291e92a4047SStephen Boyd schedule_delayed_work(&vreg->ocp_work, 1292e92a4047SStephen Boyd msecs_to_jiffies(vreg->ocp_retry_delay_ms) + 1); 1293e92a4047SStephen Boyd } else { 1294e92a4047SStephen Boyd dev_err(vreg->dev, 1295e92a4047SStephen Boyd "OCP triggered %d times; no further retries\n", 1296e92a4047SStephen Boyd vreg->ocp_count); 1297e92a4047SStephen Boyd } 1298e92a4047SStephen Boyd 1299e92a4047SStephen Boyd return IRQ_HANDLED; 1300e92a4047SStephen Boyd } 1301e92a4047SStephen Boyd 13020caecaa8SIlia Lin #define SAW3_VCTL_DATA_MASK 0xFF 13030caecaa8SIlia Lin #define SAW3_VCTL_CLEAR_MASK 0x700FF 13040caecaa8SIlia Lin #define SAW3_AVS_CTL_EN_MASK 0x1 13050caecaa8SIlia Lin #define SAW3_AVS_CTL_TGGL_MASK 0x8000000 13060caecaa8SIlia Lin #define SAW3_AVS_CTL_CLEAR_MASK 0x7efc00 13070caecaa8SIlia Lin 13089689ca0aSNiklas Cassel static struct regmap *saw_regmap; 13090caecaa8SIlia Lin 13100caecaa8SIlia Lin static void spmi_saw_set_vdd(void *data) 13110caecaa8SIlia Lin { 13120caecaa8SIlia Lin u32 vctl, data3, avs_ctl, pmic_sts; 13130caecaa8SIlia Lin bool avs_enabled = false; 13140caecaa8SIlia Lin unsigned long timeout; 13150caecaa8SIlia Lin u8 voltage_sel = *(u8 *)data; 13160caecaa8SIlia Lin 13170caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_AVS_CTL, &avs_ctl); 13180caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_VCTL, &vctl); 13190caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_SPM_PMIC_DATA_3, &data3); 13200caecaa8SIlia Lin 13210caecaa8SIlia Lin /* select the band */ 13220caecaa8SIlia Lin vctl &= ~SAW3_VCTL_CLEAR_MASK; 13230caecaa8SIlia Lin vctl |= (u32)voltage_sel; 13240caecaa8SIlia Lin 13250caecaa8SIlia Lin data3 &= ~SAW3_VCTL_CLEAR_MASK; 13260caecaa8SIlia Lin data3 |= (u32)voltage_sel; 13270caecaa8SIlia Lin 13280caecaa8SIlia Lin /* If AVS is enabled, switch it off during the voltage change */ 13290caecaa8SIlia Lin avs_enabled = SAW3_AVS_CTL_EN_MASK & avs_ctl; 13300caecaa8SIlia Lin if (avs_enabled) { 13310caecaa8SIlia Lin avs_ctl &= ~SAW3_AVS_CTL_TGGL_MASK; 13320caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_AVS_CTL, avs_ctl); 13330caecaa8SIlia Lin } 13340caecaa8SIlia Lin 13350caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_RST, 1); 13360caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_VCTL, vctl); 13370caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_SPM_PMIC_DATA_3, data3); 13380caecaa8SIlia Lin 13390caecaa8SIlia Lin timeout = jiffies + usecs_to_jiffies(100); 13400caecaa8SIlia Lin do { 13410caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_PMIC_STS, &pmic_sts); 13420caecaa8SIlia Lin pmic_sts &= SAW3_VCTL_DATA_MASK; 13430caecaa8SIlia Lin if (pmic_sts == (u32)voltage_sel) 13440caecaa8SIlia Lin break; 13450caecaa8SIlia Lin 13460caecaa8SIlia Lin cpu_relax(); 13470caecaa8SIlia Lin 13480caecaa8SIlia Lin } while (time_before(jiffies, timeout)); 13490caecaa8SIlia Lin 13500caecaa8SIlia Lin /* After successful voltage change, switch the AVS back on */ 13510caecaa8SIlia Lin if (avs_enabled) { 13520caecaa8SIlia Lin pmic_sts &= 0x3f; 13530caecaa8SIlia Lin avs_ctl &= ~SAW3_AVS_CTL_CLEAR_MASK; 13540caecaa8SIlia Lin avs_ctl |= ((pmic_sts - 4) << 10); 13550caecaa8SIlia Lin avs_ctl |= (pmic_sts << 17); 13560caecaa8SIlia Lin avs_ctl |= SAW3_AVS_CTL_TGGL_MASK; 13570caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_AVS_CTL, avs_ctl); 13580caecaa8SIlia Lin } 13590caecaa8SIlia Lin } 13600caecaa8SIlia Lin 13610caecaa8SIlia Lin static int 13620caecaa8SIlia Lin spmi_regulator_saw_set_voltage(struct regulator_dev *rdev, unsigned selector) 13630caecaa8SIlia Lin { 13640caecaa8SIlia Lin struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 13650caecaa8SIlia Lin int ret; 13660caecaa8SIlia Lin u8 range_sel, voltage_sel; 13670caecaa8SIlia Lin 13680caecaa8SIlia Lin ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); 13690caecaa8SIlia Lin if (ret) 13700caecaa8SIlia Lin return ret; 13710caecaa8SIlia Lin 13720caecaa8SIlia Lin if (0 != range_sel) { 13730caecaa8SIlia Lin dev_dbg(&rdev->dev, "range_sel = %02X voltage_sel = %02X", \ 13740caecaa8SIlia Lin range_sel, voltage_sel); 13750caecaa8SIlia Lin return -EINVAL; 13760caecaa8SIlia Lin } 13770caecaa8SIlia Lin 13780caecaa8SIlia Lin /* Always do the SAW register writes on the first CPU */ 13790caecaa8SIlia Lin return smp_call_function_single(0, spmi_saw_set_vdd, \ 13800caecaa8SIlia Lin &voltage_sel, true); 13810caecaa8SIlia Lin } 13820caecaa8SIlia Lin 13830caecaa8SIlia Lin static struct regulator_ops spmi_saw_ops = {}; 13840caecaa8SIlia Lin 13853b619e3eSRikard Falkeborn static const struct regulator_ops spmi_smps_ops = { 13869d485332SAxel Lin .enable = regulator_enable_regmap, 13879d485332SAxel Lin .disable = regulator_disable_regmap, 13889d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13891b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 13902cf7b99cSStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 13911b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 13921b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1393e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1394e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1395e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1396e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1397e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1398e92a4047SStephen Boyd }; 1399e92a4047SStephen Boyd 14003b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ldo_ops = { 14019d485332SAxel Lin .enable = regulator_enable_regmap, 14029d485332SAxel Lin .disable = regulator_disable_regmap, 14039d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14041b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 14051b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 14061b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1407e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1408e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1409e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1410e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1411e92a4047SStephen Boyd .set_bypass = spmi_regulator_common_set_bypass, 1412e92a4047SStephen Boyd .get_bypass = spmi_regulator_common_get_bypass, 1413e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1414e92a4047SStephen Boyd .set_soft_start = spmi_regulator_common_set_soft_start, 1415e92a4047SStephen Boyd }; 1416e92a4047SStephen Boyd 14173b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ln_ldo_ops = { 14189d485332SAxel Lin .enable = regulator_enable_regmap, 14199d485332SAxel Lin .disable = regulator_disable_regmap, 14209d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14211b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 14221b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 14231b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1424e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1425e92a4047SStephen Boyd .set_bypass = spmi_regulator_common_set_bypass, 1426e92a4047SStephen Boyd .get_bypass = spmi_regulator_common_get_bypass, 1427e92a4047SStephen Boyd }; 1428e92a4047SStephen Boyd 14293b619e3eSRikard Falkeborn static const struct regulator_ops spmi_vs_ops = { 1430e92a4047SStephen Boyd .enable = spmi_regulator_vs_enable, 14319d485332SAxel Lin .disable = regulator_disable_regmap, 14329d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 1433e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1434e92a4047SStephen Boyd .set_soft_start = spmi_regulator_common_set_soft_start, 1435e2adfacdSStephen Boyd .set_over_current_protection = spmi_regulator_vs_ocp, 1436919163f6SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1437919163f6SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1438e92a4047SStephen Boyd }; 1439e92a4047SStephen Boyd 14403b619e3eSRikard Falkeborn static const struct regulator_ops spmi_boost_ops = { 14419d485332SAxel Lin .enable = regulator_enable_regmap, 14429d485332SAxel Lin .disable = regulator_disable_regmap, 14439d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14441b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_single_range_set_voltage, 14451b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_single_range_get_voltage, 14461b5b1968SStephen Boyd .map_voltage = spmi_regulator_single_map_voltage, 1447e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1448e92a4047SStephen Boyd .set_input_current_limit = spmi_regulator_set_ilim, 1449e92a4047SStephen Boyd }; 1450e92a4047SStephen Boyd 14513b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ftsmps_ops = { 14529d485332SAxel Lin .enable = regulator_enable_regmap, 14539d485332SAxel Lin .disable = regulator_disable_regmap, 14549d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14551b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 1456e92a4047SStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 14571b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 14581b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1459e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1460e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1461e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1462e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1463e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1464e92a4047SStephen Boyd }; 1465e92a4047SStephen Boyd 14663b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_lo_smps_ops = { 14679d485332SAxel Lin .enable = regulator_enable_regmap, 14689d485332SAxel Lin .disable = regulator_disable_regmap, 14699d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14701b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_ult_lo_smps_set_voltage, 14712cf7b99cSStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 14721b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_ult_lo_smps_get_voltage, 1473e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1474e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1475e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1476e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1477e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1478e92a4047SStephen Boyd }; 1479e92a4047SStephen Boyd 14803b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_ho_smps_ops = { 14819d485332SAxel Lin .enable = regulator_enable_regmap, 14829d485332SAxel Lin .disable = regulator_disable_regmap, 14839d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14841b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_single_range_set_voltage, 14852cf7b99cSStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 14861b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_single_range_get_voltage, 14871b5b1968SStephen Boyd .map_voltage = spmi_regulator_single_map_voltage, 1488e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1489e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1490e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1491e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1492e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1493e92a4047SStephen Boyd }; 1494e92a4047SStephen Boyd 14953b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_ldo_ops = { 14969d485332SAxel Lin .enable = regulator_enable_regmap, 14979d485332SAxel Lin .disable = regulator_disable_regmap, 14989d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14991b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_single_range_set_voltage, 15001b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_single_range_get_voltage, 15011b5b1968SStephen Boyd .map_voltage = spmi_regulator_single_map_voltage, 1502e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1503e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1504e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1505e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1506e92a4047SStephen Boyd .set_bypass = spmi_regulator_common_set_bypass, 1507e92a4047SStephen Boyd .get_bypass = spmi_regulator_common_get_bypass, 1508e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1509e92a4047SStephen Boyd .set_soft_start = spmi_regulator_common_set_soft_start, 1510e92a4047SStephen Boyd }; 1511e92a4047SStephen Boyd 15123b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ftsmps426_ops = { 151342ba89c8SJeffrey Hugo .enable = regulator_enable_regmap, 151442ba89c8SJeffrey Hugo .disable = regulator_disable_regmap, 151542ba89c8SJeffrey Hugo .is_enabled = regulator_is_enabled_regmap, 151642ba89c8SJeffrey Hugo .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage, 151742ba89c8SJeffrey Hugo .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 151842ba89c8SJeffrey Hugo .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage, 151942ba89c8SJeffrey Hugo .map_voltage = spmi_regulator_single_map_voltage, 152042ba89c8SJeffrey Hugo .list_voltage = spmi_regulator_common_list_voltage, 152142ba89c8SJeffrey Hugo .set_mode = spmi_regulator_ftsmps426_set_mode, 152242ba89c8SJeffrey Hugo .get_mode = spmi_regulator_ftsmps426_get_mode, 152342ba89c8SJeffrey Hugo .set_load = spmi_regulator_common_set_load, 152442ba89c8SJeffrey Hugo .set_pull_down = spmi_regulator_common_set_pull_down, 152542ba89c8SJeffrey Hugo }; 152642ba89c8SJeffrey Hugo 15273b619e3eSRikard Falkeborn static const struct regulator_ops spmi_hfs430_ops = { 15280211f68eSJorge Ramirez .enable = regulator_enable_regmap, 15290211f68eSJorge Ramirez .disable = regulator_disable_regmap, 15300211f68eSJorge Ramirez .is_enabled = regulator_is_enabled_regmap, 15310211f68eSJorge Ramirez .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage, 15320211f68eSJorge Ramirez .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 15330211f68eSJorge Ramirez .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage, 15340211f68eSJorge Ramirez .map_voltage = spmi_regulator_single_map_voltage, 15350211f68eSJorge Ramirez .list_voltage = spmi_regulator_common_list_voltage, 15360211f68eSJorge Ramirez .set_mode = spmi_regulator_ftsmps426_set_mode, 15370211f68eSJorge Ramirez .get_mode = spmi_regulator_ftsmps426_get_mode, 15380211f68eSJorge Ramirez }; 15390211f68eSJorge Ramirez 1540*27850254SIskren Chernev static const struct regulator_ops spmi_hfsmps_ops = { 1541*27850254SIskren Chernev .enable = regulator_enable_regmap, 1542*27850254SIskren Chernev .disable = regulator_disable_regmap, 1543*27850254SIskren Chernev .is_enabled = regulator_is_enabled_regmap, 1544*27850254SIskren Chernev .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage, 1545*27850254SIskren Chernev .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 1546*27850254SIskren Chernev .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage, 1547*27850254SIskren Chernev .map_voltage = spmi_regulator_single_map_voltage, 1548*27850254SIskren Chernev .list_voltage = spmi_regulator_common_list_voltage, 1549*27850254SIskren Chernev .set_mode = spmi_regulator_hfsmps_set_mode, 1550*27850254SIskren Chernev .get_mode = spmi_regulator_hfsmps_get_mode, 1551*27850254SIskren Chernev .set_load = spmi_regulator_common_set_load, 1552*27850254SIskren Chernev .set_pull_down = spmi_regulator_hfsmps_set_pull_down, 1553*27850254SIskren Chernev }; 1554*27850254SIskren Chernev 1555e92a4047SStephen Boyd /* Maximum possible digital major revision value */ 1556e92a4047SStephen Boyd #define INF 0xFF 1557e92a4047SStephen Boyd 1558e92a4047SStephen Boyd static const struct spmi_regulator_mapping supported_regulators[] = { 1559e92a4047SStephen Boyd /* type subtype dig_min dig_max ltype ops setpoints hpm_min */ 15603d04ae8eSRobert Marko SPMI_VREG(LDO, HT_P600, 0, INF, HFS430, hfs430, ht_p600, 10000), 156100f6ebbdSRobert Marko SPMI_VREG(LDO, HT_P150, 0, INF, HFS430, hfs430, ht_p150, 10000), 1562e92a4047SStephen Boyd SPMI_VREG(BUCK, GP_CTL, 0, INF, SMPS, smps, smps, 100000), 1563*27850254SIskren Chernev SPMI_VREG(BUCK, HFS430, 0, 3, HFS430, hfs430, hfs430, 10000), 1564*27850254SIskren Chernev SPMI_VREG(BUCK, HFSMPS_510, 4, INF, HFSMPS, hfsmps, hfs430, 100000), 1565e92a4047SStephen Boyd SPMI_VREG(LDO, N300, 0, INF, LDO, ldo, nldo1, 10000), 1566e92a4047SStephen Boyd SPMI_VREG(LDO, N600, 0, 0, LDO, ldo, nldo2, 10000), 1567e92a4047SStephen Boyd SPMI_VREG(LDO, N1200, 0, 0, LDO, ldo, nldo2, 10000), 1568e92a4047SStephen Boyd SPMI_VREG(LDO, N600, 1, INF, LDO, ldo, nldo3, 10000), 1569e92a4047SStephen Boyd SPMI_VREG(LDO, N1200, 1, INF, LDO, ldo, nldo3, 10000), 1570e92a4047SStephen Boyd SPMI_VREG(LDO, N600_ST, 0, 0, LDO, ldo, nldo2, 10000), 1571e92a4047SStephen Boyd SPMI_VREG(LDO, N1200_ST, 0, 0, LDO, ldo, nldo2, 10000), 1572e92a4047SStephen Boyd SPMI_VREG(LDO, N600_ST, 1, INF, LDO, ldo, nldo3, 10000), 1573e92a4047SStephen Boyd SPMI_VREG(LDO, N1200_ST, 1, INF, LDO, ldo, nldo3, 10000), 1574e92a4047SStephen Boyd SPMI_VREG(LDO, P50, 0, INF, LDO, ldo, pldo, 5000), 1575e92a4047SStephen Boyd SPMI_VREG(LDO, P150, 0, INF, LDO, ldo, pldo, 10000), 1576e92a4047SStephen Boyd SPMI_VREG(LDO, P300, 0, INF, LDO, ldo, pldo, 10000), 1577e92a4047SStephen Boyd SPMI_VREG(LDO, P600, 0, INF, LDO, ldo, pldo, 10000), 1578e92a4047SStephen Boyd SPMI_VREG(LDO, P1200, 0, INF, LDO, ldo, pldo, 10000), 1579e92a4047SStephen Boyd SPMI_VREG(LDO, LN, 0, INF, LN_LDO, ln_ldo, ln_ldo, 0), 1580e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P50, 0, INF, LDO, ldo, pldo, 5000), 1581e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P150, 0, INF, LDO, ldo, pldo, 10000), 1582e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P300, 0, INF, LDO, ldo, pldo, 10000), 1583e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P600, 0, INF, LDO, ldo, pldo, 10000), 1584e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P1200, 0, INF, LDO, ldo, pldo, 10000), 1585328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_N300_ST, 0, INF, FTSMPS426, ftsmps426, 1586328816c2SAngeloGioacchino Del Regno ht_nldo, 30000), 1587328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_N600_ST, 0, INF, FTSMPS426, ftsmps426, 1588328816c2SAngeloGioacchino Del Regno ht_nldo, 30000), 1589328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_N1200_ST, 0, INF, FTSMPS426, ftsmps426, 1590328816c2SAngeloGioacchino Del Regno ht_nldo, 30000), 1591328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_LVP150, 0, INF, FTSMPS426, ftsmps426, 1592328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1593328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_LVP300, 0, INF, FTSMPS426, ftsmps426, 1594328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1595328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_N300_ST, 0, INF, FTSMPS426, ftsmps426, 1596328816c2SAngeloGioacchino Del Regno nldo660, 10000), 1597328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_N600_ST, 0, INF, FTSMPS426, ftsmps426, 1598328816c2SAngeloGioacchino Del Regno nldo660, 10000), 1599328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_P50, 0, INF, FTSMPS426, ftsmps426, 1600328816c2SAngeloGioacchino Del Regno pldo660, 10000), 1601328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_P150, 0, INF, FTSMPS426, ftsmps426, 1602328816c2SAngeloGioacchino Del Regno pldo660, 10000), 1603328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_P600, 0, INF, FTSMPS426, ftsmps426, 1604328816c2SAngeloGioacchino Del Regno pldo660, 10000), 1605328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_LVP150, 0, INF, FTSMPS426, ftsmps426, 1606328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1607328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_LVP600, 0, INF, FTSMPS426, ftsmps426, 1608328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1609e92a4047SStephen Boyd SPMI_VREG_VS(LV100, 0, INF), 1610e92a4047SStephen Boyd SPMI_VREG_VS(LV300, 0, INF), 1611e92a4047SStephen Boyd SPMI_VREG_VS(MV300, 0, INF), 1612e92a4047SStephen Boyd SPMI_VREG_VS(MV500, 0, INF), 1613e92a4047SStephen Boyd SPMI_VREG_VS(HDMI, 0, INF), 1614e92a4047SStephen Boyd SPMI_VREG_VS(OTG, 0, INF), 1615e92a4047SStephen Boyd SPMI_VREG(BOOST, 5V_BOOST, 0, INF, BOOST, boost, boost, 0), 1616e92a4047SStephen Boyd SPMI_VREG(FTS, FTS_CTL, 0, INF, FTSMPS, ftsmps, ftsmps, 100000), 1617e92a4047SStephen Boyd SPMI_VREG(FTS, FTS2p5_CTL, 0, INF, FTSMPS, ftsmps, ftsmps2p5, 100000), 161842ba89c8SJeffrey Hugo SPMI_VREG(FTS, FTS426_CTL, 0, INF, FTSMPS426, ftsmps426, ftsmps426, 100000), 1619e92a4047SStephen Boyd SPMI_VREG(BOOST_BYP, BB_2A, 0, INF, BOOST_BYP, boost, boost_byp, 0), 1620e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL1, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1621e92a4047SStephen Boyd ult_lo_smps, 100000), 1622e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL2, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1623e92a4047SStephen Boyd ult_lo_smps, 100000), 1624e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL3, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1625e92a4047SStephen Boyd ult_lo_smps, 100000), 1626e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL4, 0, INF, ULT_HO_SMPS, ult_ho_smps, 1627e92a4047SStephen Boyd ult_ho_smps, 100000), 1628e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N300_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1629e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N600_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1630e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N900_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1631e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N1200_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1632438421b0SAngeloGioacchino Del Regno SPMI_VREG(ULT_LDO, LV_P50, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1633e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, LV_P150, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1634e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, LV_P300, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1635e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, LV_P450, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1636e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, P600, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1637438421b0SAngeloGioacchino Del Regno SPMI_VREG(ULT_LDO, P300, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1638e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, P150, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1639e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, P50, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 5000), 1640e92a4047SStephen Boyd }; 1641e92a4047SStephen Boyd 1642e92a4047SStephen Boyd static void spmi_calculate_num_voltages(struct spmi_voltage_set_points *points) 1643e92a4047SStephen Boyd { 1644e92a4047SStephen Boyd unsigned int n; 1645e92a4047SStephen Boyd struct spmi_voltage_range *range = points->range; 1646e92a4047SStephen Boyd 1647e92a4047SStephen Boyd for (; range < points->range + points->count; range++) { 1648e92a4047SStephen Boyd n = 0; 1649e92a4047SStephen Boyd if (range->set_point_max_uV) { 1650e92a4047SStephen Boyd n = range->set_point_max_uV - range->set_point_min_uV; 1651419d06a1SAxel Lin n = (n / range->step_uV) + 1; 1652e92a4047SStephen Boyd } 1653e92a4047SStephen Boyd range->n_voltages = n; 1654e92a4047SStephen Boyd points->n_voltages += n; 1655e92a4047SStephen Boyd } 1656e92a4047SStephen Boyd } 1657e92a4047SStephen Boyd 1658e92a4047SStephen Boyd static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type) 1659e92a4047SStephen Boyd { 1660e92a4047SStephen Boyd const struct spmi_regulator_mapping *mapping; 1661e92a4047SStephen Boyd int ret, i; 1662e92a4047SStephen Boyd u32 dig_major_rev; 1663e92a4047SStephen Boyd u8 version[SPMI_COMMON_REG_SUBTYPE - SPMI_COMMON_REG_DIG_MAJOR_REV + 1]; 1664e92a4047SStephen Boyd u8 type, subtype; 1665e92a4047SStephen Boyd 1666e92a4047SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version, 1667e92a4047SStephen Boyd ARRAY_SIZE(version)); 1668e92a4047SStephen Boyd if (ret) { 16696ee5c044SStephen Boyd dev_dbg(vreg->dev, "could not read version registers\n"); 1670e92a4047SStephen Boyd return ret; 1671e92a4047SStephen Boyd } 1672e92a4047SStephen Boyd dig_major_rev = version[SPMI_COMMON_REG_DIG_MAJOR_REV 1673e92a4047SStephen Boyd - SPMI_COMMON_REG_DIG_MAJOR_REV]; 16740caecaa8SIlia Lin 1675e92a4047SStephen Boyd if (!force_type) { 1676e92a4047SStephen Boyd type = version[SPMI_COMMON_REG_TYPE - 1677e92a4047SStephen Boyd SPMI_COMMON_REG_DIG_MAJOR_REV]; 1678e92a4047SStephen Boyd subtype = version[SPMI_COMMON_REG_SUBTYPE - 1679e92a4047SStephen Boyd SPMI_COMMON_REG_DIG_MAJOR_REV]; 1680e92a4047SStephen Boyd } else { 1681e92a4047SStephen Boyd type = force_type >> 8; 1682e92a4047SStephen Boyd subtype = force_type; 1683e92a4047SStephen Boyd } 1684e92a4047SStephen Boyd 1685e92a4047SStephen Boyd for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) { 1686e92a4047SStephen Boyd mapping = &supported_regulators[i]; 1687e92a4047SStephen Boyd if (mapping->type == type && mapping->subtype == subtype 1688e92a4047SStephen Boyd && mapping->revision_min <= dig_major_rev 1689e92a4047SStephen Boyd && mapping->revision_max >= dig_major_rev) 1690e92a4047SStephen Boyd goto found; 1691e92a4047SStephen Boyd } 1692e92a4047SStephen Boyd 1693e92a4047SStephen Boyd dev_err(vreg->dev, 1694e92a4047SStephen Boyd "unsupported regulator: name=%s type=0x%02X, subtype=0x%02X, dig major rev=0x%02X\n", 1695e92a4047SStephen Boyd vreg->desc.name, type, subtype, dig_major_rev); 1696e92a4047SStephen Boyd 1697e92a4047SStephen Boyd return -ENODEV; 1698e92a4047SStephen Boyd 1699e92a4047SStephen Boyd found: 1700e92a4047SStephen Boyd vreg->logical_type = mapping->logical_type; 1701e92a4047SStephen Boyd vreg->set_points = mapping->set_points; 1702e92a4047SStephen Boyd vreg->hpm_min_load = mapping->hpm_min_load; 1703e92a4047SStephen Boyd vreg->desc.ops = mapping->ops; 1704e92a4047SStephen Boyd 1705e92a4047SStephen Boyd if (mapping->set_points) { 1706e92a4047SStephen Boyd if (!mapping->set_points->n_voltages) 1707e92a4047SStephen Boyd spmi_calculate_num_voltages(mapping->set_points); 1708e92a4047SStephen Boyd vreg->desc.n_voltages = mapping->set_points->n_voltages; 1709e92a4047SStephen Boyd } 1710e92a4047SStephen Boyd 1711e92a4047SStephen Boyd return 0; 1712e92a4047SStephen Boyd } 1713e92a4047SStephen Boyd 17142cf7b99cSStephen Boyd static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg) 1715e92a4047SStephen Boyd { 1716e92a4047SStephen Boyd int ret; 1717e92a4047SStephen Boyd u8 reg = 0; 17182cf7b99cSStephen Boyd int step, delay, slew_rate, step_delay; 1719e92a4047SStephen Boyd const struct spmi_voltage_range *range; 1720e92a4047SStephen Boyd 1721e92a4047SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, ®, 1); 1722e92a4047SStephen Boyd if (ret) { 1723e92a4047SStephen Boyd dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); 1724e92a4047SStephen Boyd return ret; 1725e92a4047SStephen Boyd } 1726e92a4047SStephen Boyd 1727e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 1728e92a4047SStephen Boyd if (!range) 1729e92a4047SStephen Boyd return -EINVAL; 1730e92a4047SStephen Boyd 17312cf7b99cSStephen Boyd switch (vreg->logical_type) { 17322cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS: 17332cf7b99cSStephen Boyd step_delay = SPMI_FTSMPS_STEP_DELAY; 17342cf7b99cSStephen Boyd break; 17352cf7b99cSStephen Boyd default: 17362cf7b99cSStephen Boyd step_delay = SPMI_DEFAULT_STEP_DELAY; 17372cf7b99cSStephen Boyd break; 17382cf7b99cSStephen Boyd } 17392cf7b99cSStephen Boyd 1740e92a4047SStephen Boyd step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK; 1741e92a4047SStephen Boyd step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT; 1742e92a4047SStephen Boyd 1743e92a4047SStephen Boyd delay = reg & SPMI_FTSMPS_STEP_CTRL_DELAY_MASK; 1744e92a4047SStephen Boyd delay >>= SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT; 1745e92a4047SStephen Boyd 1746e92a4047SStephen Boyd /* slew_rate has units of uV/us */ 1747e92a4047SStephen Boyd slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step); 17482cf7b99cSStephen Boyd slew_rate /= 1000 * (step_delay << delay); 1749e92a4047SStephen Boyd slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM; 1750e92a4047SStephen Boyd slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN; 1751e92a4047SStephen Boyd 1752e92a4047SStephen Boyd /* Ensure that the slew rate is greater than 0 */ 1753e92a4047SStephen Boyd vreg->slew_rate = max(slew_rate, 1); 1754e92a4047SStephen Boyd 1755e92a4047SStephen Boyd return ret; 1756e92a4047SStephen Boyd } 1757e92a4047SStephen Boyd 17580211f68eSJorge Ramirez static int spmi_regulator_init_slew_rate_ftsmps426(struct spmi_regulator *vreg, 17590211f68eSJorge Ramirez int clock_rate) 176042ba89c8SJeffrey Hugo { 176142ba89c8SJeffrey Hugo int ret; 176242ba89c8SJeffrey Hugo u8 reg = 0; 176342ba89c8SJeffrey Hugo int delay, slew_rate; 176442ba89c8SJeffrey Hugo const struct spmi_voltage_range *range = &vreg->set_points->range[0]; 176542ba89c8SJeffrey Hugo 176642ba89c8SJeffrey Hugo ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, ®, 1); 176742ba89c8SJeffrey Hugo if (ret) { 176842ba89c8SJeffrey Hugo dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); 176942ba89c8SJeffrey Hugo return ret; 177042ba89c8SJeffrey Hugo } 177142ba89c8SJeffrey Hugo 177242ba89c8SJeffrey Hugo delay = reg & SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK; 177342ba89c8SJeffrey Hugo delay >>= SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT; 177442ba89c8SJeffrey Hugo 177542ba89c8SJeffrey Hugo /* slew_rate has units of uV/us */ 17760211f68eSJorge Ramirez slew_rate = clock_rate * range->step_uV; 177742ba89c8SJeffrey Hugo slew_rate /= 1000 * (SPMI_FTSMPS426_STEP_DELAY << delay); 177842ba89c8SJeffrey Hugo slew_rate *= SPMI_FTSMPS426_STEP_MARGIN_NUM; 177942ba89c8SJeffrey Hugo slew_rate /= SPMI_FTSMPS426_STEP_MARGIN_DEN; 178042ba89c8SJeffrey Hugo 178142ba89c8SJeffrey Hugo /* Ensure that the slew rate is greater than 0 */ 178242ba89c8SJeffrey Hugo vreg->slew_rate = max(slew_rate, 1); 178342ba89c8SJeffrey Hugo 178442ba89c8SJeffrey Hugo return ret; 178542ba89c8SJeffrey Hugo } 178642ba89c8SJeffrey Hugo 1787*27850254SIskren Chernev static int spmi_regulator_init_slew_rate_hfsmps(struct spmi_regulator *vreg) 1788*27850254SIskren Chernev { 1789*27850254SIskren Chernev int ret; 1790*27850254SIskren Chernev u8 reg = 0; 1791*27850254SIskren Chernev int delay; 1792*27850254SIskren Chernev 1793*27850254SIskren Chernev ret = spmi_vreg_read(vreg, SPMI_HFSMPS_REG_STEP_CTRL, ®, 1); 1794*27850254SIskren Chernev if (ret) { 1795*27850254SIskren Chernev dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); 1796*27850254SIskren Chernev return ret; 1797*27850254SIskren Chernev } 1798*27850254SIskren Chernev 1799*27850254SIskren Chernev delay = reg & SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK; 1800*27850254SIskren Chernev delay >>= SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT; 1801*27850254SIskren Chernev 1802*27850254SIskren Chernev vreg->slew_rate = SPMI_HFSMPS_SLEW_RATE_38p4 >> delay; 1803*27850254SIskren Chernev 1804*27850254SIskren Chernev return ret; 1805*27850254SIskren Chernev } 1806*27850254SIskren Chernev 1807e2adfacdSStephen Boyd static int spmi_regulator_init_registers(struct spmi_regulator *vreg, 1808e2adfacdSStephen Boyd const struct spmi_regulator_init_data *data) 1809e2adfacdSStephen Boyd { 1810e2adfacdSStephen Boyd int ret; 1811e2adfacdSStephen Boyd enum spmi_regulator_logical_type type; 1812e2adfacdSStephen Boyd u8 ctrl_reg[8], reg, mask; 1813e2adfacdSStephen Boyd 1814e2adfacdSStephen Boyd type = vreg->logical_type; 1815e2adfacdSStephen Boyd 1816e2adfacdSStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); 1817e2adfacdSStephen Boyd if (ret) 1818e2adfacdSStephen Boyd return ret; 1819e2adfacdSStephen Boyd 1820e2adfacdSStephen Boyd /* Set up enable pin control. */ 18216a1fe83bSAxel Lin if (!(data->pin_ctrl_enable & SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) { 18226a1fe83bSAxel Lin switch (type) { 18236a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_SMPS: 18246a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_LDO: 18256a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_VS: 1826e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_ENABLE] &= 1827e2adfacdSStephen Boyd ~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK; 1828e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_ENABLE] |= 1829e2adfacdSStephen Boyd data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK; 18306a1fe83bSAxel Lin break; 18316a1fe83bSAxel Lin default: 18326a1fe83bSAxel Lin break; 18336a1fe83bSAxel Lin } 1834e2adfacdSStephen Boyd } 1835e2adfacdSStephen Boyd 1836e2adfacdSStephen Boyd /* Set up mode pin control. */ 18376a1fe83bSAxel Lin if (!(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) { 18386a1fe83bSAxel Lin switch (type) { 18396a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_SMPS: 18406a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_LDO: 1841e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] &= 1842e2adfacdSStephen Boyd ~SPMI_COMMON_MODE_FOLLOW_ALL_MASK; 1843e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] |= 1844e2adfacdSStephen Boyd data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK; 18456a1fe83bSAxel Lin break; 18466a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_VS: 18476a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS: 18486a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS: 18496a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO: 1850e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] &= 1851e2adfacdSStephen Boyd ~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; 1852e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] |= 1853e2adfacdSStephen Boyd data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; 18546a1fe83bSAxel Lin break; 18556a1fe83bSAxel Lin default: 18566a1fe83bSAxel Lin break; 1857e2adfacdSStephen Boyd } 1858e2adfacdSStephen Boyd } 1859e2adfacdSStephen Boyd 1860e2adfacdSStephen Boyd /* Write back any control register values that were modified. */ 1861e2adfacdSStephen Boyd ret = spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); 1862e2adfacdSStephen Boyd if (ret) 1863e2adfacdSStephen Boyd return ret; 1864e2adfacdSStephen Boyd 1865e2adfacdSStephen Boyd /* Set soft start strength and over current protection for VS. */ 1866e2adfacdSStephen Boyd if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS) { 1867e2adfacdSStephen Boyd if (data->vs_soft_start_strength 1868e2adfacdSStephen Boyd != SPMI_VS_SOFT_START_STR_HW_DEFAULT) { 1869e2adfacdSStephen Boyd reg = data->vs_soft_start_strength 1870e2adfacdSStephen Boyd & SPMI_VS_SOFT_START_SEL_MASK; 1871e2adfacdSStephen Boyd mask = SPMI_VS_SOFT_START_SEL_MASK; 1872e2adfacdSStephen Boyd return spmi_vreg_update_bits(vreg, 1873e2adfacdSStephen Boyd SPMI_VS_REG_SOFT_START, 1874e2adfacdSStephen Boyd reg, mask); 1875e2adfacdSStephen Boyd } 1876e2adfacdSStephen Boyd } 1877e2adfacdSStephen Boyd 1878e2adfacdSStephen Boyd return 0; 1879e2adfacdSStephen Boyd } 1880e2adfacdSStephen Boyd 1881e2adfacdSStephen Boyd static void spmi_regulator_get_dt_config(struct spmi_regulator *vreg, 1882e2adfacdSStephen Boyd struct device_node *node, struct spmi_regulator_init_data *data) 1883e2adfacdSStephen Boyd { 1884e2adfacdSStephen Boyd /* 1885e2adfacdSStephen Boyd * Initialize configuration parameters to use hardware default in case 1886e2adfacdSStephen Boyd * no value is specified via device tree. 1887e2adfacdSStephen Boyd */ 1888e2adfacdSStephen Boyd data->pin_ctrl_enable = SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT; 1889e2adfacdSStephen Boyd data->pin_ctrl_hpm = SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT; 1890e2adfacdSStephen Boyd data->vs_soft_start_strength = SPMI_VS_SOFT_START_STR_HW_DEFAULT; 1891e2adfacdSStephen Boyd 1892e2adfacdSStephen Boyd /* These bindings are optional, so it is okay if they aren't found. */ 1893e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,ocp-max-retries", 1894e2adfacdSStephen Boyd &vreg->ocp_max_retries); 1895e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,ocp-retry-delay", 1896e2adfacdSStephen Boyd &vreg->ocp_retry_delay_ms); 1897e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,pin-ctrl-enable", 1898e2adfacdSStephen Boyd &data->pin_ctrl_enable); 1899e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,pin-ctrl-hpm", &data->pin_ctrl_hpm); 1900e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,vs-soft-start-strength", 1901e2adfacdSStephen Boyd &data->vs_soft_start_strength); 1902e2adfacdSStephen Boyd } 1903e2adfacdSStephen Boyd 1904e92a4047SStephen Boyd static unsigned int spmi_regulator_of_map_mode(unsigned int mode) 1905e92a4047SStephen Boyd { 1906e2adfacdSStephen Boyd if (mode == 1) 1907e92a4047SStephen Boyd return REGULATOR_MODE_NORMAL; 1908e2adfacdSStephen Boyd if (mode == 2) 1909e2adfacdSStephen Boyd return REGULATOR_MODE_FAST; 1910e92a4047SStephen Boyd 1911e92a4047SStephen Boyd return REGULATOR_MODE_IDLE; 1912e92a4047SStephen Boyd } 1913e92a4047SStephen Boyd 1914e92a4047SStephen Boyd static int spmi_regulator_of_parse(struct device_node *node, 1915e92a4047SStephen Boyd const struct regulator_desc *desc, 1916e92a4047SStephen Boyd struct regulator_config *config) 1917e92a4047SStephen Boyd { 1918e2adfacdSStephen Boyd struct spmi_regulator_init_data data = { }; 1919e92a4047SStephen Boyd struct spmi_regulator *vreg = config->driver_data; 1920e92a4047SStephen Boyd struct device *dev = config->dev; 1921e92a4047SStephen Boyd int ret; 1922e92a4047SStephen Boyd 1923e2adfacdSStephen Boyd spmi_regulator_get_dt_config(vreg, node, &data); 1924e2adfacdSStephen Boyd 1925e2adfacdSStephen Boyd if (!vreg->ocp_max_retries) 1926e92a4047SStephen Boyd vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES; 1927e2adfacdSStephen Boyd if (!vreg->ocp_retry_delay_ms) 1928e92a4047SStephen Boyd vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS; 1929e92a4047SStephen Boyd 1930e2adfacdSStephen Boyd ret = spmi_regulator_init_registers(vreg, &data); 1931e2adfacdSStephen Boyd if (ret) { 1932e2adfacdSStephen Boyd dev_err(dev, "common initialization failed, ret=%d\n", ret); 1933e2adfacdSStephen Boyd return ret; 1934e2adfacdSStephen Boyd } 1935e2adfacdSStephen Boyd 19362cf7b99cSStephen Boyd switch (vreg->logical_type) { 19372cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS: 19382cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS: 19392cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS: 19402cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_SMPS: 19412cf7b99cSStephen Boyd ret = spmi_regulator_init_slew_rate(vreg); 1942e92a4047SStephen Boyd if (ret) 1943e92a4047SStephen Boyd return ret; 194442ba89c8SJeffrey Hugo break; 194542ba89c8SJeffrey Hugo case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426: 19460211f68eSJorge Ramirez ret = spmi_regulator_init_slew_rate_ftsmps426(vreg, 19470211f68eSJorge Ramirez SPMI_FTSMPS426_CLOCK_RATE); 19480211f68eSJorge Ramirez if (ret) 19490211f68eSJorge Ramirez return ret; 19500211f68eSJorge Ramirez break; 19510211f68eSJorge Ramirez case SPMI_REGULATOR_LOGICAL_TYPE_HFS430: 19520211f68eSJorge Ramirez ret = spmi_regulator_init_slew_rate_ftsmps426(vreg, 19530211f68eSJorge Ramirez SPMI_HFS430_CLOCK_RATE); 195442ba89c8SJeffrey Hugo if (ret) 195542ba89c8SJeffrey Hugo return ret; 195642ba89c8SJeffrey Hugo break; 1957*27850254SIskren Chernev case SPMI_REGULATOR_LOGICAL_TYPE_HFSMPS: 1958*27850254SIskren Chernev ret = spmi_regulator_init_slew_rate_hfsmps(vreg); 1959*27850254SIskren Chernev if (ret) 1960*27850254SIskren Chernev return ret; 1961*27850254SIskren Chernev break; 19622cf7b99cSStephen Boyd default: 19632cf7b99cSStephen Boyd break; 1964e92a4047SStephen Boyd } 1965e92a4047SStephen Boyd 1966e92a4047SStephen Boyd if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS) 1967e92a4047SStephen Boyd vreg->ocp_irq = 0; 1968e92a4047SStephen Boyd 1969e92a4047SStephen Boyd if (vreg->ocp_irq) { 1970e92a4047SStephen Boyd ret = devm_request_irq(dev, vreg->ocp_irq, 1971e92a4047SStephen Boyd spmi_regulator_vs_ocp_isr, IRQF_TRIGGER_RISING, "ocp", 1972e92a4047SStephen Boyd vreg); 1973e92a4047SStephen Boyd if (ret < 0) { 1974e92a4047SStephen Boyd dev_err(dev, "failed to request irq %d, ret=%d\n", 1975e92a4047SStephen Boyd vreg->ocp_irq, ret); 1976e92a4047SStephen Boyd return ret; 1977e92a4047SStephen Boyd } 1978e92a4047SStephen Boyd 1979b6688015SMatti Vaittinen ret = devm_delayed_work_autocancel(dev, &vreg->ocp_work, 1980b6688015SMatti Vaittinen spmi_regulator_vs_ocp_work); 1981b6688015SMatti Vaittinen if (ret) 1982b6688015SMatti Vaittinen return ret; 1983e92a4047SStephen Boyd } 1984e92a4047SStephen Boyd 1985e92a4047SStephen Boyd return 0; 1986e92a4047SStephen Boyd } 1987e92a4047SStephen Boyd 1988e92a4047SStephen Boyd static const struct spmi_regulator_data pm8941_regulators[] = { 1989e92a4047SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 1990e92a4047SStephen Boyd { "s2", 0x1700, "vdd_s2", }, 1991e92a4047SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 1992c333dfe8SStephen Boyd { "s4", 0xa000, }, 1993e92a4047SStephen Boyd { "l1", 0x4000, "vdd_l1_l3", }, 1994e92a4047SStephen Boyd { "l2", 0x4100, "vdd_l2_lvs_1_2_3", }, 1995e92a4047SStephen Boyd { "l3", 0x4200, "vdd_l1_l3", }, 1996e92a4047SStephen Boyd { "l4", 0x4300, "vdd_l4_l11", }, 1997e92a4047SStephen Boyd { "l5", 0x4400, "vdd_l5_l7", NULL, 0x0410 }, 1998e92a4047SStephen Boyd { "l6", 0x4500, "vdd_l6_l12_l14_l15", }, 1999e92a4047SStephen Boyd { "l7", 0x4600, "vdd_l5_l7", NULL, 0x0410 }, 2000e92a4047SStephen Boyd { "l8", 0x4700, "vdd_l8_l16_l18_19", }, 2001e92a4047SStephen Boyd { "l9", 0x4800, "vdd_l9_l10_l17_l22", }, 2002e92a4047SStephen Boyd { "l10", 0x4900, "vdd_l9_l10_l17_l22", }, 2003e92a4047SStephen Boyd { "l11", 0x4a00, "vdd_l4_l11", }, 2004e92a4047SStephen Boyd { "l12", 0x4b00, "vdd_l6_l12_l14_l15", }, 2005e92a4047SStephen Boyd { "l13", 0x4c00, "vdd_l13_l20_l23_l24", }, 2006e92a4047SStephen Boyd { "l14", 0x4d00, "vdd_l6_l12_l14_l15", }, 2007e92a4047SStephen Boyd { "l15", 0x4e00, "vdd_l6_l12_l14_l15", }, 2008e92a4047SStephen Boyd { "l16", 0x4f00, "vdd_l8_l16_l18_19", }, 2009e92a4047SStephen Boyd { "l17", 0x5000, "vdd_l9_l10_l17_l22", }, 2010e92a4047SStephen Boyd { "l18", 0x5100, "vdd_l8_l16_l18_19", }, 2011e92a4047SStephen Boyd { "l19", 0x5200, "vdd_l8_l16_l18_19", }, 2012e92a4047SStephen Boyd { "l20", 0x5300, "vdd_l13_l20_l23_l24", }, 2013e92a4047SStephen Boyd { "l21", 0x5400, "vdd_l21", }, 2014e92a4047SStephen Boyd { "l22", 0x5500, "vdd_l9_l10_l17_l22", }, 2015e92a4047SStephen Boyd { "l23", 0x5600, "vdd_l13_l20_l23_l24", }, 2016e92a4047SStephen Boyd { "l24", 0x5700, "vdd_l13_l20_l23_l24", }, 2017e92a4047SStephen Boyd { "lvs1", 0x8000, "vdd_l2_lvs_1_2_3", }, 2018e92a4047SStephen Boyd { "lvs2", 0x8100, "vdd_l2_lvs_1_2_3", }, 2019e92a4047SStephen Boyd { "lvs3", 0x8200, "vdd_l2_lvs_1_2_3", }, 202093bfe79bSStephen Boyd { "5vs1", 0x8300, "vin_5vs", "ocp-5vs1", }, 202193bfe79bSStephen Boyd { "5vs2", 0x8400, "vin_5vs", "ocp-5vs2", }, 2022e92a4047SStephen Boyd { } 2023e92a4047SStephen Boyd }; 2024e92a4047SStephen Boyd 2025f8843e5eSDominik Kobinski static const struct spmi_regulator_data pm8226_regulators[] = { 2026f8843e5eSDominik Kobinski { "s1", 0x1400, "vdd_s1", }, 2027f8843e5eSDominik Kobinski { "s2", 0x1700, "vdd_s2", }, 2028f8843e5eSDominik Kobinski { "s3", 0x1a00, "vdd_s3", }, 2029f8843e5eSDominik Kobinski { "s4", 0x1d00, "vdd_s4", }, 2030f8843e5eSDominik Kobinski { "s5", 0x2000, "vdd_s5", }, 2031f8843e5eSDominik Kobinski { "l1", 0x4000, "vdd_l1_l2_l4_l5", }, 2032f8843e5eSDominik Kobinski { "l2", 0x4100, "vdd_l1_l2_l4_l5", }, 2033f8843e5eSDominik Kobinski { "l3", 0x4200, "vdd_l3_l24_l26", }, 2034f8843e5eSDominik Kobinski { "l4", 0x4300, "vdd_l1_l2_l4_l5", }, 2035f8843e5eSDominik Kobinski { "l5", 0x4400, "vdd_l1_l2_l4_l5", }, 2036f8843e5eSDominik Kobinski { "l6", 0x4500, "vdd_l6_l7_l8_l9_l27", }, 2037f8843e5eSDominik Kobinski { "l7", 0x4600, "vdd_l6_l7_l8_l9_l27", }, 2038f8843e5eSDominik Kobinski { "l8", 0x4700, "vdd_l6_l7_l8_l9_l27", }, 2039f8843e5eSDominik Kobinski { "l9", 0x4800, "vdd_l6_l7_l8_l9_l27", }, 2040f8843e5eSDominik Kobinski { "l10", 0x4900, "vdd_l10_l11_l13", }, 2041f8843e5eSDominik Kobinski { "l11", 0x4a00, "vdd_l10_l11_l13", }, 2042f8843e5eSDominik Kobinski { "l12", 0x4b00, "vdd_l12_l14", }, 2043f8843e5eSDominik Kobinski { "l13", 0x4c00, "vdd_l10_l11_l13", }, 2044f8843e5eSDominik Kobinski { "l14", 0x4d00, "vdd_l12_l14", }, 2045f8843e5eSDominik Kobinski { "l15", 0x4e00, "vdd_l15_l16_l17_l18", }, 2046f8843e5eSDominik Kobinski { "l16", 0x4f00, "vdd_l15_l16_l17_l18", }, 2047f8843e5eSDominik Kobinski { "l17", 0x5000, "vdd_l15_l16_l17_l18", }, 2048f8843e5eSDominik Kobinski { "l18", 0x5100, "vdd_l15_l16_l17_l18", }, 2049f8843e5eSDominik Kobinski { "l19", 0x5200, "vdd_l19_l20_l21_l22_l23_l28", }, 2050f8843e5eSDominik Kobinski { "l20", 0x5300, "vdd_l19_l20_l21_l22_l23_l28", }, 2051f8843e5eSDominik Kobinski { "l21", 0x5400, "vdd_l19_l20_l21_l22_l23_l28", }, 2052f8843e5eSDominik Kobinski { "l22", 0x5500, "vdd_l19_l20_l21_l22_l23_l28", }, 2053f8843e5eSDominik Kobinski { "l23", 0x5600, "vdd_l19_l20_l21_l22_l23_l28", }, 2054f8843e5eSDominik Kobinski { "l24", 0x5700, "vdd_l3_l24_l26", }, 2055f8843e5eSDominik Kobinski { "l25", 0x5800, "vdd_l25", }, 2056f8843e5eSDominik Kobinski { "l26", 0x5900, "vdd_l3_l24_l26", }, 2057f8843e5eSDominik Kobinski { "l27", 0x5a00, "vdd_l6_l7_l8_l9_l27", }, 2058f8843e5eSDominik Kobinski { "l28", 0x5b00, "vdd_l19_l20_l21_l22_l23_l28", }, 2059f8843e5eSDominik Kobinski { "lvs1", 0x8000, "vdd_lvs1", }, 2060f8843e5eSDominik Kobinski { } 2061f8843e5eSDominik Kobinski }; 2062f8843e5eSDominik Kobinski 2063e92a4047SStephen Boyd static const struct spmi_regulator_data pm8841_regulators[] = { 2064e92a4047SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 2065e92a4047SStephen Boyd { "s2", 0x1700, "vdd_s2", NULL, 0x1c08 }, 2066e92a4047SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 2067e92a4047SStephen Boyd { "s4", 0x1d00, "vdd_s4", NULL, 0x1c08 }, 2068e92a4047SStephen Boyd { "s5", 0x2000, "vdd_s5", NULL, 0x1c08 }, 2069e92a4047SStephen Boyd { "s6", 0x2300, "vdd_s6", NULL, 0x1c08 }, 2070e92a4047SStephen Boyd { "s7", 0x2600, "vdd_s7", NULL, 0x1c08 }, 2071e92a4047SStephen Boyd { "s8", 0x2900, "vdd_s8", NULL, 0x1c08 }, 2072e92a4047SStephen Boyd { } 2073e92a4047SStephen Boyd }; 2074e92a4047SStephen Boyd 2075e92a4047SStephen Boyd static const struct spmi_regulator_data pm8916_regulators[] = { 2076e92a4047SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 2077e92a4047SStephen Boyd { "s2", 0x1700, "vdd_s2", }, 2078e92a4047SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 2079e92a4047SStephen Boyd { "s4", 0x1d00, "vdd_s4", }, 2080e92a4047SStephen Boyd { "l1", 0x4000, "vdd_l1_l3", }, 2081e92a4047SStephen Boyd { "l2", 0x4100, "vdd_l2", }, 2082e92a4047SStephen Boyd { "l3", 0x4200, "vdd_l1_l3", }, 2083e92a4047SStephen Boyd { "l4", 0x4300, "vdd_l4_l5_l6", }, 2084e92a4047SStephen Boyd { "l5", 0x4400, "vdd_l4_l5_l6", }, 2085e92a4047SStephen Boyd { "l6", 0x4500, "vdd_l4_l5_l6", }, 2086e92a4047SStephen Boyd { "l7", 0x4600, "vdd_l7", }, 2087e92a4047SStephen Boyd { "l8", 0x4700, "vdd_l8_l11_l14_l15_l16", }, 2088e92a4047SStephen Boyd { "l9", 0x4800, "vdd_l9_l10_l12_l13_l17_l18", }, 2089e92a4047SStephen Boyd { "l10", 0x4900, "vdd_l9_l10_l12_l13_l17_l18", }, 2090e92a4047SStephen Boyd { "l11", 0x4a00, "vdd_l8_l11_l14_l15_l16", }, 2091e92a4047SStephen Boyd { "l12", 0x4b00, "vdd_l9_l10_l12_l13_l17_l18", }, 2092e92a4047SStephen Boyd { "l13", 0x4c00, "vdd_l9_l10_l12_l13_l17_l18", }, 2093e92a4047SStephen Boyd { "l14", 0x4d00, "vdd_l8_l11_l14_l15_l16", }, 2094e92a4047SStephen Boyd { "l15", 0x4e00, "vdd_l8_l11_l14_l15_l16", }, 2095e92a4047SStephen Boyd { "l16", 0x4f00, "vdd_l8_l11_l14_l15_l16", }, 2096e92a4047SStephen Boyd { "l17", 0x5000, "vdd_l9_l10_l12_l13_l17_l18", }, 2097e92a4047SStephen Boyd { "l18", 0x5100, "vdd_l9_l10_l12_l13_l17_l18", }, 2098e92a4047SStephen Boyd { } 2099e92a4047SStephen Boyd }; 2100e92a4047SStephen Boyd 2101e4ff1710SAngelo G. Del Regno static const struct spmi_regulator_data pm8950_regulators[] = { 2102e4ff1710SAngelo G. Del Regno { "s1", 0x1400, "vdd_s1", }, 2103e4ff1710SAngelo G. Del Regno { "s2", 0x1700, "vdd_s2", }, 2104e4ff1710SAngelo G. Del Regno { "s3", 0x1a00, "vdd_s3", }, 2105e4ff1710SAngelo G. Del Regno { "s4", 0x1d00, "vdd_s4", }, 2106e4ff1710SAngelo G. Del Regno { "s5", 0x2000, "vdd_s5", }, 2107e4ff1710SAngelo G. Del Regno { "s6", 0x2300, "vdd_s6", }, 2108e4ff1710SAngelo G. Del Regno { "l1", 0x4000, "vdd_l1_l19", }, 2109e4ff1710SAngelo G. Del Regno { "l2", 0x4100, "vdd_l2_l23", }, 2110e4ff1710SAngelo G. Del Regno { "l3", 0x4200, "vdd_l3", }, 2111e4ff1710SAngelo G. Del Regno { "l4", 0x4300, "vdd_l4_l5_l6_l7_l16", }, 2112e4ff1710SAngelo G. Del Regno { "l5", 0x4400, "vdd_l4_l5_l6_l7_l16", }, 2113e4ff1710SAngelo G. Del Regno { "l6", 0x4500, "vdd_l4_l5_l6_l7_l16", }, 2114e4ff1710SAngelo G. Del Regno { "l7", 0x4600, "vdd_l4_l5_l6_l7_l16", }, 2115e4ff1710SAngelo G. Del Regno { "l8", 0x4700, "vdd_l8_l11_l12_l17_l22", }, 2116e4ff1710SAngelo G. Del Regno { "l9", 0x4800, "vdd_l9_l10_l13_l14_l15_l18", }, 2117e4ff1710SAngelo G. Del Regno { "l10", 0x4900, "vdd_l9_l10_l13_l14_l15_l18", }, 2118e4ff1710SAngelo G. Del Regno { "l11", 0x4a00, "vdd_l8_l11_l12_l17_l22", }, 2119e4ff1710SAngelo G. Del Regno { "l12", 0x4b00, "vdd_l8_l11_l12_l17_l22", }, 2120e4ff1710SAngelo G. Del Regno { "l13", 0x4c00, "vdd_l9_l10_l13_l14_l15_l18", }, 2121e4ff1710SAngelo G. Del Regno { "l14", 0x4d00, "vdd_l9_l10_l13_l14_l15_l18", }, 2122e4ff1710SAngelo G. Del Regno { "l15", 0x4e00, "vdd_l9_l10_l13_l14_l15_l18", }, 2123e4ff1710SAngelo G. Del Regno { "l16", 0x4f00, "vdd_l4_l5_l6_l7_l16", }, 2124e4ff1710SAngelo G. Del Regno { "l17", 0x5000, "vdd_l8_l11_l12_l17_l22", }, 2125e4ff1710SAngelo G. Del Regno { "l18", 0x5100, "vdd_l9_l10_l13_l14_l15_l18", }, 2126e4ff1710SAngelo G. Del Regno { "l19", 0x5200, "vdd_l1_l19", }, 2127e4ff1710SAngelo G. Del Regno { "l20", 0x5300, "vdd_l20", }, 2128e4ff1710SAngelo G. Del Regno { "l21", 0x5400, "vdd_l21", }, 2129e4ff1710SAngelo G. Del Regno { "l22", 0x5500, "vdd_l8_l11_l12_l17_l22", }, 2130e4ff1710SAngelo G. Del Regno { "l23", 0x5600, "vdd_l2_l23", }, 2131e4ff1710SAngelo G. Del Regno { } 2132e4ff1710SAngelo G. Del Regno }; 2133e4ff1710SAngelo G. Del Regno 213450314e55SStephen Boyd static const struct spmi_regulator_data pm8994_regulators[] = { 213550314e55SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 213650314e55SStephen Boyd { "s2", 0x1700, "vdd_s2", }, 213750314e55SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 213850314e55SStephen Boyd { "s4", 0x1d00, "vdd_s4", }, 213950314e55SStephen Boyd { "s5", 0x2000, "vdd_s5", }, 214050314e55SStephen Boyd { "s6", 0x2300, "vdd_s6", }, 214150314e55SStephen Boyd { "s7", 0x2600, "vdd_s7", }, 214250314e55SStephen Boyd { "s8", 0x2900, "vdd_s8", }, 214350314e55SStephen Boyd { "s9", 0x2c00, "vdd_s9", }, 214450314e55SStephen Boyd { "s10", 0x2f00, "vdd_s10", }, 214550314e55SStephen Boyd { "s11", 0x3200, "vdd_s11", }, 214650314e55SStephen Boyd { "s12", 0x3500, "vdd_s12", }, 214750314e55SStephen Boyd { "l1", 0x4000, "vdd_l1", }, 214850314e55SStephen Boyd { "l2", 0x4100, "vdd_l2_l26_l28", }, 214950314e55SStephen Boyd { "l3", 0x4200, "vdd_l3_l11", }, 215050314e55SStephen Boyd { "l4", 0x4300, "vdd_l4_l27_l31", }, 215150314e55SStephen Boyd { "l5", 0x4400, "vdd_l5_l7", }, 215250314e55SStephen Boyd { "l6", 0x4500, "vdd_l6_l12_l32", }, 215350314e55SStephen Boyd { "l7", 0x4600, "vdd_l5_l7", }, 215450314e55SStephen Boyd { "l8", 0x4700, "vdd_l8_l16_l30", }, 215550314e55SStephen Boyd { "l9", 0x4800, "vdd_l9_l10_l18_l22", }, 215650314e55SStephen Boyd { "l10", 0x4900, "vdd_l9_l10_l18_l22", }, 215750314e55SStephen Boyd { "l11", 0x4a00, "vdd_l3_l11", }, 215850314e55SStephen Boyd { "l12", 0x4b00, "vdd_l6_l12_l32", }, 215950314e55SStephen Boyd { "l13", 0x4c00, "vdd_l13_l19_l23_l24", }, 216050314e55SStephen Boyd { "l14", 0x4d00, "vdd_l14_l15", }, 216150314e55SStephen Boyd { "l15", 0x4e00, "vdd_l14_l15", }, 216250314e55SStephen Boyd { "l16", 0x4f00, "vdd_l8_l16_l30", }, 216350314e55SStephen Boyd { "l17", 0x5000, "vdd_l17_l29", }, 216450314e55SStephen Boyd { "l18", 0x5100, "vdd_l9_l10_l18_l22", }, 216550314e55SStephen Boyd { "l19", 0x5200, "vdd_l13_l19_l23_l24", }, 216650314e55SStephen Boyd { "l20", 0x5300, "vdd_l20_l21", }, 216750314e55SStephen Boyd { "l21", 0x5400, "vdd_l20_l21", }, 216850314e55SStephen Boyd { "l22", 0x5500, "vdd_l9_l10_l18_l22", }, 216950314e55SStephen Boyd { "l23", 0x5600, "vdd_l13_l19_l23_l24", }, 217050314e55SStephen Boyd { "l24", 0x5700, "vdd_l13_l19_l23_l24", }, 217150314e55SStephen Boyd { "l25", 0x5800, "vdd_l25", }, 217250314e55SStephen Boyd { "l26", 0x5900, "vdd_l2_l26_l28", }, 217350314e55SStephen Boyd { "l27", 0x5a00, "vdd_l4_l27_l31", }, 217450314e55SStephen Boyd { "l28", 0x5b00, "vdd_l2_l26_l28", }, 217550314e55SStephen Boyd { "l29", 0x5c00, "vdd_l17_l29", }, 217650314e55SStephen Boyd { "l30", 0x5d00, "vdd_l8_l16_l30", }, 217750314e55SStephen Boyd { "l31", 0x5e00, "vdd_l4_l27_l31", }, 217850314e55SStephen Boyd { "l32", 0x5f00, "vdd_l6_l12_l32", }, 217950314e55SStephen Boyd { "lvs1", 0x8000, "vdd_lvs_1_2", }, 218050314e55SStephen Boyd { "lvs2", 0x8100, "vdd_lvs_1_2", }, 218150314e55SStephen Boyd { } 218250314e55SStephen Boyd }; 218350314e55SStephen Boyd 2184ca5cd8c9SRajendra Nayak static const struct spmi_regulator_data pmi8994_regulators[] = { 2185ca5cd8c9SRajendra Nayak { "s1", 0x1400, "vdd_s1", }, 2186ca5cd8c9SRajendra Nayak { "s2", 0x1700, "vdd_s2", }, 2187ca5cd8c9SRajendra Nayak { "s3", 0x1a00, "vdd_s3", }, 2188ca5cd8c9SRajendra Nayak { "l1", 0x4000, "vdd_l1", }, 2189ca5cd8c9SRajendra Nayak { } 2190ca5cd8c9SRajendra Nayak }; 2191ca5cd8c9SRajendra Nayak 21920074c447SAngeloGioacchino Del Regno static const struct spmi_regulator_data pm660_regulators[] = { 21930074c447SAngeloGioacchino Del Regno { "s1", 0x1400, "vdd_s1", }, 21940074c447SAngeloGioacchino Del Regno { "s2", 0x1700, "vdd_s2", }, 21950074c447SAngeloGioacchino Del Regno { "s3", 0x1a00, "vdd_s3", }, 21960074c447SAngeloGioacchino Del Regno { "s4", 0x1d00, "vdd_s3", }, 21970074c447SAngeloGioacchino Del Regno { "s5", 0x2000, "vdd_s5", }, 21980074c447SAngeloGioacchino Del Regno { "s6", 0x2300, "vdd_s6", }, 21990074c447SAngeloGioacchino Del Regno { "l1", 0x4000, "vdd_l1_l6_l7", }, 22000074c447SAngeloGioacchino Del Regno { "l2", 0x4100, "vdd_l2_l3", }, 22010074c447SAngeloGioacchino Del Regno { "l3", 0x4200, "vdd_l2_l3", }, 22020074c447SAngeloGioacchino Del Regno /* l4 is unaccessible on PM660 */ 22030074c447SAngeloGioacchino Del Regno { "l5", 0x4400, "vdd_l5", }, 22040074c447SAngeloGioacchino Del Regno { "l6", 0x4500, "vdd_l1_l6_l7", }, 22050074c447SAngeloGioacchino Del Regno { "l7", 0x4600, "vdd_l1_l6_l7", }, 22060074c447SAngeloGioacchino Del Regno { "l8", 0x4700, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22070074c447SAngeloGioacchino Del Regno { "l9", 0x4800, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22080074c447SAngeloGioacchino Del Regno { "l10", 0x4900, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22090074c447SAngeloGioacchino Del Regno { "l11", 0x4a00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22100074c447SAngeloGioacchino Del Regno { "l12", 0x4b00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22110074c447SAngeloGioacchino Del Regno { "l13", 0x4c00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22120074c447SAngeloGioacchino Del Regno { "l14", 0x4d00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 22130074c447SAngeloGioacchino Del Regno { "l15", 0x4e00, "vdd_l15_l16_l17_l18_l19", }, 22140074c447SAngeloGioacchino Del Regno { "l16", 0x4f00, "vdd_l15_l16_l17_l18_l19", }, 22150074c447SAngeloGioacchino Del Regno { "l17", 0x5000, "vdd_l15_l16_l17_l18_l19", }, 22160074c447SAngeloGioacchino Del Regno { "l18", 0x5100, "vdd_l15_l16_l17_l18_l19", }, 22170074c447SAngeloGioacchino Del Regno { "l19", 0x5200, "vdd_l15_l16_l17_l18_l19", }, 22180074c447SAngeloGioacchino Del Regno { } 22190074c447SAngeloGioacchino Del Regno }; 22200074c447SAngeloGioacchino Del Regno 22210074c447SAngeloGioacchino Del Regno static const struct spmi_regulator_data pm660l_regulators[] = { 22220074c447SAngeloGioacchino Del Regno { "s1", 0x1400, "vdd_s1", }, 22230074c447SAngeloGioacchino Del Regno { "s2", 0x1700, "vdd_s2", }, 22240074c447SAngeloGioacchino Del Regno { "s3", 0x1a00, "vdd_s3", }, 22250074c447SAngeloGioacchino Del Regno { "s4", 0x1d00, "vdd_s4", }, 22260074c447SAngeloGioacchino Del Regno { "s5", 0x2000, "vdd_s5", }, 22270074c447SAngeloGioacchino Del Regno { "l1", 0x4000, "vdd_l1_l9_l10", }, 22280074c447SAngeloGioacchino Del Regno { "l2", 0x4100, "vdd_l2", }, 22290074c447SAngeloGioacchino Del Regno { "l3", 0x4200, "vdd_l3_l5_l7_l8", }, 22300074c447SAngeloGioacchino Del Regno { "l4", 0x4300, "vdd_l4_l6", }, 22310074c447SAngeloGioacchino Del Regno { "l5", 0x4400, "vdd_l3_l5_l7_l8", }, 22320074c447SAngeloGioacchino Del Regno { "l6", 0x4500, "vdd_l4_l6", }, 22330074c447SAngeloGioacchino Del Regno { "l7", 0x4600, "vdd_l3_l5_l7_l8", }, 22340074c447SAngeloGioacchino Del Regno { "l8", 0x4700, "vdd_l3_l5_l7_l8", }, 22350074c447SAngeloGioacchino Del Regno { "l9", 0x4800, "vdd_l1_l9_l10", }, 22360074c447SAngeloGioacchino Del Regno { "l10", 0x4900, "vdd_l1_l9_l10", }, 22370074c447SAngeloGioacchino Del Regno { } 22380074c447SAngeloGioacchino Del Regno }; 22390074c447SAngeloGioacchino Del Regno 22400074c447SAngeloGioacchino Del Regno 22412e36e140SAngelo G. Del Regno static const struct spmi_regulator_data pm8004_regulators[] = { 22422e36e140SAngelo G. Del Regno { "s2", 0x1700, "vdd_s2", }, 22432e36e140SAngelo G. Del Regno { "s5", 0x2000, "vdd_s5", }, 22442e36e140SAngelo G. Del Regno { } 22452e36e140SAngelo G. Del Regno }; 22462e36e140SAngelo G. Del Regno 224742ba89c8SJeffrey Hugo static const struct spmi_regulator_data pm8005_regulators[] = { 224842ba89c8SJeffrey Hugo { "s1", 0x1400, "vdd_s1", }, 224942ba89c8SJeffrey Hugo { "s2", 0x1700, "vdd_s2", }, 225042ba89c8SJeffrey Hugo { "s3", 0x1a00, "vdd_s3", }, 225142ba89c8SJeffrey Hugo { "s4", 0x1d00, "vdd_s4", }, 225242ba89c8SJeffrey Hugo { } 225342ba89c8SJeffrey Hugo }; 225442ba89c8SJeffrey Hugo 225534ceb6a6SRobert Marko static const struct spmi_regulator_data pmp8074_regulators[] = { 225634ceb6a6SRobert Marko { "s1", 0x1400, "vdd_s1"}, 225734ceb6a6SRobert Marko { "s2", 0x1700, "vdd_s2"}, 225834ceb6a6SRobert Marko { "s3", 0x1a00, "vdd_s3"}, 225934ceb6a6SRobert Marko { "s4", 0x1d00, "vdd_s4"}, 226034ceb6a6SRobert Marko { "s5", 0x2000, "vdd_s5"}, 226134ceb6a6SRobert Marko { "l1", 0x4000, "vdd_l1_l2"}, 226234ceb6a6SRobert Marko { "l2", 0x4100, "vdd_l1_l2"}, 226334ceb6a6SRobert Marko { "l3", 0x4200, "vdd_l3_l8"}, 226434ceb6a6SRobert Marko { "l4", 0x4300, "vdd_l4"}, 226534ceb6a6SRobert Marko { "l5", 0x4400, "vdd_l5_l6_l15"}, 226634ceb6a6SRobert Marko { "l6", 0x4500, "vdd_l5_l6_l15"}, 226734ceb6a6SRobert Marko { "l7", 0x4600, "vdd_l7"}, 226834ceb6a6SRobert Marko { "l8", 0x4700, "vdd_l3_l8"}, 226934ceb6a6SRobert Marko { "l9", 0x4800, "vdd_l9"}, 227034ceb6a6SRobert Marko /* l10 is currently unsupported HT_P50 */ 227134ceb6a6SRobert Marko { "l11", 0x4a00, "vdd_l10_l11_l12_l13"}, 227234ceb6a6SRobert Marko { "l12", 0x4b00, "vdd_l10_l11_l12_l13"}, 227334ceb6a6SRobert Marko { "l13", 0x4c00, "vdd_l10_l11_l12_l13"}, 227434ceb6a6SRobert Marko { } 227534ceb6a6SRobert Marko }; 227634ceb6a6SRobert Marko 22770211f68eSJorge Ramirez static const struct spmi_regulator_data pms405_regulators[] = { 22780211f68eSJorge Ramirez { "s3", 0x1a00, "vdd_s3"}, 22790211f68eSJorge Ramirez { } 22800211f68eSJorge Ramirez }; 22810211f68eSJorge Ramirez 2282e92a4047SStephen Boyd static const struct of_device_id qcom_spmi_regulator_match[] = { 22832e36e140SAngelo G. Del Regno { .compatible = "qcom,pm8004-regulators", .data = &pm8004_regulators }, 228442ba89c8SJeffrey Hugo { .compatible = "qcom,pm8005-regulators", .data = &pm8005_regulators }, 2285f8843e5eSDominik Kobinski { .compatible = "qcom,pm8226-regulators", .data = &pm8226_regulators }, 2286e92a4047SStephen Boyd { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators }, 2287e92a4047SStephen Boyd { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators }, 2288e92a4047SStephen Boyd { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators }, 2289e4ff1710SAngelo G. Del Regno { .compatible = "qcom,pm8950-regulators", .data = &pm8950_regulators }, 229050314e55SStephen Boyd { .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators }, 2291ca5cd8c9SRajendra Nayak { .compatible = "qcom,pmi8994-regulators", .data = &pmi8994_regulators }, 22920074c447SAngeloGioacchino Del Regno { .compatible = "qcom,pm660-regulators", .data = &pm660_regulators }, 22930074c447SAngeloGioacchino Del Regno { .compatible = "qcom,pm660l-regulators", .data = &pm660l_regulators }, 229434ceb6a6SRobert Marko { .compatible = "qcom,pmp8074-regulators", .data = &pmp8074_regulators }, 22950211f68eSJorge Ramirez { .compatible = "qcom,pms405-regulators", .data = &pms405_regulators }, 2296e92a4047SStephen Boyd { } 2297e92a4047SStephen Boyd }; 2298e92a4047SStephen Boyd MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match); 2299e92a4047SStephen Boyd 2300e92a4047SStephen Boyd static int qcom_spmi_regulator_probe(struct platform_device *pdev) 2301e92a4047SStephen Boyd { 2302e92a4047SStephen Boyd const struct spmi_regulator_data *reg; 230386f4ff7aSJorge Ramirez-Ortiz const struct spmi_voltage_range *range; 2304e92a4047SStephen Boyd const struct of_device_id *match; 2305e92a4047SStephen Boyd struct regulator_config config = { }; 2306e92a4047SStephen Boyd struct regulator_dev *rdev; 2307e92a4047SStephen Boyd struct spmi_regulator *vreg; 2308e92a4047SStephen Boyd struct regmap *regmap; 2309e92a4047SStephen Boyd const char *name; 2310e92a4047SStephen Boyd struct device *dev = &pdev->dev; 23110caecaa8SIlia Lin struct device_node *node = pdev->dev.of_node; 2312fffe7f52SNiklas Cassel struct device_node *syscon, *reg_node; 2313fffe7f52SNiklas Cassel struct property *reg_prop; 23140caecaa8SIlia Lin int ret, lenp; 2315e92a4047SStephen Boyd struct list_head *vreg_list; 2316e92a4047SStephen Boyd 2317e92a4047SStephen Boyd vreg_list = devm_kzalloc(dev, sizeof(*vreg_list), GFP_KERNEL); 2318e92a4047SStephen Boyd if (!vreg_list) 2319e92a4047SStephen Boyd return -ENOMEM; 2320e92a4047SStephen Boyd INIT_LIST_HEAD(vreg_list); 2321e92a4047SStephen Boyd platform_set_drvdata(pdev, vreg_list); 2322e92a4047SStephen Boyd 2323e92a4047SStephen Boyd regmap = dev_get_regmap(dev->parent, NULL); 2324e92a4047SStephen Boyd if (!regmap) 2325e92a4047SStephen Boyd return -ENODEV; 2326e92a4047SStephen Boyd 2327e92a4047SStephen Boyd match = of_match_device(qcom_spmi_regulator_match, &pdev->dev); 2328e92a4047SStephen Boyd if (!match) 2329e92a4047SStephen Boyd return -ENODEV; 2330e92a4047SStephen Boyd 23310caecaa8SIlia Lin if (of_find_property(node, "qcom,saw-reg", &lenp)) { 23320caecaa8SIlia Lin syscon = of_parse_phandle(node, "qcom,saw-reg", 0); 23330caecaa8SIlia Lin saw_regmap = syscon_node_to_regmap(syscon); 23340caecaa8SIlia Lin of_node_put(syscon); 233585046a15SNiklas Cassel if (IS_ERR(saw_regmap)) 23360caecaa8SIlia Lin dev_err(dev, "ERROR reading SAW regmap\n"); 23370caecaa8SIlia Lin } 23380caecaa8SIlia Lin 2339e92a4047SStephen Boyd for (reg = match->data; reg->name; reg++) { 23400caecaa8SIlia Lin 2341fffe7f52SNiklas Cassel if (saw_regmap) { 2342fffe7f52SNiklas Cassel reg_node = of_get_child_by_name(node, reg->name); 2343fffe7f52SNiklas Cassel reg_prop = of_find_property(reg_node, "qcom,saw-slave", 2344fffe7f52SNiklas Cassel &lenp); 2345fffe7f52SNiklas Cassel of_node_put(reg_node); 2346fffe7f52SNiklas Cassel if (reg_prop) 23470caecaa8SIlia Lin continue; 23480caecaa8SIlia Lin } 23490caecaa8SIlia Lin 2350e92a4047SStephen Boyd vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); 2351e92a4047SStephen Boyd if (!vreg) 2352e92a4047SStephen Boyd return -ENOMEM; 2353e92a4047SStephen Boyd 2354e92a4047SStephen Boyd vreg->dev = dev; 2355e92a4047SStephen Boyd vreg->base = reg->base; 2356e92a4047SStephen Boyd vreg->regmap = regmap; 2357e92a4047SStephen Boyd if (reg->ocp) { 2358e92a4047SStephen Boyd vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp); 2359b6688015SMatti Vaittinen if (vreg->ocp_irq < 0) 2360b6688015SMatti Vaittinen return vreg->ocp_irq; 2361e92a4047SStephen Boyd } 2362e92a4047SStephen Boyd vreg->desc.id = -1; 2363e92a4047SStephen Boyd vreg->desc.owner = THIS_MODULE; 2364e92a4047SStephen Boyd vreg->desc.type = REGULATOR_VOLTAGE; 23659d485332SAxel Lin vreg->desc.enable_reg = reg->base + SPMI_COMMON_REG_ENABLE; 23669d485332SAxel Lin vreg->desc.enable_mask = SPMI_COMMON_ENABLE_MASK; 23679d485332SAxel Lin vreg->desc.enable_val = SPMI_COMMON_ENABLE; 2368e92a4047SStephen Boyd vreg->desc.name = name = reg->name; 2369e92a4047SStephen Boyd vreg->desc.supply_name = reg->supply; 2370e92a4047SStephen Boyd vreg->desc.of_match = reg->name; 2371e92a4047SStephen Boyd vreg->desc.of_parse_cb = spmi_regulator_of_parse; 2372e92a4047SStephen Boyd vreg->desc.of_map_mode = spmi_regulator_of_map_mode; 2373e92a4047SStephen Boyd 2374e92a4047SStephen Boyd ret = spmi_regulator_match(vreg, reg->force_type); 2375e92a4047SStephen Boyd if (ret) 23766ee5c044SStephen Boyd continue; 2377e92a4047SStephen Boyd 2378fffe7f52SNiklas Cassel if (saw_regmap) { 2379fffe7f52SNiklas Cassel reg_node = of_get_child_by_name(node, reg->name); 2380fffe7f52SNiklas Cassel reg_prop = of_find_property(reg_node, "qcom,saw-leader", 2381fffe7f52SNiklas Cassel &lenp); 2382fffe7f52SNiklas Cassel of_node_put(reg_node); 2383fffe7f52SNiklas Cassel if (reg_prop) { 23840caecaa8SIlia Lin spmi_saw_ops = *(vreg->desc.ops); 2385fffe7f52SNiklas Cassel spmi_saw_ops.set_voltage_sel = 23860caecaa8SIlia Lin spmi_regulator_saw_set_voltage; 23870caecaa8SIlia Lin vreg->desc.ops = &spmi_saw_ops; 23880caecaa8SIlia Lin } 2389fffe7f52SNiklas Cassel } 23900caecaa8SIlia Lin 2391b01d1823SJeffrey Hugo if (vreg->set_points && vreg->set_points->count == 1) { 239286f4ff7aSJorge Ramirez-Ortiz /* since there is only one range */ 239386f4ff7aSJorge Ramirez-Ortiz range = vreg->set_points->range; 239486f4ff7aSJorge Ramirez-Ortiz vreg->desc.uV_step = range->step_uV; 239586f4ff7aSJorge Ramirez-Ortiz } 239686f4ff7aSJorge Ramirez-Ortiz 2397e92a4047SStephen Boyd config.dev = dev; 2398e92a4047SStephen Boyd config.driver_data = vreg; 23999d485332SAxel Lin config.regmap = regmap; 2400e92a4047SStephen Boyd rdev = devm_regulator_register(dev, &vreg->desc, &config); 2401e92a4047SStephen Boyd if (IS_ERR(rdev)) { 2402e92a4047SStephen Boyd dev_err(dev, "failed to register %s\n", name); 2403b6688015SMatti Vaittinen return PTR_ERR(rdev); 2404e92a4047SStephen Boyd } 2405e92a4047SStephen Boyd 2406e92a4047SStephen Boyd INIT_LIST_HEAD(&vreg->node); 2407e92a4047SStephen Boyd list_add(&vreg->node, vreg_list); 2408e92a4047SStephen Boyd } 2409e92a4047SStephen Boyd 2410e92a4047SStephen Boyd return 0; 2411e92a4047SStephen Boyd } 2412e92a4047SStephen Boyd 2413e92a4047SStephen Boyd static struct platform_driver qcom_spmi_regulator_driver = { 2414e92a4047SStephen Boyd .driver = { 2415e92a4047SStephen Boyd .name = "qcom-spmi-regulator", 2416e92a4047SStephen Boyd .of_match_table = qcom_spmi_regulator_match, 2417e92a4047SStephen Boyd }, 2418e92a4047SStephen Boyd .probe = qcom_spmi_regulator_probe, 2419e92a4047SStephen Boyd }; 2420e92a4047SStephen Boyd module_platform_driver(qcom_spmi_regulator_driver); 2421e92a4047SStephen Boyd 2422e92a4047SStephen Boyd MODULE_DESCRIPTION("Qualcomm SPMI PMIC regulator driver"); 2423e92a4047SStephen Boyd MODULE_LICENSE("GPL v2"); 2424e92a4047SStephen Boyd MODULE_ALIAS("platform:qcom-spmi-regulator"); 2425