sti_tvout.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4. * Vincent Abriou <vincent.abriou@st.com>
  5. * for STMicroelectronics.
  6. * License terms: GNU General Public License (GPL), version 2
  7. */
  8. #include <linux/clk.h>
  9. #include <linux/component.h>
  10. #include <linux/module.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/reset.h>
  14. #include <drm/drmP.h>
  15. #include <drm/drm_crtc_helper.h>
  16. /* glue registers */
  17. #define TVO_CSC_MAIN_M0 0x000
  18. #define TVO_CSC_MAIN_M1 0x004
  19. #define TVO_CSC_MAIN_M2 0x008
  20. #define TVO_CSC_MAIN_M3 0x00c
  21. #define TVO_CSC_MAIN_M4 0x010
  22. #define TVO_CSC_MAIN_M5 0x014
  23. #define TVO_CSC_MAIN_M6 0x018
  24. #define TVO_CSC_MAIN_M7 0x01c
  25. #define TVO_MAIN_IN_VID_FORMAT 0x030
  26. #define TVO_CSC_AUX_M0 0x100
  27. #define TVO_CSC_AUX_M1 0x104
  28. #define TVO_CSC_AUX_M2 0x108
  29. #define TVO_CSC_AUX_M3 0x10c
  30. #define TVO_CSC_AUX_M4 0x110
  31. #define TVO_CSC_AUX_M5 0x114
  32. #define TVO_CSC_AUX_M6 0x118
  33. #define TVO_CSC_AUX_M7 0x11c
  34. #define TVO_AUX_IN_VID_FORMAT 0x130
  35. #define TVO_VIP_HDF 0x400
  36. #define TVO_HD_SYNC_SEL 0x418
  37. #define TVO_HD_DAC_CFG_OFF 0x420
  38. #define TVO_VIP_HDMI 0x500
  39. #define TVO_HDMI_FORCE_COLOR_0 0x504
  40. #define TVO_HDMI_FORCE_COLOR_1 0x508
  41. #define TVO_HDMI_CLIP_VALUE_B_CB 0x50c
  42. #define TVO_HDMI_CLIP_VALUE_Y_G 0x510
  43. #define TVO_HDMI_CLIP_VALUE_R_CR 0x514
  44. #define TVO_HDMI_SYNC_SEL 0x518
  45. #define TVO_HDMI_DFV_OBS 0x540
  46. #define TVO_IN_FMT_SIGNED BIT(0)
  47. #define TVO_SYNC_EXT BIT(4)
  48. #define TVO_VIP_REORDER_R_SHIFT 24
  49. #define TVO_VIP_REORDER_G_SHIFT 20
  50. #define TVO_VIP_REORDER_B_SHIFT 16
  51. #define TVO_VIP_REORDER_MASK 0x3
  52. #define TVO_VIP_REORDER_Y_G_SEL 0
  53. #define TVO_VIP_REORDER_CB_B_SEL 1
  54. #define TVO_VIP_REORDER_CR_R_SEL 2
  55. #define TVO_VIP_CLIP_SHIFT 8
  56. #define TVO_VIP_CLIP_MASK 0x7
  57. #define TVO_VIP_CLIP_DISABLED 0
  58. #define TVO_VIP_CLIP_EAV_SAV 1
  59. #define TVO_VIP_CLIP_LIMITED_RANGE_RGB_Y 2
  60. #define TVO_VIP_CLIP_LIMITED_RANGE_CB_CR 3
  61. #define TVO_VIP_CLIP_PROG_RANGE 4
  62. #define TVO_VIP_RND_SHIFT 4
  63. #define TVO_VIP_RND_MASK 0x3
  64. #define TVO_VIP_RND_8BIT_ROUNDED 0
  65. #define TVO_VIP_RND_10BIT_ROUNDED 1
  66. #define TVO_VIP_RND_12BIT_ROUNDED 2
  67. #define TVO_VIP_SEL_INPUT_MASK 0xf
  68. #define TVO_VIP_SEL_INPUT_MAIN 0x0
  69. #define TVO_VIP_SEL_INPUT_AUX 0x8
  70. #define TVO_VIP_SEL_INPUT_FORCE_COLOR 0xf
  71. #define TVO_VIP_SEL_INPUT_BYPASS_MASK 0x1
  72. #define TVO_VIP_SEL_INPUT_BYPASSED 1
  73. #define TVO_SYNC_MAIN_VTG_SET_REF 0x00
  74. #define TVO_SYNC_MAIN_VTG_SET_1 0x01
  75. #define TVO_SYNC_MAIN_VTG_SET_2 0x02
  76. #define TVO_SYNC_MAIN_VTG_SET_3 0x03
  77. #define TVO_SYNC_MAIN_VTG_SET_4 0x04
  78. #define TVO_SYNC_MAIN_VTG_SET_5 0x05
  79. #define TVO_SYNC_MAIN_VTG_SET_6 0x06
  80. #define TVO_SYNC_AUX_VTG_SET_REF 0x10
  81. #define TVO_SYNC_AUX_VTG_SET_1 0x11
  82. #define TVO_SYNC_AUX_VTG_SET_2 0x12
  83. #define TVO_SYNC_AUX_VTG_SET_3 0x13
  84. #define TVO_SYNC_AUX_VTG_SET_4 0x14
  85. #define TVO_SYNC_AUX_VTG_SET_5 0x15
  86. #define TVO_SYNC_AUX_VTG_SET_6 0x16
  87. #define TVO_SYNC_HD_DCS_SHIFT 8
  88. #define ENCODER_MAIN_CRTC_MASK BIT(0)
  89. /* enum listing the supported output data format */
  90. enum sti_tvout_video_out_type {
  91. STI_TVOUT_VIDEO_OUT_RGB,
  92. STI_TVOUT_VIDEO_OUT_YUV,
  93. };
  94. struct sti_tvout {
  95. struct device *dev;
  96. struct drm_device *drm_dev;
  97. void __iomem *regs;
  98. struct reset_control *reset;
  99. struct drm_encoder *hdmi;
  100. struct drm_encoder *hda;
  101. };
  102. struct sti_tvout_encoder {
  103. struct drm_encoder encoder;
  104. struct sti_tvout *tvout;
  105. };
  106. #define to_sti_tvout_encoder(x) \
  107. container_of(x, struct sti_tvout_encoder, encoder)
  108. #define to_sti_tvout(x) to_sti_tvout_encoder(x)->tvout
  109. /* preformatter conversion matrix */
  110. static const u32 rgb_to_ycbcr_601[8] = {
  111. 0xF927082E, 0x04C9FEAB, 0x01D30964, 0xFA95FD3D,
  112. 0x0000082E, 0x00002000, 0x00002000, 0x00000000
  113. };
  114. /* 709 RGB to YCbCr */
  115. static const u32 rgb_to_ycbcr_709[8] = {
  116. 0xF891082F, 0x0367FF40, 0x01280B71, 0xF9B1FE20,
  117. 0x0000082F, 0x00002000, 0x00002000, 0x00000000
  118. };
  119. static u32 tvout_read(struct sti_tvout *tvout, int offset)
  120. {
  121. return readl(tvout->regs + offset);
  122. }
  123. static void tvout_write(struct sti_tvout *tvout, u32 val, int offset)
  124. {
  125. writel(val, tvout->regs + offset);
  126. }
  127. /**
  128. * Set the clipping mode of a VIP
  129. *
  130. * @tvout: tvout structure
  131. * @cr_r:
  132. * @y_g:
  133. * @cb_b:
  134. */
  135. static void tvout_vip_set_color_order(struct sti_tvout *tvout,
  136. u32 cr_r, u32 y_g, u32 cb_b)
  137. {
  138. u32 val = tvout_read(tvout, TVO_VIP_HDMI);
  139. val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_R_SHIFT);
  140. val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_G_SHIFT);
  141. val &= ~(TVO_VIP_REORDER_MASK << TVO_VIP_REORDER_B_SHIFT);
  142. val |= cr_r << TVO_VIP_REORDER_R_SHIFT;
  143. val |= y_g << TVO_VIP_REORDER_G_SHIFT;
  144. val |= cb_b << TVO_VIP_REORDER_B_SHIFT;
  145. tvout_write(tvout, val, TVO_VIP_HDMI);
  146. }
  147. /**
  148. * Set the clipping mode of a VIP
  149. *
  150. * @tvout: tvout structure
  151. * @range: clipping range
  152. */
  153. static void tvout_vip_set_clip_mode(struct sti_tvout *tvout, u32 range)
  154. {
  155. u32 val = tvout_read(tvout, TVO_VIP_HDMI);
  156. val &= ~(TVO_VIP_CLIP_MASK << TVO_VIP_CLIP_SHIFT);
  157. val |= range << TVO_VIP_CLIP_SHIFT;
  158. tvout_write(tvout, val, TVO_VIP_HDMI);
  159. }
  160. /**
  161. * Set the rounded value of a VIP
  162. *
  163. * @tvout: tvout structure
  164. * @rnd: rounded val per component
  165. */
  166. static void tvout_vip_set_rnd(struct sti_tvout *tvout, u32 rnd)
  167. {
  168. u32 val = tvout_read(tvout, TVO_VIP_HDMI);
  169. val &= ~(TVO_VIP_RND_MASK << TVO_VIP_RND_SHIFT);
  170. val |= rnd << TVO_VIP_RND_SHIFT;
  171. tvout_write(tvout, val, TVO_VIP_HDMI);
  172. }
  173. /**
  174. * Select the VIP input
  175. *
  176. * @tvout: tvout structure
  177. * @sel_input: selected_input (main/aux + conv)
  178. */
  179. static void tvout_vip_set_sel_input(struct sti_tvout *tvout,
  180. bool main_path,
  181. bool sel_input_logic_inverted,
  182. enum sti_tvout_video_out_type video_out)
  183. {
  184. u32 sel_input;
  185. u32 val = tvout_read(tvout, TVO_VIP_HDMI);
  186. if (main_path)
  187. sel_input = TVO_VIP_SEL_INPUT_MAIN;
  188. else
  189. sel_input = TVO_VIP_SEL_INPUT_AUX;
  190. switch (video_out) {
  191. case STI_TVOUT_VIDEO_OUT_RGB:
  192. sel_input |= TVO_VIP_SEL_INPUT_BYPASSED;
  193. break;
  194. case STI_TVOUT_VIDEO_OUT_YUV:
  195. sel_input &= ~TVO_VIP_SEL_INPUT_BYPASSED;
  196. break;
  197. }
  198. /* on stih407 chip the sel_input bypass mode logic is inverted */
  199. if (sel_input_logic_inverted)
  200. sel_input = sel_input ^ TVO_VIP_SEL_INPUT_BYPASS_MASK;
  201. val &= ~TVO_VIP_SEL_INPUT_MASK;
  202. val |= sel_input;
  203. tvout_write(tvout, val, TVO_VIP_HDMI);
  204. }
  205. /**
  206. * Select the input video signed or unsigned
  207. *
  208. * @tvout: tvout structure
  209. * @in_vid_signed: used video input format
  210. */
  211. static void tvout_vip_set_in_vid_fmt(struct sti_tvout *tvout, u32 in_vid_fmt)
  212. {
  213. u32 val = tvout_read(tvout, TVO_VIP_HDMI);
  214. val &= ~TVO_IN_FMT_SIGNED;
  215. val |= in_vid_fmt;
  216. tvout_write(tvout, val, TVO_MAIN_IN_VID_FORMAT);
  217. }
  218. /**
  219. * Start VIP block for HDMI output
  220. *
  221. * @tvout: pointer on tvout structure
  222. * @main_path: true if main path has to be used in the vip configuration
  223. * else aux path is used.
  224. */
  225. static void tvout_hdmi_start(struct sti_tvout *tvout, bool main_path)
  226. {
  227. struct device_node *node = tvout->dev->of_node;
  228. bool sel_input_logic_inverted = false;
  229. dev_dbg(tvout->dev, "%s\n", __func__);
  230. if (main_path) {
  231. DRM_DEBUG_DRIVER("main vip for hdmi\n");
  232. /* select the input sync for hdmi = VTG set 1 */
  233. tvout_write(tvout, TVO_SYNC_MAIN_VTG_SET_1, TVO_HDMI_SYNC_SEL);
  234. } else {
  235. DRM_DEBUG_DRIVER("aux vip for hdmi\n");
  236. /* select the input sync for hdmi = VTG set 1 */
  237. tvout_write(tvout, TVO_SYNC_AUX_VTG_SET_1, TVO_HDMI_SYNC_SEL);
  238. }
  239. /* set color channel order */
  240. tvout_vip_set_color_order(tvout,
  241. TVO_VIP_REORDER_CR_R_SEL,
  242. TVO_VIP_REORDER_Y_G_SEL,
  243. TVO_VIP_REORDER_CB_B_SEL);
  244. /* set clipping mode (Limited range RGB/Y) */
  245. tvout_vip_set_clip_mode(tvout, TVO_VIP_CLIP_LIMITED_RANGE_RGB_Y);
  246. /* set round mode (rounded to 8-bit per component) */
  247. tvout_vip_set_rnd(tvout, TVO_VIP_RND_8BIT_ROUNDED);
  248. if (of_device_is_compatible(node, "st,stih407-tvout")) {
  249. /* set input video format */
  250. tvout_vip_set_in_vid_fmt(tvout->regs + TVO_MAIN_IN_VID_FORMAT,
  251. TVO_IN_FMT_SIGNED);
  252. sel_input_logic_inverted = true;
  253. }
  254. /* input selection */
  255. tvout_vip_set_sel_input(tvout, main_path,
  256. sel_input_logic_inverted, STI_TVOUT_VIDEO_OUT_RGB);
  257. }
  258. /**
  259. * Start HDF VIP and HD DAC
  260. *
  261. * @tvout: pointer on tvout structure
  262. * @main_path: true if main path has to be used in the vip configuration
  263. * else aux path is used.
  264. */
  265. static void tvout_hda_start(struct sti_tvout *tvout, bool main_path)
  266. {
  267. struct device_node *node = tvout->dev->of_node;
  268. bool sel_input_logic_inverted = false;
  269. dev_dbg(tvout->dev, "%s\n", __func__);
  270. if (!main_path) {
  271. DRM_ERROR("HD Analog on aux not implemented\n");
  272. return;
  273. }
  274. DRM_DEBUG_DRIVER("main vip for HDF\n");
  275. /* set color channel order */
  276. tvout_vip_set_color_order(tvout->regs + TVO_VIP_HDF,
  277. TVO_VIP_REORDER_CR_R_SEL,
  278. TVO_VIP_REORDER_Y_G_SEL,
  279. TVO_VIP_REORDER_CB_B_SEL);
  280. /* set clipping mode (Limited range RGB/Y) */
  281. tvout_vip_set_clip_mode(tvout->regs + TVO_VIP_HDF,
  282. TVO_VIP_CLIP_LIMITED_RANGE_CB_CR);
  283. /* set round mode (rounded to 10-bit per component) */
  284. tvout_vip_set_rnd(tvout->regs + TVO_VIP_HDF, TVO_VIP_RND_10BIT_ROUNDED);
  285. if (of_device_is_compatible(node, "st,stih407-tvout")) {
  286. /* set input video format */
  287. tvout_vip_set_in_vid_fmt(tvout, TVO_IN_FMT_SIGNED);
  288. sel_input_logic_inverted = true;
  289. }
  290. /* Input selection */
  291. tvout_vip_set_sel_input(tvout->regs + TVO_VIP_HDF,
  292. main_path,
  293. sel_input_logic_inverted,
  294. STI_TVOUT_VIDEO_OUT_YUV);
  295. /* select the input sync for HD analog = VTG set 3
  296. * and HD DCS = VTG set 2 */
  297. tvout_write(tvout,
  298. (TVO_SYNC_MAIN_VTG_SET_2 << TVO_SYNC_HD_DCS_SHIFT)
  299. | TVO_SYNC_MAIN_VTG_SET_3,
  300. TVO_HD_SYNC_SEL);
  301. /* power up HD DAC */
  302. tvout_write(tvout, 0, TVO_HD_DAC_CFG_OFF);
  303. }
  304. static void sti_tvout_encoder_dpms(struct drm_encoder *encoder, int mode)
  305. {
  306. }
  307. static bool sti_tvout_encoder_mode_fixup(struct drm_encoder *encoder,
  308. const struct drm_display_mode *mode,
  309. struct drm_display_mode *adjusted_mode)
  310. {
  311. return true;
  312. }
  313. static void sti_tvout_encoder_mode_set(struct drm_encoder *encoder,
  314. struct drm_display_mode *mode,
  315. struct drm_display_mode *adjusted_mode)
  316. {
  317. }
  318. static void sti_tvout_encoder_prepare(struct drm_encoder *encoder)
  319. {
  320. }
  321. static void sti_tvout_encoder_destroy(struct drm_encoder *encoder)
  322. {
  323. struct sti_tvout_encoder *sti_encoder = to_sti_tvout_encoder(encoder);
  324. drm_encoder_cleanup(encoder);
  325. kfree(sti_encoder);
  326. }
  327. static const struct drm_encoder_funcs sti_tvout_encoder_funcs = {
  328. .destroy = sti_tvout_encoder_destroy,
  329. };
  330. static void sti_hda_encoder_commit(struct drm_encoder *encoder)
  331. {
  332. struct sti_tvout *tvout = to_sti_tvout(encoder);
  333. tvout_hda_start(tvout, true);
  334. }
  335. static void sti_hda_encoder_disable(struct drm_encoder *encoder)
  336. {
  337. struct sti_tvout *tvout = to_sti_tvout(encoder);
  338. /* reset VIP register */
  339. tvout_write(tvout, 0x0, TVO_VIP_HDF);
  340. /* power down HD DAC */
  341. tvout_write(tvout, 1, TVO_HD_DAC_CFG_OFF);
  342. }
  343. static const struct drm_encoder_helper_funcs sti_hda_encoder_helper_funcs = {
  344. .dpms = sti_tvout_encoder_dpms,
  345. .mode_fixup = sti_tvout_encoder_mode_fixup,
  346. .mode_set = sti_tvout_encoder_mode_set,
  347. .prepare = sti_tvout_encoder_prepare,
  348. .commit = sti_hda_encoder_commit,
  349. .disable = sti_hda_encoder_disable,
  350. };
  351. static struct drm_encoder *sti_tvout_create_hda_encoder(struct drm_device *dev,
  352. struct sti_tvout *tvout)
  353. {
  354. struct sti_tvout_encoder *encoder;
  355. struct drm_encoder *drm_encoder;
  356. encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL);
  357. if (!encoder)
  358. return NULL;
  359. encoder->tvout = tvout;
  360. drm_encoder = (struct drm_encoder *) encoder;
  361. drm_encoder->possible_crtcs = ENCODER_MAIN_CRTC_MASK;
  362. drm_encoder->possible_clones = 1 << 0;
  363. drm_encoder_init(dev, drm_encoder,
  364. &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_DAC);
  365. drm_encoder_helper_add(drm_encoder, &sti_hda_encoder_helper_funcs);
  366. return drm_encoder;
  367. }
  368. static void sti_hdmi_encoder_commit(struct drm_encoder *encoder)
  369. {
  370. struct sti_tvout *tvout = to_sti_tvout(encoder);
  371. tvout_hdmi_start(tvout, true);
  372. }
  373. static void sti_hdmi_encoder_disable(struct drm_encoder *encoder)
  374. {
  375. struct sti_tvout *tvout = to_sti_tvout(encoder);
  376. /* reset VIP register */
  377. tvout_write(tvout, 0x0, TVO_VIP_HDMI);
  378. }
  379. static const struct drm_encoder_helper_funcs sti_hdmi_encoder_helper_funcs = {
  380. .dpms = sti_tvout_encoder_dpms,
  381. .mode_fixup = sti_tvout_encoder_mode_fixup,
  382. .mode_set = sti_tvout_encoder_mode_set,
  383. .prepare = sti_tvout_encoder_prepare,
  384. .commit = sti_hdmi_encoder_commit,
  385. .disable = sti_hdmi_encoder_disable,
  386. };
  387. static struct drm_encoder *sti_tvout_create_hdmi_encoder(struct drm_device *dev,
  388. struct sti_tvout *tvout)
  389. {
  390. struct sti_tvout_encoder *encoder;
  391. struct drm_encoder *drm_encoder;
  392. encoder = devm_kzalloc(tvout->dev, sizeof(*encoder), GFP_KERNEL);
  393. if (!encoder)
  394. return NULL;
  395. encoder->tvout = tvout;
  396. drm_encoder = (struct drm_encoder *) encoder;
  397. drm_encoder->possible_crtcs = ENCODER_MAIN_CRTC_MASK;
  398. drm_encoder->possible_clones = 1 << 1;
  399. drm_encoder_init(dev, drm_encoder,
  400. &sti_tvout_encoder_funcs, DRM_MODE_ENCODER_TMDS);
  401. drm_encoder_helper_add(drm_encoder, &sti_hdmi_encoder_helper_funcs);
  402. return drm_encoder;
  403. }
  404. static void sti_tvout_create_encoders(struct drm_device *dev,
  405. struct sti_tvout *tvout)
  406. {
  407. tvout->hdmi = sti_tvout_create_hdmi_encoder(dev, tvout);
  408. tvout->hda = sti_tvout_create_hda_encoder(dev, tvout);
  409. }
  410. static void sti_tvout_destroy_encoders(struct sti_tvout *tvout)
  411. {
  412. if (tvout->hdmi)
  413. drm_encoder_cleanup(tvout->hdmi);
  414. tvout->hdmi = NULL;
  415. if (tvout->hda)
  416. drm_encoder_cleanup(tvout->hda);
  417. tvout->hda = NULL;
  418. }
  419. static int sti_tvout_bind(struct device *dev, struct device *master, void *data)
  420. {
  421. struct sti_tvout *tvout = dev_get_drvdata(dev);
  422. struct drm_device *drm_dev = data;
  423. unsigned int i;
  424. int ret;
  425. tvout->drm_dev = drm_dev;
  426. /* set preformatter matrix */
  427. for (i = 0; i < 8; i++) {
  428. tvout_write(tvout, rgb_to_ycbcr_601[i],
  429. TVO_CSC_MAIN_M0 + (i * 4));
  430. tvout_write(tvout, rgb_to_ycbcr_601[i],
  431. TVO_CSC_AUX_M0 + (i * 4));
  432. }
  433. sti_tvout_create_encoders(drm_dev, tvout);
  434. ret = component_bind_all(dev, drm_dev);
  435. if (ret)
  436. sti_tvout_destroy_encoders(tvout);
  437. return ret;
  438. }
  439. static void sti_tvout_unbind(struct device *dev, struct device *master,
  440. void *data)
  441. {
  442. /* do nothing */
  443. }
  444. static const struct component_ops sti_tvout_ops = {
  445. .bind = sti_tvout_bind,
  446. .unbind = sti_tvout_unbind,
  447. };
  448. static int compare_of(struct device *dev, void *data)
  449. {
  450. return dev->of_node == data;
  451. }
  452. static int sti_tvout_master_bind(struct device *dev)
  453. {
  454. return 0;
  455. }
  456. static void sti_tvout_master_unbind(struct device *dev)
  457. {
  458. /* do nothing */
  459. }
  460. static const struct component_master_ops sti_tvout_master_ops = {
  461. .bind = sti_tvout_master_bind,
  462. .unbind = sti_tvout_master_unbind,
  463. };
  464. static int sti_tvout_probe(struct platform_device *pdev)
  465. {
  466. struct device *dev = &pdev->dev;
  467. struct device_node *node = dev->of_node;
  468. struct sti_tvout *tvout;
  469. struct resource *res;
  470. struct device_node *child_np;
  471. struct component_match *match = NULL;
  472. DRM_INFO("%s\n", __func__);
  473. if (!node)
  474. return -ENODEV;
  475. tvout = devm_kzalloc(dev, sizeof(*tvout), GFP_KERNEL);
  476. if (!tvout)
  477. return -ENOMEM;
  478. tvout->dev = dev;
  479. /* get Memory ressources */
  480. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tvout-reg");
  481. if (!res) {
  482. DRM_ERROR("Invalid glue resource\n");
  483. return -ENOMEM;
  484. }
  485. tvout->regs = devm_ioremap_nocache(dev, res->start, resource_size(res));
  486. if (!tvout->regs)
  487. return -ENOMEM;
  488. /* get reset resources */
  489. tvout->reset = devm_reset_control_get(dev, "tvout");
  490. /* take tvout out of reset */
  491. if (!IS_ERR(tvout->reset))
  492. reset_control_deassert(tvout->reset);
  493. platform_set_drvdata(pdev, tvout);
  494. of_platform_populate(node, NULL, NULL, dev);
  495. child_np = of_get_next_available_child(node, NULL);
  496. while (child_np) {
  497. component_match_add(dev, &match, compare_of, child_np);
  498. of_node_put(child_np);
  499. child_np = of_get_next_available_child(node, child_np);
  500. }
  501. component_master_add_with_match(dev, &sti_tvout_master_ops, match);
  502. return component_add(dev, &sti_tvout_ops);
  503. }
  504. static int sti_tvout_remove(struct platform_device *pdev)
  505. {
  506. component_master_del(&pdev->dev, &sti_tvout_master_ops);
  507. component_del(&pdev->dev, &sti_tvout_ops);
  508. return 0;
  509. }
  510. static const struct of_device_id tvout_of_match[] = {
  511. { .compatible = "st,stih416-tvout", },
  512. { .compatible = "st,stih407-tvout", },
  513. { /* end node */ }
  514. };
  515. MODULE_DEVICE_TABLE(of, tvout_of_match);
  516. struct platform_driver sti_tvout_driver = {
  517. .driver = {
  518. .name = "sti-tvout",
  519. .owner = THIS_MODULE,
  520. .of_match_table = tvout_of_match,
  521. },
  522. .probe = sti_tvout_probe,
  523. .remove = sti_tvout_remove,
  524. };
  525. module_platform_driver(sti_tvout_driver);
  526. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  527. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  528. MODULE_LICENSE("GPL");