From 1efff87050b4c9b00228f4502e26ace818378471 Mon Sep 17 00:00:00 2001 From: Ralf Herz Date: Tue, 23 Oct 2018 16:11:49 +0200 Subject: [PATCH] asoc: codecs: Add ep92 version read and NULL check Provide chipid and version info in sysfs. Fix error handling and avoid polling when device is not present. Change-Id: Ie31b14e494e527ede001c334e3617f16fd687a28 Signed-off-by: Ralf Herz --- asoc/codecs/ep92/ep92.c | 436 +++++++++++++++++++++++----------------- 1 file changed, 248 insertions(+), 188 deletions(-) diff --git a/asoc/codecs/ep92/ep92.c b/asoc/codecs/ep92/ep92.c index c2cce8e2af..06d29ff820 100644 --- a/asoc/codecs/ep92/ep92.c +++ b/asoc/codecs/ep92/ep92.c @@ -41,37 +41,8 @@ static const unsigned int ep92_samp_freq_table[8] = { static bool ep92_volatile_register(struct device *dev, unsigned int reg) { - switch (reg) { - case EP92_BI_GENERAL_INFO_0: - case EP92_BI_GENERAL_INFO_1: - case EP92_BI_GENERAL_INFO_2: - case EP92_BI_GENERAL_INFO_3: - case EP92_BI_GENERAL_INFO_4: - case EP92_BI_GENERAL_INFO_5: - case EP92_BI_GENERAL_INFO_6: - case EP92_GENERAL_CONTROL_0: - case EP92_GENERAL_CONTROL_1: - case EP92_GENERAL_CONTROL_2: - case EP92_GENERAL_CONTROL_3: - case EP92_GENERAL_CONTROL_4: - case EP92_AUDIO_INFO_SYSTEM_STATUS_0: - case EP92_AUDIO_INFO_SYSTEM_STATUS_1: - case EP92_AUDIO_INFO_AUDIO_STATUS: - case EP92_AUDIO_INFO_CHANNEL_STATUS_0: - case EP92_AUDIO_INFO_CHANNEL_STATUS_1: - case EP92_AUDIO_INFO_CHANNEL_STATUS_2: - case EP92_AUDIO_INFO_CHANNEL_STATUS_3: - case EP92_AUDIO_INFO_CHANNEL_STATUS_4: - case EP92_AUDIO_INFO_ADO_INFO_FRAME_0: - case EP92_AUDIO_INFO_ADO_INFO_FRAME_1: - case EP92_AUDIO_INFO_ADO_INFO_FRAME_2: - case EP92_AUDIO_INFO_ADO_INFO_FRAME_3: - case EP92_AUDIO_INFO_ADO_INFO_FRAME_4: - case EP92_AUDIO_INFO_ADO_INFO_FRAME_5: - return true; - default: - return false; - } + /* do not cache register state in regmap */ + return true; } static bool ep92_writeable_registers(struct device *dev, unsigned int reg) @@ -176,6 +147,9 @@ static ssize_t debugfs_codec_write_op(struct file *filp, int rc; u32 param[2]; + if (!component) + return -ENODEV; + if (!filp || !ppos || !ubuf) return -EINVAL; if (cnt > sizeof(lbuf) - 1) @@ -245,6 +219,9 @@ static ssize_t debugfs_codec_read_op(struct file *filp, struct snd_soc_component *component = ep92->component; ssize_t ret_cnt; + if (!component) + return -ENODEV; + if (!filp || !ppos || !ubuf || *ppos < 0) return -EINVAL; ret_cnt = debugfs_ep92_reg_show(component, ubuf, cnt, ppos); @@ -265,6 +242,8 @@ static int ep92_send_uevent(struct ep92_pdata *ep92, char *event) if (!event || !ep92) return -EINVAL; + if (!ep92->component) + return -ENODEV; return kobject_uevent_env(&ep92->component->dev->kobj, KOBJ_CHANGE, env); } @@ -333,7 +312,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, ep92->gi.tx_info = snd_soc_component_read32(component, EP92_BI_GENERAL_INFO_0); if (ep92->gi.tx_info == 0xff) { - pr_debug("ep92 EP92_BI_GENERAL_INFO_0 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_BI_GENERAL_INFO_0 read 0xff\n"); ep92->gi.tx_info = old; } /* implement hysteresis to prevent events on glitches */ @@ -343,7 +322,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_tx_plug == EP92_HYST_CNT) && (ep92->filt_tx_plug == 0)) { ep92->filt_tx_plug = 1; - pr_debug("ep92 out_plug changed to 1\n"); + dev_dbg(component->dev, "ep92 out_plug changed to 1\n"); ep92_send_uevent(ep92, "EP92EVT_OUT_PLUG=CONNECTED"); } @@ -354,7 +333,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_tx_plug == 0) && (ep92->filt_tx_plug == 1)) { ep92->filt_tx_plug = 0; - pr_debug("ep92 out_plug changed to 0\n"); + dev_dbg(component->dev, "ep92 out_plug changed to 0\n"); ep92_send_uevent(ep92, "EP92EVT_OUT_PLUG=DISCONNECTED"); } @@ -365,7 +344,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, ep92->gi.video_latency = snd_soc_component_read32(component, EP92_BI_GENERAL_INFO_4); if (ep92->gi.video_latency == 0xff) { - pr_debug("ep92 EP92_BI_GENERAL_INFO_4 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_BI_GENERAL_INFO_4 read 0xff\n"); ep92->gi.video_latency = old; } change = ep92->gi.video_latency ^ old; @@ -373,7 +352,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, val = ep92->gi.video_latency; if (val > 0) val = (val - 1) * 2; - pr_debug("ep92 video latency changed to %d\n", val); + dev_dbg(component->dev, "ep92 video latency changed to %d\n", val); ep92_send_uevent(ep92, "EP92EVT_VIDEO_LATENCY=CHANGED"); } @@ -381,14 +360,14 @@ static void ep92_read_general_control(struct snd_soc_component *component, ep92->gc.ctl = snd_soc_component_read32(component, EP92_GENERAL_CONTROL_0); if (ep92->gc.ctl == 0xff) { - pr_debug("ep92 EP92_GENERAL_CONTROL_0 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_GENERAL_CONTROL_0 read 0xff\n"); ep92->gc.ctl = old; } change = ep92->gc.ctl ^ old; if (change & EP92_GC_POWER_MASK) { val = (ep92->gc.ctl >> EP92_GC_POWER_SHIFT) & EP92_2CHOICE_MASK; - pr_debug("ep92 power changed to %d\n", val); + dev_dbg(component->dev, "ep92 power changed to %d\n", val); if (val) ep92_send_uevent(ep92, "EP92EVT_POWER=ON"); else @@ -397,7 +376,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if (change & EP92_GC_AUDIO_PATH_MASK) { val = (ep92->gc.ctl >> EP92_GC_AUDIO_PATH_SHIFT) & EP92_2CHOICE_MASK; - pr_debug("ep92 audio_path changed to %d\n", val); + dev_dbg(component->dev, "ep92 audio_path changed to %d\n", val); if (val) ep92_send_uevent(ep92, "EP92EVT_AUDIO_PATH=TV"); else @@ -406,7 +385,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if (change & EP92_GC_CEC_MUTE_MASK) { val = (ep92->gc.ctl >> EP92_GC_CEC_MUTE_SHIFT) & EP92_2CHOICE_MASK; - pr_debug("ep92 cec_mute changed to %d\n", val); + dev_dbg(component->dev, "ep92 cec_mute changed to %d\n", val); if (val) ep92_send_uevent(ep92, "EP92EVT_CEC_MUTE=NORMAL"); else @@ -414,7 +393,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, } if (change & EP92_GC_ARC_EN_MASK) { val = ep92->gc.ctl & EP92_2CHOICE_MASK; - pr_debug("ep92 arc_en changed to %d\n", val); + dev_dbg(component->dev, "ep92 arc_en changed to %d\n", val); if (val) ep92_send_uevent(ep92, "EP92EVT_ARC_EN=ON"); else @@ -425,13 +404,13 @@ static void ep92_read_general_control(struct snd_soc_component *component, ep92->gc.rx_sel = snd_soc_component_read32(component, EP92_GENERAL_CONTROL_1); if (ep92->gc.rx_sel == 0xff) { - pr_debug("ep92 EP92_GENERAL_CONTROL_1 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_GENERAL_CONTROL_1 read 0xff\n"); ep92->gc.rx_sel = old; } change = ep92->gc.rx_sel ^ old; if (change & EP92_GC_RX_SEL_MASK) { val = ep92->gc.rx_sel & EP92_GC_RX_SEL_MASK; - pr_debug("ep92 rx_sel changed to %d\n", val); + dev_dbg(component->dev, "ep92 rx_sel changed to %d\n", val); ep92_send_uevent(ep92, "EP92EVT_SRC_SEL=CHANGED"); } @@ -439,13 +418,13 @@ static void ep92_read_general_control(struct snd_soc_component *component, ep92->gc.cec_volume = snd_soc_component_read32(component, EP92_GENERAL_CONTROL_3); if (ep92->gc.cec_volume == 0xff) { - pr_debug("ep92 EP92_GENERAL_CONTROL_3 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_GENERAL_CONTROL_3 read 0xff\n"); ep92->gc.cec_volume = old; } change = ep92->gc.cec_volume ^ old; if (change & EP92_GC_CEC_VOLUME_MASK) { val = ep92->gc.cec_volume & EP92_GC_CEC_VOLUME_MASK; - pr_debug("ep92 cec_volume changed to %d\n", val); + dev_dbg(component->dev, "ep92 cec_volume changed to %d\n", val); ep92_send_uevent(ep92, "EP92EVT_CEC_VOLUME=CHANGED"); } @@ -453,7 +432,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, ep92->gc.link = snd_soc_component_read32(component, EP92_GENERAL_CONTROL_4); if (ep92->gc.link == 0xff) { - pr_debug("ep92 EP92_GENERAL_CONTROL_4 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_GENERAL_CONTROL_4 read 0xff\n"); ep92->gc.link = old; } @@ -464,7 +443,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_link_on0 == EP92_HYST_CNT) && (ep92->filt_link_on0 == 0)) { ep92->filt_link_on0 = 1; - pr_debug("ep92 link_on0 changed to 1\n"); + dev_dbg(component->dev, "ep92 link_on0 changed to 1\n"); ep92_send_uevent(ep92, "EP92EVT_LINK_ON0=CONNECTED"); } @@ -475,7 +454,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_link_on0 == 0) && (ep92->filt_link_on0 == 1)) { ep92->filt_link_on0 = 0; - pr_debug("ep92 link_on0 changed to 0\n"); + dev_dbg(component->dev, "ep92 link_on0 changed to 0\n"); ep92_send_uevent(ep92, "EP92EVT_LINK_ON0=DISCONNECTED"); } @@ -489,7 +468,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_link_on1 == EP92_HYST_CNT) && (ep92->filt_link_on1 == 0)) { ep92->filt_link_on1 = 1; - pr_debug("ep92 link_on1 changed to 1\n"); + dev_dbg(component->dev, "ep92 link_on1 changed to 1\n"); ep92_send_uevent(ep92, "EP92EVT_LINK_ON1=CONNECTED"); } @@ -500,7 +479,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_link_on1 == 0) && (ep92->filt_link_on1 == 1)) { ep92->filt_link_on1 = 0; - pr_debug("ep92 link_on1 changed to 0\n"); + dev_dbg(component->dev, "ep92 link_on1 changed to 0\n"); ep92_send_uevent(ep92, "EP92EVT_LINK_ON1=DISCONNECTED"); } @@ -514,7 +493,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_link_on2 == EP92_HYST_CNT) && (ep92->filt_link_on2 == 0)) { ep92->filt_link_on2 = 1; - pr_debug("ep92 link_on2 changed to 1\n"); + dev_dbg(component->dev, "ep92 link_on2 changed to 1\n"); ep92_send_uevent(ep92, "EP92EVT_LINK_ON2=CONNECTED"); } @@ -525,7 +504,7 @@ static void ep92_read_general_control(struct snd_soc_component *component, if ((ep92->hyst_link_on2 == 0) && (ep92->filt_link_on2 == 1)) { ep92->filt_link_on2 = 0; - pr_debug("ep92 link_on2 changed to 0\n"); + dev_dbg(component->dev, "ep92 link_on2 changed to 0\n"); ep92_send_uevent(ep92, "EP92EVT_LINK_ON2=DISCONNECTED"); } @@ -544,24 +523,24 @@ static void ep92_read_audio_info(struct snd_soc_component *component, ep92->ai.system_status_0 = snd_soc_component_read32(component, EP92_AUDIO_INFO_SYSTEM_STATUS_0); if (ep92->ai.system_status_0 == 0xff) { - pr_debug("ep92 EP92_AUDIO_INFO_SYSTEM_STATUS_0 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_AUDIO_INFO_SYSTEM_STATUS_0 read 0xff\n"); ep92->ai.system_status_0 = old; } change = ep92->ai.system_status_0 ^ old; if (change & EP92_AI_MCLK_ON_MASK) { - pr_debug("ep92 status changed to %d\n", + dev_dbg(component->dev, "ep92 status changed to %d\n", (ep92->ai.system_status_0 >> EP92_AI_MCLK_ON_SHIFT) & EP92_2CHOICE_MASK); send_uevent = true; } if (change & EP92_AI_AVMUTE_MASK) { - pr_debug("ep92 avmute changed to %d\n", + dev_dbg(component->dev, "ep92 avmute changed to %d\n", (ep92->ai.system_status_0 >> EP92_AI_AVMUTE_SHIFT) & EP92_2CHOICE_MASK); send_uevent = true; } if (change & EP92_AI_LAYOUT_MASK) { - pr_debug("ep92 layout changed to %d\n", + dev_dbg(component->dev, "ep92 layout changed to %d\n", (ep92->ai.system_status_0) & EP92_2CHOICE_MASK); send_uevent = true; } @@ -570,12 +549,12 @@ static void ep92_read_audio_info(struct snd_soc_component *component, ep92->ai.audio_status = snd_soc_component_read32(component, EP92_AUDIO_INFO_AUDIO_STATUS); if (ep92->ai.audio_status == 0xff) { - pr_debug("ep92 EP92_AUDIO_INFO_AUDIO_STATUS read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_AUDIO_INFO_AUDIO_STATUS read 0xff\n"); ep92->ai.audio_status = old; } change = ep92->ai.audio_status ^ old; if (change & EP92_AI_RATE_MASK) { - pr_debug("ep92 rate changed to %d\n", + dev_dbg(component->dev, "ep92 rate changed to %d\n", ep92_samp_freq_table[(ep92->ai.audio_status) & EP92_AI_RATE_MASK]); send_uevent = true; @@ -587,7 +566,7 @@ static void ep92_read_audio_info(struct snd_soc_component *component, ep92->ai.cs[0] = snd_soc_component_read32(component, EP92_AUDIO_INFO_CHANNEL_STATUS_0); if (ep92->ai.cs[0] == 0xff) { - pr_debug("ep92 EP92_AUDIO_INFO_CHANNEL_STATUS_0 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_AUDIO_INFO_CHANNEL_STATUS_0 read 0xff\n"); ep92->ai.cs[0] = old; } if (ep92->ai.cs[0] & EP92_AI_NPCM_MASK) @@ -598,7 +577,7 @@ static void ep92_read_audio_info(struct snd_soc_component *component, new_mode = 1; /* Compr */ if (ep92->old_mode != new_mode) { - pr_debug("ep92 mode changed to %d\n", new_mode); + dev_dbg(component->dev, "ep92 mode changed to %d\n", new_mode); send_uevent = true; } ep92->old_mode = new_mode; @@ -607,12 +586,12 @@ static void ep92_read_audio_info(struct snd_soc_component *component, ep92->ai.cc = snd_soc_component_read32(component, EP92_AUDIO_INFO_ADO_INFO_FRAME_1); if (ep92->ai.cc == 0xff) { - pr_debug("ep92 EP92_AUDIO_INFO_ADO_INFO_FRAME_1 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_AUDIO_INFO_ADO_INFO_FRAME_1 read 0xff\n"); ep92->ai.cc = old; } change = ep92->ai.cc ^ old; if (change & EP92_AI_CH_COUNT_MASK) { - pr_debug("ep92 ch_count changed to %d (%d)\n", + dev_dbg(component->dev, "ep92 ch_count changed to %d (%d)\n", ep92->ai.cc & EP92_AI_CH_COUNT_MASK, (ep92->ai.cc & EP92_AI_CH_COUNT_MASK) == 0 ? 0 : (ep92->ai.cc & EP92_AI_CH_COUNT_MASK) + 1); @@ -623,12 +602,12 @@ static void ep92_read_audio_info(struct snd_soc_component *component, ep92->ai.ca = snd_soc_component_read32(component, EP92_AUDIO_INFO_ADO_INFO_FRAME_4); if (ep92->ai.ca == 0xff) { - pr_debug("ep92 EP92_AUDIO_INFO_ADO_INFO_FRAME_4 read 0xff\n"); + dev_dbg(component->dev, "ep92 EP92_AUDIO_INFO_ADO_INFO_FRAME_4 read 0xff\n"); ep92->ai.ca = old; } change = ep92->ai.ca ^ old; if (change & EP92_AI_CH_ALLOC_MASK) { - pr_debug("ep92 ch_alloc changed to 0x%02x\n", + dev_dbg(component->dev, "ep92 ch_alloc changed to 0x%02x\n", (ep92->ai.ca) & EP92_AI_CH_ALLOC_MASK); send_uevent = true; } @@ -640,6 +619,22 @@ static void ep92_read_audio_info(struct snd_soc_component *component, static void ep92_init(struct snd_soc_component *component, struct ep92_pdata *ep92) { + int reg0 = 0; + int reg1 = 0; + int reg2 = 0; + int reg3 = 0; + + if (!ep92 || !component) + return; + + reg0 = snd_soc_component_read32(component, EP92_BI_VERSION_YEAR); + reg1 = snd_soc_component_read32(component, EP92_BI_VERSION_MONTH); + reg2 = snd_soc_component_read32(component, EP92_BI_VERSION_DATE); + reg3 = snd_soc_component_read32(component, EP92_BI_VERSION_NUM); + + dev_info(compoent->dev, "ep92 version info %02d/%02d/%02d %d\n", + reg0, reg1, reg2, reg3); + /* update the format information in mixer controls */ ep92_read_general_control(component, ep92); ep92_read_audio_info(component, ep92); @@ -652,6 +647,12 @@ static int ep92_probe(struct snd_soc_component *component) ep92->component = component; ep92_init(component, ep92); + /* start polling when codec is registered */ + if (ep92->irq == 0) { + mod_timer(&ep92->timer, jiffies + + msecs_to_jiffies(EP92_POLL_INTERVAL_OFF_MSEC)); + } + return 0; } @@ -685,7 +686,7 @@ void ep92_read_status(struct work_struct *work) struct snd_soc_component *component = ep92->component; u8 val; - /* No polling before codec is initialized */ + /* No polling before component is initialized */ if (component == NULL) return; @@ -700,10 +701,10 @@ void ep92_read_status(struct work_struct *work) } if (val & EP92_GI_ADO_CHF_MASK) - pr_debug("ep92 audio mode change trigger.\n"); + dev_dbg(component->dev, "ep92 audio mode change trigger.\n"); if (val & EP92_GI_CEC_ECF_MASK) - pr_debug("ep92 CEC change trigger.\n"); + dev_dbg(component->dev, "ep92 CEC change trigger.\n"); /* check for general control changes */ ep92_read_general_control(component, ep92); @@ -717,7 +718,7 @@ static irqreturn_t ep92_irq(int irq, void *data) struct ep92_pdata *ep92 = data; struct snd_soc_component *component = ep92->component; - /* Treat interrupt before codec is initialized as spurious */ + /* Treat interrupt before component is initialized as spurious */ if (component == NULL) return IRQ_NONE; @@ -749,6 +750,64 @@ static const struct of_device_id ep92_of_match[] = { }; MODULE_DEVICE_TABLE(of, ep92_of_match); +static ssize_t ep92_sysfs_rda_chipid(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t ret = 0; + int reg0 = 0; + int reg1 = 0; + int reg2 = 0; + int reg3 = 0; + struct ep92_pdata *ep92 = dev_get_drvdata(dev); + + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; + } + + reg0 = snd_soc_component_read32(ep92->component, EP92_BI_VENDOR_ID_0); + reg1 = snd_soc_component_read32(ep92->component, EP92_BI_VENDOR_ID_1); + reg2 = snd_soc_component_read32(ep92->component, EP92_BI_DEVICE_ID_0); + reg3 = snd_soc_component_read32(ep92->component, EP92_BI_DEVICE_ID_1); + + ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%02x%02x/%02x%02x\n", + reg0, reg1, reg2, reg3); + dev_dbg(dev, "%s: '%s'\n", __func__, buf); + + return ret; +} + +static ssize_t ep92_sysfs_rda_version(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t ret = 0; + int reg0 = 0; + int reg1 = 0; + int reg2 = 0; + int reg3 = 0; + struct ep92_pdata *ep92 = dev_get_drvdata(dev); + + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; + } + + reg0 = snd_soc_component_read32(ep92->component, + EP92_BI_VERSION_YEAR); + reg1 = snd_soc_component_read32(ep92->component, + EP92_BI_VERSION_MONTH); + reg2 = snd_soc_component_read32(ep92->component, + EP92_BI_VERSION_DATE); + reg3 = snd_soc_component_read32(ep92->component, + EP92_BI_VERSION_NUM); + + ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%02d/%02d/%02d %d\n", + reg0, reg1, reg2, reg3); + dev_dbg(dev, "%s: '%s'\n", __func__, buf); + + return ret; +} + static ssize_t ep92_sysfs_rda_audio_state(struct device *dev, struct device_attribute *attr, char *buf) { @@ -756,16 +815,16 @@ static ssize_t ep92_sysfs_rda_audio_state(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->ai.system_status_0 & EP92_AI_MCLK_ON_MASK) >> EP92_AI_MCLK_ON_SHIFT; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -777,15 +836,15 @@ static ssize_t ep92_sysfs_rda_audio_format(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->old_mode; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -797,15 +856,15 @@ static ssize_t ep92_sysfs_rda_audio_rate(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92_samp_freq_table[(ep92->ai.audio_status) & EP92_AI_RATE_MASK]; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -817,16 +876,16 @@ static ssize_t ep92_sysfs_rda_audio_layout(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->ai.system_status_0 & EP92_AI_LAYOUT_MASK) >> EP92_AI_LAYOUT_SHIFT; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -838,9 +897,9 @@ static ssize_t ep92_sysfs_rda_audio_ch_count(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->ai.cc & EP92_AI_CH_COUNT_MASK; @@ -849,7 +908,7 @@ static ssize_t ep92_sysfs_rda_audio_ch_count(struct device *dev, val += 1; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -861,15 +920,15 @@ static ssize_t ep92_sysfs_rda_audio_ch_alloc(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->ai.ca & EP92_AI_CH_ALLOC_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -881,9 +940,9 @@ static ssize_t ep92_sysfs_rda_avmute(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } @@ -891,7 +950,7 @@ static ssize_t ep92_sysfs_rda_avmute(struct device *dev, EP92_2CHOICE_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -903,15 +962,15 @@ static ssize_t ep92_sysfs_rda_link_on0(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->filt_link_on0; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -923,15 +982,15 @@ static ssize_t ep92_sysfs_rda_link_on1(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->filt_link_on1; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -943,15 +1002,15 @@ static ssize_t ep92_sysfs_rda_link_on2(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->filt_link_on2; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -963,15 +1022,15 @@ static ssize_t ep92_sysfs_rda_out_plug(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->filt_tx_plug; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -983,9 +1042,9 @@ static ssize_t ep92_sysfs_rda_video_latency(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->gi.video_latency & EP92_GI_VIDEO_LATENCY_MASK; @@ -993,7 +1052,7 @@ static ssize_t ep92_sysfs_rda_video_latency(struct device *dev, val = (val - 1) * 2; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1005,16 +1064,16 @@ static ssize_t ep92_sysfs_rda_arc_disable(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->gc.ctl2 >> EP92_GC_ARC_DIS_SHIFT) & EP92_2CHOICE_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1025,18 +1084,18 @@ static ssize_t ep92_sysfs_wta_arc_disable(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > 1)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1061,15 +1120,15 @@ static ssize_t ep92_sysfs_rda_power(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->gc.ctl >> EP92_GC_POWER_SHIFT) & EP92_2CHOICE_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1080,18 +1139,18 @@ static ssize_t ep92_sysfs_wta_power(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > 1)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1115,15 +1174,15 @@ static ssize_t ep92_sysfs_rda_audio_path(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->gc.ctl >> EP92_GC_AUDIO_PATH_SHIFT) & EP92_2CHOICE_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1134,18 +1193,18 @@ static ssize_t ep92_sysfs_wta_audio_path(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > 1)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1171,15 +1230,15 @@ static ssize_t ep92_sysfs_rda_src_sel(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = ep92->gc.rx_sel & EP92_GC_RX_SEL_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1190,18 +1249,18 @@ static ssize_t ep92_sysfs_wta_src_sel(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > 7)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1226,15 +1285,15 @@ static ssize_t ep92_sysfs_rda_arc_enable(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->gc.ctl >> EP92_GC_ARC_EN_SHIFT) & EP92_2CHOICE_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1245,18 +1304,18 @@ static ssize_t ep92_sysfs_wta_arc_enable(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > 1)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1281,15 +1340,15 @@ static ssize_t ep92_sysfs_rda_cec_mute(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->gc.ctl >> EP92_GC_CEC_MUTE_SHIFT) & EP92_2CHOICE_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1300,18 +1359,18 @@ static ssize_t ep92_sysfs_wta_cec_mute(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > 1)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1336,16 +1395,16 @@ static ssize_t ep92_sysfs_rda_cec_volume(struct device *dev, int val; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } val = (ep92->gc.cec_volume >> EP92_GC_CEC_VOLUME_SHIFT) & EP92_GC_CEC_VOLUME_MASK; ret = snprintf(buf, EP92_SYSFS_ENTRY_MAX_LEN, "%d\n", val); - pr_debug("%s: '%d'\n", __func__, val); + dev_dbg(dev, "%s: '%d'\n", __func__, val); return ret; } @@ -1356,18 +1415,18 @@ static ssize_t ep92_sysfs_wta_cec_volume(struct device *dev, int reg, val, rc; struct ep92_pdata *ep92 = dev_get_drvdata(dev); - if (!ep92) { - pr_err("%s: invalid input\n", __func__); - return -EINVAL; + if (!ep92 || !ep92->component) { + dev_err(dev, "%s: device error\n", __func__); + return -ENODEV; } rc = kstrtoint(buf, 10, &val); if (rc) { - pr_err("%s: kstrtoint failed. rc=%d\n", __func__, rc); + dev_err(dev, "%s: kstrtoint failed. rc=%d\n", __func__, rc); goto end; } if ((val < 0) || (val > EP92_GC_CEC_VOLUME_MAX)) { - pr_err("%s: value out of range.\n", __func__); + dev_err(dev, "%s: value out of range.\n", __func__); rc = -EINVAL; goto end; } @@ -1381,6 +1440,8 @@ end: return rc; } +static DEVICE_ATTR(chipid, 0444, ep92_sysfs_rda_chipid, NULL); +static DEVICE_ATTR(version, 0444, ep92_sysfs_rda_version, NULL); static DEVICE_ATTR(audio_state, 0444, ep92_sysfs_rda_audio_state, NULL); static DEVICE_ATTR(audio_format, 0444, ep92_sysfs_rda_audio_format, NULL); static DEVICE_ATTR(audio_rate, 0444, ep92_sysfs_rda_audio_rate, NULL); @@ -1408,6 +1469,8 @@ static DEVICE_ATTR(cec_volume, 0644, ep92_sysfs_rda_cec_volume, ep92_sysfs_wta_cec_volume); static struct attribute *ep92_fs_attrs[] = { + &dev_attr_chipid.attr, + &dev_attr_version.attr, &dev_attr_audio_state.attr, &dev_attr_audio_format.attr, &dev_attr_audio_rate.attr, @@ -1490,11 +1553,8 @@ static int ep92_i2c_probe(struct i2c_client *client, } } /* poll status if IRQ is not configured */ - if (ep92->irq == 0) { + if (ep92->irq == 0) timer_setup(&ep92->timer, ep92_poll_status, 0); - mod_timer(&ep92->timer, jiffies + - msecs_to_jiffies(EP92_POLL_INTERVAL_OFF_MSEC)); - } #if IS_ENABLED(CONFIG_DEBUG_FS) /* debugfs interface */ @@ -1529,19 +1589,19 @@ static int ep92_i2c_probe(struct i2c_client *client, } #endif /* CONFIG_DEBUG_FS */ - /* register codec */ + /* register component */ ret = snd_soc_register_component(&client->dev, &soc_codec_drv_ep92, ep92_dai, ARRAY_SIZE(ep92_dai)); if (ret) { - dev_err(&client->dev, - "%s %d: Failed to register CODEC: %d\n", - __func__, __LINE__, ret); + dev_err(&client->dev, "%s %d: Failed to register CODEC: %d\n", + __func__, __LINE__, ret); goto err_reg; } ret = ep92_sysfs_create(client, ep92); if (ret) { - pr_err("%s: sysfs creation failed ret=%d\n", __func__, ret); + dev_err(&client->dev, "%s: sysfs creation failed ret=%d\n", + __func__, ret); goto err_sysfs; }