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