ep93xx_bl.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for the Cirrus EP93xx lcd backlight
  4. *
  5. * Copyright (c) 2010 H Hartley Sweeten <hsweeten@visionengravers.com>
  6. *
  7. * This driver controls the pulse width modulated brightness control output,
  8. * BRIGHT, on the Cirrus EP9307, EP9312, and EP9315 processors.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/io.h>
  13. #include <linux/fb.h>
  14. #include <linux/backlight.h>
  15. #define EP93XX_MAX_COUNT 255
  16. #define EP93XX_MAX_BRIGHT 255
  17. #define EP93XX_DEF_BRIGHT 128
  18. struct ep93xxbl {
  19. void __iomem *mmio;
  20. int brightness;
  21. };
  22. static int ep93xxbl_set(struct backlight_device *bl, int brightness)
  23. {
  24. struct ep93xxbl *ep93xxbl = bl_get_data(bl);
  25. writel((brightness << 8) | EP93XX_MAX_COUNT, ep93xxbl->mmio);
  26. ep93xxbl->brightness = brightness;
  27. return 0;
  28. }
  29. static int ep93xxbl_update_status(struct backlight_device *bl)
  30. {
  31. return ep93xxbl_set(bl, backlight_get_brightness(bl));
  32. }
  33. static int ep93xxbl_get_brightness(struct backlight_device *bl)
  34. {
  35. struct ep93xxbl *ep93xxbl = bl_get_data(bl);
  36. return ep93xxbl->brightness;
  37. }
  38. static const struct backlight_ops ep93xxbl_ops = {
  39. .update_status = ep93xxbl_update_status,
  40. .get_brightness = ep93xxbl_get_brightness,
  41. };
  42. static int ep93xxbl_probe(struct platform_device *dev)
  43. {
  44. struct ep93xxbl *ep93xxbl;
  45. struct backlight_device *bl;
  46. struct backlight_properties props;
  47. struct resource *res;
  48. ep93xxbl = devm_kzalloc(&dev->dev, sizeof(*ep93xxbl), GFP_KERNEL);
  49. if (!ep93xxbl)
  50. return -ENOMEM;
  51. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  52. if (!res)
  53. return -ENXIO;
  54. /*
  55. * FIXME - We don't do a request_mem_region here because we are
  56. * sharing the register space with the framebuffer driver (see
  57. * drivers/video/ep93xx-fb.c) and doing so will cause the second
  58. * loaded driver to return -EBUSY.
  59. *
  60. * NOTE: No locking is required; the framebuffer does not touch
  61. * this register.
  62. */
  63. ep93xxbl->mmio = devm_ioremap(&dev->dev, res->start,
  64. resource_size(res));
  65. if (!ep93xxbl->mmio)
  66. return -ENXIO;
  67. memset(&props, 0, sizeof(struct backlight_properties));
  68. props.type = BACKLIGHT_RAW;
  69. props.max_brightness = EP93XX_MAX_BRIGHT;
  70. bl = devm_backlight_device_register(&dev->dev, dev->name, &dev->dev,
  71. ep93xxbl, &ep93xxbl_ops, &props);
  72. if (IS_ERR(bl))
  73. return PTR_ERR(bl);
  74. bl->props.brightness = EP93XX_DEF_BRIGHT;
  75. platform_set_drvdata(dev, bl);
  76. ep93xxbl_update_status(bl);
  77. return 0;
  78. }
  79. #ifdef CONFIG_PM_SLEEP
  80. static int ep93xxbl_suspend(struct device *dev)
  81. {
  82. struct backlight_device *bl = dev_get_drvdata(dev);
  83. return ep93xxbl_set(bl, 0);
  84. }
  85. static int ep93xxbl_resume(struct device *dev)
  86. {
  87. struct backlight_device *bl = dev_get_drvdata(dev);
  88. backlight_update_status(bl);
  89. return 0;
  90. }
  91. #endif
  92. static SIMPLE_DEV_PM_OPS(ep93xxbl_pm_ops, ep93xxbl_suspend, ep93xxbl_resume);
  93. static struct platform_driver ep93xxbl_driver = {
  94. .driver = {
  95. .name = "ep93xx-bl",
  96. .pm = &ep93xxbl_pm_ops,
  97. },
  98. .probe = ep93xxbl_probe,
  99. };
  100. module_platform_driver(ep93xxbl_driver);
  101. MODULE_DESCRIPTION("EP93xx Backlight Driver");
  102. MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
  103. MODULE_LICENSE("GPL");
  104. MODULE_ALIAS("platform:ep93xx-bl");