diff options
Diffstat (limited to 'drivers/regulator/fixed.c')
| -rw-r--r-- | drivers/regulator/fixed.c | 97 | 
1 files changed, 23 insertions, 74 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 7610920014d..354105eff1f 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c @@ -34,7 +34,6 @@  struct fixed_voltage_data {  	struct regulator_desc desc;  	struct regulator_dev *dev; -	int microvolts;  }; @@ -51,7 +50,6 @@ of_get_fixed_voltage_config(struct device *dev)  {  	struct fixed_voltage_config *config;  	struct device_node *np = dev->of_node; -	const __be32 *delay;  	struct regulator_init_data *init_data;  	config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config), @@ -92,15 +90,11 @@ of_get_fixed_voltage_config(struct device *dev)  	if ((config->gpio == -ENODEV) || (config->gpio == -EPROBE_DEFER))  		return ERR_PTR(-EPROBE_DEFER); -	delay = of_get_property(np, "startup-delay-us", NULL); -	if (delay) -		config->startup_delay = be32_to_cpu(*delay); +	of_property_read_u32(np, "startup-delay-us", &config->startup_delay); -	if (of_find_property(np, "enable-active-high", NULL)) -		config->enable_high = true; - -	if (of_find_property(np, "gpio-open-drain", NULL)) -		config->gpio_is_open_drain = true; +	config->enable_high = of_property_read_bool(np, "enable-active-high"); +	config->gpio_is_open_drain = of_property_read_bool(np, +							   "gpio-open-drain");  	if (of_find_property(np, "vin-supply", NULL))  		config->input_supply = "vin"; @@ -108,30 +102,7 @@ of_get_fixed_voltage_config(struct device *dev)  	return config;  } -static int fixed_voltage_get_voltage(struct regulator_dev *dev) -{ -	struct fixed_voltage_data *data = rdev_get_drvdata(dev); - -	if (data->microvolts) -		return data->microvolts; -	else -		return -EINVAL; -} - -static int fixed_voltage_list_voltage(struct regulator_dev *dev, -				      unsigned selector) -{ -	struct fixed_voltage_data *data = rdev_get_drvdata(dev); - -	if (selector != 0) -		return -EINVAL; - -	return data->microvolts; -} -  static struct regulator_ops fixed_voltage_ops = { -	.get_voltage = fixed_voltage_get_voltage, -	.list_voltage = fixed_voltage_list_voltage,  };  static int reg_fixed_voltage_probe(struct platform_device *pdev) @@ -154,17 +125,15 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)  	drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data),  			       GFP_KERNEL); -	if (drvdata == NULL) { -		dev_err(&pdev->dev, "Failed to allocate device data\n"); -		ret = -ENOMEM; -		goto err; -	} +	if (!drvdata) +		return -ENOMEM; -	drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); +	drvdata->desc.name = devm_kstrdup(&pdev->dev, +					  config->supply_name, +					  GFP_KERNEL);  	if (drvdata->desc.name == NULL) {  		dev_err(&pdev->dev, "Failed to allocate supply name\n"); -		ret = -ENOMEM; -		goto err; +		return -ENOMEM;  	}  	drvdata->desc.type = REGULATOR_VOLTAGE;  	drvdata->desc.owner = THIS_MODULE; @@ -173,36 +142,34 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)  	drvdata->desc.enable_time = config->startup_delay;  	if (config->input_supply) { -		drvdata->desc.supply_name = kstrdup(config->input_supply, -							GFP_KERNEL); +		drvdata->desc.supply_name = devm_kstrdup(&pdev->dev, +					    config->input_supply, +					    GFP_KERNEL);  		if (!drvdata->desc.supply_name) {  			dev_err(&pdev->dev,  				"Failed to allocate input supply\n"); -			ret = -ENOMEM; -			goto err_name; +			return -ENOMEM;  		}  	}  	if (config->microvolts)  		drvdata->desc.n_voltages = 1; -	drvdata->microvolts = config->microvolts; +	drvdata->desc.fixed_uV = config->microvolts;  	if (config->gpio >= 0)  		cfg.ena_gpio = config->gpio;  	cfg.ena_gpio_invert = !config->enable_high;  	if (config->enabled_at_boot) { -		if (config->enable_high) { +		if (config->enable_high)  			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; -		} else { +		else  			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; -		}  	} else { -		if (config->enable_high) { +		if (config->enable_high)  			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_LOW; -		} else { +		else  			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; -		}  	}  	if (config->gpio_is_open_drain)  		cfg.ena_gpio_flags |= GPIOF_OPEN_DRAIN; @@ -212,35 +179,18 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)  	cfg.driver_data = drvdata;  	cfg.of_node = pdev->dev.of_node; -	drvdata->dev = regulator_register(&drvdata->desc, &cfg); +	drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc, +					       &cfg);  	if (IS_ERR(drvdata->dev)) {  		ret = PTR_ERR(drvdata->dev);  		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); -		goto err_input; +		return ret;  	}  	platform_set_drvdata(pdev, drvdata);  	dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, -		drvdata->microvolts); - -	return 0; - -err_input: -	kfree(drvdata->desc.supply_name); -err_name: -	kfree(drvdata->desc.name); -err: -	return ret; -} - -static int reg_fixed_voltage_remove(struct platform_device *pdev) -{ -	struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); - -	regulator_unregister(drvdata->dev); -	kfree(drvdata->desc.supply_name); -	kfree(drvdata->desc.name); +		drvdata->desc.fixed_uV);  	return 0;  } @@ -255,7 +205,6 @@ MODULE_DEVICE_TABLE(of, fixed_of_match);  static struct platform_driver regulator_fixed_voltage_driver = {  	.probe		= reg_fixed_voltage_probe, -	.remove		= reg_fixed_voltage_remove,  	.driver		= {  		.name		= "reg-fixed-voltage",  		.owner		= THIS_MODULE,  | 
