[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-ti33x-psp-3.2 / beaglebone / 0015-beaglebone-enable-PWM-for-lcd-backlight-backlight-is.patch
1 From b1340250f872964ced2298fc4e0ae4d39469cf12 Mon Sep 17 00:00:00 2001
2 From: Koen Kooi <koen@dominion.thruhere.net>
3 Date: Tue, 31 Jan 2012 17:02:10 +0100
4 Subject: [PATCH 15/22] beaglebone: enable PWM for lcd backlight <- backlight
5 is inverted
7 Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
8 ---
9 arch/arm/mach-omap2/board-am335xevm.c | 54 +++++++++++++++++++++++++++------
10 arch/arm/mach-omap2/devices.c | 13 ++++++++
11 arch/arm/mach-omap2/devices.h | 1 +
12 3 files changed, 58 insertions(+), 10 deletions(-)
14 diff --git a/arch/arm/mach-omap2/board-am335xevm.c b/arch/arm/mach-omap2/board-am335xevm.c
15 index 177ab9e..6a77194 100644
16 --- a/arch/arm/mach-omap2/board-am335xevm.c
17 +++ b/arch/arm/mach-omap2/board-am335xevm.c
18 @@ -36,6 +36,7 @@
19 #include <linux/mfd/tps65910.h>
20 #include <linux/mfd/tps65217.h>
21 #include <linux/pwm_backlight.h>
22 +#include <linux/pwm/pwm.h>
24 /* LCD controller is similar to DA850 */
25 #include <video/da8xx-fb.h>
26 @@ -131,7 +132,7 @@ static const struct display_panel disp_panel = {
27 /* LCD backlight platform Data */
28 #define AM335X_BACKLIGHT_MAX_BRIGHTNESS 100
29 #define AM335X_BACKLIGHT_DEFAULT_BRIGHTNESS 100
30 -#define AM335X_PWM_PERIOD_NANO_SECONDS (1000000 * 10)
31 +#define AM335X_PWM_PERIOD_NANO_SECONDS (1000000 * 5)
33 #define PWM_DEVICE_ID "ecap.0"
35 @@ -175,6 +176,16 @@ static const struct display_panel bbtoys7_panel = {
36 COLOR_ACTIVE,
37 };
39 +#define BBTOYS7LCD_PWM_DEVICE_ID "ehrpwm.1:0"
40 +
41 +static struct platform_pwm_backlight_data bbtoys7lcd_backlight_data = {
42 + .pwm_id = BBTOYS7LCD_PWM_DEVICE_ID,
43 + .ch = -1,
44 + .max_brightness = AM335X_BACKLIGHT_MAX_BRIGHTNESS,
45 + .dft_brightness = AM335X_BACKLIGHT_DEFAULT_BRIGHTNESS,
46 + .pwm_period_ns = AM335X_PWM_PERIOD_NANO_SECONDS,
47 +};
48 +
49 static struct lcd_ctrl_config bbtoys7_cfg = {
50 &bbtoys7_panel,
51 .ac_bias = 255,
52 @@ -586,9 +597,9 @@ static struct pinmux_config bbtoys7_pin_mux[] = {
53 {"lcd_vsync.lcd_vsync", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
54 {"lcd_hsync.lcd_hsync", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
55 {"lcd_pclk.lcd_pclk", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
56 - {"lcd_ac_bias_en.lcd_ac_bias_en", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
57 - {"gpmc_a2.gpio1_18", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // Backlight
58 + {"lcd_ac_bias_en.lcd_ac_bias_en", OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
59 {"ecap0_in_pwm0_out.gpio0_7", OMAP_MUX_MODE7 | AM33XX_PIN_OUTPUT}, // AVDD_EN
60 + {"gpmc_a2.ehrpwm1A", OMAP_MUX_MODE6 | AM33XX_PIN_OUTPUT}, // Backlight
61 {NULL, 0},
62 };
64 @@ -1121,6 +1132,7 @@ static struct pinmux_config ecap0_pin_mux[] = {
65 {NULL, 0},
66 };
68 +static int ehrpwm_backlight_enable;
69 static int backlight_enable;
71 #define AM335XEVM_WLAN_PMENA_GPIO GPIO_TO_PIN(1, 30)
72 @@ -1190,6 +1202,30 @@ static int __init ecap0_init(void)
73 }
74 late_initcall(ecap0_init);
76 +static void enable_ehrpwm1(int evm_id, int profile)
77 +{
78 + ehrpwm_backlight_enable = true;
79 +}
80 +
81 +/* Setup pwm-backlight for bbtoys7lcd */
82 +static struct platform_device bbtoys7lcd_backlight = {
83 + .name = "pwm-backlight",
84 + .id = -1,
85 + .dev = {
86 + .platform_data = &bbtoys7lcd_backlight_data,
87 + }
88 +};
89 +
90 +static int __init ehrpwm1_init(void)
91 +{
92 + int status = 0;
93 + if (ehrpwm_backlight_enable) {
94 + platform_device_register(&bbtoys7lcd_backlight);
95 + }
96 + return status;
97 +}
98 +late_initcall(ehrpwm1_init);
99 +
100 static int __init conf_disp_pll(int rate)
101 {
102 struct clk *disp_pll;
103 @@ -1224,11 +1260,12 @@ static void lcdc_init(int evm_id, int profile)
104 }
106 #define BEAGLEBONE_LCD_AVDD_EN GPIO_TO_PIN(0, 7)
107 -#define BEAGLEBONE_LCD_BL GPIO_TO_PIN(1, 18)
109 static void bbtoys7lcd_init(int evm_id, int profile)
110 {
111 setup_pin_mux(bbtoys7_pin_mux);
112 + gpio_request(BEAGLEBONE_LCD_AVDD_EN, "BONE_LCD_AVDD_EN");
113 + gpio_direction_output(BEAGLEBONE_LCD_AVDD_EN, 1);
115 // we are being stupid and setting pixclock from here instead of da8xx-fb.c
116 if (conf_disp_pll(300000000)) {
117 @@ -1239,12 +1276,7 @@ static void bbtoys7lcd_init(int evm_id, int profile)
119 if (am33xx_register_lcdc(&bbtoys7_pdata))
120 pr_info("Failed to register Beagleboardtoys 7\" LCD cape device\n");
121 -
122 - gpio_request(BEAGLEBONE_LCD_BL, "BONE_LCD_BL");
123 - gpio_direction_output(BEAGLEBONE_LCD_BL, 1);
124 - gpio_request(BEAGLEBONE_LCD_AVDD_EN, "BONE_LCD_AVDD_EN");
125 - gpio_direction_output(BEAGLEBONE_LCD_AVDD_EN, 1);
126 -
127 +
128 return;
129 }
131 @@ -1768,6 +1800,8 @@ static void beaglebone_cape_setup(struct memory_accessor *mem_acc, void *context
132 bbtoys7lcd_init(0,0);
133 pr_info("BeagleBone cape: initializing LCD cape touchscreen\n");
134 tsc_init(0,0);
135 + pr_info("BeagleBone cape: Registering PWM backlight for LCD cape\n");
136 + enable_ehrpwm1(0,0);
137 beaglebone_tsadcpins_free = 0;
138 }
140 diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
141 index 198df7b..8cd2523 100644
142 --- a/arch/arm/mach-omap2/devices.c
143 +++ b/arch/arm/mach-omap2/devices.c
144 @@ -1278,6 +1278,19 @@ void register_ehrpwm(int max_freq)
145 platform_device_register(&am335x_epwm2_device);
146 }
148 +void register_ehrpwm1(int max_freq)
149 +{
150 + int val;
151 +
152 + val = __raw_readw(AM33XX_CTRL_REGADDR(AM33XX_PWMSS_CTRL));
153 + val |= PWMSS1_TBCLKEN;
154 + __raw_writew(val, AM33XX_CTRL_REGADDR(AM33XX_PWMSS_CTRL));
155 + am335x_pwmss_config1.chan_attrib[1].max_freq = max_freq;
156 + sema_init(&am335x_pwmss_config1.config_semaphore, 1);
157 + am335x_pwmss_config1.version = PWM_VERSION_1;
158 + platform_device_register(&am335x_epwm1_device);
159 +}
160 +
161 static struct resource am335x_ecap0_resurce[] = {
162 {
163 .start = AM33XX_EPWMSS0_BASE ,
164 diff --git a/arch/arm/mach-omap2/devices.h b/arch/arm/mach-omap2/devices.h
165 index e086839..5161eb4 100644
166 --- a/arch/arm/mach-omap2/devices.h
167 +++ b/arch/arm/mach-omap2/devices.h
168 @@ -18,5 +18,6 @@ int omap3_init_camera(struct isp_platform_data *pdata);
170 void __init am335x_register_mcasp1(struct snd_platform_data *pdata);
171 extern void register_ehrpwm(int max_freq);
172 +extern void register_ehrpwm1(int max_freq);
174 #endif
175 --
176 1.7.9.4