panel-sharp-ls037v7dw01.c 5.1 KB

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