summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Lehrer <jlehrer@nvidia.com>2011-02-13 18:19:34 -0800
committerVarun Colbert <vcolbert@nvidia.com>2011-02-22 18:13:32 -0800
commit70949985bed59a1488bdf5a4481512f214648811 (patch)
tree3a4b932e515c8f31adfee3b2441fff605c7c9129
parentf7a800483296dc29d846d232b58ba7c694e7baab (diff)
video: tegra: Add PWM backlight driver
bug 773671 Change-Id: Ib93f0dcb7e22220fe297c81d403c401548f3c649 Reviewed-on: http://git-master/r/18280 Tested-by: Joseph Lehrer <jlehrer@nvidia.com> Reviewed-by: Thomas Cherry <tcherry@nvidia.com> Reviewed-by: Jonathan Mayo <jmayo@nvidia.com> Reviewed-by: Sachin Nikam <snikam@nvidia.com> Reviewed-by: Daniel Willemsen <dwillemsen@nvidia.com>
-rw-r--r--drivers/video/backlight/Kconfig9
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/tegra_pwm_bl.c155
-rw-r--r--include/linux/tegra_pwm_bl.h25
4 files changed, 190 insertions, 0 deletions
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index e54a337227ea..3a5db8da1d62 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -222,6 +222,15 @@ config BACKLIGHT_PWM
If you have a LCD backlight adjustable by PWM, say Y to enable
this driver.
+config BACKLIGHT_TEGRA_PWM
+ bool "Tegra2 PMx based PWM Backlight Driver"
+ depends on ARCH_TEGRA_2x_SOC && TEGRA_DC
+ help
+ Enable support for Tegra2 DC pwm backlight.
+
+ If you have a pwm backlight adjustable by the DC PM0 or PM1 signal
+ control on tegra2, say Y to enable this driver.
+
config BACKLIGHT_DA903X
tristate "Backlight Driver for DA9030/DA9034 using WLED"
depends on PMIC_DA903X
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 44c0f81ad85d..50dafd875db1 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o
obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
+obj-$(CONFIG_BACKLIGHT_TEGRA_PWM) += tegra_pwm_bl.o
obj-$(CONFIG_BACKLIGHT_DA903X) += da903x_bl.o
obj-$(CONFIG_BACKLIGHT_MAX8925) += max8925_bl.o
obj-$(CONFIG_BACKLIGHT_MBP_NVIDIA) += mbp_nvidia_bl.o
diff --git a/drivers/video/backlight/tegra_pwm_bl.c b/drivers/video/backlight/tegra_pwm_bl.c
new file mode 100644
index 000000000000..4c823b5a08e8
--- /dev/null
+++ b/drivers/video/backlight/tegra_pwm_bl.c
@@ -0,0 +1,155 @@
+/*
+ * linux/drivers/video/backlight/tegra_pwm_bl.c
+ *
+ * Tegra pwm backlight driver
+ *
+ * Copyright (C) 2011 NVIDIA Corporation
+ * Author: Renuka Apte <rapte@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/fb.h>
+#include <linux/backlight.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/tegra_pwm_bl.h>
+#include <mach/dc.h>
+
+struct tegra_pwm_bl_data {
+ struct device *dev;
+ int which_dc;
+ struct tegra_dc_pwm_params params;
+};
+
+static int tegra_pwm_backlight_update_status(struct backlight_device *bl)
+{
+ struct tegra_pwm_bl_data *tbl = dev_get_drvdata(&bl->dev);
+ int brightness = bl->props.brightness;
+ int max = bl->props.max_brightness;
+ struct tegra_dc *dc;
+
+ if (bl->props.power != FB_BLANK_UNBLANK)
+ brightness = 0;
+
+ if (bl->props.fb_blank != FB_BLANK_UNBLANK)
+ brightness = 0;
+
+ if (brightness > max)
+ dev_err(&bl->dev, "Invalid brightness value: %d max: %d\n",
+ brightness, max);
+
+ /* map API brightness range from (0~255) to hw range (0~128) */
+ tbl->params.duty_cycle = (brightness * 128) / 255;
+
+ /* Call tegra display controller function to update backlight */
+ dc = tegra_dc_get_dc(tbl->which_dc);
+ if (dc)
+ tegra_dc_config_pwm(dc, &tbl->params);
+ else
+ dev_err(&bl->dev, "tegra display controller not available\n");
+
+ return 0;
+}
+
+static int tegra_pwm_backlight_get_brightness(struct backlight_device *bl)
+{
+ return bl->props.brightness;
+}
+
+static const struct backlight_ops tegra_pwm_backlight_ops = {
+ .update_status = tegra_pwm_backlight_update_status,
+ .get_brightness = tegra_pwm_backlight_get_brightness,
+};
+
+static int tegra_pwm_backlight_probe(struct platform_device *pdev)
+{
+ struct backlight_properties props;
+ struct platform_tegra_pwm_backlight_data *data;
+ struct backlight_device *bl;
+ struct tegra_pwm_bl_data *tbl;
+ int ret;
+
+ data = pdev->dev.platform_data;
+ if (!data) {
+ dev_err(&pdev->dev, "failed to find platform data\n");
+ return -EINVAL;
+ }
+
+ tbl = kzalloc(sizeof(*tbl), GFP_KERNEL);
+ if (!tbl) {
+ dev_err(&pdev->dev, "no memory for state\n");
+ ret = -ENOMEM;
+ goto err_alloc;
+ }
+
+ tbl->dev = &pdev->dev;
+ tbl->which_dc = data->which_dc;
+ tbl->params.which_pwm = data->which_pwm;
+ tbl->params.period = data->period;
+ tbl->params.clk_div = data->clk_div;
+ tbl->params.clk_select = data->clk_select;
+
+ memset(&props, 0, sizeof(struct backlight_properties));
+ props.max_brightness = data->max_brightness;
+ bl = backlight_device_register(dev_name(&pdev->dev), &pdev->dev, tbl,
+ &tegra_pwm_backlight_ops, &props);
+ if (IS_ERR(bl)) {
+ dev_err(&pdev->dev, "failed to register backlight\n");
+ ret = PTR_ERR(bl);
+ goto err_bl;
+ }
+
+ bl->props.brightness = data->dft_brightness;
+ backlight_update_status(bl);
+
+ platform_set_drvdata(pdev, bl);
+ return 0;
+
+err_bl:
+ kfree(tbl);
+err_alloc:
+ return ret;
+}
+
+static int tegra_pwm_backlight_remove(struct platform_device *pdev)
+{
+ struct backlight_device *bl = platform_get_drvdata(pdev);
+ struct tegra_pwm_bl_data *tbl = dev_get_drvdata(&bl->dev);
+
+ backlight_device_unregister(bl);
+ kfree(tbl);
+ return 0;
+}
+
+static struct platform_driver tegra_pwm_backlight_driver = {
+ .driver = {
+ .name = "tegra-pwm-bl",
+ .owner = THIS_MODULE,
+ },
+ .probe = tegra_pwm_backlight_probe,
+ .remove = tegra_pwm_backlight_remove,
+};
+
+static int __init tegra_pwm_backlight_init(void)
+{
+ return platform_driver_register(&tegra_pwm_backlight_driver);
+}
+module_init(tegra_pwm_backlight_init);
+
+static void __exit tegra_pwm_backlight_exit(void)
+{
+ platform_driver_unregister(&tegra_pwm_backlight_driver);
+}
+module_exit(tegra_pwm_backlight_exit);
+
+MODULE_DESCRIPTION("Tegra PWM Backlight Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:tegra-pwm-backlight");
+
diff --git a/include/linux/tegra_pwm_bl.h b/include/linux/tegra_pwm_bl.h
new file mode 100644
index 000000000000..4eac77b04203
--- /dev/null
+++ b/include/linux/tegra_pwm_bl.h
@@ -0,0 +1,25 @@
+/* Tegra PWM backlight data *
+ *
+ * Copyright (C) 2011 NVIDIA Corporation
+ * Author: Renuka Apte <rapte@nvidia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef TEGRA_PWM_BL_H
+#define TEGRA_PWM_BL_H
+
+struct platform_tegra_pwm_backlight_data {
+ int which_dc;
+ int which_pwm;
+ unsigned int dft_brightness;
+ unsigned int max_brightness;
+ unsigned int period;
+ unsigned int clk_div;
+ unsigned int clk_select;
+};
+
+#endif /* TERGA_PWM_BL_H */