@@ -35,9 +35,6 @@ struct fixed_voltage_data {
3535 struct regulator_desc desc ;
3636 struct regulator_dev * dev ;
3737 int microvolts ;
38- int gpio ;
39- bool enable_high ;
40- bool is_enabled ;
4138};
4239
4340
@@ -108,33 +105,6 @@ of_get_fixed_voltage_config(struct device *dev)
108105 return config ;
109106}
110107
111- static int fixed_voltage_is_enabled (struct regulator_dev * dev )
112- {
113- struct fixed_voltage_data * data = rdev_get_drvdata (dev );
114-
115- return data -> is_enabled ;
116- }
117-
118- static int fixed_voltage_enable (struct regulator_dev * dev )
119- {
120- struct fixed_voltage_data * data = rdev_get_drvdata (dev );
121-
122- gpio_set_value_cansleep (data -> gpio , data -> enable_high );
123- data -> is_enabled = true;
124-
125- return 0 ;
126- }
127-
128- static int fixed_voltage_disable (struct regulator_dev * dev )
129- {
130- struct fixed_voltage_data * data = rdev_get_drvdata (dev );
131-
132- gpio_set_value_cansleep (data -> gpio , !data -> enable_high );
133- data -> is_enabled = false;
134-
135- return 0 ;
136- }
137-
138108static int fixed_voltage_get_voltage (struct regulator_dev * dev )
139109{
140110 struct fixed_voltage_data * data = rdev_get_drvdata (dev );
@@ -156,14 +126,6 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev,
156126 return data -> microvolts ;
157127}
158128
159- static struct regulator_ops fixed_voltage_gpio_ops = {
160- .is_enabled = fixed_voltage_is_enabled ,
161- .enable = fixed_voltage_enable ,
162- .disable = fixed_voltage_disable ,
163- .get_voltage = fixed_voltage_get_voltage ,
164- .list_voltage = fixed_voltage_list_voltage ,
165- };
166-
167129static struct regulator_ops fixed_voltage_ops = {
168130 .get_voltage = fixed_voltage_get_voltage ,
169131 .list_voltage = fixed_voltage_list_voltage ,
@@ -203,60 +165,33 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
203165 }
204166 drvdata -> desc .type = REGULATOR_VOLTAGE ;
205167 drvdata -> desc .owner = THIS_MODULE ;
168+ drvdata -> desc .ops = & fixed_voltage_ops ;
206169
207170 drvdata -> desc .enable_time = config -> startup_delay ;
208171
209172 if (config -> microvolts )
210173 drvdata -> desc .n_voltages = 1 ;
211174
212175 drvdata -> microvolts = config -> microvolts ;
213- drvdata -> gpio = config -> gpio ;
214-
215- if (gpio_is_valid (config -> gpio )) {
216- int gpio_flag ;
217- drvdata -> enable_high = config -> enable_high ;
218-
219- /* FIXME: Remove below print warning
220- *
221- * config->gpio must be set to -EINVAL by platform code if
222- * GPIO control is not required. However, early adopters
223- * not requiring GPIO control may forget to initialize
224- * config->gpio to -EINVAL. This will cause GPIO 0 to be used
225- * for GPIO control.
226- *
227- * This warning will be removed once there are a couple of users
228- * for this driver.
229- */
230- if (!config -> gpio )
231- dev_warn (& pdev -> dev ,
232- "using GPIO 0 for regulator enable control\n" );
233-
234- /*
235- * set output direction without changing state
236- * to prevent glitch
237- */
238- drvdata -> is_enabled = config -> enabled_at_boot ;
239- ret = drvdata -> is_enabled ?
240- config -> enable_high : !config -> enable_high ;
241- gpio_flag = ret ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW ;
242-
243- if (config -> gpio_is_open_drain )
244- gpio_flag |= GPIOF_OPEN_DRAIN ;
245-
246- ret = gpio_request_one (config -> gpio , gpio_flag ,
247- config -> supply_name );
248- if (ret ) {
249- dev_err (& pdev -> dev ,
250- "Could not obtain regulator enable GPIO %d: %d\n" ,
251- config -> gpio , ret );
252- goto err_name ;
253- }
254-
255- drvdata -> desc .ops = & fixed_voltage_gpio_ops ;
256176
177+ if (config -> gpio >= 0 )
178+ cfg .ena_gpio = config -> gpio ;
179+ cfg .ena_gpio_invert = !config -> enable_high ;
180+ if (config -> enabled_at_boot ) {
181+ if (config -> enable_high ) {
182+ cfg .ena_gpio_flags |= GPIOF_OUT_INIT_HIGH ;
183+ } else {
184+ cfg .ena_gpio_flags |= GPIOF_OUT_INIT_LOW ;
185+ }
257186 } else {
258- drvdata -> desc .ops = & fixed_voltage_ops ;
187+ if (config -> enable_high ) {
188+ cfg .ena_gpio_flags |= GPIOF_OUT_INIT_LOW ;
189+ } else {
190+ cfg .ena_gpio_flags |= GPIOF_OUT_INIT_HIGH ;
191+ }
259192 }
193+ if (config -> gpio_is_open_drain )
194+ cfg .ena_gpio_flags |= GPIOF_OPEN_DRAIN ;
260195
261196 cfg .dev = & pdev -> dev ;
262197 cfg .init_data = config -> init_data ;
@@ -267,7 +202,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
267202 if (IS_ERR (drvdata -> dev )) {
268203 ret = PTR_ERR (drvdata -> dev );
269204 dev_err (& pdev -> dev , "Failed to register regulator: %d\n" , ret );
270- goto err_gpio ;
205+ goto err_name ;
271206 }
272207
273208 platform_set_drvdata (pdev , drvdata );
@@ -277,9 +212,6 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev)
277212
278213 return 0 ;
279214
280- err_gpio :
281- if (gpio_is_valid (config -> gpio ))
282- gpio_free (config -> gpio );
283215err_name :
284216 kfree (drvdata -> desc .name );
285217err :
@@ -291,8 +223,6 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev)
291223 struct fixed_voltage_data * drvdata = platform_get_drvdata (pdev );
292224
293225 regulator_unregister (drvdata -> dev );
294- if (gpio_is_valid (drvdata -> gpio ))
295- gpio_free (drvdata -> gpio );
296226 kfree (drvdata -> desc .name );
297227
298228 return 0 ;
0 commit comments