From: denis@eukrea.com (Denis Carikli)
To: linux-arm-kernel@lists.infradead.org
Subject: [Patch v2][ 06/37] video: backlight: gpio-backlight: Add DT support.
Date: Thu, 17 Oct 2013 17:02:04 +0200 [thread overview]
Message-ID: <1382022155-21954-7-git-send-email-denis@eukrea.com> (raw)
In-Reply-To: <1382022155-21954-1-git-send-email-denis@eukrea.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Pawel Moll <pawel.moll@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: Ian Campbell <ijc+devicetree@hellion.org.uk>
Cc: devicetree at vger.kernel.org
Cc: Sascha Hauer <kernel@pengutronix.de>
Cc: linux-arm-kernel at lists.infradead.org
Cc: Eric B?nard <eric@eukrea.com>
Signed-off-by: Denis Carikli <denis@eukrea.com>
---
.../bindings/video/backlight/gpio-backlight.txt | 18 +++++
drivers/video/backlight/gpio_backlight.c | 73 ++++++++++++++++++--
2 files changed, 84 insertions(+), 7 deletions(-)
create mode 100644 Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt
diff --git a/Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt b/Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt
new file mode 100644
index 0000000..362dd40
--- /dev/null
+++ b/Documentation/devicetree/bindings/video/backlight/gpio-backlight.txt
@@ -0,0 +1,18 @@
+gpio-backlight bindings
+
+Required properties:
+ - compatible: "gpio-backlight"
+ - gpios: describes the gpio that is used for enabling/disabling the backlight
+ (see GPIO binding[0] for more details).
+ - default-brightness-level: the default brightness level (can be 0(off) or
+ 1(on) since GPIOs only support theses levels).
+
+[0]: Documentation/devicetree/bindings/gpio/gpio.txt
+
+Example:
+
+ backlight {
+ compatible = "gpio-backlight";
+ gpios = <&gpio3 4 0>;
+ default-brightness-level = <1>;
+ };
diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c
index 81fb127..f5d31e7 100644
--- a/drivers/video/backlight/gpio_backlight.c
+++ b/drivers/video/backlight/gpio_backlight.c
@@ -13,6 +13,8 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
#include <linux/platform_data/gpio_backlight.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
@@ -23,6 +25,7 @@ struct gpio_backlight {
int gpio;
int active;
+ int def_value;
};
static int gpio_backlight_update_status(struct backlight_device *bl)
@@ -60,6 +63,43 @@ static const struct backlight_ops gpio_backlight_ops = {
.check_fb = gpio_backlight_check_fb,
};
+static int gpio_backlight_probe_dt(struct platform_device *pdev,
+ struct gpio_backlight *gbl)
+{
+ struct device_node *np = pdev->dev.of_node;
+ enum of_gpio_flags gpio_flags;
+ int ret;
+
+ gbl->fbdev = NULL;
+ gbl->gpio = of_get_gpio_flags(np, 0, &gpio_flags);
+
+ gbl->active = (gpio_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1;
+
+ if (gbl->gpio == -EPROBE_DEFER) {
+ return ERR_PTR(-EPROBE_DEFER);
+ } else if (gbl->gpio < 0) {
+ dev_err(&pdev->dev, "Error: gpios is a required parameter.\n");
+ return gbl->gpio;
+ }
+
+ ret = of_property_read_u32(np, "default-brightness-level",
+ &gbl->def_value);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Error: default-brightness-level "
+ "is a required parameter.\n");
+ return ret;
+ }
+
+ if (gbl->def_value < 0 || gbl->def_value > 1) {
+ dev_err(&pdev->dev, "Error: Invalid "
+ "default-brightness-level value. Its value can be "
+ "either 0(off) or 1(on).\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int gpio_backlight_probe(struct platform_device *pdev)
{
struct gpio_backlight_platform_data *pdata =
@@ -67,10 +107,12 @@ static int gpio_backlight_probe(struct platform_device *pdev)
struct backlight_properties props;
struct backlight_device *bl;
struct gpio_backlight *gbl;
+ struct device_node *np = pdev->dev.of_node;
int ret;
- if (!pdata) {
- dev_err(&pdev->dev, "failed to find platform data\n");
+ if (!pdata && !np) {
+ dev_err(&pdev->dev, "failed to find platform data or device "
+ "tree node.\n");
return -ENODEV;
}
@@ -79,14 +121,21 @@ static int gpio_backlight_probe(struct platform_device *pdev)
return -ENOMEM;
gbl->dev = &pdev->dev;
- gbl->fbdev = pdata->fbdev;
- gbl->gpio = pdata->gpio;
- gbl->active = pdata->active_low ? 0 : 1;
+
+ if (np) {
+ ret = gpio_backlight_probe_dt(pdev, gbl);
+ if (ret)
+ return ret;
+ } else {
+ gbl->fbdev = pdata->fbdev;
+ gbl->gpio = pdata->gpio;
+ gbl->active = pdata->active_low ? 0 : 1;
+ }
ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT |
(gbl->active ? GPIOF_INIT_LOW
: GPIOF_INIT_HIGH),
- pdata->name);
+ pdata ? pdata->name : "backlight");
if (ret < 0) {
dev_err(&pdev->dev, "unable to request GPIO\n");
return ret;
@@ -103,17 +152,27 @@ static int gpio_backlight_probe(struct platform_device *pdev)
return PTR_ERR(bl);
}
- bl->props.brightness = pdata->def_value;
+ if (np)
+ bl->props.brightness = gbl->def_value;
+ else
+ bl->props.brightness = pdata->def_value;
+
backlight_update_status(bl);
platform_set_drvdata(pdev, bl);
return 0;
}
+static struct of_device_id gpio_backlight_of_match[] = {
+ { .compatible = "gpio-backlight" },
+ { /* sentinel */ }
+};
+
static struct platform_driver gpio_backlight_driver = {
.driver = {
.name = "gpio-backlight",
.owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(gpio_backlight_of_match),
},
.probe = gpio_backlight_probe,
};
--
1.7.9.5
next prev parent reply other threads:[~2013-10-17 15:02 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-17 15:01 Devicetree support for Eukrea cpuimx{25,35,51} (v2) Denis Carikli
2013-10-17 15:01 ` [Patch v2][ 01/37] of: add vendor prefix for Eukréa Electromatique Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 02/37] dma: ipu: Add devicetree support Denis Carikli
2013-10-18 6:42 ` Sascha Hauer
2013-10-17 15:02 ` [Patch v2][ 03/37] drm: Add the lacking DRM_MODE_FLAG_* for matching the DISPLAY_FLAGS_* Denis Carikli
2013-10-18 7:46 ` Ville Syrjälä
2013-10-23 14:48 ` Denis Carikli
2013-10-23 15:38 ` Ville Syrjälä
2013-10-23 15:47 ` Matt Sealey
2013-10-17 15:02 ` [Patch v2][ 04/37] [media] v4l2: add new V4L2_PIX_FMT_RGB666 pixel format Denis Carikli
2013-10-31 13:18 ` Mauro Carvalho Chehab
2013-10-31 14:06 ` Laurent Pinchart
2013-10-17 15:02 ` [Patch v2][ 05/37] fbdev: Add the lacking FB_SYNC_* for matching the DISPLAY_FLAGS_* Denis Carikli
2013-10-19 11:08 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-17 15:02 ` Denis Carikli [this message]
2013-10-17 15:02 ` [Patch v2][ 07/37] video: mx3fb: Introduce regulator support Denis Carikli
2013-10-19 11:08 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-17 15:02 ` [Patch v2][ 08/37] video: mx3fb: Add device tree suport Denis Carikli
2013-10-19 11:04 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-21 8:03 ` Sascha Hauer
2013-10-17 15:02 ` [Patch v2][ 09/37] video: imxfb: Introduce regulator support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 10/37] video: imxfb: Also add pwmr for the device tree Denis Carikli
2013-10-19 10:57 ` Jean-Christophe PLAGNIOL-VILLARD
2013-10-17 15:02 ` [Patch v2][ 11/37] staging: imx-drm: use of_get_display_timings Denis Carikli
2013-10-18 6:46 ` Sascha Hauer
2013-10-17 15:02 ` [Patch v2][ 12/37] staging: imx-drm: ipuv3-crtc: don't harcode some mode flags Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 13/37] staging: imx-drm: Add RGB666 support for parallel display Denis Carikli
2013-10-31 13:18 ` Mauro Carvalho Chehab
2013-10-17 15:02 ` [Patch v2][ 14/37] staging: imx-drm: parallel display: add regulator support Denis Carikli
2013-10-17 16:47 ` Dan Carpenter
2013-10-17 15:02 ` [Patch v2][ 15/37] Input: tsc2007: Add device tree support Denis Carikli
2013-10-18 8:36 ` Lothar Waßmann
2013-10-17 15:02 ` [Patch v2][ 16/37] ASoC: eukrea-tlv320: Add DT support Denis Carikli
2013-10-18 9:19 ` Lothar Waßmann
2013-10-17 15:02 ` [Patch v2][ 17/37] DT: Add basic support for imx35-based devices Denis Carikli
2013-10-18 6:58 ` Sascha Hauer
2013-10-17 15:02 ` [Patch v2][ 18/37] ARM: imx{25, 27} DT: Permit the selection of the imxfb framebuffer driver Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 19/37] pinctrl: pinctrl-imx: add imx25 pinctrl driver Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 20/37] arm/dts: imx25.dtsi: Add some pinmux pins Denis Carikli
2013-10-18 7:02 ` Sascha Hauer
2013-10-17 15:02 ` [Patch v2][ 21/37] arm/dts: i.MX25: Add ssi clocks and DMA events Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 22/37] arm/dts: i.MX25: Add sdma script path Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 23/37] arm/dts: imx25.dtsi: Add an alias for the Audio Multiplexer Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 24/37] arm/dts: Add support for the cpuimx25 board from Eukrea and its baseboard Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 25/37] arm/dts: imx51.dtsi: Add some pinmux pins Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 26/37] arm/dts: Add support for the cpuimx51 board from Eukrea and its baseboard Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 27/37] arm/dts: Add support for the cpuimx35 " Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 28/37] ARM: imx_v6_v7_defconfig: Enable i.MX35 DT support Denis Carikli
2013-10-18 8:23 ` Shawn Guo
2013-10-17 15:02 ` [Patch v2][ 29/37] ARM: imx_v6_v7_defconfig: Enable tsc2007 support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 30/37] ARM: imx_v6_v7_defconfig: Enable pcf8563 support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 31/37] ARM: imx_v6_v7_defconfig: Enable gpio regulator support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 32/37] ARM: imx_v4_v5_defconfig: " Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 33/37] ARM: imx_v4_v5_defconfig: Enable backlight gpio support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 34/37] ARM: imx_v6_v7_defconfig: " Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 35/37] ARM: imx_v4_v5_defconfig: Enable gpio button/keyboard support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 36/37] ARM: imx_v6_v7_defconfig: Enable led gpio support Denis Carikli
2013-10-17 15:02 ` [Patch v2][ 37/37] ARM: imx_v6_v7_defconfig: Enable heartbeat led trigger Denis Carikli
2013-10-18 7:59 ` Devicetree support for Eukrea cpuimx{25,35,51} (v2) Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382022155-21954-7-git-send-email-denis@eukrea.com \
--to=denis@eukrea.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).