hdmi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Copyright (c) 2014 The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <robdclark@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/of_irq.h>
  19. #include <linux/of_gpio.h>
  20. #include <sound/hdmi-codec.h>
  21. #include "hdmi.h"
  22. void msm_hdmi_set_mode(struct hdmi *hdmi, bool power_on)
  23. {
  24. uint32_t ctrl = 0;
  25. unsigned long flags;
  26. spin_lock_irqsave(&hdmi->reg_lock, flags);
  27. if (power_on) {
  28. ctrl |= HDMI_CTRL_ENABLE;
  29. if (!hdmi->hdmi_mode) {
  30. ctrl |= HDMI_CTRL_HDMI;
  31. hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
  32. ctrl &= ~HDMI_CTRL_HDMI;
  33. } else {
  34. ctrl |= HDMI_CTRL_HDMI;
  35. }
  36. } else {
  37. ctrl = HDMI_CTRL_HDMI;
  38. }
  39. hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
  40. spin_unlock_irqrestore(&hdmi->reg_lock, flags);
  41. DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
  42. power_on ? "Enable" : "Disable", ctrl);
  43. }
  44. static irqreturn_t msm_hdmi_irq(int irq, void *dev_id)
  45. {
  46. struct hdmi *hdmi = dev_id;
  47. /* Process HPD: */
  48. msm_hdmi_connector_irq(hdmi->connector);
  49. /* Process DDC: */
  50. msm_hdmi_i2c_irq(hdmi->i2c);
  51. /* Process HDCP: */
  52. if (hdmi->hdcp_ctrl)
  53. msm_hdmi_hdcp_irq(hdmi->hdcp_ctrl);
  54. /* TODO audio.. */
  55. return IRQ_HANDLED;
  56. }
  57. static void msm_hdmi_destroy(struct hdmi *hdmi)
  58. {
  59. /*
  60. * at this point, hpd has been disabled,
  61. * after flush workq, it's safe to deinit hdcp
  62. */
  63. if (hdmi->workq) {
  64. flush_workqueue(hdmi->workq);
  65. destroy_workqueue(hdmi->workq);
  66. }
  67. msm_hdmi_hdcp_destroy(hdmi);
  68. if (hdmi->phy_dev) {
  69. put_device(hdmi->phy_dev);
  70. hdmi->phy = NULL;
  71. hdmi->phy_dev = NULL;
  72. }
  73. if (hdmi->i2c)
  74. msm_hdmi_i2c_destroy(hdmi->i2c);
  75. platform_set_drvdata(hdmi->pdev, NULL);
  76. }
  77. static int msm_hdmi_get_phy(struct hdmi *hdmi)
  78. {
  79. struct platform_device *pdev = hdmi->pdev;
  80. struct platform_device *phy_pdev;
  81. struct device_node *phy_node;
  82. phy_node = of_parse_phandle(pdev->dev.of_node, "phys", 0);
  83. if (!phy_node) {
  84. dev_err(&pdev->dev, "cannot find phy device\n");
  85. return -ENXIO;
  86. }
  87. phy_pdev = of_find_device_by_node(phy_node);
  88. if (phy_pdev)
  89. hdmi->phy = platform_get_drvdata(phy_pdev);
  90. of_node_put(phy_node);
  91. if (!phy_pdev || !hdmi->phy) {
  92. dev_err(&pdev->dev, "phy driver is not ready\n");
  93. return -EPROBE_DEFER;
  94. }
  95. hdmi->phy_dev = get_device(&phy_pdev->dev);
  96. return 0;
  97. }
  98. /* construct hdmi at bind/probe time, grab all the resources. If
  99. * we are to EPROBE_DEFER we want to do it here, rather than later
  100. * at modeset_init() time
  101. */
  102. static struct hdmi *msm_hdmi_init(struct platform_device *pdev)
  103. {
  104. struct hdmi_platform_config *config = pdev->dev.platform_data;
  105. struct hdmi *hdmi = NULL;
  106. struct resource *res;
  107. int i, ret;
  108. hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
  109. if (!hdmi) {
  110. ret = -ENOMEM;
  111. goto fail;
  112. }
  113. hdmi->pdev = pdev;
  114. hdmi->config = config;
  115. spin_lock_init(&hdmi->reg_lock);
  116. hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
  117. if (IS_ERR(hdmi->mmio)) {
  118. ret = PTR_ERR(hdmi->mmio);
  119. goto fail;
  120. }
  121. /* HDCP needs physical address of hdmi register */
  122. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  123. config->mmio_name);
  124. hdmi->mmio_phy_addr = res->start;
  125. hdmi->qfprom_mmio = msm_ioremap(pdev,
  126. config->qfprom_mmio_name, "HDMI_QFPROM");
  127. if (IS_ERR(hdmi->qfprom_mmio)) {
  128. dev_info(&pdev->dev, "can't find qfprom resource\n");
  129. hdmi->qfprom_mmio = NULL;
  130. }
  131. hdmi->hpd_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_regs[0]) *
  132. config->hpd_reg_cnt, GFP_KERNEL);
  133. if (!hdmi->hpd_regs) {
  134. ret = -ENOMEM;
  135. goto fail;
  136. }
  137. for (i = 0; i < config->hpd_reg_cnt; i++) {
  138. struct regulator *reg;
  139. reg = devm_regulator_get(&pdev->dev,
  140. config->hpd_reg_names[i]);
  141. if (IS_ERR(reg)) {
  142. ret = PTR_ERR(reg);
  143. dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
  144. config->hpd_reg_names[i], ret);
  145. goto fail;
  146. }
  147. hdmi->hpd_regs[i] = reg;
  148. }
  149. hdmi->pwr_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_regs[0]) *
  150. config->pwr_reg_cnt, GFP_KERNEL);
  151. if (!hdmi->pwr_regs) {
  152. ret = -ENOMEM;
  153. goto fail;
  154. }
  155. for (i = 0; i < config->pwr_reg_cnt; i++) {
  156. struct regulator *reg;
  157. reg = devm_regulator_get(&pdev->dev,
  158. config->pwr_reg_names[i]);
  159. if (IS_ERR(reg)) {
  160. ret = PTR_ERR(reg);
  161. dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
  162. config->pwr_reg_names[i], ret);
  163. goto fail;
  164. }
  165. hdmi->pwr_regs[i] = reg;
  166. }
  167. hdmi->hpd_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_clks[0]) *
  168. config->hpd_clk_cnt, GFP_KERNEL);
  169. if (!hdmi->hpd_clks) {
  170. ret = -ENOMEM;
  171. goto fail;
  172. }
  173. for (i = 0; i < config->hpd_clk_cnt; i++) {
  174. struct clk *clk;
  175. clk = msm_clk_get(pdev, config->hpd_clk_names[i]);
  176. if (IS_ERR(clk)) {
  177. ret = PTR_ERR(clk);
  178. dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
  179. config->hpd_clk_names[i], ret);
  180. goto fail;
  181. }
  182. hdmi->hpd_clks[i] = clk;
  183. }
  184. hdmi->pwr_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_clks[0]) *
  185. config->pwr_clk_cnt, GFP_KERNEL);
  186. if (!hdmi->pwr_clks) {
  187. ret = -ENOMEM;
  188. goto fail;
  189. }
  190. for (i = 0; i < config->pwr_clk_cnt; i++) {
  191. struct clk *clk;
  192. clk = msm_clk_get(pdev, config->pwr_clk_names[i]);
  193. if (IS_ERR(clk)) {
  194. ret = PTR_ERR(clk);
  195. dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
  196. config->pwr_clk_names[i], ret);
  197. goto fail;
  198. }
  199. hdmi->pwr_clks[i] = clk;
  200. }
  201. pm_runtime_enable(&pdev->dev);
  202. hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
  203. hdmi->i2c = msm_hdmi_i2c_init(hdmi);
  204. if (IS_ERR(hdmi->i2c)) {
  205. ret = PTR_ERR(hdmi->i2c);
  206. dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
  207. hdmi->i2c = NULL;
  208. goto fail;
  209. }
  210. ret = msm_hdmi_get_phy(hdmi);
  211. if (ret) {
  212. dev_err(&pdev->dev, "failed to get phy\n");
  213. goto fail;
  214. }
  215. hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
  216. if (IS_ERR(hdmi->hdcp_ctrl)) {
  217. dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
  218. hdmi->hdcp_ctrl = NULL;
  219. }
  220. return hdmi;
  221. fail:
  222. if (hdmi)
  223. msm_hdmi_destroy(hdmi);
  224. return ERR_PTR(ret);
  225. }
  226. /* Second part of initialization, the drm/kms level modeset_init,
  227. * constructs/initializes mode objects, etc, is called from master
  228. * driver (not hdmi sub-device's probe/bind!)
  229. *
  230. * Any resource (regulator/clk/etc) which could be missing at boot
  231. * should be handled in msm_hdmi_init() so that failure happens from
  232. * hdmi sub-device's probe.
  233. */
  234. int msm_hdmi_modeset_init(struct hdmi *hdmi,
  235. struct drm_device *dev, struct drm_encoder *encoder)
  236. {
  237. struct msm_drm_private *priv = dev->dev_private;
  238. struct platform_device *pdev = hdmi->pdev;
  239. int ret;
  240. hdmi->dev = dev;
  241. hdmi->encoder = encoder;
  242. hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
  243. hdmi->bridge = msm_hdmi_bridge_init(hdmi);
  244. if (IS_ERR(hdmi->bridge)) {
  245. ret = PTR_ERR(hdmi->bridge);
  246. dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
  247. hdmi->bridge = NULL;
  248. goto fail;
  249. }
  250. hdmi->connector = msm_hdmi_connector_init(hdmi);
  251. if (IS_ERR(hdmi->connector)) {
  252. ret = PTR_ERR(hdmi->connector);
  253. dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
  254. hdmi->connector = NULL;
  255. goto fail;
  256. }
  257. hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  258. if (hdmi->irq < 0) {
  259. ret = hdmi->irq;
  260. dev_err(dev->dev, "failed to get irq: %d\n", ret);
  261. goto fail;
  262. }
  263. ret = devm_request_irq(&pdev->dev, hdmi->irq,
  264. msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  265. "hdmi_isr", hdmi);
  266. if (ret < 0) {
  267. dev_err(dev->dev, "failed to request IRQ%u: %d\n",
  268. hdmi->irq, ret);
  269. goto fail;
  270. }
  271. encoder->bridge = hdmi->bridge;
  272. priv->bridges[priv->num_bridges++] = hdmi->bridge;
  273. priv->connectors[priv->num_connectors++] = hdmi->connector;
  274. platform_set_drvdata(pdev, hdmi);
  275. return 0;
  276. fail:
  277. /* bridge is normally destroyed by drm: */
  278. if (hdmi->bridge) {
  279. msm_hdmi_bridge_destroy(hdmi->bridge);
  280. hdmi->bridge = NULL;
  281. }
  282. if (hdmi->connector) {
  283. hdmi->connector->funcs->destroy(hdmi->connector);
  284. hdmi->connector = NULL;
  285. }
  286. return ret;
  287. }
  288. /*
  289. * The hdmi device:
  290. */
  291. #define HDMI_CFG(item, entry) \
  292. .item ## _names = item ##_names_ ## entry, \
  293. .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
  294. static const char *pwr_reg_names_none[] = {};
  295. static const char *hpd_reg_names_none[] = {};
  296. static struct hdmi_platform_config hdmi_tx_8660_config;
  297. static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
  298. static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"};
  299. static struct hdmi_platform_config hdmi_tx_8960_config = {
  300. HDMI_CFG(hpd_reg, 8960),
  301. HDMI_CFG(hpd_clk, 8960),
  302. };
  303. static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
  304. static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
  305. static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"};
  306. static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"};
  307. static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
  308. static struct hdmi_platform_config hdmi_tx_8974_config = {
  309. HDMI_CFG(pwr_reg, 8x74),
  310. HDMI_CFG(hpd_reg, 8x74),
  311. HDMI_CFG(pwr_clk, 8x74),
  312. HDMI_CFG(hpd_clk, 8x74),
  313. .hpd_freq = hpd_clk_freq_8x74,
  314. };
  315. static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
  316. static struct hdmi_platform_config hdmi_tx_8084_config = {
  317. HDMI_CFG(pwr_reg, 8x74),
  318. HDMI_CFG(hpd_reg, 8084),
  319. HDMI_CFG(pwr_clk, 8x74),
  320. HDMI_CFG(hpd_clk, 8x74),
  321. .hpd_freq = hpd_clk_freq_8x74,
  322. };
  323. static struct hdmi_platform_config hdmi_tx_8994_config = {
  324. HDMI_CFG(pwr_reg, 8x74),
  325. HDMI_CFG(hpd_reg, none),
  326. HDMI_CFG(pwr_clk, 8x74),
  327. HDMI_CFG(hpd_clk, 8x74),
  328. .hpd_freq = hpd_clk_freq_8x74,
  329. };
  330. static struct hdmi_platform_config hdmi_tx_8996_config = {
  331. HDMI_CFG(pwr_reg, none),
  332. HDMI_CFG(hpd_reg, none),
  333. HDMI_CFG(pwr_clk, 8x74),
  334. HDMI_CFG(hpd_clk, 8x74),
  335. .hpd_freq = hpd_clk_freq_8x74,
  336. };
  337. static const struct {
  338. const char *name;
  339. const bool output;
  340. const int value;
  341. const char *label;
  342. } msm_hdmi_gpio_pdata[] = {
  343. { "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" },
  344. { "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" },
  345. { "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" },
  346. { "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" },
  347. { "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" },
  348. { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
  349. };
  350. static int msm_hdmi_get_gpio(struct device_node *of_node, const char *name)
  351. {
  352. int gpio;
  353. /* try with the gpio names as in the table (downstream bindings) */
  354. gpio = of_get_named_gpio(of_node, name, 0);
  355. if (gpio < 0) {
  356. char name2[32];
  357. /* try with the gpio names as in the upstream bindings */
  358. snprintf(name2, sizeof(name2), "%s-gpios", name);
  359. gpio = of_get_named_gpio(of_node, name2, 0);
  360. if (gpio < 0) {
  361. char name3[32];
  362. /*
  363. * try again after stripping out the "qcom,hdmi-tx"
  364. * prefix. This is mainly to match "hpd-gpios" used
  365. * in the upstream bindings
  366. */
  367. if (sscanf(name2, "qcom,hdmi-tx-%s", name3))
  368. gpio = of_get_named_gpio(of_node, name3, 0);
  369. }
  370. if (gpio < 0) {
  371. DBG("failed to get gpio: %s (%d)", name, gpio);
  372. gpio = -1;
  373. }
  374. }
  375. return gpio;
  376. }
  377. /*
  378. * HDMI audio codec callbacks
  379. */
  380. static int msm_hdmi_audio_hw_params(struct device *dev, void *data,
  381. struct hdmi_codec_daifmt *daifmt,
  382. struct hdmi_codec_params *params)
  383. {
  384. struct hdmi *hdmi = dev_get_drvdata(dev);
  385. unsigned int chan;
  386. unsigned int channel_allocation = 0;
  387. unsigned int rate;
  388. unsigned int level_shift = 0; /* 0dB */
  389. bool down_mix = false;
  390. dev_dbg(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
  391. params->sample_width, params->cea.channels);
  392. switch (params->cea.channels) {
  393. case 2:
  394. /* FR and FL speakers */
  395. channel_allocation = 0;
  396. chan = MSM_HDMI_AUDIO_CHANNEL_2;
  397. break;
  398. case 4:
  399. /* FC, LFE, FR and FL speakers */
  400. channel_allocation = 0x3;
  401. chan = MSM_HDMI_AUDIO_CHANNEL_4;
  402. break;
  403. case 6:
  404. /* RR, RL, FC, LFE, FR and FL speakers */
  405. channel_allocation = 0x0B;
  406. chan = MSM_HDMI_AUDIO_CHANNEL_6;
  407. break;
  408. case 8:
  409. /* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
  410. channel_allocation = 0x1F;
  411. chan = MSM_HDMI_AUDIO_CHANNEL_8;
  412. break;
  413. default:
  414. return -EINVAL;
  415. }
  416. switch (params->sample_rate) {
  417. case 32000:
  418. rate = HDMI_SAMPLE_RATE_32KHZ;
  419. break;
  420. case 44100:
  421. rate = HDMI_SAMPLE_RATE_44_1KHZ;
  422. break;
  423. case 48000:
  424. rate = HDMI_SAMPLE_RATE_48KHZ;
  425. break;
  426. case 88200:
  427. rate = HDMI_SAMPLE_RATE_88_2KHZ;
  428. break;
  429. case 96000:
  430. rate = HDMI_SAMPLE_RATE_96KHZ;
  431. break;
  432. case 176400:
  433. rate = HDMI_SAMPLE_RATE_176_4KHZ;
  434. break;
  435. case 192000:
  436. rate = HDMI_SAMPLE_RATE_192KHZ;
  437. break;
  438. default:
  439. dev_err(dev, "rate[%d] not supported!\n",
  440. params->sample_rate);
  441. return -EINVAL;
  442. }
  443. msm_hdmi_audio_set_sample_rate(hdmi, rate);
  444. msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
  445. level_shift, down_mix);
  446. return 0;
  447. }
  448. static void msm_hdmi_audio_shutdown(struct device *dev, void *data)
  449. {
  450. struct hdmi *hdmi = dev_get_drvdata(dev);
  451. msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
  452. }
  453. static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
  454. .hw_params = msm_hdmi_audio_hw_params,
  455. .audio_shutdown = msm_hdmi_audio_shutdown,
  456. };
  457. static struct hdmi_codec_pdata codec_data = {
  458. .ops = &msm_hdmi_audio_codec_ops,
  459. .max_i2s_channels = 8,
  460. .i2s = 1,
  461. };
  462. static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
  463. {
  464. hdmi->audio_pdev = platform_device_register_data(dev,
  465. HDMI_CODEC_DRV_NAME,
  466. PLATFORM_DEVID_AUTO,
  467. &codec_data,
  468. sizeof(codec_data));
  469. return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
  470. }
  471. static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
  472. {
  473. struct drm_device *drm = dev_get_drvdata(master);
  474. struct msm_drm_private *priv = drm->dev_private;
  475. static struct hdmi_platform_config *hdmi_cfg;
  476. struct hdmi *hdmi;
  477. struct device_node *of_node = dev->of_node;
  478. int i, err;
  479. hdmi_cfg = (struct hdmi_platform_config *)
  480. of_device_get_match_data(dev);
  481. if (!hdmi_cfg) {
  482. dev_err(dev, "unknown hdmi_cfg: %s\n", of_node->name);
  483. return -ENXIO;
  484. }
  485. hdmi_cfg->mmio_name = "core_physical";
  486. hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
  487. for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
  488. hdmi_cfg->gpios[i].num = msm_hdmi_get_gpio(of_node,
  489. msm_hdmi_gpio_pdata[i].name);
  490. hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
  491. hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
  492. hdmi_cfg->gpios[i].label = msm_hdmi_gpio_pdata[i].label;
  493. }
  494. dev->platform_data = hdmi_cfg;
  495. hdmi = msm_hdmi_init(to_platform_device(dev));
  496. if (IS_ERR(hdmi))
  497. return PTR_ERR(hdmi);
  498. priv->hdmi = hdmi;
  499. err = msm_hdmi_register_audio_driver(hdmi, dev);
  500. if (err) {
  501. DRM_ERROR("Failed to attach an audio codec %d\n", err);
  502. hdmi->audio_pdev = NULL;
  503. }
  504. return 0;
  505. }
  506. static void msm_hdmi_unbind(struct device *dev, struct device *master,
  507. void *data)
  508. {
  509. struct drm_device *drm = dev_get_drvdata(master);
  510. struct msm_drm_private *priv = drm->dev_private;
  511. if (priv->hdmi) {
  512. if (priv->hdmi->audio_pdev)
  513. platform_device_unregister(priv->hdmi->audio_pdev);
  514. msm_hdmi_destroy(priv->hdmi);
  515. priv->hdmi = NULL;
  516. }
  517. }
  518. static const struct component_ops msm_hdmi_ops = {
  519. .bind = msm_hdmi_bind,
  520. .unbind = msm_hdmi_unbind,
  521. };
  522. static int msm_hdmi_dev_probe(struct platform_device *pdev)
  523. {
  524. return component_add(&pdev->dev, &msm_hdmi_ops);
  525. }
  526. static int msm_hdmi_dev_remove(struct platform_device *pdev)
  527. {
  528. component_del(&pdev->dev, &msm_hdmi_ops);
  529. return 0;
  530. }
  531. static const struct of_device_id msm_hdmi_dt_match[] = {
  532. { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
  533. { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
  534. { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
  535. { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
  536. { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
  537. { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
  538. {}
  539. };
  540. static struct platform_driver msm_hdmi_driver = {
  541. .probe = msm_hdmi_dev_probe,
  542. .remove = msm_hdmi_dev_remove,
  543. .driver = {
  544. .name = "hdmi_msm",
  545. .of_match_table = msm_hdmi_dt_match,
  546. },
  547. };
  548. void __init msm_hdmi_register(void)
  549. {
  550. msm_hdmi_phy_driver_register();
  551. platform_driver_register(&msm_hdmi_driver);
  552. }
  553. void __exit msm_hdmi_unregister(void)
  554. {
  555. platform_driver_unregister(&msm_hdmi_driver);
  556. msm_hdmi_phy_driver_unregister();
  557. }