2 * LCD panel driver for LG.Philips LB035Q02
4 * Author: Steve Sakoman <steve@sakoman.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/module.h>
20 #include <linux/delay.h>
21 #include <linux/spi/spi.h>
22 #include <linux/mutex.h>
24 #include <video/omapdss.h>
26 struct lb035q02_data
{
30 static struct omap_video_timings lb035q02_timings
= {
45 static int lb035q02_panel_power_on(struct omap_dss_device
*dssdev
)
49 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
52 r
= omapdss_dpi_display_enable(dssdev
);
56 if (dssdev
->platform_enable
) {
57 r
= dssdev
->platform_enable(dssdev
);
64 omapdss_dpi_display_disable(dssdev
);
69 static void lb035q02_panel_power_off(struct omap_dss_device
*dssdev
)
71 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
)
74 if (dssdev
->platform_disable
)
75 dssdev
->platform_disable(dssdev
);
77 omapdss_dpi_display_disable(dssdev
);
80 static int lb035q02_panel_probe(struct omap_dss_device
*dssdev
)
82 struct lb035q02_data
*ld
;
85 dssdev
->panel
.config
= OMAP_DSS_LCD_TFT
| OMAP_DSS_LCD_IVS
|
87 dssdev
->panel
.timings
= lb035q02_timings
;
89 ld
= kzalloc(sizeof(*ld
), GFP_KERNEL
);
94 mutex_init(&ld
->lock
);
95 dev_set_drvdata(&dssdev
->dev
, ld
);
101 static void lb035q02_panel_remove(struct omap_dss_device
*dssdev
)
103 struct lb035q02_data
*ld
= dev_get_drvdata(&dssdev
->dev
);
108 static int lb035q02_panel_enable(struct omap_dss_device
*dssdev
)
110 struct lb035q02_data
*ld
= dev_get_drvdata(&dssdev
->dev
);
113 mutex_lock(&ld
->lock
);
115 r
= lb035q02_panel_power_on(dssdev
);
118 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
120 mutex_unlock(&ld
->lock
);
123 mutex_unlock(&ld
->lock
);
127 static void lb035q02_panel_disable(struct omap_dss_device
*dssdev
)
129 struct lb035q02_data
*ld
= dev_get_drvdata(&dssdev
->dev
);
131 mutex_lock(&ld
->lock
);
133 lb035q02_panel_power_off(dssdev
);
134 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
136 mutex_unlock(&ld
->lock
);
139 static int lb035q02_panel_suspend(struct omap_dss_device
*dssdev
)
141 struct lb035q02_data
*ld
= dev_get_drvdata(&dssdev
->dev
);
143 mutex_lock(&ld
->lock
);
145 lb035q02_panel_power_off(dssdev
);
146 dssdev
->state
= OMAP_DSS_DISPLAY_SUSPENDED
;
148 mutex_unlock(&ld
->lock
);
152 static int lb035q02_panel_resume(struct omap_dss_device
*dssdev
)
154 struct lb035q02_data
*ld
= dev_get_drvdata(&dssdev
->dev
);
157 mutex_lock(&ld
->lock
);
159 r
= lb035q02_panel_power_on(dssdev
);
162 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
164 mutex_unlock(&ld
->lock
);
167 mutex_unlock(&ld
->lock
);
171 static struct omap_dss_driver lb035q02_driver
= {
172 .probe
= lb035q02_panel_probe
,
173 .remove
= lb035q02_panel_remove
,
175 .enable
= lb035q02_panel_enable
,
176 .disable
= lb035q02_panel_disable
,
177 .suspend
= lb035q02_panel_suspend
,
178 .resume
= lb035q02_panel_resume
,
181 .name
= "lgphilips_lb035q02_panel",
182 .owner
= THIS_MODULE
,
186 static int lb035q02_write_reg(struct spi_device
*spi
, u8 reg
, u16 val
)
188 struct spi_message msg
;
189 struct spi_transfer index_xfer
= {
193 struct spi_transfer value_xfer
= {
198 spi_message_init(&msg
);
203 buffer
[2] = reg
& 0x7f;
204 index_xfer
.tx_buf
= buffer
;
205 spi_message_add_tail(&index_xfer
, &msg
);
209 buffer
[5] = val
>> 8;
211 value_xfer
.tx_buf
= buffer
+ 4;
212 spi_message_add_tail(&value_xfer
, &msg
);
214 return spi_sync(spi
, &msg
);
217 static void init_lb035q02_panel(struct spi_device
*spi
)
219 /* Init sequence from page 28 of the lb035q02 spec */
220 lb035q02_write_reg(spi
, 0x01, 0x6300);
221 lb035q02_write_reg(spi
, 0x02, 0x0200);
222 lb035q02_write_reg(spi
, 0x03, 0x0177);
223 lb035q02_write_reg(spi
, 0x04, 0x04c7);
224 lb035q02_write_reg(spi
, 0x05, 0xffc0);
225 lb035q02_write_reg(spi
, 0x06, 0xe806);
226 lb035q02_write_reg(spi
, 0x0a, 0x4008);
227 lb035q02_write_reg(spi
, 0x0b, 0x0000);
228 lb035q02_write_reg(spi
, 0x0d, 0x0030);
229 lb035q02_write_reg(spi
, 0x0e, 0x2800);
230 lb035q02_write_reg(spi
, 0x0f, 0x0000);
231 lb035q02_write_reg(spi
, 0x16, 0x9f80);
232 lb035q02_write_reg(spi
, 0x17, 0x0a0f);
233 lb035q02_write_reg(spi
, 0x1e, 0x00c1);
234 lb035q02_write_reg(spi
, 0x30, 0x0300);
235 lb035q02_write_reg(spi
, 0x31, 0x0007);
236 lb035q02_write_reg(spi
, 0x32, 0x0000);
237 lb035q02_write_reg(spi
, 0x33, 0x0000);
238 lb035q02_write_reg(spi
, 0x34, 0x0707);
239 lb035q02_write_reg(spi
, 0x35, 0x0004);
240 lb035q02_write_reg(spi
, 0x36, 0x0302);
241 lb035q02_write_reg(spi
, 0x37, 0x0202);
242 lb035q02_write_reg(spi
, 0x3a, 0x0a0d);
243 lb035q02_write_reg(spi
, 0x3b, 0x0806);
246 static int __devinit
lb035q02_panel_spi_probe(struct spi_device
*spi
)
248 init_lb035q02_panel(spi
);
249 return omap_dss_register_driver(&lb035q02_driver
);
252 static int __devexit
lb035q02_panel_spi_remove(struct spi_device
*spi
)
254 omap_dss_unregister_driver(&lb035q02_driver
);
258 static struct spi_driver lb035q02_spi_driver
= {
260 .name
= "lgphilips_lb035q02_panel-spi",
261 .owner
= THIS_MODULE
,
263 .probe
= lb035q02_panel_spi_probe
,
264 .remove
= __devexit_p(lb035q02_panel_spi_remove
),
267 static int __init
lb035q02_panel_drv_init(void)
269 return spi_register_driver(&lb035q02_spi_driver
);
272 static void __exit
lb035q02_panel_drv_exit(void)
274 spi_unregister_driver(&lb035q02_spi_driver
);
277 module_init(lb035q02_panel_drv_init
);
278 module_exit(lb035q02_panel_drv_exit
);
279 MODULE_LICENSE("GPL");