[RFC PATCH 1/3] drm/panel: Pull common panel code out into helpers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch pulls the regulator/backlight/enable_gpio code out of
panel-simple and creates a new panel-common helper with it. This
helper will be useful to the more complicated drivers which cannot
use panel-simple.

Signed-off-by: Sean Paul <seanpaul@xxxxxxxxxxxx>
---
 drivers/gpu/drm/panel/Kconfig        |  20 +++--
 drivers/gpu/drm/panel/Makefile       |   1 +
 drivers/gpu/drm/panel/panel-common.c | 149 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/panel/panel-common.h |  44 +++++++++++
 drivers/gpu/drm/panel/panel-simple.c | 112 ++++----------------------
 5 files changed, 225 insertions(+), 101 deletions(-)
 create mode 100644 drivers/gpu/drm/panel/panel-common.c
 create mode 100644 drivers/gpu/drm/panel/panel-common.h

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 62aba976e744..be8590724042 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -7,16 +7,26 @@ config DRM_PANEL
 menu "Display Panels"
 	depends on DRM && DRM_PANEL
 
+config DRM_PANEL_COMMON
+	bool
+	depends on OF
+	depends on BACKLIGHT_CLASS_DEVICE
+	select VIDEOMODE_HELPERS
+	help
+	  Common DRM panel helpers for panels using a regulator and a GPIO to
+	  be powered up. Optionally a backlight can be attached so that it can
+	  be automatically turned off when the panel goes into a low power
+	  state.
+
 config DRM_PANEL_SIMPLE
 	tristate "support for simple panels"
 	depends on OF
-	depends on BACKLIGHT_CLASS_DEVICE
+	select DRM_PANEL_COMMON
 	select VIDEOMODE_HELPERS
 	help
-	  DRM panel driver for dumb panels that need at most a regulator and
-	  a GPIO to be powered up. Optionally a backlight can be attached so
-	  that it can be automatically turned off when the panel goes into a
-	  low power state.
+	  DRM panel driver for dumb panels that are not more complicated than
+	  what the common helpers provide for power on/off. Allows for mode
+	  probing via ddc bus, or using fixed modes.
 
 config DRM_PANEL_JDI_LT070ME05000
 	tristate "JDI LT070ME05000 WUXGA DSI panel"
diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
index a5c7ec0236e0..48c84db88c48 100644
--- a/drivers/gpu/drm/panel/Makefile
+++ b/drivers/gpu/drm/panel/Makefile
@@ -1,3 +1,4 @@
+obj-$(CONFIG_DRM_PANEL_COMMON) += panel-common.o
 obj-$(CONFIG_DRM_PANEL_SIMPLE) += panel-simple.o
 obj-$(CONFIG_DRM_PANEL_JDI_LT070ME05000) += panel-jdi-lt070me05000.o
 obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
diff --git a/drivers/gpu/drm/panel/panel-common.c b/drivers/gpu/drm/panel/panel-common.c
new file mode 100644
index 000000000000..2979d7439bdc
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-common.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2017 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/backlight.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/of.h>
+#include <linux/regulator/consumer.h>
+
+#include <drm/drm_panel.h>
+
+#include "panel-common.h"
+
+int panel_common_init(struct device *dev, struct panel_common *common,
+		      const char *supply_name, const char *gpio_name,
+		      const char *backlight_name)
+{
+	struct device_node *backlight;
+	int err;
+
+	common->dev = dev;
+	common->enabled = false;
+	common->prepared = false;
+
+	common->supply = devm_regulator_get(dev, supply_name);
+	if (IS_ERR(common->supply))
+		return PTR_ERR(common->supply);
+
+	common->enable_gpio = devm_gpiod_get_optional(dev, gpio_name,
+						     GPIOD_OUT_LOW);
+	if (IS_ERR(common->enable_gpio)) {
+		err = PTR_ERR(common->enable_gpio);
+		dev_err(dev, "failed to request GPIO: %d\n", err);
+		return err;
+	}
+
+	backlight = of_parse_phandle(dev->of_node, backlight_name, 0);
+	if (backlight) {
+		common->backlight = of_find_backlight_by_node(backlight);
+		of_node_put(backlight);
+
+		if (!common->backlight)
+			return -EPROBE_DEFER;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(panel_common_init);
+
+void panel_common_fini(struct panel_common *common)
+{
+	if (common->backlight)
+		put_device(&common->backlight->dev);
+}
+EXPORT_SYMBOL(panel_common_fini);
+
+int panel_common_prepare(struct panel_common *common, unsigned int delay)
+{
+	int err;
+
+	if (common->prepared)
+		return 0;
+
+	err = regulator_enable(common->supply);
+	if (err < 0) {
+		dev_err(common->dev, "failed to enable supply: %d\n", err);
+		return err;
+	}
+
+	if (common->enable_gpio)
+		gpiod_set_value_cansleep(common->enable_gpio, 1);
+
+	if (delay)
+		msleep(delay);
+
+	common->prepared = true;
+
+	return 0;
+}
+EXPORT_SYMBOL(panel_common_prepare);
+
+int panel_common_unprepare(struct panel_common *common, unsigned int delay)
+{
+	if (!common->prepared)
+		return 0;
+
+	if (common->enable_gpio)
+		gpiod_set_value_cansleep(common->enable_gpio, 0);
+
+	regulator_disable(common->supply);
+
+	if (delay)
+		msleep(delay);
+
+	common->prepared = false;
+
+	return 0;
+}
+EXPORT_SYMBOL(panel_common_unprepare);
+
+int panel_common_enable(struct panel_common *common, unsigned int delay)
+{
+	if (common->enabled)
+		return 0;
+
+	if (delay)
+		msleep(delay);
+
+	if (common->backlight) {
+		common->backlight->props.state &= ~BL_CORE_FBBLANK;
+		common->backlight->props.power = FB_BLANK_UNBLANK;
+		backlight_update_status(common->backlight);
+	}
+
+	common->enabled = true;
+
+	return 0;
+}
+EXPORT_SYMBOL(panel_common_enable);
+
+int panel_common_disable(struct panel_common *common, unsigned int delay)
+{
+	if (!common->enabled)
+		return 0;
+
+	if (common->backlight) {
+		common->backlight->props.power = FB_BLANK_POWERDOWN;
+		common->backlight->props.state |= BL_CORE_FBBLANK;
+		backlight_update_status(common->backlight);
+	}
+
+	if (delay)
+		msleep(delay);
+
+	common->enabled = false;
+
+	return 0;
+}
+EXPORT_SYMBOL(panel_common_disable);
diff --git a/drivers/gpu/drm/panel/panel-common.h b/drivers/gpu/drm/panel/panel-common.h
new file mode 100644
index 000000000000..dc3b24ac2938
--- /dev/null
+++ b/drivers/gpu/drm/panel/panel-common.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _PANEL_COMMON_H_
+#define _PANEL_COMMON_H_
+
+struct backlight_device;
+struct regulator;
+struct i2c_adapter;
+struct gpio_desc;
+
+struct panel_common {
+	struct device *dev;
+
+	bool prepared;
+	bool enabled;
+
+	struct backlight_device *backlight;
+	struct regulator *supply;
+
+	struct gpio_desc *enable_gpio;
+};
+
+int panel_common_init(struct device *dev, struct panel_common *common,
+		      const char *supply_name, const char *gpio_name,
+		      const char *backlight_name);
+void panel_common_fini(struct panel_common *common);
+
+int panel_common_prepare(struct panel_common *common, unsigned int delay);
+int panel_common_unprepare(struct panel_common *common, unsigned int delay);
+int panel_common_enable(struct panel_common *common, unsigned int delay);
+int panel_common_disable(struct panel_common *common, unsigned int delay);
+
+#endif // _PANEL_COMMON_H_
diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
index 89eb0422821c..1c21ff2dcd36 100644
--- a/drivers/gpu/drm/panel/panel-simple.c
+++ b/drivers/gpu/drm/panel/panel-simple.c
@@ -21,12 +21,9 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-#include <linux/backlight.h>
-#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
-#include <linux/regulator/consumer.h>
 
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
@@ -36,6 +33,8 @@
 #include <video/display_timing.h>
 #include <video/videomode.h>
 
+#include "panel-common.h"
+
 struct panel_desc {
 	const struct drm_display_mode *modes;
 	unsigned int num_modes;
@@ -77,13 +76,13 @@ struct panel_desc {
 
 struct panel_simple {
 	struct drm_panel base;
+	struct panel_common common;
+
 	bool prepared;
 	bool enabled;
 
 	const struct panel_desc *desc;
 
-	struct backlight_device *backlight;
-	struct regulator *supply;
 	struct i2c_adapter *ddc;
 
 	struct gpio_desc *enable_gpio;
@@ -163,87 +162,28 @@ static int panel_simple_disable(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);
 
-	if (!p->enabled)
-		return 0;
-
-	if (p->backlight) {
-		p->backlight->props.power = FB_BLANK_POWERDOWN;
-		p->backlight->props.state |= BL_CORE_FBBLANK;
-		backlight_update_status(p->backlight);
-	}
-
-	if (p->desc->delay.disable)
-		msleep(p->desc->delay.disable);
-
-	p->enabled = false;
-
-	return 0;
+	return panel_common_disable(&p->common, p->desc->delay.disable);
 }
 
 static int panel_simple_unprepare(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);
 
-	if (!p->prepared)
-		return 0;
-
-	if (p->enable_gpio)
-		gpiod_set_value_cansleep(p->enable_gpio, 0);
-
-	regulator_disable(p->supply);
-
-	if (p->desc->delay.unprepare)
-		msleep(p->desc->delay.unprepare);
-
-	p->prepared = false;
-
-	return 0;
+	return panel_common_unprepare(&p->common, p->desc->delay.unprepare);
 }
 
 static int panel_simple_prepare(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);
-	int err;
-
-	if (p->prepared)
-		return 0;
 
-	err = regulator_enable(p->supply);
-	if (err < 0) {
-		dev_err(panel->dev, "failed to enable supply: %d\n", err);
-		return err;
-	}
-
-	if (p->enable_gpio)
-		gpiod_set_value_cansleep(p->enable_gpio, 1);
-
-	if (p->desc->delay.prepare)
-		msleep(p->desc->delay.prepare);
-
-	p->prepared = true;
-
-	return 0;
+	return panel_common_prepare(&p->common, p->desc->delay.prepare);
 }
 
 static int panel_simple_enable(struct drm_panel *panel)
 {
 	struct panel_simple *p = to_panel_simple(panel);
 
-	if (p->enabled)
-		return 0;
-
-	if (p->desc->delay.enable)
-		msleep(p->desc->delay.enable);
-
-	if (p->backlight) {
-		p->backlight->props.state &= ~BL_CORE_FBBLANK;
-		p->backlight->props.power = FB_BLANK_UNBLANK;
-		backlight_update_status(p->backlight);
-	}
-
-	p->enabled = true;
-
-	return 0;
+	return panel_common_enable(&p->common, p->desc->delay.enable);
 }
 
 static int panel_simple_get_modes(struct drm_panel *panel)
@@ -295,7 +235,7 @@ static const struct drm_panel_funcs panel_simple_funcs = {
 
 static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 {
-	struct device_node *backlight, *ddc;
+	struct device_node *ddc;
 	struct panel_simple *panel;
 	int err;
 
@@ -303,30 +243,12 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 	if (!panel)
 		return -ENOMEM;
 
-	panel->enabled = false;
-	panel->prepared = false;
 	panel->desc = desc;
 
-	panel->supply = devm_regulator_get(dev, "power");
-	if (IS_ERR(panel->supply))
-		return PTR_ERR(panel->supply);
-
-	panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
-						     GPIOD_OUT_LOW);
-	if (IS_ERR(panel->enable_gpio)) {
-		err = PTR_ERR(panel->enable_gpio);
-		dev_err(dev, "failed to request GPIO: %d\n", err);
+	err = panel_common_init(dev, &panel->common, "supply", "gpio",
+				"backlight");
+	if (err)
 		return err;
-	}
-
-	backlight = of_parse_phandle(dev->of_node, "backlight", 0);
-	if (backlight) {
-		panel->backlight = of_find_backlight_by_node(backlight);
-		of_node_put(backlight);
-
-		if (!panel->backlight)
-			return -EPROBE_DEFER;
-	}
 
 	ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
 	if (ddc) {
@@ -335,7 +257,7 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 
 		if (!panel->ddc) {
 			err = -EPROBE_DEFER;
-			goto free_backlight;
+			goto free_common;
 		}
 	}
 
@@ -354,9 +276,8 @@ static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
 free_ddc:
 	if (panel->ddc)
 		put_device(&panel->ddc->dev);
-free_backlight:
-	if (panel->backlight)
-		put_device(&panel->backlight->dev);
+free_common:
+	panel_common_fini(&panel->common);
 
 	return err;
 }
@@ -373,8 +294,7 @@ static int panel_simple_remove(struct device *dev)
 	if (panel->ddc)
 		put_device(&panel->ddc->dev);
 
-	if (panel->backlight)
-		put_device(&panel->backlight->dev);
+	panel_common_fini(&panel->common);
 
 	return 0;
 }
-- 
2.12.0.367.g23dc2f6d3c-goog

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux