Path: blob/master/drivers/gpu/drm/bridge/synopsys/dw-hdmi-gp-audio.c
26516 views
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)1/*2* dw-hdmi-gp-audio.c3*4* Copyright 2020-2022 NXP5*/6#include <linux/io.h>7#include <linux/interrupt.h>8#include <linux/module.h>9#include <linux/platform_device.h>10#include <linux/dmaengine.h>11#include <linux/dma-mapping.h>12#include <drm/bridge/dw_hdmi.h>13#include <drm/drm_edid.h>14#include <drm/drm_connector.h>1516#include <sound/hdmi-codec.h>17#include <sound/asoundef.h>18#include <sound/core.h>19#include <sound/initval.h>20#include <sound/pcm.h>21#include <sound/pcm_drm_eld.h>22#include <sound/pcm_iec958.h>23#include <sound/dmaengine_pcm.h>2425#include "dw-hdmi-audio.h"2627#define DRIVER_NAME "dw-hdmi-gp-audio"28#define DRV_NAME "hdmi-gp-audio"2930struct snd_dw_hdmi {31struct dw_hdmi_audio_data data;32struct platform_device *audio_pdev;33unsigned int pos;34};3536struct dw_hdmi_channel_conf {37u8 conf1;38u8 ca;39};4041/*42* The default mapping of ALSA channels to HDMI channels and speaker43* allocation bits. Note that we can't do channel remapping here -44* channels must be in the same order.45*46* Mappings for alsa-lib pcm/surround*.conf files:47*48* Front Sur4.0 Sur4.1 Sur5.0 Sur5.1 Sur7.149* Channels 2 4 6 6 6 850*51* Our mapping from ALSA channel to CEA686D speaker name and HDMI channel:52*53* Number of ALSA channels54* ALSA Channel 2 3 4 5 6 7 855* 0 FL:0 = = = = = =56* 1 FR:1 = = = = = =57* 2 FC:3 RL:4 LFE:2 = = =58* 3 RR:5 RL:4 FC:3 = =59* 4 RR:5 RL:4 = =60* 5 RR:5 = =61* 6 RC:6 =62* 7 RLC/FRC RLC/FRC63*/64static struct dw_hdmi_channel_conf default_hdmi_channel_config[7] = {65{ 0x03, 0x00 }, /* FL,FR */66{ 0x0b, 0x02 }, /* FL,FR,FC */67{ 0x33, 0x08 }, /* FL,FR,RL,RR */68{ 0x37, 0x09 }, /* FL,FR,LFE,RL,RR */69{ 0x3f, 0x0b }, /* FL,FR,LFE,FC,RL,RR */70{ 0x7f, 0x0f }, /* FL,FR,LFE,FC,RL,RR,RC */71{ 0xff, 0x13 }, /* FL,FR,LFE,FC,RL,RR,[FR]RC,[FR]LC */72};7374static int audio_hw_params(struct device *dev, void *data,75struct hdmi_codec_daifmt *daifmt,76struct hdmi_codec_params *params)77{78struct snd_dw_hdmi *dw = dev_get_drvdata(dev);79u8 ca;8081dw_hdmi_set_sample_rate(dw->data.hdmi, params->sample_rate);8283ca = default_hdmi_channel_config[params->channels - 2].ca;8485dw_hdmi_set_channel_count(dw->data.hdmi, params->channels);86dw_hdmi_set_channel_allocation(dw->data.hdmi, ca);8788dw_hdmi_set_sample_non_pcm(dw->data.hdmi,89params->iec.status[0] & IEC958_AES0_NONAUDIO);90dw_hdmi_set_sample_width(dw->data.hdmi, params->sample_width);9192return 0;93}9495static void audio_shutdown(struct device *dev, void *data)96{97}9899static int audio_mute_stream(struct device *dev, void *data,100bool enable, int direction)101{102struct snd_dw_hdmi *dw = dev_get_drvdata(dev);103104if (!enable)105dw_hdmi_audio_enable(dw->data.hdmi);106else107dw_hdmi_audio_disable(dw->data.hdmi);108109return 0;110}111112static int audio_get_eld(struct device *dev, void *data,113u8 *buf, size_t len)114{115struct dw_hdmi_audio_data *audio = data;116u8 *eld;117118eld = audio->get_eld(audio->hdmi);119if (eld)120memcpy(buf, eld, min_t(size_t, MAX_ELD_BYTES, len));121else122/* Pass en empty ELD if connector not available */123memset(buf, 0, len);124125return 0;126}127128static int audio_hook_plugged_cb(struct device *dev, void *data,129hdmi_codec_plugged_cb fn,130struct device *codec_dev)131{132struct snd_dw_hdmi *dw = dev_get_drvdata(dev);133134return dw_hdmi_set_plugged_cb(dw->data.hdmi, fn, codec_dev);135}136137static const struct hdmi_codec_ops audio_codec_ops = {138.hw_params = audio_hw_params,139.audio_shutdown = audio_shutdown,140.mute_stream = audio_mute_stream,141.get_eld = audio_get_eld,142.hook_plugged_cb = audio_hook_plugged_cb,143};144145static int snd_dw_hdmi_probe(struct platform_device *pdev)146{147struct dw_hdmi_audio_data *data = pdev->dev.platform_data;148struct snd_dw_hdmi *dw;149150const struct hdmi_codec_pdata codec_data = {151.i2s = 1,152.spdif = 0,153.ops = &audio_codec_ops,154.max_i2s_channels = 8,155.data = data,156};157158dw = devm_kzalloc(&pdev->dev, sizeof(*dw), GFP_KERNEL);159if (!dw)160return -ENOMEM;161162dw->data = *data;163164platform_set_drvdata(pdev, dw);165166dw->audio_pdev = platform_device_register_data(&pdev->dev,167HDMI_CODEC_DRV_NAME, 1,168&codec_data,169sizeof(codec_data));170171return PTR_ERR_OR_ZERO(dw->audio_pdev);172}173174static void snd_dw_hdmi_remove(struct platform_device *pdev)175{176struct snd_dw_hdmi *dw = platform_get_drvdata(pdev);177178platform_device_unregister(dw->audio_pdev);179}180181static struct platform_driver snd_dw_hdmi_driver = {182.probe = snd_dw_hdmi_probe,183.remove = snd_dw_hdmi_remove,184.driver = {185.name = DRIVER_NAME,186},187};188189module_platform_driver(snd_dw_hdmi_driver);190191MODULE_AUTHOR("Shengjiu Wang <[email protected]>");192MODULE_DESCRIPTION("Synopsys Designware HDMI GPA ALSA interface");193MODULE_LICENSE("GPL");194MODULE_ALIAS("platform:" DRIVER_NAME);195196197