0087-rpi_display-add-backlight-driver-and-overlay.patch 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. From bfcb98a5f383cd1cdd08156f8f7267447ab1b7cd Mon Sep 17 00:00:00 2001
  2. From: P33M <P33M@github.com>
  3. Date: Wed, 21 Oct 2015 14:55:21 +0100
  4. Subject: [PATCH 087/381] rpi_display: add backlight driver and overlay
  5. Add a mailbox-driven backlight controller for the Raspberry Pi DSI
  6. touchscreen display. Requires updated GPU firmware to recognise the
  7. mailbox request.
  8. Signed-off-by: Gordon Hollingworth <gordon@raspberrypi.org>
  9. ---
  10. arch/arm/boot/dts/overlays/Makefile | 1 +
  11. arch/arm/boot/dts/overlays/README | 6 ++
  12. .../boot/dts/overlays/rpi-backlight-overlay.dts | 21 ++++
  13. arch/arm/configs/bcm2709_defconfig | 1 +
  14. arch/arm/configs/bcmrpi_defconfig | 1 +
  15. drivers/video/backlight/Kconfig | 6 ++
  16. drivers/video/backlight/Makefile | 1 +
  17. drivers/video/backlight/rpi_backlight.c | 119 +++++++++++++++++++++
  18. include/soc/bcm2835/raspberrypi-firmware.h | 1 +
  19. 9 files changed, 157 insertions(+)
  20. create mode 100644 arch/arm/boot/dts/overlays/rpi-backlight-overlay.dts
  21. create mode 100644 drivers/video/backlight/rpi_backlight.c
  22. --- a/arch/arm/boot/dts/overlays/Makefile
  23. +++ b/arch/arm/boot/dts/overlays/Makefile
  24. @@ -38,6 +38,7 @@ dtb-$(RPI_DT_OVERLAYS) += pps-gpio-overl
  25. dtb-$(RPI_DT_OVERLAYS) += pwm-overlay.dtb
  26. dtb-$(RPI_DT_OVERLAYS) += pwm-2chan-overlay.dtb
  27. dtb-$(RPI_DT_OVERLAYS) += raspidac3-overlay.dtb
  28. +dtb-$(RPI_DT_OVERLAYS) += rpi-backlight-overlay.dtb
  29. dtb-$(RPI_DT_OVERLAYS) += rpi-dac-overlay.dtb
  30. dtb-$(RPI_DT_OVERLAYS) += rpi-display-overlay.dtb
  31. dtb-$(RPI_DT_OVERLAYS) += rpi-ft5406-overlay.dtb
  32. --- a/arch/arm/boot/dts/overlays/README
  33. +++ b/arch/arm/boot/dts/overlays/README
  34. @@ -462,6 +462,12 @@ Load: dtoverlay=raspidac3
  35. Params: <None>
  36. +Name: rpi-backlight
  37. +Info: Raspberry Pi official display backlight driver
  38. +Load: dtoverlay=rpi-backlight
  39. +Params: <None>
  40. +
  41. +
  42. Name: rpi-dac
  43. Info: Configures the RPi DAC audio card
  44. Load: dtoverlay=rpi-dac
  45. --- /dev/null
  46. +++ b/arch/arm/boot/dts/overlays/rpi-backlight-overlay.dts
  47. @@ -0,0 +1,21 @@
  48. +/*
  49. + * Devicetree overlay for mailbox-driven Raspberry Pi DSI Display
  50. + * backlight controller
  51. + */
  52. +/dts-v1/;
  53. +/plugin/;
  54. +
  55. +/ {
  56. + compatible = "brcm,bcm2708";
  57. +
  58. + fragment@0 {
  59. + target-path = "/";
  60. + __overlay__ {
  61. + rpi_backlight: rpi_backlight {
  62. + compatible = "raspberrypi,rpi-backlight";
  63. + firmware = <&firmware>;
  64. + status = "okay";
  65. + };
  66. + };
  67. + };
  68. +};
  69. --- a/arch/arm/configs/bcm2709_defconfig
  70. +++ b/arch/arm/configs/bcm2709_defconfig
  71. @@ -808,6 +808,7 @@ CONFIG_FB_UDL=m
  72. CONFIG_FB_SSD1307=m
  73. CONFIG_FB_RPISENSE=m
  74. # CONFIG_BACKLIGHT_GENERIC is not set
  75. +CONFIG_BACKLIGHT_RPI=m
  76. CONFIG_BACKLIGHT_GPIO=m
  77. CONFIG_FRAMEBUFFER_CONSOLE=y
  78. CONFIG_LOGO=y
  79. --- a/arch/arm/configs/bcmrpi_defconfig
  80. +++ b/arch/arm/configs/bcmrpi_defconfig
  81. @@ -801,6 +801,7 @@ CONFIG_FB_UDL=m
  82. CONFIG_FB_SSD1307=m
  83. CONFIG_FB_RPISENSE=m
  84. # CONFIG_BACKLIGHT_GENERIC is not set
  85. +CONFIG_BACKLIGHT_RPI=m
  86. CONFIG_BACKLIGHT_GPIO=m
  87. CONFIG_FRAMEBUFFER_CONSOLE=y
  88. CONFIG_LOGO=y
  89. --- a/drivers/video/backlight/Kconfig
  90. +++ b/drivers/video/backlight/Kconfig
  91. @@ -265,6 +265,12 @@ config BACKLIGHT_PWM
  92. If you have a LCD backlight adjustable by PWM, say Y to enable
  93. this driver.
  94. +config BACKLIGHT_RPI
  95. + tristate "Raspberry Pi display firmware driven backlight"
  96. + help
  97. + If you have the Raspberry Pi DSI touchscreen display, say Y to
  98. + enable the mailbox-controlled backlight driver.
  99. +
  100. config BACKLIGHT_DA903X
  101. tristate "Backlight Driver for DA9030/DA9034 using WLED"
  102. depends on PMIC_DA903X
  103. --- a/drivers/video/backlight/Makefile
  104. +++ b/drivers/video/backlight/Makefile
  105. @@ -50,6 +50,7 @@ obj-$(CONFIG_BACKLIGHT_PANDORA) += pand
  106. obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o
  107. obj-$(CONFIG_BACKLIGHT_PM8941_WLED) += pm8941-wled.o
  108. obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
  109. +obj-$(CONFIG_BACKLIGHT_RPI) += rpi_backlight.o
  110. obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o
  111. obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o
  112. obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o
  113. --- /dev/null
  114. +++ b/drivers/video/backlight/rpi_backlight.c
  115. @@ -0,0 +1,119 @@
  116. +/*
  117. + * rpi_bl.c - Backlight controller through VPU
  118. + *
  119. + * This program is free software; you can redistribute it and/or modify
  120. + * it under the terms of the GNU General Public License version 2 as
  121. + * published by the Free Software Foundation.
  122. + */
  123. +
  124. +#include <linux/backlight.h>
  125. +#include <linux/err.h>
  126. +#include <linux/fb.h>
  127. +#include <linux/gpio.h>
  128. +#include <linux/init.h>
  129. +#include <linux/kernel.h>
  130. +#include <linux/module.h>
  131. +#include <linux/of.h>
  132. +#include <linux/of_gpio.h>
  133. +#include <linux/platform_device.h>
  134. +#include <linux/slab.h>
  135. +#include <soc/bcm2835/raspberrypi-firmware.h>
  136. +
  137. +struct rpi_backlight {
  138. + struct device *dev;
  139. + struct device *fbdev;
  140. + struct rpi_firmware *fw;
  141. +};
  142. +
  143. +static int rpi_backlight_update_status(struct backlight_device *bl)
  144. +{
  145. + struct rpi_backlight *gbl = bl_get_data(bl);
  146. + int brightness = bl->props.brightness;
  147. + int ret;
  148. +
  149. + if (bl->props.power != FB_BLANK_UNBLANK ||
  150. + bl->props.fb_blank != FB_BLANK_UNBLANK ||
  151. + bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
  152. + brightness = 0;
  153. +
  154. + ret = rpi_firmware_property(gbl->fw,
  155. + RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT,
  156. + &brightness, sizeof(brightness));
  157. + if (ret) {
  158. + dev_err(gbl->dev, "Failed to set brightness\n");
  159. + return ret;
  160. + }
  161. +
  162. + if (brightness < 0) {
  163. + dev_err(gbl->dev, "Backlight change failed\n");
  164. + return -EAGAIN;
  165. + }
  166. +
  167. + return 0;
  168. +}
  169. +
  170. +static const struct backlight_ops rpi_backlight_ops = {
  171. + .options = BL_CORE_SUSPENDRESUME,
  172. + .update_status = rpi_backlight_update_status,
  173. +};
  174. +
  175. +static int rpi_backlight_probe(struct platform_device *pdev)
  176. +{
  177. + struct backlight_properties props;
  178. + struct backlight_device *bl;
  179. + struct rpi_backlight *gbl;
  180. + struct device_node *fw_node;
  181. +
  182. + gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL);
  183. + if (gbl == NULL)
  184. + return -ENOMEM;
  185. +
  186. + gbl->dev = &pdev->dev;
  187. +
  188. + fw_node = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
  189. + if (!fw_node) {
  190. + dev_err(&pdev->dev, "Missing firmware node\n");
  191. + return -ENOENT;
  192. + }
  193. +
  194. + gbl->fw = rpi_firmware_get(fw_node);
  195. + if (!gbl->fw)
  196. + return -EPROBE_DEFER;
  197. +
  198. + memset(&props, 0, sizeof(props));
  199. + props.type = BACKLIGHT_RAW;
  200. + props.max_brightness = 255;
  201. + bl = devm_backlight_device_register(&pdev->dev, dev_name(&pdev->dev),
  202. + &pdev->dev, gbl, &rpi_backlight_ops,
  203. + &props);
  204. + if (IS_ERR(bl)) {
  205. + dev_err(&pdev->dev, "failed to register backlight\n");
  206. + return PTR_ERR(bl);
  207. + }
  208. +
  209. + bl->props.brightness = 255;
  210. + backlight_update_status(bl);
  211. +
  212. + platform_set_drvdata(pdev, bl);
  213. + return 0;
  214. +}
  215. +
  216. +static const struct of_device_id rpi_backlight_of_match[] = {
  217. + { .compatible = "raspberrypi,rpi-backlight" },
  218. + { /* sentinel */ }
  219. +};
  220. +MODULE_DEVICE_TABLE(of, rpi_backlight_of_match);
  221. +
  222. +static struct platform_driver rpi_backlight_driver = {
  223. + .driver = {
  224. + .name = "rpi-backlight",
  225. + .of_match_table = of_match_ptr(rpi_backlight_of_match),
  226. + },
  227. + .probe = rpi_backlight_probe,
  228. +};
  229. +
  230. +module_platform_driver(rpi_backlight_driver);
  231. +
  232. +MODULE_AUTHOR("Gordon Hollingworth <gordon@raspberrypi.org>");
  233. +MODULE_DESCRIPTION("Raspberry Pi mailbox based Backlight Driver");
  234. +MODULE_LICENSE("GPL");
  235. --- a/include/soc/bcm2835/raspberrypi-firmware.h
  236. +++ b/include/soc/bcm2835/raspberrypi-firmware.h
  237. @@ -112,6 +112,7 @@ enum rpi_firmware_property_tag {
  238. RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN = 0x0004800a,
  239. RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE = 0x0004800b,
  240. RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC = 0x0004800e,
  241. + RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT = 0x0004800f,
  242. RPI_FIRMWARE_VCHIQ_INIT = 0x00048010,