Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: max8952: Add Device Tree support

This patch adds Device Tree support to max8952 regulator driver.

Signed-off-by: Tomasz Figa <t.figa@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Tomasz Figa and committed by
Mark Brown
3ff4aa95 3ec6eb9c

+126 -4
+52
Documentation/devicetree/bindings/regulator/max8952.txt
··· 1 + Maxim MAX8952 voltage regulator 2 + 3 + Required properties: 4 + - compatible: must be equal to "maxim,max8952" 5 + - reg: I2C slave address, usually 0x60 6 + - max8952,dvs-mode-microvolt: array of 4 integer values defining DVS voltages 7 + in microvolts. All values must be from range <770000, 1400000> 8 + - any required generic properties defined in regulator.txt 9 + 10 + Optional properties: 11 + - max8952,vid-gpios: array of two GPIO pins used for DVS voltage selection 12 + - max8952,en-gpio: GPIO used to control enable status of regulator 13 + - max8952,default-mode: index of default DVS voltage, from <0, 3> range 14 + - max8952,sync-freq: sync frequency, must be one of following values: 15 + - 0: 26 MHz 16 + - 1: 13 MHz 17 + - 2: 19.2 MHz 18 + Defaults to 26 MHz if not specified. 19 + - max8952,ramp-speed: voltage ramp speed, must be one of following values: 20 + - 0: 32mV/us 21 + - 1: 16mV/us 22 + - 2: 8mV/us 23 + - 3: 4mV/us 24 + - 4: 2mV/us 25 + - 5: 1mV/us 26 + - 6: 0.5mV/us 27 + - 7: 0.25mV/us 28 + Defaults to 32mV/us if not specified. 29 + - any available generic properties defined in regulator.txt 30 + 31 + Example: 32 + 33 + vdd_arm_reg: pmic@60 { 34 + compatible = "maxim,max8952"; 35 + reg = <0x60>; 36 + 37 + /* max8952-specific properties */ 38 + max8952,vid-gpios = <&gpx0 3 0>, <&gpx0 4 0>; 39 + max8952,en-gpio = <&gpx0 1 0>; 40 + max8952,default-mode = <0>; 41 + max8952,dvs-mode-microvolt = <1250000>, <1200000>, 42 + <1050000>, <950000>; 43 + max8952,sync-freq = <0>; 44 + max8952,ramp-speed = <0>; 45 + 46 + /* generic regulator properties */ 47 + regulator-name = "vdd_arm"; 48 + regulator-min-microvolt = <770000>; 49 + regulator-max-microvolt = <1400000>; 50 + regulator-always-on; 51 + regulator-boot-on; 52 + };
+70
drivers/regulator/max8952.c
··· 28 28 #include <linux/regulator/max8952.h> 29 29 #include <linux/gpio.h> 30 30 #include <linux/io.h> 31 + #include <linux/of.h> 32 + #include <linux/of_gpio.h> 33 + #include <linux/regulator/of_regulator.h> 31 34 #include <linux/slab.h> 32 35 33 36 /* Registers */ ··· 129 126 .owner = THIS_MODULE, 130 127 }; 131 128 129 + #ifdef CONFIG_OF 130 + static struct of_device_id max8952_dt_match[] = { 131 + { .compatible = "maxim,max8952" }, 132 + {}, 133 + }; 134 + MODULE_DEVICE_TABLE(of, max8952_dt_match); 135 + 136 + static struct max8952_platform_data *max8952_parse_dt(struct device *dev) 137 + { 138 + struct max8952_platform_data *pd; 139 + struct device_node *np = dev->of_node; 140 + int ret; 141 + int i; 142 + 143 + pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); 144 + if (!pd) { 145 + dev_err(dev, "Failed to allocate platform data\n"); 146 + return NULL; 147 + } 148 + 149 + pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0); 150 + pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1); 151 + pd->gpio_en = of_get_named_gpio(np, "max8952,en-gpio", 0); 152 + 153 + if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode)) 154 + dev_warn(dev, "Default mode not specified, assuming 0\n"); 155 + 156 + ret = of_property_read_u32_array(np, "max8952,dvs-mode-microvolt", 157 + pd->dvs_mode, ARRAY_SIZE(pd->dvs_mode)); 158 + if (ret) { 159 + dev_err(dev, "max8952,dvs-mode-microvolt property not specified"); 160 + return NULL; 161 + } 162 + 163 + for (i = 0; i < ARRAY_SIZE(pd->dvs_mode); ++i) { 164 + if (pd->dvs_mode[i] < 770000 || pd->dvs_mode[i] > 1400000) { 165 + dev_err(dev, "DVS voltage %d out of range\n", i); 166 + return NULL; 167 + } 168 + pd->dvs_mode[i] = (pd->dvs_mode[i] - 770000) / 10000; 169 + } 170 + 171 + if (of_property_read_u32(np, "max8952,sync-freq", &pd->sync_freq)) 172 + dev_warn(dev, "max8952,sync-freq property not specified, defaulting to 26MHz\n"); 173 + 174 + if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed)) 175 + dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n"); 176 + 177 + pd->reg_data = of_get_regulator_init_data(dev, np); 178 + if (!pd->reg_data) { 179 + dev_err(dev, "Failed to parse regulator init data\n"); 180 + return NULL; 181 + } 182 + 183 + return pd; 184 + } 185 + #else 186 + static struct max8952_platform_data *max8952_parse_dt(struct device *dev) 187 + { 188 + return NULL; 189 + } 190 + #endif 191 + 132 192 static int max8952_pmic_probe(struct i2c_client *client, 133 193 const struct i2c_device_id *i2c_id) 134 194 { ··· 201 135 struct max8952_data *max8952; 202 136 203 137 int ret = 0, err = 0; 138 + 139 + if (client->dev.of_node) 140 + pdata = max8952_parse_dt(&client->dev); 204 141 205 142 if (!pdata) { 206 143 dev_err(&client->dev, "Require the platform data\n"); ··· 340 271 .remove = max8952_pmic_remove, 341 272 .driver = { 342 273 .name = "max8952", 274 + .of_match_table = of_match_ptr(max8952_dt_match), 343 275 }, 344 276 .id_table = max8952_ids, 345 277 };
+4 -4
include/linux/regulator/max8952.h
··· 122 122 int gpio_vid1; 123 123 int gpio_en; 124 124 125 - u8 default_mode; 126 - u8 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */ 125 + u32 default_mode; 126 + u32 dvs_mode[MAX8952_NUM_DVS_MODE]; /* MAX8952_DVS_MODEx_XXXXmV */ 127 127 128 - u8 sync_freq; 129 - u8 ramp_speed; 128 + u32 sync_freq; 129 + u32 ramp_speed; 130 130 131 131 struct regulator_init_data *reg_data; 132 132 };