diff options
| -rw-r--r-- | drivers/regulator/fixed.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 988a7472c2ab..a43b0e8a438d 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c | |||
| @@ -30,6 +30,9 @@ | |||
| 30 | #include <linux/of_gpio.h> | 30 | #include <linux/of_gpio.h> |
| 31 | #include <linux/regulator/of_regulator.h> | 31 | #include <linux/regulator/of_regulator.h> |
| 32 | #include <linux/regulator/machine.h> | 32 | #include <linux/regulator/machine.h> |
| 33 | #include <linux/acpi.h> | ||
| 34 | #include <linux/property.h> | ||
| 35 | #include <linux/gpio/consumer.h> | ||
| 33 | 36 | ||
| 34 | struct fixed_voltage_data { | 37 | struct fixed_voltage_data { |
| 35 | struct regulator_desc desc; | 38 | struct regulator_desc desc; |
| @@ -94,6 +97,44 @@ of_get_fixed_voltage_config(struct device *dev, | |||
| 94 | return config; | 97 | return config; |
| 95 | } | 98 | } |
| 96 | 99 | ||
| 100 | /** | ||
| 101 | * acpi_get_fixed_voltage_config - extract fixed_voltage_config structure info | ||
| 102 | * @dev: device requesting for fixed_voltage_config | ||
| 103 | * @desc: regulator description | ||
| 104 | * | ||
| 105 | * Populates fixed_voltage_config structure by extracting data through ACPI | ||
| 106 | * interface, returns a pointer to the populated structure of NULL if memory | ||
| 107 | * alloc fails. | ||
| 108 | */ | ||
| 109 | static struct fixed_voltage_config * | ||
| 110 | acpi_get_fixed_voltage_config(struct device *dev, | ||
| 111 | const struct regulator_desc *desc) | ||
| 112 | { | ||
| 113 | struct fixed_voltage_config *config; | ||
| 114 | const char *supply_name; | ||
| 115 | struct gpio_desc *gpiod; | ||
| 116 | int ret; | ||
| 117 | |||
| 118 | config = devm_kzalloc(dev, sizeof(*config), GFP_KERNEL); | ||
| 119 | if (!config) | ||
| 120 | return ERR_PTR(-ENOMEM); | ||
| 121 | |||
| 122 | ret = device_property_read_string(dev, "supply-name", &supply_name); | ||
| 123 | if (!ret) | ||
| 124 | config->supply_name = supply_name; | ||
| 125 | |||
| 126 | gpiod = gpiod_get(dev, "gpio", GPIOD_ASIS); | ||
| 127 | if (IS_ERR(gpiod)) | ||
| 128 | return ERR_PTR(-ENODEV); | ||
| 129 | |||
| 130 | config->gpio = desc_to_gpio(gpiod); | ||
| 131 | config->enable_high = device_property_read_bool(dev, | ||
| 132 | "enable-active-high"); | ||
| 133 | gpiod_put(gpiod); | ||
| 134 | |||
| 135 | return config; | ||
| 136 | } | ||
| 137 | |||
| 97 | static struct regulator_ops fixed_voltage_ops = { | 138 | static struct regulator_ops fixed_voltage_ops = { |
| 98 | }; | 139 | }; |
| 99 | 140 | ||
| @@ -114,6 +155,11 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev) | |||
| 114 | &drvdata->desc); | 155 | &drvdata->desc); |
| 115 | if (IS_ERR(config)) | 156 | if (IS_ERR(config)) |
| 116 | return PTR_ERR(config); | 157 | return PTR_ERR(config); |
| 158 | } else if (ACPI_HANDLE(&pdev->dev)) { | ||
| 159 | config = acpi_get_fixed_voltage_config(&pdev->dev, | ||
| 160 | &drvdata->desc); | ||
| 161 | if (IS_ERR(config)) | ||
| 162 | return PTR_ERR(config); | ||
| 117 | } else { | 163 | } else { |
| 118 | config = dev_get_platdata(&pdev->dev); | 164 | config = dev_get_platdata(&pdev->dev); |
| 119 | } | 165 | } |
