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>
This commit is contained in:
parent
ec7c565383
commit
cfdf0549f8
@ -22,9 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/backlight.h>
|
#include <linux/backlight.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio/consumer.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/of_gpio.h>
|
|
||||||
#include <linux/of_platform.h>
|
#include <linux/of_platform.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/regulator/consumer.h>
|
#include <linux/regulator/consumer.h>
|
||||||
@ -44,9 +43,6 @@ struct panel_desc {
|
|||||||
} size;
|
} size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO: convert to gpiod_*() API once it's been merged */
|
|
||||||
#define GPIO_ACTIVE_LOW (1 << 0)
|
|
||||||
|
|
||||||
struct panel_simple {
|
struct panel_simple {
|
||||||
struct drm_panel base;
|
struct drm_panel base;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
@ -57,8 +53,7 @@ struct panel_simple {
|
|||||||
struct regulator *supply;
|
struct regulator *supply;
|
||||||
struct i2c_adapter *ddc;
|
struct i2c_adapter *ddc;
|
||||||
|
|
||||||
unsigned long enable_gpio_flags;
|
struct gpio_desc *enable_gpio;
|
||||||
int enable_gpio;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
|
static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
|
||||||
@ -110,12 +105,8 @@ static int panel_simple_disable(struct drm_panel *panel)
|
|||||||
backlight_update_status(p->backlight);
|
backlight_update_status(p->backlight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_is_valid(p->enable_gpio)) {
|
if (p->enable_gpio)
|
||||||
if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
|
gpiod_set_value(p->enable_gpio, 0);
|
||||||
gpio_set_value(p->enable_gpio, 1);
|
|
||||||
else
|
|
||||||
gpio_set_value(p->enable_gpio, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
regulator_disable(p->supply);
|
regulator_disable(p->supply);
|
||||||
p->enabled = false;
|
p->enabled = false;
|
||||||
@ -137,12 +128,8 @@ static int panel_simple_enable(struct drm_panel *panel)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_is_valid(p->enable_gpio)) {
|
if (p->enable_gpio)
|
||||||
if (p->enable_gpio_flags & GPIO_ACTIVE_LOW)
|
gpiod_set_value(p->enable_gpio, 1);
|
||||||
gpio_set_value(p->enable_gpio, 0);
|
|
||||||
else
|
|
||||||
gpio_set_value(p->enable_gpio, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p->backlight) {
|
if (p->backlight) {
|
||||||
p->backlight->props.power = FB_BLANK_UNBLANK;
|
p->backlight->props.power = FB_BLANK_UNBLANK;
|
||||||
@ -185,7 +172,6 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
|
|||||||
{
|
{
|
||||||
struct device_node *backlight, *ddc;
|
struct device_node *backlight, *ddc;
|
||||||
struct panel_simple *panel;
|
struct panel_simple *panel;
|
||||||
enum of_gpio_flags flags;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
|
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)
|
|||||||
if (IS_ERR(panel->supply))
|
if (IS_ERR(panel->supply))
|
||||||
return PTR_ERR(panel->supply);
|
return PTR_ERR(panel->supply);
|
||||||
|
|
||||||
panel->enable_gpio = of_get_named_gpio_flags(dev->of_node,
|
panel->enable_gpio = devm_gpiod_get(dev, "enable");
|
||||||
"enable-gpios", 0,
|
if (IS_ERR(panel->enable_gpio)) {
|
||||||
&flags);
|
err = PTR_ERR(panel->enable_gpio);
|
||||||
if (gpio_is_valid(panel->enable_gpio)) {
|
if (err != -ENOENT) {
|
||||||
unsigned int value;
|
dev_err(dev, "failed to request GPIO: %d\n", err);
|
||||||
|
|
||||||
if (flags & OF_GPIO_ACTIVE_LOW)
|
|
||||||
panel->enable_gpio_flags |= GPIO_ACTIVE_LOW;
|
|
||||||
|
|
||||||
err = gpio_request(panel->enable_gpio, "enable");
|
|
||||||
if (err < 0) {
|
|
||||||
dev_err(dev, "failed to request GPIO#%u: %d\n",
|
|
||||||
panel->enable_gpio, err);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = (panel->enable_gpio_flags & GPIO_ACTIVE_LOW) != 0;
|
panel->enable_gpio = NULL;
|
||||||
|
} else {
|
||||||
err = gpio_direction_output(panel->enable_gpio, value);
|
err = gpiod_direction_output(panel->enable_gpio, 0);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
dev_err(dev, "failed to setup GPIO%u: %d\n",
|
dev_err(dev, "failed to setup GPIO: %d\n", err);
|
||||||
panel->enable_gpio, err);
|
return err;
|
||||||
goto free_gpio;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,10 +207,8 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
|
|||||||
panel->backlight = of_find_backlight_by_node(backlight);
|
panel->backlight = of_find_backlight_by_node(backlight);
|
||||||
of_node_put(backlight);
|
of_node_put(backlight);
|
||||||
|
|
||||||
if (!panel->backlight) {
|
if (!panel->backlight)
|
||||||
err = -EPROBE_DEFER;
|
return -EPROBE_DEFER;
|
||||||
goto free_gpio;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
|
ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
|
||||||
@ -265,9 +240,6 @@ free_ddc:
|
|||||||
free_backlight:
|
free_backlight:
|
||||||
if (panel->backlight)
|
if (panel->backlight)
|
||||||
put_device(&panel->backlight->dev);
|
put_device(&panel->backlight->dev);
|
||||||
free_gpio:
|
|
||||||
if (gpio_is_valid(panel->enable_gpio))
|
|
||||||
gpio_free(panel->enable_gpio);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -287,9 +259,6 @@ static int panel_simple_remove(struct device *dev)
|
|||||||
if (panel->backlight)
|
if (panel->backlight)
|
||||||
put_device(&panel->backlight->dev);
|
put_device(&panel->backlight->dev);
|
||||||
|
|
||||||
if (gpio_is_valid(panel->enable_gpio))
|
|
||||||
gpio_free(panel->enable_gpio);
|
|
||||||
|
|
||||||
regulator_disable(panel->supply);
|
regulator_disable(panel->supply);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user