omap1_bl.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Backlight driver for OMAP based boards.
  3. *
  4. * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
  5. *
  6. * This package is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this package; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/fb.h>
  25. #include <linux/backlight.h>
  26. #include <linux/slab.h>
  27. #include <mach/hardware.h>
  28. #include <plat/board.h>
  29. #include <plat/mux.h>
  30. #define OMAPBL_MAX_INTENSITY 0xff
  31. struct omap_backlight {
  32. int powermode;
  33. int current_intensity;
  34. struct device *dev;
  35. struct omap_backlight_config *pdata;
  36. };
  37. static void inline omapbl_send_intensity(int intensity)
  38. {
  39. omap_writeb(intensity, OMAP_PWL_ENABLE);
  40. }
  41. static void inline omapbl_send_enable(int enable)
  42. {
  43. omap_writeb(enable, OMAP_PWL_CLK_ENABLE);
  44. }
  45. static void omapbl_blank(struct omap_backlight *bl, int mode)
  46. {
  47. if (bl->pdata->set_power)
  48. bl->pdata->set_power(bl->dev, mode);
  49. switch (mode) {
  50. case FB_BLANK_NORMAL:
  51. case FB_BLANK_VSYNC_SUSPEND:
  52. case FB_BLANK_HSYNC_SUSPEND:
  53. case FB_BLANK_POWERDOWN:
  54. omapbl_send_intensity(0);
  55. omapbl_send_enable(0);
  56. break;
  57. case FB_BLANK_UNBLANK:
  58. omapbl_send_intensity(bl->current_intensity);
  59. omapbl_send_enable(1);
  60. break;
  61. }
  62. }
  63. #ifdef CONFIG_PM
  64. static int omapbl_suspend(struct platform_device *pdev, pm_message_t state)
  65. {
  66. struct backlight_device *dev = platform_get_drvdata(pdev);
  67. struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
  68. omapbl_blank(bl, FB_BLANK_POWERDOWN);
  69. return 0;
  70. }
  71. static int omapbl_resume(struct platform_device *pdev)
  72. {
  73. struct backlight_device *dev = platform_get_drvdata(pdev);
  74. struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
  75. omapbl_blank(bl, bl->powermode);
  76. return 0;
  77. }
  78. #else
  79. #define omapbl_suspend NULL
  80. #define omapbl_resume NULL
  81. #endif
  82. static int omapbl_set_power(struct backlight_device *dev, int state)
  83. {
  84. struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
  85. omapbl_blank(bl, state);
  86. bl->powermode = state;
  87. return 0;
  88. }
  89. static int omapbl_update_status(struct backlight_device *dev)
  90. {
  91. struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
  92. if (bl->current_intensity != dev->props.brightness) {
  93. if (bl->powermode == FB_BLANK_UNBLANK)
  94. omapbl_send_intensity(dev->props.brightness);
  95. bl->current_intensity = dev->props.brightness;
  96. }
  97. if (dev->props.fb_blank != bl->powermode)
  98. omapbl_set_power(dev, dev->props.fb_blank);
  99. return 0;
  100. }
  101. static int omapbl_get_intensity(struct backlight_device *dev)
  102. {
  103. struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
  104. return bl->current_intensity;
  105. }
  106. static const struct backlight_ops omapbl_ops = {
  107. .get_brightness = omapbl_get_intensity,
  108. .update_status = omapbl_update_status,
  109. };
  110. static int omapbl_probe(struct platform_device *pdev)
  111. {
  112. struct backlight_properties props;
  113. struct backlight_device *dev;
  114. struct omap_backlight *bl;
  115. struct omap_backlight_config *pdata = pdev->dev.platform_data;
  116. if (!pdata)
  117. return -ENXIO;
  118. bl = kzalloc(sizeof(struct omap_backlight), GFP_KERNEL);
  119. if (unlikely(!bl))
  120. return -ENOMEM;
  121. memset(&props, 0, sizeof(struct backlight_properties));
  122. props.type = BACKLIGHT_RAW;
  123. props.max_brightness = OMAPBL_MAX_INTENSITY;
  124. dev = backlight_device_register("omap-bl", &pdev->dev, bl, &omapbl_ops,
  125. &props);
  126. if (IS_ERR(dev)) {
  127. kfree(bl);
  128. return PTR_ERR(dev);
  129. }
  130. bl->powermode = FB_BLANK_POWERDOWN;
  131. bl->current_intensity = 0;
  132. bl->pdata = pdata;
  133. bl->dev = &pdev->dev;
  134. platform_set_drvdata(pdev, dev);
  135. omap_cfg_reg(PWL); /* Conflicts with UART3 */
  136. dev->props.fb_blank = FB_BLANK_UNBLANK;
  137. dev->props.brightness = pdata->default_intensity;
  138. omapbl_update_status(dev);
  139. printk(KERN_INFO "OMAP LCD backlight initialised\n");
  140. return 0;
  141. }
  142. static int omapbl_remove(struct platform_device *pdev)
  143. {
  144. struct backlight_device *dev = platform_get_drvdata(pdev);
  145. struct omap_backlight *bl = dev_get_drvdata(&dev->dev);
  146. backlight_device_unregister(dev);
  147. kfree(bl);
  148. return 0;
  149. }
  150. static struct platform_driver omapbl_driver = {
  151. .probe = omapbl_probe,
  152. .remove = omapbl_remove,
  153. .suspend = omapbl_suspend,
  154. .resume = omapbl_resume,
  155. .driver = {
  156. .name = "omap-bl",
  157. },
  158. };
  159. static int __init omapbl_init(void)
  160. {
  161. return platform_driver_register(&omapbl_driver);
  162. }
  163. static void __exit omapbl_exit(void)
  164. {
  165. platform_driver_unregister(&omapbl_driver);
  166. }
  167. module_init(omapbl_init);
  168. module_exit(omapbl_exit);
  169. MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
  170. MODULE_DESCRIPTION("OMAP LCD Backlight driver");
  171. MODULE_LICENSE("GPL");