0331-drm-vc4-Add-DPI-driver.patch 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. From 1993e73606600fecd48190c650b732da12d62158 Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Wed, 10 Feb 2016 11:42:32 -0800
  4. Subject: [PATCH] drm/vc4: Add DPI driver
  5. The DPI interface involves taking a ton of our GPIOs to be used as
  6. outputs, and routing display signals over them in parallel.
  7. v2: Use display_info.bus_formats[] to replace our custom DT
  8. properties.
  9. v3: Rebase on V3D documentation changes.
  10. v4: Fix rebase detritus from V3D documentation changes.
  11. Signed-off-by: Eric Anholt <eric@anholt.net>
  12. Acked-by: Rob Herring <robh@kernel.org>
  13. (cherry picked from commit 08302c35b59d306ff37b996e56fb2a488c1d2c2e)
  14. ---
  15. .../devicetree/bindings/display/brcm,bcm-vc4.txt | 36 ++
  16. drivers/gpu/drm/vc4/Kconfig | 1 +
  17. drivers/gpu/drm/vc4/Makefile | 1 +
  18. drivers/gpu/drm/vc4/vc4_debugfs.c | 1 +
  19. drivers/gpu/drm/vc4/vc4_dpi.c | 520 +++++++++++++++++++++
  20. drivers/gpu/drm/vc4/vc4_drv.c | 1 +
  21. drivers/gpu/drm/vc4/vc4_drv.h | 5 +
  22. 7 files changed, 565 insertions(+)
  23. create mode 100644 drivers/gpu/drm/vc4/vc4_dpi.c
  24. --- a/Documentation/devicetree/bindings/display/brcm,bcm-vc4.txt
  25. +++ b/Documentation/devicetree/bindings/display/brcm,bcm-vc4.txt
  26. @@ -35,12 +35,22 @@ Optional properties for HDMI:
  27. as an interrupt/status bit in the HDMI controller
  28. itself). See bindings/pinctrl/brcm,bcm2835-gpio.txt
  29. +Required properties for DPI:
  30. +- compatible: Should be "brcm,bcm2835-dpi"
  31. +- reg: Physical base address and length of the registers
  32. +- clocks: a) core: The core clock the unit runs on
  33. + b) pixel: The pixel clock that feeds the pixelvalve
  34. +- port: Port node with a single endpoint connecting to the panel
  35. + device, as defined in [1]
  36. +
  37. Required properties for V3D:
  38. - compatible: Should be "brcm,bcm2835-v3d"
  39. - reg: Physical base address and length of the V3D's registers
  40. - interrupts: The interrupt number
  41. See bindings/interrupt-controller/brcm,bcm2835-armctrl-ic.txt
  42. +[1] Documentation/devicetree/bindings/media/video-interfaces.txt
  43. +
  44. Example:
  45. pixelvalve@7e807000 {
  46. compatible = "brcm,bcm2835-pixelvalve2";
  47. @@ -66,6 +76,22 @@ hdmi: hdmi@7e902000 {
  48. clock-names = "pixel", "hdmi";
  49. };
  50. +dpi: dpi@7e208000 {
  51. + compatible = "brcm,bcm2835-dpi";
  52. + reg = <0x7e208000 0x8c>;
  53. + clocks = <&clocks BCM2835_CLOCK_VPU>,
  54. + <&clocks BCM2835_CLOCK_DPI>;
  55. + clock-names = "core", "pixel";
  56. + #address-cells = <1>;
  57. + #size-cells = <0>;
  58. +
  59. + port {
  60. + dpi_out: endpoint@0 {
  61. + remote-endpoint = <&panel_in>;
  62. + };
  63. + };
  64. +};
  65. +
  66. v3d: v3d@7ec00000 {
  67. compatible = "brcm,bcm2835-v3d";
  68. reg = <0x7ec00000 0x1000>;
  69. @@ -75,3 +101,13 @@ v3d: v3d@7ec00000 {
  70. vc4: gpu {
  71. compatible = "brcm,bcm2835-vc4";
  72. };
  73. +
  74. +panel: panel {
  75. + compatible = "ontat,yx700wv03", "simple-panel";
  76. +
  77. + port {
  78. + panel_in: endpoint {
  79. + remote-endpoint = <&dpi_out>;
  80. + };
  81. + };
  82. +};
  83. --- a/drivers/gpu/drm/vc4/Kconfig
  84. +++ b/drivers/gpu/drm/vc4/Kconfig
  85. @@ -5,6 +5,7 @@ config DRM_VC4
  86. select DRM_KMS_HELPER
  87. select DRM_KMS_CMA_HELPER
  88. select DRM_GEM_CMA_HELPER
  89. + select DRM_PANEL
  90. help
  91. Choose this option if you have a system that has a Broadcom
  92. VC4 GPU, such as the Raspberry Pi or other BCM2708/BCM2835.
  93. --- a/drivers/gpu/drm/vc4/Makefile
  94. +++ b/drivers/gpu/drm/vc4/Makefile
  95. @@ -7,6 +7,7 @@ vc4-y := \
  96. vc4_bo.o \
  97. vc4_crtc.o \
  98. vc4_drv.o \
  99. + vc4_dpi.o \
  100. vc4_kms.o \
  101. vc4_gem.o \
  102. vc4_hdmi.o \
  103. --- a/drivers/gpu/drm/vc4/vc4_debugfs.c
  104. +++ b/drivers/gpu/drm/vc4/vc4_debugfs.c
  105. @@ -17,6 +17,7 @@
  106. static const struct drm_info_list vc4_debugfs_list[] = {
  107. {"bo_stats", vc4_bo_stats_debugfs, 0},
  108. + {"dpi_regs", vc4_dpi_debugfs_regs, 0},
  109. {"gem_exec", vc4_gem_exec_debugfs, 0},
  110. {"hdmi_regs", vc4_hdmi_debugfs_regs, 0},
  111. {"hvs_regs", vc4_hvs_debugfs_regs, 0},
  112. --- /dev/null
  113. +++ b/drivers/gpu/drm/vc4/vc4_dpi.c
  114. @@ -0,0 +1,520 @@
  115. +/*
  116. + * Copyright (C) 2016 Broadcom Limited
  117. + *
  118. + * This program is free software; you can redistribute it and/or modify it
  119. + * under the terms of the GNU General Public License version 2 as published by
  120. + * the Free Software Foundation.
  121. + *
  122. + * This program is distributed in the hope that it will be useful, but WITHOUT
  123. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  124. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  125. + * more details.
  126. + *
  127. + * You should have received a copy of the GNU General Public License along with
  128. + * this program. If not, see <http://www.gnu.org/licenses/>.
  129. + */
  130. +
  131. +/**
  132. + * DOC: VC4 DPI module
  133. + *
  134. + * The VC4 DPI hardware supports MIPI DPI type 4 and Nokia ViSSI
  135. + * signals, which are routed out to GPIO0-27 with the ALT2 function.
  136. + */
  137. +
  138. +#include "drm_atomic_helper.h"
  139. +#include "drm_crtc_helper.h"
  140. +#include "drm_edid.h"
  141. +#include "drm_panel.h"
  142. +#include "linux/clk.h"
  143. +#include "linux/component.h"
  144. +#include "linux/of_graph.h"
  145. +#include "linux/of_platform.h"
  146. +#include "vc4_drv.h"
  147. +#include "vc4_regs.h"
  148. +
  149. +#define DPI_C 0x00
  150. +# define DPI_OUTPUT_ENABLE_MODE BIT(16)
  151. +
  152. +/* The order field takes the incoming 24 bit RGB from the pixel valve
  153. + * and shuffles the 3 channels.
  154. + */
  155. +# define DPI_ORDER_MASK VC4_MASK(15, 14)
  156. +# define DPI_ORDER_SHIFT 14
  157. +# define DPI_ORDER_RGB 0
  158. +# define DPI_ORDER_BGR 1
  159. +# define DPI_ORDER_GRB 2
  160. +# define DPI_ORDER_BRG 3
  161. +
  162. +/* The format field takes the ORDER-shuffled pixel valve data and
  163. + * formats it onto the output lines.
  164. + */
  165. +# define DPI_FORMAT_MASK VC4_MASK(13, 11)
  166. +# define DPI_FORMAT_SHIFT 11
  167. +/* This define is named in the hardware, but actually just outputs 0. */
  168. +# define DPI_FORMAT_9BIT_666_RGB 0
  169. +/* Outputs 00000000rrrrrggggggbbbbb */
  170. +# define DPI_FORMAT_16BIT_565_RGB_1 1
  171. +/* Outputs 000rrrrr00gggggg000bbbbb */
  172. +# define DPI_FORMAT_16BIT_565_RGB_2 2
  173. +/* Outputs 00rrrrr000gggggg00bbbbb0 */
  174. +# define DPI_FORMAT_16BIT_565_RGB_3 3
  175. +/* Outputs 000000rrrrrrggggggbbbbbb */
  176. +# define DPI_FORMAT_18BIT_666_RGB_1 4
  177. +/* Outputs 00rrrrrr00gggggg00bbbbbb */
  178. +# define DPI_FORMAT_18BIT_666_RGB_2 5
  179. +/* Outputs rrrrrrrrggggggggbbbbbbbb */
  180. +# define DPI_FORMAT_24BIT_888_RGB 6
  181. +
  182. +/* Reverses the polarity of the corresponding signal */
  183. +# define DPI_PIXEL_CLK_INVERT BIT(10)
  184. +# define DPI_HSYNC_INVERT BIT(9)
  185. +# define DPI_VSYNC_INVERT BIT(8)
  186. +# define DPI_OUTPUT_ENABLE_INVERT BIT(7)
  187. +
  188. +/* Outputs the signal the falling clock edge instead of rising. */
  189. +# define DPI_HSYNC_NEGATE BIT(6)
  190. +# define DPI_VSYNC_NEGATE BIT(5)
  191. +# define DPI_OUTPUT_ENABLE_NEGATE BIT(4)
  192. +
  193. +/* Disables the signal */
  194. +# define DPI_HSYNC_DISABLE BIT(3)
  195. +# define DPI_VSYNC_DISABLE BIT(2)
  196. +# define DPI_OUTPUT_ENABLE_DISABLE BIT(1)
  197. +
  198. +/* Power gate to the device, full reset at 0 -> 1 transition */
  199. +# define DPI_ENABLE BIT(0)
  200. +
  201. +/* All other registers besides DPI_C return the ID */
  202. +#define DPI_ID 0x04
  203. +# define DPI_ID_VALUE 0x00647069
  204. +
  205. +/* General DPI hardware state. */
  206. +struct vc4_dpi {
  207. + struct platform_device *pdev;
  208. +
  209. + struct drm_encoder *encoder;
  210. + struct drm_connector *connector;
  211. + struct drm_panel *panel;
  212. +
  213. + void __iomem *regs;
  214. +
  215. + struct clk *pixel_clock;
  216. + struct clk *core_clock;
  217. +};
  218. +
  219. +#define DPI_READ(offset) readl(dpi->regs + (offset))
  220. +#define DPI_WRITE(offset, val) writel(val, dpi->regs + (offset))
  221. +
  222. +/* VC4 DPI encoder KMS struct */
  223. +struct vc4_dpi_encoder {
  224. + struct vc4_encoder base;
  225. + struct vc4_dpi *dpi;
  226. +};
  227. +
  228. +static inline struct vc4_dpi_encoder *
  229. +to_vc4_dpi_encoder(struct drm_encoder *encoder)
  230. +{
  231. + return container_of(encoder, struct vc4_dpi_encoder, base.base);
  232. +}
  233. +
  234. +/* VC4 DPI connector KMS struct */
  235. +struct vc4_dpi_connector {
  236. + struct drm_connector base;
  237. + struct vc4_dpi *dpi;
  238. +
  239. + /* Since the connector is attached to just the one encoder,
  240. + * this is the reference to it so we can do the best_encoder()
  241. + * hook.
  242. + */
  243. + struct drm_encoder *encoder;
  244. +};
  245. +
  246. +static inline struct vc4_dpi_connector *
  247. +to_vc4_dpi_connector(struct drm_connector *connector)
  248. +{
  249. + return container_of(connector, struct vc4_dpi_connector, base);
  250. +}
  251. +
  252. +#define DPI_REG(reg) { reg, #reg }
  253. +static const struct {
  254. + u32 reg;
  255. + const char *name;
  256. +} dpi_regs[] = {
  257. + DPI_REG(DPI_C),
  258. + DPI_REG(DPI_ID),
  259. +};
  260. +
  261. +static void vc4_dpi_dump_regs(struct vc4_dpi *dpi)
  262. +{
  263. + int i;
  264. +
  265. + for (i = 0; i < ARRAY_SIZE(dpi_regs); i++) {
  266. + DRM_INFO("0x%04x (%s): 0x%08x\n",
  267. + dpi_regs[i].reg, dpi_regs[i].name,
  268. + DPI_READ(dpi_regs[i].reg));
  269. + }
  270. +}
  271. +
  272. +#ifdef CONFIG_DEBUG_FS
  273. +int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused)
  274. +{
  275. + struct drm_info_node *node = (struct drm_info_node *)m->private;
  276. + struct drm_device *dev = node->minor->dev;
  277. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  278. + struct vc4_dpi *dpi = vc4->dpi;
  279. + int i;
  280. +
  281. + if (!dpi)
  282. + return 0;
  283. +
  284. + for (i = 0; i < ARRAY_SIZE(dpi_regs); i++) {
  285. + seq_printf(m, "%s (0x%04x): 0x%08x\n",
  286. + dpi_regs[i].name, dpi_regs[i].reg,
  287. + DPI_READ(dpi_regs[i].reg));
  288. + }
  289. +
  290. + return 0;
  291. +}
  292. +#endif
  293. +
  294. +static enum drm_connector_status
  295. +vc4_dpi_connector_detect(struct drm_connector *connector, bool force)
  296. +{
  297. + struct vc4_dpi_connector *vc4_connector =
  298. + to_vc4_dpi_connector(connector);
  299. + struct vc4_dpi *dpi = vc4_connector->dpi;
  300. +
  301. + if (dpi->panel)
  302. + return connector_status_connected;
  303. + else
  304. + return connector_status_disconnected;
  305. +}
  306. +
  307. +static void vc4_dpi_connector_destroy(struct drm_connector *connector)
  308. +{
  309. + drm_connector_unregister(connector);
  310. + drm_connector_cleanup(connector);
  311. +}
  312. +
  313. +static int vc4_dpi_connector_get_modes(struct drm_connector *connector)
  314. +{
  315. + struct vc4_dpi_connector *vc4_connector =
  316. + to_vc4_dpi_connector(connector);
  317. + struct vc4_dpi *dpi = vc4_connector->dpi;
  318. +
  319. + if (dpi->panel)
  320. + return drm_panel_get_modes(dpi->panel);
  321. +
  322. + return 0;
  323. +}
  324. +
  325. +static struct drm_encoder *
  326. +vc4_dpi_connector_best_encoder(struct drm_connector *connector)
  327. +{
  328. + struct vc4_dpi_connector *dpi_connector =
  329. + to_vc4_dpi_connector(connector);
  330. + return dpi_connector->encoder;
  331. +}
  332. +
  333. +static const struct drm_connector_funcs vc4_dpi_connector_funcs = {
  334. + .dpms = drm_atomic_helper_connector_dpms,
  335. + .detect = vc4_dpi_connector_detect,
  336. + .fill_modes = drm_helper_probe_single_connector_modes,
  337. + .destroy = vc4_dpi_connector_destroy,
  338. + .reset = drm_atomic_helper_connector_reset,
  339. + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  340. + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  341. +};
  342. +
  343. +static const struct drm_connector_helper_funcs vc4_dpi_connector_helper_funcs = {
  344. + .get_modes = vc4_dpi_connector_get_modes,
  345. + .best_encoder = vc4_dpi_connector_best_encoder,
  346. +};
  347. +
  348. +static struct drm_connector *vc4_dpi_connector_init(struct drm_device *dev,
  349. + struct vc4_dpi *dpi)
  350. +{
  351. + struct drm_connector *connector = NULL;
  352. + struct vc4_dpi_connector *dpi_connector;
  353. + int ret = 0;
  354. +
  355. + dpi_connector = devm_kzalloc(dev->dev, sizeof(*dpi_connector),
  356. + GFP_KERNEL);
  357. + if (!dpi_connector) {
  358. + ret = -ENOMEM;
  359. + goto fail;
  360. + }
  361. + connector = &dpi_connector->base;
  362. +
  363. + dpi_connector->encoder = dpi->encoder;
  364. + dpi_connector->dpi = dpi;
  365. +
  366. + drm_connector_init(dev, connector, &vc4_dpi_connector_funcs,
  367. + DRM_MODE_CONNECTOR_DPI);
  368. + drm_connector_helper_add(connector, &vc4_dpi_connector_helper_funcs);
  369. +
  370. + connector->polled = 0;
  371. + connector->interlace_allowed = 0;
  372. + connector->doublescan_allowed = 0;
  373. +
  374. + drm_mode_connector_attach_encoder(connector, dpi->encoder);
  375. +
  376. + return connector;
  377. +
  378. + fail:
  379. + if (connector)
  380. + vc4_dpi_connector_destroy(connector);
  381. +
  382. + return ERR_PTR(ret);
  383. +}
  384. +
  385. +static const struct drm_encoder_funcs vc4_dpi_encoder_funcs = {
  386. + .destroy = drm_encoder_cleanup,
  387. +};
  388. +
  389. +static void vc4_dpi_encoder_disable(struct drm_encoder *encoder)
  390. +{
  391. + struct vc4_dpi_encoder *vc4_encoder = to_vc4_dpi_encoder(encoder);
  392. + struct vc4_dpi *dpi = vc4_encoder->dpi;
  393. +
  394. + drm_panel_disable(dpi->panel);
  395. +
  396. + clk_disable_unprepare(dpi->pixel_clock);
  397. +
  398. + drm_panel_unprepare(dpi->panel);
  399. +}
  400. +
  401. +static void vc4_dpi_encoder_enable(struct drm_encoder *encoder)
  402. +{
  403. + struct drm_display_mode *mode = &encoder->crtc->mode;
  404. + struct vc4_dpi_encoder *vc4_encoder = to_vc4_dpi_encoder(encoder);
  405. + struct vc4_dpi *dpi = vc4_encoder->dpi;
  406. + u32 dpi_c = DPI_ENABLE | DPI_OUTPUT_ENABLE_MODE;
  407. + int ret;
  408. +
  409. + ret = drm_panel_prepare(dpi->panel);
  410. + if (ret) {
  411. + DRM_ERROR("Panel failed to prepare\n");
  412. + return;
  413. + }
  414. +
  415. + if (dpi->connector->display_info.num_bus_formats) {
  416. + u32 bus_format = dpi->connector->display_info.bus_formats[0];
  417. +
  418. + switch (bus_format) {
  419. + case MEDIA_BUS_FMT_RGB888_1X24:
  420. + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_24BIT_888_RGB,
  421. + DPI_FORMAT);
  422. + break;
  423. + case MEDIA_BUS_FMT_BGR888_1X24:
  424. + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_24BIT_888_RGB,
  425. + DPI_FORMAT);
  426. + dpi_c |= VC4_SET_FIELD(DPI_ORDER_BGR, DPI_ORDER);
  427. + break;
  428. + case MEDIA_BUS_FMT_RGB666_1X24_CPADHI:
  429. + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_18BIT_666_RGB_2,
  430. + DPI_FORMAT);
  431. + break;
  432. + case MEDIA_BUS_FMT_RGB666_1X18:
  433. + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_18BIT_666_RGB_1,
  434. + DPI_FORMAT);
  435. + break;
  436. + case MEDIA_BUS_FMT_RGB565_1X16:
  437. + dpi_c |= VC4_SET_FIELD(DPI_FORMAT_16BIT_565_RGB_3,
  438. + DPI_FORMAT);
  439. + break;
  440. + default:
  441. + DRM_ERROR("Unknown media bus format %d\n", bus_format);
  442. + break;
  443. + }
  444. + }
  445. +
  446. + if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  447. + dpi_c |= DPI_HSYNC_INVERT;
  448. + else if (!(mode->flags & DRM_MODE_FLAG_PHSYNC))
  449. + dpi_c |= DPI_HSYNC_DISABLE;
  450. +
  451. + if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  452. + dpi_c |= DPI_VSYNC_INVERT;
  453. + else if (!(mode->flags & DRM_MODE_FLAG_PVSYNC))
  454. + dpi_c |= DPI_VSYNC_DISABLE;
  455. +
  456. + DPI_WRITE(DPI_C, dpi_c);
  457. +
  458. + ret = clk_set_rate(dpi->pixel_clock, mode->clock * 1000);
  459. + if (ret)
  460. + DRM_ERROR("Failed to set clock rate: %d\n", ret);
  461. +
  462. + ret = clk_prepare_enable(dpi->pixel_clock);
  463. + if (ret)
  464. + DRM_ERROR("Failed to set clock rate: %d\n", ret);
  465. +
  466. + ret = drm_panel_enable(dpi->panel);
  467. + if (ret) {
  468. + DRM_ERROR("Panel failed to enable\n");
  469. + drm_panel_unprepare(dpi->panel);
  470. + return;
  471. + }
  472. +}
  473. +
  474. +static const struct drm_encoder_helper_funcs vc4_dpi_encoder_helper_funcs = {
  475. + .disable = vc4_dpi_encoder_disable,
  476. + .enable = vc4_dpi_encoder_enable,
  477. +};
  478. +
  479. +static const struct of_device_id vc4_dpi_dt_match[] = {
  480. + { .compatible = "brcm,bcm2835-dpi", .data = NULL },
  481. + {}
  482. +};
  483. +
  484. +/* Walks the OF graph to find the panel node and then asks DRM to look
  485. + * up the panel.
  486. + */
  487. +static struct drm_panel *vc4_dpi_get_panel(struct device *dev)
  488. +{
  489. + struct device_node *endpoint, *panel_node;
  490. + struct device_node *np = dev->of_node;
  491. + struct drm_panel *panel;
  492. +
  493. + endpoint = of_graph_get_next_endpoint(np, NULL);
  494. + if (!endpoint) {
  495. + dev_err(dev, "no endpoint to fetch DPI panel\n");
  496. + return NULL;
  497. + }
  498. +
  499. + /* don't proceed if we have an endpoint but no panel_node tied to it */
  500. + panel_node = of_graph_get_remote_port_parent(endpoint);
  501. + of_node_put(endpoint);
  502. + if (!panel_node) {
  503. + dev_err(dev, "no valid panel node\n");
  504. + return NULL;
  505. + }
  506. +
  507. + panel = of_drm_find_panel(panel_node);
  508. + of_node_put(panel_node);
  509. +
  510. + return panel;
  511. +}
  512. +
  513. +static int vc4_dpi_bind(struct device *dev, struct device *master, void *data)
  514. +{
  515. + struct platform_device *pdev = to_platform_device(dev);
  516. + struct drm_device *drm = dev_get_drvdata(master);
  517. + struct vc4_dev *vc4 = to_vc4_dev(drm);
  518. + struct vc4_dpi *dpi;
  519. + struct vc4_dpi_encoder *vc4_dpi_encoder;
  520. + int ret;
  521. +
  522. + dpi = devm_kzalloc(dev, sizeof(*dpi), GFP_KERNEL);
  523. + if (!dpi)
  524. + return -ENOMEM;
  525. +
  526. + vc4_dpi_encoder = devm_kzalloc(dev, sizeof(*vc4_dpi_encoder),
  527. + GFP_KERNEL);
  528. + if (!vc4_dpi_encoder)
  529. + return -ENOMEM;
  530. + vc4_dpi_encoder->base.type = VC4_ENCODER_TYPE_DPI;
  531. + vc4_dpi_encoder->dpi = dpi;
  532. + dpi->encoder = &vc4_dpi_encoder->base.base;
  533. +
  534. + dpi->pdev = pdev;
  535. + dpi->regs = vc4_ioremap_regs(pdev, 0);
  536. + if (IS_ERR(dpi->regs))
  537. + return PTR_ERR(dpi->regs);
  538. +
  539. + vc4_dpi_dump_regs(dpi);
  540. +
  541. + if (DPI_READ(DPI_ID) != DPI_ID_VALUE) {
  542. + dev_err(dev, "Port returned 0x%08x for ID instead of 0x%08x\n",
  543. + DPI_READ(DPI_ID), DPI_ID_VALUE);
  544. + return -ENODEV;
  545. + }
  546. +
  547. + dpi->core_clock = devm_clk_get(dev, "core");
  548. + if (IS_ERR(dpi->core_clock)) {
  549. + ret = PTR_ERR(dpi->core_clock);
  550. + if (ret != -EPROBE_DEFER)
  551. + DRM_ERROR("Failed to get core clock: %d\n", ret);
  552. + return ret;
  553. + }
  554. + dpi->pixel_clock = devm_clk_get(dev, "pixel");
  555. + if (IS_ERR(dpi->pixel_clock)) {
  556. + ret = PTR_ERR(dpi->pixel_clock);
  557. + if (ret != -EPROBE_DEFER)
  558. + DRM_ERROR("Failed to get pixel clock: %d\n", ret);
  559. + return ret;
  560. + }
  561. +
  562. + ret = clk_prepare_enable(dpi->core_clock);
  563. + if (ret)
  564. + DRM_ERROR("Failed to turn on core clock: %d\n", ret);
  565. +
  566. + dpi->panel = vc4_dpi_get_panel(dev);
  567. +
  568. + drm_encoder_init(drm, dpi->encoder, &vc4_dpi_encoder_funcs,
  569. + DRM_MODE_ENCODER_DPI);
  570. + drm_encoder_helper_add(dpi->encoder, &vc4_dpi_encoder_helper_funcs);
  571. +
  572. + dpi->connector = vc4_dpi_connector_init(drm, dpi);
  573. + if (IS_ERR(dpi->connector)) {
  574. + ret = PTR_ERR(dpi->connector);
  575. + goto err_destroy_encoder;
  576. + }
  577. +
  578. + if (dpi->panel)
  579. + drm_panel_attach(dpi->panel, dpi->connector);
  580. +
  581. + dev_set_drvdata(dev, dpi);
  582. +
  583. + vc4->dpi = dpi;
  584. +
  585. + return 0;
  586. +
  587. +err_destroy_encoder:
  588. + drm_encoder_cleanup(dpi->encoder);
  589. + clk_disable_unprepare(dpi->core_clock);
  590. + return ret;
  591. +}
  592. +
  593. +static void vc4_dpi_unbind(struct device *dev, struct device *master,
  594. + void *data)
  595. +{
  596. + struct drm_device *drm = dev_get_drvdata(master);
  597. + struct vc4_dev *vc4 = to_vc4_dev(drm);
  598. + struct vc4_dpi *dpi = dev_get_drvdata(dev);
  599. +
  600. + if (dpi->panel)
  601. + drm_panel_detach(dpi->panel);
  602. +
  603. + vc4_dpi_connector_destroy(dpi->connector);
  604. + drm_encoder_cleanup(dpi->encoder);
  605. +
  606. + clk_disable_unprepare(dpi->core_clock);
  607. +
  608. + vc4->dpi = NULL;
  609. +}
  610. +
  611. +static const struct component_ops vc4_dpi_ops = {
  612. + .bind = vc4_dpi_bind,
  613. + .unbind = vc4_dpi_unbind,
  614. +};
  615. +
  616. +static int vc4_dpi_dev_probe(struct platform_device *pdev)
  617. +{
  618. + return component_add(&pdev->dev, &vc4_dpi_ops);
  619. +}
  620. +
  621. +static int vc4_dpi_dev_remove(struct platform_device *pdev)
  622. +{
  623. + component_del(&pdev->dev, &vc4_dpi_ops);
  624. + return 0;
  625. +}
  626. +
  627. +struct platform_driver vc4_dpi_driver = {
  628. + .probe = vc4_dpi_dev_probe,
  629. + .remove = vc4_dpi_dev_remove,
  630. + .driver = {
  631. + .name = "vc4_dpi",
  632. + .of_match_table = vc4_dpi_dt_match,
  633. + },
  634. +};
  635. --- a/drivers/gpu/drm/vc4/vc4_drv.c
  636. +++ b/drivers/gpu/drm/vc4/vc4_drv.c
  637. @@ -259,6 +259,7 @@ static const struct component_master_ops
  638. static struct platform_driver *const component_drivers[] = {
  639. &vc4_hdmi_driver,
  640. + &vc4_dpi_driver,
  641. &vc4_crtc_driver,
  642. &vc4_hvs_driver,
  643. &vc4_v3d_driver,
  644. --- a/drivers/gpu/drm/vc4/vc4_drv.h
  645. +++ b/drivers/gpu/drm/vc4/vc4_drv.h
  646. @@ -16,6 +16,7 @@ struct vc4_dev {
  647. struct vc4_hvs *hvs;
  648. struct vc4_crtc *crtc[3];
  649. struct vc4_v3d *v3d;
  650. + struct vc4_dpi *dpi;
  651. struct drm_fbdev_cma *fbdev;
  652. struct rpi_firmware *firmware;
  653. @@ -418,6 +419,10 @@ void vc4_debugfs_cleanup(struct drm_mino
  654. /* vc4_drv.c */
  655. void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
  656. +/* vc4_dpi.c */
  657. +extern struct platform_driver vc4_dpi_driver;
  658. +int vc4_dpi_debugfs_regs(struct seq_file *m, void *unused);
  659. +
  660. /* vc4_gem.c */
  661. void vc4_gem_init(struct drm_device *dev);
  662. void vc4_gem_destroy(struct drm_device *dev);