ep93xx_bl.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Driver for the Cirrus EP93xx lcd backlight
  3. *
  4. * Copyright (c) 2010 H Hartley Sweeten <hsweeten@visionengravers.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This driver controls the pulse width modulated brightness control output,
  11. * BRIGHT, on the Cirrus EP9307, EP9312, and EP9315 processors.
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/io.h>
  15. #include <linux/fb.h>
  16. #include <linux/backlight.h>
  17. #include <mach/hardware.h>
  18. #define EP93XX_RASTER_REG(x) (EP93XX_RASTER_BASE + (x))
  19. #define EP93XX_RASTER_BRIGHTNESS EP93XX_RASTER_REG(0x20)
  20. #define EP93XX_MAX_COUNT 255
  21. #define EP93XX_MAX_BRIGHT 255
  22. #define EP93XX_DEF_BRIGHT 128
  23. struct ep93xxbl {
  24. void __iomem *mmio;
  25. int brightness;
  26. };
  27. static int ep93xxbl_set(struct backlight_device *bl, int brightness)
  28. {
  29. struct ep93xxbl *ep93xxbl = bl_get_data(bl);
  30. __raw_writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio);
  31. ep93xxbl->brightness = brightness;
  32. return 0;
  33. }
  34. static int ep93xxbl_update_status(struct backlight_device *bl)
  35. {
  36. int brightness = bl->props.brightness;
  37. if (bl->props.power != FB_BLANK_UNBLANK ||
  38. bl->props.fb_blank != FB_BLANK_UNBLANK)
  39. brightness = 0;
  40. return ep93xxbl_set(bl, brightness);
  41. }
  42. static int ep93xxbl_get_brightness(struct backlight_device *bl)
  43. {
  44. struct ep93xxbl *ep93xxbl = bl_get_data(bl);
  45. return ep93xxbl->brightness;
  46. }
  47. static const struct backlight_ops ep93xxbl_ops = {
  48. .update_status = ep93xxbl_update_status,
  49. .get_brightness = ep93xxbl_get_brightness,
  50. };
  51. static int __init ep93xxbl_probe(struct platform_device *dev)
  52. {
  53. struct ep93xxbl *ep93xxbl;
  54. struct backlight_device *bl;
  55. struct backlight_properties props;
  56. ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL);
  57. if (!ep93xxbl)
  58. return -ENOMEM;
  59. /*
  60. * This register is located in the range already ioremap'ed by
  61. * the framebuffer driver. A MFD driver seems a bit of overkill
  62. * to handle this so use the static I/O mapping; this address
  63. * is already virtual.
  64. *
  65. * NOTE: No locking is required; the framebuffer does not touch
  66. * this register.
  67. */
  68. ep93xxbl->mmio = EP93XX_RASTER_BRIGHTNESS;
  69. memset(&props, 0, sizeof(struct backlight_properties));
  70. props.type = BACKLIGHT_RAW;
  71. props.max_brightness = EP93XX_MAX_BRIGHT;
  72. bl = backlight_device_register(dev->name, &dev->dev, ep93xxbl,
  73. &ep93xxbl_ops, &props);
  74. if (IS_ERR(bl))
  75. return PTR_ERR(bl);
  76. bl->props.brightness = EP93XX_DEF_BRIGHT;
  77. platform_set_drvdata(dev, bl);
  78. ep93xxbl_update_status(bl);
  79. return 0;
  80. }
  81. static int ep93xxbl_remove(struct platform_device *dev)
  82. {
  83. struct backlight_device *bl = platform_get_drvdata(dev);
  84. backlight_device_unregister(bl);
  85. platform_set_drvdata(dev, NULL);
  86. return 0;
  87. }
  88. #ifdef CONFIG_PM
  89. static int ep93xxbl_suspend(struct platform_device *dev, pm_message_t state)
  90. {
  91. struct backlight_device *bl = platform_get_drvdata(dev);
  92. return ep93xxbl_set(bl, 0);
  93. }
  94. static int ep93xxbl_resume(struct platform_device *dev)
  95. {
  96. struct backlight_device *bl = platform_get_drvdata(dev);
  97. backlight_update_status(bl);
  98. return 0;
  99. }
  100. #else
  101. #define ep93xxbl_suspend NULL
  102. #define ep93xxbl_resume NULL
  103. #endif
  104. static struct platform_driver ep93xxbl_driver = {
  105. .driver = {
  106. .name = "ep93xx-bl",
  107. .owner = THIS_MODULE,
  108. },
  109. .probe = ep93xxbl_probe,
  110. .remove = __devexit_p(ep93xxbl_remove),
  111. .suspend = ep93xxbl_suspend,
  112. .resume = ep93xxbl_resume,
  113. };
  114. static int __init ep93xxbl_init(void)
  115. {
  116. return platform_driver_register(&ep93xxbl_driver);
  117. }
  118. module_init(ep93xxbl_init);
  119. static void __exit ep93xxbl_exit(void)
  120. {
  121. platform_driver_unregister(&ep93xxbl_driver);
  122. }
  123. module_exit(ep93xxbl_exit);
  124. MODULE_DESCRIPTION("EP93xx Backlight Driver");
  125. MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
  126. MODULE_LICENSE("GPL");
  127. MODULE_ALIAS("platform:ep93xx-bl");