1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #include "audio_hdmi_codec_linux.h" 10 #include <linux/module.h> 11 #include <linux/of_graph.h> 12 #include <linux/string.h> 13 #include "audio_driver_log.h" 14 15 #define HDF_LOG_TAG HDF_AUDIO_HDMI 16 17 #define AUDIO_HDMI_CODEC_DRV_NAME "hdmi-audio-codec" 18 19 static struct HdmiCodecPriv *g_hdmiCodecPriv = NULL; 20 AudioGetHdmiCodecPriv(void)21struct HdmiCodecPriv *AudioGetHdmiCodecPriv(void) 22 { 23 return g_hdmiCodecPriv; 24 } 25 HdmiCodecProbe(struct platform_device * pdev)26static int32_t HdmiCodecProbe(struct platform_device *pdev) 27 { 28 struct hdmi_codec_pdata *hdmiCodecData = NULL; 29 struct device *dev = NULL; 30 struct HdmiCodecPriv *hdmiCodecPriv = NULL; 31 int32_t daiCount; 32 33 AUDIO_DRIVER_LOG_INFO("entry"); 34 if (pdev == NULL) { 35 AUDIO_DRIVER_LOG_ERR("input param is null"); 36 return -EINVAL; 37 } 38 dev = &pdev->dev; 39 hdmiCodecData = pdev->dev.platform_data; 40 if (hdmiCodecData == NULL) { 41 AUDIO_DRIVER_LOG_ERR("No hdmi codec data"); 42 return -EINVAL; 43 } 44 45 daiCount = hdmiCodecData->i2s + hdmiCodecData->spdif; 46 if (daiCount < 1) { // count minimum 1 47 AUDIO_DRIVER_LOG_ERR("daiCount < 1, daiCount is %d", daiCount); 48 return -EINVAL; 49 } 50 51 hdmiCodecPriv = devm_kzalloc(dev, sizeof(struct HdmiCodecPriv), GFP_KERNEL); 52 if (hdmiCodecPriv == NULL) { 53 AUDIO_DRIVER_LOG_ERR("hdmiCodecPriv devm_kzalloc failed"); 54 return -ENOMEM; 55 } 56 57 hdmiCodecPriv->hdmiCodecData = *hdmiCodecData; 58 mutex_init(&hdmiCodecPriv->lock); 59 hdmiCodecPriv->dev = dev; 60 61 g_hdmiCodecPriv = hdmiCodecPriv; 62 return 0; 63 } 64 65 static struct platform_driver g_audioHdmiCodecDriver = { 66 .driver.name = AUDIO_HDMI_CODEC_DRV_NAME, 67 .probe = HdmiCodecProbe, 68 }; 69 70 module_platform_driver(g_audioHdmiCodecDriver); 71