aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/panel/panel-simple.c
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2014-03-01 00:00:58 -0500
committerThierry Reding <treding@nvidia.com>2014-04-04 03:06:38 -0400
commitcfdf0549f85f9a48e74bf8f6e36572ccdb75d274 (patch)
tree08715b7b52ca0ccc18600c169da69da4c85ded6a /drivers/gpu/drm/panel/panel-simple.c
parentec7c565383ee7fd4847705b8aafefb8e589aea93 (diff)
drm/panel: use gpiod interface for enable GPIO
Use the new GPIO descriptor interface to handle the panel's enable GPIO. This considerably simplifies the code. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> [treding@nvidia.com: rework to improve readability] Signed-off-by: Thierry Reding <treding@nvidia.com>
Diffstat (limited to 'drivers/gpu/drm/panel/panel-simple.c')
-rw-r--r--drivers/gpu/drm/panel/panel-simple.c67
1 files changed, 18 insertions, 49 deletions
diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index 0231945c2934..87cc238c8a85 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -22,9 +22,8 @@
22 */ 22 */
23 23
24#include <linux/backlight.h> 24#include <linux/backlight.h>
25#include <linux/gpio.h> 25#include <linux/gpio/consumer.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/of_gpio.h>
28#include <linux/of_platform.h> 27#include <linux/of_platform.h>
29#include <linux/platform_device.h> 28#include <linux/platform_device.h>
30#include <linux/regulator/consumer.h> 29#include <linux/regulator/consumer.h>
@@ -44,9 +43,6 @@ struct panel_desc {
44 } size; 43 } size;
45}; 44};
46 45
47/* TODO: convert to gpiod_*() API once it's been merged */
48#define GPIO_ACTIVE_LOW (1 << 0)
49
50struct panel_simple { 46struct panel_simple {
51 struct drm_panel base; 47 struct drm_panel base;
52 bool enabled; 48 bool enabled;
@@ -57,8 +53,7 @@ struct panel_simple {
57 struct regulator *supply; 53 struct regulator *supply;
58 struct i2c_adapter *ddc; 54 struct i2c_adapter *ddc;
59 55
60 unsigned long enable_gpio_flags; 56 struct gpio_desc *enable_gpio;
61 int enable_gpio;
62}; 57};
63 58
64static inline struct panel_simple *to_panel_simple(struct drm_panel *panel) 59static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
@@ -110,12 +105,8 @@ static int panel_simple_disable(struct drm_panel *panel)
110 backlight_update_status(p->backlight); 105 backlight_update_status(p->backlight);
111 } 106 }
112 107
113 if (gpio_is_valid(p->enable_gpio)) { 108 if (p->enable_gpio)
114 if (p->enable_gpio_flags & GPIO_ACTIVE_LOW) 109 gpiod_set_value(p->enable_gpio, 0);
115 gpio_set_value(p->enable_gpio, 1);
116 else
117 gpio_set_value(p->enable_gpio, 0);
118 }
119 110
120 regulator_disable(p->supply); 111 regulator_disable(p->supply);
121 p->enabled = false; 112 p->enabled = false;
@@ -137,12 +128,8 @@ static int panel_simple_enable(struct drm_panel *panel)
137 return err; 128 return err;
138 } 129 }
139 130
140 if (gpio_is_valid(p->enable_gpio)) { 131 if (p->enable_gpio)
141 if (p->enable_gpio_flags & GPIO_ACTIVE_LOW) 132 gpiod_set_value(p->enable_gpio, 1);
142 gpio_set_value(p->enable_gpio, 0);
143 else
144 gpio_set_value(p->enable_gpio, 1);
145 }
146 133
147 if (p->backlight) { 134 if (p->backlight) {
148 p->backlight->props.power = FB_BLANK_UNBLANK; 135 p->backlight->props.power = FB_BLANK_UNBLANK;
@@ -185,7 +172,6 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
185{ 172{
186 struct device_node *backlight, *ddc; 173 struct device_node *backlight, *ddc;
187 struct panel_simple *panel; 174 struct panel_simple *panel;
188 enum of_gpio_flags flags;
189 int err; 175 int err;
190 176
191 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL); 177 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
@@ -199,29 +185,20 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
199 if (IS_ERR(panel->supply)) 185 if (IS_ERR(panel->supply))
200 return PTR_ERR(panel->supply); 186 return PTR_ERR(panel->supply);
201 187
202 panel->enable_gpio = of_get_named_gpio_flags(dev->of_node, 188 panel->enable_gpio = devm_gpiod_get(dev, "enable");
203 "enable-gpios", 0, 189 if (IS_ERR(panel->enable_gpio)) {
204 &flags); 190 err = PTR_ERR(panel->enable_gpio);
205 if (gpio_is_valid(panel->enable_gpio)) { 191 if (err != -ENOENT) {
206 unsigned int value; 192 dev_err(dev, "failed to request GPIO: %d\n", err);
207
208 if (flags & OF_GPIO_ACTIVE_LOW)
209 panel->enable_gpio_flags |= GPIO_ACTIVE_LOW;
210
211 err = gpio_request(panel->enable_gpio, "enable");
212 if (err < 0) {
213 dev_err(dev, "failed to request GPIO#%u: %d\n",
214 panel->enable_gpio, err);
215 return err; 193 return err;
216 } 194 }
217 195
218 value = (panel->enable_gpio_flags & GPIO_ACTIVE_LOW) != 0; 196 panel->enable_gpio = NULL;
219 197 } else {
220 err = gpio_direction_output(panel->enable_gpio, value); 198 err = gpiod_direction_output(panel->enable_gpio, 0);
221 if (err < 0) { 199 if (err < 0) {
222 dev_err(dev, "failed to setup GPIO%u: %d\n", 200 dev_err(dev, "failed to setup GPIO: %d\n", err);
223 panel->enable_gpio, err); 201 return err;
224 goto free_gpio;
225 } 202 }
226 } 203 }
227 204
@@ -230,10 +207,8 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
230 panel->backlight = of_find_backlight_by_node(backlight); 207 panel->backlight = of_find_backlight_by_node(backlight);
231 of_node_put(backlight); 208 of_node_put(backlight);
232 209
233 if (!panel->backlight) { 210 if (!panel->backlight)
234 err = -EPROBE_DEFER; 211 return -EPROBE_DEFER;
235 goto free_gpio;
236 }
237 } 212 }
238 213
239 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0); 214 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
@@ -265,9 +240,6 @@ free_ddc:
265free_backlight: 240free_backlight:
266 if (panel->backlight) 241 if (panel->backlight)
267 put_device(&panel->backlight->dev); 242 put_device(&panel->backlight->dev);
268free_gpio:
269 if (gpio_is_valid(panel->enable_gpio))
270 gpio_free(panel->enable_gpio);
271 243
272 return err; 244 return err;
273} 245}
@@ -287,9 +259,6 @@ static int panel_simple_remove(struct device *dev)
287 if (panel->backlight) 259 if (panel->backlight)
288 put_device(&panel->backlight->dev); 260 put_device(&panel->backlight->dev);
289 261
290 if (gpio_is_valid(panel->enable_gpio))
291 gpio_free(panel->enable_gpio);
292
293 regulator_disable(panel->supply); 262 regulator_disable(panel->supply);
294 263
295 return 0; 264 return 0;