]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/msm/hdmi/hdmi.c
Merge branch 'tracking-qcomlt-power-regulator' into integration-linux-qcomlt
[karo-tx-linux.git] / drivers / gpu / drm / msm / hdmi / hdmi.c
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
19 #include <linux/of_irq.h>
20 #include <sound/hdmi-codec.h>
21 #include <sound/msm_hdmi_audio.h>
22 #include "hdmi.h"
23
24 void hdmi_set_mode(struct hdmi *hdmi, bool power_on)
25 {
26         uint32_t ctrl = 0;
27         unsigned long flags;
28
29         spin_lock_irqsave(&hdmi->reg_lock, flags);
30         if (power_on) {
31                 ctrl |= HDMI_CTRL_ENABLE;
32                 if (!hdmi->hdmi_mode) {
33                         ctrl |= HDMI_CTRL_HDMI;
34                         hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
35                         ctrl &= ~HDMI_CTRL_HDMI;
36                 } else {
37                         ctrl |= HDMI_CTRL_HDMI;
38                 }
39         } else {
40                 ctrl = HDMI_CTRL_HDMI;
41         }
42
43         hdmi_write(hdmi, REG_HDMI_CTRL, ctrl);
44         spin_unlock_irqrestore(&hdmi->reg_lock, flags);
45         DBG("HDMI Core: %s, HDMI_CTRL=0x%08x",
46                         power_on ? "Enable" : "Disable", ctrl);
47 }
48
49 static irqreturn_t hdmi_irq(int irq, void *dev_id)
50 {
51         struct hdmi *hdmi = dev_id;
52
53         /* Process HPD: */
54         hdmi_connector_irq(hdmi->connector);
55
56         /* Process DDC: */
57         hdmi_i2c_irq(hdmi->i2c);
58
59         /* Process HDCP: */
60         if (hdmi->hdcp_ctrl)
61                 hdmi_hdcp_irq(hdmi->hdcp_ctrl);
62
63         /* TODO audio.. */
64
65         return IRQ_HANDLED;
66 }
67
68 static void hdmi_destroy(struct hdmi *hdmi)
69 {
70         struct hdmi_phy *phy = hdmi->phy;
71
72         /*
73          * at this point, hpd has been disabled,
74          * after flush workq, it's safe to deinit hdcp
75          */
76         if (hdmi->workq) {
77                 flush_workqueue(hdmi->workq);
78                 destroy_workqueue(hdmi->workq);
79         }
80         hdmi_hdcp_destroy(hdmi);
81         if (phy)
82                 phy->funcs->destroy(phy);
83
84         if (hdmi->i2c)
85                 hdmi_i2c_destroy(hdmi->i2c);
86
87         platform_set_drvdata(hdmi->pdev, NULL);
88 }
89
90 /* construct hdmi at bind/probe time, grab all the resources.  If
91  * we are to EPROBE_DEFER we want to do it here, rather than later
92  * at modeset_init() time
93  */
94 static struct hdmi *hdmi_init(struct platform_device *pdev)
95 {
96         struct hdmi_platform_config *config = pdev->dev.platform_data;
97         struct hdmi *hdmi = NULL;
98         struct resource *res;
99         int i, ret;
100
101         hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
102         if (!hdmi) {
103                 ret = -ENOMEM;
104                 goto fail;
105         }
106
107         hdmi->pdev = pdev;
108         hdmi->config = config;
109         spin_lock_init(&hdmi->reg_lock);
110
111         /* not sure about which phy maps to which msm.. probably I miss some */
112         if (config->phy_init) {
113                 hdmi->phy = config->phy_init(hdmi);
114
115                 if (IS_ERR(hdmi->phy)) {
116                         ret = PTR_ERR(hdmi->phy);
117                         dev_err(&pdev->dev, "failed to load phy: %d\n", ret);
118                         hdmi->phy = NULL;
119                         goto fail;
120                 }
121         }
122
123         hdmi->mmio = msm_ioremap(pdev, config->mmio_name, "HDMI");
124         if (IS_ERR(hdmi->mmio)) {
125                 ret = PTR_ERR(hdmi->mmio);
126                 goto fail;
127         }
128
129         /* HDCP needs physical address of hdmi register */
130         res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
131                 config->mmio_name);
132         hdmi->mmio_phy_addr = res->start;
133
134         hdmi->qfprom_mmio = msm_ioremap(pdev,
135                 config->qfprom_mmio_name, "HDMI_QFPROM");
136         if (IS_ERR(hdmi->qfprom_mmio)) {
137                 dev_info(&pdev->dev, "can't find qfprom resource\n");
138                 hdmi->qfprom_mmio = NULL;
139         }
140
141         hdmi->hpd_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_regs[0]) *
142                         config->hpd_reg_cnt, GFP_KERNEL);
143         if (!hdmi->hpd_regs) {
144                 ret = -ENOMEM;
145                 goto fail;
146         }
147         for (i = 0; i < config->hpd_reg_cnt; i++) {
148                 struct regulator *reg;
149
150                 reg = devm_regulator_get(&pdev->dev,
151                                 config->hpd_reg_names[i]);
152                 if (IS_ERR(reg)) {
153                         ret = PTR_ERR(reg);
154                         dev_err(&pdev->dev, "failed to get hpd regulator: %s (%d)\n",
155                                         config->hpd_reg_names[i], ret);
156                         goto fail;
157                 }
158
159                 hdmi->hpd_regs[i] = reg;
160         }
161
162         hdmi->pwr_regs = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_regs[0]) *
163                         config->pwr_reg_cnt, GFP_KERNEL);
164         if (!hdmi->pwr_regs) {
165                 ret = -ENOMEM;
166                 goto fail;
167         }
168         for (i = 0; i < config->pwr_reg_cnt; i++) {
169                 struct regulator *reg;
170
171                 reg = devm_regulator_get(&pdev->dev,
172                                 config->pwr_reg_names[i]);
173                 if (IS_ERR(reg)) {
174                         ret = PTR_ERR(reg);
175                         dev_err(&pdev->dev, "failed to get pwr regulator: %s (%d)\n",
176                                         config->pwr_reg_names[i], ret);
177                         goto fail;
178                 }
179
180                 hdmi->pwr_regs[i] = reg;
181         }
182
183         hdmi->hpd_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->hpd_clks[0]) *
184                         config->hpd_clk_cnt, GFP_KERNEL);
185         if (!hdmi->hpd_clks) {
186                 ret = -ENOMEM;
187                 goto fail;
188         }
189         for (i = 0; i < config->hpd_clk_cnt; i++) {
190                 struct clk *clk;
191
192                 clk = devm_clk_get(&pdev->dev, config->hpd_clk_names[i]);
193                 if (IS_ERR(clk)) {
194                         ret = PTR_ERR(clk);
195                         dev_err(&pdev->dev, "failed to get hpd clk: %s (%d)\n",
196                                         config->hpd_clk_names[i], ret);
197                         goto fail;
198                 }
199
200                 hdmi->hpd_clks[i] = clk;
201         }
202
203         hdmi->pwr_clks = devm_kzalloc(&pdev->dev, sizeof(hdmi->pwr_clks[0]) *
204                         config->pwr_clk_cnt, GFP_KERNEL);
205         if (!hdmi->pwr_clks) {
206                 ret = -ENOMEM;
207                 goto fail;
208         }
209         for (i = 0; i < config->pwr_clk_cnt; i++) {
210                 struct clk *clk;
211
212                 clk = devm_clk_get(&pdev->dev, config->pwr_clk_names[i]);
213                 if (IS_ERR(clk)) {
214                         ret = PTR_ERR(clk);
215                         dev_err(&pdev->dev, "failed to get pwr clk: %s (%d)\n",
216                                         config->pwr_clk_names[i], ret);
217                         goto fail;
218                 }
219
220                 hdmi->pwr_clks[i] = clk;
221         }
222
223         hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
224
225         hdmi->i2c = hdmi_i2c_init(hdmi);
226         if (IS_ERR(hdmi->i2c)) {
227                 ret = PTR_ERR(hdmi->i2c);
228                 dev_err(&pdev->dev, "failed to get i2c: %d\n", ret);
229                 hdmi->i2c = NULL;
230                 goto fail;
231         }
232
233         hdmi->hdcp_ctrl = hdmi_hdcp_init(hdmi);
234         if (IS_ERR(hdmi->hdcp_ctrl)) {
235                 dev_warn(&pdev->dev, "failed to init hdcp: disabled\n");
236                 hdmi->hdcp_ctrl = NULL;
237         }
238
239         return hdmi;
240
241 fail:
242         if (hdmi)
243                 hdmi_destroy(hdmi);
244
245         return ERR_PTR(ret);
246 }
247
248 /* Second part of initialization, the drm/kms level modeset_init,
249  * constructs/initializes mode objects, etc, is called from master
250  * driver (not hdmi sub-device's probe/bind!)
251  *
252  * Any resource (regulator/clk/etc) which could be missing at boot
253  * should be handled in hdmi_init() so that failure happens from
254  * hdmi sub-device's probe.
255  */
256 int hdmi_modeset_init(struct hdmi *hdmi,
257                 struct drm_device *dev, struct drm_encoder *encoder)
258 {
259         struct msm_drm_private *priv = dev->dev_private;
260         struct platform_device *pdev = hdmi->pdev;
261         int ret;
262
263         hdmi->dev = dev;
264         hdmi->encoder = encoder;
265
266         hdmi_audio_infoframe_init(&hdmi->audio.infoframe);
267
268         hdmi->bridge = hdmi_bridge_init(hdmi);
269         if (IS_ERR(hdmi->bridge)) {
270                 ret = PTR_ERR(hdmi->bridge);
271                 dev_err(dev->dev, "failed to create HDMI bridge: %d\n", ret);
272                 hdmi->bridge = NULL;
273                 goto fail;
274         }
275
276         hdmi->connector = hdmi_connector_init(hdmi);
277         if (IS_ERR(hdmi->connector)) {
278                 ret = PTR_ERR(hdmi->connector);
279                 dev_err(dev->dev, "failed to create HDMI connector: %d\n", ret);
280                 hdmi->connector = NULL;
281                 goto fail;
282         }
283
284         hdmi->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
285         if (hdmi->irq < 0) {
286                 ret = hdmi->irq;
287                 dev_err(dev->dev, "failed to get irq: %d\n", ret);
288                 goto fail;
289         }
290
291         ret = devm_request_irq(&pdev->dev, hdmi->irq,
292                         hdmi_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
293                         "hdmi_isr", hdmi);
294         if (ret < 0) {
295                 dev_err(dev->dev, "failed to request IRQ%u: %d\n",
296                                 hdmi->irq, ret);
297                 goto fail;
298         }
299
300         encoder->bridge = hdmi->bridge;
301
302         priv->bridges[priv->num_bridges++]       = hdmi->bridge;
303         priv->connectors[priv->num_connectors++] = hdmi->connector;
304
305         platform_set_drvdata(pdev, hdmi);
306
307         return 0;
308
309 fail:
310         /* bridge is normally destroyed by drm: */
311         if (hdmi->bridge) {
312                 hdmi_bridge_destroy(hdmi->bridge);
313                 hdmi->bridge = NULL;
314         }
315         if (hdmi->connector) {
316                 hdmi->connector->funcs->destroy(hdmi->connector);
317                 hdmi->connector = NULL;
318         }
319
320         return ret;
321 }
322
323 /*
324  * The hdmi device:
325  */
326
327 #include <linux/of_gpio.h>
328
329 #define HDMI_CFG(item, entry) \
330         .item ## _names = item ##_names_ ## entry, \
331         .item ## _cnt   = ARRAY_SIZE(item ## _names_ ## entry)
332
333 static const char *pwr_reg_names_none[] = {};
334 static const char *hpd_reg_names_none[] = {};
335
336 static struct hdmi_platform_config hdmi_tx_8660_config = {
337                 .phy_init = hdmi_phy_8x60_init,
338 };
339
340 static const char *hpd_reg_names_8960[] = {"core-vdda", "hdmi-mux"};
341 static const char *hpd_clk_names_8960[] = {"core_clk", "master_iface_clk", "slave_iface_clk"};
342
343 static struct hdmi_platform_config hdmi_tx_8960_config = {
344                 .phy_init = hdmi_phy_8960_init,
345                 HDMI_CFG(hpd_reg, 8960),
346                 HDMI_CFG(hpd_clk, 8960),
347 };
348
349 static const char *pwr_reg_names_8x74[] = {"core-vdda", "core-vcc"};
350 static const char *hpd_reg_names_8x74[] = {"hpd-gdsc", "hpd-5v"};
351 static const char *pwr_clk_names_8x74[] = {"extp_clk", "alt_iface_clk"};
352 static const char *hpd_clk_names_8x74[] = {"iface_clk", "core_clk", "mdp_core_clk"};
353 static unsigned long hpd_clk_freq_8x74[] = {0, 19200000, 0};
354
355 static struct hdmi_platform_config hdmi_tx_8974_config = {
356                 .phy_init = hdmi_phy_8x74_init,
357                 HDMI_CFG(pwr_reg, 8x74),
358                 HDMI_CFG(hpd_reg, 8x74),
359                 HDMI_CFG(pwr_clk, 8x74),
360                 HDMI_CFG(hpd_clk, 8x74),
361                 .hpd_freq      = hpd_clk_freq_8x74,
362 };
363
364 static const char *hpd_reg_names_8084[] = {"hpd-gdsc", "hpd-5v", "hpd-5v-en"};
365
366 static struct hdmi_platform_config hdmi_tx_8084_config = {
367                 .phy_init = hdmi_phy_8x74_init,
368                 HDMI_CFG(pwr_reg, 8x74),
369                 HDMI_CFG(hpd_reg, 8084),
370                 HDMI_CFG(pwr_clk, 8x74),
371                 HDMI_CFG(hpd_clk, 8x74),
372                 .hpd_freq      = hpd_clk_freq_8x74,
373 };
374
375 static struct hdmi_platform_config hdmi_tx_8994_config = {
376                 .phy_init = NULL, /* nothing to do for this HDMI PHY 20nm */
377                 HDMI_CFG(pwr_reg, 8x74),
378                 HDMI_CFG(hpd_reg, none),
379                 HDMI_CFG(pwr_clk, 8x74),
380                 HDMI_CFG(hpd_clk, 8x74),
381                 .hpd_freq      = hpd_clk_freq_8x74,
382 };
383
384 static struct hdmi_platform_config hdmi_tx_8996_config = {
385                 .phy_init = NULL,
386                 HDMI_CFG(pwr_reg, none),
387                 HDMI_CFG(hpd_reg, none),
388                 HDMI_CFG(pwr_clk, 8x74),
389                 HDMI_CFG(hpd_clk, 8x74),
390                 .hpd_freq      = hpd_clk_freq_8x74,
391 };
392
393 static const struct of_device_id dt_match[] = {
394         { .compatible = "qcom,hdmi-tx-8996", .data = &hdmi_tx_8996_config },
395         { .compatible = "qcom,hdmi-tx-8994", .data = &hdmi_tx_8994_config },
396         { .compatible = "qcom,hdmi-tx-8084", .data = &hdmi_tx_8084_config },
397         { .compatible = "qcom,hdmi-tx-8974", .data = &hdmi_tx_8974_config },
398         { .compatible = "qcom,hdmi-tx-8960", .data = &hdmi_tx_8960_config },
399         { .compatible = "qcom,hdmi-tx-8660", .data = &hdmi_tx_8660_config },
400         {}
401 };
402
403 #ifdef CONFIG_OF
404 static int get_gpio(struct device *dev, struct device_node *of_node, const char *name)
405 {
406         int gpio = of_get_named_gpio(of_node, name, 0);
407         if (gpio < 0) {
408                 char name2[32];
409                 snprintf(name2, sizeof(name2), "%s-gpio", name);
410                 gpio = of_get_named_gpio(of_node, name2, 0);
411                 if (gpio < 0) {
412                         DBG("failed to get gpio: %s (%d)", name, gpio);
413                         gpio = -1;
414                 }
415         }
416         return gpio;
417 }
418 #endif
419
420 static void msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev);
421 static int hdmi_bind(struct device *dev, struct device *master, void *data)
422 {
423         struct drm_device *drm = dev_get_drvdata(master);
424         struct msm_drm_private *priv = drm->dev_private;
425         static struct hdmi_platform_config *hdmi_cfg;
426         struct hdmi *hdmi;
427 #ifdef CONFIG_OF
428         struct device_node *of_node = dev->of_node;
429         const struct of_device_id *match;
430
431         match = of_match_node(dt_match, of_node);
432         if (match && match->data) {
433                 hdmi_cfg = (struct hdmi_platform_config *)match->data;
434                 DBG("hdmi phy: %s", match->compatible);
435         } else {
436                 dev_err(dev, "unknown phy: %s\n", of_node->name);
437                 return -ENXIO;
438         }
439
440         hdmi_cfg->mmio_name     = "core_physical";
441         hdmi_cfg->qfprom_mmio_name = "qfprom_physical";
442         hdmi_cfg->ddc_clk_gpio  = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-clk");
443         hdmi_cfg->ddc_data_gpio = get_gpio(dev, of_node, "qcom,hdmi-tx-ddc-data");
444         hdmi_cfg->hpd_gpio      = get_gpio(dev, of_node, "qcom,hdmi-tx-hpd");
445         hdmi_cfg->mux_en_gpio   = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-en");
446         hdmi_cfg->mux_sel_gpio  = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-sel");
447         hdmi_cfg->mux_lpm_gpio  = get_gpio(dev, of_node, "qcom,hdmi-tx-mux-lpm");
448
449 #else
450         static struct hdmi_platform_config config = {};
451         static const char *hpd_clk_names[] = {
452                         "core_clk", "master_iface_clk", "slave_iface_clk",
453         };
454         if (cpu_is_apq8064()) {
455                 static const char *hpd_reg_names[] = {"8921_hdmi_mvs"};
456                 config.phy_init      = hdmi_phy_8960_init;
457                 config.hpd_reg_names = hpd_reg_names;
458                 config.hpd_reg_cnt   = ARRAY_SIZE(hpd_reg_names);
459                 config.hpd_clk_names = hpd_clk_names;
460                 config.hpd_clk_cnt   = ARRAY_SIZE(hpd_clk_names);
461                 config.ddc_clk_gpio  = 70;
462                 config.ddc_data_gpio = 71;
463                 config.hpd_gpio      = 72;
464                 config.mux_en_gpio   = -1;
465                 config.mux_sel_gpio  = -1;
466         } else if (cpu_is_msm8960() || cpu_is_msm8960ab()) {
467                 static const char *hpd_reg_names[] = {"8921_hdmi_mvs"};
468                 config.phy_init      = hdmi_phy_8960_init;
469                 config.hpd_reg_names = hpd_reg_names;
470                 config.hpd_reg_cnt   = ARRAY_SIZE(hpd_reg_names);
471                 config.hpd_clk_names = hpd_clk_names;
472                 config.hpd_clk_cnt   = ARRAY_SIZE(hpd_clk_names);
473                 config.ddc_clk_gpio  = 100;
474                 config.ddc_data_gpio = 101;
475                 config.hpd_gpio      = 102;
476                 config.mux_en_gpio   = -1;
477                 config.mux_sel_gpio  = -1;
478         } else if (cpu_is_msm8x60()) {
479                 static const char *hpd_reg_names[] = {
480                                 "8901_hdmi_mvs", "8901_mpp0"
481                 };
482                 config.phy_init      = hdmi_phy_8x60_init;
483                 config.hpd_reg_names = hpd_reg_names;
484                 config.hpd_reg_cnt   = ARRAY_SIZE(hpd_reg_names);
485                 config.hpd_clk_names = hpd_clk_names;
486                 config.hpd_clk_cnt   = ARRAY_SIZE(hpd_clk_names);
487                 config.ddc_clk_gpio  = 170;
488                 config.ddc_data_gpio = 171;
489                 config.hpd_gpio      = 172;
490                 config.mux_en_gpio   = -1;
491                 config.mux_sel_gpio  = -1;
492         }
493         config.mmio_name     = "hdmi_msm_hdmi_addr";
494         config.qfprom_mmio_name = "hdmi_msm_qfprom_addr";
495
496         hdmi_cfg = &config;
497 #endif
498         dev->platform_data = hdmi_cfg;
499
500         hdmi = hdmi_init(to_platform_device(dev));
501         if (IS_ERR(hdmi))
502                 return PTR_ERR(hdmi);
503         priv->hdmi = hdmi;
504         msm_hdmi_register_audio_driver(hdmi, dev);
505
506         return 0;
507 }
508
509 static void hdmi_unbind(struct device *dev, struct device *master,
510                 void *data)
511 {
512         struct drm_device *drm = dev_get_drvdata(master);
513         struct msm_drm_private *priv = drm->dev_private;
514         if (priv->hdmi) {
515                 DRM_INFO("%s driver unbound to HDMI\n", HDMI_CODEC_DRV_NAME);
516                 platform_device_unregister(priv->hdmi->audio_pdev);
517                 hdmi_destroy(priv->hdmi);
518                 priv->hdmi = NULL;
519         }
520 }
521
522 static const struct component_ops hdmi_ops = {
523                 .bind   = hdmi_bind,
524                 .unbind = hdmi_unbind,
525 };
526 /*
527  * HDMI audio codec callbacks
528  */
529
530 static int msm_hdmi_audio_hw_params(struct device *dev,
531                                     struct hdmi_codec_daifmt *daifmt,
532                                     struct hdmi_codec_params *params)
533 {
534         struct hdmi *hdmi = dev_get_drvdata(dev);
535         unsigned int chan;// = params->cea.channels;
536         unsigned int channel_allocation = 0;
537         unsigned int rate;//
538         unsigned int level_shift  = 0; /* 0dB */
539         bool down_mix = false;
540         dev_dbg(dev, "%s: %u Hz, %d bit, %d channels\n", __func__,
541                 params->sample_rate, params->sample_width, chan);
542
543         switch (params->cea.channels) {
544         case 2:
545                 channel_allocation  = 0;
546                 chan = MSM_HDMI_AUDIO_CHANNEL_2;
547                 break;
548         case 4:
549                 channel_allocation  = 0;
550                 chan = MSM_HDMI_AUDIO_CHANNEL_4;
551                 break;
552         case 6:
553                 channel_allocation  = 0x0B;
554                 chan = MSM_HDMI_AUDIO_CHANNEL_6;
555                 break;
556         case 8:
557                 channel_allocation  = 0x1F;
558                 chan = MSM_HDMI_AUDIO_CHANNEL_8;
559                 break;
560         default:
561                 //dev_err(hdmi->dev, "channel[%d] not supported!\n", chan);
562                 return -EINVAL;
563         }
564
565         switch (params->sample_rate) {
566         case 32000:
567                 rate = HDMI_SAMPLE_RATE_32KHZ;
568         case 44100:
569                 rate = HDMI_SAMPLE_RATE_48KHZ;
570         case 48000:
571                 rate = HDMI_SAMPLE_RATE_48KHZ;
572         case 88200:
573                 rate = HDMI_SAMPLE_RATE_88_2KHZ;
574         case 96000:
575                 rate = HDMI_SAMPLE_RATE_96KHZ;
576         case 176400:
577                 rate = HDMI_SAMPLE_RATE_176_4KHZ;
578         case 192000:
579                 rate = HDMI_SAMPLE_RATE_192KHZ;
580                 break;
581         default:
582                 dev_err(dev, "rate[%d] not supported!\n",
583                         params->sample_rate);
584                 return -EINVAL;
585         }
586                 rate = HDMI_SAMPLE_RATE_48KHZ;
587                 channel_allocation  = 0;
588
589         //FIXME..
590         hdmi_audio_set_sample_rate(hdmi, rate);
591
592         hdmi_audio_info_setup(hdmi, 1, chan,
593                         channel_allocation, level_shift, down_mix);
594
595
596
597         return 0;
598 }
599
600 static int msm_hdmi_audio_startup(struct device *dev,
601                                   void (*abort_cb)(struct device *dev))
602 {
603         struct hdmi *hdmi = dev_get_drvdata(dev);
604
605         dev_dbg(dev, "%s\n", __func__);
606
607         //msm_hdmi_audio_enable(hdmi);
608
609         return 0;
610 }
611
612 static void msm_hdmi_audio_shutdown(struct device *dev)
613 {
614         struct hdmi *hdmi = dev_get_drvdata(dev);
615
616         dev_dbg(dev, "%s\n", __func__);
617
618         hdmi_audio_info_setup(hdmi, 0, 0, 0, 0, 0);
619 }
620
621 static const struct hdmi_codec_ops msm_hdmi_audio_codec_ops = {
622         .hw_params = msm_hdmi_audio_hw_params,
623         .audio_startup = msm_hdmi_audio_startup,
624         .audio_shutdown = msm_hdmi_audio_shutdown,
625 };
626
627 static void msm_hdmi_register_audio_driver(struct hdmi *hdmi, struct device *dev)
628 {
629         struct hdmi_codec_pdata codec_data = {
630                 .ops = &msm_hdmi_audio_codec_ops,
631                 .max_i2s_channels = 2,
632                 .i2s = 1,
633         };
634         //struct platform_device *pdev;
635
636         hdmi->audio_pdev = platform_device_register_data(dev, HDMI_CODEC_DRV_NAME,
637                                              PLATFORM_DEVID_AUTO, &codec_data,
638                                              sizeof(codec_data));
639         if (IS_ERR(hdmi->audio_pdev))
640                 return;
641
642         DRM_INFO("%s driver bound to HDMI\n", HDMI_CODEC_DRV_NAME);
643 }
644
645 static int hdmi_dev_probe(struct platform_device *pdev)
646 {
647         return component_add(&pdev->dev, &hdmi_ops);
648 }
649
650 static int hdmi_dev_remove(struct platform_device *pdev)
651 {
652         component_del(&pdev->dev, &hdmi_ops);
653         return 0;
654 }
655
656 static struct platform_driver hdmi_driver = {
657         .probe = hdmi_dev_probe,
658         .remove = hdmi_dev_remove,
659         .driver = {
660                 .name = "hdmi_msm",
661                 .of_match_table = dt_match,
662         },
663 };
664
665 void __init hdmi_register(void)
666 {
667         platform_driver_register(&hdmi_driver);
668 }
669
670 void __exit hdmi_unregister(void)
671 {
672         platform_driver_unregister(&hdmi_driver);
673 }