blob: 9363cf4ab74007a453c04ab3e7630acefdea154b [file] [log] [blame]
Mayuresh Janorkar24305db2011-05-17 17:49:40 +05301/*
2 * picodlp panel driver
3 * picodlp_i2c_driver: i2c_client driver
4 *
5 * Copyright (C) 2009-2011 Texas Instruments
6 * Author: Mythri P K <mythripk@ti.com>
7 * Mayuresh Janorkar <mayur@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published by
11 * the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
Tomi Valkeinen3e281892011-10-04 11:39:38 +030022#include <linux/module.h>
Mayuresh Janorkar24305db2011-05-17 17:49:40 +053023#include <linux/input.h>
24#include <linux/platform_device.h>
25#include <linux/interrupt.h>
26#include <linux/firmware.h>
27#include <linux/slab.h>
28#include <linux/mutex.h>
29#include <linux/i2c.h>
30#include <linux/delay.h>
31#include <linux/gpio.h>
32
33#include <video/omapdss.h>
34#include <video/omap-panel-picodlp.h>
35
36#include "panel-picodlp.h"
37
38struct picodlp_data {
39 struct mutex lock;
40 struct i2c_client *picodlp_i2c_client;
41};
42
43static struct i2c_board_info picodlp_i2c_board_info = {
44 I2C_BOARD_INFO("picodlp_i2c_driver", 0x1b),
45};
46
47struct picodlp_i2c_data {
48 struct mutex xfer_lock;
49};
50
51static struct i2c_device_id picodlp_i2c_id[] = {
52 { "picodlp_i2c_driver", 0 },
53};
54
55struct picodlp_i2c_command {
56 u8 reg;
57 u32 value;
58};
59
60static struct omap_video_timings pico_ls_timings = {
61 .x_res = 864,
62 .y_res = 480,
63 .hsw = 7,
64 .hfp = 11,
65 .hbp = 7,
66
67 .pixel_clock = 19200,
68
69 .vsw = 2,
70 .vfp = 3,
71 .vbp = 14,
Archit Tanejaa8d5e412012-06-25 12:26:38 +053072
73 .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
74 .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
75 .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
76 .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
77 .sync_pclk_edge = OMAPDSS_DRIVE_SIG_FALLING_EDGE,
Mayuresh Janorkar24305db2011-05-17 17:49:40 +053078};
79
80static inline struct picodlp_panel_data
81 *get_panel_data(const struct omap_dss_device *dssdev)
82{
83 return (struct picodlp_panel_data *) dssdev->data;
84}
85
86static u32 picodlp_i2c_read(struct i2c_client *client, u8 reg)
87{
88 u8 read_cmd[] = {READ_REG_SELECT, reg}, data[4];
89 struct picodlp_i2c_data *picodlp_i2c_data = i2c_get_clientdata(client);
90 struct i2c_msg msg[2];
91
92 mutex_lock(&picodlp_i2c_data->xfer_lock);
93
94 msg[0].addr = client->addr;
95 msg[0].flags = 0;
96 msg[0].len = 2;
97 msg[0].buf = read_cmd;
98
99 msg[1].addr = client->addr;
100 msg[1].flags = I2C_M_RD;
101 msg[1].len = 4;
102 msg[1].buf = data;
103
104 i2c_transfer(client->adapter, msg, 2);
105 mutex_unlock(&picodlp_i2c_data->xfer_lock);
106 return (data[3] | (data[2] << 8) | (data[1] << 16) | (data[0] << 24));
107}
108
109static int picodlp_i2c_write_block(struct i2c_client *client,
110 u8 *data, int len)
111{
112 struct i2c_msg msg;
113 int i, r, msg_count = 1;
114
115 struct picodlp_i2c_data *picodlp_i2c_data = i2c_get_clientdata(client);
116
117 if (len < 1 || len > 32) {
118 dev_err(&client->dev,
119 "too long syn_write_block len %d\n", len);
120 return -EIO;
121 }
122 mutex_lock(&picodlp_i2c_data->xfer_lock);
123
124 msg.addr = client->addr;
125 msg.flags = 0;
126 msg.len = len;
127 msg.buf = data;
128 r = i2c_transfer(client->adapter, &msg, msg_count);
129 mutex_unlock(&picodlp_i2c_data->xfer_lock);
130
131 /*
132 * i2c_transfer returns:
133 * number of messages sent in case of success
134 * a negative error number in case of failure
135 */
136 if (r != msg_count)
137 goto err;
138
139 /* In case of success */
140 for (i = 0; i < len; i++)
141 dev_dbg(&client->dev,
142 "addr %x bw 0x%02x[%d]: 0x%02x\n",
143 client->addr, data[0] + i, i, data[i]);
144
145 return 0;
146err:
147 dev_err(&client->dev, "picodlp_i2c_write error\n");
148 return r;
149}
150
151static int picodlp_i2c_write(struct i2c_client *client, u8 reg, u32 value)
152{
153 u8 data[5];
154 int i;
155
156 data[0] = reg;
157 for (i = 1; i < 5; i++)
158 data[i] = (value >> (32 - (i) * 8)) & 0xFF;
159
160 return picodlp_i2c_write_block(client, data, 5);
161}
162
163static int picodlp_i2c_write_array(struct i2c_client *client,
164 const struct picodlp_i2c_command commands[],
165 int count)
166{
167 int i, r = 0;
168 for (i = 0; i < count; i++) {
169 r = picodlp_i2c_write(client, commands[i].reg,
170 commands[i].value);
171 if (r)
172 return r;
173 }
174 return r;
175}
176
177static int picodlp_wait_for_dma_done(struct i2c_client *client)
178{
179 u8 trial = 100;
180
181 do {
182 msleep(1);
183 if (!trial--)
184 return -ETIMEDOUT;
185 } while (picodlp_i2c_read(client, MAIN_STATUS) & DMA_STATUS);
186
187 return 0;
188}
189
190/**
191 * picodlp_i2c_init: i2c_initialization routine
192 * client: i2c_client for communication
193 *
194 * return
195 * 0 : Success, no error
196 * error code : Failure
197 */
198static int picodlp_i2c_init(struct i2c_client *client)
199{
200 int r;
201 static const struct picodlp_i2c_command init_cmd_set1[] = {
202 {SOFT_RESET, 1},
203 {DMD_PARK_TRIGGER, 1},
204 {MISC_REG, 5},
205 {SEQ_CONTROL, 0},
206 {SEQ_VECTOR, 0x100},
207 {DMD_BLOCK_COUNT, 7},
208 {DMD_VCC_CONTROL, 0x109},
209 {DMD_PARK_PULSE_COUNT, 0xA},
210 {DMD_PARK_PULSE_WIDTH, 0xB},
211 {DMD_PARK_DELAY, 0x2ED},
212 {DMD_SHADOW_ENABLE, 0},
213 {FLASH_OPCODE, 0xB},
214 {FLASH_DUMMY_BYTES, 1},
215 {FLASH_ADDR_BYTES, 3},
216 {PBC_CONTROL, 0},
217 {FLASH_START_ADDR, CMT_LUT_0_START_ADDR},
218 {FLASH_READ_BYTES, CMT_LUT_0_SIZE},
219 {CMT_SPLASH_LUT_START_ADDR, 0},
220 {CMT_SPLASH_LUT_DEST_SELECT, CMT_LUT_ALL},
221 {PBC_CONTROL, 1},
222 };
223
224 static const struct picodlp_i2c_command init_cmd_set2[] = {
225 {PBC_CONTROL, 0},
226 {CMT_SPLASH_LUT_DEST_SELECT, 0},
227 {PBC_CONTROL, 0},
228 {FLASH_START_ADDR, SEQUENCE_0_START_ADDR},
229 {FLASH_READ_BYTES, SEQUENCE_0_SIZE},
230 {SEQ_RESET_LUT_START_ADDR, 0},
231 {SEQ_RESET_LUT_DEST_SELECT, SEQ_SEQ_LUT},
232 {PBC_CONTROL, 1},
233 };
234
235 static const struct picodlp_i2c_command init_cmd_set3[] = {
236 {PBC_CONTROL, 0},
237 {SEQ_RESET_LUT_DEST_SELECT, 0},
238 {PBC_CONTROL, 0},
239 {FLASH_START_ADDR, DRC_TABLE_0_START_ADDR},
240 {FLASH_READ_BYTES, DRC_TABLE_0_SIZE},
241 {SEQ_RESET_LUT_START_ADDR, 0},
242 {SEQ_RESET_LUT_DEST_SELECT, SEQ_DRC_LUT_ALL},
243 {PBC_CONTROL, 1},
244 };
245
246 static const struct picodlp_i2c_command init_cmd_set4[] = {
247 {PBC_CONTROL, 0},
248 {SEQ_RESET_LUT_DEST_SELECT, 0},
249 {SDC_ENABLE, 1},
250 {AGC_CTRL, 7},
251 {CCA_C1A, 0x100},
252 {CCA_C1B, 0x0},
253 {CCA_C1C, 0x0},
254 {CCA_C2A, 0x0},
255 {CCA_C2B, 0x100},
256 {CCA_C2C, 0x0},
257 {CCA_C3A, 0x0},
258 {CCA_C3B, 0x0},
259 {CCA_C3C, 0x100},
260 {CCA_C7A, 0x100},
261 {CCA_C7B, 0x100},
262 {CCA_C7C, 0x100},
263 {CCA_ENABLE, 1},
264 {CPU_IF_MODE, 1},
265 {SHORT_FLIP, 1},
266 {CURTAIN_CONTROL, 0},
267 {DMD_PARK_TRIGGER, 0},
268 {R_DRIVE_CURRENT, 0x298},
269 {G_DRIVE_CURRENT, 0x298},
270 {B_DRIVE_CURRENT, 0x298},
271 {RGB_DRIVER_ENABLE, 7},
272 {SEQ_CONTROL, 0},
273 {ACTGEN_CONTROL, 0x10},
274 {SEQUENCE_MODE, SEQ_LOCK},
275 {DATA_FORMAT, RGB888},
276 {INPUT_RESOLUTION, WVGA_864_LANDSCAPE},
277 {INPUT_SOURCE, PARALLEL_RGB},
278 {CPU_IF_SYNC_METHOD, 1},
279 {SEQ_CONTROL, 1}
280 };
281
282 r = picodlp_i2c_write_array(client, init_cmd_set1,
283 ARRAY_SIZE(init_cmd_set1));
284 if (r)
285 return r;
286
287 r = picodlp_wait_for_dma_done(client);
288 if (r)
289 return r;
290
291 r = picodlp_i2c_write_array(client, init_cmd_set2,
292 ARRAY_SIZE(init_cmd_set2));
293 if (r)
294 return r;
295
296 r = picodlp_wait_for_dma_done(client);
297 if (r)
298 return r;
299
300 r = picodlp_i2c_write_array(client, init_cmd_set3,
301 ARRAY_SIZE(init_cmd_set3));
302 if (r)
303 return r;
304
305 r = picodlp_wait_for_dma_done(client);
306 if (r)
307 return r;
308
309 r = picodlp_i2c_write_array(client, init_cmd_set4,
310 ARRAY_SIZE(init_cmd_set4));
311 if (r)
312 return r;
313
314 return 0;
315}
316
317static int picodlp_i2c_probe(struct i2c_client *client,
318 const struct i2c_device_id *id)
319{
320 struct picodlp_i2c_data *picodlp_i2c_data;
321
322 picodlp_i2c_data = kzalloc(sizeof(struct picodlp_i2c_data), GFP_KERNEL);
323
324 if (!picodlp_i2c_data)
325 return -ENOMEM;
326
327 mutex_init(&picodlp_i2c_data->xfer_lock);
328 i2c_set_clientdata(client, picodlp_i2c_data);
329
330 return 0;
331}
332
333static int picodlp_i2c_remove(struct i2c_client *client)
334{
335 struct picodlp_i2c_data *picodlp_i2c_data =
336 i2c_get_clientdata(client);
337 kfree(picodlp_i2c_data);
338 return 0;
339}
340
341static struct i2c_driver picodlp_i2c_driver = {
342 .driver = {
343 .name = "picodlp_i2c_driver",
344 },
345 .probe = picodlp_i2c_probe,
346 .remove = picodlp_i2c_remove,
347 .id_table = picodlp_i2c_id,
348};
349
350static int picodlp_panel_power_on(struct omap_dss_device *dssdev)
351{
352 int r, trial = 100;
353 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
354 struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
355
356 if (dssdev->platform_enable) {
357 r = dssdev->platform_enable(dssdev);
358 if (r)
359 return r;
360 }
361
362 gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
363 msleep(1);
364 gpio_set_value(picodlp_pdata->pwrgood_gpio, 1);
365
366 while (!gpio_get_value(picodlp_pdata->emu_done_gpio)) {
367 if (!trial--) {
368 dev_err(&dssdev->dev, "emu_done signal not"
369 " going high\n");
370 return -ETIMEDOUT;
371 }
372 msleep(5);
373 }
374 /*
375 * As per dpp2600 programming guide,
376 * it is required to sleep for 1000ms after emu_done signal goes high
377 * then only i2c commands can be successfully sent to dpp2600
378 */
379 msleep(1000);
Tomi Valkeinen79e44242011-06-23 16:36:36 +0300380 r = omapdss_dpi_display_enable(dssdev);
381 if (r) {
Mayuresh Janorkar24305db2011-05-17 17:49:40 +0530382 dev_err(&dssdev->dev, "failed to enable DPI\n");
383 goto err1;
384 }
Mayuresh Janorkar24305db2011-05-17 17:49:40 +0530385
386 r = picodlp_i2c_init(picod->picodlp_i2c_client);
387 if (r)
388 goto err;
389
Tomi Valkeinen79e44242011-06-23 16:36:36 +0300390 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
391
Mayuresh Janorkar24305db2011-05-17 17:49:40 +0530392 return r;
393err:
394 omapdss_dpi_display_disable(dssdev);
395err1:
396 if (dssdev->platform_disable)
397 dssdev->platform_disable(dssdev);
398
399 return r;
400}
401
402static void picodlp_panel_power_off(struct omap_dss_device *dssdev)
403{
404 struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
405
406 omapdss_dpi_display_disable(dssdev);
407
408 gpio_set_value(picodlp_pdata->emu_done_gpio, 0);
409 gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
410
411 if (dssdev->platform_disable)
412 dssdev->platform_disable(dssdev);
413}
414
415static int picodlp_panel_probe(struct omap_dss_device *dssdev)
416{
417 struct picodlp_data *picod;
418 struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
419 struct i2c_adapter *adapter;
420 struct i2c_client *picodlp_i2c_client;
421 int r = 0, picodlp_adapter_id;
422
Archit Taneja5ae9eaa2012-06-21 09:41:10 +0530423 dssdev->panel.config = OMAP_DSS_LCD_ONOFF | OMAP_DSS_LCD_IHS |
424 OMAP_DSS_LCD_IVS;
Mayuresh Janorkar24305db2011-05-17 17:49:40 +0530425 dssdev->panel.timings = pico_ls_timings;
426
427 picod = kzalloc(sizeof(struct picodlp_data), GFP_KERNEL);
428 if (!picod)
429 return -ENOMEM;
430
431 mutex_init(&picod->lock);
432
433 picodlp_adapter_id = picodlp_pdata->picodlp_adapter_id;
434
435 adapter = i2c_get_adapter(picodlp_adapter_id);
436 if (!adapter) {
437 dev_err(&dssdev->dev, "can't get i2c adapter\n");
438 r = -ENODEV;
439 goto err;
440 }
441
442 picodlp_i2c_client = i2c_new_device(adapter, &picodlp_i2c_board_info);
443 if (!picodlp_i2c_client) {
444 dev_err(&dssdev->dev, "can't add i2c device::"
445 " picodlp_i2c_client is NULL\n");
446 r = -ENODEV;
447 goto err;
448 }
449
450 picod->picodlp_i2c_client = picodlp_i2c_client;
451
452 dev_set_drvdata(&dssdev->dev, picod);
453 return r;
454err:
455 kfree(picod);
456 return r;
457}
458
459static void picodlp_panel_remove(struct omap_dss_device *dssdev)
460{
461 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
462
463 i2c_unregister_device(picod->picodlp_i2c_client);
464 dev_set_drvdata(&dssdev->dev, NULL);
465 dev_dbg(&dssdev->dev, "removing picodlp panel\n");
466
467 kfree(picod);
468}
469
470static int picodlp_panel_enable(struct omap_dss_device *dssdev)
471{
472 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
473 int r;
474
475 dev_dbg(&dssdev->dev, "enabling picodlp panel\n");
476
477 mutex_lock(&picod->lock);
478 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
479 mutex_unlock(&picod->lock);
480 return -EINVAL;
481 }
482
483 r = picodlp_panel_power_on(dssdev);
484 mutex_unlock(&picod->lock);
485
486 return r;
487}
488
489static void picodlp_panel_disable(struct omap_dss_device *dssdev)
490{
491 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
492
493 mutex_lock(&picod->lock);
494 /* Turn off DLP Power */
495 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
496 picodlp_panel_power_off(dssdev);
497
498 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
499 mutex_unlock(&picod->lock);
500
501 dev_dbg(&dssdev->dev, "disabling picodlp panel\n");
502}
503
504static int picodlp_panel_suspend(struct omap_dss_device *dssdev)
505{
506 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
507
508 mutex_lock(&picod->lock);
509 /* Turn off DLP Power */
510 if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
511 mutex_unlock(&picod->lock);
512 dev_err(&dssdev->dev, "unable to suspend picodlp panel,"
513 " panel is not ACTIVE\n");
514 return -EINVAL;
515 }
516
517 picodlp_panel_power_off(dssdev);
518
519 dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
520 mutex_unlock(&picod->lock);
521
522 dev_dbg(&dssdev->dev, "suspending picodlp panel\n");
523 return 0;
524}
525
526static int picodlp_panel_resume(struct omap_dss_device *dssdev)
527{
528 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
529 int r;
530
531 mutex_lock(&picod->lock);
532 if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
533 mutex_unlock(&picod->lock);
534 dev_err(&dssdev->dev, "unable to resume picodlp panel,"
535 " panel is not ACTIVE\n");
536 return -EINVAL;
537 }
538
539 r = picodlp_panel_power_on(dssdev);
540 mutex_unlock(&picod->lock);
541 dev_dbg(&dssdev->dev, "resuming picodlp panel\n");
542 return r;
543}
544
545static void picodlp_get_resolution(struct omap_dss_device *dssdev,
546 u16 *xres, u16 *yres)
547{
548 *xres = dssdev->panel.timings.x_res;
549 *yres = dssdev->panel.timings.y_res;
550}
551
552static struct omap_dss_driver picodlp_driver = {
553 .probe = picodlp_panel_probe,
554 .remove = picodlp_panel_remove,
555
556 .enable = picodlp_panel_enable,
557 .disable = picodlp_panel_disable,
558
559 .get_resolution = picodlp_get_resolution,
560
561 .suspend = picodlp_panel_suspend,
562 .resume = picodlp_panel_resume,
563
564 .driver = {
565 .name = "picodlp_panel",
566 .owner = THIS_MODULE,
567 },
568};
569
570static int __init picodlp_init(void)
571{
572 int r = 0;
573
574 r = i2c_add_driver(&picodlp_i2c_driver);
575 if (r) {
576 printk(KERN_WARNING "picodlp_i2c_driver" \
577 " registration failed\n");
578 return r;
579 }
580
581 r = omap_dss_register_driver(&picodlp_driver);
582 if (r)
583 i2c_del_driver(&picodlp_i2c_driver);
584
585 return r;
586}
587
588static void __exit picodlp_exit(void)
589{
590 i2c_del_driver(&picodlp_i2c_driver);
591 omap_dss_unregister_driver(&picodlp_driver);
592}
593
594module_init(picodlp_init);
595module_exit(picodlp_exit);
596
597MODULE_AUTHOR("Mythri P K <mythripk@ti.com>");
598MODULE_DESCRIPTION("picodlp driver");
599MODULE_LICENSE("GPL");