3 * picodlp_i2c_driver: i2c_client driver
5 * Copyright (C) 2009-2011 Texas Instruments
6 * Author: Mythri P K <mythripk@ti.com>
7 * Mayuresh Janorkar <mayur@ti.com>
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.
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
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/>.
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>
33 #include <video/omapdss.h>
34 #include <video/omap-panel-picodlp.h>
36 #include "panel-picodlp.h"
40 struct i2c_client
*picodlp_i2c_client
;
43 static struct i2c_board_info picodlp_i2c_board_info
= {
44 I2C_BOARD_INFO("picodlp_i2c_driver", 0x1b),
47 struct picodlp_i2c_data
{
48 struct mutex xfer_lock
;
51 static struct i2c_device_id picodlp_i2c_id
[] = {
52 { "picodlp_i2c_driver", 0 },
55 struct picodlp_i2c_command
{
60 static struct omap_video_timings pico_ls_timings
= {
74 static inline struct picodlp_panel_data
75 *get_panel_data(const struct omap_dss_device
*dssdev
)
77 return (struct picodlp_panel_data
*) dssdev
->data
;
80 static u32
picodlp_i2c_read(struct i2c_client
*client
, u8 reg
)
82 u8 read_cmd
[] = {READ_REG_SELECT
, reg
}, data
[4];
83 struct picodlp_i2c_data
*picodlp_i2c_data
= i2c_get_clientdata(client
);
84 struct i2c_msg msg
[2];
86 mutex_lock(&picodlp_i2c_data
->xfer_lock
);
88 msg
[0].addr
= client
->addr
;
91 msg
[0].buf
= read_cmd
;
93 msg
[1].addr
= client
->addr
;
94 msg
[1].flags
= I2C_M_RD
;
98 i2c_transfer(client
->adapter
, msg
, 2);
99 mutex_unlock(&picodlp_i2c_data
->xfer_lock
);
100 return (data
[3] | (data
[2] << 8) | (data
[1] << 16) | (data
[0] << 24));
103 static int picodlp_i2c_write_block(struct i2c_client
*client
,
107 int i
, r
, msg_count
= 1;
109 struct picodlp_i2c_data
*picodlp_i2c_data
= i2c_get_clientdata(client
);
111 if (len
< 1 || len
> 32) {
112 dev_err(&client
->dev
,
113 "too long syn_write_block len %d\n", len
);
116 mutex_lock(&picodlp_i2c_data
->xfer_lock
);
118 msg
.addr
= client
->addr
;
122 r
= i2c_transfer(client
->adapter
, &msg
, msg_count
);
123 mutex_unlock(&picodlp_i2c_data
->xfer_lock
);
126 * i2c_transfer returns:
127 * number of messages sent in case of success
128 * a negative error number in case of failure
133 /* In case of success */
134 for (i
= 0; i
< len
; i
++)
135 dev_dbg(&client
->dev
,
136 "addr %x bw 0x%02x[%d]: 0x%02x\n",
137 client
->addr
, data
[0] + i
, i
, data
[i
]);
141 dev_err(&client
->dev
, "picodlp_i2c_write error\n");
145 static int picodlp_i2c_write(struct i2c_client
*client
, u8 reg
, u32 value
)
151 for (i
= 1; i
< 5; i
++)
152 data
[i
] = (value
>> (32 - (i
) * 8)) & 0xFF;
154 return picodlp_i2c_write_block(client
, data
, 5);
157 static int picodlp_i2c_write_array(struct i2c_client
*client
,
158 const struct picodlp_i2c_command commands
[],
162 for (i
= 0; i
< count
; i
++) {
163 r
= picodlp_i2c_write(client
, commands
[i
].reg
,
171 static int picodlp_wait_for_dma_done(struct i2c_client
*client
)
179 } while (picodlp_i2c_read(client
, MAIN_STATUS
) & DMA_STATUS
);
185 * picodlp_i2c_init: i2c_initialization routine
186 * client: i2c_client for communication
189 * 0 : Success, no error
190 * error code : Failure
192 static int picodlp_i2c_init(struct i2c_client
*client
)
195 static const struct picodlp_i2c_command init_cmd_set1
[] = {
197 {DMD_PARK_TRIGGER
, 1},
201 {DMD_BLOCK_COUNT
, 7},
202 {DMD_VCC_CONTROL
, 0x109},
203 {DMD_PARK_PULSE_COUNT
, 0xA},
204 {DMD_PARK_PULSE_WIDTH
, 0xB},
205 {DMD_PARK_DELAY
, 0x2ED},
206 {DMD_SHADOW_ENABLE
, 0},
208 {FLASH_DUMMY_BYTES
, 1},
209 {FLASH_ADDR_BYTES
, 3},
211 {FLASH_START_ADDR
, CMT_LUT_0_START_ADDR
},
212 {FLASH_READ_BYTES
, CMT_LUT_0_SIZE
},
213 {CMT_SPLASH_LUT_START_ADDR
, 0},
214 {CMT_SPLASH_LUT_DEST_SELECT
, CMT_LUT_ALL
},
218 static const struct picodlp_i2c_command init_cmd_set2
[] = {
220 {CMT_SPLASH_LUT_DEST_SELECT
, 0},
222 {FLASH_START_ADDR
, SEQUENCE_0_START_ADDR
},
223 {FLASH_READ_BYTES
, SEQUENCE_0_SIZE
},
224 {SEQ_RESET_LUT_START_ADDR
, 0},
225 {SEQ_RESET_LUT_DEST_SELECT
, SEQ_SEQ_LUT
},
229 static const struct picodlp_i2c_command init_cmd_set3
[] = {
231 {SEQ_RESET_LUT_DEST_SELECT
, 0},
233 {FLASH_START_ADDR
, DRC_TABLE_0_START_ADDR
},
234 {FLASH_READ_BYTES
, DRC_TABLE_0_SIZE
},
235 {SEQ_RESET_LUT_START_ADDR
, 0},
236 {SEQ_RESET_LUT_DEST_SELECT
, SEQ_DRC_LUT_ALL
},
240 static const struct picodlp_i2c_command init_cmd_set4
[] = {
242 {SEQ_RESET_LUT_DEST_SELECT
, 0},
260 {CURTAIN_CONTROL
, 0},
261 {DMD_PARK_TRIGGER
, 0},
262 {R_DRIVE_CURRENT
, 0x298},
263 {G_DRIVE_CURRENT
, 0x298},
264 {B_DRIVE_CURRENT
, 0x298},
265 {RGB_DRIVER_ENABLE
, 7},
267 {ACTGEN_CONTROL
, 0x10},
268 {SEQUENCE_MODE
, SEQ_LOCK
},
269 {DATA_FORMAT
, RGB888
},
270 {INPUT_RESOLUTION
, WVGA_864_LANDSCAPE
},
271 {INPUT_SOURCE
, PARALLEL_RGB
},
272 {CPU_IF_SYNC_METHOD
, 1},
276 r
= picodlp_i2c_write_array(client
, init_cmd_set1
,
277 ARRAY_SIZE(init_cmd_set1
));
281 r
= picodlp_wait_for_dma_done(client
);
285 r
= picodlp_i2c_write_array(client
, init_cmd_set2
,
286 ARRAY_SIZE(init_cmd_set2
));
290 r
= picodlp_wait_for_dma_done(client
);
294 r
= picodlp_i2c_write_array(client
, init_cmd_set3
,
295 ARRAY_SIZE(init_cmd_set3
));
299 r
= picodlp_wait_for_dma_done(client
);
303 r
= picodlp_i2c_write_array(client
, init_cmd_set4
,
304 ARRAY_SIZE(init_cmd_set4
));
311 static int picodlp_i2c_probe(struct i2c_client
*client
,
312 const struct i2c_device_id
*id
)
314 struct picodlp_i2c_data
*picodlp_i2c_data
;
316 picodlp_i2c_data
= kzalloc(sizeof(struct picodlp_i2c_data
), GFP_KERNEL
);
318 if (!picodlp_i2c_data
)
321 mutex_init(&picodlp_i2c_data
->xfer_lock
);
322 i2c_set_clientdata(client
, picodlp_i2c_data
);
327 static int picodlp_i2c_remove(struct i2c_client
*client
)
329 struct picodlp_i2c_data
*picodlp_i2c_data
=
330 i2c_get_clientdata(client
);
331 kfree(picodlp_i2c_data
);
335 static struct i2c_driver picodlp_i2c_driver
= {
337 .name
= "picodlp_i2c_driver",
339 .probe
= picodlp_i2c_probe
,
340 .remove
= picodlp_i2c_remove
,
341 .id_table
= picodlp_i2c_id
,
344 static int picodlp_panel_power_on(struct omap_dss_device
*dssdev
)
347 struct picodlp_data
*picod
= dev_get_drvdata(&dssdev
->dev
);
348 struct picodlp_panel_data
*picodlp_pdata
= get_panel_data(dssdev
);
350 if (dssdev
->platform_enable
) {
351 r
= dssdev
->platform_enable(dssdev
);
356 gpio_set_value(picodlp_pdata
->pwrgood_gpio
, 0);
358 gpio_set_value(picodlp_pdata
->pwrgood_gpio
, 1);
360 while (!gpio_get_value(picodlp_pdata
->emu_done_gpio
)) {
362 dev_err(&dssdev
->dev
, "emu_done signal not"
369 * As per dpp2600 programming guide,
370 * it is required to sleep for 1000ms after emu_done signal goes high
371 * then only i2c commands can be successfully sent to dpp2600
374 r
= omapdss_dpi_display_enable(dssdev
);
376 dev_err(&dssdev
->dev
, "failed to enable DPI\n");
380 r
= picodlp_i2c_init(picod
->picodlp_i2c_client
);
384 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
388 omapdss_dpi_display_disable(dssdev
);
390 if (dssdev
->platform_disable
)
391 dssdev
->platform_disable(dssdev
);
396 static void picodlp_panel_power_off(struct omap_dss_device
*dssdev
)
398 struct picodlp_panel_data
*picodlp_pdata
= get_panel_data(dssdev
);
400 omapdss_dpi_display_disable(dssdev
);
402 gpio_set_value(picodlp_pdata
->emu_done_gpio
, 0);
403 gpio_set_value(picodlp_pdata
->pwrgood_gpio
, 0);
405 if (dssdev
->platform_disable
)
406 dssdev
->platform_disable(dssdev
);
409 static int picodlp_panel_probe(struct omap_dss_device
*dssdev
)
411 struct picodlp_data
*picod
;
412 struct picodlp_panel_data
*picodlp_pdata
= get_panel_data(dssdev
);
413 struct i2c_adapter
*adapter
;
414 struct i2c_client
*picodlp_i2c_client
;
415 int r
= 0, picodlp_adapter_id
;
417 dssdev
->panel
.config
= OMAP_DSS_LCD_TFT
| OMAP_DSS_LCD_ONOFF
|
418 OMAP_DSS_LCD_IHS
| OMAP_DSS_LCD_IVS
;
419 dssdev
->panel
.acb
= 0x0;
420 dssdev
->panel
.timings
= pico_ls_timings
;
422 picod
= kzalloc(sizeof(struct picodlp_data
), GFP_KERNEL
);
426 mutex_init(&picod
->lock
);
428 picodlp_adapter_id
= picodlp_pdata
->picodlp_adapter_id
;
430 adapter
= i2c_get_adapter(picodlp_adapter_id
);
432 dev_err(&dssdev
->dev
, "can't get i2c adapter\n");
437 picodlp_i2c_client
= i2c_new_device(adapter
, &picodlp_i2c_board_info
);
438 if (!picodlp_i2c_client
) {
439 dev_err(&dssdev
->dev
, "can't add i2c device::"
440 " picodlp_i2c_client is NULL\n");
445 picod
->picodlp_i2c_client
= picodlp_i2c_client
;
447 dev_set_drvdata(&dssdev
->dev
, picod
);
454 static void picodlp_panel_remove(struct omap_dss_device
*dssdev
)
456 struct picodlp_data
*picod
= dev_get_drvdata(&dssdev
->dev
);
458 i2c_unregister_device(picod
->picodlp_i2c_client
);
459 dev_set_drvdata(&dssdev
->dev
, NULL
);
460 dev_dbg(&dssdev
->dev
, "removing picodlp panel\n");
465 static int picodlp_panel_enable(struct omap_dss_device
*dssdev
)
467 struct picodlp_data
*picod
= dev_get_drvdata(&dssdev
->dev
);
470 dev_dbg(&dssdev
->dev
, "enabling picodlp panel\n");
472 mutex_lock(&picod
->lock
);
473 if (dssdev
->state
!= OMAP_DSS_DISPLAY_DISABLED
) {
474 mutex_unlock(&picod
->lock
);
478 r
= picodlp_panel_power_on(dssdev
);
479 mutex_unlock(&picod
->lock
);
484 static void picodlp_panel_disable(struct omap_dss_device
*dssdev
)
486 struct picodlp_data
*picod
= dev_get_drvdata(&dssdev
->dev
);
488 mutex_lock(&picod
->lock
);
489 /* Turn off DLP Power */
490 if (dssdev
->state
== OMAP_DSS_DISPLAY_ACTIVE
)
491 picodlp_panel_power_off(dssdev
);
493 dssdev
->state
= OMAP_DSS_DISPLAY_DISABLED
;
494 mutex_unlock(&picod
->lock
);
496 dev_dbg(&dssdev
->dev
, "disabling picodlp panel\n");
499 static int picodlp_panel_suspend(struct omap_dss_device
*dssdev
)
501 struct picodlp_data
*picod
= dev_get_drvdata(&dssdev
->dev
);
503 mutex_lock(&picod
->lock
);
504 /* Turn off DLP Power */
505 if (dssdev
->state
!= OMAP_DSS_DISPLAY_ACTIVE
) {
506 mutex_unlock(&picod
->lock
);
507 dev_err(&dssdev
->dev
, "unable to suspend picodlp panel,"
508 " panel is not ACTIVE\n");
512 picodlp_panel_power_off(dssdev
);
514 dssdev
->state
= OMAP_DSS_DISPLAY_SUSPENDED
;
515 mutex_unlock(&picod
->lock
);
517 dev_dbg(&dssdev
->dev
, "suspending picodlp panel\n");
521 static int picodlp_panel_resume(struct omap_dss_device
*dssdev
)
523 struct picodlp_data
*picod
= dev_get_drvdata(&dssdev
->dev
);
526 mutex_lock(&picod
->lock
);
527 if (dssdev
->state
!= OMAP_DSS_DISPLAY_SUSPENDED
) {
528 mutex_unlock(&picod
->lock
);
529 dev_err(&dssdev
->dev
, "unable to resume picodlp panel,"
530 " panel is not ACTIVE\n");
534 r
= picodlp_panel_power_on(dssdev
);
535 mutex_unlock(&picod
->lock
);
536 dev_dbg(&dssdev
->dev
, "resuming picodlp panel\n");
540 static void picodlp_get_resolution(struct omap_dss_device
*dssdev
,
541 u16
*xres
, u16
*yres
)
543 *xres
= dssdev
->panel
.timings
.x_res
;
544 *yres
= dssdev
->panel
.timings
.y_res
;
547 static struct omap_dss_driver picodlp_driver
= {
548 .probe
= picodlp_panel_probe
,
549 .remove
= picodlp_panel_remove
,
551 .enable
= picodlp_panel_enable
,
552 .disable
= picodlp_panel_disable
,
554 .get_resolution
= picodlp_get_resolution
,
556 .suspend
= picodlp_panel_suspend
,
557 .resume
= picodlp_panel_resume
,
560 .name
= "picodlp_panel",
561 .owner
= THIS_MODULE
,
565 static int __init
picodlp_init(void)
569 r
= i2c_add_driver(&picodlp_i2c_driver
);
571 printk(KERN_WARNING
"picodlp_i2c_driver" \
572 " registration failed\n");
576 r
= omap_dss_register_driver(&picodlp_driver
);
578 i2c_del_driver(&picodlp_i2c_driver
);
583 static void __exit
picodlp_exit(void)
585 i2c_del_driver(&picodlp_i2c_driver
);
586 omap_dss_unregister_driver(&picodlp_driver
);
589 module_init(picodlp_init
);
590 module_exit(picodlp_exit
);
592 MODULE_AUTHOR("Mythri P K <mythripk@ti.com>");
593 MODULE_DESCRIPTION("picodlp driver");
594 MODULE_LICENSE("GPL");