panel-sharp-ls037v7dw01.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * LCD panel driver for Sharp LS037V7DW01
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/delay.h>
  21. #include <linux/device.h>
  22. #include <linux/backlight.h>
  23. #include <linux/fb.h>
  24. #include <linux/err.h>
  25. #include <linux/slab.h>
  26. #include <video/omapdss.h>
  27. struct sharp_data {
  28. struct backlight_device *bl;
  29. };
  30. static struct omap_video_timings sharp_ls_timings = {
  31. .x_res = 480,
  32. .y_res = 640,
  33. .pixel_clock = 19200,
  34. .hsw = 2,
  35. .hfp = 1,
  36. .hbp = 28,
  37. .vsw = 1,
  38. .vfp = 1,
  39. .vbp = 1,
  40. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  41. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  42. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  43. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  44. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
  45. };
  46. static int sharp_ls_bl_update_status(struct backlight_device *bl)
  47. {
  48. struct omap_dss_device *dssdev = dev_get_drvdata(&bl->dev);
  49. int level;
  50. if (!dssdev->set_backlight)
  51. return -EINVAL;
  52. if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
  53. bl->props.power == FB_BLANK_UNBLANK)
  54. level = bl->props.brightness;
  55. else
  56. level = 0;
  57. return dssdev->set_backlight(dssdev, level);
  58. }
  59. static int sharp_ls_bl_get_brightness(struct backlight_device *bl)
  60. {
  61. if (bl->props.fb_blank == FB_BLANK_UNBLANK &&
  62. bl->props.power == FB_BLANK_UNBLANK)
  63. return bl->props.brightness;
  64. return 0;
  65. }
  66. static const struct backlight_ops sharp_ls_bl_ops = {
  67. .get_brightness = sharp_ls_bl_get_brightness,
  68. .update_status = sharp_ls_bl_update_status,
  69. };
  70. static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
  71. {
  72. struct backlight_properties props;
  73. struct backlight_device *bl;
  74. struct sharp_data *sd;
  75. int r;
  76. dssdev->panel.timings = sharp_ls_timings;
  77. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  78. if (!sd)
  79. return -ENOMEM;
  80. dev_set_drvdata(&dssdev->dev, sd);
  81. memset(&props, 0, sizeof(struct backlight_properties));
  82. props.max_brightness = dssdev->max_backlight_level;
  83. props.type = BACKLIGHT_RAW;
  84. bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
  85. &sharp_ls_bl_ops, &props);
  86. if (IS_ERR(bl)) {
  87. r = PTR_ERR(bl);
  88. kfree(sd);
  89. return r;
  90. }
  91. sd->bl = bl;
  92. bl->props.fb_blank = FB_BLANK_UNBLANK;
  93. bl->props.power = FB_BLANK_UNBLANK;
  94. bl->props.brightness = dssdev->max_backlight_level;
  95. r = sharp_ls_bl_update_status(bl);
  96. if (r < 0)
  97. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  98. return 0;
  99. }
  100. static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
  101. {
  102. struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
  103. struct backlight_device *bl = sd->bl;
  104. bl->props.power = FB_BLANK_POWERDOWN;
  105. sharp_ls_bl_update_status(bl);
  106. backlight_device_unregister(bl);
  107. kfree(sd);
  108. }
  109. static int sharp_ls_power_on(struct omap_dss_device *dssdev)
  110. {
  111. int r = 0;
  112. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  113. return 0;
  114. omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
  115. omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
  116. r = omapdss_dpi_display_enable(dssdev);
  117. if (r)
  118. goto err0;
  119. /* wait couple of vsyncs until enabling the LCD */
  120. msleep(50);
  121. if (dssdev->platform_enable) {
  122. r = dssdev->platform_enable(dssdev);
  123. if (r)
  124. goto err1;
  125. }
  126. return 0;
  127. err1:
  128. omapdss_dpi_display_disable(dssdev);
  129. err0:
  130. return r;
  131. }
  132. static void sharp_ls_power_off(struct omap_dss_device *dssdev)
  133. {
  134. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  135. return;
  136. if (dssdev->platform_disable)
  137. dssdev->platform_disable(dssdev);
  138. /* wait at least 5 vsyncs after disabling the LCD */
  139. msleep(100);
  140. omapdss_dpi_display_disable(dssdev);
  141. }
  142. static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
  143. {
  144. int r;
  145. r = sharp_ls_power_on(dssdev);
  146. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  147. return r;
  148. }
  149. static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
  150. {
  151. sharp_ls_power_off(dssdev);
  152. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  153. }
  154. static struct omap_dss_driver sharp_ls_driver = {
  155. .probe = sharp_ls_panel_probe,
  156. .remove = __exit_p(sharp_ls_panel_remove),
  157. .enable = sharp_ls_panel_enable,
  158. .disable = sharp_ls_panel_disable,
  159. .driver = {
  160. .name = "sharp_ls_panel",
  161. .owner = THIS_MODULE,
  162. },
  163. };
  164. static int __init sharp_ls_panel_drv_init(void)
  165. {
  166. return omap_dss_register_driver(&sharp_ls_driver);
  167. }
  168. static void __exit sharp_ls_panel_drv_exit(void)
  169. {
  170. omap_dss_unregister_driver(&sharp_ls_driver);
  171. }
  172. module_init(sharp_ls_panel_drv_init);
  173. module_exit(sharp_ls_panel_drv_exit);
  174. MODULE_LICENSE("GPL");