sun4i_tcon.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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_of.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_irq.h>
  23. #include <linux/regmap.h>
  24. #include <linux/reset.h>
  25. #include "sun4i_crtc.h"
  26. #include "sun4i_dotclock.h"
  27. #include "sun4i_drv.h"
  28. #include "sun4i_rgb.h"
  29. #include "sun4i_tcon.h"
  30. #include "sunxi_engine.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. DRM_DEBUG_DRIVER("Disabling TCON channel %d\n", channel);
  51. /* Disable the TCON's channel */
  52. if (channel == 0) {
  53. regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
  54. SUN4I_TCON0_CTL_TCON_ENABLE, 0);
  55. clk_disable_unprepare(tcon->dclk);
  56. return;
  57. }
  58. WARN_ON(!tcon->quirks->has_channel_1);
  59. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  60. SUN4I_TCON1_CTL_TCON_ENABLE, 0);
  61. clk_disable_unprepare(tcon->sclk1);
  62. }
  63. EXPORT_SYMBOL(sun4i_tcon_channel_disable);
  64. void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel)
  65. {
  66. DRM_DEBUG_DRIVER("Enabling TCON channel %d\n", channel);
  67. /* Enable the TCON's channel */
  68. if (channel == 0) {
  69. regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
  70. SUN4I_TCON0_CTL_TCON_ENABLE,
  71. SUN4I_TCON0_CTL_TCON_ENABLE);
  72. clk_prepare_enable(tcon->dclk);
  73. return;
  74. }
  75. WARN_ON(!tcon->quirks->has_channel_1);
  76. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  77. SUN4I_TCON1_CTL_TCON_ENABLE,
  78. SUN4I_TCON1_CTL_TCON_ENABLE);
  79. clk_prepare_enable(tcon->sclk1);
  80. }
  81. EXPORT_SYMBOL(sun4i_tcon_channel_enable);
  82. void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable)
  83. {
  84. u32 mask, val = 0;
  85. DRM_DEBUG_DRIVER("%sabling VBLANK interrupt\n", enable ? "En" : "Dis");
  86. mask = SUN4I_TCON_GINT0_VBLANK_ENABLE(0) |
  87. SUN4I_TCON_GINT0_VBLANK_ENABLE(1);
  88. if (enable)
  89. val = mask;
  90. regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val);
  91. }
  92. EXPORT_SYMBOL(sun4i_tcon_enable_vblank);
  93. void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel,
  94. struct drm_encoder *encoder)
  95. {
  96. u32 val;
  97. if (!tcon->quirks->has_unknown_mux)
  98. return;
  99. if (channel != 1)
  100. return;
  101. if (encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
  102. val = 1;
  103. else
  104. val = 0;
  105. /*
  106. * FIXME: Undocumented bits
  107. */
  108. regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, val);
  109. }
  110. EXPORT_SYMBOL(sun4i_tcon_set_mux);
  111. static int sun4i_tcon_get_clk_delay(struct drm_display_mode *mode,
  112. int channel)
  113. {
  114. int delay = mode->vtotal - mode->vdisplay;
  115. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  116. delay /= 2;
  117. if (channel == 1)
  118. delay -= 2;
  119. delay = min(delay, 30);
  120. DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay);
  121. return delay;
  122. }
  123. void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon,
  124. struct drm_display_mode *mode)
  125. {
  126. unsigned int bp, hsync, vsync;
  127. u8 clk_delay;
  128. u32 val = 0;
  129. /* Configure the dot clock */
  130. clk_set_rate(tcon->dclk, mode->crtc_clock * 1000);
  131. /* Adjust clock delay */
  132. clk_delay = sun4i_tcon_get_clk_delay(mode, 0);
  133. regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
  134. SUN4I_TCON0_CTL_CLK_DELAY_MASK,
  135. SUN4I_TCON0_CTL_CLK_DELAY(clk_delay));
  136. /* Set the resolution */
  137. regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG,
  138. SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) |
  139. SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
  140. /*
  141. * This is called a backporch in the register documentation,
  142. * but it really is the back porch + hsync
  143. */
  144. bp = mode->crtc_htotal - mode->crtc_hsync_start;
  145. DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
  146. mode->crtc_htotal, bp);
  147. /* Set horizontal display timings */
  148. regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG,
  149. SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) |
  150. SUN4I_TCON0_BASIC1_H_BACKPORCH(bp));
  151. /*
  152. * This is called a backporch in the register documentation,
  153. * but it really is the back porch + hsync
  154. */
  155. bp = mode->crtc_vtotal - mode->crtc_vsync_start;
  156. DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
  157. mode->crtc_vtotal, bp);
  158. /* Set vertical display timings */
  159. regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG,
  160. SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) |
  161. SUN4I_TCON0_BASIC2_V_BACKPORCH(bp));
  162. /* Set Hsync and Vsync length */
  163. hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
  164. vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
  165. DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
  166. regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG,
  167. SUN4I_TCON0_BASIC3_V_SYNC(vsync) |
  168. SUN4I_TCON0_BASIC3_H_SYNC(hsync));
  169. /* Setup the polarity of the various signals */
  170. if (!(mode->flags & DRM_MODE_FLAG_PHSYNC))
  171. val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE;
  172. if (!(mode->flags & DRM_MODE_FLAG_PVSYNC))
  173. val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE;
  174. regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG,
  175. SUN4I_TCON0_IO_POL_HSYNC_POSITIVE | SUN4I_TCON0_IO_POL_VSYNC_POSITIVE,
  176. val);
  177. /* Map output pins to channel 0 */
  178. regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
  179. SUN4I_TCON_GCTL_IOMAP_MASK,
  180. SUN4I_TCON_GCTL_IOMAP_TCON0);
  181. /* Enable the output on the pins */
  182. regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0);
  183. }
  184. EXPORT_SYMBOL(sun4i_tcon0_mode_set);
  185. void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
  186. struct drm_display_mode *mode)
  187. {
  188. unsigned int bp, hsync, vsync, vtotal;
  189. u8 clk_delay;
  190. u32 val;
  191. WARN_ON(!tcon->quirks->has_channel_1);
  192. /* Configure the dot clock */
  193. clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000);
  194. /* Adjust clock delay */
  195. clk_delay = sun4i_tcon_get_clk_delay(mode, 1);
  196. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  197. SUN4I_TCON1_CTL_CLK_DELAY_MASK,
  198. SUN4I_TCON1_CTL_CLK_DELAY(clk_delay));
  199. /* Set interlaced mode */
  200. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  201. val = SUN4I_TCON1_CTL_INTERLACE_ENABLE;
  202. else
  203. val = 0;
  204. regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
  205. SUN4I_TCON1_CTL_INTERLACE_ENABLE,
  206. val);
  207. /* Set the input resolution */
  208. regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG,
  209. SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) |
  210. SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay));
  211. /* Set the upscaling resolution */
  212. regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG,
  213. SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) |
  214. SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay));
  215. /* Set the output resolution */
  216. regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG,
  217. SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) |
  218. SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay));
  219. /* Set horizontal display timings */
  220. bp = mode->crtc_htotal - mode->crtc_hsync_start;
  221. DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
  222. mode->htotal, bp);
  223. regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG,
  224. SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) |
  225. SUN4I_TCON1_BASIC3_H_BACKPORCH(bp));
  226. bp = mode->crtc_vtotal - mode->crtc_vsync_start;
  227. DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
  228. mode->crtc_vtotal, bp);
  229. /*
  230. * The vertical resolution needs to be doubled in all
  231. * cases. We could use crtc_vtotal and always multiply by two,
  232. * but that leads to a rounding error in interlace when vtotal
  233. * is odd.
  234. *
  235. * This happens with TV's PAL for example, where vtotal will
  236. * be 625, crtc_vtotal 312, and thus crtc_vtotal * 2 will be
  237. * 624, which apparently confuses the hardware.
  238. *
  239. * To work around this, we will always use vtotal, and
  240. * multiply by two only if we're not in interlace.
  241. */
  242. vtotal = mode->vtotal;
  243. if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
  244. vtotal = vtotal * 2;
  245. /* Set vertical display timings */
  246. regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG,
  247. SUN4I_TCON1_BASIC4_V_TOTAL(vtotal) |
  248. SUN4I_TCON1_BASIC4_V_BACKPORCH(bp));
  249. /* Set Hsync and Vsync length */
  250. hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
  251. vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
  252. DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
  253. regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG,
  254. SUN4I_TCON1_BASIC5_V_SYNC(vsync) |
  255. SUN4I_TCON1_BASIC5_H_SYNC(hsync));
  256. /* Map output pins to channel 1 */
  257. regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
  258. SUN4I_TCON_GCTL_IOMAP_MASK,
  259. SUN4I_TCON_GCTL_IOMAP_TCON1);
  260. }
  261. EXPORT_SYMBOL(sun4i_tcon1_mode_set);
  262. static void sun4i_tcon_finish_page_flip(struct drm_device *dev,
  263. struct sun4i_crtc *scrtc)
  264. {
  265. unsigned long flags;
  266. spin_lock_irqsave(&dev->event_lock, flags);
  267. if (scrtc->event) {
  268. drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event);
  269. drm_crtc_vblank_put(&scrtc->crtc);
  270. scrtc->event = NULL;
  271. }
  272. spin_unlock_irqrestore(&dev->event_lock, flags);
  273. }
  274. static irqreturn_t sun4i_tcon_handler(int irq, void *private)
  275. {
  276. struct sun4i_tcon *tcon = private;
  277. struct drm_device *drm = tcon->drm;
  278. struct sun4i_crtc *scrtc = tcon->crtc;
  279. unsigned int status;
  280. regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status);
  281. if (!(status & (SUN4I_TCON_GINT0_VBLANK_INT(0) |
  282. SUN4I_TCON_GINT0_VBLANK_INT(1))))
  283. return IRQ_NONE;
  284. drm_crtc_handle_vblank(&scrtc->crtc);
  285. sun4i_tcon_finish_page_flip(drm, scrtc);
  286. /* Acknowledge the interrupt */
  287. regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG,
  288. SUN4I_TCON_GINT0_VBLANK_INT(0) |
  289. SUN4I_TCON_GINT0_VBLANK_INT(1),
  290. 0);
  291. return IRQ_HANDLED;
  292. }
  293. static int sun4i_tcon_init_clocks(struct device *dev,
  294. struct sun4i_tcon *tcon)
  295. {
  296. tcon->clk = devm_clk_get(dev, "ahb");
  297. if (IS_ERR(tcon->clk)) {
  298. dev_err(dev, "Couldn't get the TCON bus clock\n");
  299. return PTR_ERR(tcon->clk);
  300. }
  301. clk_prepare_enable(tcon->clk);
  302. tcon->sclk0 = devm_clk_get(dev, "tcon-ch0");
  303. if (IS_ERR(tcon->sclk0)) {
  304. dev_err(dev, "Couldn't get the TCON channel 0 clock\n");
  305. return PTR_ERR(tcon->sclk0);
  306. }
  307. if (tcon->quirks->has_channel_1) {
  308. tcon->sclk1 = devm_clk_get(dev, "tcon-ch1");
  309. if (IS_ERR(tcon->sclk1)) {
  310. dev_err(dev, "Couldn't get the TCON channel 1 clock\n");
  311. return PTR_ERR(tcon->sclk1);
  312. }
  313. }
  314. return 0;
  315. }
  316. static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon)
  317. {
  318. clk_disable_unprepare(tcon->clk);
  319. }
  320. static int sun4i_tcon_init_irq(struct device *dev,
  321. struct sun4i_tcon *tcon)
  322. {
  323. struct platform_device *pdev = to_platform_device(dev);
  324. int irq, ret;
  325. irq = platform_get_irq(pdev, 0);
  326. if (irq < 0) {
  327. dev_err(dev, "Couldn't retrieve the TCON interrupt\n");
  328. return irq;
  329. }
  330. ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0,
  331. dev_name(dev), tcon);
  332. if (ret) {
  333. dev_err(dev, "Couldn't request the IRQ\n");
  334. return ret;
  335. }
  336. return 0;
  337. }
  338. static struct regmap_config sun4i_tcon_regmap_config = {
  339. .reg_bits = 32,
  340. .val_bits = 32,
  341. .reg_stride = 4,
  342. .max_register = 0x800,
  343. };
  344. static int sun4i_tcon_init_regmap(struct device *dev,
  345. struct sun4i_tcon *tcon)
  346. {
  347. struct platform_device *pdev = to_platform_device(dev);
  348. struct resource *res;
  349. void __iomem *regs;
  350. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  351. regs = devm_ioremap_resource(dev, res);
  352. if (IS_ERR(regs))
  353. return PTR_ERR(regs);
  354. tcon->regs = devm_regmap_init_mmio(dev, regs,
  355. &sun4i_tcon_regmap_config);
  356. if (IS_ERR(tcon->regs)) {
  357. dev_err(dev, "Couldn't create the TCON regmap\n");
  358. return PTR_ERR(tcon->regs);
  359. }
  360. /* Make sure the TCON is disabled and all IRQs are off */
  361. regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0);
  362. regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0);
  363. regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0);
  364. /* Disable IO lines and set them to tristate */
  365. regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0);
  366. regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0);
  367. return 0;
  368. }
  369. /*
  370. * On SoCs with the old display pipeline design (Display Engine 1.0),
  371. * the TCON is always tied to just one backend. Hence we can traverse
  372. * the of_graph upwards to find the backend our tcon is connected to,
  373. * and take its ID as our own.
  374. *
  375. * We can either identify backends from their compatible strings, which
  376. * means maintaining a large list of them. Or, since the backend is
  377. * registered and binded before the TCON, we can just go through the
  378. * list of registered backends and compare the device node.
  379. *
  380. * As the structures now store engines instead of backends, here this
  381. * function in fact searches the corresponding engine, and the ID is
  382. * requested via the get_id function of the engine.
  383. */
  384. static struct sunxi_engine *sun4i_tcon_find_engine(struct sun4i_drv *drv,
  385. struct device_node *node)
  386. {
  387. struct device_node *port, *ep, *remote;
  388. struct sunxi_engine *engine;
  389. port = of_graph_get_port_by_id(node, 0);
  390. if (!port)
  391. return ERR_PTR(-EINVAL);
  392. for_each_available_child_of_node(port, ep) {
  393. remote = of_graph_get_remote_port_parent(ep);
  394. if (!remote)
  395. continue;
  396. /* does this node match any registered engines? */
  397. list_for_each_entry(engine, &drv->engine_list, list) {
  398. if (remote == engine->node) {
  399. of_node_put(remote);
  400. of_node_put(port);
  401. return engine;
  402. }
  403. }
  404. /* keep looking through upstream ports */
  405. engine = sun4i_tcon_find_engine(drv, remote);
  406. if (!IS_ERR(engine)) {
  407. of_node_put(remote);
  408. of_node_put(port);
  409. return engine;
  410. }
  411. }
  412. return ERR_PTR(-EINVAL);
  413. }
  414. static int sun4i_tcon_bind(struct device *dev, struct device *master,
  415. void *data)
  416. {
  417. struct drm_device *drm = data;
  418. struct sun4i_drv *drv = drm->dev_private;
  419. struct sunxi_engine *engine;
  420. struct sun4i_tcon *tcon;
  421. int ret;
  422. engine = sun4i_tcon_find_engine(drv, dev->of_node);
  423. if (IS_ERR(engine)) {
  424. dev_err(dev, "Couldn't find matching engine\n");
  425. return -EPROBE_DEFER;
  426. }
  427. tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
  428. if (!tcon)
  429. return -ENOMEM;
  430. dev_set_drvdata(dev, tcon);
  431. tcon->drm = drm;
  432. tcon->dev = dev;
  433. tcon->id = engine->id;
  434. tcon->quirks = of_device_get_match_data(dev);
  435. tcon->lcd_rst = devm_reset_control_get(dev, "lcd");
  436. if (IS_ERR(tcon->lcd_rst)) {
  437. dev_err(dev, "Couldn't get our reset line\n");
  438. return PTR_ERR(tcon->lcd_rst);
  439. }
  440. /* Make sure our TCON is reset */
  441. if (!reset_control_status(tcon->lcd_rst))
  442. reset_control_assert(tcon->lcd_rst);
  443. ret = reset_control_deassert(tcon->lcd_rst);
  444. if (ret) {
  445. dev_err(dev, "Couldn't deassert our reset line\n");
  446. return ret;
  447. }
  448. ret = sun4i_tcon_init_clocks(dev, tcon);
  449. if (ret) {
  450. dev_err(dev, "Couldn't init our TCON clocks\n");
  451. goto err_assert_reset;
  452. }
  453. ret = sun4i_tcon_init_regmap(dev, tcon);
  454. if (ret) {
  455. dev_err(dev, "Couldn't init our TCON regmap\n");
  456. goto err_free_clocks;
  457. }
  458. ret = sun4i_dclk_create(dev, tcon);
  459. if (ret) {
  460. dev_err(dev, "Couldn't create our TCON dot clock\n");
  461. goto err_free_clocks;
  462. }
  463. ret = sun4i_tcon_init_irq(dev, tcon);
  464. if (ret) {
  465. dev_err(dev, "Couldn't init our TCON interrupts\n");
  466. goto err_free_dotclock;
  467. }
  468. tcon->crtc = sun4i_crtc_init(drm, engine, tcon);
  469. if (IS_ERR(tcon->crtc)) {
  470. dev_err(dev, "Couldn't create our CRTC\n");
  471. ret = PTR_ERR(tcon->crtc);
  472. goto err_free_clocks;
  473. }
  474. ret = sun4i_rgb_init(drm, tcon);
  475. if (ret < 0)
  476. goto err_free_clocks;
  477. list_add_tail(&tcon->list, &drv->tcon_list);
  478. return 0;
  479. err_free_dotclock:
  480. sun4i_dclk_free(tcon);
  481. err_free_clocks:
  482. sun4i_tcon_free_clocks(tcon);
  483. err_assert_reset:
  484. reset_control_assert(tcon->lcd_rst);
  485. return ret;
  486. }
  487. static void sun4i_tcon_unbind(struct device *dev, struct device *master,
  488. void *data)
  489. {
  490. struct sun4i_tcon *tcon = dev_get_drvdata(dev);
  491. list_del(&tcon->list);
  492. sun4i_dclk_free(tcon);
  493. sun4i_tcon_free_clocks(tcon);
  494. }
  495. static const struct component_ops sun4i_tcon_ops = {
  496. .bind = sun4i_tcon_bind,
  497. .unbind = sun4i_tcon_unbind,
  498. };
  499. static int sun4i_tcon_probe(struct platform_device *pdev)
  500. {
  501. struct device_node *node = pdev->dev.of_node;
  502. struct drm_bridge *bridge;
  503. struct drm_panel *panel;
  504. int ret;
  505. ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
  506. if (ret == -EPROBE_DEFER)
  507. return ret;
  508. return component_add(&pdev->dev, &sun4i_tcon_ops);
  509. }
  510. static int sun4i_tcon_remove(struct platform_device *pdev)
  511. {
  512. component_del(&pdev->dev, &sun4i_tcon_ops);
  513. return 0;
  514. }
  515. static const struct sun4i_tcon_quirks sun5i_a13_quirks = {
  516. .has_unknown_mux = true,
  517. .has_channel_1 = true,
  518. };
  519. static const struct sun4i_tcon_quirks sun6i_a31_quirks = {
  520. .has_channel_1 = true,
  521. };
  522. static const struct sun4i_tcon_quirks sun6i_a31s_quirks = {
  523. .has_channel_1 = true,
  524. };
  525. static const struct sun4i_tcon_quirks sun8i_a33_quirks = {
  526. /* nothing is supported */
  527. };
  528. static const struct sun4i_tcon_quirks sun8i_v3s_quirks = {
  529. /* nothing is supported */
  530. };
  531. static const struct of_device_id sun4i_tcon_of_table[] = {
  532. { .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
  533. { .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
  534. { .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks },
  535. { .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks },
  536. { .compatible = "allwinner,sun8i-v3s-tcon", .data = &sun8i_v3s_quirks },
  537. { }
  538. };
  539. MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table);
  540. static struct platform_driver sun4i_tcon_platform_driver = {
  541. .probe = sun4i_tcon_probe,
  542. .remove = sun4i_tcon_remove,
  543. .driver = {
  544. .name = "sun4i-tcon",
  545. .of_match_table = sun4i_tcon_of_table,
  546. },
  547. };
  548. module_platform_driver(sun4i_tcon_platform_driver);
  549. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  550. MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver");
  551. MODULE_LICENSE("GPL");