panel-sharp-ls037v7dw01.c 5.1 KB

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