ec48d4674680d66ca6ba8cd159751a3038ee32ec
[openembedded.git] / packages / linux / linux-ezx-2.6.21 / ezx-backlight.patch
1
2 #
3 # Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
4 #
5
6 Index: linux-2.6.21/drivers/video/backlight/Kconfig
7 ===================================================================
8 --- linux-2.6.21.orig/drivers/video/backlight/Kconfig   2007-05-08 14:19:18.000000000 -0300
9 +++ linux-2.6.21/drivers/video/backlight/Kconfig        2007-05-08 14:22:22.000000000 -0300
10 @@ -63,3 +63,12 @@
11         help
12           If you have a Frontpath ProGear say Y to enable the
13           backlight driver.
14 +
15 +config BACKLIGHT_EZX
16 +       tristate "Motorola EXZ Backlight Driver (A780/E680/E680i)"
17 +       depends on BACKLIGHT_CLASS_DEVICE && PXA_EZX
18 +       default y
19 +       help
20 +         If you have a Motorola A780 or E680(i), say y to enable the
21 +         backlight driver.
22 +
23 Index: linux-2.6.21/drivers/video/backlight/Makefile
24 ===================================================================
25 --- linux-2.6.21.orig/drivers/video/backlight/Makefile  2007-05-08 14:19:18.000000000 -0300
26 +++ linux-2.6.21/drivers/video/backlight/Makefile       2007-05-08 14:22:22.000000000 -0300
27 @@ -6,3 +6,4 @@
28  obj-$(CONFIG_BACKLIGHT_HP680)  += hp680_bl.o
29  obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
30  obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
31 +obj-$(CONFIG_BACKLIGHT_EZX)    += ezx_bl.o
32 Index: linux-2.6.21/drivers/video/backlight/ezx_bl.c
33 ===================================================================
34 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
35 +++ linux-2.6.21/drivers/video/backlight/ezx_bl.c       2007-05-08 14:24:16.000000000 -0300
36 @@ -0,0 +1,142 @@
37 +/*
38 + * Backlight Driver for Motorola A780 and E680(i) GSM Phones.
39 + *
40 + * Copyright 2006 Vanille Media
41 + *
42 + * Author: Michael Lauer <mickey@Vanille.de>
43 + *
44 + * This program is free software; you can redistribute it and/or modify
45 + * it under the terms of the GNU General Public License version 2 as
46 + * published by the Free Software Foundation.
47 + *
48 + */
49 +
50 +#include <linux/module.h>
51 +#include <linux/kernel.h>
52 +#include <linux/init.h>
53 +#include <linux/platform_device.h>
54 +#include <linux/fb.h>
55 +#include <linux/backlight.h>
56 +
57 +#include <asm/arch/pxa-regs.h>
58 +#include <asm/arch/ezx.h>
59 +
60 +#define EZX_MIN_INTENSITY       0
61 +#define EZX_MAX_INTENSITY      50
62 +#define EZX_DEFAULT_INTENSITY  30
63 +
64 +static struct backlight_device *ezx_backlight_device;
65 +static int last_intensity;
66 +static int suspended;
67 +
68 +static int ezxbl_send_intensity(struct backlight_device *bd)
69 +{
70 +       int intensity = bd->props.brightness;
71 +
72 +       if (suspended || bd->props.power != FB_BLANK_UNBLANK ||
73 +                       bd->props.fb_blank != FB_BLANK_UNBLANK)
74 +               intensity = 0;
75 +
76 +       if ( !last_intensity && intensity ) {
77 +               PWM_CTRL0 = 2; /* pre-scaler */
78 +               PWM_PWDUTY0 = intensity; /* duty cycle */
79 +               PWM_PERVAL0 = 49; /* period */
80 +               pxa_gpio_mode(GPIO16_PWM0_MD); /* set GPIO16 as alternate function + output */
81 +               pxa_set_cken(CKEN0_PWM0, 1); /* clock enable */
82 +       }
83 +       else if ( last_intensity && !intensity ) {
84 +               PWM_PWDUTY0 = 0;
85 +               GAFR0_U &= 0xFFFFFFFC; /* ??? */
86 +               pxa_set_cken(CKEN0_PWM0, 0); /* clock disable */
87 +               pxa_gpio_mode(GPIO16_PWM0); /* set GPIO16 as input */
88 +       } else if ( last_intensity && intensity ) {
89 +               PWM_PWDUTY0 = intensity; /* duty cycle */
90 +       }
91 +       last_intensity = intensity;
92 +       return 0;
93 +}
94 +
95 +static int ezxbl_get_intensity(struct backlight_device *bd)
96 +{
97 +       return last_intensity;
98 +}
99 +
100 +static int ezxbl_set_intensity(struct backlight_device *bd)
101 +{
102 +       return ezxbl_send_intensity(ezx_backlight_device);
103 +}
104 +
105 +#ifdef CONFIG_PM
106 +static int ezxbl_suspend(struct platform_device *pdev, pm_message_t state)
107 +{
108 +       suspended = 1;
109 +       ezxbl_set_intensity(ezx_backlight_device);
110 +       return 0;
111 +}
112 +
113 +static int ezxbl_resume(struct platform_device *pdev)
114 +{
115 +       suspended = 0;
116 +       ezxbl_set_intensity(ezx_backlight_device);
117 +       return 0;
118 +}
119 +#else
120 +#define ezxbl_suspend  NULL
121 +#define ezxbl_resume   NULL
122 +#endif
123 +
124 +static struct backlight_ops ezxbl_ops = {
125 +       .get_brightness = ezxbl_get_intensity,
126 +       .update_status  = ezxbl_set_intensity,
127 +};
128 +
129 +static int __init ezxbl_probe(struct platform_device *pdev)
130 +{
131 +       ezx_backlight_device = backlight_device_register ("ezx-bl",
132 +               &pdev->dev, NULL, &ezxbl_ops);
133 +       if (IS_ERR (ezx_backlight_device))
134 +               return PTR_ERR (ezx_backlight_device);
135 +
136 +       platform_set_drvdata(pdev, ezx_backlight_device);
137 +
138 +       ezx_backlight_device->props.power = FB_BLANK_UNBLANK;
139 +       ezx_backlight_device->props.max_brightness = EZX_MAX_INTENSITY;
140 +       ezx_backlight_device->props.brightness = EZX_DEFAULT_INTENSITY;
141 +       ezxbl_set_intensity(ezx_backlight_device);
142 +       backlight_update_status(ezx_backlight_device);
143 +
144 +       return 0;
145 +}
146 +
147 +static int ezxbl_remove(struct platform_device *pdev)
148 +{
149 +       backlight_device_unregister(ezx_backlight_device);
150 +       return 0;
151 +}
152 +
153 +static struct platform_driver ezxbl_driver = {
154 +       .probe          = ezxbl_probe,
155 +       .remove         = ezxbl_remove,
156 +       .suspend        = ezxbl_suspend,
157 +       .resume         = ezxbl_resume,
158 +       .driver         = {
159 +               .name           = "ezx-bl",
160 +       },
161 +};
162 +
163 +static int __init ezxbl_init(void)
164 +{
165 +       return platform_driver_register(&ezxbl_driver);
166 +}
167 +
168 +static void __exit ezxbl_exit(void)
169 +{
170 +       platform_driver_unregister(&ezxbl_driver);
171 +}
172 +
173 +module_init(ezxbl_init);
174 +module_exit(ezxbl_exit);
175 +
176 +MODULE_AUTHOR("Michael Lauer <mickey@Vanille.de>");
177 +MODULE_DESCRIPTION("Backlight Driver for Motorola A780|E680(i)");
178 +MODULE_LICENSE("GPL");
179 Index: linux-2.6.21/arch/arm/mach-pxa/ezx.c
180 ===================================================================
181 --- linux-2.6.21.orig/arch/arm/mach-pxa/ezx.c   2007-05-08 14:22:21.000000000 -0300
182 +++ linux-2.6.21/arch/arm/mach-pxa/ezx.c        2007-05-08 14:22:22.000000000 -0300
183 @@ -67,6 +67,12 @@
184  #endif
185  EXPORT_SYMBOL(ezx_backlight_power);
186  
187 +/* EZX LCD Backlight */
188 +static struct platform_device ezxbacklight_device = {
189 +       .name           = "ezx-bl",
190 +       .id             = -1,
191 +};
192 +
193  /* SSP */
194  struct platform_device ezxssp_device = {
195         .name           = "ezx-ssp",
196 @@ -204,6 +210,7 @@
197         &ezxpcap_device,
198         &ezxemu_device,
199         &pcap_ts_device,
200 +       &ezxbacklight_device,
201  };
202  
203  /* PM */