sun4i_tcon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /*
  2. * Copyright (C) 2015 Free Electrons
  3. * Copyright (C) 2015 NextThing Co
  4. *
  5. * Maxime Ripard <maxime.ripard@free-electrons.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. */
  12. #include <drm/drmP.h>
  13. #include <drm/drm_atomic_helper.h>
  14. #include <drm/drm_crtc.h>
  15. #include <drm/drm_crtc_helper.h>
  16. #include <drm/drm_modes.h>
  17. #include <drm/drm_panel.h>
  18. #include <linux/component.h>
  19. #include <linux/ioport.h>
  20. #include <linux/of_address.h>
  21. #include <linux/of_device.h>
  22. #include <linux/of_graph.h>
  23. #include <linux/of_irq.h>
  24. #include <linux/regmap.h>
  25. #include <linux/reset.h>
  26. #include "sun4i_crtc.h"
  27. #include "sun4i_dotclock.h"
  28. #include "sun4i_drv.h"
  29. #include "sun4i_rgb.h"
  30. #include "sun4i_tcon.h"
  31. void sun4i_tcon_disable(struct sun4i_tcon *tcon)
  32. {
  33. DRM_DEBUG_DRIVER("Disabling TCON\n");
  34. /* Disable the TCON */
  35. regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
  36. SUN4I_TCON_GCTL_TCON_ENABLE, 0);
  37. }
  38. EXPORT_SYMBOL(sun4i_tcon_disable);
  39. void sun4i_tcon_enable(struct sun4i_tcon *tcon)
  40. {
  41. DRM_DEBUG_DRIVER("Enabling TCON\n");
  42. /* Enable the TCON */
  43. regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
  44. SUN4I_TCON_GCTL_TCON_ENABLE,
  45. SUN4I_TCON_GCTL_TCON_ENABLE);
  46. }
  47. EXPORT_SYMBOL(sun4i_tcon_enable);
  48. void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel)
  49. {
  50. /* Disable the TCON's channel */
  51. if (channel == 0) {
  52. regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
  53. SUN4I_TCON0_CTL_TCON_ENABLE, 0);
  54. clk_disable_unprepare(tcon->dclk);
  55. return;
  56. }
  57. WARN_ON(!tcon->quirks->has_channel_1);
  58. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  59. SUN4I_TCON1_CTL_TCON_ENABLE, 0);
  60. clk_disable_unprepare(tcon->sclk1);
  61. }
  62. EXPORT_SYMBOL(sun4i_tcon_channel_disable);
  63. void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel)
  64. {
  65. /* Enable the TCON's channel */
  66. if (channel == 0) {
  67. regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
  68. SUN4I_TCON0_CTL_TCON_ENABLE,
  69. SUN4I_TCON0_CTL_TCON_ENABLE);
  70. clk_prepare_enable(tcon->dclk);
  71. return;
  72. }
  73. WARN_ON(!tcon->quirks->has_channel_1);
  74. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  75. SUN4I_TCON1_CTL_TCON_ENABLE,
  76. SUN4I_TCON1_CTL_TCON_ENABLE);
  77. clk_prepare_enable(tcon->sclk1);
  78. }
  79. EXPORT_SYMBOL(sun4i_tcon_channel_enable);
  80. void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable)
  81. {
  82. u32 mask, val = 0;
  83. DRM_DEBUG_DRIVER("%sabling VBLANK interrupt\n", enable ? "En" : "Dis");
  84. mask = SUN4I_TCON_GINT0_VBLANK_ENABLE(0) |
  85. SUN4I_TCON_GINT0_VBLANK_ENABLE(1);
  86. if (enable)
  87. val = mask;
  88. regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val);
  89. }
  90. EXPORT_SYMBOL(sun4i_tcon_enable_vblank);
  91. static int sun4i_tcon_get_clk_delay(struct drm_display_mode *mode,
  92. int channel)
  93. {
  94. int delay = mode->vtotal - mode->vdisplay;
  95. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  96. delay /= 2;
  97. if (channel == 1)
  98. delay -= 2;
  99. delay = min(delay, 30);
  100. DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay);
  101. return delay;
  102. }
  103. void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon,
  104. struct drm_display_mode *mode)
  105. {
  106. unsigned int bp, hsync, vsync;
  107. u8 clk_delay;
  108. u32 val = 0;
  109. /* Adjust clock delay */
  110. clk_delay = sun4i_tcon_get_clk_delay(mode, 0);
  111. regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
  112. SUN4I_TCON0_CTL_CLK_DELAY_MASK,
  113. SUN4I_TCON0_CTL_CLK_DELAY(clk_delay));
  114. /* Set the resolution */
  115. regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG,
  116. SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) |
  117. SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
  118. /*
  119. * This is called a backporch in the register documentation,
  120. * but it really is the front porch + hsync
  121. */
  122. bp = mode->crtc_htotal - mode->crtc_hsync_start;
  123. DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
  124. mode->crtc_htotal, bp);
  125. /* Set horizontal display timings */
  126. regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG,
  127. SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) |
  128. SUN4I_TCON0_BASIC1_H_BACKPORCH(bp));
  129. /*
  130. * This is called a backporch in the register documentation,
  131. * but it really is the front porch + hsync
  132. */
  133. bp = mode->crtc_vtotal - mode->crtc_vsync_start;
  134. DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
  135. mode->crtc_vtotal, bp);
  136. /* Set vertical display timings */
  137. regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG,
  138. SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal) |
  139. SUN4I_TCON0_BASIC2_V_BACKPORCH(bp));
  140. /* Set Hsync and Vsync length */
  141. hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
  142. vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
  143. DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
  144. regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG,
  145. SUN4I_TCON0_BASIC3_V_SYNC(vsync) |
  146. SUN4I_TCON0_BASIC3_H_SYNC(hsync));
  147. /* Setup the polarity of the various signals */
  148. if (!(mode->flags & DRM_MODE_FLAG_PHSYNC))
  149. val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE;
  150. if (!(mode->flags & DRM_MODE_FLAG_PVSYNC))
  151. val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE;
  152. regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG,
  153. SUN4I_TCON0_IO_POL_HSYNC_POSITIVE | SUN4I_TCON0_IO_POL_VSYNC_POSITIVE,
  154. val);
  155. /* Map output pins to channel 0 */
  156. regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
  157. SUN4I_TCON_GCTL_IOMAP_MASK,
  158. SUN4I_TCON_GCTL_IOMAP_TCON0);
  159. /* Enable the output on the pins */
  160. regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0);
  161. }
  162. EXPORT_SYMBOL(sun4i_tcon0_mode_set);
  163. void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
  164. struct drm_display_mode *mode)
  165. {
  166. unsigned int bp, hsync, vsync;
  167. u8 clk_delay;
  168. u32 val;
  169. WARN_ON(!tcon->quirks->has_channel_1);
  170. /* Adjust clock delay */
  171. clk_delay = sun4i_tcon_get_clk_delay(mode, 1);
  172. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  173. SUN4I_TCON1_CTL_CLK_DELAY_MASK,
  174. SUN4I_TCON1_CTL_CLK_DELAY(clk_delay));
  175. /* Set interlaced mode */
  176. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  177. val = SUN4I_TCON1_CTL_INTERLACE_ENABLE;
  178. else
  179. val = 0;
  180. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  181. SUN4I_TCON1_CTL_INTERLACE_ENABLE,
  182. val);
  183. /* Set the input resolution */
  184. regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG,
  185. SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) |
  186. SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay));
  187. /* Set the upscaling resolution */
  188. regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG,
  189. SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) |
  190. SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay));
  191. /* Set the output resolution */
  192. regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG,
  193. SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) |
  194. SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay));
  195. /* Set horizontal display timings */
  196. bp = mode->crtc_htotal - mode->crtc_hsync_end;
  197. DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
  198. mode->htotal, bp);
  199. regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG,
  200. SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) |
  201. SUN4I_TCON1_BASIC3_H_BACKPORCH(bp));
  202. /* Set vertical display timings */
  203. bp = mode->crtc_vtotal - mode->crtc_vsync_end;
  204. DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
  205. mode->vtotal, bp);
  206. regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG,
  207. SUN4I_TCON1_BASIC4_V_TOTAL(mode->vtotal) |
  208. SUN4I_TCON1_BASIC4_V_BACKPORCH(bp));
  209. /* Set Hsync and Vsync length */
  210. hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
  211. vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
  212. DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
  213. regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG,
  214. SUN4I_TCON1_BASIC5_V_SYNC(vsync) |
  215. SUN4I_TCON1_BASIC5_H_SYNC(hsync));
  216. /* Map output pins to channel 1 */
  217. regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
  218. SUN4I_TCON_GCTL_IOMAP_MASK,
  219. SUN4I_TCON_GCTL_IOMAP_TCON1);
  220. /*
  221. * FIXME: Undocumented bits
  222. */
  223. if (tcon->quirks->has_unknown_mux)
  224. regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, 1);
  225. }
  226. EXPORT_SYMBOL(sun4i_tcon1_mode_set);
  227. static void sun4i_tcon_finish_page_flip(struct drm_device *dev,
  228. struct sun4i_crtc *scrtc)
  229. {
  230. unsigned long flags;
  231. spin_lock_irqsave(&dev->event_lock, flags);
  232. if (scrtc->event) {
  233. drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event);
  234. drm_crtc_vblank_put(&scrtc->crtc);
  235. scrtc->event = NULL;
  236. }
  237. spin_unlock_irqrestore(&dev->event_lock, flags);
  238. }
  239. static irqreturn_t sun4i_tcon_handler(int irq, void *private)
  240. {
  241. struct sun4i_tcon *tcon = private;
  242. struct drm_device *drm = tcon->drm;
  243. struct sun4i_drv *drv = drm->dev_private;
  244. struct sun4i_crtc *scrtc = drv->crtc;
  245. unsigned int status;
  246. regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status);
  247. if (!(status & (SUN4I_TCON_GINT0_VBLANK_INT(0) |
  248. SUN4I_TCON_GINT0_VBLANK_INT(1))))
  249. return IRQ_NONE;
  250. drm_crtc_handle_vblank(&scrtc->crtc);
  251. sun4i_tcon_finish_page_flip(drm, scrtc);
  252. /* Acknowledge the interrupt */
  253. regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG,
  254. SUN4I_TCON_GINT0_VBLANK_INT(0) |
  255. SUN4I_TCON_GINT0_VBLANK_INT(1),
  256. 0);
  257. return IRQ_HANDLED;
  258. }
  259. static int sun4i_tcon_init_clocks(struct device *dev,
  260. struct sun4i_tcon *tcon)
  261. {
  262. tcon->clk = devm_clk_get(dev, "ahb");
  263. if (IS_ERR(tcon->clk)) {
  264. dev_err(dev, "Couldn't get the TCON bus clock\n");
  265. return PTR_ERR(tcon->clk);
  266. }
  267. clk_prepare_enable(tcon->clk);
  268. tcon->sclk0 = devm_clk_get(dev, "tcon-ch0");
  269. if (IS_ERR(tcon->sclk0)) {
  270. dev_err(dev, "Couldn't get the TCON channel 0 clock\n");
  271. return PTR_ERR(tcon->sclk0);
  272. }
  273. if (tcon->quirks->has_channel_1) {
  274. tcon->sclk1 = devm_clk_get(dev, "tcon-ch1");
  275. if (IS_ERR(tcon->sclk1)) {
  276. dev_err(dev, "Couldn't get the TCON channel 1 clock\n");
  277. return PTR_ERR(tcon->sclk1);
  278. }
  279. }
  280. return sun4i_dclk_create(dev, tcon);
  281. }
  282. static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon)
  283. {
  284. sun4i_dclk_free(tcon);
  285. clk_disable_unprepare(tcon->clk);
  286. }
  287. static int sun4i_tcon_init_irq(struct device *dev,
  288. struct sun4i_tcon *tcon)
  289. {
  290. struct platform_device *pdev = to_platform_device(dev);
  291. int irq, ret;
  292. irq = platform_get_irq(pdev, 0);
  293. if (irq < 0) {
  294. dev_err(dev, "Couldn't retrieve the TCON interrupt\n");
  295. return irq;
  296. }
  297. ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0,
  298. dev_name(dev), tcon);
  299. if (ret) {
  300. dev_err(dev, "Couldn't request the IRQ\n");
  301. return ret;
  302. }
  303. return 0;
  304. }
  305. static struct regmap_config sun4i_tcon_regmap_config = {
  306. .reg_bits = 32,
  307. .val_bits = 32,
  308. .reg_stride = 4,
  309. .max_register = 0x800,
  310. };
  311. static int sun4i_tcon_init_regmap(struct device *dev,
  312. struct sun4i_tcon *tcon)
  313. {
  314. struct platform_device *pdev = to_platform_device(dev);
  315. struct resource *res;
  316. void __iomem *regs;
  317. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  318. regs = devm_ioremap_resource(dev, res);
  319. if (IS_ERR(regs))
  320. return PTR_ERR(regs);
  321. tcon->regs = devm_regmap_init_mmio(dev, regs,
  322. &sun4i_tcon_regmap_config);
  323. if (IS_ERR(tcon->regs)) {
  324. dev_err(dev, "Couldn't create the TCON regmap\n");
  325. return PTR_ERR(tcon->regs);
  326. }
  327. /* Make sure the TCON is disabled and all IRQs are off */
  328. regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0);
  329. regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0);
  330. regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0);
  331. /* Disable IO lines and set them to tristate */
  332. regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0);
  333. regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0);
  334. return 0;
  335. }
  336. struct drm_panel *sun4i_tcon_find_panel(struct device_node *node)
  337. {
  338. struct device_node *port, *remote, *child;
  339. struct device_node *end_node = NULL;
  340. /* Inputs are listed first, then outputs */
  341. port = of_graph_get_port_by_id(node, 1);
  342. /*
  343. * Our first output is the RGB interface where the panel will
  344. * be connected.
  345. */
  346. for_each_child_of_node(port, child) {
  347. u32 reg;
  348. of_property_read_u32(child, "reg", &reg);
  349. if (reg == 0)
  350. end_node = child;
  351. }
  352. if (!end_node) {
  353. DRM_DEBUG_DRIVER("Missing panel endpoint\n");
  354. return ERR_PTR(-ENODEV);
  355. }
  356. remote = of_graph_get_remote_port_parent(end_node);
  357. if (!remote) {
  358. DRM_DEBUG_DRIVER("Unable to parse remote node\n");
  359. return ERR_PTR(-EINVAL);
  360. }
  361. return of_drm_find_panel(remote) ?: ERR_PTR(-EPROBE_DEFER);
  362. }
  363. struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node)
  364. {
  365. struct device_node *port, *remote, *child;
  366. struct device_node *end_node = NULL;
  367. /* Inputs are listed first, then outputs */
  368. port = of_graph_get_port_by_id(node, 1);
  369. /*
  370. * Our first output is the RGB interface where the panel will
  371. * be connected.
  372. */
  373. for_each_child_of_node(port, child) {
  374. u32 reg;
  375. of_property_read_u32(child, "reg", &reg);
  376. if (reg == 0)
  377. end_node = child;
  378. }
  379. if (!end_node) {
  380. DRM_DEBUG_DRIVER("Missing bridge endpoint\n");
  381. return ERR_PTR(-ENODEV);
  382. }
  383. remote = of_graph_get_remote_port_parent(end_node);
  384. if (!remote) {
  385. DRM_DEBUG_DRIVER("Enable to parse remote node\n");
  386. return ERR_PTR(-EINVAL);
  387. }
  388. return of_drm_find_bridge(remote) ?: ERR_PTR(-EPROBE_DEFER);
  389. }
  390. static int sun4i_tcon_bind(struct device *dev, struct device *master,
  391. void *data)
  392. {
  393. struct drm_device *drm = data;
  394. struct sun4i_drv *drv = drm->dev_private;
  395. struct sun4i_tcon *tcon;
  396. int ret;
  397. tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
  398. if (!tcon)
  399. return -ENOMEM;
  400. dev_set_drvdata(dev, tcon);
  401. drv->tcon = tcon;
  402. tcon->drm = drm;
  403. tcon->dev = dev;
  404. tcon->quirks = of_device_get_match_data(dev);
  405. tcon->lcd_rst = devm_reset_control_get(dev, "lcd");
  406. if (IS_ERR(tcon->lcd_rst)) {
  407. dev_err(dev, "Couldn't get our reset line\n");
  408. return PTR_ERR(tcon->lcd_rst);
  409. }
  410. /* Make sure our TCON is reset */
  411. if (!reset_control_status(tcon->lcd_rst))
  412. reset_control_assert(tcon->lcd_rst);
  413. ret = reset_control_deassert(tcon->lcd_rst);
  414. if (ret) {
  415. dev_err(dev, "Couldn't deassert our reset line\n");
  416. return ret;
  417. }
  418. ret = sun4i_tcon_init_regmap(dev, tcon);
  419. if (ret) {
  420. dev_err(dev, "Couldn't init our TCON regmap\n");
  421. goto err_assert_reset;
  422. }
  423. ret = sun4i_tcon_init_clocks(dev, tcon);
  424. if (ret) {
  425. dev_err(dev, "Couldn't init our TCON clocks\n");
  426. goto err_assert_reset;
  427. }
  428. ret = sun4i_tcon_init_irq(dev, tcon);
  429. if (ret) {
  430. dev_err(dev, "Couldn't init our TCON interrupts\n");
  431. goto err_free_clocks;
  432. }
  433. ret = sun4i_rgb_init(drm);
  434. if (ret < 0)
  435. goto err_free_clocks;
  436. return 0;
  437. err_free_clocks:
  438. sun4i_tcon_free_clocks(tcon);
  439. err_assert_reset:
  440. reset_control_assert(tcon->lcd_rst);
  441. return ret;
  442. }
  443. static void sun4i_tcon_unbind(struct device *dev, struct device *master,
  444. void *data)
  445. {
  446. struct sun4i_tcon *tcon = dev_get_drvdata(dev);
  447. sun4i_tcon_free_clocks(tcon);
  448. }
  449. static const struct component_ops sun4i_tcon_ops = {
  450. .bind = sun4i_tcon_bind,
  451. .unbind = sun4i_tcon_unbind,
  452. };
  453. static int sun4i_tcon_probe(struct platform_device *pdev)
  454. {
  455. struct device_node *node = pdev->dev.of_node;
  456. struct drm_bridge *bridge;
  457. struct drm_panel *panel;
  458. /*
  459. * Neither the bridge or the panel is ready.
  460. * Defer the probe.
  461. */
  462. panel = sun4i_tcon_find_panel(node);
  463. bridge = sun4i_tcon_find_bridge(node);
  464. /*
  465. * If we don't have a panel endpoint, just go on
  466. */
  467. if ((PTR_ERR(panel) == -EPROBE_DEFER) &&
  468. (PTR_ERR(bridge) == -EPROBE_DEFER)) {
  469. DRM_DEBUG_DRIVER("Still waiting for our panel/bridge. Deferring...\n");
  470. return -EPROBE_DEFER;
  471. }
  472. return component_add(&pdev->dev, &sun4i_tcon_ops);
  473. }
  474. static int sun4i_tcon_remove(struct platform_device *pdev)
  475. {
  476. component_del(&pdev->dev, &sun4i_tcon_ops);
  477. return 0;
  478. }
  479. static const struct sun4i_tcon_quirks sun5i_a13_quirks = {
  480. .has_unknown_mux = true,
  481. .has_channel_1 = true,
  482. };
  483. static const struct sun4i_tcon_quirks sun6i_a31_quirks = {
  484. .has_channel_1 = true,
  485. };
  486. static const struct sun4i_tcon_quirks sun6i_a31s_quirks = {
  487. .has_channel_1 = true,
  488. };
  489. static const struct sun4i_tcon_quirks sun8i_a33_quirks = {
  490. /* nothing is supported */
  491. };
  492. static const struct of_device_id sun4i_tcon_of_table[] = {
  493. { .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
  494. { .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
  495. { .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks },
  496. { .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks },
  497. { }
  498. };
  499. MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table);
  500. static struct platform_driver sun4i_tcon_platform_driver = {
  501. .probe = sun4i_tcon_probe,
  502. .remove = sun4i_tcon_remove,
  503. .driver = {
  504. .name = "sun4i-tcon",
  505. .of_match_table = sun4i_tcon_of_table,
  506. },
  507. };
  508. module_platform_driver(sun4i_tcon_platform_driver);
  509. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  510. MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver");
  511. MODULE_LICENSE("GPL");