Lines Matching +full:dvs +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max8952.c - Voltage and current regulation for the Maxim 8952
16 #include <linux/gpio/consumer.h>
46 int ret = i2c_smbus_read_byte_data(max8952->client, reg); in max8952_read_reg()
57 return i2c_smbus_write_byte_data(max8952->client, reg, value); in max8952_write_reg()
66 return -EINVAL; in max8952_list_voltage()
68 return (max8952->pdata->dvs_mode[selector] * 10 + 770) * 1000; in max8952_list_voltage()
76 if (max8952->vid0) in max8952_get_voltage_sel()
78 if (max8952->vid1) in max8952_get_voltage_sel()
89 if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) { in max8952_set_voltage_sel()
90 /* DVS not supported */ in max8952_set_voltage_sel()
91 return -EPERM; in max8952_set_voltage_sel()
94 max8952->vid0 = selector & 0x1; in max8952_set_voltage_sel()
95 max8952->vid1 = (selector >> 1) & 0x1; in max8952_set_voltage_sel()
96 gpiod_set_value(max8952->vid0_gpiod, max8952->vid0); in max8952_set_voltage_sel()
97 gpiod_set_value(max8952->vid1_gpiod, max8952->vid1); in max8952_set_voltage_sel()
127 struct device_node *np = dev->of_node; in max8952_parse_dt()
135 if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode)) in max8952_parse_dt()
138 ret = of_property_read_u32_array(np, "max8952,dvs-mode-microvolt", in max8952_parse_dt()
139 pd->dvs_mode, ARRAY_SIZE(pd->dvs_mode)); in max8952_parse_dt()
141 dev_err(dev, "max8952,dvs-mode-microvolt property not specified"); in max8952_parse_dt()
145 for (i = 0; i < ARRAY_SIZE(pd->dvs_mode); ++i) { in max8952_parse_dt()
146 if (pd->dvs_mode[i] < 770000 || pd->dvs_mode[i] > 1400000) { in max8952_parse_dt()
147 dev_err(dev, "DVS voltage %d out of range\n", i); in max8952_parse_dt()
150 pd->dvs_mode[i] = (pd->dvs_mode[i] - 770000) / 10000; in max8952_parse_dt()
153 if (of_property_read_u32(np, "max8952,sync-freq", &pd->sync_freq)) in max8952_parse_dt()
154 dev_warn(dev, "max8952,sync-freq property not specified, defaulting to 26MHz\n"); in max8952_parse_dt()
156 if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed)) in max8952_parse_dt()
157 dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n"); in max8952_parse_dt()
159 pd->reg_data = of_get_regulator_init_data(dev, np, ®ulator); in max8952_parse_dt()
160 if (!pd->reg_data) { in max8952_parse_dt()
176 struct i2c_adapter *adapter = client->adapter; in max8952_pmic_probe()
177 struct max8952_platform_data *pdata = dev_get_platdata(&client->dev); in max8952_pmic_probe()
186 if (client->dev.of_node) in max8952_pmic_probe()
187 pdata = max8952_parse_dt(&client->dev); in max8952_pmic_probe()
190 dev_err(&client->dev, "Require the platform data\n"); in max8952_pmic_probe()
191 return -EINVAL; in max8952_pmic_probe()
195 return -EIO; in max8952_pmic_probe()
197 max8952 = devm_kzalloc(&client->dev, sizeof(struct max8952_data), in max8952_pmic_probe()
200 return -ENOMEM; in max8952_pmic_probe()
202 max8952->client = client; in max8952_pmic_probe()
203 max8952->pdata = pdata; in max8952_pmic_probe()
205 config.dev = &client->dev; in max8952_pmic_probe()
206 config.init_data = pdata->reg_data; in max8952_pmic_probe()
208 config.of_node = client->dev.of_node; in max8952_pmic_probe()
210 if (pdata->reg_data->constraints.boot_on) in max8952_pmic_probe()
217 * lifecycle management of the GPIO descriptor. in max8952_pmic_probe()
219 gpiod = gpiod_get_optional(&client->dev, in max8952_pmic_probe()
227 rdev = devm_regulator_register(&client->dev, ®ulator, &config); in max8952_pmic_probe()
230 dev_err(&client->dev, "regulator init failed (%d)\n", ret); in max8952_pmic_probe()
234 max8952->vid0 = pdata->default_mode & 0x1; in max8952_pmic_probe()
235 max8952->vid1 = (pdata->default_mode >> 1) & 0x1; in max8952_pmic_probe()
238 gflags = max8952->vid0 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; in max8952_pmic_probe()
239 max8952->vid0_gpiod = devm_gpiod_get_index_optional(&client->dev, in max8952_pmic_probe()
242 if (IS_ERR(max8952->vid0_gpiod)) in max8952_pmic_probe()
243 return PTR_ERR(max8952->vid0_gpiod); in max8952_pmic_probe()
244 gflags = max8952->vid1 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; in max8952_pmic_probe()
245 max8952->vid1_gpiod = devm_gpiod_get_index_optional(&client->dev, in max8952_pmic_probe()
248 if (IS_ERR(max8952->vid1_gpiod)) in max8952_pmic_probe()
249 return PTR_ERR(max8952->vid1_gpiod); in max8952_pmic_probe()
251 /* If either VID GPIO is missing just disable this */ in max8952_pmic_probe()
252 if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) { in max8952_pmic_probe()
253 dev_warn(&client->dev, "VID0/1 gpio invalid: " in max8952_pmic_probe()
254 "DVS not available.\n"); in max8952_pmic_probe()
255 max8952->vid0 = 0; in max8952_pmic_probe()
256 max8952->vid1 = 0; in max8952_pmic_probe()
258 if (max8952->vid0_gpiod) in max8952_pmic_probe()
259 gpiod_set_value(max8952->vid0_gpiod, 0); in max8952_pmic_probe()
260 if (max8952->vid1_gpiod) in max8952_pmic_probe()
261 gpiod_set_value(max8952->vid1_gpiod, 0); in max8952_pmic_probe()
266 dev_err(&client->dev, "DVS modes disabled because VID0 and VID1" in max8952_pmic_probe()
275 * controllable by GPIO. in max8952_pmic_probe()
283 (pdata->dvs_mode[0] & 0x3F)); in max8952_pmic_probe()
287 (pdata->dvs_mode[1] & 0x3F)); in max8952_pmic_probe()
291 (pdata->dvs_mode[2] & 0x3F)); in max8952_pmic_probe()
295 (pdata->dvs_mode[3] & 0x3F)); in max8952_pmic_probe()
299 ((pdata->sync_freq & 0x3) << 6)); in max8952_pmic_probe()
302 ((pdata->ramp_speed & 0x7) << 5)); in max8952_pmic_probe()