panel-sharp-ls037v7dw01.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.config = OMAP_DSS_LCD_IVS | OMAP_DSS_LCD_IHS;
  77. dssdev->panel.timings = sharp_ls_timings;
  78. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  79. if (!sd)
  80. return -ENOMEM;
  81. dev_set_drvdata(&dssdev->dev, sd);
  82. memset(&props, 0, sizeof(struct backlight_properties));
  83. props.max_brightness = dssdev->max_backlight_level;
  84. props.type = BACKLIGHT_RAW;
  85. bl = backlight_device_register("sharp-ls", &dssdev->dev, dssdev,
  86. &sharp_ls_bl_ops, &props);
  87. if (IS_ERR(bl)) {
  88. r = PTR_ERR(bl);
  89. kfree(sd);
  90. return r;
  91. }
  92. sd->bl = bl;
  93. bl->props.fb_blank = FB_BLANK_UNBLANK;
  94. bl->props.power = FB_BLANK_UNBLANK;
  95. bl->props.brightness = dssdev->max_backlight_level;
  96. r = sharp_ls_bl_update_status(bl);
  97. if (r < 0)
  98. dev_err(&dssdev->dev, "failed to set lcd brightness\n");
  99. return 0;
  100. }
  101. static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
  102. {
  103. struct sharp_data *sd = dev_get_drvdata(&dssdev->dev);
  104. struct backlight_device *bl = sd->bl;
  105. bl->props.power = FB_BLANK_POWERDOWN;
  106. sharp_ls_bl_update_status(bl);
  107. backlight_device_unregister(bl);
  108. kfree(sd);
  109. }
  110. static int sharp_ls_power_on(struct omap_dss_device *dssdev)
  111. {
  112. int r = 0;
  113. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  114. return 0;
  115. r = omapdss_dpi_display_enable(dssdev);
  116. if (r)
  117. goto err0;
  118. /* wait couple of vsyncs until enabling the LCD */
  119. msleep(50);
  120. if (dssdev->platform_enable) {
  121. r = dssdev->platform_enable(dssdev);
  122. if (r)
  123. goto err1;
  124. }
  125. return 0;
  126. err1:
  127. omapdss_dpi_display_disable(dssdev);
  128. err0:
  129. return r;
  130. }
  131. static void sharp_ls_power_off(struct omap_dss_device *dssdev)
  132. {
  133. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  134. return;
  135. if (dssdev->platform_disable)
  136. dssdev->platform_disable(dssdev);
  137. /* wait at least 5 vsyncs after disabling the LCD */
  138. msleep(100);
  139. omapdss_dpi_display_disable(dssdev);
  140. }
  141. static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
  142. {
  143. int r;
  144. r = sharp_ls_power_on(dssdev);
  145. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  146. return r;
  147. }
  148. static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
  149. {
  150. sharp_ls_power_off(dssdev);
  151. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  152. }
  153. static int sharp_ls_panel_suspend(struct omap_dss_device *dssdev)
  154. {
  155. sharp_ls_power_off(dssdev);
  156. dssdev->state = OMAP_DSS_DISPLAY_SUSPENDED;
  157. return 0;
  158. }
  159. static int sharp_ls_panel_resume(struct omap_dss_device *dssdev)
  160. {
  161. int r;
  162. r = sharp_ls_power_on(dssdev);
  163. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  164. return r;
  165. }
  166. static struct omap_dss_driver sharp_ls_driver = {
  167. .probe = sharp_ls_panel_probe,
  168. .remove = __exit_p(sharp_ls_panel_remove),
  169. .enable = sharp_ls_panel_enable,
  170. .disable = sharp_ls_panel_disable,
  171. .suspend = sharp_ls_panel_suspend,
  172. .resume = sharp_ls_panel_resume,
  173. .driver = {
  174. .name = "sharp_ls_panel",
  175. .owner = THIS_MODULE,
  176. },
  177. };
  178. static int __init sharp_ls_panel_drv_init(void)
  179. {
  180. return omap_dss_register_driver(&sharp_ls_driver);
  181. }
  182. static void __exit sharp_ls_panel_drv_exit(void)
  183. {
  184. omap_dss_unregister_driver(&sharp_ls_driver);
  185. }
  186. module_init(sharp_ls_panel_drv_init);
  187. module_exit(sharp_ls_panel_drv_exit);
  188. MODULE_LICENSE("GPL");