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, 102e92a4047SStephen Boyd }; 103e92a4047SStephen Boyd 104e92a4047SStephen Boyd enum spmi_regulator_type { 105e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_BUCK = 0x03, 106e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_LDO = 0x04, 107e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_VS = 0x05, 108e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_BOOST = 0x1b, 109e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_FTS = 0x1c, 110e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_BOOST_BYP = 0x1f, 111e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_ULT_LDO = 0x21, 112e92a4047SStephen Boyd SPMI_REGULATOR_TYPE_ULT_BUCK = 0x22, 113e92a4047SStephen Boyd }; 114e92a4047SStephen Boyd 115e92a4047SStephen Boyd enum spmi_regulator_subtype { 116e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_GP_CTL = 0x08, 117e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_RF_CTL = 0x09, 118e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N50 = 0x01, 119e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N150 = 0x02, 120e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N300 = 0x03, 121e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N600 = 0x04, 122e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N1200 = 0x05, 123e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N600_ST = 0x06, 124e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N1200_ST = 0x07, 125e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N900_ST = 0x14, 126e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_N300_ST = 0x15, 127e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P50 = 0x08, 128e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P150 = 0x09, 129e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P300 = 0x0a, 130e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P600 = 0x0b, 131e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_P1200 = 0x0c, 132e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LN = 0x10, 133e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P50 = 0x28, 134e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P150 = 0x29, 135e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P300 = 0x2a, 136e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P600 = 0x2b, 137e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P1200 = 0x2c, 138e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV_P450 = 0x2d, 139328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_N300_ST = 0x30, 140328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_N600_ST = 0x31, 141328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_N1200_ST = 0x32, 142328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_LVP150 = 0x3b, 143328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_HT_LVP300 = 0x3c, 144328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_N300_ST = 0x42, 145328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_N600_ST = 0x43, 146328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_P50 = 0x46, 147328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_P150 = 0x47, 148328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_P600 = 0x49, 149328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_LVP150 = 0x4d, 150328816c2SAngeloGioacchino Del Regno SPMI_REGULATOR_SUBTYPE_L660_LVP600 = 0x4f, 151e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV100 = 0x01, 152e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_LV300 = 0x02, 153e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_MV300 = 0x08, 154e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_MV500 = 0x09, 155e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_HDMI = 0x10, 156e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_OTG = 0x11, 157e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_5V_BOOST = 0x01, 158e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_FTS_CTL = 0x08, 159e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_FTS2p5_CTL = 0x09, 16042ba89c8SJeffrey Hugo SPMI_REGULATOR_SUBTYPE_FTS426_CTL = 0x0a, 161e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_BB_2A = 0x01, 162e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL1 = 0x0d, 163e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL2 = 0x0e, 164e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL3 = 0x0f, 165e92a4047SStephen Boyd SPMI_REGULATOR_SUBTYPE_ULT_HF_CTL4 = 0x10, 1660211f68eSJorge Ramirez SPMI_REGULATOR_SUBTYPE_HFS430 = 0x0a, 167e92a4047SStephen Boyd }; 168e92a4047SStephen Boyd 169e92a4047SStephen Boyd enum spmi_common_regulator_registers { 170e92a4047SStephen Boyd SPMI_COMMON_REG_DIG_MAJOR_REV = 0x01, 171e92a4047SStephen Boyd SPMI_COMMON_REG_TYPE = 0x04, 172e92a4047SStephen Boyd SPMI_COMMON_REG_SUBTYPE = 0x05, 173e92a4047SStephen Boyd SPMI_COMMON_REG_VOLTAGE_RANGE = 0x40, 174e92a4047SStephen Boyd SPMI_COMMON_REG_VOLTAGE_SET = 0x41, 175e92a4047SStephen Boyd SPMI_COMMON_REG_MODE = 0x45, 176e92a4047SStephen Boyd SPMI_COMMON_REG_ENABLE = 0x46, 177e92a4047SStephen Boyd SPMI_COMMON_REG_PULL_DOWN = 0x48, 178e92a4047SStephen Boyd SPMI_COMMON_REG_SOFT_START = 0x4c, 179e92a4047SStephen Boyd SPMI_COMMON_REG_STEP_CTRL = 0x61, 180e92a4047SStephen Boyd }; 181e92a4047SStephen Boyd 18242ba89c8SJeffrey Hugo /* 18342ba89c8SJeffrey Hugo * Second common register layout used by newer devices starting with ftsmps426 18442ba89c8SJeffrey Hugo * Note that some of the registers from the first common layout remain 18542ba89c8SJeffrey Hugo * unchanged and their definition is not duplicated. 18642ba89c8SJeffrey Hugo */ 18742ba89c8SJeffrey Hugo enum spmi_ftsmps426_regulator_registers { 18842ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_LSB = 0x40, 18942ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_MSB = 0x41, 19042ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_ULS_LSB = 0x68, 19142ba89c8SJeffrey Hugo SPMI_FTSMPS426_REG_VOLTAGE_ULS_MSB = 0x69, 19242ba89c8SJeffrey Hugo }; 19342ba89c8SJeffrey Hugo 194e92a4047SStephen Boyd enum spmi_vs_registers { 195e92a4047SStephen Boyd SPMI_VS_REG_OCP = 0x4a, 196e92a4047SStephen Boyd SPMI_VS_REG_SOFT_START = 0x4c, 197e92a4047SStephen Boyd }; 198e92a4047SStephen Boyd 199e92a4047SStephen Boyd enum spmi_boost_registers { 200e92a4047SStephen Boyd SPMI_BOOST_REG_CURRENT_LIMIT = 0x4a, 201e92a4047SStephen Boyd }; 202e92a4047SStephen Boyd 203e92a4047SStephen Boyd enum spmi_boost_byp_registers { 204e92a4047SStephen Boyd SPMI_BOOST_BYP_REG_CURRENT_LIMIT = 0x4b, 205e92a4047SStephen Boyd }; 206e92a4047SStephen Boyd 2070caecaa8SIlia Lin enum spmi_saw3_registers { 2080caecaa8SIlia Lin SAW3_SECURE = 0x00, 2090caecaa8SIlia Lin SAW3_ID = 0x04, 2100caecaa8SIlia Lin SAW3_SPM_STS = 0x0C, 2110caecaa8SIlia Lin SAW3_AVS_STS = 0x10, 2120caecaa8SIlia Lin SAW3_PMIC_STS = 0x14, 2130caecaa8SIlia Lin SAW3_RST = 0x18, 2140caecaa8SIlia Lin SAW3_VCTL = 0x1C, 2150caecaa8SIlia Lin SAW3_AVS_CTL = 0x20, 2160caecaa8SIlia Lin SAW3_AVS_LIMIT = 0x24, 2170caecaa8SIlia Lin SAW3_AVS_DLY = 0x28, 2180caecaa8SIlia Lin SAW3_AVS_HYSTERESIS = 0x2C, 2190caecaa8SIlia Lin SAW3_SPM_STS2 = 0x38, 2200caecaa8SIlia Lin SAW3_SPM_PMIC_DATA_3 = 0x4C, 2210caecaa8SIlia Lin SAW3_VERSION = 0xFD0, 2220caecaa8SIlia Lin }; 2230caecaa8SIlia Lin 224e92a4047SStephen Boyd /* Used for indexing into ctrl_reg. These are offets from 0x40 */ 225e92a4047SStephen Boyd enum spmi_common_control_register_index { 226e92a4047SStephen Boyd SPMI_COMMON_IDX_VOLTAGE_RANGE = 0, 227e92a4047SStephen Boyd SPMI_COMMON_IDX_VOLTAGE_SET = 1, 228e92a4047SStephen Boyd SPMI_COMMON_IDX_MODE = 5, 229e92a4047SStephen Boyd SPMI_COMMON_IDX_ENABLE = 6, 230e92a4047SStephen Boyd }; 231e92a4047SStephen Boyd 232e92a4047SStephen Boyd /* Common regulator control register layout */ 233e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_MASK 0x80 234e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE 0x80 235e92a4047SStephen Boyd #define SPMI_COMMON_DISABLE 0x00 236e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN3_MASK 0x08 237e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN2_MASK 0x04 238e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN1_MASK 0x02 239e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_HW_EN0_MASK 0x01 240e92a4047SStephen Boyd #define SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK 0x0f 241e92a4047SStephen Boyd 242e92a4047SStephen Boyd /* Common regulator mode register layout */ 243e92a4047SStephen Boyd #define SPMI_COMMON_MODE_HPM_MASK 0x80 244e92a4047SStephen Boyd #define SPMI_COMMON_MODE_AUTO_MASK 0x40 245e92a4047SStephen Boyd #define SPMI_COMMON_MODE_BYPASS_MASK 0x20 246e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK 0x10 247e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN3_MASK 0x08 248e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN2_MASK 0x04 249e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN1_MASK 0x02 250e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_HW_EN0_MASK 0x01 251e92a4047SStephen Boyd #define SPMI_COMMON_MODE_FOLLOW_ALL_MASK 0x1f 252e92a4047SStephen Boyd 25342ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_BYPASS_MASK 3 25442ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_RETENTION_MASK 4 25542ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_LPM_MASK 5 25642ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_AUTO_MASK 6 25742ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_HPM_MASK 7 25842ba89c8SJeffrey Hugo 25942ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_MODE_MASK 0x07 26042ba89c8SJeffrey Hugo 261e92a4047SStephen Boyd /* Common regulator pull down control register layout */ 262e92a4047SStephen Boyd #define SPMI_COMMON_PULL_DOWN_ENABLE_MASK 0x80 263e92a4047SStephen Boyd 264e92a4047SStephen Boyd /* LDO regulator current limit control register layout */ 265e92a4047SStephen Boyd #define SPMI_LDO_CURRENT_LIMIT_ENABLE_MASK 0x80 266e92a4047SStephen Boyd 267e92a4047SStephen Boyd /* LDO regulator soft start control register layout */ 268e92a4047SStephen Boyd #define SPMI_LDO_SOFT_START_ENABLE_MASK 0x80 269e92a4047SStephen Boyd 270e92a4047SStephen Boyd /* VS regulator over current protection control register layout */ 271e92a4047SStephen Boyd #define SPMI_VS_OCP_OVERRIDE 0x01 272e92a4047SStephen Boyd #define SPMI_VS_OCP_NO_OVERRIDE 0x00 273e92a4047SStephen Boyd 274e92a4047SStephen Boyd /* VS regulator soft start control register layout */ 275e92a4047SStephen Boyd #define SPMI_VS_SOFT_START_ENABLE_MASK 0x80 276e92a4047SStephen Boyd #define SPMI_VS_SOFT_START_SEL_MASK 0x03 277e92a4047SStephen Boyd 278e92a4047SStephen Boyd /* Boost regulator current limit control register layout */ 279e92a4047SStephen Boyd #define SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK 0x80 280e92a4047SStephen Boyd #define SPMI_BOOST_CURRENT_LIMIT_MASK 0x07 281e92a4047SStephen Boyd 282e92a4047SStephen Boyd #define SPMI_VS_OCP_DEFAULT_MAX_RETRIES 10 283e92a4047SStephen Boyd #define SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS 30 284e92a4047SStephen Boyd #define SPMI_VS_OCP_FALL_DELAY_US 90 285e92a4047SStephen Boyd #define SPMI_VS_OCP_FAULT_DELAY_US 20000 286e92a4047SStephen Boyd 287e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_STEP_MASK 0x18 288e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT 3 289e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_DELAY_MASK 0x07 290e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT 0 291e92a4047SStephen Boyd 292e92a4047SStephen Boyd /* Clock rate in kHz of the FTSMPS regulator reference clock. */ 293e92a4047SStephen Boyd #define SPMI_FTSMPS_CLOCK_RATE 19200 294e92a4047SStephen Boyd 295e92a4047SStephen Boyd /* Minimum voltage stepper delay for each step. */ 296e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_DELAY 8 2972cf7b99cSStephen Boyd #define SPMI_DEFAULT_STEP_DELAY 20 298e92a4047SStephen Boyd 299e92a4047SStephen Boyd /* 300e92a4047SStephen Boyd * The ratio SPMI_FTSMPS_STEP_MARGIN_NUM/SPMI_FTSMPS_STEP_MARGIN_DEN is used to 301e92a4047SStephen Boyd * adjust the step rate in order to account for oscillator variance. 302e92a4047SStephen Boyd */ 303e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_MARGIN_NUM 4 304e92a4047SStephen Boyd #define SPMI_FTSMPS_STEP_MARGIN_DEN 5 305e92a4047SStephen Boyd 30642ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK 0x03 30742ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT 0 30842ba89c8SJeffrey Hugo 30942ba89c8SJeffrey Hugo /* Clock rate in kHz of the FTSMPS426 regulator reference clock. */ 31042ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_CLOCK_RATE 4800 31142ba89c8SJeffrey Hugo 3120211f68eSJorge Ramirez #define SPMI_HFS430_CLOCK_RATE 1600 3130211f68eSJorge Ramirez 31442ba89c8SJeffrey Hugo /* Minimum voltage stepper delay for each step. */ 31542ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_DELAY 2 31642ba89c8SJeffrey Hugo 31742ba89c8SJeffrey Hugo /* 31842ba89c8SJeffrey Hugo * The ratio SPMI_FTSMPS426_STEP_MARGIN_NUM/SPMI_FTSMPS426_STEP_MARGIN_DEN is 31942ba89c8SJeffrey Hugo * used to adjust the step rate in order to account for oscillator variance. 32042ba89c8SJeffrey Hugo */ 32142ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_MARGIN_NUM 10 32242ba89c8SJeffrey Hugo #define SPMI_FTSMPS426_STEP_MARGIN_DEN 11 32342ba89c8SJeffrey Hugo 32442ba89c8SJeffrey Hugo 325e92a4047SStephen Boyd /* VSET value to decide the range of ULT SMPS */ 326e92a4047SStephen Boyd #define ULT_SMPS_RANGE_SPLIT 0x60 327e92a4047SStephen Boyd 328e92a4047SStephen Boyd /** 329e92a4047SStephen Boyd * struct spmi_voltage_range - regulator set point voltage mapping description 330e92a4047SStephen Boyd * @min_uV: Minimum programmable output voltage resulting from 331e92a4047SStephen Boyd * set point register value 0x00 332e92a4047SStephen Boyd * @max_uV: Maximum programmable output voltage 333e92a4047SStephen Boyd * @step_uV: Output voltage increase resulting from the set point 334e92a4047SStephen Boyd * register value increasing by 1 335e92a4047SStephen Boyd * @set_point_min_uV: Minimum allowed voltage 336e92a4047SStephen Boyd * @set_point_max_uV: Maximum allowed voltage. This may be tweaked in order 337e92a4047SStephen Boyd * to pick which range should be used in the case of 338e92a4047SStephen Boyd * overlapping set points. 339e92a4047SStephen Boyd * @n_voltages: Number of preferred voltage set points present in this 340e92a4047SStephen Boyd * range 341e92a4047SStephen Boyd * @range_sel: Voltage range register value corresponding to this range 342e92a4047SStephen Boyd * 343e92a4047SStephen Boyd * The following relationships must be true for the values used in this struct: 344e92a4047SStephen Boyd * (max_uV - min_uV) % step_uV == 0 345e92a4047SStephen Boyd * (set_point_min_uV - min_uV) % step_uV == 0* 346e92a4047SStephen Boyd * (set_point_max_uV - min_uV) % step_uV == 0* 347e92a4047SStephen Boyd * n_voltages = (set_point_max_uV - set_point_min_uV) / step_uV + 1 348e92a4047SStephen Boyd * 349e92a4047SStephen Boyd * *Note, set_point_min_uV == set_point_max_uV == 0 is allowed in order to 350e92a4047SStephen Boyd * specify that the voltage range has meaning, but is not preferred. 351e92a4047SStephen Boyd */ 352e92a4047SStephen Boyd struct spmi_voltage_range { 353e92a4047SStephen Boyd int min_uV; 354e92a4047SStephen Boyd int max_uV; 355e92a4047SStephen Boyd int step_uV; 356e92a4047SStephen Boyd int set_point_min_uV; 357e92a4047SStephen Boyd int set_point_max_uV; 358e92a4047SStephen Boyd unsigned n_voltages; 359e92a4047SStephen Boyd u8 range_sel; 360e92a4047SStephen Boyd }; 361e92a4047SStephen Boyd 362e92a4047SStephen Boyd /* 363e92a4047SStephen Boyd * The ranges specified in the spmi_voltage_set_points struct must be listed 364e92a4047SStephen Boyd * so that range[i].set_point_max_uV < range[i+1].set_point_min_uV. 365e92a4047SStephen Boyd */ 366e92a4047SStephen Boyd struct spmi_voltage_set_points { 367e92a4047SStephen Boyd struct spmi_voltage_range *range; 368e92a4047SStephen Boyd int count; 369e92a4047SStephen Boyd unsigned n_voltages; 370e92a4047SStephen Boyd }; 371e92a4047SStephen Boyd 372e92a4047SStephen Boyd struct spmi_regulator { 373e92a4047SStephen Boyd struct regulator_desc desc; 374e92a4047SStephen Boyd struct device *dev; 375e92a4047SStephen Boyd struct delayed_work ocp_work; 376e92a4047SStephen Boyd struct regmap *regmap; 377e92a4047SStephen Boyd struct spmi_voltage_set_points *set_points; 378e92a4047SStephen Boyd enum spmi_regulator_logical_type logical_type; 379e92a4047SStephen Boyd int ocp_irq; 380e92a4047SStephen Boyd int ocp_count; 381e92a4047SStephen Boyd int ocp_max_retries; 382e92a4047SStephen Boyd int ocp_retry_delay_ms; 383e92a4047SStephen Boyd int hpm_min_load; 384e92a4047SStephen Boyd int slew_rate; 385e92a4047SStephen Boyd ktime_t vs_enable_time; 386e92a4047SStephen Boyd u16 base; 387e92a4047SStephen Boyd struct list_head node; 388e92a4047SStephen Boyd }; 389e92a4047SStephen Boyd 390e92a4047SStephen Boyd struct spmi_regulator_mapping { 391e92a4047SStephen Boyd enum spmi_regulator_type type; 392e92a4047SStephen Boyd enum spmi_regulator_subtype subtype; 393e92a4047SStephen Boyd enum spmi_regulator_logical_type logical_type; 394e92a4047SStephen Boyd u32 revision_min; 395e92a4047SStephen Boyd u32 revision_max; 3963b619e3eSRikard Falkeborn const struct regulator_ops *ops; 397e92a4047SStephen Boyd struct spmi_voltage_set_points *set_points; 398e92a4047SStephen Boyd int hpm_min_load; 399e92a4047SStephen Boyd }; 400e92a4047SStephen Boyd 401e92a4047SStephen Boyd struct spmi_regulator_data { 402e92a4047SStephen Boyd const char *name; 403e92a4047SStephen Boyd u16 base; 404e92a4047SStephen Boyd const char *supply; 405e92a4047SStephen Boyd const char *ocp; 406e92a4047SStephen Boyd u16 force_type; 407e92a4047SStephen Boyd }; 408e92a4047SStephen Boyd 409e92a4047SStephen Boyd #define SPMI_VREG(_type, _subtype, _dig_major_min, _dig_major_max, \ 410e92a4047SStephen Boyd _logical_type, _ops_val, _set_points_val, _hpm_min_load) \ 411e92a4047SStephen Boyd { \ 412e92a4047SStephen Boyd .type = SPMI_REGULATOR_TYPE_##_type, \ 413e92a4047SStephen Boyd .subtype = SPMI_REGULATOR_SUBTYPE_##_subtype, \ 414e92a4047SStephen Boyd .revision_min = _dig_major_min, \ 415e92a4047SStephen Boyd .revision_max = _dig_major_max, \ 416e92a4047SStephen Boyd .logical_type = SPMI_REGULATOR_LOGICAL_TYPE_##_logical_type, \ 417e92a4047SStephen Boyd .ops = &spmi_##_ops_val##_ops, \ 418e92a4047SStephen Boyd .set_points = &_set_points_val##_set_points, \ 419e92a4047SStephen Boyd .hpm_min_load = _hpm_min_load, \ 420e92a4047SStephen Boyd } 421e92a4047SStephen Boyd 422e92a4047SStephen Boyd #define SPMI_VREG_VS(_subtype, _dig_major_min, _dig_major_max) \ 423e92a4047SStephen Boyd { \ 424e92a4047SStephen Boyd .type = SPMI_REGULATOR_TYPE_VS, \ 425e92a4047SStephen Boyd .subtype = SPMI_REGULATOR_SUBTYPE_##_subtype, \ 426e92a4047SStephen Boyd .revision_min = _dig_major_min, \ 427e92a4047SStephen Boyd .revision_max = _dig_major_max, \ 428e92a4047SStephen Boyd .logical_type = SPMI_REGULATOR_LOGICAL_TYPE_VS, \ 429e92a4047SStephen Boyd .ops = &spmi_vs_ops, \ 430e92a4047SStephen Boyd } 431e92a4047SStephen Boyd 432e92a4047SStephen Boyd #define SPMI_VOLTAGE_RANGE(_range_sel, _min_uV, _set_point_min_uV, \ 433e92a4047SStephen Boyd _set_point_max_uV, _max_uV, _step_uV) \ 434e92a4047SStephen Boyd { \ 435e92a4047SStephen Boyd .min_uV = _min_uV, \ 436e92a4047SStephen Boyd .max_uV = _max_uV, \ 437e92a4047SStephen Boyd .set_point_min_uV = _set_point_min_uV, \ 438e92a4047SStephen Boyd .set_point_max_uV = _set_point_max_uV, \ 439e92a4047SStephen Boyd .step_uV = _step_uV, \ 440e92a4047SStephen Boyd .range_sel = _range_sel, \ 441e92a4047SStephen Boyd } 442e92a4047SStephen Boyd 443e92a4047SStephen Boyd #define DEFINE_SPMI_SET_POINTS(name) \ 444e92a4047SStephen Boyd struct spmi_voltage_set_points name##_set_points = { \ 445e92a4047SStephen Boyd .range = name##_ranges, \ 446e92a4047SStephen Boyd .count = ARRAY_SIZE(name##_ranges), \ 447e92a4047SStephen Boyd } 448e92a4047SStephen Boyd 449e92a4047SStephen Boyd /* 450e92a4047SStephen Boyd * These tables contain the physically available PMIC regulator voltage setpoint 451e92a4047SStephen Boyd * ranges. Where two ranges overlap in hardware, one of the ranges is trimmed 452e92a4047SStephen Boyd * to ensure that the setpoints available to software are monotonically 453e92a4047SStephen Boyd * increasing and unique. The set_voltage callback functions expect these 454e92a4047SStephen Boyd * properties to hold. 455e92a4047SStephen Boyd */ 456e92a4047SStephen Boyd static struct spmi_voltage_range pldo_ranges[] = { 457e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500), 458e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(3, 1500000, 1550000, 3075000, 3075000, 25000), 459e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(4, 1750000, 3100000, 4900000, 4900000, 50000), 460e92a4047SStephen Boyd }; 461e92a4047SStephen Boyd 462e92a4047SStephen Boyd static struct spmi_voltage_range nldo1_ranges[] = { 463e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 750000, 1537500, 1537500, 12500), 464e92a4047SStephen Boyd }; 465e92a4047SStephen Boyd 466e92a4047SStephen Boyd static struct spmi_voltage_range nldo2_ranges[] = { 467e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 0, 0, 1537500, 12500), 468e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 375000, 375000, 768750, 768750, 6250), 469e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 775000, 1537500, 1537500, 12500), 470e92a4047SStephen Boyd }; 471e92a4047SStephen Boyd 472e92a4047SStephen Boyd static struct spmi_voltage_range nldo3_ranges[] = { 473e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500), 474e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 375000, 0, 0, 1537500, 12500), 475e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(2, 750000, 0, 0, 1537500, 12500), 476e92a4047SStephen Boyd }; 477e92a4047SStephen Boyd 478e92a4047SStephen Boyd static struct spmi_voltage_range ln_ldo_ranges[] = { 479e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 690000, 690000, 1110000, 1110000, 60000), 480e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 1380000, 1380000, 2220000, 2220000, 120000), 481e92a4047SStephen Boyd }; 482e92a4047SStephen Boyd 483e92a4047SStephen Boyd static struct spmi_voltage_range smps_ranges[] = { 484e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500), 485e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 1550000, 1575000, 3125000, 3125000, 25000), 486e92a4047SStephen Boyd }; 487e92a4047SStephen Boyd 488e92a4047SStephen Boyd static struct spmi_voltage_range ftsmps_ranges[] = { 489e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 0, 350000, 1275000, 1275000, 5000), 490e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 0, 1280000, 2040000, 2040000, 10000), 491e92a4047SStephen Boyd }; 492e92a4047SStephen Boyd 493e92a4047SStephen Boyd static struct spmi_voltage_range ftsmps2p5_ranges[] = { 494e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 80000, 350000, 1355000, 1355000, 5000), 495e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 160000, 1360000, 2200000, 2200000, 10000), 496e92a4047SStephen Boyd }; 497e92a4047SStephen Boyd 49842ba89c8SJeffrey Hugo static struct spmi_voltage_range ftsmps426_ranges[] = { 49942ba89c8SJeffrey Hugo SPMI_VOLTAGE_RANGE(0, 0, 320000, 1352000, 1352000, 4000), 50042ba89c8SJeffrey Hugo }; 50142ba89c8SJeffrey Hugo 502e92a4047SStephen Boyd static struct spmi_voltage_range boost_ranges[] = { 503e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 4000000, 4000000, 5550000, 5550000, 50000), 504e92a4047SStephen Boyd }; 505e92a4047SStephen Boyd 506e92a4047SStephen Boyd static struct spmi_voltage_range boost_byp_ranges[] = { 507e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 2500000, 2500000, 5200000, 5650000, 50000), 508e92a4047SStephen Boyd }; 509e92a4047SStephen Boyd 510e92a4047SStephen Boyd static struct spmi_voltage_range ult_lo_smps_ranges[] = { 511e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1562500, 1562500, 12500), 512e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(1, 750000, 0, 0, 1525000, 25000), 513e92a4047SStephen Boyd }; 514e92a4047SStephen Boyd 515e92a4047SStephen Boyd static struct spmi_voltage_range ult_ho_smps_ranges[] = { 516e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 1550000, 1550000, 2325000, 2325000, 25000), 517e92a4047SStephen Boyd }; 518e92a4047SStephen Boyd 519e92a4047SStephen Boyd static struct spmi_voltage_range ult_nldo_ranges[] = { 520e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 375000, 375000, 1537500, 1537500, 12500), 521e92a4047SStephen Boyd }; 522e92a4047SStephen Boyd 523e92a4047SStephen Boyd static struct spmi_voltage_range ult_pldo_ranges[] = { 524e92a4047SStephen Boyd SPMI_VOLTAGE_RANGE(0, 1750000, 1750000, 3337500, 3337500, 12500), 525e92a4047SStephen Boyd }; 526e92a4047SStephen Boyd 527328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range pldo660_ranges[] = { 528328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 3544000, 3544000, 8000), 529328816c2SAngeloGioacchino Del Regno }; 530328816c2SAngeloGioacchino Del Regno 531328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range nldo660_ranges[] = { 532328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 320000, 320000, 1304000, 1304000, 8000), 533328816c2SAngeloGioacchino Del Regno }; 534328816c2SAngeloGioacchino Del Regno 535328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range ht_lvpldo_ranges[] = { 536328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 1504000, 1504000, 2000000, 2000000, 8000), 537328816c2SAngeloGioacchino Del Regno }; 538328816c2SAngeloGioacchino Del Regno 539328816c2SAngeloGioacchino Del Regno static struct spmi_voltage_range ht_nldo_ranges[] = { 540328816c2SAngeloGioacchino Del Regno SPMI_VOLTAGE_RANGE(0, 312000, 312000, 1304000, 1304000, 8000), 541328816c2SAngeloGioacchino Del Regno }; 542328816c2SAngeloGioacchino Del Regno 5430211f68eSJorge Ramirez static struct spmi_voltage_range hfs430_ranges[] = { 5440211f68eSJorge Ramirez SPMI_VOLTAGE_RANGE(0, 320000, 320000, 2040000, 2040000, 8000), 5450211f68eSJorge Ramirez }; 5460211f68eSJorge Ramirez 547e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(pldo); 548e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo1); 549e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo2); 550e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(nldo3); 551e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ln_ldo); 552e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(smps); 553e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ftsmps); 554e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ftsmps2p5); 55542ba89c8SJeffrey Hugo static DEFINE_SPMI_SET_POINTS(ftsmps426); 556e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(boost); 557e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(boost_byp); 558e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_lo_smps); 559e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_ho_smps); 560e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_nldo); 561e92a4047SStephen Boyd static DEFINE_SPMI_SET_POINTS(ult_pldo); 562328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(pldo660); 563328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(nldo660); 564328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(ht_lvpldo); 565328816c2SAngeloGioacchino Del Regno static DEFINE_SPMI_SET_POINTS(ht_nldo); 5660211f68eSJorge Ramirez static DEFINE_SPMI_SET_POINTS(hfs430); 567e92a4047SStephen Boyd 568e92a4047SStephen Boyd static inline int spmi_vreg_read(struct spmi_regulator *vreg, u16 addr, u8 *buf, 569e92a4047SStephen Boyd int len) 570e92a4047SStephen Boyd { 571e92a4047SStephen Boyd return regmap_bulk_read(vreg->regmap, vreg->base + addr, buf, len); 572e92a4047SStephen Boyd } 573e92a4047SStephen Boyd 574e92a4047SStephen Boyd static inline int spmi_vreg_write(struct spmi_regulator *vreg, u16 addr, 575e92a4047SStephen Boyd u8 *buf, int len) 576e92a4047SStephen Boyd { 577e92a4047SStephen Boyd return regmap_bulk_write(vreg->regmap, vreg->base + addr, buf, len); 578e92a4047SStephen Boyd } 579e92a4047SStephen Boyd 580e92a4047SStephen Boyd static int spmi_vreg_update_bits(struct spmi_regulator *vreg, u16 addr, u8 val, 581e92a4047SStephen Boyd u8 mask) 582e92a4047SStephen Boyd { 583e92a4047SStephen Boyd return regmap_update_bits(vreg->regmap, vreg->base + addr, mask, val); 584e92a4047SStephen Boyd } 585e92a4047SStephen Boyd 586e92a4047SStephen Boyd static int spmi_regulator_vs_enable(struct regulator_dev *rdev) 587e92a4047SStephen Boyd { 588e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 589e92a4047SStephen Boyd 590e92a4047SStephen Boyd if (vreg->ocp_irq) { 591e92a4047SStephen Boyd vreg->ocp_count = 0; 592e92a4047SStephen Boyd vreg->vs_enable_time = ktime_get(); 593e92a4047SStephen Boyd } 594e92a4047SStephen Boyd 5959d485332SAxel Lin return regulator_enable_regmap(rdev); 596e92a4047SStephen Boyd } 597e92a4047SStephen Boyd 598*89a6a5e5SMatti Vaittinen static int spmi_regulator_vs_ocp(struct regulator_dev *rdev, int lim_uA, 599*89a6a5e5SMatti Vaittinen int severity, bool enable) 600e2adfacdSStephen Boyd { 601e2adfacdSStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 602e2adfacdSStephen Boyd u8 reg = SPMI_VS_OCP_OVERRIDE; 603e2adfacdSStephen Boyd 604*89a6a5e5SMatti Vaittinen if (lim_uA || !enable || severity != REGULATOR_SEVERITY_PROT) 605*89a6a5e5SMatti Vaittinen return -EINVAL; 606*89a6a5e5SMatti Vaittinen 607e2adfacdSStephen Boyd return spmi_vreg_write(vreg, SPMI_VS_REG_OCP, ®, 1); 608e2adfacdSStephen Boyd } 609e2adfacdSStephen Boyd 610e92a4047SStephen Boyd static int spmi_regulator_select_voltage(struct spmi_regulator *vreg, 6111b5b1968SStephen Boyd int min_uV, int max_uV) 612e92a4047SStephen Boyd { 613e92a4047SStephen Boyd const struct spmi_voltage_range *range; 614e92a4047SStephen Boyd int uV = min_uV; 615e92a4047SStephen Boyd int lim_min_uV, lim_max_uV, i, range_id, range_max_uV; 6161b5b1968SStephen Boyd int selector, voltage_sel; 617e92a4047SStephen Boyd 618e92a4047SStephen Boyd /* Check if request voltage is outside of physically settable range. */ 619e92a4047SStephen Boyd lim_min_uV = vreg->set_points->range[0].set_point_min_uV; 620e92a4047SStephen Boyd lim_max_uV = 621e92a4047SStephen Boyd vreg->set_points->range[vreg->set_points->count - 1].set_point_max_uV; 622e92a4047SStephen Boyd 623e92a4047SStephen Boyd if (uV < lim_min_uV && max_uV >= lim_min_uV) 624e92a4047SStephen Boyd uV = lim_min_uV; 625e92a4047SStephen Boyd 626e92a4047SStephen Boyd if (uV < lim_min_uV || uV > lim_max_uV) { 627e92a4047SStephen Boyd dev_err(vreg->dev, 628e92a4047SStephen Boyd "request v=[%d, %d] is outside possible v=[%d, %d]\n", 629e92a4047SStephen Boyd min_uV, max_uV, lim_min_uV, lim_max_uV); 630e92a4047SStephen Boyd return -EINVAL; 631e92a4047SStephen Boyd } 632e92a4047SStephen Boyd 633e92a4047SStephen Boyd /* Find the range which uV is inside of. */ 634e92a4047SStephen Boyd for (i = vreg->set_points->count - 1; i > 0; i--) { 635e92a4047SStephen Boyd range_max_uV = vreg->set_points->range[i - 1].set_point_max_uV; 636e92a4047SStephen Boyd if (uV > range_max_uV && range_max_uV > 0) 637e92a4047SStephen Boyd break; 638e92a4047SStephen Boyd } 639e92a4047SStephen Boyd 640e92a4047SStephen Boyd range_id = i; 641e92a4047SStephen Boyd range = &vreg->set_points->range[range_id]; 642e92a4047SStephen Boyd 643e92a4047SStephen Boyd /* 644e92a4047SStephen Boyd * Force uV to be an allowed set point by applying a ceiling function to 645e92a4047SStephen Boyd * the uV value. 646e92a4047SStephen Boyd */ 6471b5b1968SStephen Boyd voltage_sel = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); 6481b5b1968SStephen Boyd uV = voltage_sel * range->step_uV + range->min_uV; 649e92a4047SStephen Boyd 650e92a4047SStephen Boyd if (uV > max_uV) { 651e92a4047SStephen Boyd dev_err(vreg->dev, 652e92a4047SStephen Boyd "request v=[%d, %d] cannot be met by any set point; " 653e92a4047SStephen Boyd "next set point: %d\n", 654e92a4047SStephen Boyd min_uV, max_uV, uV); 655e92a4047SStephen Boyd return -EINVAL; 656e92a4047SStephen Boyd } 657e92a4047SStephen Boyd 6581b5b1968SStephen Boyd selector = 0; 659e92a4047SStephen Boyd for (i = 0; i < range_id; i++) 6601b5b1968SStephen Boyd selector += vreg->set_points->range[i].n_voltages; 6611b5b1968SStephen Boyd selector += (uV - range->set_point_min_uV) / range->step_uV; 662e92a4047SStephen Boyd 6631b5b1968SStephen Boyd return selector; 6641b5b1968SStephen Boyd } 6651b5b1968SStephen Boyd 6661b5b1968SStephen Boyd static int spmi_sw_selector_to_hw(struct spmi_regulator *vreg, 6671b5b1968SStephen Boyd unsigned selector, u8 *range_sel, 6681b5b1968SStephen Boyd u8 *voltage_sel) 6691b5b1968SStephen Boyd { 6701b5b1968SStephen Boyd const struct spmi_voltage_range *range, *end; 671ab953b9dSStephen Boyd unsigned offset; 6721b5b1968SStephen Boyd 6731b5b1968SStephen Boyd range = vreg->set_points->range; 6741b5b1968SStephen Boyd end = range + vreg->set_points->count; 6751b5b1968SStephen Boyd 6761b5b1968SStephen Boyd for (; range < end; range++) { 6771b5b1968SStephen Boyd if (selector < range->n_voltages) { 678ab953b9dSStephen Boyd /* 679ab953b9dSStephen Boyd * hardware selectors between set point min and real 680ab953b9dSStephen Boyd * min are invalid so we ignore them 681ab953b9dSStephen Boyd */ 682ab953b9dSStephen Boyd offset = range->set_point_min_uV - range->min_uV; 683ab953b9dSStephen Boyd offset /= range->step_uV; 684ab953b9dSStephen Boyd *voltage_sel = selector + offset; 6851b5b1968SStephen Boyd *range_sel = range->range_sel; 686e92a4047SStephen Boyd return 0; 687e92a4047SStephen Boyd } 688e92a4047SStephen Boyd 6891b5b1968SStephen Boyd selector -= range->n_voltages; 6901b5b1968SStephen Boyd } 6911b5b1968SStephen Boyd 6921b5b1968SStephen Boyd return -EINVAL; 6931b5b1968SStephen Boyd } 6941b5b1968SStephen Boyd 6951b5b1968SStephen Boyd static int spmi_hw_selector_to_sw(struct spmi_regulator *vreg, u8 hw_sel, 6961b5b1968SStephen Boyd const struct spmi_voltage_range *range) 6971b5b1968SStephen Boyd { 698ab953b9dSStephen Boyd unsigned sw_sel = 0; 699ab953b9dSStephen Boyd unsigned offset, max_hw_sel; 7001b5b1968SStephen Boyd const struct spmi_voltage_range *r = vreg->set_points->range; 701ab953b9dSStephen Boyd const struct spmi_voltage_range *end = r + vreg->set_points->count; 7021b5b1968SStephen Boyd 703ab953b9dSStephen Boyd for (; r < end; r++) { 704ab953b9dSStephen Boyd if (r == range && range->n_voltages) { 705ab953b9dSStephen Boyd /* 706ab953b9dSStephen Boyd * hardware selectors between set point min and real 707ab953b9dSStephen Boyd * min and between set point max and real max are 708ab953b9dSStephen Boyd * invalid so we return an error if they're 709ab953b9dSStephen Boyd * programmed into the hardware 710ab953b9dSStephen Boyd */ 711ab953b9dSStephen Boyd offset = range->set_point_min_uV - range->min_uV; 712ab953b9dSStephen Boyd offset /= range->step_uV; 713ab953b9dSStephen Boyd if (hw_sel < offset) 714ab953b9dSStephen Boyd return -EINVAL; 715ab953b9dSStephen Boyd 716ab953b9dSStephen Boyd max_hw_sel = range->set_point_max_uV - range->min_uV; 717ab953b9dSStephen Boyd max_hw_sel /= range->step_uV; 718ab953b9dSStephen Boyd if (hw_sel > max_hw_sel) 719ab953b9dSStephen Boyd return -EINVAL; 720ab953b9dSStephen Boyd 721ab953b9dSStephen Boyd return sw_sel + hw_sel - offset; 722ab953b9dSStephen Boyd } 7231b5b1968SStephen Boyd sw_sel += r->n_voltages; 7241b5b1968SStephen Boyd } 7251b5b1968SStephen Boyd 726ab953b9dSStephen Boyd return -EINVAL; 7271b5b1968SStephen Boyd } 7281b5b1968SStephen Boyd 729e92a4047SStephen Boyd static const struct spmi_voltage_range * 730e92a4047SStephen Boyd spmi_regulator_find_range(struct spmi_regulator *vreg) 731e92a4047SStephen Boyd { 732e92a4047SStephen Boyd u8 range_sel; 733e92a4047SStephen Boyd const struct spmi_voltage_range *range, *end; 734e92a4047SStephen Boyd 735e92a4047SStephen Boyd range = vreg->set_points->range; 736e92a4047SStephen Boyd end = range + vreg->set_points->count; 737e92a4047SStephen Boyd 738e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, &range_sel, 1); 739e92a4047SStephen Boyd 740e92a4047SStephen Boyd for (; range < end; range++) 741e92a4047SStephen Boyd if (range->range_sel == range_sel) 742e92a4047SStephen Boyd return range; 743e92a4047SStephen Boyd 744e92a4047SStephen Boyd return NULL; 745e92a4047SStephen Boyd } 746e92a4047SStephen Boyd 747e92a4047SStephen Boyd static int spmi_regulator_select_voltage_same_range(struct spmi_regulator *vreg, 7481b5b1968SStephen Boyd int min_uV, int max_uV) 749e92a4047SStephen Boyd { 750e92a4047SStephen Boyd const struct spmi_voltage_range *range; 751e92a4047SStephen Boyd int uV = min_uV; 7521b5b1968SStephen Boyd int i, selector; 753e92a4047SStephen Boyd 754e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 755e92a4047SStephen Boyd if (!range) 756e92a4047SStephen Boyd goto different_range; 757e92a4047SStephen Boyd 758e92a4047SStephen Boyd if (uV < range->min_uV && max_uV >= range->min_uV) 759e92a4047SStephen Boyd uV = range->min_uV; 760e92a4047SStephen Boyd 761e92a4047SStephen Boyd if (uV < range->min_uV || uV > range->max_uV) { 762e92a4047SStephen Boyd /* Current range doesn't support the requested voltage. */ 763e92a4047SStephen Boyd goto different_range; 764e92a4047SStephen Boyd } 765e92a4047SStephen Boyd 766e92a4047SStephen Boyd /* 767e92a4047SStephen Boyd * Force uV to be an allowed set point by applying a ceiling function to 768e92a4047SStephen Boyd * the uV value. 769e92a4047SStephen Boyd */ 7701b5b1968SStephen Boyd uV = DIV_ROUND_UP(uV - range->min_uV, range->step_uV); 7711b5b1968SStephen Boyd uV = uV * range->step_uV + range->min_uV; 772e92a4047SStephen Boyd 773e92a4047SStephen Boyd if (uV > max_uV) { 774e92a4047SStephen Boyd /* 775e92a4047SStephen Boyd * No set point in the current voltage range is within the 776e92a4047SStephen Boyd * requested min_uV to max_uV range. 777e92a4047SStephen Boyd */ 778e92a4047SStephen Boyd goto different_range; 779e92a4047SStephen Boyd } 780e92a4047SStephen Boyd 7811b5b1968SStephen Boyd selector = 0; 782e92a4047SStephen Boyd for (i = 0; i < vreg->set_points->count; i++) { 783e92a4047SStephen Boyd if (uV >= vreg->set_points->range[i].set_point_min_uV 7849b2dfee3SStephen Boyd && uV <= vreg->set_points->range[i].set_point_max_uV) { 7851b5b1968SStephen Boyd selector += 786e92a4047SStephen Boyd (uV - vreg->set_points->range[i].set_point_min_uV) 787e92a4047SStephen Boyd / vreg->set_points->range[i].step_uV; 788e92a4047SStephen Boyd break; 7899b2dfee3SStephen Boyd } 790e92a4047SStephen Boyd 7911b5b1968SStephen Boyd selector += vreg->set_points->range[i].n_voltages; 792e92a4047SStephen Boyd } 793e92a4047SStephen Boyd 7941b5b1968SStephen Boyd if (selector >= vreg->set_points->n_voltages) 795e92a4047SStephen Boyd goto different_range; 796e92a4047SStephen Boyd 797b1d21a24SStephen Boyd return selector; 798e92a4047SStephen Boyd 799e92a4047SStephen Boyd different_range: 8001b5b1968SStephen Boyd return spmi_regulator_select_voltage(vreg, min_uV, max_uV); 801e92a4047SStephen Boyd } 802e92a4047SStephen Boyd 8031b5b1968SStephen Boyd static int spmi_regulator_common_map_voltage(struct regulator_dev *rdev, 8041b5b1968SStephen Boyd int min_uV, int max_uV) 8051b5b1968SStephen Boyd { 8061b5b1968SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 8071b5b1968SStephen Boyd 8081b5b1968SStephen Boyd /* 8091b5b1968SStephen Boyd * Favor staying in the current voltage range if possible. This avoids 8101b5b1968SStephen Boyd * voltage spikes that occur when changing the voltage range. 8111b5b1968SStephen Boyd */ 8121b5b1968SStephen Boyd return spmi_regulator_select_voltage_same_range(vreg, min_uV, max_uV); 8131b5b1968SStephen Boyd } 8141b5b1968SStephen Boyd 8151b5b1968SStephen Boyd static int 8161b5b1968SStephen Boyd spmi_regulator_common_set_voltage(struct regulator_dev *rdev, unsigned selector) 817e92a4047SStephen Boyd { 818e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 819e92a4047SStephen Boyd int ret; 820e92a4047SStephen Boyd u8 buf[2]; 821e92a4047SStephen Boyd u8 range_sel, voltage_sel; 822e92a4047SStephen Boyd 8231b5b1968SStephen Boyd ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); 824e92a4047SStephen Boyd if (ret) 825e92a4047SStephen Boyd return ret; 826e92a4047SStephen Boyd 827e92a4047SStephen Boyd buf[0] = range_sel; 828e92a4047SStephen Boyd buf[1] = voltage_sel; 829e92a4047SStephen Boyd return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, buf, 2); 830e92a4047SStephen Boyd } 831e92a4047SStephen Boyd 83242ba89c8SJeffrey Hugo static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev, 83342ba89c8SJeffrey Hugo unsigned selector); 83442ba89c8SJeffrey Hugo 83542ba89c8SJeffrey Hugo static int spmi_regulator_ftsmps426_set_voltage(struct regulator_dev *rdev, 83642ba89c8SJeffrey Hugo unsigned selector) 83742ba89c8SJeffrey Hugo { 83842ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 83942ba89c8SJeffrey Hugo u8 buf[2]; 84042ba89c8SJeffrey Hugo int mV; 84142ba89c8SJeffrey Hugo 84242ba89c8SJeffrey Hugo mV = spmi_regulator_common_list_voltage(rdev, selector) / 1000; 84342ba89c8SJeffrey Hugo 84442ba89c8SJeffrey Hugo buf[0] = mV & 0xff; 84542ba89c8SJeffrey Hugo buf[1] = mV >> 8; 84642ba89c8SJeffrey Hugo return spmi_vreg_write(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2); 84742ba89c8SJeffrey Hugo } 84842ba89c8SJeffrey Hugo 849e92a4047SStephen Boyd static int spmi_regulator_set_voltage_time_sel(struct regulator_dev *rdev, 850e92a4047SStephen Boyd unsigned int old_selector, unsigned int new_selector) 851e92a4047SStephen Boyd { 852e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 853e92a4047SStephen Boyd int diff_uV; 854e92a4047SStephen Boyd 85561d7fdc4SJeffrey Hugo diff_uV = abs(spmi_regulator_common_list_voltage(rdev, new_selector) - 85661d7fdc4SJeffrey Hugo spmi_regulator_common_list_voltage(rdev, old_selector)); 857e92a4047SStephen Boyd 858e92a4047SStephen Boyd return DIV_ROUND_UP(diff_uV, vreg->slew_rate); 859e92a4047SStephen Boyd } 860e92a4047SStephen Boyd 861e92a4047SStephen Boyd static int spmi_regulator_common_get_voltage(struct regulator_dev *rdev) 862e92a4047SStephen Boyd { 863e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 864e92a4047SStephen Boyd const struct spmi_voltage_range *range; 865e92a4047SStephen Boyd u8 voltage_sel; 866e92a4047SStephen Boyd 867e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); 868e92a4047SStephen Boyd 869e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 870e92a4047SStephen Boyd if (!range) 8711b5b1968SStephen Boyd return -EINVAL; 872e92a4047SStephen Boyd 8731b5b1968SStephen Boyd return spmi_hw_selector_to_sw(vreg, voltage_sel, range); 8741b5b1968SStephen Boyd } 8751b5b1968SStephen Boyd 87642ba89c8SJeffrey Hugo static int spmi_regulator_ftsmps426_get_voltage(struct regulator_dev *rdev) 87742ba89c8SJeffrey Hugo { 87842ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 87942ba89c8SJeffrey Hugo const struct spmi_voltage_range *range; 88042ba89c8SJeffrey Hugo u8 buf[2]; 88142ba89c8SJeffrey Hugo int uV; 88242ba89c8SJeffrey Hugo 88342ba89c8SJeffrey Hugo spmi_vreg_read(vreg, SPMI_FTSMPS426_REG_VOLTAGE_LSB, buf, 2); 88442ba89c8SJeffrey Hugo 88542ba89c8SJeffrey Hugo uV = (((unsigned int)buf[1] << 8) | (unsigned int)buf[0]) * 1000; 88642ba89c8SJeffrey Hugo range = vreg->set_points->range; 88742ba89c8SJeffrey Hugo 88842ba89c8SJeffrey Hugo return (uV - range->set_point_min_uV) / range->step_uV; 88942ba89c8SJeffrey Hugo } 89042ba89c8SJeffrey Hugo 8911b5b1968SStephen Boyd static int spmi_regulator_single_map_voltage(struct regulator_dev *rdev, 8921b5b1968SStephen Boyd int min_uV, int max_uV) 8931b5b1968SStephen Boyd { 8941b5b1968SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 8951b5b1968SStephen Boyd 8961b5b1968SStephen Boyd return spmi_regulator_select_voltage(vreg, min_uV, max_uV); 897e92a4047SStephen Boyd } 898e92a4047SStephen Boyd 899e92a4047SStephen Boyd static int spmi_regulator_single_range_set_voltage(struct regulator_dev *rdev, 9001b5b1968SStephen Boyd unsigned selector) 901e92a4047SStephen Boyd { 902e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 9031b5b1968SStephen Boyd u8 sel = selector; 904e92a4047SStephen Boyd 905e92a4047SStephen Boyd /* 906e92a4047SStephen Boyd * Certain types of regulators do not have a range select register so 907e92a4047SStephen Boyd * only voltage set register needs to be written. 908e92a4047SStephen Boyd */ 909e92a4047SStephen Boyd return spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &sel, 1); 910e92a4047SStephen Boyd } 911e92a4047SStephen Boyd 912e92a4047SStephen Boyd static int spmi_regulator_single_range_get_voltage(struct regulator_dev *rdev) 913e92a4047SStephen Boyd { 914e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 9151b5b1968SStephen Boyd u8 selector; 9161b5b1968SStephen Boyd int ret; 917e92a4047SStephen Boyd 9181b5b1968SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &selector, 1); 9191b5b1968SStephen Boyd if (ret) 9201b5b1968SStephen Boyd return ret; 921e92a4047SStephen Boyd 9221b5b1968SStephen Boyd return selector; 923e92a4047SStephen Boyd } 924e92a4047SStephen Boyd 925e92a4047SStephen Boyd static int spmi_regulator_ult_lo_smps_set_voltage(struct regulator_dev *rdev, 9261b5b1968SStephen Boyd unsigned selector) 927e92a4047SStephen Boyd { 928e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 929e92a4047SStephen Boyd int ret; 930e92a4047SStephen Boyd u8 range_sel, voltage_sel; 931e92a4047SStephen Boyd 9321b5b1968SStephen Boyd ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); 933e92a4047SStephen Boyd if (ret) 934e92a4047SStephen Boyd return ret; 935e92a4047SStephen Boyd 936e92a4047SStephen Boyd /* 937e92a4047SStephen Boyd * Calculate VSET based on range 938e92a4047SStephen Boyd * In case of range 0: voltage_sel is a 7 bit value, can be written 939e92a4047SStephen Boyd * witout any modification. 940e92a4047SStephen Boyd * In case of range 1: voltage_sel is a 5 bit value, bits[7-5] set to 941e92a4047SStephen Boyd * [011]. 942e92a4047SStephen Boyd */ 943e92a4047SStephen Boyd if (range_sel == 1) 944e92a4047SStephen Boyd voltage_sel |= ULT_SMPS_RANGE_SPLIT; 945e92a4047SStephen Boyd 9460f94bffaSJulia Lawall return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_VOLTAGE_SET, 947e92a4047SStephen Boyd voltage_sel, 0xff); 948e92a4047SStephen Boyd } 949e92a4047SStephen Boyd 950e92a4047SStephen Boyd static int spmi_regulator_ult_lo_smps_get_voltage(struct regulator_dev *rdev) 951e92a4047SStephen Boyd { 952e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 953e92a4047SStephen Boyd const struct spmi_voltage_range *range; 954e92a4047SStephen Boyd u8 voltage_sel; 955e92a4047SStephen Boyd 956e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_SET, &voltage_sel, 1); 957e92a4047SStephen Boyd 958e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 959e92a4047SStephen Boyd if (!range) 9601b5b1968SStephen Boyd return -EINVAL; 961e92a4047SStephen Boyd 962e92a4047SStephen Boyd if (range->range_sel == 1) 963e92a4047SStephen Boyd voltage_sel &= ~ULT_SMPS_RANGE_SPLIT; 964e92a4047SStephen Boyd 9651b5b1968SStephen Boyd return spmi_hw_selector_to_sw(vreg, voltage_sel, range); 966e92a4047SStephen Boyd } 967e92a4047SStephen Boyd 968e92a4047SStephen Boyd static int spmi_regulator_common_list_voltage(struct regulator_dev *rdev, 969e92a4047SStephen Boyd unsigned selector) 970e92a4047SStephen Boyd { 971e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 972e92a4047SStephen Boyd int uV = 0; 973e92a4047SStephen Boyd int i; 974e92a4047SStephen Boyd 975e92a4047SStephen Boyd if (selector >= vreg->set_points->n_voltages) 976e92a4047SStephen Boyd return 0; 977e92a4047SStephen Boyd 978e92a4047SStephen Boyd for (i = 0; i < vreg->set_points->count; i++) { 9799b2dfee3SStephen Boyd if (selector < vreg->set_points->range[i].n_voltages) { 980e92a4047SStephen Boyd uV = selector * vreg->set_points->range[i].step_uV 981e92a4047SStephen Boyd + vreg->set_points->range[i].set_point_min_uV; 982e92a4047SStephen Boyd break; 9839b2dfee3SStephen Boyd } 984e92a4047SStephen Boyd 985e92a4047SStephen Boyd selector -= vreg->set_points->range[i].n_voltages; 986e92a4047SStephen Boyd } 987e92a4047SStephen Boyd 988e92a4047SStephen Boyd return uV; 989e92a4047SStephen Boyd } 990e92a4047SStephen Boyd 991e92a4047SStephen Boyd static int 992e92a4047SStephen Boyd spmi_regulator_common_set_bypass(struct regulator_dev *rdev, bool enable) 993e92a4047SStephen Boyd { 994e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 995e92a4047SStephen Boyd u8 mask = SPMI_COMMON_MODE_BYPASS_MASK; 996e92a4047SStephen Boyd u8 val = 0; 997e92a4047SStephen Boyd 998e92a4047SStephen Boyd if (enable) 999e92a4047SStephen Boyd val = mask; 1000e92a4047SStephen Boyd 1001e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 1002e92a4047SStephen Boyd } 1003e92a4047SStephen Boyd 1004e92a4047SStephen Boyd static int 1005e92a4047SStephen Boyd spmi_regulator_common_get_bypass(struct regulator_dev *rdev, bool *enable) 1006e92a4047SStephen Boyd { 1007e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1008e92a4047SStephen Boyd u8 val; 1009e92a4047SStephen Boyd int ret; 1010e92a4047SStephen Boyd 1011e92a4047SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, &val, 1); 1012e92a4047SStephen Boyd *enable = val & SPMI_COMMON_MODE_BYPASS_MASK; 1013e92a4047SStephen Boyd 1014e92a4047SStephen Boyd return ret; 1015e92a4047SStephen Boyd } 1016e92a4047SStephen Boyd 1017e92a4047SStephen Boyd static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev) 1018e92a4047SStephen Boyd { 1019e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1020e92a4047SStephen Boyd u8 reg; 1021e92a4047SStephen Boyd 1022e92a4047SStephen Boyd spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); 1023e92a4047SStephen Boyd 1024ba576a62SJeffrey Hugo reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; 1025ba576a62SJeffrey Hugo 1026ba576a62SJeffrey Hugo switch (reg) { 1027ba576a62SJeffrey Hugo case SPMI_COMMON_MODE_HPM_MASK: 1028e92a4047SStephen Boyd return REGULATOR_MODE_NORMAL; 1029ba576a62SJeffrey Hugo case SPMI_COMMON_MODE_AUTO_MASK: 1030e2adfacdSStephen Boyd return REGULATOR_MODE_FAST; 1031ba576a62SJeffrey Hugo default: 1032e92a4047SStephen Boyd return REGULATOR_MODE_IDLE; 1033e92a4047SStephen Boyd } 1034ba576a62SJeffrey Hugo } 1035e92a4047SStephen Boyd 103642ba89c8SJeffrey Hugo static unsigned int spmi_regulator_ftsmps426_get_mode(struct regulator_dev *rdev) 103742ba89c8SJeffrey Hugo { 103842ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 103942ba89c8SJeffrey Hugo u8 reg; 104042ba89c8SJeffrey Hugo 104142ba89c8SJeffrey Hugo spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); 104242ba89c8SJeffrey Hugo 104342ba89c8SJeffrey Hugo switch (reg) { 104442ba89c8SJeffrey Hugo case SPMI_FTSMPS426_MODE_HPM_MASK: 104542ba89c8SJeffrey Hugo return REGULATOR_MODE_NORMAL; 104642ba89c8SJeffrey Hugo case SPMI_FTSMPS426_MODE_AUTO_MASK: 104742ba89c8SJeffrey Hugo return REGULATOR_MODE_FAST; 104842ba89c8SJeffrey Hugo default: 104942ba89c8SJeffrey Hugo return REGULATOR_MODE_IDLE; 105042ba89c8SJeffrey Hugo } 105142ba89c8SJeffrey Hugo } 105242ba89c8SJeffrey Hugo 1053e92a4047SStephen Boyd static int 1054e92a4047SStephen Boyd spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) 1055e92a4047SStephen Boyd { 1056e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1057e2adfacdSStephen Boyd u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; 1058ba576a62SJeffrey Hugo u8 val; 1059e92a4047SStephen Boyd 1060ba576a62SJeffrey Hugo switch (mode) { 1061ba576a62SJeffrey Hugo case REGULATOR_MODE_NORMAL: 1062e2adfacdSStephen Boyd val = SPMI_COMMON_MODE_HPM_MASK; 1063ba576a62SJeffrey Hugo break; 1064ba576a62SJeffrey Hugo case REGULATOR_MODE_FAST: 1065e2adfacdSStephen Boyd val = SPMI_COMMON_MODE_AUTO_MASK; 1066ba576a62SJeffrey Hugo break; 1067ba576a62SJeffrey Hugo default: 1068ba576a62SJeffrey Hugo val = 0; 1069ba576a62SJeffrey Hugo break; 1070ba576a62SJeffrey Hugo } 1071e92a4047SStephen Boyd 1072e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 1073e92a4047SStephen Boyd } 1074e92a4047SStephen Boyd 1075e92a4047SStephen Boyd static int 107642ba89c8SJeffrey Hugo spmi_regulator_ftsmps426_set_mode(struct regulator_dev *rdev, unsigned int mode) 107742ba89c8SJeffrey Hugo { 107842ba89c8SJeffrey Hugo struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 107942ba89c8SJeffrey Hugo u8 mask = SPMI_FTSMPS426_MODE_MASK; 108042ba89c8SJeffrey Hugo u8 val; 108142ba89c8SJeffrey Hugo 108242ba89c8SJeffrey Hugo switch (mode) { 108342ba89c8SJeffrey Hugo case REGULATOR_MODE_NORMAL: 108442ba89c8SJeffrey Hugo val = SPMI_FTSMPS426_MODE_HPM_MASK; 108542ba89c8SJeffrey Hugo break; 108642ba89c8SJeffrey Hugo case REGULATOR_MODE_FAST: 108742ba89c8SJeffrey Hugo val = SPMI_FTSMPS426_MODE_AUTO_MASK; 108842ba89c8SJeffrey Hugo break; 108942ba89c8SJeffrey Hugo case REGULATOR_MODE_IDLE: 109042ba89c8SJeffrey Hugo val = SPMI_FTSMPS426_MODE_LPM_MASK; 109142ba89c8SJeffrey Hugo break; 109242ba89c8SJeffrey Hugo default: 109342ba89c8SJeffrey Hugo return -EINVAL; 109442ba89c8SJeffrey Hugo } 109542ba89c8SJeffrey Hugo 109642ba89c8SJeffrey Hugo return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); 109742ba89c8SJeffrey Hugo } 109842ba89c8SJeffrey Hugo 109942ba89c8SJeffrey Hugo static int 1100e92a4047SStephen Boyd spmi_regulator_common_set_load(struct regulator_dev *rdev, int load_uA) 1101e92a4047SStephen Boyd { 1102e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1103e92a4047SStephen Boyd unsigned int mode; 1104e92a4047SStephen Boyd 1105e92a4047SStephen Boyd if (load_uA >= vreg->hpm_min_load) 1106e92a4047SStephen Boyd mode = REGULATOR_MODE_NORMAL; 1107e92a4047SStephen Boyd else 1108e92a4047SStephen Boyd mode = REGULATOR_MODE_IDLE; 1109e92a4047SStephen Boyd 1110e92a4047SStephen Boyd return spmi_regulator_common_set_mode(rdev, mode); 1111e92a4047SStephen Boyd } 1112e92a4047SStephen Boyd 1113e92a4047SStephen Boyd static int spmi_regulator_common_set_pull_down(struct regulator_dev *rdev) 1114e92a4047SStephen Boyd { 1115e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1116e92a4047SStephen Boyd unsigned int mask = SPMI_COMMON_PULL_DOWN_ENABLE_MASK; 1117e92a4047SStephen Boyd 1118e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_PULL_DOWN, 1119e92a4047SStephen Boyd mask, mask); 1120e92a4047SStephen Boyd } 1121e92a4047SStephen Boyd 1122e92a4047SStephen Boyd static int spmi_regulator_common_set_soft_start(struct regulator_dev *rdev) 1123e92a4047SStephen Boyd { 1124e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1125e92a4047SStephen Boyd unsigned int mask = SPMI_LDO_SOFT_START_ENABLE_MASK; 1126e92a4047SStephen Boyd 1127e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_SOFT_START, 1128e92a4047SStephen Boyd mask, mask); 1129e92a4047SStephen Boyd } 1130e92a4047SStephen Boyd 1131e92a4047SStephen Boyd static int spmi_regulator_set_ilim(struct regulator_dev *rdev, int ilim_uA) 1132e92a4047SStephen Boyd { 1133e92a4047SStephen Boyd struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 1134e92a4047SStephen Boyd enum spmi_regulator_logical_type type = vreg->logical_type; 1135e92a4047SStephen Boyd unsigned int current_reg; 1136e92a4047SStephen Boyd u8 reg; 1137e92a4047SStephen Boyd u8 mask = SPMI_BOOST_CURRENT_LIMIT_MASK | 1138e92a4047SStephen Boyd SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK; 1139e92a4047SStephen Boyd int max = (SPMI_BOOST_CURRENT_LIMIT_MASK + 1) * 500; 1140e92a4047SStephen Boyd 1141e92a4047SStephen Boyd if (type == SPMI_REGULATOR_LOGICAL_TYPE_BOOST) 1142e92a4047SStephen Boyd current_reg = SPMI_BOOST_REG_CURRENT_LIMIT; 1143e92a4047SStephen Boyd else 1144e92a4047SStephen Boyd current_reg = SPMI_BOOST_BYP_REG_CURRENT_LIMIT; 1145e92a4047SStephen Boyd 1146e92a4047SStephen Boyd if (ilim_uA > max || ilim_uA <= 0) 1147e92a4047SStephen Boyd return -EINVAL; 1148e92a4047SStephen Boyd 1149e92a4047SStephen Boyd reg = (ilim_uA - 1) / 500; 1150e92a4047SStephen Boyd reg |= SPMI_BOOST_CURRENT_LIMIT_ENABLE_MASK; 1151e92a4047SStephen Boyd 1152e92a4047SStephen Boyd return spmi_vreg_update_bits(vreg, current_reg, reg, mask); 1153e92a4047SStephen Boyd } 1154e92a4047SStephen Boyd 1155e92a4047SStephen Boyd static int spmi_regulator_vs_clear_ocp(struct spmi_regulator *vreg) 1156e92a4047SStephen Boyd { 1157e92a4047SStephen Boyd int ret; 1158e92a4047SStephen Boyd 1159e92a4047SStephen Boyd ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, 1160e92a4047SStephen Boyd SPMI_COMMON_DISABLE, SPMI_COMMON_ENABLE_MASK); 1161e92a4047SStephen Boyd 1162e92a4047SStephen Boyd vreg->vs_enable_time = ktime_get(); 1163e92a4047SStephen Boyd 1164e92a4047SStephen Boyd ret = spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_ENABLE, 1165e92a4047SStephen Boyd SPMI_COMMON_ENABLE, SPMI_COMMON_ENABLE_MASK); 1166e92a4047SStephen Boyd 1167e92a4047SStephen Boyd return ret; 1168e92a4047SStephen Boyd } 1169e92a4047SStephen Boyd 1170e92a4047SStephen Boyd static void spmi_regulator_vs_ocp_work(struct work_struct *work) 1171e92a4047SStephen Boyd { 1172e92a4047SStephen Boyd struct delayed_work *dwork = to_delayed_work(work); 1173e92a4047SStephen Boyd struct spmi_regulator *vreg 1174e92a4047SStephen Boyd = container_of(dwork, struct spmi_regulator, ocp_work); 1175e92a4047SStephen Boyd 1176e92a4047SStephen Boyd spmi_regulator_vs_clear_ocp(vreg); 1177e92a4047SStephen Boyd } 1178e92a4047SStephen Boyd 1179e92a4047SStephen Boyd static irqreturn_t spmi_regulator_vs_ocp_isr(int irq, void *data) 1180e92a4047SStephen Boyd { 1181e92a4047SStephen Boyd struct spmi_regulator *vreg = data; 1182e92a4047SStephen Boyd ktime_t ocp_irq_time; 1183e92a4047SStephen Boyd s64 ocp_trigger_delay_us; 1184e92a4047SStephen Boyd 1185e92a4047SStephen Boyd ocp_irq_time = ktime_get(); 1186e92a4047SStephen Boyd ocp_trigger_delay_us = ktime_us_delta(ocp_irq_time, 1187e92a4047SStephen Boyd vreg->vs_enable_time); 1188e92a4047SStephen Boyd 1189e92a4047SStephen Boyd /* 1190e92a4047SStephen Boyd * Reset the OCP count if there is a large delay between switch enable 1191e92a4047SStephen Boyd * and when OCP triggers. This is indicative of a hotplug event as 1192e92a4047SStephen Boyd * opposed to a fault. 1193e92a4047SStephen Boyd */ 1194e92a4047SStephen Boyd if (ocp_trigger_delay_us > SPMI_VS_OCP_FAULT_DELAY_US) 1195e92a4047SStephen Boyd vreg->ocp_count = 0; 1196e92a4047SStephen Boyd 1197e92a4047SStephen Boyd /* Wait for switch output to settle back to 0 V after OCP triggered. */ 1198e92a4047SStephen Boyd udelay(SPMI_VS_OCP_FALL_DELAY_US); 1199e92a4047SStephen Boyd 1200e92a4047SStephen Boyd vreg->ocp_count++; 1201e92a4047SStephen Boyd 1202e92a4047SStephen Boyd if (vreg->ocp_count == 1) { 1203e92a4047SStephen Boyd /* Immediately clear the over current condition. */ 1204e92a4047SStephen Boyd spmi_regulator_vs_clear_ocp(vreg); 1205e92a4047SStephen Boyd } else if (vreg->ocp_count <= vreg->ocp_max_retries) { 1206e92a4047SStephen Boyd /* Schedule the over current clear task to run later. */ 1207e92a4047SStephen Boyd schedule_delayed_work(&vreg->ocp_work, 1208e92a4047SStephen Boyd msecs_to_jiffies(vreg->ocp_retry_delay_ms) + 1); 1209e92a4047SStephen Boyd } else { 1210e92a4047SStephen Boyd dev_err(vreg->dev, 1211e92a4047SStephen Boyd "OCP triggered %d times; no further retries\n", 1212e92a4047SStephen Boyd vreg->ocp_count); 1213e92a4047SStephen Boyd } 1214e92a4047SStephen Boyd 1215e92a4047SStephen Boyd return IRQ_HANDLED; 1216e92a4047SStephen Boyd } 1217e92a4047SStephen Boyd 12180caecaa8SIlia Lin #define SAW3_VCTL_DATA_MASK 0xFF 12190caecaa8SIlia Lin #define SAW3_VCTL_CLEAR_MASK 0x700FF 12200caecaa8SIlia Lin #define SAW3_AVS_CTL_EN_MASK 0x1 12210caecaa8SIlia Lin #define SAW3_AVS_CTL_TGGL_MASK 0x8000000 12220caecaa8SIlia Lin #define SAW3_AVS_CTL_CLEAR_MASK 0x7efc00 12230caecaa8SIlia Lin 12249689ca0aSNiklas Cassel static struct regmap *saw_regmap; 12250caecaa8SIlia Lin 12260caecaa8SIlia Lin static void spmi_saw_set_vdd(void *data) 12270caecaa8SIlia Lin { 12280caecaa8SIlia Lin u32 vctl, data3, avs_ctl, pmic_sts; 12290caecaa8SIlia Lin bool avs_enabled = false; 12300caecaa8SIlia Lin unsigned long timeout; 12310caecaa8SIlia Lin u8 voltage_sel = *(u8 *)data; 12320caecaa8SIlia Lin 12330caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_AVS_CTL, &avs_ctl); 12340caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_VCTL, &vctl); 12350caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_SPM_PMIC_DATA_3, &data3); 12360caecaa8SIlia Lin 12370caecaa8SIlia Lin /* select the band */ 12380caecaa8SIlia Lin vctl &= ~SAW3_VCTL_CLEAR_MASK; 12390caecaa8SIlia Lin vctl |= (u32)voltage_sel; 12400caecaa8SIlia Lin 12410caecaa8SIlia Lin data3 &= ~SAW3_VCTL_CLEAR_MASK; 12420caecaa8SIlia Lin data3 |= (u32)voltage_sel; 12430caecaa8SIlia Lin 12440caecaa8SIlia Lin /* If AVS is enabled, switch it off during the voltage change */ 12450caecaa8SIlia Lin avs_enabled = SAW3_AVS_CTL_EN_MASK & avs_ctl; 12460caecaa8SIlia Lin if (avs_enabled) { 12470caecaa8SIlia Lin avs_ctl &= ~SAW3_AVS_CTL_TGGL_MASK; 12480caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_AVS_CTL, avs_ctl); 12490caecaa8SIlia Lin } 12500caecaa8SIlia Lin 12510caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_RST, 1); 12520caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_VCTL, vctl); 12530caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_SPM_PMIC_DATA_3, data3); 12540caecaa8SIlia Lin 12550caecaa8SIlia Lin timeout = jiffies + usecs_to_jiffies(100); 12560caecaa8SIlia Lin do { 12570caecaa8SIlia Lin regmap_read(saw_regmap, SAW3_PMIC_STS, &pmic_sts); 12580caecaa8SIlia Lin pmic_sts &= SAW3_VCTL_DATA_MASK; 12590caecaa8SIlia Lin if (pmic_sts == (u32)voltage_sel) 12600caecaa8SIlia Lin break; 12610caecaa8SIlia Lin 12620caecaa8SIlia Lin cpu_relax(); 12630caecaa8SIlia Lin 12640caecaa8SIlia Lin } while (time_before(jiffies, timeout)); 12650caecaa8SIlia Lin 12660caecaa8SIlia Lin /* After successful voltage change, switch the AVS back on */ 12670caecaa8SIlia Lin if (avs_enabled) { 12680caecaa8SIlia Lin pmic_sts &= 0x3f; 12690caecaa8SIlia Lin avs_ctl &= ~SAW3_AVS_CTL_CLEAR_MASK; 12700caecaa8SIlia Lin avs_ctl |= ((pmic_sts - 4) << 10); 12710caecaa8SIlia Lin avs_ctl |= (pmic_sts << 17); 12720caecaa8SIlia Lin avs_ctl |= SAW3_AVS_CTL_TGGL_MASK; 12730caecaa8SIlia Lin regmap_write(saw_regmap, SAW3_AVS_CTL, avs_ctl); 12740caecaa8SIlia Lin } 12750caecaa8SIlia Lin } 12760caecaa8SIlia Lin 12770caecaa8SIlia Lin static int 12780caecaa8SIlia Lin spmi_regulator_saw_set_voltage(struct regulator_dev *rdev, unsigned selector) 12790caecaa8SIlia Lin { 12800caecaa8SIlia Lin struct spmi_regulator *vreg = rdev_get_drvdata(rdev); 12810caecaa8SIlia Lin int ret; 12820caecaa8SIlia Lin u8 range_sel, voltage_sel; 12830caecaa8SIlia Lin 12840caecaa8SIlia Lin ret = spmi_sw_selector_to_hw(vreg, selector, &range_sel, &voltage_sel); 12850caecaa8SIlia Lin if (ret) 12860caecaa8SIlia Lin return ret; 12870caecaa8SIlia Lin 12880caecaa8SIlia Lin if (0 != range_sel) { 12890caecaa8SIlia Lin dev_dbg(&rdev->dev, "range_sel = %02X voltage_sel = %02X", \ 12900caecaa8SIlia Lin range_sel, voltage_sel); 12910caecaa8SIlia Lin return -EINVAL; 12920caecaa8SIlia Lin } 12930caecaa8SIlia Lin 12940caecaa8SIlia Lin /* Always do the SAW register writes on the first CPU */ 12950caecaa8SIlia Lin return smp_call_function_single(0, spmi_saw_set_vdd, \ 12960caecaa8SIlia Lin &voltage_sel, true); 12970caecaa8SIlia Lin } 12980caecaa8SIlia Lin 12990caecaa8SIlia Lin static struct regulator_ops spmi_saw_ops = {}; 13000caecaa8SIlia Lin 13013b619e3eSRikard Falkeborn static const struct regulator_ops spmi_smps_ops = { 13029d485332SAxel Lin .enable = regulator_enable_regmap, 13039d485332SAxel Lin .disable = regulator_disable_regmap, 13049d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13051b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 13062cf7b99cSStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 13071b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 13081b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1309e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1310e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1311e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1312e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1313e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1314e92a4047SStephen Boyd }; 1315e92a4047SStephen Boyd 13163b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ldo_ops = { 13179d485332SAxel Lin .enable = regulator_enable_regmap, 13189d485332SAxel Lin .disable = regulator_disable_regmap, 13199d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13201b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 13211b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 13221b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1323e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1324e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1325e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1326e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1327e92a4047SStephen Boyd .set_bypass = spmi_regulator_common_set_bypass, 1328e92a4047SStephen Boyd .get_bypass = spmi_regulator_common_get_bypass, 1329e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1330e92a4047SStephen Boyd .set_soft_start = spmi_regulator_common_set_soft_start, 1331e92a4047SStephen Boyd }; 1332e92a4047SStephen Boyd 13333b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ln_ldo_ops = { 13349d485332SAxel Lin .enable = regulator_enable_regmap, 13359d485332SAxel Lin .disable = regulator_disable_regmap, 13369d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13371b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 13381b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 13391b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1340e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1341e92a4047SStephen Boyd .set_bypass = spmi_regulator_common_set_bypass, 1342e92a4047SStephen Boyd .get_bypass = spmi_regulator_common_get_bypass, 1343e92a4047SStephen Boyd }; 1344e92a4047SStephen Boyd 13453b619e3eSRikard Falkeborn static const struct regulator_ops spmi_vs_ops = { 1346e92a4047SStephen Boyd .enable = spmi_regulator_vs_enable, 13479d485332SAxel Lin .disable = regulator_disable_regmap, 13489d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 1349e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1350e92a4047SStephen Boyd .set_soft_start = spmi_regulator_common_set_soft_start, 1351e2adfacdSStephen Boyd .set_over_current_protection = spmi_regulator_vs_ocp, 1352919163f6SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1353919163f6SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1354e92a4047SStephen Boyd }; 1355e92a4047SStephen Boyd 13563b619e3eSRikard Falkeborn static const struct regulator_ops spmi_boost_ops = { 13579d485332SAxel Lin .enable = regulator_enable_regmap, 13589d485332SAxel Lin .disable = regulator_disable_regmap, 13599d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13601b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_single_range_set_voltage, 13611b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_single_range_get_voltage, 13621b5b1968SStephen Boyd .map_voltage = spmi_regulator_single_map_voltage, 1363e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1364e92a4047SStephen Boyd .set_input_current_limit = spmi_regulator_set_ilim, 1365e92a4047SStephen Boyd }; 1366e92a4047SStephen Boyd 13673b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ftsmps_ops = { 13689d485332SAxel Lin .enable = regulator_enable_regmap, 13699d485332SAxel Lin .disable = regulator_disable_regmap, 13709d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13711b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_common_set_voltage, 1372e92a4047SStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 13731b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_common_get_voltage, 13741b5b1968SStephen Boyd .map_voltage = spmi_regulator_common_map_voltage, 1375e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1376e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1377e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1378e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1379e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1380e92a4047SStephen Boyd }; 1381e92a4047SStephen Boyd 13823b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_lo_smps_ops = { 13839d485332SAxel Lin .enable = regulator_enable_regmap, 13849d485332SAxel Lin .disable = regulator_disable_regmap, 13859d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 13861b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_ult_lo_smps_set_voltage, 13872cf7b99cSStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 13881b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_ult_lo_smps_get_voltage, 1389e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1390e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1391e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1392e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1393e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1394e92a4047SStephen Boyd }; 1395e92a4047SStephen Boyd 13963b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_ho_smps_ops = { 13979d485332SAxel Lin .enable = regulator_enable_regmap, 13989d485332SAxel Lin .disable = regulator_disable_regmap, 13999d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14001b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_single_range_set_voltage, 14012cf7b99cSStephen Boyd .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 14021b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_single_range_get_voltage, 14031b5b1968SStephen Boyd .map_voltage = spmi_regulator_single_map_voltage, 1404e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1405e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1406e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1407e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1408e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1409e92a4047SStephen Boyd }; 1410e92a4047SStephen Boyd 14113b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ult_ldo_ops = { 14129d485332SAxel Lin .enable = regulator_enable_regmap, 14139d485332SAxel Lin .disable = regulator_disable_regmap, 14149d485332SAxel Lin .is_enabled = regulator_is_enabled_regmap, 14151b5b1968SStephen Boyd .set_voltage_sel = spmi_regulator_single_range_set_voltage, 14161b5b1968SStephen Boyd .get_voltage_sel = spmi_regulator_single_range_get_voltage, 14171b5b1968SStephen Boyd .map_voltage = spmi_regulator_single_map_voltage, 1418e92a4047SStephen Boyd .list_voltage = spmi_regulator_common_list_voltage, 1419e92a4047SStephen Boyd .set_mode = spmi_regulator_common_set_mode, 1420e92a4047SStephen Boyd .get_mode = spmi_regulator_common_get_mode, 1421e92a4047SStephen Boyd .set_load = spmi_regulator_common_set_load, 1422e92a4047SStephen Boyd .set_bypass = spmi_regulator_common_set_bypass, 1423e92a4047SStephen Boyd .get_bypass = spmi_regulator_common_get_bypass, 1424e92a4047SStephen Boyd .set_pull_down = spmi_regulator_common_set_pull_down, 1425e92a4047SStephen Boyd .set_soft_start = spmi_regulator_common_set_soft_start, 1426e92a4047SStephen Boyd }; 1427e92a4047SStephen Boyd 14283b619e3eSRikard Falkeborn static const struct regulator_ops spmi_ftsmps426_ops = { 142942ba89c8SJeffrey Hugo .enable = regulator_enable_regmap, 143042ba89c8SJeffrey Hugo .disable = regulator_disable_regmap, 143142ba89c8SJeffrey Hugo .is_enabled = regulator_is_enabled_regmap, 143242ba89c8SJeffrey Hugo .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage, 143342ba89c8SJeffrey Hugo .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 143442ba89c8SJeffrey Hugo .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage, 143542ba89c8SJeffrey Hugo .map_voltage = spmi_regulator_single_map_voltage, 143642ba89c8SJeffrey Hugo .list_voltage = spmi_regulator_common_list_voltage, 143742ba89c8SJeffrey Hugo .set_mode = spmi_regulator_ftsmps426_set_mode, 143842ba89c8SJeffrey Hugo .get_mode = spmi_regulator_ftsmps426_get_mode, 143942ba89c8SJeffrey Hugo .set_load = spmi_regulator_common_set_load, 144042ba89c8SJeffrey Hugo .set_pull_down = spmi_regulator_common_set_pull_down, 144142ba89c8SJeffrey Hugo }; 144242ba89c8SJeffrey Hugo 14433b619e3eSRikard Falkeborn static const struct regulator_ops spmi_hfs430_ops = { 14440211f68eSJorge Ramirez .enable = regulator_enable_regmap, 14450211f68eSJorge Ramirez .disable = regulator_disable_regmap, 14460211f68eSJorge Ramirez .is_enabled = regulator_is_enabled_regmap, 14470211f68eSJorge Ramirez .set_voltage_sel = spmi_regulator_ftsmps426_set_voltage, 14480211f68eSJorge Ramirez .set_voltage_time_sel = spmi_regulator_set_voltage_time_sel, 14490211f68eSJorge Ramirez .get_voltage_sel = spmi_regulator_ftsmps426_get_voltage, 14500211f68eSJorge Ramirez .map_voltage = spmi_regulator_single_map_voltage, 14510211f68eSJorge Ramirez .list_voltage = spmi_regulator_common_list_voltage, 14520211f68eSJorge Ramirez .set_mode = spmi_regulator_ftsmps426_set_mode, 14530211f68eSJorge Ramirez .get_mode = spmi_regulator_ftsmps426_get_mode, 14540211f68eSJorge Ramirez }; 14550211f68eSJorge Ramirez 1456e92a4047SStephen Boyd /* Maximum possible digital major revision value */ 1457e92a4047SStephen Boyd #define INF 0xFF 1458e92a4047SStephen Boyd 1459e92a4047SStephen Boyd static const struct spmi_regulator_mapping supported_regulators[] = { 1460e92a4047SStephen Boyd /* type subtype dig_min dig_max ltype ops setpoints hpm_min */ 1461e92a4047SStephen Boyd SPMI_VREG(BUCK, GP_CTL, 0, INF, SMPS, smps, smps, 100000), 14620211f68eSJorge Ramirez SPMI_VREG(BUCK, HFS430, 0, INF, HFS430, hfs430, hfs430, 10000), 1463e92a4047SStephen Boyd SPMI_VREG(LDO, N300, 0, INF, LDO, ldo, nldo1, 10000), 1464e92a4047SStephen Boyd SPMI_VREG(LDO, N600, 0, 0, LDO, ldo, nldo2, 10000), 1465e92a4047SStephen Boyd SPMI_VREG(LDO, N1200, 0, 0, LDO, ldo, nldo2, 10000), 1466e92a4047SStephen Boyd SPMI_VREG(LDO, N600, 1, INF, LDO, ldo, nldo3, 10000), 1467e92a4047SStephen Boyd SPMI_VREG(LDO, N1200, 1, INF, LDO, ldo, nldo3, 10000), 1468e92a4047SStephen Boyd SPMI_VREG(LDO, N600_ST, 0, 0, LDO, ldo, nldo2, 10000), 1469e92a4047SStephen Boyd SPMI_VREG(LDO, N1200_ST, 0, 0, LDO, ldo, nldo2, 10000), 1470e92a4047SStephen Boyd SPMI_VREG(LDO, N600_ST, 1, INF, LDO, ldo, nldo3, 10000), 1471e92a4047SStephen Boyd SPMI_VREG(LDO, N1200_ST, 1, INF, LDO, ldo, nldo3, 10000), 1472e92a4047SStephen Boyd SPMI_VREG(LDO, P50, 0, INF, LDO, ldo, pldo, 5000), 1473e92a4047SStephen Boyd SPMI_VREG(LDO, P150, 0, INF, LDO, ldo, pldo, 10000), 1474e92a4047SStephen Boyd SPMI_VREG(LDO, P300, 0, INF, LDO, ldo, pldo, 10000), 1475e92a4047SStephen Boyd SPMI_VREG(LDO, P600, 0, INF, LDO, ldo, pldo, 10000), 1476e92a4047SStephen Boyd SPMI_VREG(LDO, P1200, 0, INF, LDO, ldo, pldo, 10000), 1477e92a4047SStephen Boyd SPMI_VREG(LDO, LN, 0, INF, LN_LDO, ln_ldo, ln_ldo, 0), 1478e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P50, 0, INF, LDO, ldo, pldo, 5000), 1479e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P150, 0, INF, LDO, ldo, pldo, 10000), 1480e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P300, 0, INF, LDO, ldo, pldo, 10000), 1481e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P600, 0, INF, LDO, ldo, pldo, 10000), 1482e92a4047SStephen Boyd SPMI_VREG(LDO, LV_P1200, 0, INF, LDO, ldo, pldo, 10000), 1483328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_N300_ST, 0, INF, FTSMPS426, ftsmps426, 1484328816c2SAngeloGioacchino Del Regno ht_nldo, 30000), 1485328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_N600_ST, 0, INF, FTSMPS426, ftsmps426, 1486328816c2SAngeloGioacchino Del Regno ht_nldo, 30000), 1487328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_N1200_ST, 0, INF, FTSMPS426, ftsmps426, 1488328816c2SAngeloGioacchino Del Regno ht_nldo, 30000), 1489328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_LVP150, 0, INF, FTSMPS426, ftsmps426, 1490328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1491328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, HT_LVP300, 0, INF, FTSMPS426, ftsmps426, 1492328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1493328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_N300_ST, 0, INF, FTSMPS426, ftsmps426, 1494328816c2SAngeloGioacchino Del Regno nldo660, 10000), 1495328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_N600_ST, 0, INF, FTSMPS426, ftsmps426, 1496328816c2SAngeloGioacchino Del Regno nldo660, 10000), 1497328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_P50, 0, INF, FTSMPS426, ftsmps426, 1498328816c2SAngeloGioacchino Del Regno pldo660, 10000), 1499328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_P150, 0, INF, FTSMPS426, ftsmps426, 1500328816c2SAngeloGioacchino Del Regno pldo660, 10000), 1501328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_P600, 0, INF, FTSMPS426, ftsmps426, 1502328816c2SAngeloGioacchino Del Regno pldo660, 10000), 1503328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_LVP150, 0, INF, FTSMPS426, ftsmps426, 1504328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1505328816c2SAngeloGioacchino Del Regno SPMI_VREG(LDO, L660_LVP600, 0, INF, FTSMPS426, ftsmps426, 1506328816c2SAngeloGioacchino Del Regno ht_lvpldo, 10000), 1507e92a4047SStephen Boyd SPMI_VREG_VS(LV100, 0, INF), 1508e92a4047SStephen Boyd SPMI_VREG_VS(LV300, 0, INF), 1509e92a4047SStephen Boyd SPMI_VREG_VS(MV300, 0, INF), 1510e92a4047SStephen Boyd SPMI_VREG_VS(MV500, 0, INF), 1511e92a4047SStephen Boyd SPMI_VREG_VS(HDMI, 0, INF), 1512e92a4047SStephen Boyd SPMI_VREG_VS(OTG, 0, INF), 1513e92a4047SStephen Boyd SPMI_VREG(BOOST, 5V_BOOST, 0, INF, BOOST, boost, boost, 0), 1514e92a4047SStephen Boyd SPMI_VREG(FTS, FTS_CTL, 0, INF, FTSMPS, ftsmps, ftsmps, 100000), 1515e92a4047SStephen Boyd SPMI_VREG(FTS, FTS2p5_CTL, 0, INF, FTSMPS, ftsmps, ftsmps2p5, 100000), 151642ba89c8SJeffrey Hugo SPMI_VREG(FTS, FTS426_CTL, 0, INF, FTSMPS426, ftsmps426, ftsmps426, 100000), 1517e92a4047SStephen Boyd SPMI_VREG(BOOST_BYP, BB_2A, 0, INF, BOOST_BYP, boost, boost_byp, 0), 1518e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL1, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1519e92a4047SStephen Boyd ult_lo_smps, 100000), 1520e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL2, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1521e92a4047SStephen Boyd ult_lo_smps, 100000), 1522e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL3, 0, INF, ULT_LO_SMPS, ult_lo_smps, 1523e92a4047SStephen Boyd ult_lo_smps, 100000), 1524e92a4047SStephen Boyd SPMI_VREG(ULT_BUCK, ULT_HF_CTL4, 0, INF, ULT_HO_SMPS, ult_ho_smps, 1525e92a4047SStephen Boyd ult_ho_smps, 100000), 1526e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N300_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1527e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N600_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1528e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N900_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1529e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, N1200_ST, 0, INF, ULT_LDO, ult_ldo, ult_nldo, 10000), 1530438421b0SAngeloGioacchino Del Regno SPMI_VREG(ULT_LDO, LV_P50, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1531e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, LV_P150, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1532e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, LV_P300, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1533e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, LV_P450, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1534e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, P600, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1535438421b0SAngeloGioacchino Del Regno SPMI_VREG(ULT_LDO, P300, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1536e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, P150, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 10000), 1537e92a4047SStephen Boyd SPMI_VREG(ULT_LDO, P50, 0, INF, ULT_LDO, ult_ldo, ult_pldo, 5000), 1538e92a4047SStephen Boyd }; 1539e92a4047SStephen Boyd 1540e92a4047SStephen Boyd static void spmi_calculate_num_voltages(struct spmi_voltage_set_points *points) 1541e92a4047SStephen Boyd { 1542e92a4047SStephen Boyd unsigned int n; 1543e92a4047SStephen Boyd struct spmi_voltage_range *range = points->range; 1544e92a4047SStephen Boyd 1545e92a4047SStephen Boyd for (; range < points->range + points->count; range++) { 1546e92a4047SStephen Boyd n = 0; 1547e92a4047SStephen Boyd if (range->set_point_max_uV) { 1548e92a4047SStephen Boyd n = range->set_point_max_uV - range->set_point_min_uV; 1549419d06a1SAxel Lin n = (n / range->step_uV) + 1; 1550e92a4047SStephen Boyd } 1551e92a4047SStephen Boyd range->n_voltages = n; 1552e92a4047SStephen Boyd points->n_voltages += n; 1553e92a4047SStephen Boyd } 1554e92a4047SStephen Boyd } 1555e92a4047SStephen Boyd 1556e92a4047SStephen Boyd static int spmi_regulator_match(struct spmi_regulator *vreg, u16 force_type) 1557e92a4047SStephen Boyd { 1558e92a4047SStephen Boyd const struct spmi_regulator_mapping *mapping; 1559e92a4047SStephen Boyd int ret, i; 1560e92a4047SStephen Boyd u32 dig_major_rev; 1561e92a4047SStephen Boyd u8 version[SPMI_COMMON_REG_SUBTYPE - SPMI_COMMON_REG_DIG_MAJOR_REV + 1]; 1562e92a4047SStephen Boyd u8 type, subtype; 1563e92a4047SStephen Boyd 1564e92a4047SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_DIG_MAJOR_REV, version, 1565e92a4047SStephen Boyd ARRAY_SIZE(version)); 1566e92a4047SStephen Boyd if (ret) { 15676ee5c044SStephen Boyd dev_dbg(vreg->dev, "could not read version registers\n"); 1568e92a4047SStephen Boyd return ret; 1569e92a4047SStephen Boyd } 1570e92a4047SStephen Boyd dig_major_rev = version[SPMI_COMMON_REG_DIG_MAJOR_REV 1571e92a4047SStephen Boyd - SPMI_COMMON_REG_DIG_MAJOR_REV]; 15720caecaa8SIlia Lin 1573e92a4047SStephen Boyd if (!force_type) { 1574e92a4047SStephen Boyd type = version[SPMI_COMMON_REG_TYPE - 1575e92a4047SStephen Boyd SPMI_COMMON_REG_DIG_MAJOR_REV]; 1576e92a4047SStephen Boyd subtype = version[SPMI_COMMON_REG_SUBTYPE - 1577e92a4047SStephen Boyd SPMI_COMMON_REG_DIG_MAJOR_REV]; 1578e92a4047SStephen Boyd } else { 1579e92a4047SStephen Boyd type = force_type >> 8; 1580e92a4047SStephen Boyd subtype = force_type; 1581e92a4047SStephen Boyd } 1582e92a4047SStephen Boyd 1583e92a4047SStephen Boyd for (i = 0; i < ARRAY_SIZE(supported_regulators); i++) { 1584e92a4047SStephen Boyd mapping = &supported_regulators[i]; 1585e92a4047SStephen Boyd if (mapping->type == type && mapping->subtype == subtype 1586e92a4047SStephen Boyd && mapping->revision_min <= dig_major_rev 1587e92a4047SStephen Boyd && mapping->revision_max >= dig_major_rev) 1588e92a4047SStephen Boyd goto found; 1589e92a4047SStephen Boyd } 1590e92a4047SStephen Boyd 1591e92a4047SStephen Boyd dev_err(vreg->dev, 1592e92a4047SStephen Boyd "unsupported regulator: name=%s type=0x%02X, subtype=0x%02X, dig major rev=0x%02X\n", 1593e92a4047SStephen Boyd vreg->desc.name, type, subtype, dig_major_rev); 1594e92a4047SStephen Boyd 1595e92a4047SStephen Boyd return -ENODEV; 1596e92a4047SStephen Boyd 1597e92a4047SStephen Boyd found: 1598e92a4047SStephen Boyd vreg->logical_type = mapping->logical_type; 1599e92a4047SStephen Boyd vreg->set_points = mapping->set_points; 1600e92a4047SStephen Boyd vreg->hpm_min_load = mapping->hpm_min_load; 1601e92a4047SStephen Boyd vreg->desc.ops = mapping->ops; 1602e92a4047SStephen Boyd 1603e92a4047SStephen Boyd if (mapping->set_points) { 1604e92a4047SStephen Boyd if (!mapping->set_points->n_voltages) 1605e92a4047SStephen Boyd spmi_calculate_num_voltages(mapping->set_points); 1606e92a4047SStephen Boyd vreg->desc.n_voltages = mapping->set_points->n_voltages; 1607e92a4047SStephen Boyd } 1608e92a4047SStephen Boyd 1609e92a4047SStephen Boyd return 0; 1610e92a4047SStephen Boyd } 1611e92a4047SStephen Boyd 16122cf7b99cSStephen Boyd static int spmi_regulator_init_slew_rate(struct spmi_regulator *vreg) 1613e92a4047SStephen Boyd { 1614e92a4047SStephen Boyd int ret; 1615e92a4047SStephen Boyd u8 reg = 0; 16162cf7b99cSStephen Boyd int step, delay, slew_rate, step_delay; 1617e92a4047SStephen Boyd const struct spmi_voltage_range *range; 1618e92a4047SStephen Boyd 1619e92a4047SStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, ®, 1); 1620e92a4047SStephen Boyd if (ret) { 1621e92a4047SStephen Boyd dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); 1622e92a4047SStephen Boyd return ret; 1623e92a4047SStephen Boyd } 1624e92a4047SStephen Boyd 1625e92a4047SStephen Boyd range = spmi_regulator_find_range(vreg); 1626e92a4047SStephen Boyd if (!range) 1627e92a4047SStephen Boyd return -EINVAL; 1628e92a4047SStephen Boyd 16292cf7b99cSStephen Boyd switch (vreg->logical_type) { 16302cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS: 16312cf7b99cSStephen Boyd step_delay = SPMI_FTSMPS_STEP_DELAY; 16322cf7b99cSStephen Boyd break; 16332cf7b99cSStephen Boyd default: 16342cf7b99cSStephen Boyd step_delay = SPMI_DEFAULT_STEP_DELAY; 16352cf7b99cSStephen Boyd break; 16362cf7b99cSStephen Boyd } 16372cf7b99cSStephen Boyd 1638e92a4047SStephen Boyd step = reg & SPMI_FTSMPS_STEP_CTRL_STEP_MASK; 1639e92a4047SStephen Boyd step >>= SPMI_FTSMPS_STEP_CTRL_STEP_SHIFT; 1640e92a4047SStephen Boyd 1641e92a4047SStephen Boyd delay = reg & SPMI_FTSMPS_STEP_CTRL_DELAY_MASK; 1642e92a4047SStephen Boyd delay >>= SPMI_FTSMPS_STEP_CTRL_DELAY_SHIFT; 1643e92a4047SStephen Boyd 1644e92a4047SStephen Boyd /* slew_rate has units of uV/us */ 1645e92a4047SStephen Boyd slew_rate = SPMI_FTSMPS_CLOCK_RATE * range->step_uV * (1 << step); 16462cf7b99cSStephen Boyd slew_rate /= 1000 * (step_delay << delay); 1647e92a4047SStephen Boyd slew_rate *= SPMI_FTSMPS_STEP_MARGIN_NUM; 1648e92a4047SStephen Boyd slew_rate /= SPMI_FTSMPS_STEP_MARGIN_DEN; 1649e92a4047SStephen Boyd 1650e92a4047SStephen Boyd /* Ensure that the slew rate is greater than 0 */ 1651e92a4047SStephen Boyd vreg->slew_rate = max(slew_rate, 1); 1652e92a4047SStephen Boyd 1653e92a4047SStephen Boyd return ret; 1654e92a4047SStephen Boyd } 1655e92a4047SStephen Boyd 16560211f68eSJorge Ramirez static int spmi_regulator_init_slew_rate_ftsmps426(struct spmi_regulator *vreg, 16570211f68eSJorge Ramirez int clock_rate) 165842ba89c8SJeffrey Hugo { 165942ba89c8SJeffrey Hugo int ret; 166042ba89c8SJeffrey Hugo u8 reg = 0; 166142ba89c8SJeffrey Hugo int delay, slew_rate; 166242ba89c8SJeffrey Hugo const struct spmi_voltage_range *range = &vreg->set_points->range[0]; 166342ba89c8SJeffrey Hugo 166442ba89c8SJeffrey Hugo ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_STEP_CTRL, ®, 1); 166542ba89c8SJeffrey Hugo if (ret) { 166642ba89c8SJeffrey Hugo dev_err(vreg->dev, "spmi read failed, ret=%d\n", ret); 166742ba89c8SJeffrey Hugo return ret; 166842ba89c8SJeffrey Hugo } 166942ba89c8SJeffrey Hugo 167042ba89c8SJeffrey Hugo delay = reg & SPMI_FTSMPS426_STEP_CTRL_DELAY_MASK; 167142ba89c8SJeffrey Hugo delay >>= SPMI_FTSMPS426_STEP_CTRL_DELAY_SHIFT; 167242ba89c8SJeffrey Hugo 167342ba89c8SJeffrey Hugo /* slew_rate has units of uV/us */ 16740211f68eSJorge Ramirez slew_rate = clock_rate * range->step_uV; 167542ba89c8SJeffrey Hugo slew_rate /= 1000 * (SPMI_FTSMPS426_STEP_DELAY << delay); 167642ba89c8SJeffrey Hugo slew_rate *= SPMI_FTSMPS426_STEP_MARGIN_NUM; 167742ba89c8SJeffrey Hugo slew_rate /= SPMI_FTSMPS426_STEP_MARGIN_DEN; 167842ba89c8SJeffrey Hugo 167942ba89c8SJeffrey Hugo /* Ensure that the slew rate is greater than 0 */ 168042ba89c8SJeffrey Hugo vreg->slew_rate = max(slew_rate, 1); 168142ba89c8SJeffrey Hugo 168242ba89c8SJeffrey Hugo return ret; 168342ba89c8SJeffrey Hugo } 168442ba89c8SJeffrey Hugo 1685e2adfacdSStephen Boyd static int spmi_regulator_init_registers(struct spmi_regulator *vreg, 1686e2adfacdSStephen Boyd const struct spmi_regulator_init_data *data) 1687e2adfacdSStephen Boyd { 1688e2adfacdSStephen Boyd int ret; 1689e2adfacdSStephen Boyd enum spmi_regulator_logical_type type; 1690e2adfacdSStephen Boyd u8 ctrl_reg[8], reg, mask; 1691e2adfacdSStephen Boyd 1692e2adfacdSStephen Boyd type = vreg->logical_type; 1693e2adfacdSStephen Boyd 1694e2adfacdSStephen Boyd ret = spmi_vreg_read(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); 1695e2adfacdSStephen Boyd if (ret) 1696e2adfacdSStephen Boyd return ret; 1697e2adfacdSStephen Boyd 1698e2adfacdSStephen Boyd /* Set up enable pin control. */ 16996a1fe83bSAxel Lin if (!(data->pin_ctrl_enable & SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT)) { 17006a1fe83bSAxel Lin switch (type) { 17016a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_SMPS: 17026a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_LDO: 17036a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_VS: 1704e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_ENABLE] &= 1705e2adfacdSStephen Boyd ~SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK; 1706e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_ENABLE] |= 1707e2adfacdSStephen Boyd data->pin_ctrl_enable & SPMI_COMMON_ENABLE_FOLLOW_ALL_MASK; 17086a1fe83bSAxel Lin break; 17096a1fe83bSAxel Lin default: 17106a1fe83bSAxel Lin break; 17116a1fe83bSAxel Lin } 1712e2adfacdSStephen Boyd } 1713e2adfacdSStephen Boyd 1714e2adfacdSStephen Boyd /* Set up mode pin control. */ 17156a1fe83bSAxel Lin if (!(data->pin_ctrl_hpm & SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT)) { 17166a1fe83bSAxel Lin switch (type) { 17176a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_SMPS: 17186a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_LDO: 1719e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] &= 1720e2adfacdSStephen Boyd ~SPMI_COMMON_MODE_FOLLOW_ALL_MASK; 1721e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] |= 1722e2adfacdSStephen Boyd data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_ALL_MASK; 17236a1fe83bSAxel Lin break; 17246a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_VS: 17256a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS: 17266a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS: 17276a1fe83bSAxel Lin case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LDO: 1728e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] &= 1729e2adfacdSStephen Boyd ~SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; 1730e2adfacdSStephen Boyd ctrl_reg[SPMI_COMMON_IDX_MODE] |= 1731e2adfacdSStephen Boyd data->pin_ctrl_hpm & SPMI_COMMON_MODE_FOLLOW_AWAKE_MASK; 17326a1fe83bSAxel Lin break; 17336a1fe83bSAxel Lin default: 17346a1fe83bSAxel Lin break; 1735e2adfacdSStephen Boyd } 1736e2adfacdSStephen Boyd } 1737e2adfacdSStephen Boyd 1738e2adfacdSStephen Boyd /* Write back any control register values that were modified. */ 1739e2adfacdSStephen Boyd ret = spmi_vreg_write(vreg, SPMI_COMMON_REG_VOLTAGE_RANGE, ctrl_reg, 8); 1740e2adfacdSStephen Boyd if (ret) 1741e2adfacdSStephen Boyd return ret; 1742e2adfacdSStephen Boyd 1743e2adfacdSStephen Boyd /* Set soft start strength and over current protection for VS. */ 1744e2adfacdSStephen Boyd if (type == SPMI_REGULATOR_LOGICAL_TYPE_VS) { 1745e2adfacdSStephen Boyd if (data->vs_soft_start_strength 1746e2adfacdSStephen Boyd != SPMI_VS_SOFT_START_STR_HW_DEFAULT) { 1747e2adfacdSStephen Boyd reg = data->vs_soft_start_strength 1748e2adfacdSStephen Boyd & SPMI_VS_SOFT_START_SEL_MASK; 1749e2adfacdSStephen Boyd mask = SPMI_VS_SOFT_START_SEL_MASK; 1750e2adfacdSStephen Boyd return spmi_vreg_update_bits(vreg, 1751e2adfacdSStephen Boyd SPMI_VS_REG_SOFT_START, 1752e2adfacdSStephen Boyd reg, mask); 1753e2adfacdSStephen Boyd } 1754e2adfacdSStephen Boyd } 1755e2adfacdSStephen Boyd 1756e2adfacdSStephen Boyd return 0; 1757e2adfacdSStephen Boyd } 1758e2adfacdSStephen Boyd 1759e2adfacdSStephen Boyd static void spmi_regulator_get_dt_config(struct spmi_regulator *vreg, 1760e2adfacdSStephen Boyd struct device_node *node, struct spmi_regulator_init_data *data) 1761e2adfacdSStephen Boyd { 1762e2adfacdSStephen Boyd /* 1763e2adfacdSStephen Boyd * Initialize configuration parameters to use hardware default in case 1764e2adfacdSStephen Boyd * no value is specified via device tree. 1765e2adfacdSStephen Boyd */ 1766e2adfacdSStephen Boyd data->pin_ctrl_enable = SPMI_REGULATOR_PIN_CTRL_ENABLE_HW_DEFAULT; 1767e2adfacdSStephen Boyd data->pin_ctrl_hpm = SPMI_REGULATOR_PIN_CTRL_HPM_HW_DEFAULT; 1768e2adfacdSStephen Boyd data->vs_soft_start_strength = SPMI_VS_SOFT_START_STR_HW_DEFAULT; 1769e2adfacdSStephen Boyd 1770e2adfacdSStephen Boyd /* These bindings are optional, so it is okay if they aren't found. */ 1771e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,ocp-max-retries", 1772e2adfacdSStephen Boyd &vreg->ocp_max_retries); 1773e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,ocp-retry-delay", 1774e2adfacdSStephen Boyd &vreg->ocp_retry_delay_ms); 1775e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,pin-ctrl-enable", 1776e2adfacdSStephen Boyd &data->pin_ctrl_enable); 1777e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,pin-ctrl-hpm", &data->pin_ctrl_hpm); 1778e2adfacdSStephen Boyd of_property_read_u32(node, "qcom,vs-soft-start-strength", 1779e2adfacdSStephen Boyd &data->vs_soft_start_strength); 1780e2adfacdSStephen Boyd } 1781e2adfacdSStephen Boyd 1782e92a4047SStephen Boyd static unsigned int spmi_regulator_of_map_mode(unsigned int mode) 1783e92a4047SStephen Boyd { 1784e2adfacdSStephen Boyd if (mode == 1) 1785e92a4047SStephen Boyd return REGULATOR_MODE_NORMAL; 1786e2adfacdSStephen Boyd if (mode == 2) 1787e2adfacdSStephen Boyd return REGULATOR_MODE_FAST; 1788e92a4047SStephen Boyd 1789e92a4047SStephen Boyd return REGULATOR_MODE_IDLE; 1790e92a4047SStephen Boyd } 1791e92a4047SStephen Boyd 1792e92a4047SStephen Boyd static int spmi_regulator_of_parse(struct device_node *node, 1793e92a4047SStephen Boyd const struct regulator_desc *desc, 1794e92a4047SStephen Boyd struct regulator_config *config) 1795e92a4047SStephen Boyd { 1796e2adfacdSStephen Boyd struct spmi_regulator_init_data data = { }; 1797e92a4047SStephen Boyd struct spmi_regulator *vreg = config->driver_data; 1798e92a4047SStephen Boyd struct device *dev = config->dev; 1799e92a4047SStephen Boyd int ret; 1800e92a4047SStephen Boyd 1801e2adfacdSStephen Boyd spmi_regulator_get_dt_config(vreg, node, &data); 1802e2adfacdSStephen Boyd 1803e2adfacdSStephen Boyd if (!vreg->ocp_max_retries) 1804e92a4047SStephen Boyd vreg->ocp_max_retries = SPMI_VS_OCP_DEFAULT_MAX_RETRIES; 1805e2adfacdSStephen Boyd if (!vreg->ocp_retry_delay_ms) 1806e92a4047SStephen Boyd vreg->ocp_retry_delay_ms = SPMI_VS_OCP_DEFAULT_RETRY_DELAY_MS; 1807e92a4047SStephen Boyd 1808e2adfacdSStephen Boyd ret = spmi_regulator_init_registers(vreg, &data); 1809e2adfacdSStephen Boyd if (ret) { 1810e2adfacdSStephen Boyd dev_err(dev, "common initialization failed, ret=%d\n", ret); 1811e2adfacdSStephen Boyd return ret; 1812e2adfacdSStephen Boyd } 1813e2adfacdSStephen Boyd 18142cf7b99cSStephen Boyd switch (vreg->logical_type) { 18152cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS: 18162cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_ULT_LO_SMPS: 18172cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_ULT_HO_SMPS: 18182cf7b99cSStephen Boyd case SPMI_REGULATOR_LOGICAL_TYPE_SMPS: 18192cf7b99cSStephen Boyd ret = spmi_regulator_init_slew_rate(vreg); 1820e92a4047SStephen Boyd if (ret) 1821e92a4047SStephen Boyd return ret; 182242ba89c8SJeffrey Hugo break; 182342ba89c8SJeffrey Hugo case SPMI_REGULATOR_LOGICAL_TYPE_FTSMPS426: 18240211f68eSJorge Ramirez ret = spmi_regulator_init_slew_rate_ftsmps426(vreg, 18250211f68eSJorge Ramirez SPMI_FTSMPS426_CLOCK_RATE); 18260211f68eSJorge Ramirez if (ret) 18270211f68eSJorge Ramirez return ret; 18280211f68eSJorge Ramirez break; 18290211f68eSJorge Ramirez case SPMI_REGULATOR_LOGICAL_TYPE_HFS430: 18300211f68eSJorge Ramirez ret = spmi_regulator_init_slew_rate_ftsmps426(vreg, 18310211f68eSJorge Ramirez SPMI_HFS430_CLOCK_RATE); 183242ba89c8SJeffrey Hugo if (ret) 183342ba89c8SJeffrey Hugo return ret; 183442ba89c8SJeffrey Hugo break; 18352cf7b99cSStephen Boyd default: 18362cf7b99cSStephen Boyd break; 1837e92a4047SStephen Boyd } 1838e92a4047SStephen Boyd 1839e92a4047SStephen Boyd if (vreg->logical_type != SPMI_REGULATOR_LOGICAL_TYPE_VS) 1840e92a4047SStephen Boyd vreg->ocp_irq = 0; 1841e92a4047SStephen Boyd 1842e92a4047SStephen Boyd if (vreg->ocp_irq) { 1843e92a4047SStephen Boyd ret = devm_request_irq(dev, vreg->ocp_irq, 1844e92a4047SStephen Boyd spmi_regulator_vs_ocp_isr, IRQF_TRIGGER_RISING, "ocp", 1845e92a4047SStephen Boyd vreg); 1846e92a4047SStephen Boyd if (ret < 0) { 1847e92a4047SStephen Boyd dev_err(dev, "failed to request irq %d, ret=%d\n", 1848e92a4047SStephen Boyd vreg->ocp_irq, ret); 1849e92a4047SStephen Boyd return ret; 1850e92a4047SStephen Boyd } 1851e92a4047SStephen Boyd 1852b6688015SMatti Vaittinen ret = devm_delayed_work_autocancel(dev, &vreg->ocp_work, 1853b6688015SMatti Vaittinen spmi_regulator_vs_ocp_work); 1854b6688015SMatti Vaittinen if (ret) 1855b6688015SMatti Vaittinen return ret; 1856e92a4047SStephen Boyd } 1857e92a4047SStephen Boyd 1858e92a4047SStephen Boyd return 0; 1859e92a4047SStephen Boyd } 1860e92a4047SStephen Boyd 1861e92a4047SStephen Boyd static const struct spmi_regulator_data pm8941_regulators[] = { 1862e92a4047SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 1863e92a4047SStephen Boyd { "s2", 0x1700, "vdd_s2", }, 1864e92a4047SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 1865c333dfe8SStephen Boyd { "s4", 0xa000, }, 1866e92a4047SStephen Boyd { "l1", 0x4000, "vdd_l1_l3", }, 1867e92a4047SStephen Boyd { "l2", 0x4100, "vdd_l2_lvs_1_2_3", }, 1868e92a4047SStephen Boyd { "l3", 0x4200, "vdd_l1_l3", }, 1869e92a4047SStephen Boyd { "l4", 0x4300, "vdd_l4_l11", }, 1870e92a4047SStephen Boyd { "l5", 0x4400, "vdd_l5_l7", NULL, 0x0410 }, 1871e92a4047SStephen Boyd { "l6", 0x4500, "vdd_l6_l12_l14_l15", }, 1872e92a4047SStephen Boyd { "l7", 0x4600, "vdd_l5_l7", NULL, 0x0410 }, 1873e92a4047SStephen Boyd { "l8", 0x4700, "vdd_l8_l16_l18_19", }, 1874e92a4047SStephen Boyd { "l9", 0x4800, "vdd_l9_l10_l17_l22", }, 1875e92a4047SStephen Boyd { "l10", 0x4900, "vdd_l9_l10_l17_l22", }, 1876e92a4047SStephen Boyd { "l11", 0x4a00, "vdd_l4_l11", }, 1877e92a4047SStephen Boyd { "l12", 0x4b00, "vdd_l6_l12_l14_l15", }, 1878e92a4047SStephen Boyd { "l13", 0x4c00, "vdd_l13_l20_l23_l24", }, 1879e92a4047SStephen Boyd { "l14", 0x4d00, "vdd_l6_l12_l14_l15", }, 1880e92a4047SStephen Boyd { "l15", 0x4e00, "vdd_l6_l12_l14_l15", }, 1881e92a4047SStephen Boyd { "l16", 0x4f00, "vdd_l8_l16_l18_19", }, 1882e92a4047SStephen Boyd { "l17", 0x5000, "vdd_l9_l10_l17_l22", }, 1883e92a4047SStephen Boyd { "l18", 0x5100, "vdd_l8_l16_l18_19", }, 1884e92a4047SStephen Boyd { "l19", 0x5200, "vdd_l8_l16_l18_19", }, 1885e92a4047SStephen Boyd { "l20", 0x5300, "vdd_l13_l20_l23_l24", }, 1886e92a4047SStephen Boyd { "l21", 0x5400, "vdd_l21", }, 1887e92a4047SStephen Boyd { "l22", 0x5500, "vdd_l9_l10_l17_l22", }, 1888e92a4047SStephen Boyd { "l23", 0x5600, "vdd_l13_l20_l23_l24", }, 1889e92a4047SStephen Boyd { "l24", 0x5700, "vdd_l13_l20_l23_l24", }, 1890e92a4047SStephen Boyd { "lvs1", 0x8000, "vdd_l2_lvs_1_2_3", }, 1891e92a4047SStephen Boyd { "lvs2", 0x8100, "vdd_l2_lvs_1_2_3", }, 1892e92a4047SStephen Boyd { "lvs3", 0x8200, "vdd_l2_lvs_1_2_3", }, 189393bfe79bSStephen Boyd { "5vs1", 0x8300, "vin_5vs", "ocp-5vs1", }, 189493bfe79bSStephen Boyd { "5vs2", 0x8400, "vin_5vs", "ocp-5vs2", }, 1895e92a4047SStephen Boyd { } 1896e92a4047SStephen Boyd }; 1897e92a4047SStephen Boyd 1898e92a4047SStephen Boyd static const struct spmi_regulator_data pm8841_regulators[] = { 1899e92a4047SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 1900e92a4047SStephen Boyd { "s2", 0x1700, "vdd_s2", NULL, 0x1c08 }, 1901e92a4047SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 1902e92a4047SStephen Boyd { "s4", 0x1d00, "vdd_s4", NULL, 0x1c08 }, 1903e92a4047SStephen Boyd { "s5", 0x2000, "vdd_s5", NULL, 0x1c08 }, 1904e92a4047SStephen Boyd { "s6", 0x2300, "vdd_s6", NULL, 0x1c08 }, 1905e92a4047SStephen Boyd { "s7", 0x2600, "vdd_s7", NULL, 0x1c08 }, 1906e92a4047SStephen Boyd { "s8", 0x2900, "vdd_s8", NULL, 0x1c08 }, 1907e92a4047SStephen Boyd { } 1908e92a4047SStephen Boyd }; 1909e92a4047SStephen Boyd 1910e92a4047SStephen Boyd static const struct spmi_regulator_data pm8916_regulators[] = { 1911e92a4047SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 1912e92a4047SStephen Boyd { "s2", 0x1700, "vdd_s2", }, 1913e92a4047SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 1914e92a4047SStephen Boyd { "s4", 0x1d00, "vdd_s4", }, 1915e92a4047SStephen Boyd { "l1", 0x4000, "vdd_l1_l3", }, 1916e92a4047SStephen Boyd { "l2", 0x4100, "vdd_l2", }, 1917e92a4047SStephen Boyd { "l3", 0x4200, "vdd_l1_l3", }, 1918e92a4047SStephen Boyd { "l4", 0x4300, "vdd_l4_l5_l6", }, 1919e92a4047SStephen Boyd { "l5", 0x4400, "vdd_l4_l5_l6", }, 1920e92a4047SStephen Boyd { "l6", 0x4500, "vdd_l4_l5_l6", }, 1921e92a4047SStephen Boyd { "l7", 0x4600, "vdd_l7", }, 1922e92a4047SStephen Boyd { "l8", 0x4700, "vdd_l8_l11_l14_l15_l16", }, 1923e92a4047SStephen Boyd { "l9", 0x4800, "vdd_l9_l10_l12_l13_l17_l18", }, 1924e92a4047SStephen Boyd { "l10", 0x4900, "vdd_l9_l10_l12_l13_l17_l18", }, 1925e92a4047SStephen Boyd { "l11", 0x4a00, "vdd_l8_l11_l14_l15_l16", }, 1926e92a4047SStephen Boyd { "l12", 0x4b00, "vdd_l9_l10_l12_l13_l17_l18", }, 1927e92a4047SStephen Boyd { "l13", 0x4c00, "vdd_l9_l10_l12_l13_l17_l18", }, 1928e92a4047SStephen Boyd { "l14", 0x4d00, "vdd_l8_l11_l14_l15_l16", }, 1929e92a4047SStephen Boyd { "l15", 0x4e00, "vdd_l8_l11_l14_l15_l16", }, 1930e92a4047SStephen Boyd { "l16", 0x4f00, "vdd_l8_l11_l14_l15_l16", }, 1931e92a4047SStephen Boyd { "l17", 0x5000, "vdd_l9_l10_l12_l13_l17_l18", }, 1932e92a4047SStephen Boyd { "l18", 0x5100, "vdd_l9_l10_l12_l13_l17_l18", }, 1933e92a4047SStephen Boyd { } 1934e92a4047SStephen Boyd }; 1935e92a4047SStephen Boyd 1936e4ff1710SAngelo G. Del Regno static const struct spmi_regulator_data pm8950_regulators[] = { 1937e4ff1710SAngelo G. Del Regno { "s1", 0x1400, "vdd_s1", }, 1938e4ff1710SAngelo G. Del Regno { "s2", 0x1700, "vdd_s2", }, 1939e4ff1710SAngelo G. Del Regno { "s3", 0x1a00, "vdd_s3", }, 1940e4ff1710SAngelo G. Del Regno { "s4", 0x1d00, "vdd_s4", }, 1941e4ff1710SAngelo G. Del Regno { "s5", 0x2000, "vdd_s5", }, 1942e4ff1710SAngelo G. Del Regno { "s6", 0x2300, "vdd_s6", }, 1943e4ff1710SAngelo G. Del Regno { "l1", 0x4000, "vdd_l1_l19", }, 1944e4ff1710SAngelo G. Del Regno { "l2", 0x4100, "vdd_l2_l23", }, 1945e4ff1710SAngelo G. Del Regno { "l3", 0x4200, "vdd_l3", }, 1946e4ff1710SAngelo G. Del Regno { "l4", 0x4300, "vdd_l4_l5_l6_l7_l16", }, 1947e4ff1710SAngelo G. Del Regno { "l5", 0x4400, "vdd_l4_l5_l6_l7_l16", }, 1948e4ff1710SAngelo G. Del Regno { "l6", 0x4500, "vdd_l4_l5_l6_l7_l16", }, 1949e4ff1710SAngelo G. Del Regno { "l7", 0x4600, "vdd_l4_l5_l6_l7_l16", }, 1950e4ff1710SAngelo G. Del Regno { "l8", 0x4700, "vdd_l8_l11_l12_l17_l22", }, 1951e4ff1710SAngelo G. Del Regno { "l9", 0x4800, "vdd_l9_l10_l13_l14_l15_l18", }, 1952e4ff1710SAngelo G. Del Regno { "l10", 0x4900, "vdd_l9_l10_l13_l14_l15_l18", }, 1953e4ff1710SAngelo G. Del Regno { "l11", 0x4a00, "vdd_l8_l11_l12_l17_l22", }, 1954e4ff1710SAngelo G. Del Regno { "l12", 0x4b00, "vdd_l8_l11_l12_l17_l22", }, 1955e4ff1710SAngelo G. Del Regno { "l13", 0x4c00, "vdd_l9_l10_l13_l14_l15_l18", }, 1956e4ff1710SAngelo G. Del Regno { "l14", 0x4d00, "vdd_l9_l10_l13_l14_l15_l18", }, 1957e4ff1710SAngelo G. Del Regno { "l15", 0x4e00, "vdd_l9_l10_l13_l14_l15_l18", }, 1958e4ff1710SAngelo G. Del Regno { "l16", 0x4f00, "vdd_l4_l5_l6_l7_l16", }, 1959e4ff1710SAngelo G. Del Regno { "l17", 0x5000, "vdd_l8_l11_l12_l17_l22", }, 1960e4ff1710SAngelo G. Del Regno { "l18", 0x5100, "vdd_l9_l10_l13_l14_l15_l18", }, 1961e4ff1710SAngelo G. Del Regno { "l19", 0x5200, "vdd_l1_l19", }, 1962e4ff1710SAngelo G. Del Regno { "l20", 0x5300, "vdd_l20", }, 1963e4ff1710SAngelo G. Del Regno { "l21", 0x5400, "vdd_l21", }, 1964e4ff1710SAngelo G. Del Regno { "l22", 0x5500, "vdd_l8_l11_l12_l17_l22", }, 1965e4ff1710SAngelo G. Del Regno { "l23", 0x5600, "vdd_l2_l23", }, 1966e4ff1710SAngelo G. Del Regno { } 1967e4ff1710SAngelo G. Del Regno }; 1968e4ff1710SAngelo G. Del Regno 196950314e55SStephen Boyd static const struct spmi_regulator_data pm8994_regulators[] = { 197050314e55SStephen Boyd { "s1", 0x1400, "vdd_s1", }, 197150314e55SStephen Boyd { "s2", 0x1700, "vdd_s2", }, 197250314e55SStephen Boyd { "s3", 0x1a00, "vdd_s3", }, 197350314e55SStephen Boyd { "s4", 0x1d00, "vdd_s4", }, 197450314e55SStephen Boyd { "s5", 0x2000, "vdd_s5", }, 197550314e55SStephen Boyd { "s6", 0x2300, "vdd_s6", }, 197650314e55SStephen Boyd { "s7", 0x2600, "vdd_s7", }, 197750314e55SStephen Boyd { "s8", 0x2900, "vdd_s8", }, 197850314e55SStephen Boyd { "s9", 0x2c00, "vdd_s9", }, 197950314e55SStephen Boyd { "s10", 0x2f00, "vdd_s10", }, 198050314e55SStephen Boyd { "s11", 0x3200, "vdd_s11", }, 198150314e55SStephen Boyd { "s12", 0x3500, "vdd_s12", }, 198250314e55SStephen Boyd { "l1", 0x4000, "vdd_l1", }, 198350314e55SStephen Boyd { "l2", 0x4100, "vdd_l2_l26_l28", }, 198450314e55SStephen Boyd { "l3", 0x4200, "vdd_l3_l11", }, 198550314e55SStephen Boyd { "l4", 0x4300, "vdd_l4_l27_l31", }, 198650314e55SStephen Boyd { "l5", 0x4400, "vdd_l5_l7", }, 198750314e55SStephen Boyd { "l6", 0x4500, "vdd_l6_l12_l32", }, 198850314e55SStephen Boyd { "l7", 0x4600, "vdd_l5_l7", }, 198950314e55SStephen Boyd { "l8", 0x4700, "vdd_l8_l16_l30", }, 199050314e55SStephen Boyd { "l9", 0x4800, "vdd_l9_l10_l18_l22", }, 199150314e55SStephen Boyd { "l10", 0x4900, "vdd_l9_l10_l18_l22", }, 199250314e55SStephen Boyd { "l11", 0x4a00, "vdd_l3_l11", }, 199350314e55SStephen Boyd { "l12", 0x4b00, "vdd_l6_l12_l32", }, 199450314e55SStephen Boyd { "l13", 0x4c00, "vdd_l13_l19_l23_l24", }, 199550314e55SStephen Boyd { "l14", 0x4d00, "vdd_l14_l15", }, 199650314e55SStephen Boyd { "l15", 0x4e00, "vdd_l14_l15", }, 199750314e55SStephen Boyd { "l16", 0x4f00, "vdd_l8_l16_l30", }, 199850314e55SStephen Boyd { "l17", 0x5000, "vdd_l17_l29", }, 199950314e55SStephen Boyd { "l18", 0x5100, "vdd_l9_l10_l18_l22", }, 200050314e55SStephen Boyd { "l19", 0x5200, "vdd_l13_l19_l23_l24", }, 200150314e55SStephen Boyd { "l20", 0x5300, "vdd_l20_l21", }, 200250314e55SStephen Boyd { "l21", 0x5400, "vdd_l20_l21", }, 200350314e55SStephen Boyd { "l22", 0x5500, "vdd_l9_l10_l18_l22", }, 200450314e55SStephen Boyd { "l23", 0x5600, "vdd_l13_l19_l23_l24", }, 200550314e55SStephen Boyd { "l24", 0x5700, "vdd_l13_l19_l23_l24", }, 200650314e55SStephen Boyd { "l25", 0x5800, "vdd_l25", }, 200750314e55SStephen Boyd { "l26", 0x5900, "vdd_l2_l26_l28", }, 200850314e55SStephen Boyd { "l27", 0x5a00, "vdd_l4_l27_l31", }, 200950314e55SStephen Boyd { "l28", 0x5b00, "vdd_l2_l26_l28", }, 201050314e55SStephen Boyd { "l29", 0x5c00, "vdd_l17_l29", }, 201150314e55SStephen Boyd { "l30", 0x5d00, "vdd_l8_l16_l30", }, 201250314e55SStephen Boyd { "l31", 0x5e00, "vdd_l4_l27_l31", }, 201350314e55SStephen Boyd { "l32", 0x5f00, "vdd_l6_l12_l32", }, 201450314e55SStephen Boyd { "lvs1", 0x8000, "vdd_lvs_1_2", }, 201550314e55SStephen Boyd { "lvs2", 0x8100, "vdd_lvs_1_2", }, 201650314e55SStephen Boyd { } 201750314e55SStephen Boyd }; 201850314e55SStephen Boyd 2019ca5cd8c9SRajendra Nayak static const struct spmi_regulator_data pmi8994_regulators[] = { 2020ca5cd8c9SRajendra Nayak { "s1", 0x1400, "vdd_s1", }, 2021ca5cd8c9SRajendra Nayak { "s2", 0x1700, "vdd_s2", }, 2022ca5cd8c9SRajendra Nayak { "s3", 0x1a00, "vdd_s3", }, 2023ca5cd8c9SRajendra Nayak { "l1", 0x4000, "vdd_l1", }, 2024ca5cd8c9SRajendra Nayak { } 2025ca5cd8c9SRajendra Nayak }; 2026ca5cd8c9SRajendra Nayak 20270074c447SAngeloGioacchino Del Regno static const struct spmi_regulator_data pm660_regulators[] = { 20280074c447SAngeloGioacchino Del Regno { "s1", 0x1400, "vdd_s1", }, 20290074c447SAngeloGioacchino Del Regno { "s2", 0x1700, "vdd_s2", }, 20300074c447SAngeloGioacchino Del Regno { "s3", 0x1a00, "vdd_s3", }, 20310074c447SAngeloGioacchino Del Regno { "s4", 0x1d00, "vdd_s3", }, 20320074c447SAngeloGioacchino Del Regno { "s5", 0x2000, "vdd_s5", }, 20330074c447SAngeloGioacchino Del Regno { "s6", 0x2300, "vdd_s6", }, 20340074c447SAngeloGioacchino Del Regno { "l1", 0x4000, "vdd_l1_l6_l7", }, 20350074c447SAngeloGioacchino Del Regno { "l2", 0x4100, "vdd_l2_l3", }, 20360074c447SAngeloGioacchino Del Regno { "l3", 0x4200, "vdd_l2_l3", }, 20370074c447SAngeloGioacchino Del Regno /* l4 is unaccessible on PM660 */ 20380074c447SAngeloGioacchino Del Regno { "l5", 0x4400, "vdd_l5", }, 20390074c447SAngeloGioacchino Del Regno { "l6", 0x4500, "vdd_l1_l6_l7", }, 20400074c447SAngeloGioacchino Del Regno { "l7", 0x4600, "vdd_l1_l6_l7", }, 20410074c447SAngeloGioacchino Del Regno { "l8", 0x4700, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20420074c447SAngeloGioacchino Del Regno { "l9", 0x4800, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20430074c447SAngeloGioacchino Del Regno { "l10", 0x4900, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20440074c447SAngeloGioacchino Del Regno { "l11", 0x4a00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20450074c447SAngeloGioacchino Del Regno { "l12", 0x4b00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20460074c447SAngeloGioacchino Del Regno { "l13", 0x4c00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20470074c447SAngeloGioacchino Del Regno { "l14", 0x4d00, "vdd_l8_l9_l10_l11_l12_l13_l14", }, 20480074c447SAngeloGioacchino Del Regno { "l15", 0x4e00, "vdd_l15_l16_l17_l18_l19", }, 20490074c447SAngeloGioacchino Del Regno { "l16", 0x4f00, "vdd_l15_l16_l17_l18_l19", }, 20500074c447SAngeloGioacchino Del Regno { "l17", 0x5000, "vdd_l15_l16_l17_l18_l19", }, 20510074c447SAngeloGioacchino Del Regno { "l18", 0x5100, "vdd_l15_l16_l17_l18_l19", }, 20520074c447SAngeloGioacchino Del Regno { "l19", 0x5200, "vdd_l15_l16_l17_l18_l19", }, 20530074c447SAngeloGioacchino Del Regno { } 20540074c447SAngeloGioacchino Del Regno }; 20550074c447SAngeloGioacchino Del Regno 20560074c447SAngeloGioacchino Del Regno static const struct spmi_regulator_data pm660l_regulators[] = { 20570074c447SAngeloGioacchino Del Regno { "s1", 0x1400, "vdd_s1", }, 20580074c447SAngeloGioacchino Del Regno { "s2", 0x1700, "vdd_s2", }, 20590074c447SAngeloGioacchino Del Regno { "s3", 0x1a00, "vdd_s3", }, 20600074c447SAngeloGioacchino Del Regno { "s4", 0x1d00, "vdd_s4", }, 20610074c447SAngeloGioacchino Del Regno { "s5", 0x2000, "vdd_s5", }, 20620074c447SAngeloGioacchino Del Regno { "l1", 0x4000, "vdd_l1_l9_l10", }, 20630074c447SAngeloGioacchino Del Regno { "l2", 0x4100, "vdd_l2", }, 20640074c447SAngeloGioacchino Del Regno { "l3", 0x4200, "vdd_l3_l5_l7_l8", }, 20650074c447SAngeloGioacchino Del Regno { "l4", 0x4300, "vdd_l4_l6", }, 20660074c447SAngeloGioacchino Del Regno { "l5", 0x4400, "vdd_l3_l5_l7_l8", }, 20670074c447SAngeloGioacchino Del Regno { "l6", 0x4500, "vdd_l4_l6", }, 20680074c447SAngeloGioacchino Del Regno { "l7", 0x4600, "vdd_l3_l5_l7_l8", }, 20690074c447SAngeloGioacchino Del Regno { "l8", 0x4700, "vdd_l3_l5_l7_l8", }, 20700074c447SAngeloGioacchino Del Regno { "l9", 0x4800, "vdd_l1_l9_l10", }, 20710074c447SAngeloGioacchino Del Regno { "l10", 0x4900, "vdd_l1_l9_l10", }, 20720074c447SAngeloGioacchino Del Regno { } 20730074c447SAngeloGioacchino Del Regno }; 20740074c447SAngeloGioacchino Del Regno 20750074c447SAngeloGioacchino Del Regno 20762e36e140SAngelo G. Del Regno static const struct spmi_regulator_data pm8004_regulators[] = { 20772e36e140SAngelo G. Del Regno { "s2", 0x1700, "vdd_s2", }, 20782e36e140SAngelo G. Del Regno { "s5", 0x2000, "vdd_s5", }, 20792e36e140SAngelo G. Del Regno { } 20802e36e140SAngelo G. Del Regno }; 20812e36e140SAngelo G. Del Regno 208242ba89c8SJeffrey Hugo static const struct spmi_regulator_data pm8005_regulators[] = { 208342ba89c8SJeffrey Hugo { "s1", 0x1400, "vdd_s1", }, 208442ba89c8SJeffrey Hugo { "s2", 0x1700, "vdd_s2", }, 208542ba89c8SJeffrey Hugo { "s3", 0x1a00, "vdd_s3", }, 208642ba89c8SJeffrey Hugo { "s4", 0x1d00, "vdd_s4", }, 208742ba89c8SJeffrey Hugo { } 208842ba89c8SJeffrey Hugo }; 208942ba89c8SJeffrey Hugo 20900211f68eSJorge Ramirez static const struct spmi_regulator_data pms405_regulators[] = { 20910211f68eSJorge Ramirez { "s3", 0x1a00, "vdd_s3"}, 20920211f68eSJorge Ramirez { } 20930211f68eSJorge Ramirez }; 20940211f68eSJorge Ramirez 2095e92a4047SStephen Boyd static const struct of_device_id qcom_spmi_regulator_match[] = { 20962e36e140SAngelo G. Del Regno { .compatible = "qcom,pm8004-regulators", .data = &pm8004_regulators }, 209742ba89c8SJeffrey Hugo { .compatible = "qcom,pm8005-regulators", .data = &pm8005_regulators }, 2098e92a4047SStephen Boyd { .compatible = "qcom,pm8841-regulators", .data = &pm8841_regulators }, 2099e92a4047SStephen Boyd { .compatible = "qcom,pm8916-regulators", .data = &pm8916_regulators }, 2100e92a4047SStephen Boyd { .compatible = "qcom,pm8941-regulators", .data = &pm8941_regulators }, 2101e4ff1710SAngelo G. Del Regno { .compatible = "qcom,pm8950-regulators", .data = &pm8950_regulators }, 210250314e55SStephen Boyd { .compatible = "qcom,pm8994-regulators", .data = &pm8994_regulators }, 2103ca5cd8c9SRajendra Nayak { .compatible = "qcom,pmi8994-regulators", .data = &pmi8994_regulators }, 21040074c447SAngeloGioacchino Del Regno { .compatible = "qcom,pm660-regulators", .data = &pm660_regulators }, 21050074c447SAngeloGioacchino Del Regno { .compatible = "qcom,pm660l-regulators", .data = &pm660l_regulators }, 21060211f68eSJorge Ramirez { .compatible = "qcom,pms405-regulators", .data = &pms405_regulators }, 2107e92a4047SStephen Boyd { } 2108e92a4047SStephen Boyd }; 2109e92a4047SStephen Boyd MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match); 2110e92a4047SStephen Boyd 2111e92a4047SStephen Boyd static int qcom_spmi_regulator_probe(struct platform_device *pdev) 2112e92a4047SStephen Boyd { 2113e92a4047SStephen Boyd const struct spmi_regulator_data *reg; 211486f4ff7aSJorge Ramirez-Ortiz const struct spmi_voltage_range *range; 2115e92a4047SStephen Boyd const struct of_device_id *match; 2116e92a4047SStephen Boyd struct regulator_config config = { }; 2117e92a4047SStephen Boyd struct regulator_dev *rdev; 2118e92a4047SStephen Boyd struct spmi_regulator *vreg; 2119e92a4047SStephen Boyd struct regmap *regmap; 2120e92a4047SStephen Boyd const char *name; 2121e92a4047SStephen Boyd struct device *dev = &pdev->dev; 21220caecaa8SIlia Lin struct device_node *node = pdev->dev.of_node; 2123fffe7f52SNiklas Cassel struct device_node *syscon, *reg_node; 2124fffe7f52SNiklas Cassel struct property *reg_prop; 21250caecaa8SIlia Lin int ret, lenp; 2126e92a4047SStephen Boyd struct list_head *vreg_list; 2127e92a4047SStephen Boyd 2128e92a4047SStephen Boyd vreg_list = devm_kzalloc(dev, sizeof(*vreg_list), GFP_KERNEL); 2129e92a4047SStephen Boyd if (!vreg_list) 2130e92a4047SStephen Boyd return -ENOMEM; 2131e92a4047SStephen Boyd INIT_LIST_HEAD(vreg_list); 2132e92a4047SStephen Boyd platform_set_drvdata(pdev, vreg_list); 2133e92a4047SStephen Boyd 2134e92a4047SStephen Boyd regmap = dev_get_regmap(dev->parent, NULL); 2135e92a4047SStephen Boyd if (!regmap) 2136e92a4047SStephen Boyd return -ENODEV; 2137e92a4047SStephen Boyd 2138e92a4047SStephen Boyd match = of_match_device(qcom_spmi_regulator_match, &pdev->dev); 2139e92a4047SStephen Boyd if (!match) 2140e92a4047SStephen Boyd return -ENODEV; 2141e92a4047SStephen Boyd 21420caecaa8SIlia Lin if (of_find_property(node, "qcom,saw-reg", &lenp)) { 21430caecaa8SIlia Lin syscon = of_parse_phandle(node, "qcom,saw-reg", 0); 21440caecaa8SIlia Lin saw_regmap = syscon_node_to_regmap(syscon); 21450caecaa8SIlia Lin of_node_put(syscon); 214685046a15SNiklas Cassel if (IS_ERR(saw_regmap)) 21470caecaa8SIlia Lin dev_err(dev, "ERROR reading SAW regmap\n"); 21480caecaa8SIlia Lin } 21490caecaa8SIlia Lin 2150e92a4047SStephen Boyd for (reg = match->data; reg->name; reg++) { 21510caecaa8SIlia Lin 2152fffe7f52SNiklas Cassel if (saw_regmap) { 2153fffe7f52SNiklas Cassel reg_node = of_get_child_by_name(node, reg->name); 2154fffe7f52SNiklas Cassel reg_prop = of_find_property(reg_node, "qcom,saw-slave", 2155fffe7f52SNiklas Cassel &lenp); 2156fffe7f52SNiklas Cassel of_node_put(reg_node); 2157fffe7f52SNiklas Cassel if (reg_prop) 21580caecaa8SIlia Lin continue; 21590caecaa8SIlia Lin } 21600caecaa8SIlia Lin 2161e92a4047SStephen Boyd vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); 2162e92a4047SStephen Boyd if (!vreg) 2163e92a4047SStephen Boyd return -ENOMEM; 2164e92a4047SStephen Boyd 2165e92a4047SStephen Boyd vreg->dev = dev; 2166e92a4047SStephen Boyd vreg->base = reg->base; 2167e92a4047SStephen Boyd vreg->regmap = regmap; 2168e92a4047SStephen Boyd if (reg->ocp) { 2169e92a4047SStephen Boyd vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp); 2170b6688015SMatti Vaittinen if (vreg->ocp_irq < 0) 2171b6688015SMatti Vaittinen return vreg->ocp_irq; 2172e92a4047SStephen Boyd } 2173e92a4047SStephen Boyd vreg->desc.id = -1; 2174e92a4047SStephen Boyd vreg->desc.owner = THIS_MODULE; 2175e92a4047SStephen Boyd vreg->desc.type = REGULATOR_VOLTAGE; 21769d485332SAxel Lin vreg->desc.enable_reg = reg->base + SPMI_COMMON_REG_ENABLE; 21779d485332SAxel Lin vreg->desc.enable_mask = SPMI_COMMON_ENABLE_MASK; 21789d485332SAxel Lin vreg->desc.enable_val = SPMI_COMMON_ENABLE; 2179e92a4047SStephen Boyd vreg->desc.name = name = reg->name; 2180e92a4047SStephen Boyd vreg->desc.supply_name = reg->supply; 2181e92a4047SStephen Boyd vreg->desc.of_match = reg->name; 2182e92a4047SStephen Boyd vreg->desc.of_parse_cb = spmi_regulator_of_parse; 2183e92a4047SStephen Boyd vreg->desc.of_map_mode = spmi_regulator_of_map_mode; 2184e92a4047SStephen Boyd 2185e92a4047SStephen Boyd ret = spmi_regulator_match(vreg, reg->force_type); 2186e92a4047SStephen Boyd if (ret) 21876ee5c044SStephen Boyd continue; 2188e92a4047SStephen Boyd 2189fffe7f52SNiklas Cassel if (saw_regmap) { 2190fffe7f52SNiklas Cassel reg_node = of_get_child_by_name(node, reg->name); 2191fffe7f52SNiklas Cassel reg_prop = of_find_property(reg_node, "qcom,saw-leader", 2192fffe7f52SNiklas Cassel &lenp); 2193fffe7f52SNiklas Cassel of_node_put(reg_node); 2194fffe7f52SNiklas Cassel if (reg_prop) { 21950caecaa8SIlia Lin spmi_saw_ops = *(vreg->desc.ops); 2196fffe7f52SNiklas Cassel spmi_saw_ops.set_voltage_sel = 21970caecaa8SIlia Lin spmi_regulator_saw_set_voltage; 21980caecaa8SIlia Lin vreg->desc.ops = &spmi_saw_ops; 21990caecaa8SIlia Lin } 2200fffe7f52SNiklas Cassel } 22010caecaa8SIlia Lin 2202b01d1823SJeffrey Hugo if (vreg->set_points && vreg->set_points->count == 1) { 220386f4ff7aSJorge Ramirez-Ortiz /* since there is only one range */ 220486f4ff7aSJorge Ramirez-Ortiz range = vreg->set_points->range; 220586f4ff7aSJorge Ramirez-Ortiz vreg->desc.uV_step = range->step_uV; 220686f4ff7aSJorge Ramirez-Ortiz } 220786f4ff7aSJorge Ramirez-Ortiz 2208e92a4047SStephen Boyd config.dev = dev; 2209e92a4047SStephen Boyd config.driver_data = vreg; 22109d485332SAxel Lin config.regmap = regmap; 2211e92a4047SStephen Boyd rdev = devm_regulator_register(dev, &vreg->desc, &config); 2212e92a4047SStephen Boyd if (IS_ERR(rdev)) { 2213e92a4047SStephen Boyd dev_err(dev, "failed to register %s\n", name); 2214b6688015SMatti Vaittinen return PTR_ERR(rdev); 2215e92a4047SStephen Boyd } 2216e92a4047SStephen Boyd 2217e92a4047SStephen Boyd INIT_LIST_HEAD(&vreg->node); 2218e92a4047SStephen Boyd list_add(&vreg->node, vreg_list); 2219e92a4047SStephen Boyd } 2220e92a4047SStephen Boyd 2221e92a4047SStephen Boyd return 0; 2222e92a4047SStephen Boyd } 2223e92a4047SStephen Boyd 2224e92a4047SStephen Boyd static struct platform_driver qcom_spmi_regulator_driver = { 2225e92a4047SStephen Boyd .driver = { 2226e92a4047SStephen Boyd .name = "qcom-spmi-regulator", 2227e92a4047SStephen Boyd .of_match_table = qcom_spmi_regulator_match, 2228e92a4047SStephen Boyd }, 2229e92a4047SStephen Boyd .probe = qcom_spmi_regulator_probe, 2230e92a4047SStephen Boyd }; 2231e92a4047SStephen Boyd module_platform_driver(qcom_spmi_regulator_driver); 2232e92a4047SStephen Boyd 2233e92a4047SStephen Boyd MODULE_DESCRIPTION("Qualcomm SPMI PMIC regulator driver"); 2234e92a4047SStephen Boyd MODULE_LICENSE("GPL v2"); 2235e92a4047SStephen Boyd MODULE_ALIAS("platform:qcom-spmi-regulator"); 2236