hdmi.c 16 KB

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