sun4i_tv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2015 Free Electrons
  4. * Copyright (C) 2015 NextThing Co
  5. *
  6. * Maxime Ripard <maxime.ripard@free-electrons.com>
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/component.h>
  10. #include <linux/module.h>
  11. #include <linux/of_address.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regmap.h>
  14. #include <linux/reset.h>
  15. #include <drm/drm_atomic.h>
  16. #include <drm/drm_atomic_helper.h>
  17. #include <drm/drm_of.h>
  18. #include <drm/drm_panel.h>
  19. #include <drm/drm_print.h>
  20. #include <drm/drm_probe_helper.h>
  21. #include <drm/drm_simple_kms_helper.h>
  22. #include "sun4i_crtc.h"
  23. #include "sun4i_drv.h"
  24. #include "sunxi_engine.h"
  25. #define SUN4I_TVE_EN_REG 0x000
  26. #define SUN4I_TVE_EN_DAC_MAP_MASK GENMASK(19, 4)
  27. #define SUN4I_TVE_EN_DAC_MAP(dac, out) (((out) & 0xf) << (dac + 1) * 4)
  28. #define SUN4I_TVE_EN_ENABLE BIT(0)
  29. #define SUN4I_TVE_CFG0_REG 0x004
  30. #define SUN4I_TVE_CFG0_DAC_CONTROL_54M BIT(26)
  31. #define SUN4I_TVE_CFG0_CORE_DATAPATH_54M BIT(25)
  32. #define SUN4I_TVE_CFG0_CORE_CONTROL_54M BIT(24)
  33. #define SUN4I_TVE_CFG0_YC_EN BIT(17)
  34. #define SUN4I_TVE_CFG0_COMP_EN BIT(16)
  35. #define SUN4I_TVE_CFG0_RES(x) ((x) & 0xf)
  36. #define SUN4I_TVE_CFG0_RES_480i SUN4I_TVE_CFG0_RES(0)
  37. #define SUN4I_TVE_CFG0_RES_576i SUN4I_TVE_CFG0_RES(1)
  38. #define SUN4I_TVE_DAC0_REG 0x008
  39. #define SUN4I_TVE_DAC0_CLOCK_INVERT BIT(24)
  40. #define SUN4I_TVE_DAC0_LUMA(x) (((x) & 3) << 20)
  41. #define SUN4I_TVE_DAC0_LUMA_0_4 SUN4I_TVE_DAC0_LUMA(3)
  42. #define SUN4I_TVE_DAC0_CHROMA(x) (((x) & 3) << 18)
  43. #define SUN4I_TVE_DAC0_CHROMA_0_75 SUN4I_TVE_DAC0_CHROMA(3)
  44. #define SUN4I_TVE_DAC0_INTERNAL_DAC(x) (((x) & 3) << 16)
  45. #define SUN4I_TVE_DAC0_INTERNAL_DAC_37_5_OHMS SUN4I_TVE_DAC0_INTERNAL_DAC(3)
  46. #define SUN4I_TVE_DAC0_DAC_EN(dac) BIT(dac)
  47. #define SUN4I_TVE_NOTCH_REG 0x00c
  48. #define SUN4I_TVE_NOTCH_DAC0_TO_DAC_DLY(dac, x) ((4 - (x)) << (dac * 3))
  49. #define SUN4I_TVE_CHROMA_FREQ_REG 0x010
  50. #define SUN4I_TVE_PORCH_REG 0x014
  51. #define SUN4I_TVE_PORCH_BACK(x) ((x) << 16)
  52. #define SUN4I_TVE_PORCH_FRONT(x) (x)
  53. #define SUN4I_TVE_LINE_REG 0x01c
  54. #define SUN4I_TVE_LINE_FIRST(x) ((x) << 16)
  55. #define SUN4I_TVE_LINE_NUMBER(x) (x)
  56. #define SUN4I_TVE_LEVEL_REG 0x020
  57. #define SUN4I_TVE_LEVEL_BLANK(x) ((x) << 16)
  58. #define SUN4I_TVE_LEVEL_BLACK(x) (x)
  59. #define SUN4I_TVE_DAC1_REG 0x024
  60. #define SUN4I_TVE_DAC1_AMPLITUDE(dac, x) ((x) << (dac * 8))
  61. #define SUN4I_TVE_DETECT_STA_REG 0x038
  62. #define SUN4I_TVE_DETECT_STA_DAC(dac) BIT((dac * 8))
  63. #define SUN4I_TVE_DETECT_STA_UNCONNECTED 0
  64. #define SUN4I_TVE_DETECT_STA_CONNECTED 1
  65. #define SUN4I_TVE_DETECT_STA_GROUND 2
  66. #define SUN4I_TVE_CB_CR_LVL_REG 0x10c
  67. #define SUN4I_TVE_CB_CR_LVL_CR_BURST(x) ((x) << 8)
  68. #define SUN4I_TVE_CB_CR_LVL_CB_BURST(x) (x)
  69. #define SUN4I_TVE_TINT_BURST_PHASE_REG 0x110
  70. #define SUN4I_TVE_TINT_BURST_PHASE_CHROMA(x) (x)
  71. #define SUN4I_TVE_BURST_WIDTH_REG 0x114
  72. #define SUN4I_TVE_BURST_WIDTH_BREEZEWAY(x) ((x) << 16)
  73. #define SUN4I_TVE_BURST_WIDTH_BURST_WIDTH(x) ((x) << 8)
  74. #define SUN4I_TVE_BURST_WIDTH_HSYNC_WIDTH(x) (x)
  75. #define SUN4I_TVE_CB_CR_GAIN_REG 0x118
  76. #define SUN4I_TVE_CB_CR_GAIN_CR(x) ((x) << 8)
  77. #define SUN4I_TVE_CB_CR_GAIN_CB(x) (x)
  78. #define SUN4I_TVE_SYNC_VBI_REG 0x11c
  79. #define SUN4I_TVE_SYNC_VBI_SYNC(x) ((x) << 16)
  80. #define SUN4I_TVE_SYNC_VBI_VBLANK(x) (x)
  81. #define SUN4I_TVE_ACTIVE_LINE_REG 0x124
  82. #define SUN4I_TVE_ACTIVE_LINE(x) (x)
  83. #define SUN4I_TVE_CHROMA_REG 0x128
  84. #define SUN4I_TVE_CHROMA_COMP_GAIN(x) ((x) & 3)
  85. #define SUN4I_TVE_CHROMA_COMP_GAIN_50 SUN4I_TVE_CHROMA_COMP_GAIN(2)
  86. #define SUN4I_TVE_12C_REG 0x12c
  87. #define SUN4I_TVE_12C_NOTCH_WIDTH_WIDE BIT(8)
  88. #define SUN4I_TVE_12C_COMP_YUV_EN BIT(0)
  89. #define SUN4I_TVE_RESYNC_REG 0x130
  90. #define SUN4I_TVE_RESYNC_FIELD BIT(31)
  91. #define SUN4I_TVE_RESYNC_LINE(x) ((x) << 16)
  92. #define SUN4I_TVE_RESYNC_PIXEL(x) (x)
  93. #define SUN4I_TVE_SLAVE_REG 0x134
  94. #define SUN4I_TVE_WSS_DATA2_REG 0x244
  95. struct color_gains {
  96. u16 cb;
  97. u16 cr;
  98. };
  99. struct burst_levels {
  100. u16 cb;
  101. u16 cr;
  102. };
  103. struct video_levels {
  104. u16 black;
  105. u16 blank;
  106. };
  107. struct resync_parameters {
  108. bool field;
  109. u16 line;
  110. u16 pixel;
  111. };
  112. struct tv_mode {
  113. char *name;
  114. unsigned int tv_mode;
  115. u32 mode;
  116. u32 chroma_freq;
  117. u16 back_porch;
  118. u16 front_porch;
  119. u16 vblank_level;
  120. bool yc_en;
  121. bool dac3_en;
  122. bool dac_bit25_en;
  123. const struct color_gains *color_gains;
  124. const struct burst_levels *burst_levels;
  125. const struct video_levels *video_levels;
  126. const struct resync_parameters *resync_params;
  127. };
  128. struct sun4i_tv {
  129. struct drm_connector connector;
  130. struct drm_encoder encoder;
  131. struct clk *clk;
  132. struct regmap *regs;
  133. struct reset_control *reset;
  134. struct sun4i_drv *drv;
  135. };
  136. static const struct video_levels ntsc_video_levels = {
  137. .black = 282, .blank = 240,
  138. };
  139. static const struct video_levels pal_video_levels = {
  140. .black = 252, .blank = 252,
  141. };
  142. static const struct burst_levels ntsc_burst_levels = {
  143. .cb = 79, .cr = 0,
  144. };
  145. static const struct burst_levels pal_burst_levels = {
  146. .cb = 40, .cr = 40,
  147. };
  148. static const struct color_gains ntsc_color_gains = {
  149. .cb = 160, .cr = 160,
  150. };
  151. static const struct color_gains pal_color_gains = {
  152. .cb = 224, .cr = 224,
  153. };
  154. static const struct resync_parameters ntsc_resync_parameters = {
  155. .field = false, .line = 14, .pixel = 12,
  156. };
  157. static const struct resync_parameters pal_resync_parameters = {
  158. .field = true, .line = 13, .pixel = 12,
  159. };
  160. static const struct tv_mode tv_modes[] = {
  161. {
  162. .tv_mode = DRM_MODE_TV_MODE_NTSC,
  163. .mode = SUN4I_TVE_CFG0_RES_480i,
  164. .chroma_freq = 0x21f07c1f,
  165. .yc_en = true,
  166. .dac3_en = true,
  167. .dac_bit25_en = true,
  168. .back_porch = 118,
  169. .front_porch = 32,
  170. .vblank_level = 240,
  171. .color_gains = &ntsc_color_gains,
  172. .burst_levels = &ntsc_burst_levels,
  173. .video_levels = &ntsc_video_levels,
  174. .resync_params = &ntsc_resync_parameters,
  175. },
  176. {
  177. .tv_mode = DRM_MODE_TV_MODE_PAL,
  178. .mode = SUN4I_TVE_CFG0_RES_576i,
  179. .chroma_freq = 0x2a098acb,
  180. .back_porch = 138,
  181. .front_porch = 24,
  182. .vblank_level = 252,
  183. .color_gains = &pal_color_gains,
  184. .burst_levels = &pal_burst_levels,
  185. .video_levels = &pal_video_levels,
  186. .resync_params = &pal_resync_parameters,
  187. },
  188. };
  189. static inline struct sun4i_tv *
  190. drm_encoder_to_sun4i_tv(struct drm_encoder *encoder)
  191. {
  192. return container_of(encoder, struct sun4i_tv,
  193. encoder);
  194. }
  195. static const struct tv_mode *
  196. sun4i_tv_find_tv_by_mode(unsigned int mode)
  197. {
  198. int i;
  199. for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
  200. const struct tv_mode *tv_mode = &tv_modes[i];
  201. if (tv_mode->tv_mode == mode)
  202. return tv_mode;
  203. }
  204. return NULL;
  205. }
  206. static void sun4i_tv_disable(struct drm_encoder *encoder,
  207. struct drm_atomic_state *state)
  208. {
  209. struct sun4i_tv *tv = drm_encoder_to_sun4i_tv(encoder);
  210. struct sun4i_crtc *crtc = drm_crtc_to_sun4i_crtc(encoder->crtc);
  211. DRM_DEBUG_DRIVER("Disabling the TV Output\n");
  212. regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG,
  213. SUN4I_TVE_EN_ENABLE,
  214. 0);
  215. sunxi_engine_disable_color_correction(crtc->engine);
  216. }
  217. static void sun4i_tv_enable(struct drm_encoder *encoder,
  218. struct drm_atomic_state *state)
  219. {
  220. struct sun4i_tv *tv = drm_encoder_to_sun4i_tv(encoder);
  221. struct sun4i_crtc *crtc = drm_crtc_to_sun4i_crtc(encoder->crtc);
  222. struct drm_crtc_state *crtc_state =
  223. drm_atomic_get_new_crtc_state(state, encoder->crtc);
  224. struct drm_display_mode *mode = &crtc_state->mode;
  225. struct drm_connector *connector = &tv->connector;
  226. struct drm_connector_state *conn_state =
  227. drm_atomic_get_new_connector_state(state, connector);
  228. const struct tv_mode *tv_mode =
  229. sun4i_tv_find_tv_by_mode(conn_state->tv.mode);
  230. DRM_DEBUG_DRIVER("Enabling the TV Output\n");
  231. /* Enable and map the DAC to the output */
  232. regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG,
  233. SUN4I_TVE_EN_DAC_MAP_MASK,
  234. SUN4I_TVE_EN_DAC_MAP(0, 1) |
  235. SUN4I_TVE_EN_DAC_MAP(1, 2) |
  236. SUN4I_TVE_EN_DAC_MAP(2, 3) |
  237. SUN4I_TVE_EN_DAC_MAP(3, 4));
  238. /* Set PAL settings */
  239. regmap_write(tv->regs, SUN4I_TVE_CFG0_REG,
  240. tv_mode->mode |
  241. (tv_mode->yc_en ? SUN4I_TVE_CFG0_YC_EN : 0) |
  242. SUN4I_TVE_CFG0_COMP_EN |
  243. SUN4I_TVE_CFG0_DAC_CONTROL_54M |
  244. SUN4I_TVE_CFG0_CORE_DATAPATH_54M |
  245. SUN4I_TVE_CFG0_CORE_CONTROL_54M);
  246. /* Configure the DAC for a composite output */
  247. regmap_write(tv->regs, SUN4I_TVE_DAC0_REG,
  248. SUN4I_TVE_DAC0_DAC_EN(0) |
  249. (tv_mode->dac3_en ? SUN4I_TVE_DAC0_DAC_EN(3) : 0) |
  250. SUN4I_TVE_DAC0_INTERNAL_DAC_37_5_OHMS |
  251. SUN4I_TVE_DAC0_CHROMA_0_75 |
  252. SUN4I_TVE_DAC0_LUMA_0_4 |
  253. SUN4I_TVE_DAC0_CLOCK_INVERT |
  254. (tv_mode->dac_bit25_en ? BIT(25) : 0) |
  255. BIT(30));
  256. /* Configure the sample delay between DAC0 and the other DAC */
  257. regmap_write(tv->regs, SUN4I_TVE_NOTCH_REG,
  258. SUN4I_TVE_NOTCH_DAC0_TO_DAC_DLY(1, 0) |
  259. SUN4I_TVE_NOTCH_DAC0_TO_DAC_DLY(2, 0));
  260. regmap_write(tv->regs, SUN4I_TVE_CHROMA_FREQ_REG,
  261. tv_mode->chroma_freq);
  262. /* Set the front and back porch */
  263. regmap_write(tv->regs, SUN4I_TVE_PORCH_REG,
  264. SUN4I_TVE_PORCH_BACK(tv_mode->back_porch) |
  265. SUN4I_TVE_PORCH_FRONT(tv_mode->front_porch));
  266. /* Set the lines setup */
  267. regmap_write(tv->regs, SUN4I_TVE_LINE_REG,
  268. SUN4I_TVE_LINE_FIRST(22) |
  269. SUN4I_TVE_LINE_NUMBER(mode->vtotal));
  270. regmap_write(tv->regs, SUN4I_TVE_LEVEL_REG,
  271. SUN4I_TVE_LEVEL_BLANK(tv_mode->video_levels->blank) |
  272. SUN4I_TVE_LEVEL_BLACK(tv_mode->video_levels->black));
  273. regmap_write(tv->regs, SUN4I_TVE_DAC1_REG,
  274. SUN4I_TVE_DAC1_AMPLITUDE(0, 0x18) |
  275. SUN4I_TVE_DAC1_AMPLITUDE(1, 0x18) |
  276. SUN4I_TVE_DAC1_AMPLITUDE(2, 0x18) |
  277. SUN4I_TVE_DAC1_AMPLITUDE(3, 0x18));
  278. regmap_write(tv->regs, SUN4I_TVE_CB_CR_LVL_REG,
  279. SUN4I_TVE_CB_CR_LVL_CB_BURST(tv_mode->burst_levels->cb) |
  280. SUN4I_TVE_CB_CR_LVL_CR_BURST(tv_mode->burst_levels->cr));
  281. /* Set burst width for a composite output */
  282. regmap_write(tv->regs, SUN4I_TVE_BURST_WIDTH_REG,
  283. SUN4I_TVE_BURST_WIDTH_HSYNC_WIDTH(126) |
  284. SUN4I_TVE_BURST_WIDTH_BURST_WIDTH(68) |
  285. SUN4I_TVE_BURST_WIDTH_BREEZEWAY(22));
  286. regmap_write(tv->regs, SUN4I_TVE_CB_CR_GAIN_REG,
  287. SUN4I_TVE_CB_CR_GAIN_CB(tv_mode->color_gains->cb) |
  288. SUN4I_TVE_CB_CR_GAIN_CR(tv_mode->color_gains->cr));
  289. regmap_write(tv->regs, SUN4I_TVE_SYNC_VBI_REG,
  290. SUN4I_TVE_SYNC_VBI_SYNC(0x10) |
  291. SUN4I_TVE_SYNC_VBI_VBLANK(tv_mode->vblank_level));
  292. regmap_write(tv->regs, SUN4I_TVE_ACTIVE_LINE_REG,
  293. SUN4I_TVE_ACTIVE_LINE(1440));
  294. /* Set composite chroma gain to 50 % */
  295. regmap_write(tv->regs, SUN4I_TVE_CHROMA_REG,
  296. SUN4I_TVE_CHROMA_COMP_GAIN_50);
  297. regmap_write(tv->regs, SUN4I_TVE_12C_REG,
  298. SUN4I_TVE_12C_COMP_YUV_EN |
  299. SUN4I_TVE_12C_NOTCH_WIDTH_WIDE);
  300. regmap_write(tv->regs, SUN4I_TVE_RESYNC_REG,
  301. SUN4I_TVE_RESYNC_PIXEL(tv_mode->resync_params->pixel) |
  302. SUN4I_TVE_RESYNC_LINE(tv_mode->resync_params->line) |
  303. (tv_mode->resync_params->field ?
  304. SUN4I_TVE_RESYNC_FIELD : 0));
  305. regmap_write(tv->regs, SUN4I_TVE_SLAVE_REG, 0);
  306. sunxi_engine_apply_color_correction(crtc->engine);
  307. regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG,
  308. SUN4I_TVE_EN_ENABLE,
  309. SUN4I_TVE_EN_ENABLE);
  310. }
  311. static const struct drm_encoder_helper_funcs sun4i_tv_helper_funcs = {
  312. .atomic_disable = sun4i_tv_disable,
  313. .atomic_enable = sun4i_tv_enable,
  314. };
  315. static const struct drm_connector_helper_funcs sun4i_tv_comp_connector_helper_funcs = {
  316. .atomic_check = drm_atomic_helper_connector_tv_check,
  317. .get_modes = drm_connector_helper_tv_get_modes,
  318. };
  319. static void sun4i_tv_connector_reset(struct drm_connector *connector)
  320. {
  321. drm_atomic_helper_connector_reset(connector);
  322. drm_atomic_helper_connector_tv_reset(connector);
  323. }
  324. static const struct drm_connector_funcs sun4i_tv_comp_connector_funcs = {
  325. .fill_modes = drm_helper_probe_single_connector_modes,
  326. .destroy = drm_connector_cleanup,
  327. .reset = sun4i_tv_connector_reset,
  328. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  329. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  330. };
  331. static const struct regmap_config sun4i_tv_regmap_config = {
  332. .reg_bits = 32,
  333. .val_bits = 32,
  334. .reg_stride = 4,
  335. .max_register = SUN4I_TVE_WSS_DATA2_REG,
  336. .name = "tv-encoder",
  337. };
  338. static int sun4i_tv_bind(struct device *dev, struct device *master,
  339. void *data)
  340. {
  341. struct platform_device *pdev = to_platform_device(dev);
  342. struct drm_device *drm = data;
  343. struct sun4i_drv *drv = drm->dev_private;
  344. struct sun4i_tv *tv;
  345. void __iomem *regs;
  346. int ret;
  347. tv = devm_kzalloc(dev, sizeof(*tv), GFP_KERNEL);
  348. if (!tv)
  349. return -ENOMEM;
  350. tv->drv = drv;
  351. dev_set_drvdata(dev, tv);
  352. regs = devm_platform_ioremap_resource(pdev, 0);
  353. if (IS_ERR(regs)) {
  354. dev_err(dev, "Couldn't map the TV encoder registers\n");
  355. return PTR_ERR(regs);
  356. }
  357. tv->regs = devm_regmap_init_mmio(dev, regs,
  358. &sun4i_tv_regmap_config);
  359. if (IS_ERR(tv->regs)) {
  360. dev_err(dev, "Couldn't create the TV encoder regmap\n");
  361. return PTR_ERR(tv->regs);
  362. }
  363. tv->reset = devm_reset_control_get(dev, NULL);
  364. if (IS_ERR(tv->reset)) {
  365. dev_err(dev, "Couldn't get our reset line\n");
  366. return PTR_ERR(tv->reset);
  367. }
  368. ret = reset_control_deassert(tv->reset);
  369. if (ret) {
  370. dev_err(dev, "Couldn't deassert our reset line\n");
  371. return ret;
  372. }
  373. tv->clk = devm_clk_get(dev, NULL);
  374. if (IS_ERR(tv->clk)) {
  375. dev_err(dev, "Couldn't get the TV encoder clock\n");
  376. ret = PTR_ERR(tv->clk);
  377. goto err_assert_reset;
  378. }
  379. clk_prepare_enable(tv->clk);
  380. drm_encoder_helper_add(&tv->encoder,
  381. &sun4i_tv_helper_funcs);
  382. ret = drm_simple_encoder_init(drm, &tv->encoder,
  383. DRM_MODE_ENCODER_TVDAC);
  384. if (ret) {
  385. dev_err(dev, "Couldn't initialise the TV encoder\n");
  386. goto err_disable_clk;
  387. }
  388. tv->encoder.possible_crtcs = drm_of_find_possible_crtcs(drm,
  389. dev->of_node);
  390. if (!tv->encoder.possible_crtcs) {
  391. ret = -EPROBE_DEFER;
  392. goto err_disable_clk;
  393. }
  394. drm_connector_helper_add(&tv->connector,
  395. &sun4i_tv_comp_connector_helper_funcs);
  396. ret = drm_connector_init(drm, &tv->connector,
  397. &sun4i_tv_comp_connector_funcs,
  398. DRM_MODE_CONNECTOR_Composite);
  399. if (ret) {
  400. dev_err(dev,
  401. "Couldn't initialise the Composite connector\n");
  402. goto err_cleanup_encoder;
  403. }
  404. tv->connector.interlace_allowed = true;
  405. drm_connector_attach_encoder(&tv->connector, &tv->encoder);
  406. ret = drm_mode_create_tv_properties(drm,
  407. BIT(DRM_MODE_TV_MODE_NTSC) |
  408. BIT(DRM_MODE_TV_MODE_PAL));
  409. if (ret)
  410. goto err_cleanup_connector;
  411. drm_object_attach_property(&tv->connector.base,
  412. drm->mode_config.tv_mode_property,
  413. DRM_MODE_TV_MODE_NTSC);
  414. return 0;
  415. err_cleanup_connector:
  416. drm_connector_cleanup(&tv->connector);
  417. err_cleanup_encoder:
  418. drm_encoder_cleanup(&tv->encoder);
  419. err_disable_clk:
  420. clk_disable_unprepare(tv->clk);
  421. err_assert_reset:
  422. reset_control_assert(tv->reset);
  423. return ret;
  424. }
  425. static void sun4i_tv_unbind(struct device *dev, struct device *master,
  426. void *data)
  427. {
  428. struct sun4i_tv *tv = dev_get_drvdata(dev);
  429. drm_connector_cleanup(&tv->connector);
  430. drm_encoder_cleanup(&tv->encoder);
  431. clk_disable_unprepare(tv->clk);
  432. reset_control_assert(tv->reset);
  433. }
  434. static const struct component_ops sun4i_tv_ops = {
  435. .bind = sun4i_tv_bind,
  436. .unbind = sun4i_tv_unbind,
  437. };
  438. static int sun4i_tv_probe(struct platform_device *pdev)
  439. {
  440. return component_add(&pdev->dev, &sun4i_tv_ops);
  441. }
  442. static void sun4i_tv_remove(struct platform_device *pdev)
  443. {
  444. component_del(&pdev->dev, &sun4i_tv_ops);
  445. }
  446. static const struct of_device_id sun4i_tv_of_table[] = {
  447. { .compatible = "allwinner,sun4i-a10-tv-encoder" },
  448. { }
  449. };
  450. MODULE_DEVICE_TABLE(of, sun4i_tv_of_table);
  451. static struct platform_driver sun4i_tv_platform_driver = {
  452. .probe = sun4i_tv_probe,
  453. .remove_new = sun4i_tv_remove,
  454. .driver = {
  455. .name = "sun4i-tve",
  456. .of_match_table = sun4i_tv_of_table,
  457. },
  458. };
  459. module_platform_driver(sun4i_tv_platform_driver);
  460. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  461. MODULE_DESCRIPTION("Allwinner A10 TV Encoder Driver");
  462. MODULE_LICENSE("GPL");