omap1_bl.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 <linux/platform_data/omap1_bl.h>
  28. #include <mach/hardware.h>
  29. #include <mach/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 inline void omapbl_send_intensity(int intensity)
  38. {
  39. omap_writeb(intensity, OMAP_PWL_ENABLE);
  40. }
  41. static inline void 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_SLEEP
  64. static int omapbl_suspend(struct device *dev)
  65. {
  66. struct backlight_device *bl_dev = dev_get_drvdata(dev);
  67. struct omap_backlight *bl = bl_get_data(bl_dev);
  68. omapbl_blank(bl, FB_BLANK_POWERDOWN);
  69. return 0;
  70. }
  71. static int omapbl_resume(struct device *dev)
  72. {
  73. struct backlight_device *bl_dev = dev_get_drvdata(dev);
  74. struct omap_backlight *bl = bl_get_data(bl_dev);
  75. omapbl_blank(bl, bl->powermode);
  76. return 0;
  77. }
  78. #endif
  79. static int omapbl_set_power(struct backlight_device *dev, int state)
  80. {
  81. struct omap_backlight *bl = bl_get_data(dev);
  82. omapbl_blank(bl, state);
  83. bl->powermode = state;
  84. return 0;
  85. }
  86. static int omapbl_update_status(struct backlight_device *dev)
  87. {
  88. struct omap_backlight *bl = bl_get_data(dev);
  89. if (bl->current_intensity != dev->props.brightness) {
  90. if (bl->powermode == FB_BLANK_UNBLANK)
  91. omapbl_send_intensity(dev->props.brightness);
  92. bl->current_intensity = dev->props.brightness;
  93. }
  94. if (dev->props.fb_blank != bl->powermode)
  95. omapbl_set_power(dev, dev->props.fb_blank);
  96. return 0;
  97. }
  98. static int omapbl_get_intensity(struct backlight_device *dev)
  99. {
  100. struct omap_backlight *bl = bl_get_data(dev);
  101. return bl->current_intensity;
  102. }
  103. static const struct backlight_ops omapbl_ops = {
  104. .get_brightness = omapbl_get_intensity,
  105. .update_status = omapbl_update_status,
  106. };
  107. static int omapbl_probe(struct platform_device *pdev)
  108. {
  109. struct backlight_properties props;
  110. struct backlight_device *dev;
  111. struct omap_backlight *bl;
  112. struct omap_backlight_config *pdata = dev_get_platdata(&pdev->dev);
  113. if (!pdata)
  114. return -ENXIO;
  115. bl = devm_kzalloc(&pdev->dev, sizeof(struct omap_backlight),
  116. GFP_KERNEL);
  117. if (unlikely(!bl))
  118. return -ENOMEM;
  119. memset(&props, 0, sizeof(struct backlight_properties));
  120. props.type = BACKLIGHT_RAW;
  121. props.max_brightness = OMAPBL_MAX_INTENSITY;
  122. dev = devm_backlight_device_register(&pdev->dev, "omap-bl", &pdev->dev,
  123. bl, &omapbl_ops, &props);
  124. if (IS_ERR(dev))
  125. return PTR_ERR(dev);
  126. bl->powermode = FB_BLANK_POWERDOWN;
  127. bl->current_intensity = 0;
  128. bl->pdata = pdata;
  129. bl->dev = &pdev->dev;
  130. platform_set_drvdata(pdev, dev);
  131. omap_cfg_reg(PWL); /* Conflicts with UART3 */
  132. dev->props.fb_blank = FB_BLANK_UNBLANK;
  133. dev->props.brightness = pdata->default_intensity;
  134. omapbl_update_status(dev);
  135. dev_info(&pdev->dev, "OMAP LCD backlight initialised\n");
  136. return 0;
  137. }
  138. static SIMPLE_DEV_PM_OPS(omapbl_pm_ops, omapbl_suspend, omapbl_resume);
  139. static struct platform_driver omapbl_driver = {
  140. .probe = omapbl_probe,
  141. .driver = {
  142. .name = "omap-bl",
  143. .pm = &omapbl_pm_ops,
  144. },
  145. };
  146. module_platform_driver(omapbl_driver);
  147. MODULE_AUTHOR("Andrzej Zaborowski <balrog@zabor.org>");
  148. MODULE_DESCRIPTION("OMAP LCD Backlight driver");
  149. MODULE_LICENSE("GPL");