devterm-4.19_v0.1.patch 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. diff --git a/arch/arm/boot/dts/overlays/Makefile b/arch/arm/boot/dts/overlays/Makefile
  2. index 9863b50ad6da..4ec57b4a087f 100644
  3. --- a/arch/arm/boot/dts/overlays/Makefile
  4. +++ b/arch/arm/boot/dts/overlays/Makefile
  5. @@ -27,6 +27,11 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
  6. audremap.dtbo \
  7. balena-fin.dtbo \
  8. bmp085_i2c-sensor.dtbo \
  9. + devterm-bt.dtbo \
  10. + devterm-misc.dtbo \
  11. + devterm-panel.dtbo \
  12. + devterm-pmu.dtbo \
  13. + devterm-wifi.dtbo \
  14. dht11.dtbo \
  15. dionaudio-loco.dtbo \
  16. dionaudio-loco-v2.dtbo \
  17. diff --git a/arch/arm/boot/dts/overlays/devterm-bt-overlay.dts b/arch/arm/boot/dts/overlays/devterm-bt-overlay.dts
  18. new file mode 100755
  19. index 000000000000..4b634fdd3bda
  20. --- /dev/null
  21. +++ b/arch/arm/boot/dts/overlays/devterm-bt-overlay.dts
  22. @@ -0,0 +1,40 @@
  23. +/dts-v1/;
  24. +/plugin/;
  25. +
  26. +/{
  27. + compatible = "brcm,bcm2835";
  28. +
  29. + fragment@0 {
  30. + target = <&uart0>;
  31. + __overlay__ {
  32. + pinctrl-names = "default";
  33. + pinctrl-0 = <&uart0_pins &bt_pins>;
  34. + status = "okay";
  35. + };
  36. + };
  37. +
  38. + fragment@1 {
  39. + target = <&gpio>;
  40. + __overlay__ {
  41. + uart0_pins: uart0_pins {
  42. + brcm,pins = <14 15 16 17>;
  43. + brcm,function = <4 4 7 7>;
  44. + brcm,pull = <0 2 0 2>;
  45. + };
  46. +
  47. + bt_pins: bt_pins {
  48. + brcm,pins = <5 6 7>;
  49. + brcm,function = <1 0 1>;
  50. + brcm,pull = <0 2 0>;
  51. + };
  52. + };
  53. + };
  54. +
  55. + fragment@2 {
  56. + target-path = "/aliases";
  57. + __overlay__ {
  58. + serial1 = "/soc/serial@7e201000";
  59. + serial0 = "/soc/serial@7e215040";
  60. + };
  61. + };
  62. +};
  63. diff --git a/arch/arm/boot/dts/overlays/devterm-misc-overlay.dts b/arch/arm/boot/dts/overlays/devterm-misc-overlay.dts
  64. new file mode 100644
  65. index 000000000000..84413870bf4c
  66. --- /dev/null
  67. +++ b/arch/arm/boot/dts/overlays/devterm-misc-overlay.dts
  68. @@ -0,0 +1,94 @@
  69. +/dts-v1/;
  70. +/plugin/;
  71. +
  72. +/{
  73. + compatible = "brcm,bcm2835";
  74. +
  75. + fragment@0 {
  76. + target = <&pwm>;
  77. + __overlay__ {
  78. + pinctrl-names = "default";
  79. + pinctrl-0 = <&pwm_pins>;
  80. + assigned-clock-rates = <100000000>;
  81. + status = "okay";
  82. + };
  83. + };
  84. +
  85. + fragment@1 {
  86. + target = <&i2c1>;
  87. + __overlay__ {
  88. + #address-cells = <1>;
  89. + #size-cells = <0>;
  90. + pinctrl-names = "default";
  91. + pinctrl-0 = <&i2c1_pins>;
  92. + status = "okay";
  93. +
  94. + adc101c: adc@54 {
  95. + reg = <0x54>;
  96. + compatible = "ti,adc101c";
  97. + status = "okay";
  98. + };
  99. +
  100. + };
  101. + };
  102. +
  103. + fragment@2 {
  104. + target = <&spi0>;
  105. + __overlay__ {
  106. + pinctrl-names = "default";
  107. + pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
  108. + cs-gpios = <&gpio 35 1>;
  109. + status = "okay";
  110. + };
  111. + };
  112. +
  113. + fragment@3 {
  114. + target = <&uart1>;
  115. + __overlay__ {
  116. + pinctrl-names = "default";
  117. + pinctrl-0 = <&uart1_pins>;
  118. + status = "okay";
  119. + };
  120. + };
  121. +
  122. + fragment@4 {
  123. + target = <&gpio>;
  124. + __overlay__ {
  125. +
  126. + pwm_pins: pwm_pins {
  127. + brcm,pins = <12 13>;
  128. + brcm,function = <4>;
  129. + };
  130. +
  131. + i2c1_pins: i2c1 {
  132. + brcm,pins = <44 45>;
  133. + brcm,function = <6>;
  134. + };
  135. +
  136. + spi0_pins: spi0_pins {
  137. + brcm,pins = <38 39>;
  138. + brcm,function = <4>;
  139. + };
  140. +
  141. + spi0_cs_pins: spi0_cs_pins {
  142. + brcm,pins = <35>;
  143. + brcm,function = <1>;
  144. + };
  145. +
  146. + uart1_pins: uart1_pins {
  147. + brcm,pins = <32 33>;
  148. + brcm,function = <2>;
  149. + brcm,pull = <0 2>;
  150. + };
  151. +
  152. + };
  153. + };
  154. +
  155. + fragment@5 {
  156. + target-path = "/chosen";
  157. + __overlay__ {
  158. + bootargs = "8250.nr_uarts=1";
  159. + };
  160. + };
  161. +
  162. +};
  163. diff --git a/arch/arm/boot/dts/overlays/devterm-panel-overlay.dts b/arch/arm/boot/dts/overlays/devterm-panel-overlay.dts
  164. new file mode 100644
  165. index 000000000000..7d9ff963f309
  166. --- /dev/null
  167. +++ b/arch/arm/boot/dts/overlays/devterm-panel-overlay.dts
  168. @@ -0,0 +1,46 @@
  169. +/dts-v1/;
  170. +/plugin/;
  171. +
  172. +/ {
  173. + compatible = "brcm,bcm2835";
  174. +
  175. + fragment@0 {
  176. + target=<&dsi1>;
  177. + __overlay__ {
  178. + #address-cells = <1>;
  179. + #size-cells = <0>;
  180. + status = "okay";
  181. +
  182. + port {
  183. + dsi_out_port: endpoint {
  184. + remote-endpoint = <&panel_dsi_port>;
  185. + };
  186. + };
  187. +
  188. + panel_cwd686: panel@0 {
  189. + compatible = "cw,cwd686";
  190. + reg = <0>;
  191. + reset-gpio = <&gpio 8 1>;
  192. + backlight = <&ocp8178_backlight>;
  193. +
  194. + port {
  195. + panel_dsi_port: endpoint {
  196. + remote-endpoint = <&dsi_out_port>;
  197. + };
  198. + };
  199. + };
  200. + };
  201. + };
  202. +
  203. + fragment@1 {
  204. + target-path = "/";
  205. + __overlay__ {
  206. + ocp8178_backlight: backlight@0 {
  207. + compatible = "ocp8178-backlight";
  208. + backlight-control-gpios = <&gpio 9 0>;
  209. + default-brightness = <5>;
  210. + };
  211. + };
  212. + };
  213. +
  214. +};
  215. diff --git a/arch/arm/boot/dts/overlays/devterm-pmu-overlay.dts b/arch/arm/boot/dts/overlays/devterm-pmu-overlay.dts
  216. new file mode 100644
  217. index 000000000000..45f730e0e757
  218. --- /dev/null
  219. +++ b/arch/arm/boot/dts/overlays/devterm-pmu-overlay.dts
  220. @@ -0,0 +1,124 @@
  221. +/dts-v1/;
  222. +/plugin/;
  223. +
  224. +/ {
  225. + compatible = "brcm,bcm2835";
  226. +
  227. + fragment@0 {
  228. + target = <&i2c0>;
  229. + __overlay__ {
  230. + #address-cells = <1>;
  231. + #size-cells = <0>;
  232. + pinctrl-0 = <&i2c0_pins>;
  233. + pinctrl-names = "default";
  234. + status = "okay";
  235. +
  236. + axp22x: pmic@34 {
  237. + interrupt-controller;
  238. + #interrupt-cells = <1>;
  239. + compatible = "x-powers,axp221";
  240. + reg = <0x34>; /* i2c address */
  241. + interrupt-parent = <&gpio>;
  242. + interrupts = <2 8>; /* IRQ_TYPE_EDGE_FALLING */
  243. + irq-gpios = <&gpio 2 0>;
  244. +
  245. + regulators {
  246. +
  247. + x-powers,dcdc-freq = <3000>;
  248. +
  249. + reg_aldo1: aldo1 {
  250. + regulator-always-on;
  251. + regulator-min-microvolt = <3300000>;
  252. + regulator-max-microvolt = <3300000>;
  253. + regulator-name = "audio-vdd";
  254. + };
  255. +
  256. + reg_aldo2: aldo2 {
  257. + regulator-min-microvolt = <3300000>;
  258. + regulator-max-microvolt = <3300000>;
  259. + regulator-name = "display-vcc";
  260. + };
  261. +
  262. + reg_aldo3: aldo3 {
  263. + regulator-always-on;
  264. + regulator-min-microvolt = <3300000>;
  265. + regulator-max-microvolt = <3300000>;
  266. + regulator-name = "wifi-vdd";
  267. + };
  268. +
  269. + reg_dldo1: dldo1 {
  270. + regulator-always-on;
  271. + regulator-min-microvolt = <3300000>;
  272. + regulator-max-microvolt = <3300000>;
  273. + regulator-name = "wifi-vcc1";
  274. + };
  275. +
  276. + reg_dldo2: dldo2 {
  277. + regulator-always-on;
  278. + regulator-min-microvolt = <3300000>;
  279. + regulator-max-microvolt = <3300000>;
  280. + regulator-name = "dldo2";
  281. + };
  282. +
  283. + reg_dldo3: dldo3 {
  284. + regulator-always-on;
  285. + regulator-min-microvolt = <3300000>;
  286. + regulator-max-microvolt = <3300000>;
  287. + regulator-name = "dldo3";
  288. + };
  289. +
  290. + reg_dldo4: dldo4 {
  291. + regulator-always-on;
  292. + regulator-min-microvolt = <3300000>;
  293. + regulator-max-microvolt = <3300000>;
  294. + regulator-name = "dldo4";
  295. + };
  296. +
  297. + reg_eldo1: eldo1 {
  298. + regulator-always-on;
  299. + regulator-min-microvolt = <3300000>;
  300. + regulator-max-microvolt = <3300000>;
  301. + regulator-name = "wifi-vcc2";
  302. + };
  303. +
  304. + reg_eldo2: eldo2 {
  305. + regulator-always-on;
  306. + regulator-min-microvolt = <3300000>;
  307. + regulator-max-microvolt = <3300000>;
  308. + regulator-name = "wifi-vcc3";
  309. + };
  310. +
  311. + reg_eldo3: eldo3 {
  312. + regulator-always-on;
  313. + regulator-min-microvolt = <3300000>;
  314. + regulator-max-microvolt = <3300000>;
  315. + regulator-name = "wifi-vcc4";
  316. + };
  317. +
  318. + };
  319. +
  320. + battery_power_supply: battery-power-supply {
  321. + compatible = "x-powers,axp221-battery-power-supply";
  322. + monitored-battery = <&battery>;
  323. + };
  324. +
  325. + usb_power_supply: usb_power_supply {
  326. + compatible = "x-powers,axp221-usb-power-supply";
  327. + };
  328. +
  329. + };
  330. + };
  331. + };
  332. +
  333. + fragment@1 {
  334. + target-path = "/";
  335. + __overlay__ {
  336. + battery: battery@0 {
  337. + compatible = "simple-battery";
  338. + constant_charge_current_max_microamp = <2100000>;
  339. + voltage-min-design-microvolt = <3300000>;
  340. + };
  341. + };
  342. + };
  343. +
  344. +};
  345. diff --git a/arch/arm/boot/dts/overlays/devterm-wifi-overlay.dts b/arch/arm/boot/dts/overlays/devterm-wifi-overlay.dts
  346. new file mode 100644
  347. index 000000000000..d5da786dc445
  348. --- /dev/null
  349. +++ b/arch/arm/boot/dts/overlays/devterm-wifi-overlay.dts
  350. @@ -0,0 +1,41 @@
  351. +/dts-v1/;
  352. +/plugin/;
  353. +
  354. +/* Enable SDIO from MMC interface via various GPIO groups */
  355. +
  356. +/{
  357. + compatible = "brcm,bcm2835";
  358. +
  359. + fragment@0 {
  360. + target = <&mmc>;
  361. + sdio_ovl: __overlay__ {
  362. + pinctrl-0 = <&sdio_ovl_pins>;
  363. + pinctrl-names = "default";
  364. + non-removable;
  365. + bus-width = <4>;
  366. + status = "okay";
  367. + };
  368. + };
  369. +
  370. + fragment@1 {
  371. + target = <&gpio>;
  372. + __overlay__ {
  373. + sdio_ovl_pins: sdio_ovl_pins {
  374. + brcm,pins = <22 23 24 25 26 27>;
  375. + brcm,function = <7>; /* ALT3 = SD1 */
  376. + brcm,pull = <0 2 2 2 2 2>;
  377. + };
  378. + };
  379. + };
  380. +
  381. + fragment@2 {
  382. + target-path = "/";
  383. + __overlay__ {
  384. + wifi_pwrseq: wifi-pwrseq {
  385. + compatible = "mmc-pwrseq-simple";
  386. + reset-gpios = <&gpio 3 0>;
  387. + };
  388. + };
  389. + };
  390. +
  391. +};
  392. diff --git a/arch/arm/boot/dts/overlays/vc4-kms-v3d-overlay.dts b/arch/arm/boot/dts/overlays/vc4-kms-v3d-overlay.dts
  393. index c5f687e8bcb9..d01d5e5d7810 100644
  394. --- a/arch/arm/boot/dts/overlays/vc4-kms-v3d-overlay.dts
  395. +++ b/arch/arm/boot/dts/overlays/vc4-kms-v3d-overlay.dts
  396. @@ -141,12 +141,20 @@
  397. };
  398. };
  399. + fragment@18 {
  400. + target-path = "/chosen";
  401. + __dormant__ {
  402. + bootargs = "cma=384M";
  403. + };
  404. + };
  405. +
  406. __overrides__ {
  407. - cma-256 = <0>,"+0-1-2-3-4";
  408. - cma-192 = <0>,"-0+1-2-3-4";
  409. - cma-128 = <0>,"-0-1+2-3-4";
  410. - cma-96 = <0>,"-0-1-2+3-4";
  411. - cma-64 = <0>,"-0-1-2-3+4";
  412. + cma-256 = <0>,"+0-1-2-3-4-18";
  413. + cma-192 = <0>,"-0+1-2-3-4-18";
  414. + cma-128 = <0>,"-0-1+2-3-4-18";
  415. + cma-96 = <0>,"-0-1-2+3-4-18";
  416. + cma-64 = <0>,"-0-1-2-3+4-18";
  417. + cma-384 = <0>,"-0-1-2-3-4+18";
  418. audio = <0>,"!17";
  419. };
  420. };
  421. diff --git a/arch/arm/configs/bcm2709_defconfig b/arch/arm/configs/bcm2709_defconfig
  422. index 4fd6bcc8b2bb..b9fbb84c8811 100644
  423. --- a/arch/arm/configs/bcm2709_defconfig
  424. +++ b/arch/arm/configs/bcm2709_defconfig
  425. @@ -676,7 +676,7 @@ CONFIG_I2C_MUX=m
  426. CONFIG_I2C_MUX_GPMUX=m
  427. CONFIG_I2C_MUX_PCA954x=m
  428. CONFIG_I2C_BCM2708=m
  429. -CONFIG_I2C_BCM2835=m
  430. +CONFIG_I2C_BCM2835=y
  431. CONFIG_I2C_GPIO=m
  432. CONFIG_I2C_ROBOTFUZZ_OSIF=m
  433. CONFIG_I2C_TINY_USB=m
  434. @@ -1468,3 +1468,15 @@ CONFIG_FUNCTION_PROFILER=y
  435. CONFIG_KGDB=y
  436. CONFIG_KGDB_KDB=y
  437. CONFIG_KDB_KEYBOARD=y
  438. +
  439. +CONFIG_AXP20X_ADC=m
  440. +CONFIG_AXP20X_POWER=m
  441. +CONFIG_BATTERY_AXP20X=m
  442. +CONFIG_CHARGER_AXP20X=m
  443. +CONFIG_INPUT_AXP20X_PEK=y
  444. +CONFIG_MFD_AXP20X=y
  445. +CONFIG_MFD_AXP20X_I2C=y
  446. +CONFIG_REGULATOR_AXP20X=y
  447. +CONFIG_BACKLIGHT_OCP8178=y
  448. +CONFIG_DRM_PANEL_CWD686=m
  449. +CONFIG_TI_ADC081C=m
  450. diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
  451. index 6020c30a33b3..1a0f8d87c7db 100644
  452. --- a/drivers/gpu/drm/panel/Kconfig
  453. +++ b/drivers/gpu/drm/panel/Kconfig
  454. @@ -186,4 +186,17 @@ config DRM_PANEL_SITRONIX_ST7789V
  455. Say Y here if you want to enable support for the Sitronix
  456. ST7789V controller for 240x320 LCD panels
  457. +
  458. +config DRM_PANEL_CWD686
  459. + tristate "CWD686 panel"
  460. + depends on OF
  461. + depends on DRM_MIPI_DSI
  462. + depends on BACKLIGHT_CLASS_DEVICE
  463. + help
  464. + Say Y here if you want to enable support for CWD686 panel.
  465. + The panel has a 480x1280 resolution and uses 24 bit RGB per pixel.
  466. +
  467. + To compile this driver as a module, choose M here: the module
  468. + will be called panel-cwd686.
  469. +
  470. endmenu
  471. diff --git a/drivers/gpu/drm/panel/Makefile b/drivers/gpu/drm/panel/Makefile
  472. index 5ccaaa9d13af..52859d54b0f9 100644
  473. --- a/drivers/gpu/drm/panel/Makefile
  474. +++ b/drivers/gpu/drm/panel/Makefile
  475. @@ -19,3 +19,4 @@ obj-$(CONFIG_DRM_PANEL_SEIKO_43WVF1G) += panel-seiko-43wvf1g.o
  476. obj-$(CONFIG_DRM_PANEL_SHARP_LQ101R1SX01) += panel-sharp-lq101r1sx01.o
  477. obj-$(CONFIG_DRM_PANEL_SHARP_LS043T1LE01) += panel-sharp-ls043t1le01.o
  478. obj-$(CONFIG_DRM_PANEL_SITRONIX_ST7789V) += panel-sitronix-st7789v.o
  479. +obj-$(CONFIG_DRM_PANEL_CWD686) += panel-cwd686.o
  480. diff --git a/drivers/gpu/drm/panel/panel-cwd686.c b/drivers/gpu/drm/panel/panel-cwd686.c
  481. new file mode 100644
  482. index 000000000000..6b6969f29f62
  483. --- /dev/null
  484. +++ b/drivers/gpu/drm/panel/panel-cwd686.c
  485. @@ -0,0 +1,295 @@
  486. +// SPDX-License-Identifier: GPL-2.0
  487. +
  488. +#include <linux/backlight.h>
  489. +#include <linux/gpio/consumer.h>
  490. +#include <linux/regulator/consumer.h>
  491. +
  492. +#include <video/mipi_display.h>
  493. +
  494. +#include <drm/drmP.h>
  495. +#include <drm/drm_mipi_dsi.h>
  496. +#include <drm/drm_panel.h>
  497. +
  498. +
  499. +struct cwd686 {
  500. + struct device *dev;
  501. + struct drm_panel panel;
  502. + struct gpio_desc *reset_gpio;
  503. + struct regulator *supply;
  504. + struct backlight_device *backlight;
  505. + bool prepared;
  506. + bool enabled;
  507. +};
  508. +
  509. +static const struct drm_display_mode default_mode = {
  510. + .clock = 54465,
  511. + .hdisplay = 480,
  512. + .hsync_start = 480 + 150,
  513. + .hsync_end = 480 + 150 + 24,
  514. + .htotal = 480 + 150 + 24 + 40,
  515. + .vdisplay = 1280,
  516. + .vsync_start = 1280 + 12,
  517. + .vsync_end = 1280 + 12+ 6,
  518. + .vtotal = 1280 + 12 + 6 + 10,
  519. + .vrefresh = 60,
  520. + .flags = 0,
  521. +};
  522. +
  523. +static inline struct cwd686 *panel_to_cwd686(struct drm_panel *panel)
  524. +{
  525. + return container_of(panel, struct cwd686, panel);
  526. +}
  527. +
  528. +#define dcs_write_seq(seq...) \
  529. +({ \
  530. + static const u8 d[] = { seq }; \
  531. + mipi_dsi_dcs_write_buffer(dsi, d, ARRAY_SIZE(d)); \
  532. +})
  533. +
  534. +static void cwd686_init_sequence(struct cwd686 *ctx)
  535. +{
  536. + struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
  537. +
  538. + dcs_write_seq(0xF0,0x5A,0x5A);
  539. + dcs_write_seq(0xF1,0xA5,0xA5);
  540. + dcs_write_seq(0xB6,0x0D,0x0D);
  541. + dcs_write_seq(0xB4,0x0A,0x08,0x12,0x10,0x0E,0x0C,0x00,0x00,0x00,0x03,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x04,0x06);
  542. + dcs_write_seq(0xB3,0x0B,0x09,0x13,0x11,0x0F,0x0D,0x00,0x00,0x00,0x03,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x05,0x07);
  543. + dcs_write_seq(0xB0,0x54,0x32,0x23,0x45,0x44,0x44,0x44,0x44,0x90,0x01,0x90,0x01);
  544. + dcs_write_seq(0xB1,0x32,0x84,0x02,0x83,0x30,0x01,0x6B,0x01);
  545. + dcs_write_seq(0xB2,0x73);
  546. + dcs_write_seq(0xBD,0x4E,0x0E,0x50,0x50,0x26,0x1D,0x00,0x14,0x42,0x03);
  547. + dcs_write_seq(0xB7,0x01,0x01,0x09,0x11,0x0D,0x55,0x19,0x19,0x21,0x1D,0x00,0x00,0x00,0x00,0x02,0xFF,0x3C);
  548. + dcs_write_seq(0xB8,0x23,0x01,0x30,0x34,0x63);
  549. + dcs_write_seq(0xB9,0xA0,0x22,0x00,0x44);
  550. + dcs_write_seq(0xBA,0x12,0x63);
  551. + dcs_write_seq(0xC1,0x0C,0x16,0x04,0x0C,0x10,0x04);
  552. + dcs_write_seq(0xC2,0x11,0x41);
  553. + dcs_write_seq(0xC3,0x22,0x31,0x04);
  554. + dcs_write_seq(0xC7,0x05,0x23,0x6B,0x49,0x00);
  555. + dcs_write_seq(0xC5,0x00);
  556. + dcs_write_seq(0xD0,0x37,0xFF,0xFF);
  557. + dcs_write_seq(0xD2,0x63,0x0B,0x08,0x88);
  558. + dcs_write_seq(0xD3,0x01,0x00,0x00,0x01,0x01,0x37,0x25,0x38,0x31,0x06,0x07);
  559. + dcs_write_seq(0xC8,0x7C,0x6A,0x5D,0x53,0x53,0x45,0x4B,0x35,0x4D,0x4A,0x49,0x66,0x53,0x57,0x4A,0x48,0x3B,0x2A,0x06,0x7C,0x6A,0x5D,0x53,0x53,0x45,0x4B,0x35,0x4D,0x4A,0x49,0x66,0x53,0x57,0x4A,0x48,0x3B,0x2A,0x06);//GAMMA2.2
  560. + dcs_write_seq(0xC6,0x00,0x00,0xFF,0x00,0x00,0xFF,0x00,0x00);
  561. + dcs_write_seq(0xF4,0x08,0x77);
  562. + dcs_write_seq(0x36,0x14);
  563. + dcs_write_seq(0x35,0x00);
  564. + dcs_write_seq(0xF1,0x5A,0x5A);
  565. + dcs_write_seq(0xF0,0xA5,0xA5);
  566. +}
  567. +
  568. +static int cwd686_disable(struct drm_panel *panel)
  569. +{
  570. + struct cwd686 *ctx = panel_to_cwd686(panel);
  571. +
  572. + if (!ctx->enabled)
  573. + return 0;
  574. +
  575. + backlight_disable(ctx->backlight);
  576. +
  577. + ctx->enabled = false;
  578. +
  579. + return 0;
  580. +}
  581. +
  582. +static int cwd686_unprepare(struct drm_panel *panel)
  583. +{
  584. + struct cwd686 *ctx = panel_to_cwd686(panel);
  585. + struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
  586. + int ret;
  587. +
  588. +#if 0
  589. + if (!ctx->prepared)
  590. + return 0;
  591. +
  592. + ret = mipi_dsi_dcs_set_display_off(dsi);
  593. + if (ret)
  594. + DRM_WARN("failed to set display off: %d\n", ret);
  595. +
  596. + ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
  597. + if (ret)
  598. + DRM_WARN("failed to enter sleep mode: %d\n", ret);
  599. +
  600. + msleep(120);
  601. +
  602. + if (ctx->reset_gpio) {
  603. + gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  604. + msleep(20);
  605. + }
  606. +
  607. + regulator_disable(ctx->supply);
  608. +
  609. + ctx->prepared = false;
  610. +#endif
  611. +
  612. + return 0;
  613. +}
  614. +
  615. +static int cwd686_prepare(struct drm_panel *panel)
  616. +{
  617. + struct cwd686 *ctx = panel_to_cwd686(panel);
  618. + struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
  619. + int ret;
  620. +
  621. + if (ctx->prepared)
  622. + return 0;
  623. +
  624. + ret = regulator_enable(ctx->supply);
  625. + if (ret < 0) {
  626. + DRM_ERROR("failed to enable supply: %d\n", ret);
  627. + return ret;
  628. + }
  629. +
  630. + if (ctx->reset_gpio) {
  631. + gpiod_set_value_cansleep(ctx->reset_gpio, 1);
  632. + msleep(10);
  633. + gpiod_set_value_cansleep(ctx->reset_gpio, 0);
  634. + msleep(100);
  635. + }
  636. +
  637. + cwd686_init_sequence(ctx);
  638. +
  639. + ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
  640. + if (ret)
  641. + return ret;
  642. +
  643. + msleep(120);
  644. +
  645. + ret = mipi_dsi_dcs_set_display_on(dsi);
  646. + if (ret)
  647. + return ret;
  648. +
  649. + msleep(20);
  650. +
  651. + ctx->prepared = true;
  652. +
  653. + return 0;
  654. +}
  655. +
  656. +static int cwd686_enable(struct drm_panel *panel)
  657. +{
  658. + struct cwd686 *ctx = panel_to_cwd686(panel);
  659. +
  660. + if (ctx->enabled)
  661. + return 0;
  662. +
  663. + backlight_enable(ctx->backlight);
  664. +
  665. + ctx->enabled = true;
  666. +
  667. + return 0;
  668. +}
  669. +
  670. +static int cwd686_get_modes(struct drm_panel *panel)
  671. +{
  672. + struct drm_display_mode *mode;
  673. +
  674. + mode = drm_mode_duplicate(panel->drm, &default_mode);
  675. + if (!mode) {
  676. + DRM_ERROR("failed to add mode %ux%ux@%u\n",
  677. + default_mode.hdisplay, default_mode.vdisplay,
  678. + default_mode.vrefresh);
  679. + return -ENOMEM;
  680. + }
  681. +
  682. + drm_mode_set_name(mode);
  683. +
  684. + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  685. +
  686. + panel->connector->display_info.width_mm = mode->width_mm;
  687. + panel->connector->display_info.height_mm = mode->height_mm;
  688. +
  689. + drm_mode_probed_add(panel->connector, mode);
  690. + return 1;
  691. +}
  692. +
  693. +static const struct drm_panel_funcs cwd686_drm_funcs = {
  694. + .disable = cwd686_disable,
  695. + .unprepare = cwd686_unprepare,
  696. + .prepare = cwd686_prepare,
  697. + .enable = cwd686_enable,
  698. + .get_modes = cwd686_get_modes,
  699. +};
  700. +
  701. +static int cwd686_probe(struct mipi_dsi_device *dsi)
  702. +{
  703. + struct device *dev = &dsi->dev;
  704. + struct cwd686 *ctx;
  705. + int ret;
  706. +
  707. + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  708. + if (!ctx)
  709. + return -ENOMEM;
  710. +
  711. + ctx->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
  712. + if (IS_ERR(ctx->reset_gpio)) {
  713. + ret = PTR_ERR(ctx->reset_gpio);
  714. + dev_err(dev, "cannot get reset GPIO: %d\n", ret);
  715. + return ret;
  716. + }
  717. +
  718. + ctx->supply = devm_regulator_get(dev, "display-vcc");
  719. + if (IS_ERR(ctx->supply)) {
  720. + ret = PTR_ERR(ctx->supply);
  721. + dev_err(dev, "cannot get regulator: %d\n", ret);
  722. + return ret;
  723. + }
  724. +
  725. + ctx->backlight = devm_of_find_backlight(dev);
  726. + if (IS_ERR(ctx->backlight))
  727. + return PTR_ERR(ctx->backlight);
  728. +
  729. + mipi_dsi_set_drvdata(dsi, ctx);
  730. +
  731. + ctx->dev = dev;
  732. +
  733. + dsi->lanes = 4;
  734. + dsi->format = MIPI_DSI_FMT_RGB888;
  735. + dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | MIPI_DSI_MODE_LPM;
  736. +
  737. + drm_panel_init(&ctx->panel);
  738. + ctx->panel.dev = dev;
  739. + ctx->panel.funcs = &cwd686_drm_funcs;
  740. +
  741. + drm_panel_add(&ctx->panel);
  742. +
  743. + ret = mipi_dsi_attach(dsi);
  744. + if (ret < 0) {
  745. + dev_err(dev, "mipi_dsi_attach() failed: %d\n", ret);
  746. + drm_panel_remove(&ctx->panel);
  747. + return ret;
  748. + }
  749. +
  750. + return 0;
  751. +}
  752. +
  753. +static int cwd686_remove(struct mipi_dsi_device *dsi)
  754. +{
  755. + struct cwd686 *ctx = mipi_dsi_get_drvdata(dsi);
  756. +
  757. + mipi_dsi_detach(dsi);
  758. + drm_panel_remove(&ctx->panel);
  759. +
  760. + return 0;
  761. +}
  762. +
  763. +static const struct of_device_id cwd686_of_match[] = {
  764. + { .compatible = "cw,cwd686" },
  765. + { }
  766. +};
  767. +MODULE_DEVICE_TABLE(of, cwd686_of_match);
  768. +
  769. +static struct mipi_dsi_driver cwd686_driver = {
  770. + .probe = cwd686_probe,
  771. + .remove = cwd686_remove,
  772. + .driver = {
  773. + .name = "panel-cwd686",
  774. + .of_match_table = cwd686_of_match,
  775. + },
  776. +};
  777. +module_mipi_dsi_driver(cwd686_driver);
  778. +
  779. +MODULE_DESCRIPTION("DRM Driver for cwd686 MIPI DSI panel");
  780. +MODULE_LICENSE("GPL v2");
  781. diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
  782. index aa65931142ba..405358cf24c8 100644
  783. --- a/drivers/mfd/axp20x.c
  784. +++ b/drivers/mfd/axp20x.c
  785. @@ -962,6 +962,7 @@ int axp20x_device_probe(struct axp20x_dev *axp20x)
  786. return ret;
  787. }
  788. + pm_power_off = 0;
  789. if (!pm_power_off) {
  790. axp20x_pm_power_off = axp20x;
  791. pm_power_off = axp20x_power_off;
  792. diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
  793. index 0eaacdbc612f..32c59228b1a6 100644
  794. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
  795. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
  796. @@ -622,6 +622,7 @@ BRCMF_FW_DEF(43430A0, "brcmfmac43430a0-sdio");
  797. /* Note the names are not postfixed with a1 for backward compatibility */
  798. BRCMF_FW_DEF(43430A1, "brcmfmac43430-sdio");
  799. BRCMF_FW_DEF(43455, "brcmfmac43455-sdio");
  800. +BRCMF_FW_DEF(43456, "brcmfmac43456-sdio");
  801. BRCMF_FW_DEF(4354, "brcmfmac4354-sdio");
  802. BRCMF_FW_DEF(4356, "brcmfmac4356-sdio");
  803. BRCMF_FW_DEF(4373, "brcmfmac4373-sdio");
  804. @@ -641,6 +642,7 @@ static const struct brcmf_firmware_mapping brcmf_sdio_fwnames[] = {
  805. BRCMF_FW_ENTRY(BRCM_CC_4339_CHIP_ID, 0xFFFFFFFF, 4339),
  806. BRCMF_FW_ENTRY(BRCM_CC_43430_CHIP_ID, 0x00000001, 43430A0),
  807. BRCMF_FW_ENTRY(BRCM_CC_43430_CHIP_ID, 0xFFFFFFFE, 43430A1),
  808. + BRCMF_FW_ENTRY(BRCM_CC_4345_CHIP_ID, 0x00000200, 43456),
  809. BRCMF_FW_ENTRY(BRCM_CC_4345_CHIP_ID, 0xFFFFFFC0, 43455),
  810. BRCMF_FW_ENTRY(BRCM_CC_4354_CHIP_ID, 0xFFFFFFFF, 4354),
  811. BRCMF_FW_ENTRY(BRCM_CC_4356_CHIP_ID, 0xFFFFFFFF, 4356),
  812. diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
  813. index e84b6e4da14a..b62c361e2589 100644
  814. --- a/drivers/power/supply/axp20x_battery.c
  815. +++ b/drivers/power/supply/axp20x_battery.c
  816. @@ -326,6 +326,42 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
  817. val->intval *= 1000;
  818. break;
  819. + case POWER_SUPPLY_PROP_ENERGY_FULL:
  820. + case POWER_SUPPLY_PROP_ENERGY_NOW:
  821. + /* When no battery is present, return 0 */
  822. + ret = regmap_read(axp20x_batt->regmap, AXP20X_PWR_OP_MODE,
  823. + &reg);
  824. + if (ret)
  825. + return ret;
  826. +
  827. + if (!(reg & AXP20X_PWR_OP_BATT_PRESENT)) {
  828. + val->intval = 0;
  829. + return 0;
  830. + }
  831. +
  832. + if(psp == POWER_SUPPLY_PROP_ENERGY_FULL) {
  833. + val->intval = 8000000;
  834. + return 0;
  835. + }
  836. +
  837. + ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, &reg);
  838. + if (ret)
  839. + return ret;
  840. +
  841. + if (axp20x_batt->data->has_fg_valid && !(reg & AXP22X_FG_VALID))
  842. + return -EINVAL;
  843. +
  844. + val1 = reg & AXP209_FG_PERCENT;
  845. + if (val1 > 90)
  846. + val1= 80;
  847. + else if (val1 < 10)
  848. + val1 = 0;
  849. + else
  850. + val1 -= 10;
  851. +
  852. + val->intval = val1 * 100000;
  853. + break;
  854. +
  855. default:
  856. return -EINVAL;
  857. }
  858. @@ -486,6 +522,8 @@ static enum power_supply_property axp20x_battery_props[] = {
  859. POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
  860. POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
  861. POWER_SUPPLY_PROP_CAPACITY,
  862. + POWER_SUPPLY_PROP_ENERGY_FULL,
  863. + POWER_SUPPLY_PROP_ENERGY_NOW,
  864. };
  865. static int axp20x_battery_prop_writeable(struct power_supply *psy,
  866. @@ -630,6 +668,12 @@ static int axp20x_power_probe(struct platform_device *pdev)
  867. axp20x_get_constant_charge_current(axp20x_batt,
  868. &axp20x_batt->max_ccc);
  869. + regmap_update_bits(axp20x_batt->regmap, AXP20X_VBUS_IPSOUT_MGMT, 0x03, 0x03);
  870. + regmap_update_bits(axp20x_batt->regmap, AXP20X_OFF_CTRL, 0x08, 0x08);
  871. + regmap_update_bits(axp20x_batt->regmap, AXP20X_CHRG_CTRL2, 0x30, 0x20);
  872. + regmap_update_bits(axp20x_batt->regmap, AXP20X_PEK_KEY, 0x0f, 0x0b);
  873. + regmap_update_bits(axp20x_batt->regmap, AXP20X_GPIO0_CTRL, 0x07, 0x00);
  874. +
  875. return 0;
  876. }
  877. diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
  878. index 42001df4bd13..791ec9f466cb 100644
  879. --- a/drivers/power/supply/axp20x_usb_power.c
  880. +++ b/drivers/power/supply/axp20x_usb_power.c
  881. @@ -58,6 +58,9 @@ static irqreturn_t axp20x_usb_power_irq(int irq, void *devid)
  882. {
  883. struct axp20x_usb_power *power = devid;
  884. + regmap_update_bits(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, 0x03, 0x00);
  885. + regmap_update_bits(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, 0x03, 0x03);
  886. +
  887. power_supply_changed(power->supply);
  888. return IRQ_HANDLED;
  889. diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
  890. index 2f465dba54bf..b12eb465b44c 100644
  891. --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
  892. +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c
  893. @@ -11,9 +11,9 @@
  894. #include "bcm2835.h"
  895. #include <soc/bcm2835/raspberrypi-firmware.h>
  896. -static bool enable_hdmi, enable_hdmi0, enable_hdmi1;
  897. -static bool enable_headphones;
  898. -static bool enable_compat_alsa = true;
  899. +static bool enable_hdmi = true, enable_hdmi0, enable_hdmi1;
  900. +static bool enable_headphones = true;
  901. +static bool enable_compat_alsa;
  902. module_param(enable_hdmi, bool, 0444);
  903. MODULE_PARM_DESC(enable_hdmi, "Enables HDMI virtual audio device");
  904. diff --git a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
  905. index 9478f9fd96e2..621a4b3e0860 100644
  906. --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
  907. +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
  908. @@ -2559,7 +2559,7 @@ static const struct v4l2_m2m_ops m2m_ops = {
  909. * The ISP component currently advertises 33 input formats, so add a small
  910. * overhead on that.
  911. */
  912. -#define MAX_SUPPORTED_ENCODINGS 40
  913. +#define MAX_SUPPORTED_ENCODINGS 70
  914. /* Populate dev->supported_fmts with the formats supported by those ports. */
  915. static int bcm2835_codec_get_supported_fmts(struct bcm2835_codec_dev *dev)
  916. diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
  917. index 5268ed6d12c0..0da804257739 100644
  918. --- a/drivers/video/backlight/Kconfig
  919. +++ b/drivers/video/backlight/Kconfig
  920. @@ -487,6 +487,12 @@ config BACKLIGHT_RAVE_SP
  921. help
  922. Support for backlight control on RAVE SP device.
  923. +config BACKLIGHT_OCP8178
  924. + tristate "OCP8178 Backlight Driver"
  925. + depends on GPIOLIB
  926. + help
  927. + If you have an OCP8178, say Y to enable the backlight driver.
  928. +
  929. endif # BACKLIGHT_CLASS_DEVICE
  930. endif # BACKLIGHT_LCD_SUPPORT
  931. diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
  932. index 476f855a093f..56d7c9909cc4 100644
  933. --- a/drivers/video/backlight/Makefile
  934. +++ b/drivers/video/backlight/Makefile
  935. @@ -60,3 +60,4 @@ obj-$(CONFIG_BACKLIGHT_TPS65217) += tps65217_bl.o
  936. obj-$(CONFIG_BACKLIGHT_WM831X) += wm831x_bl.o
  937. obj-$(CONFIG_BACKLIGHT_ARCXCNN) += arcxcnn_bl.o
  938. obj-$(CONFIG_BACKLIGHT_RAVE_SP) += rave-sp-backlight.o
  939. +obj-$(CONFIG_BACKLIGHT_OCP8178) += ocp8178_bl.o
  940. diff --git a/drivers/video/backlight/ocp8178_bl.c b/drivers/video/backlight/ocp8178_bl.c
  941. new file mode 100644
  942. index 000000000000..db8db1771644
  943. --- /dev/null
  944. +++ b/drivers/video/backlight/ocp8178_bl.c
  945. @@ -0,0 +1,277 @@
  946. +/*
  947. + * ocp8178_bl.c - ocp8178 backlight driver
  948. + *
  949. + * This program is free software; you can redistribute it and/or modify
  950. + * it under the terms of the GNU General Public License version 2 as
  951. + * published by the Free Software Foundation.
  952. + */
  953. +
  954. +#include <linux/backlight.h>
  955. +#include <linux/err.h>
  956. +#include <linux/fb.h>
  957. +#include <linux/gpio.h> /* Only for legacy support */
  958. +#include <linux/gpio/consumer.h>
  959. +#include <linux/init.h>
  960. +#include <linux/kernel.h>
  961. +#include <linux/module.h>
  962. +#include <linux/of.h>
  963. +#include <linux/of_gpio.h>
  964. +#include <linux/platform_data/gpio_backlight.h>
  965. +#include <linux/platform_device.h>
  966. +#include <linux/slab.h>
  967. +#include <linux/delay.h>
  968. +#include <linux/timer.h>
  969. +#include <linux/poll.h>
  970. +#include <linux/proc_fs.h>
  971. +#include <linux/seq_file.h>
  972. +#include <linux/sched.h>
  973. +#include <linux/interrupt.h>
  974. +#include <linux/irq.h>
  975. +#include <linux/io.h>
  976. +#include <linux/clk.h>
  977. +
  978. +struct ocp8178_backlight {
  979. + struct device *dev;
  980. + struct device *fbdev;
  981. +
  982. + struct gpio_desc *gpiod;
  983. + int def_value;
  984. + int current_value;
  985. +};
  986. +
  987. +#define DETECT_DELAY 200
  988. +#define DETECT_TIME 500
  989. +#define DETECT_WINDOW_TIME 1000
  990. +#define START_TIME 10
  991. +#define END_TIME 10
  992. +#define SHUTDOWN_TIME 3000
  993. +#define LOW_BIT_HIGH_TIME 10
  994. +#define LOW_BIT_LOW_TIME 50
  995. +#define HIGH_BIT_HIGH_TIME 50
  996. +#define HIGH_BIT_LOW_TIME 10
  997. +#define MAX_BRIGHTNESS_VALUE 9
  998. +
  999. +static void entry_1wire_mode(struct ocp8178_backlight *gbl)
  1000. +{
  1001. + unsigned long flags = 0;
  1002. + local_irq_save(flags);
  1003. + gpiod_set_value(gbl->gpiod, 0);
  1004. + mdelay(SHUTDOWN_TIME/1000);
  1005. + gpiod_set_value(gbl->gpiod, 1);
  1006. + udelay(DETECT_DELAY);
  1007. + gpiod_set_value(gbl->gpiod, 0);
  1008. + udelay(DETECT_TIME);
  1009. + gpiod_set_value(gbl->gpiod, 1);
  1010. + udelay(DETECT_WINDOW_TIME);
  1011. + local_irq_restore(flags);
  1012. +}
  1013. +
  1014. +static inline void write_bit(struct ocp8178_backlight *gbl, int bit)
  1015. +{
  1016. + if (bit) {
  1017. + gpiod_set_value(gbl->gpiod, 0);
  1018. + udelay(HIGH_BIT_LOW_TIME);
  1019. + gpiod_set_value(gbl->gpiod, 1);
  1020. + udelay(HIGH_BIT_HIGH_TIME);
  1021. + } else {
  1022. + gpiod_set_value(gbl->gpiod, 0);
  1023. + udelay(LOW_BIT_LOW_TIME);
  1024. + gpiod_set_value(gbl->gpiod, 1);
  1025. + udelay(LOW_BIT_HIGH_TIME);
  1026. + }
  1027. +}
  1028. +
  1029. +static void write_byte(struct ocp8178_backlight *gbl, int byte)
  1030. +{
  1031. + unsigned long flags = 0;
  1032. + unsigned char data = 0x72;
  1033. + int i;
  1034. +
  1035. + local_irq_save(flags);
  1036. +
  1037. + gpiod_set_value(gbl->gpiod, 1);
  1038. + udelay(START_TIME);
  1039. + for(i = 0; i < 8; i++) {
  1040. + if(data & 0x80) {
  1041. + write_bit(gbl, 1);
  1042. + } else {
  1043. + write_bit(gbl, 0);
  1044. + }
  1045. + data <<= 1;
  1046. + }
  1047. + gpiod_set_value(gbl->gpiod, 0);
  1048. + udelay(END_TIME);
  1049. +
  1050. + data = byte & 0x1f;
  1051. +
  1052. + gpiod_set_value(gbl->gpiod, 1);
  1053. + udelay(START_TIME);
  1054. + for(i = 0; i < 8; i++) {
  1055. + if(data & 0x80) {
  1056. + write_bit(gbl, 1);
  1057. + } else {
  1058. + write_bit(gbl, 0);
  1059. + }
  1060. + data <<= 1;
  1061. + }
  1062. + gpiod_set_value(gbl->gpiod, 0);
  1063. + udelay(END_TIME);
  1064. + gpiod_set_value(gbl->gpiod, 1);
  1065. +
  1066. + local_irq_restore(flags);
  1067. +}
  1068. +
  1069. +unsigned char ocp8178_bl_table[MAX_BRIGHTNESS_VALUE+1] = {0, 1, 4, 8, 12, 16, 20, 24, 28, 31};
  1070. +
  1071. +static int ocp8178_update_status(struct backlight_device *bl)
  1072. +{
  1073. + struct ocp8178_backlight *gbl = bl_get_data(bl);
  1074. + int brightness = bl->props.brightness, i;
  1075. +
  1076. + if (bl->props.power != FB_BLANK_UNBLANK ||
  1077. + bl->props.fb_blank != FB_BLANK_UNBLANK ||
  1078. + bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
  1079. + brightness = 0;
  1080. +
  1081. + if(brightness > MAX_BRIGHTNESS_VALUE)
  1082. + brightness = MAX_BRIGHTNESS_VALUE;
  1083. +
  1084. + for(i = 0; i < 2; i++) {
  1085. + entry_1wire_mode(gbl);
  1086. + write_byte(gbl, ocp8178_bl_table[brightness]);
  1087. + }
  1088. + gbl->current_value = brightness;
  1089. +
  1090. + return 0;
  1091. +}
  1092. +
  1093. +static int ocp8178_get_brightness(struct backlight_device *bl)
  1094. +{
  1095. + struct ocp8178_backlight *gbl = bl_get_data(bl);
  1096. + return gbl->current_value;
  1097. +}
  1098. +
  1099. +static int ocp8178_check_fb(struct backlight_device *bl,
  1100. + struct fb_info *info)
  1101. +{
  1102. + struct ocp8178_backlight *gbl = bl_get_data(bl);
  1103. + return gbl->fbdev == NULL || gbl->fbdev == info->dev;
  1104. +}
  1105. +
  1106. +static const struct backlight_ops ocp8178_backlight_ops = {
  1107. + .options = BL_CORE_SUSPENDRESUME,
  1108. + .update_status = ocp8178_update_status,
  1109. + .get_brightness = ocp8178_get_brightness,
  1110. + .check_fb = ocp8178_check_fb,
  1111. +};
  1112. +
  1113. +static int ocp8178_probe_dt(struct platform_device *pdev,
  1114. + struct ocp8178_backlight *gbl)
  1115. +{
  1116. + struct device *dev = &pdev->dev;
  1117. + struct device_node *np = dev->of_node;
  1118. + enum gpiod_flags flags;
  1119. + int ret = 0;
  1120. + u32 value32;
  1121. +
  1122. + of_property_read_u32(np, "default-brightness", &value32);
  1123. + if(value32 > MAX_BRIGHTNESS_VALUE)
  1124. + gbl->def_value = MAX_BRIGHTNESS_VALUE;
  1125. + else
  1126. + gbl->def_value = value32;
  1127. + flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
  1128. +
  1129. + gbl->gpiod = devm_gpiod_get(dev, "backlight-control", flags);
  1130. + if (IS_ERR(gbl->gpiod)) {
  1131. + ret = PTR_ERR(gbl->gpiod);
  1132. +
  1133. + if (ret != -EPROBE_DEFER) {
  1134. + dev_err(dev,
  1135. + "Error: The gpios parameter is missing or invalid.\n");
  1136. + }
  1137. + }
  1138. +
  1139. + return ret;
  1140. +}
  1141. +
  1142. +static struct backlight_device *backlight;
  1143. +
  1144. +static int ocp8178_probe(struct platform_device *pdev)
  1145. +{
  1146. + struct backlight_properties props;
  1147. + struct backlight_device *bl;
  1148. + struct ocp8178_backlight *gbl;
  1149. + struct device_node *np = pdev->dev.of_node;
  1150. + int ret;
  1151. +
  1152. + if ( !np) {
  1153. + dev_err(&pdev->dev,
  1154. + "failed to find platform data or device tree node.\n");
  1155. + return -ENODEV;
  1156. + }
  1157. +
  1158. + gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL);
  1159. + if (gbl == NULL)
  1160. + return -ENOMEM;
  1161. +
  1162. + gbl->dev = &pdev->dev;
  1163. +
  1164. + ret = ocp8178_probe_dt(pdev, gbl);
  1165. + if (ret)
  1166. + return ret;
  1167. +
  1168. + gbl->current_value = gbl->def_value;
  1169. +
  1170. + memset(&props, 0, sizeof(props));
  1171. + props.type = BACKLIGHT_RAW;
  1172. + props.max_brightness = MAX_BRIGHTNESS_VALUE;
  1173. + bl = devm_backlight_device_register(&pdev->dev, dev_name(&pdev->dev),
  1174. + &pdev->dev, gbl, &ocp8178_backlight_ops,
  1175. + &props);
  1176. + if (IS_ERR(bl)) {
  1177. + dev_err(&pdev->dev, "failed to register backlight\n");
  1178. + return PTR_ERR(bl);
  1179. + }
  1180. +
  1181. +// entry_1wire_mode(gbl);
  1182. +
  1183. + bl->props.brightness = gbl->def_value;
  1184. + backlight_update_status(bl);
  1185. +
  1186. + platform_set_drvdata(pdev, bl);
  1187. +
  1188. + backlight = bl;
  1189. + return 0;
  1190. +}
  1191. +
  1192. +static int ocp8178_suspend(struct platform_device *pdev, pm_message_t state)
  1193. +{
  1194. + return 0;
  1195. +}
  1196. +
  1197. +static int ocp8178_resume(struct platform_device *pdev)
  1198. +{
  1199. + return 0;
  1200. +}
  1201. +
  1202. +static struct of_device_id ocp8178_of_match[] = {
  1203. + { .compatible = "ocp8178-backlight" },
  1204. + { /* sentinel */ }
  1205. +};
  1206. +
  1207. +MODULE_DEVICE_TABLE(of, ocp8178_of_match);
  1208. +
  1209. +static struct platform_driver ocp8178_driver = {
  1210. + .driver = {
  1211. + .name = "ocp8178-backlight",
  1212. + .of_match_table = of_match_ptr(ocp8178_of_match),
  1213. + },
  1214. + .probe = ocp8178_probe,
  1215. + .suspend = ocp8178_suspend,
  1216. + .resume = ocp8178_resume,
  1217. +};
  1218. +
  1219. +module_platform_driver(ocp8178_driver);
  1220. +
  1221. +MODULE_DESCRIPTION("OCP8178 Driver");
  1222. +MODULE_LICENSE("GPL");