panel-sharp-ls037v7dw01.c 5.1 KB

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