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-data.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 },
56 struct picodlp_i2c_command {
61 static struct omap_video_timings pico_ls_timings = {
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,
81 static inline struct picodlp_panel_data
82 *get_panel_data(const struct omap_dss_device *dssdev)
84 return (struct picodlp_panel_data *) dssdev->data;
87 static u32 picodlp_i2c_read(struct i2c_client *client, u8 reg)
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];
93 mutex_lock(&picodlp_i2c_data->xfer_lock);
95 msg[0].addr = client->addr;
98 msg[0].buf = read_cmd;
100 msg[1].addr = client->addr;
101 msg[1].flags = I2C_M_RD;
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));
110 static int picodlp_i2c_write_block(struct i2c_client *client,
114 int i, r, msg_count = 1;
116 struct picodlp_i2c_data *picodlp_i2c_data = i2c_get_clientdata(client);
118 if (len < 1 || len > 32) {
119 dev_err(&client->dev,
120 "too long syn_write_block len %d\n", len);
123 mutex_lock(&picodlp_i2c_data->xfer_lock);
125 msg.addr = client->addr;
129 r = i2c_transfer(client->adapter, &msg, msg_count);
130 mutex_unlock(&picodlp_i2c_data->xfer_lock);
133 * i2c_transfer returns:
134 * number of messages sent in case of success
135 * a negative error number in case of failure
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]);
148 dev_err(&client->dev, "picodlp_i2c_write error\n");
152 static int picodlp_i2c_write(struct i2c_client *client, u8 reg, u32 value)
158 for (i = 1; i < 5; i++)
159 data[i] = (value >> (32 - (i) * 8)) & 0xFF;
161 return picodlp_i2c_write_block(client, data, 5);
164 static int picodlp_i2c_write_array(struct i2c_client *client,
165 const struct picodlp_i2c_command commands[],
169 for (i = 0; i < count; i++) {
170 r = picodlp_i2c_write(client, commands[i].reg,
178 static int picodlp_wait_for_dma_done(struct i2c_client *client)
186 } while (picodlp_i2c_read(client, MAIN_STATUS) & DMA_STATUS);
192 * picodlp_i2c_init: i2c_initialization routine
193 * client: i2c_client for communication
196 * 0 : Success, no error
197 * error code : Failure
199 static int picodlp_i2c_init(struct i2c_client *client)
202 static const struct picodlp_i2c_command init_cmd_set1[] = {
204 {DMD_PARK_TRIGGER, 1},
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},
215 {FLASH_DUMMY_BYTES, 1},
216 {FLASH_ADDR_BYTES, 3},
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},
225 static const struct picodlp_i2c_command init_cmd_set2[] = {
227 {CMT_SPLASH_LUT_DEST_SELECT, 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},
236 static const struct picodlp_i2c_command init_cmd_set3[] = {
238 {SEQ_RESET_LUT_DEST_SELECT, 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},
247 static const struct picodlp_i2c_command init_cmd_set4[] = {
249 {SEQ_RESET_LUT_DEST_SELECT, 0},
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},
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},
283 r = picodlp_i2c_write_array(client, init_cmd_set1,
284 ARRAY_SIZE(init_cmd_set1));
288 r = picodlp_wait_for_dma_done(client);
292 r = picodlp_i2c_write_array(client, init_cmd_set2,
293 ARRAY_SIZE(init_cmd_set2));
297 r = picodlp_wait_for_dma_done(client);
301 r = picodlp_i2c_write_array(client, init_cmd_set3,
302 ARRAY_SIZE(init_cmd_set3));
306 r = picodlp_wait_for_dma_done(client);
310 r = picodlp_i2c_write_array(client, init_cmd_set4,
311 ARRAY_SIZE(init_cmd_set4));
318 static int picodlp_i2c_probe(struct i2c_client *client,
319 const struct i2c_device_id *id)
321 struct picodlp_i2c_data *picodlp_i2c_data;
323 picodlp_i2c_data = kzalloc(sizeof(struct picodlp_i2c_data), GFP_KERNEL);
325 if (!picodlp_i2c_data)
328 mutex_init(&picodlp_i2c_data->xfer_lock);
329 i2c_set_clientdata(client, picodlp_i2c_data);
334 static int picodlp_i2c_remove(struct i2c_client *client)
336 struct picodlp_i2c_data *picodlp_i2c_data =
337 i2c_get_clientdata(client);
338 kfree(picodlp_i2c_data);
342 static struct i2c_driver picodlp_i2c_driver = {
344 .name = "picodlp_i2c_driver",
346 .probe = picodlp_i2c_probe,
347 .remove = picodlp_i2c_remove,
348 .id_table = picodlp_i2c_id,
351 static int picodlp_panel_power_on(struct omap_dss_device *dssdev)
354 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
355 struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
357 gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
359 gpio_set_value(picodlp_pdata->pwrgood_gpio, 1);
361 while (!gpio_get_value(picodlp_pdata->emu_done_gpio)) {
363 dev_err(&dssdev->dev, "emu_done signal not"
370 * As per dpp2600 programming guide,
371 * it is required to sleep for 1000ms after emu_done signal goes high
372 * then only i2c commands can be successfully sent to dpp2600
376 omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
377 omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
379 r = omapdss_dpi_display_enable(dssdev);
381 dev_err(&dssdev->dev, "failed to enable DPI\n");
385 r = picodlp_i2c_init(picod->picodlp_i2c_client);
389 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
393 omapdss_dpi_display_disable(dssdev);
398 static void picodlp_panel_power_off(struct omap_dss_device *dssdev)
400 struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
402 omapdss_dpi_display_disable(dssdev);
404 gpio_set_value(picodlp_pdata->emu_done_gpio, 0);
405 gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
408 static int picodlp_panel_probe(struct omap_dss_device *dssdev)
410 struct picodlp_data *picod;
411 struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
412 struct i2c_adapter *adapter;
413 struct i2c_client *picodlp_i2c_client;
414 int r, picodlp_adapter_id;
416 dssdev->panel.timings = pico_ls_timings;
421 picod = devm_kzalloc(&dssdev->dev, sizeof(*picod), GFP_KERNEL);
425 mutex_init(&picod->lock);
427 picodlp_adapter_id = picodlp_pdata->picodlp_adapter_id;
429 adapter = i2c_get_adapter(picodlp_adapter_id);
431 dev_err(&dssdev->dev, "can't get i2c adapter\n");
435 picodlp_i2c_client = i2c_new_device(adapter, &picodlp_i2c_board_info);
436 if (!picodlp_i2c_client) {
437 dev_err(&dssdev->dev, "can't add i2c device::"
438 " picodlp_i2c_client is NULL\n");
442 picod->picodlp_i2c_client = picodlp_i2c_client;
444 dev_set_drvdata(&dssdev->dev, picod);
446 if (gpio_is_valid(picodlp_pdata->emu_done_gpio)) {
447 r = devm_gpio_request_one(&dssdev->dev,
448 picodlp_pdata->emu_done_gpio,
449 GPIOF_IN, "DLP EMU DONE");
454 if (gpio_is_valid(picodlp_pdata->pwrgood_gpio)) {
455 r = devm_gpio_request_one(&dssdev->dev,
456 picodlp_pdata->pwrgood_gpio,
457 GPIOF_OUT_INIT_LOW, "DLP PWRGOOD");
465 static void picodlp_panel_remove(struct omap_dss_device *dssdev)
467 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
469 i2c_unregister_device(picod->picodlp_i2c_client);
470 dev_set_drvdata(&dssdev->dev, NULL);
471 dev_dbg(&dssdev->dev, "removing picodlp panel\n");
476 static int picodlp_panel_enable(struct omap_dss_device *dssdev)
478 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
481 dev_dbg(&dssdev->dev, "enabling picodlp panel\n");
483 mutex_lock(&picod->lock);
484 if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
485 mutex_unlock(&picod->lock);
489 r = picodlp_panel_power_on(dssdev);
490 mutex_unlock(&picod->lock);
495 static void picodlp_panel_disable(struct omap_dss_device *dssdev)
497 struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
499 mutex_lock(&picod->lock);
500 /* Turn off DLP Power */
501 if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
502 picodlp_panel_power_off(dssdev);
504 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
505 mutex_unlock(&picod->lock);
507 dev_dbg(&dssdev->dev, "disabling picodlp panel\n");
510 static void picodlp_get_resolution(struct omap_dss_device *dssdev,
511 u16 *xres, u16 *yres)
513 *xres = dssdev->panel.timings.x_res;
514 *yres = dssdev->panel.timings.y_res;
517 static struct omap_dss_driver picodlp_driver = {
518 .probe = picodlp_panel_probe,
519 .remove = picodlp_panel_remove,
521 .enable = picodlp_panel_enable,
522 .disable = picodlp_panel_disable,
524 .get_resolution = picodlp_get_resolution,
527 .name = "picodlp_panel",
528 .owner = THIS_MODULE,
532 static int __init picodlp_init(void)
536 r = i2c_add_driver(&picodlp_i2c_driver);
538 printk(KERN_WARNING "picodlp_i2c_driver" \
539 " registration failed\n");
543 r = omap_dss_register_driver(&picodlp_driver);
545 i2c_del_driver(&picodlp_i2c_driver);
550 static void __exit picodlp_exit(void)
552 i2c_del_driver(&picodlp_i2c_driver);
553 omap_dss_unregister_driver(&picodlp_driver);
556 module_init(picodlp_init);
557 module_exit(picodlp_exit);
559 MODULE_AUTHOR("Mythri P K <mythripk@ti.com>");
560 MODULE_DESCRIPTION("picodlp driver");
561 MODULE_LICENSE("GPL");