Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
panel-picodlp.c
Go to the documentation of this file.
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 <[email protected]>
7  * Mayuresh Janorkar <[email protected]>
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>
35 
36 #include "panel-picodlp.h"
37 
38 struct picodlp_data {
39  struct mutex lock;
41 };
42 
43 static struct i2c_board_info picodlp_i2c_board_info = {
44  I2C_BOARD_INFO("picodlp_i2c_driver", 0x1b),
45 };
46 
48  struct mutex xfer_lock;
49 };
50 
51 static struct i2c_device_id picodlp_i2c_id[] = {
52  { "picodlp_i2c_driver", 0 },
53 };
54 
58 };
59 
60 static 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,
72 
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,
78 };
79 
80 static 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 
86 static 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 
109 static 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;
146 err:
147  dev_err(&client->dev, "picodlp_i2c_write error\n");
148  return r;
149 }
150 
151 static 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 
163 static 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 
177 static 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 
198 static 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},
221  {PBC_CONTROL, 1},
222  };
223 
224  static const struct picodlp_i2c_command init_cmd_set2[] = {
225  {PBC_CONTROL, 0},
227  {PBC_CONTROL, 0},
232  {PBC_CONTROL, 1},
233  };
234 
235  static const struct picodlp_i2c_command init_cmd_set3[] = {
236  {PBC_CONTROL, 0},
238  {PBC_CONTROL, 0},
243  {PBC_CONTROL, 1},
244  };
245 
246  static const struct picodlp_i2c_command init_cmd_set4[] = {
247  {PBC_CONTROL, 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},
275  {DATA_FORMAT, RGB888},
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 
317 static 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 
333 static 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 
341 static 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 
350 static 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);
380 
381  omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
382  omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
383 
384  r = omapdss_dpi_display_enable(dssdev);
385  if (r) {
386  dev_err(&dssdev->dev, "failed to enable DPI\n");
387  goto err1;
388  }
389 
390  r = picodlp_i2c_init(picod->picodlp_i2c_client);
391  if (r)
392  goto err;
393 
394  dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
395 
396  return r;
397 err:
399 err1:
400  if (dssdev->platform_disable)
401  dssdev->platform_disable(dssdev);
402 
403  return r;
404 }
405 
406 static void picodlp_panel_power_off(struct omap_dss_device *dssdev)
407 {
408  struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
409 
411 
412  gpio_set_value(picodlp_pdata->emu_done_gpio, 0);
413  gpio_set_value(picodlp_pdata->pwrgood_gpio, 0);
414 
415  if (dssdev->platform_disable)
416  dssdev->platform_disable(dssdev);
417 }
418 
419 static int picodlp_panel_probe(struct omap_dss_device *dssdev)
420 {
421  struct picodlp_data *picod;
422  struct picodlp_panel_data *picodlp_pdata = get_panel_data(dssdev);
423  struct i2c_adapter *adapter;
424  struct i2c_client *picodlp_i2c_client;
425  int r = 0, picodlp_adapter_id;
426 
427  dssdev->panel.timings = pico_ls_timings;
428 
429  picod = kzalloc(sizeof(struct picodlp_data), GFP_KERNEL);
430  if (!picod)
431  return -ENOMEM;
432 
433  mutex_init(&picod->lock);
434 
435  picodlp_adapter_id = picodlp_pdata->picodlp_adapter_id;
436 
437  adapter = i2c_get_adapter(picodlp_adapter_id);
438  if (!adapter) {
439  dev_err(&dssdev->dev, "can't get i2c adapter\n");
440  r = -ENODEV;
441  goto err;
442  }
443 
444  picodlp_i2c_client = i2c_new_device(adapter, &picodlp_i2c_board_info);
445  if (!picodlp_i2c_client) {
446  dev_err(&dssdev->dev, "can't add i2c device::"
447  " picodlp_i2c_client is NULL\n");
448  r = -ENODEV;
449  goto err;
450  }
451 
452  picod->picodlp_i2c_client = picodlp_i2c_client;
453 
454  dev_set_drvdata(&dssdev->dev, picod);
455  return r;
456 err:
457  kfree(picod);
458  return r;
459 }
460 
461 static void picodlp_panel_remove(struct omap_dss_device *dssdev)
462 {
463  struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
464 
466  dev_set_drvdata(&dssdev->dev, NULL);
467  dev_dbg(&dssdev->dev, "removing picodlp panel\n");
468 
469  kfree(picod);
470 }
471 
472 static int picodlp_panel_enable(struct omap_dss_device *dssdev)
473 {
474  struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
475  int r;
476 
477  dev_dbg(&dssdev->dev, "enabling picodlp panel\n");
478 
479  mutex_lock(&picod->lock);
480  if (dssdev->state != OMAP_DSS_DISPLAY_DISABLED) {
481  mutex_unlock(&picod->lock);
482  return -EINVAL;
483  }
484 
485  r = picodlp_panel_power_on(dssdev);
486  mutex_unlock(&picod->lock);
487 
488  return r;
489 }
490 
491 static void picodlp_panel_disable(struct omap_dss_device *dssdev)
492 {
493  struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
494 
495  mutex_lock(&picod->lock);
496  /* Turn off DLP Power */
497  if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
498  picodlp_panel_power_off(dssdev);
499 
501  mutex_unlock(&picod->lock);
502 
503  dev_dbg(&dssdev->dev, "disabling picodlp panel\n");
504 }
505 
506 static int picodlp_panel_suspend(struct omap_dss_device *dssdev)
507 {
508  struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
509 
510  mutex_lock(&picod->lock);
511  /* Turn off DLP Power */
512  if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE) {
513  mutex_unlock(&picod->lock);
514  dev_err(&dssdev->dev, "unable to suspend picodlp panel,"
515  " panel is not ACTIVE\n");
516  return -EINVAL;
517  }
518 
519  picodlp_panel_power_off(dssdev);
520 
522  mutex_unlock(&picod->lock);
523 
524  dev_dbg(&dssdev->dev, "suspending picodlp panel\n");
525  return 0;
526 }
527 
528 static int picodlp_panel_resume(struct omap_dss_device *dssdev)
529 {
530  struct picodlp_data *picod = dev_get_drvdata(&dssdev->dev);
531  int r;
532 
533  mutex_lock(&picod->lock);
534  if (dssdev->state != OMAP_DSS_DISPLAY_SUSPENDED) {
535  mutex_unlock(&picod->lock);
536  dev_err(&dssdev->dev, "unable to resume picodlp panel,"
537  " panel is not ACTIVE\n");
538  return -EINVAL;
539  }
540 
541  r = picodlp_panel_power_on(dssdev);
542  mutex_unlock(&picod->lock);
543  dev_dbg(&dssdev->dev, "resuming picodlp panel\n");
544  return r;
545 }
546 
547 static void picodlp_get_resolution(struct omap_dss_device *dssdev,
548  u16 *xres, u16 *yres)
549 {
550  *xres = dssdev->panel.timings.x_res;
551  *yres = dssdev->panel.timings.y_res;
552 }
553 
554 static struct omap_dss_driver picodlp_driver = {
555  .probe = picodlp_panel_probe,
556  .remove = picodlp_panel_remove,
557 
558  .enable = picodlp_panel_enable,
559  .disable = picodlp_panel_disable,
560 
561  .get_resolution = picodlp_get_resolution,
562 
563  .suspend = picodlp_panel_suspend,
564  .resume = picodlp_panel_resume,
565 
566  .driver = {
567  .name = "picodlp_panel",
568  .owner = THIS_MODULE,
569  },
570 };
571 
572 static int __init picodlp_init(void)
573 {
574  int r = 0;
575 
576  r = i2c_add_driver(&picodlp_i2c_driver);
577  if (r) {
578  printk(KERN_WARNING "picodlp_i2c_driver" \
579  " registration failed\n");
580  return r;
581  }
582 
583  r = omap_dss_register_driver(&picodlp_driver);
584  if (r)
585  i2c_del_driver(&picodlp_i2c_driver);
586 
587  return r;
588 }
589 
590 static void __exit picodlp_exit(void)
591 {
592  i2c_del_driver(&picodlp_i2c_driver);
593  omap_dss_unregister_driver(&picodlp_driver);
594 }
595 
596 module_init(picodlp_init);
597 module_exit(picodlp_exit);
598 
599 MODULE_AUTHOR("Mythri P K <[email protected]>");
600 MODULE_DESCRIPTION("picodlp driver");
601 MODULE_LICENSE("GPL");