--- zzzz-none-000/linux-3.10.107/drivers/regulator/max8952.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/regulator/max8952.c 2021-02-04 17:41:59.000000000 +0000 @@ -48,9 +48,7 @@ struct max8952_data { struct i2c_client *client; - struct device *dev; struct max8952_platform_data *pdata; - struct regulator_dev *rdev; bool vid0; bool vid1; @@ -59,6 +57,7 @@ static int max8952_read_reg(struct max8952_data *max8952, u8 reg) { int ret = i2c_smbus_read_byte_data(max8952->client, reg); + if (ret > 0) ret &= 0xff; @@ -130,7 +129,7 @@ }; #ifdef CONFIG_OF -static struct of_device_id max8952_dt_match[] = { +static const struct of_device_id max8952_dt_match[] = { { .compatible = "maxim,max8952" }, {}, }; @@ -144,10 +143,8 @@ int i; pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); - if (!pd) { - dev_err(dev, "Failed to allocate platform data\n"); + if (!pd) return NULL; - } pd->gpio_vid0 = of_get_named_gpio(np, "max8952,vid-gpios", 0); pd->gpio_vid1 = of_get_named_gpio(np, "max8952,vid-gpios", 1); @@ -177,7 +174,7 @@ 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); + 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; @@ -196,9 +193,10 @@ const struct i2c_device_id *i2c_id) { struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); - struct max8952_platform_data *pdata = client->dev.platform_data; + struct max8952_platform_data *pdata = dev_get_platdata(&client->dev); struct regulator_config config = { }; struct max8952_data *max8952; + struct regulator_dev *rdev; int ret = 0, err = 0; @@ -219,23 +217,23 @@ return -ENOMEM; max8952->client = client; - max8952->dev = &client->dev; max8952->pdata = pdata; - config.dev = max8952->dev; + config.dev = &client->dev; config.init_data = pdata->reg_data; config.driver_data = max8952; config.of_node = client->dev.of_node; config.ena_gpio = pdata->gpio_en; + if (client->dev.of_node) + config.ena_gpio_initialized = true; if (pdata->reg_data->constraints.boot_on) config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; - max8952->rdev = regulator_register(®ulator, &config); - - if (IS_ERR(max8952->rdev)) { - ret = PTR_ERR(max8952->rdev); - dev_err(max8952->dev, "regulator init failed (%d)\n", ret); + 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; } @@ -244,26 +242,24 @@ if (gpio_is_valid(pdata->gpio_vid0) && gpio_is_valid(pdata->gpio_vid1)) { - if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0")) - gpio_direction_output(pdata->gpio_vid0, - (pdata->default_mode) & 0x1); - else + unsigned long gpio_flags; + + gpio_flags = max8952->vid0 ? + GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; + if (devm_gpio_request_one(&client->dev, pdata->gpio_vid0, + gpio_flags, "MAX8952 VID0")) err = 1; - if (!gpio_request(pdata->gpio_vid1, "MAX8952 VID1")) - gpio_direction_output(pdata->gpio_vid1, - (pdata->default_mode >> 1) & 0x1); - else { - if (!err) - gpio_free(pdata->gpio_vid0); + gpio_flags = max8952->vid1 ? + GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; + if (devm_gpio_request_one(&client->dev, pdata->gpio_vid1, + gpio_flags, "MAX8952 VID1")) err = 2; - } - } else err = 3; if (err) { - dev_warn(max8952->dev, "VID0/1 gpio invalid: " + dev_warn(&client->dev, "VID0/1 gpio invalid: " "DVS not available.\n"); max8952->vid0 = 0; max8952->vid1 = 0; @@ -274,7 +270,7 @@ /* Disable Pulldown of EN only */ max8952_write_reg(max8952, MAX8952_REG_CONTROL, 0x60); - dev_err(max8952->dev, "DVS modes disabled because VID0 and VID1" + dev_err(&client->dev, "DVS modes disabled because VID0 and VID1" " do not have proper controls.\n"); } else { /* @@ -317,19 +313,6 @@ return 0; } -static int max8952_pmic_remove(struct i2c_client *client) -{ - struct max8952_data *max8952 = i2c_get_clientdata(client); - struct max8952_platform_data *pdata = max8952->pdata; - struct regulator_dev *rdev = max8952->rdev; - - regulator_unregister(rdev); - - gpio_free(pdata->gpio_vid0); - gpio_free(pdata->gpio_vid1); - return 0; -} - static const struct i2c_device_id max8952_ids[] = { { "max8952", 0 }, { }, @@ -338,7 +321,6 @@ static struct i2c_driver max8952_pmic_driver = { .probe = max8952_pmic_probe, - .remove = max8952_pmic_remove, .driver = { .name = "max8952", .of_match_table = of_match_ptr(max8952_dt_match),