// SPDX-License-Identifier: GPL-2.0-or-later /* * max8952.c - Voltage and current regulation for the Maxim 8952 * * Copyright (C) 2010 Samsung Electronics * MyungJoo Ham <myungjoo.ham@samsung.com>
*/
staticstruct max8952_platform_data *max8952_parse_dt(struct device *dev)
{ struct max8952_platform_data *pd; struct device_node *np = dev->of_node; int ret; int i;
pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); if (!pd) return NULL;
if (of_property_read_u32(np, "max8952,default-mode", &pd->default_mode))
dev_warn(dev, "Default mode not specified, assuming 0\n");
ret = of_property_read_u32_array(np, "max8952,dvs-mode-microvolt",
pd->dvs_mode, ARRAY_SIZE(pd->dvs_mode)); if (ret) {
dev_err(dev, "max8952,dvs-mode-microvolt property not specified"); return NULL;
}
for (i = 0; i < ARRAY_SIZE(pd->dvs_mode); ++i) { if (pd->dvs_mode[i] < 770000 || pd->dvs_mode[i] > 1400000) {
dev_err(dev, "DVS voltage %d out of range\n", i); return NULL;
}
pd->dvs_mode[i] = (pd->dvs_mode[i] - 770000) / 10000;
}
if (of_property_read_u32(np, "max8952,sync-freq", &pd->sync_freq))
dev_warn(dev, "max8952,sync-freq property not specified, defaulting to 26MHz\n");
if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed))
dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n");
pd->reg_data = of_get_regulator_init_data(dev, np, ®ulator); if (!pd->reg_data) {
dev_err(dev, "Failed to parse regulator init data\n"); return NULL;
}
if (pdata->reg_data->constraints.boot_on)
gflags = GPIOD_OUT_HIGH; else
gflags = GPIOD_OUT_LOW;
gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE; /* * Do not use devm* here: the regulator core takes over the * lifecycle management of the GPIO descriptor.
*/
gpiod = gpiod_get_optional(&client->dev, "max8952,en",
gflags); if (IS_ERR(gpiod)) return PTR_ERR(gpiod); if (gpiod)
config.ena_gpiod = gpiod;
rdev = devm_regulator_register(&client->dev, ®ulator, &config); if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
dev_err(&client->dev, "regulator init failed (%d)\n", ret); return ret;
}
/* Fetch vid0 and vid1 GPIOs if available */
gflags = max8952->vid0 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
max8952->vid0_gpiod = devm_gpiod_get_index_optional(&client->dev, "max8952,vid",
0, gflags); if (IS_ERR(max8952->vid0_gpiod)) return PTR_ERR(max8952->vid0_gpiod);
gflags = max8952->vid1 ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
max8952->vid1_gpiod = devm_gpiod_get_index_optional(&client->dev, "max8952,vid",
1, gflags); if (IS_ERR(max8952->vid1_gpiod)) return PTR_ERR(max8952->vid1_gpiod);
/* If either VID GPIO is missing just disable this */ if (!max8952->vid0_gpiod || !max8952->vid1_gpiod) {
dev_warn(&client->dev, "VID0/1 gpio invalid: " "DVS not available.\n");
max8952->vid0 = 0;
max8952->vid1 = 0; /* Make sure if we have any descriptors they get set to low */ if (max8952->vid0_gpiod)
gpiod_set_value(max8952->vid0_gpiod, 0); if (max8952->vid1_gpiod)
gpiod_set_value(max8952->vid1_gpiod, 0);
/* Disable Pulldown of EN only */
max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60);
dev_err(&client->dev, "DVS modes disabled because VID0 and VID1" " do not have proper controls.\n");
} else { /* * Disable Pulldown on EN, VID0, VID1 to reduce * leakage current of MAX8952 assuming that MAX8952 * is turned on (EN==1). Note that without having VID0/1 * properly connected, turning pulldown off can be * problematic. Thus, turn this off only when they are * controllable by GPIO.
*/
max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.