hdmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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_kcalloc(&pdev->dev,
  132. config->hpd_reg_cnt,
  133. sizeof(hdmi->hpd_regs[0]),
  134. GFP_KERNEL);
  135. if (!hdmi->hpd_regs) {
  136. ret = -ENOMEM;
  137. goto fail;
  138. }
  139. for (i = 0; i < config->hpd_reg_cnt; i++) {
  140. struct regulator *reg;
  141. reg = devm_regulator_get(&pdev->dev,
  142. config->hpd_reg_names[i]);
  143. if (IS_ERR(reg)) {
  144. ret = PTR_ERR(reg);
  145. dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
  146. config->hpd_reg_names[i], ret);
  147. goto fail;
  148. }
  149. hdmi->hpd_regs[i] = reg;
  150. }
  151. hdmi->pwr_regs = devm_kcalloc(&pdev->dev,
  152. config->pwr_reg_cnt,
  153. sizeof(hdmi->pwr_regs[0]),
  154. GFP_KERNEL);
  155. if (!hdmi->pwr_regs) {
  156. ret = -ENOMEM;
  157. goto fail;
  158. }
  159. for (i = 0; i < config->pwr_reg_cnt; i++) {
  160. struct regulator *reg;
  161. reg = devm_regulator_get(&pdev->dev,
  162. config->pwr_reg_names[i]);
  163. if (IS_ERR(reg)) {
  164. ret = PTR_ERR(reg);
  165. dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
  166. config->pwr_reg_names[i], ret);
  167. goto fail;
  168. }
  169. hdmi->pwr_regs[i] = reg;
  170. }
  171. hdmi->hpd_clks = devm_kcalloc(&pdev->dev,
  172. config->hpd_clk_cnt,
  173. sizeof(hdmi->hpd_clks[0]),
  174. GFP_KERNEL);
  175. if (!hdmi->hpd_clks) {
  176. ret = -ENOMEM;
  177. goto fail;
  178. }
  179. for (i = 0; i < config->hpd_clk_cnt; i++) {
  180. struct clk *clk;
  181. clk = msm_clk_get(pdev, config->hpd_clk_names[i]);
  182. if (IS_ERR(clk)) {
  183. ret = PTR_ERR(clk);
  184. dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
  185. config->hpd_clk_names[i], ret);
  186. goto fail;
  187. }
  188. hdmi->hpd_clks[i] = clk;
  189. }
  190. hdmi->pwr_clks = devm_kcalloc(&pdev->dev,
  191. config->pwr_clk_cnt,
  192. sizeof(hdmi->pwr_clks[0]),
  193. GFP_KERNEL);
  194. if (!hdmi->pwr_clks) {
  195. ret = -ENOMEM;
  196. goto fail;
  197. }
  198. for (i = 0; i < config->pwr_clk_cnt; i++) {
  199. struct clk *clk;
  200. clk = msm_clk_get(pdev, config->pwr_clk_names[i]);
  201. if (IS_ERR(clk)) {
  202. ret = PTR_ERR(clk);
  203. dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
  204. config->pwr_clk_names[i], ret);
  205. goto fail;
  206. }
  207. hdmi->pwr_clks[i] = clk;
  208. }
  209. pm_runtime_enable(&pdev->dev);
  210. hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
  211. hdmi->i2c = msm_hdmi_i2c_init(hdmi);
  212. if (IS_ERR(hdmi->i2c)) {
  213. ret = PTR_ERR(hdmi->i2c);
  214. dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
  215. hdmi->i2c = NULL;
  216. goto fail;
  217. }
  218. ret = msm_hdmi_get_phy(hdmi);
  219. if (ret) {
  220. dev_err(&pdev->dev, "failed to get phy\n");
  221. goto fail;
  222. }
  223. hdmi->hdcp_ctrl = msm_hdmi_hdcp_init(hdmi);
  224. if (IS_ERR(hdmi->hdcp_ctrl)) {
  225. dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
  226. hdmi->hdcp_ctrl = NULL;
  227. }
  228. return hdmi;
  229. fail:
  230. if (hdmi)
  231. msm_hdmi_destroy(hdmi);
  232. return ERR_PTR(ret);
  233. }
  234. /* Second part of initialization, the drm/kms level modeset_init,
  235. * constructs/initializes mode objects, etc, is called from master
  236. * driver (not hdmi sub-device's probe/bind!)
  237. *
  238. * Any resource (regulator/clk/etc) which could be missing at boot
  239. * should be handled in msm_hdmi_init() so that failure happens from
  240. * hdmi sub-device's probe.
  241. */
  242. int msm_hdmi_modeset_init(struct hdmi *hdmi,
  243. struct drm_device *dev, struct drm_encoder *encoder)
  244. {
  245. struct msm_drm_private *priv = dev->dev_private;
  246. struct platform_device *pdev = hdmi->pdev;
  247. int ret;
  248. hdmi->dev = dev;
  249. hdmi->encoder = encoder;
  250. hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
  251. hdmi->bridge = msm_hdmi_bridge_init(hdmi);
  252. if (IS_ERR(hdmi->bridge)) {
  253. ret = PTR_ERR(hdmi->bridge);
  254. dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
  255. hdmi->bridge = NULL;
  256. goto fail;
  257. }
  258. hdmi->connector = msm_hdmi_connector_init(hdmi);
  259. if (IS_ERR(hdmi->connector)) {
  260. ret = PTR_ERR(hdmi->connector);
  261. dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
  262. hdmi->connector = NULL;
  263. goto fail;
  264. }
  265. hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  266. if (hdmi->irq < 0) {
  267. ret = hdmi->irq;
  268. dev_err(dev->dev, "failed to get irq: %d\n", ret);
  269. goto fail;
  270. }
  271. ret = devm_request_irq(&pdev->dev, hdmi->irq,
  272. msm_hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  273. "hdmi_isr", hdmi);
  274. if (ret < 0) {
  275. dev_err(dev->dev, "failed to request IRQ%u: %d\n",
  276. hdmi->irq, ret);
  277. goto fail;
  278. }
  279. ret = msm_hdmi_hpd_enable(hdmi->connector);
  280. if (ret < 0) {
  281. DRM_DEV_ERROR(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
  282. goto fail;
  283. }
  284. encoder->bridge = hdmi->bridge;
  285. priv->bridges[priv->num_bridges++] = hdmi->bridge;
  286. priv->connectors[priv->num_connectors++] = hdmi->connector;
  287. platform_set_drvdata(pdev, hdmi);
  288. return 0;
  289. fail:
  290. /* bridge is normally destroyed by drm: */
  291. if (hdmi->bridge) {
  292. msm_hdmi_bridge_destroy(hdmi->bridge);
  293. hdmi->bridge = NULL;
  294. }
  295. if (hdmi->connector) {
  296. hdmi->connector->funcs->destroy(hdmi->connector);
  297. hdmi->connector = NULL;
  298. }
  299. return ret;
  300. }
  301. /*
  302. * The hdmi device:
  303. */
  304. #define HDMI_CFG(item, entry) \
  305. .item ## _names = item ##_names_ ## entry, \
  306. .item ## _cnt = ARRAY_SIZE(item ## _names_ ## entry)
  307. static const char *pwr_reg_names_none[] = {};
  308. static const char *hpd_reg_names_none[] = {};
  309. static struct hdmi_platform_config hdmi_tx_8660_config;
  310. static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
  311. static const char *hpd_clk_names_8960[] = {"core", "master_iface", "slave_iface"};
  312. static struct hdmi_platform_config hdmi_tx_8960_config = {
  313. HDMI_CFG(hpd_reg, 8960),
  314. HDMI_CFG(hpd_clk, 8960),
  315. };
  316. static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
  317. static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
  318. static const char *pwr_clk_names_8x74[] = {"extp", "alt_iface"};
  319. static const char *hpd_clk_names_8x74[] = {"iface", "core", "mdp_core"};
  320. static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
  321. static struct hdmi_platform_config hdmi_tx_8974_config = {
  322. HDMI_CFG(pwr_reg, 8x74),
  323. HDMI_CFG(hpd_reg, 8x74),
  324. HDMI_CFG(pwr_clk, 8x74),
  325. HDMI_CFG(hpd_clk, 8x74),
  326. .hpd_freq = hpd_clk_freq_8x74,
  327. };
  328. static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
  329. static struct hdmi_platform_config hdmi_tx_8084_config = {
  330. HDMI_CFG(pwr_reg, 8x74),
  331. HDMI_CFG(hpd_reg, 8084),
  332. HDMI_CFG(pwr_clk, 8x74),
  333. HDMI_CFG(hpd_clk, 8x74),
  334. .hpd_freq = hpd_clk_freq_8x74,
  335. };
  336. static struct hdmi_platform_config hdmi_tx_8994_config = {
  337. HDMI_CFG(pwr_reg, 8x74),
  338. HDMI_CFG(hpd_reg, none),
  339. HDMI_CFG(pwr_clk, 8x74),
  340. HDMI_CFG(hpd_clk, 8x74),
  341. .hpd_freq = hpd_clk_freq_8x74,
  342. };
  343. static struct hdmi_platform_config hdmi_tx_8996_config = {
  344. HDMI_CFG(pwr_reg, none),
  345. HDMI_CFG(hpd_reg, none),
  346. HDMI_CFG(pwr_clk, 8x74),
  347. HDMI_CFG(hpd_clk, 8x74),
  348. .hpd_freq = hpd_clk_freq_8x74,
  349. };
  350. static const struct {
  351. const char *name;
  352. const bool output;
  353. const int value;
  354. const char *label;
  355. } msm_hdmi_gpio_pdata[] = {
  356. { "qcom,hdmi-tx-ddc-clk", true, 1, "HDMI_DDC_CLK" },
  357. { "qcom,hdmi-tx-ddc-data", true, 1, "HDMI_DDC_DATA" },
  358. { "qcom,hdmi-tx-hpd", false, 1, "HDMI_HPD" },
  359. { "qcom,hdmi-tx-mux-en", true, 1, "HDMI_MUX_EN" },
  360. { "qcom,hdmi-tx-mux-sel", true, 0, "HDMI_MUX_SEL" },
  361. { "qcom,hdmi-tx-mux-lpm", true, 1, "HDMI_MUX_LPM" },
  362. };
  363. static int msm_hdmi_get_gpio(struct device_node *of_node, const char *name)
  364. {
  365. int gpio;
  366. /* try with the gpio names as in the table (downstream bindings) */
  367. gpio = of_get_named_gpio(of_node, name, 0);
  368. if (gpio < 0) {
  369. char name2[32];
  370. /* try with the gpio names as in the upstream bindings */
  371. snprintf(name2, sizeof(name2), "%s-gpios", name);
  372. gpio = of_get_named_gpio(of_node, name2, 0);
  373. if (gpio < 0) {
  374. char name3[32];
  375. /*
  376. * try again after stripping out the "qcom,hdmi-tx"
  377. * prefix. This is mainly to match "hpd-gpios" used
  378. * in the upstream bindings
  379. */
  380. if (sscanf(name2, "qcom,hdmi-tx-%s", name3))
  381. gpio = of_get_named_gpio(of_node, name3, 0);
  382. }
  383. if (gpio < 0) {
  384. DBG("failed to get gpio: %s (%d)", name, gpio);
  385. gpio = -1;
  386. }
  387. }
  388. return gpio;
  389. }
  390. /*
  391. * HDMI audio codec callbacks
  392. */
  393. static int msm_hdmi_audio_hw_params(struct device *dev, void *data,
  394. struct hdmi_codec_daifmt *daifmt,
  395. struct hdmi_codec_params *params)
  396. {
  397. struct hdmi *hdmi = dev_get_drvdata(dev);
  398. unsigned int chan;
  399. unsigned int channel_allocation = 0;
  400. unsigned int rate;
  401. unsigned int level_shift = 0; /* 0dB */
  402. bool down_mix = false;
  403. dev_dbg(dev, "%u Hz, %d bit, %d channels\n", params->sample_rate,
  404. params->sample_width, params->cea.channels);
  405. switch (params->cea.channels) {
  406. case 2:
  407. /* FR and FL speakers */
  408. channel_allocation = 0;
  409. chan = MSM_HDMI_AUDIO_CHANNEL_2;
  410. break;
  411. case 4:
  412. /* FC, LFE, FR and FL speakers */
  413. channel_allocation = 0x3;
  414. chan = MSM_HDMI_AUDIO_CHANNEL_4;
  415. break;
  416. case 6:
  417. /* RR, RL, FC, LFE, FR and FL speakers */
  418. channel_allocation = 0x0B;
  419. chan = MSM_HDMI_AUDIO_CHANNEL_6;
  420. break;
  421. case 8:
  422. /* FRC, FLC, RR, RL, FC, LFE, FR and FL speakers */
  423. channel_allocation = 0x1F;
  424. chan = MSM_HDMI_AUDIO_CHANNEL_8;
  425. break;
  426. default:
  427. return -EINVAL;
  428. }
  429. switch (params->sample_rate) {
  430. case 32000:
  431. rate = HDMI_SAMPLE_RATE_32KHZ;
  432. break;
  433. case 44100:
  434. rate = HDMI_SAMPLE_RATE_44_1KHZ;
  435. break;
  436. case 48000:
  437. rate = HDMI_SAMPLE_RATE_48KHZ;
  438. break;
  439. case 88200:
  440. rate = HDMI_SAMPLE_RATE_88_2KHZ;
  441. break;
  442. case 96000:
  443. rate = HDMI_SAMPLE_RATE_96KHZ;
  444. break;
  445. case 176400:
  446. rate = HDMI_SAMPLE_RATE_176_4KHZ;
  447. break;
  448. case 192000:
  449. rate = HDMI_SAMPLE_RATE_192KHZ;
  450. break;
  451. default:
  452. dev_err(dev, "rate[%d] not supported!\n",
  453. params->sample_rate);
  454. return -EINVAL;
  455. }
  456. msm_hdmi_audio_set_sample_rate(hdmi, rate);
  457. msm_hdmi_audio_info_setup(hdmi, 1, chan, channel_allocation,
  458. level_shift, down_mix);
  459. return 0;
  460. }
  461. static void msm_hdmi_audio_shutdown(struct device *dev, void *data)
  462. {
  463. struct hdmi *hdmi = dev_get_drvdata(dev);
  464. msm_hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
  465. }
  466. static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
  467. .hw_params = msm_hdmi_audio_hw_params,
  468. .audio_shutdown = msm_hdmi_audio_shutdown,
  469. };
  470. static struct hdmi_codec_pdata codec_data = {
  471. .ops = &msm_hdmi_audio_codec_ops,
  472. .max_i2s_channels = 8,
  473. .i2s = 1,
  474. };
  475. static int msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
  476. {
  477. hdmi->audio_pdev = platform_device_register_data(dev,
  478. HDMI_CODEC_DRV_NAME,
  479. PLATFORM_DEVID_AUTO,
  480. &codec_data,
  481. sizeof(codec_data));
  482. return PTR_ERR_OR_ZERO(hdmi->audio_pdev);
  483. }
  484. static int msm_hdmi_bind(struct device *dev, struct device *master, void *data)
  485. {
  486. struct drm_device *drm = dev_get_drvdata(master);
  487. struct msm_drm_private *priv = drm->dev_private;
  488. struct hdmi_platform_config *hdmi_cfg;
  489. struct hdmi *hdmi;
  490. struct device_node *of_node = dev->of_node;
  491. int i, err;
  492. hdmi_cfg = (struct hdmi_platform_config *)
  493. of_device_get_match_data(dev);
  494. if (!hdmi_cfg) {
  495. dev_err(dev, "unknown hdmi_cfg: %s\n", of_node->name);
  496. return -ENXIO;
  497. }
  498. hdmi_cfg->mmio_name = "core_physical";
  499. hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
  500. for (i = 0; i < HDMI_MAX_NUM_GPIO; i++) {
  501. hdmi_cfg->gpios[i].num = msm_hdmi_get_gpio(of_node,
  502. msm_hdmi_gpio_pdata[i].name);
  503. hdmi_cfg->gpios[i].output = msm_hdmi_gpio_pdata[i].output;
  504. hdmi_cfg->gpios[i].value = msm_hdmi_gpio_pdata[i].value;
  505. hdmi_cfg->gpios[i].label = msm_hdmi_gpio_pdata[i].label;
  506. }
  507. dev->platform_data = hdmi_cfg;
  508. hdmi = msm_hdmi_init(to_platform_device(dev));
  509. if (IS_ERR(hdmi))
  510. return PTR_ERR(hdmi);
  511. priv->hdmi = hdmi;
  512. err = msm_hdmi_register_audio_driver(hdmi, dev);
  513. if (err) {
  514. DRM_ERROR("Failed to attach an audio codec %d\n", err);
  515. hdmi->audio_pdev = NULL;
  516. }
  517. return 0;
  518. }
  519. static void msm_hdmi_unbind(struct device *dev, struct device *master,
  520. void *data)
  521. {
  522. struct drm_device *drm = dev_get_drvdata(master);
  523. struct msm_drm_private *priv = drm->dev_private;
  524. if (priv->hdmi) {
  525. if (priv->hdmi->audio_pdev)
  526. platform_device_unregister(priv->hdmi->audio_pdev);
  527. msm_hdmi_destroy(priv->hdmi);
  528. priv->hdmi = NULL;
  529. }
  530. }
  531. static const struct component_ops msm_hdmi_ops = {
  532. .bind = msm_hdmi_bind,
  533. .unbind = msm_hdmi_unbind,
  534. };
  535. static int msm_hdmi_dev_probe(struct platform_device *pdev)
  536. {
  537. return component_add(&pdev->dev, &msm_hdmi_ops);
  538. }
  539. static int msm_hdmi_dev_remove(struct platform_device *pdev)
  540. {
  541. component_del(&pdev->dev, &msm_hdmi_ops);
  542. return 0;
  543. }
  544. static const struct of_device_id msm_hdmi_dt_match[] = {
  545. { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
  546. { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
  547. { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
  548. { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
  549. { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
  550. { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
  551. {}
  552. };
  553. static struct platform_driver msm_hdmi_driver = {
  554. .probe = msm_hdmi_dev_probe,
  555. .remove = msm_hdmi_dev_remove,
  556. .driver = {
  557. .name = "hdmi_msm",
  558. .of_match_table = msm_hdmi_dt_match,
  559. },
  560. };
  561. void __init msm_hdmi_register(void)
  562. {
  563. msm_hdmi_phy_driver_register();
  564. platform_driver_register(&msm_hdmi_driver);
  565. }
  566. void __exit msm_hdmi_unregister(void)
  567. {
  568. platform_driver_unregister(&msm_hdmi_driver);
  569. msm_hdmi_phy_driver_unregister();
  570. }