4 * Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #include <drm/bridge/dw_hdmi.h>
12 #include <sound/hdmi-codec.h>
15 #include "dw-hdmi-audio.h"
17 #define DRIVER_NAME "dw-hdmi-i2s-audio"
19 static inline void hdmi_write(struct dw_hdmi_i2s_audio_data *audio,
22 struct dw_hdmi *hdmi = audio->hdmi;
24 audio->write(hdmi, val, offset);
27 static inline u8 hdmi_read(struct dw_hdmi_i2s_audio_data *audio, int offset)
29 struct dw_hdmi *hdmi = audio->hdmi;
31 return audio->read(hdmi, offset);
34 static int dw_hdmi_i2s_hw_params(struct device *dev, void *data,
35 struct hdmi_codec_daifmt *fmt,
36 struct hdmi_codec_params *hparms)
38 struct dw_hdmi_i2s_audio_data *audio = data;
39 struct dw_hdmi *hdmi = audio->hdmi;
44 /* it cares I2S only */
45 if ((fmt->fmt != HDMI_I2S) ||
46 (fmt->bit_clk_master | fmt->frame_clk_master)) {
47 dev_err(dev, "unsupported format/settings\n");
51 inputclkfs = HDMI_AUD_INPUTCLKFS_64FS;
52 conf0 = HDMI_AUD_CONF0_I2S_ALL_ENABLE;
54 switch (hparms->sample_width) {
56 conf1 = HDMI_AUD_CONF1_WIDTH_16;
60 conf1 = HDMI_AUD_CONF1_WIDTH_24;
64 dw_hdmi_set_sample_rate(hdmi, hparms->sample_rate);
66 hdmi_write(audio, inputclkfs, HDMI_AUD_INPUTCLKFS);
67 hdmi_write(audio, conf0, HDMI_AUD_CONF0);
68 hdmi_write(audio, conf1, HDMI_AUD_CONF1);
70 dw_hdmi_audio_enable(hdmi);
75 static void dw_hdmi_i2s_audio_shutdown(struct device *dev, void *data)
77 struct dw_hdmi_i2s_audio_data *audio = data;
78 struct dw_hdmi *hdmi = audio->hdmi;
80 dw_hdmi_audio_disable(hdmi);
82 hdmi_write(audio, HDMI_AUD_CONF0_SW_RESET, HDMI_AUD_CONF0);
85 static struct hdmi_codec_ops dw_hdmi_i2s_ops = {
86 .hw_params = dw_hdmi_i2s_hw_params,
87 .audio_shutdown = dw_hdmi_i2s_audio_shutdown,
90 static int snd_dw_hdmi_probe(struct platform_device *pdev)
92 struct dw_hdmi_i2s_audio_data *audio = pdev->dev.platform_data;
93 struct platform_device_info pdevinfo;
94 struct hdmi_codec_pdata pdata;
95 struct platform_device *platform;
97 pdata.ops = &dw_hdmi_i2s_ops;
99 pdata.max_i2s_channels = 6;
102 memset(&pdevinfo, 0, sizeof(pdevinfo));
103 pdevinfo.parent = pdev->dev.parent;
104 pdevinfo.id = PLATFORM_DEVID_AUTO;
105 pdevinfo.name = HDMI_CODEC_DRV_NAME;
106 pdevinfo.data = &pdata;
107 pdevinfo.size_data = sizeof(pdata);
108 pdevinfo.dma_mask = DMA_BIT_MASK(32);
110 platform = platform_device_register_full(&pdevinfo);
111 if (IS_ERR(platform))
112 return PTR_ERR(platform);
114 dev_set_drvdata(&pdev->dev, platform);
119 static int snd_dw_hdmi_remove(struct platform_device *pdev)
121 struct platform_device *platform = dev_get_drvdata(&pdev->dev);
123 platform_device_unregister(platform);
128 static struct platform_driver snd_dw_hdmi_driver = {
129 .probe = snd_dw_hdmi_probe,
130 .remove = snd_dw_hdmi_remove,
133 .owner = THIS_MODULE,
136 module_platform_driver(snd_dw_hdmi_driver);
138 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
139 MODULE_DESCRIPTION("Synopsis Designware HDMI I2S ALSA SoC interface");
140 MODULE_LICENSE("GPL v2");
141 MODULE_ALIAS("platform:" DRIVER_NAME);