sun4i_tcon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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 0;
  281. }
  282. static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon)
  283. {
  284. clk_disable_unprepare(tcon->clk);
  285. }
  286. static int sun4i_tcon_init_irq(struct device *dev,
  287. struct sun4i_tcon *tcon)
  288. {
  289. struct platform_device *pdev = to_platform_device(dev);
  290. int irq, ret;
  291. irq = platform_get_irq(pdev, 0);
  292. if (irq < 0) {
  293. dev_err(dev, "Couldn't retrieve the TCON interrupt\n");
  294. return irq;
  295. }
  296. ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0,
  297. dev_name(dev), tcon);
  298. if (ret) {
  299. dev_err(dev, "Couldn't request the IRQ\n");
  300. return ret;
  301. }
  302. return 0;
  303. }
  304. static struct regmap_config sun4i_tcon_regmap_config = {
  305. .reg_bits = 32,
  306. .val_bits = 32,
  307. .reg_stride = 4,
  308. .max_register = 0x800,
  309. };
  310. static int sun4i_tcon_init_regmap(struct device *dev,
  311. struct sun4i_tcon *tcon)
  312. {
  313. struct platform_device *pdev = to_platform_device(dev);
  314. struct resource *res;
  315. void __iomem *regs;
  316. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  317. regs = devm_ioremap_resource(dev, res);
  318. if (IS_ERR(regs))
  319. return PTR_ERR(regs);
  320. tcon->regs = devm_regmap_init_mmio(dev, regs,
  321. &sun4i_tcon_regmap_config);
  322. if (IS_ERR(tcon->regs)) {
  323. dev_err(dev, "Couldn't create the TCON regmap\n");
  324. return PTR_ERR(tcon->regs);
  325. }
  326. /* Make sure the TCON is disabled and all IRQs are off */
  327. regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0);
  328. regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0);
  329. regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0);
  330. /* Disable IO lines and set them to tristate */
  331. regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0);
  332. regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0);
  333. return 0;
  334. }
  335. struct drm_panel *sun4i_tcon_find_panel(struct device_node *node)
  336. {
  337. struct device_node *port, *remote, *child;
  338. struct device_node *end_node = NULL;
  339. /* Inputs are listed first, then outputs */
  340. port = of_graph_get_port_by_id(node, 1);
  341. /*
  342. * Our first output is the RGB interface where the panel will
  343. * be connected.
  344. */
  345. for_each_child_of_node(port, child) {
  346. u32 reg;
  347. of_property_read_u32(child, "reg", &reg);
  348. if (reg == 0)
  349. end_node = child;
  350. }
  351. if (!end_node) {
  352. DRM_DEBUG_DRIVER("Missing panel endpoint\n");
  353. return ERR_PTR(-ENODEV);
  354. }
  355. remote = of_graph_get_remote_port_parent(end_node);
  356. if (!remote) {
  357. DRM_DEBUG_DRIVER("Unable to parse remote node\n");
  358. return ERR_PTR(-EINVAL);
  359. }
  360. return of_drm_find_panel(remote) ?: ERR_PTR(-EPROBE_DEFER);
  361. }
  362. struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node)
  363. {
  364. struct device_node *port, *remote, *child;
  365. struct device_node *end_node = NULL;
  366. /* Inputs are listed first, then outputs */
  367. port = of_graph_get_port_by_id(node, 1);
  368. /*
  369. * Our first output is the RGB interface where the panel will
  370. * be connected.
  371. */
  372. for_each_child_of_node(port, child) {
  373. u32 reg;
  374. of_property_read_u32(child, "reg", &reg);
  375. if (reg == 0)
  376. end_node = child;
  377. }
  378. if (!end_node) {
  379. DRM_DEBUG_DRIVER("Missing bridge endpoint\n");
  380. return ERR_PTR(-ENODEV);
  381. }
  382. remote = of_graph_get_remote_port_parent(end_node);
  383. if (!remote) {
  384. DRM_DEBUG_DRIVER("Enable to parse remote node\n");
  385. return ERR_PTR(-EINVAL);
  386. }
  387. return of_drm_find_bridge(remote) ?: ERR_PTR(-EPROBE_DEFER);
  388. }
  389. static int sun4i_tcon_bind(struct device *dev, struct device *master,
  390. void *data)
  391. {
  392. struct drm_device *drm = data;
  393. struct sun4i_drv *drv = drm->dev_private;
  394. struct sun4i_tcon *tcon;
  395. int ret;
  396. tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
  397. if (!tcon)
  398. return -ENOMEM;
  399. dev_set_drvdata(dev, tcon);
  400. drv->tcon = tcon;
  401. tcon->drm = drm;
  402. tcon->dev = dev;
  403. tcon->quirks = of_device_get_match_data(dev);
  404. tcon->lcd_rst = devm_reset_control_get(dev, "lcd");
  405. if (IS_ERR(tcon->lcd_rst)) {
  406. dev_err(dev, "Couldn't get our reset line\n");
  407. return PTR_ERR(tcon->lcd_rst);
  408. }
  409. /* Make sure our TCON is reset */
  410. if (!reset_control_status(tcon->lcd_rst))
  411. reset_control_assert(tcon->lcd_rst);
  412. ret = reset_control_deassert(tcon->lcd_rst);
  413. if (ret) {
  414. dev_err(dev, "Couldn't deassert our reset line\n");
  415. return ret;
  416. }
  417. ret = sun4i_tcon_init_clocks(dev, tcon);
  418. if (ret) {
  419. dev_err(dev, "Couldn't init our TCON clocks\n");
  420. goto err_assert_reset;
  421. }
  422. ret = sun4i_tcon_init_regmap(dev, tcon);
  423. if (ret) {
  424. dev_err(dev, "Couldn't init our TCON regmap\n");
  425. goto err_free_clocks;
  426. }
  427. ret = sun4i_dclk_create(dev, tcon);
  428. if (ret) {
  429. dev_err(dev, "Couldn't create our TCON dot clock\n");
  430. goto err_free_clocks;
  431. }
  432. ret = sun4i_tcon_init_irq(dev, tcon);
  433. if (ret) {
  434. dev_err(dev, "Couldn't init our TCON interrupts\n");
  435. goto err_free_dotclock;
  436. }
  437. ret = sun4i_rgb_init(drm);
  438. if (ret < 0)
  439. goto err_free_clocks;
  440. return 0;
  441. err_free_dotclock:
  442. sun4i_dclk_free(tcon);
  443. err_free_clocks:
  444. sun4i_tcon_free_clocks(tcon);
  445. err_assert_reset:
  446. reset_control_assert(tcon->lcd_rst);
  447. return ret;
  448. }
  449. static void sun4i_tcon_unbind(struct device *dev, struct device *master,
  450. void *data)
  451. {
  452. struct sun4i_tcon *tcon = dev_get_drvdata(dev);
  453. sun4i_dclk_free(tcon);
  454. sun4i_tcon_free_clocks(tcon);
  455. }
  456. static struct component_ops sun4i_tcon_ops = {
  457. .bind = sun4i_tcon_bind,
  458. .unbind = sun4i_tcon_unbind,
  459. };
  460. static int sun4i_tcon_probe(struct platform_device *pdev)
  461. {
  462. struct device_node *node = pdev->dev.of_node;
  463. struct drm_bridge *bridge;
  464. struct drm_panel *panel;
  465. /*
  466. * Neither the bridge or the panel is ready.
  467. * Defer the probe.
  468. */
  469. panel = sun4i_tcon_find_panel(node);
  470. bridge = sun4i_tcon_find_bridge(node);
  471. /*
  472. * If we don't have a panel endpoint, just go on
  473. */
  474. if ((PTR_ERR(panel) == -EPROBE_DEFER) &&
  475. (PTR_ERR(bridge) == -EPROBE_DEFER)) {
  476. DRM_DEBUG_DRIVER("Still waiting for our panel/bridge. Deferring...\n");
  477. return -EPROBE_DEFER;
  478. }
  479. return component_add(&pdev->dev, &sun4i_tcon_ops);
  480. }
  481. static int sun4i_tcon_remove(struct platform_device *pdev)
  482. {
  483. component_del(&pdev->dev, &sun4i_tcon_ops);
  484. return 0;
  485. }
  486. static const struct sun4i_tcon_quirks sun5i_a13_quirks = {
  487. .has_unknown_mux = true,
  488. .has_channel_1 = true,
  489. };
  490. static const struct sun4i_tcon_quirks sun6i_a31_quirks = {
  491. .has_channel_1 = true,
  492. };
  493. static const struct sun4i_tcon_quirks sun6i_a31s_quirks = {
  494. .has_channel_1 = true,
  495. };
  496. static const struct sun4i_tcon_quirks sun8i_a33_quirks = {
  497. /* nothing is supported */
  498. };
  499. static const struct of_device_id sun4i_tcon_of_table[] = {
  500. { .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
  501. { .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
  502. { .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks },
  503. { .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks },
  504. { }
  505. };
  506. MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table);
  507. static struct platform_driver sun4i_tcon_platform_driver = {
  508. .probe = sun4i_tcon_probe,
  509. .remove = sun4i_tcon_remove,
  510. .driver = {
  511. .name = "sun4i-tcon",
  512. .of_match_table = sun4i_tcon_of_table,
  513. },
  514. };
  515. module_platform_driver(sun4i_tcon_platform_driver);
  516. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  517. MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver");
  518. MODULE_LICENSE("GPL");