ep93xx_bl.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <linux/fb.h>
  17. #include <linux/backlight.h>
  18. #include <mach/hardware.h>
  19. #define EP93XX_RASTER_REG(x) (EP93XX_RASTER_BASE + (x))
  20. #define EP93XX_RASTER_BRIGHTNESS EP93XX_RASTER_REG(0x20)
  21. #define EP93XX_MAX_COUNT 255
  22. #define EP93XX_MAX_BRIGHT 255
  23. #define EP93XX_DEF_BRIGHT 128
  24. struct ep93xxbl {
  25. void __iomem *mmio;
  26. int brightness;
  27. };
  28. static int ep93xxbl_set(struct backlight_device *bl, int brightness)
  29. {
  30. struct ep93xxbl *ep93xxbl = bl_get_data(bl);
  31. __raw_writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio);
  32. ep93xxbl->brightness = brightness;
  33. return 0;
  34. }
  35. static int ep93xxbl_update_status(struct backlight_device *bl)
  36. {
  37. int brightness = bl->props.brightness;
  38. if (bl->props.power != FB_BLANK_UNBLANK ||
  39. bl->props.fb_blank != FB_BLANK_UNBLANK)
  40. brightness = 0;
  41. return ep93xxbl_set(bl, brightness);
  42. }
  43. static int ep93xxbl_get_brightness(struct backlight_device *bl)
  44. {
  45. struct ep93xxbl *ep93xxbl = bl_get_data(bl);
  46. return ep93xxbl->brightness;
  47. }
  48. static const struct backlight_ops ep93xxbl_ops = {
  49. .update_status = ep93xxbl_update_status,
  50. .get_brightness = ep93xxbl_get_brightness,
  51. };
  52. static int __init ep93xxbl_probe(struct platform_device *dev)
  53. {
  54. struct ep93xxbl *ep93xxbl;
  55. struct backlight_device *bl;
  56. struct backlight_properties props;
  57. ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL);
  58. if (!ep93xxbl)
  59. return -ENOMEM;
  60. /*
  61. * This register is located in the range already ioremap'ed by
  62. * the framebuffer driver. A MFD driver seems a bit of overkill
  63. * to handle this so use the static I/O mapping; this address
  64. * is already virtual.
  65. *
  66. * NOTE: No locking is required; the framebuffer does not touch
  67. * this register.
  68. */
  69. ep93xxbl->mmio = EP93XX_RASTER_BRIGHTNESS;
  70. memset(&props, 0, sizeof(struct backlight_properties));
  71. props.type = BACKLIGHT_RAW;
  72. props.max_brightness = EP93XX_MAX_BRIGHT;
  73. bl = backlight_device_register(dev->name, &dev->dev, ep93xxbl,
  74. &ep93xxbl_ops, &props);
  75. if (IS_ERR(bl))
  76. return PTR_ERR(bl);
  77. bl->props.brightness = EP93XX_DEF_BRIGHT;
  78. platform_set_drvdata(dev, bl);
  79. ep93xxbl_update_status(bl);
  80. return 0;
  81. }
  82. static int ep93xxbl_remove(struct platform_device *dev)
  83. {
  84. struct backlight_device *bl = platform_get_drvdata(dev);
  85. backlight_device_unregister(bl);
  86. platform_set_drvdata(dev, NULL);
  87. return 0;
  88. }
  89. #ifdef CONFIG_PM
  90. static int ep93xxbl_suspend(struct platform_device *dev, pm_message_t state)
  91. {
  92. struct backlight_device *bl = platform_get_drvdata(dev);
  93. return ep93xxbl_set(bl, 0);
  94. }
  95. static int ep93xxbl_resume(struct platform_device *dev)
  96. {
  97. struct backlight_device *bl = platform_get_drvdata(dev);
  98. backlight_update_status(bl);
  99. return 0;
  100. }
  101. #else
  102. #define ep93xxbl_suspend NULL
  103. #define ep93xxbl_resume NULL
  104. #endif
  105. static struct platform_driver ep93xxbl_driver = {
  106. .driver = {
  107. .name = "ep93xx-bl",
  108. .owner = THIS_MODULE,
  109. },
  110. .probe = ep93xxbl_probe,
  111. .remove = __devexit_p(ep93xxbl_remove),
  112. .suspend = ep93xxbl_suspend,
  113. .resume = ep93xxbl_resume,
  114. };
  115. module_platform_driver(ep93xxbl_driver);
  116. MODULE_DESCRIPTION("EP93xx Backlight Driver");
  117. MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
  118. MODULE_LICENSE("GPL");
  119. MODULE_ALIAS("platform:ep93xx-bl");