From: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: <alsa-devel@alsa-project.org>, <patches@opensource.cirrus.com>,
<linux-kernel@vger.kernel.org>,
Stefan Binding <sbinding@opensource.cirrus.com>
Subject: [PATCH v1 1/4] ALSA: hda/cirrus: Add error handling into CS8409 I2C functions
Date: Sat, 13 Mar 2021 11:34:07 +0000 [thread overview]
Message-ID: <20210313113410.90088-2-vitalyr@opensource.cirrus.com> (raw)
In-Reply-To: <20210313113410.90088-1-vitalyr@opensource.cirrus.com>
From: Stefan Binding <sbinding@opensource.cirrus.com>
Tested on DELL Inspiron-3505, DELL Inspiron-3501, DELL Inspiron-3500
Signed-off-by: Stefan Binding <sbinding@opensource.cirrus.com>
Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
Changes in v1:
- No changes
---
sound/pci/hda/patch_cirrus.c | 95 +++++++++++++++++++++---------------
1 file changed, 56 insertions(+), 39 deletions(-)
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 6a9e5c803977..ca8b522b1d6d 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -1508,7 +1508,7 @@ static void cs8409_enable_i2c_clock(struct hda_codec *codec, unsigned int flag)
static int cs8409_i2c_wait_complete(struct hda_codec *codec)
{
int repeat = 5;
- unsigned int retval = 0;
+ unsigned int retval;
do {
retval = cs_vendor_coef_get(codec, CIR_I2C_STATUS);
@@ -1520,78 +1520,82 @@ static int cs8409_i2c_wait_complete(struct hda_codec *codec)
} while (repeat);
- return repeat > 0 ? 0 : -1;
+ return !!repeat;
}
-/* CS8409 slave i2cRead */
-static unsigned int cs8409_i2c_read(struct hda_codec *codec,
+/* CS8409 slave i2cRead.
+ * Returns negative on error, otherwise returns read value in bits 0-7.
+ */
+static int cs8409_i2c_read(struct hda_codec *codec,
unsigned int i2c_address,
unsigned int i2c_reg,
unsigned int paged)
{
unsigned int i2c_reg_data;
- unsigned int retval = 0;
+ unsigned int read_data;
cs8409_enable_i2c_clock(codec, 1);
cs_vendor_coef_set(codec, CIR_I2C_ADDR, i2c_address);
if (paged) {
cs_vendor_coef_set(codec, CIR_I2C_QWRITE, i2c_reg >> 8);
- if (cs8409_i2c_wait_complete(codec) == -1) {
+ if (!cs8409_i2c_wait_complete(codec)) {
codec_err(codec,
- "%s() Paged Transaction Failed 0x%02x : 0x%04x = 0x%02x\n",
- __func__, i2c_address, i2c_reg, retval);
+ "%s() Paged Transaction Failed 0x%02x : 0x%04x\n",
+ __func__, i2c_address, i2c_reg);
+ return -EIO;
}
}
i2c_reg_data = (i2c_reg << 8) & 0x0ffff;
cs_vendor_coef_set(codec, CIR_I2C_QREAD, i2c_reg_data);
- if (cs8409_i2c_wait_complete(codec) == -1) {
- codec_err(codec, "%s() Transaction Failed 0x%02x : 0x%04x = 0x%02x\n",
- __func__, i2c_address, i2c_reg, retval);
+ if (!cs8409_i2c_wait_complete(codec)) {
+ codec_err(codec, "%s() Transaction Failed 0x%02x : 0x%04x\n",
+ __func__, i2c_address, i2c_reg);
+ return -EIO;
}
/* Register in bits 15-8 and the data in 7-0 */
- retval = cs_vendor_coef_get(codec, CIR_I2C_QREAD);
- retval &= 0x0ff;
+ read_data = cs_vendor_coef_get(codec, CIR_I2C_QREAD);
cs8409_enable_i2c_clock(codec, 0);
- return retval;
+ return read_data & 0x0ff;
}
/* CS8409 slave i2cWrite */
-static unsigned int cs8409_i2c_write(struct hda_codec *codec,
+static int cs8409_i2c_write(struct hda_codec *codec,
unsigned int i2c_address, unsigned int i2c_reg,
unsigned int i2c_data,
unsigned int paged)
{
- unsigned int retval = 0;
- unsigned int i2c_reg_data = 0;
+ unsigned int i2c_reg_data;
cs8409_enable_i2c_clock(codec, 1);
cs_vendor_coef_set(codec, CIR_I2C_ADDR, i2c_address);
if (paged) {
cs_vendor_coef_set(codec, CIR_I2C_QWRITE, i2c_reg >> 8);
- if (cs8409_i2c_wait_complete(codec) == -1) {
+ if (!cs8409_i2c_wait_complete(codec)) {
codec_err(codec,
- "%s() Paged Transaction Failed 0x%02x : 0x%04x = 0x%02x\n",
- __func__, i2c_address, i2c_reg, retval);
+ "%s() Paged Transaction Failed 0x%02x : 0x%04x\n",
+ __func__, i2c_address, i2c_reg);
+ return -EIO;
}
}
i2c_reg_data = ((i2c_reg << 8) & 0x0ff00) | (i2c_data & 0x0ff);
cs_vendor_coef_set(codec, CIR_I2C_QWRITE, i2c_reg_data);
- if (cs8409_i2c_wait_complete(codec) == -1) {
- codec_err(codec, "%s() Transaction Failed 0x%02x : 0x%04x = 0x%02x\n",
- __func__, i2c_address, i2c_reg, retval);
+ if (!cs8409_i2c_wait_complete(codec)) {
+ codec_err(codec, "%s() Transaction Failed 0x%02x : 0x%04x\n",
+ __func__, i2c_address, i2c_reg);
+ return -EIO;
}
cs8409_enable_i2c_clock(codec, 0);
- return retval;
+ return 0;
}
static int cs8409_cs42l42_volume_info(struct snd_kcontrol *kcontrol,
@@ -1624,14 +1628,27 @@ static int cs8409_cs42l42_volume_info(struct snd_kcontrol *kcontrol,
static void cs8409_cs42l42_update_volume(struct hda_codec *codec)
{
struct cs_spec *spec = codec->spec;
+ int data;
mutex_lock(&spec->cs8409_i2c_mux);
- spec->cs42l42_hp_volume[0] = -(cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
- CS8409_CS42L42_REG_HS_VOLUME_CHA, 1));
- spec->cs42l42_hp_volume[1] = -(cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
- CS8409_CS42L42_REG_HS_VOLUME_CHB, 1));
- spec->cs42l42_hs_mic_volume[0] = -(cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
- CS8409_CS42L42_REG_AMIC_VOLUME, 1));
+ data = cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
+ CS8409_CS42L42_REG_HS_VOLUME_CHA, 1);
+ if (data >= 0)
+ spec->cs42l42_hp_volume[0] = -data;
+ else
+ spec->cs42l42_hp_volume[0] = CS8409_CS42L42_HP_VOL_REAL_MIN;
+ data = cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
+ CS8409_CS42L42_REG_HS_VOLUME_CHB, 1);
+ if (data >= 0)
+ spec->cs42l42_hp_volume[1] = -data;
+ else
+ spec->cs42l42_hp_volume[1] = CS8409_CS42L42_HP_VOL_REAL_MIN;
+ data = cs8409_i2c_read(codec, CS42L42_I2C_ADDR,
+ CS8409_CS42L42_REG_AMIC_VOLUME, 1);
+ if (data >= 0)
+ spec->cs42l42_hs_mic_volume[0] = -data;
+ else
+ spec->cs42l42_hs_mic_volume[0] = CS8409_CS42L42_AMIC_VOL_REAL_MIN;
mutex_unlock(&spec->cs8409_i2c_mux);
spec->cs42l42_volume_init = 1;
}
@@ -1782,7 +1799,7 @@ static void cs8409_cs42l42_reset(struct hda_codec *codec)
}
/* Configure CS42L42 slave codec for jack autodetect */
-static int cs8409_cs42l42_enable_jack_detect(struct hda_codec *codec)
+static void cs8409_cs42l42_enable_jack_detect(struct hda_codec *codec)
{
struct cs_spec *spec = codec->spec;
@@ -1804,8 +1821,6 @@ static int cs8409_cs42l42_enable_jack_detect(struct hda_codec *codec)
cs8409_i2c_write(codec, CS42L42_I2C_ADDR, 0x1b79, 0x00, 1);
mutex_unlock(&spec->cs8409_i2c_mux);
-
- return 0;
}
/* Enable and run CS42L42 slave codec jack auto detect */
@@ -1860,9 +1875,9 @@ static void cs8409_jack_unsol_event(struct hda_codec *codec, unsigned int res)
{
struct cs_spec *spec = codec->spec;
int status_changed = 0;
- unsigned int reg_cdc_status = 0;
- unsigned int reg_hs_status = 0;
- unsigned int reg_ts_status = 0;
+ int reg_cdc_status;
+ int reg_hs_status;
+ int reg_ts_status;
int type = 0;
struct hda_jack_tbl *jk;
@@ -1881,13 +1896,15 @@ static void cs8409_jack_unsol_event(struct hda_codec *codec, unsigned int res)
reg_hs_status = cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1124, 1);
reg_ts_status = cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x130f, 1);
- /* Clear interrupts */
+ /* Clear interrupts, by reading interrupt status registers */
cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1b7b, 1);
- cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x1308, 1);
- cs8409_i2c_read(codec, CS42L42_I2C_ADDR, 0x130f, 1);
mutex_unlock(&spec->cs8409_i2c_mux);
+ /* If status values are < 0, read error has occurred. */
+ if ((reg_cdc_status < 0) || (reg_hs_status < 0) || (reg_ts_status < 0))
+ return;
+
/* HSDET_AUTO_DONE */
if (reg_cdc_status & CS42L42_HSDET_AUTO_DONE) {
--
2.25.1
next prev parent reply other threads:[~2021-03-13 11:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-13 11:34 [PATCH v1 0/4] ALSA: hda/cirrus: Make CS8409 driver more generic by using fixups Vitaly Rodionov
2021-03-13 11:34 ` Vitaly Rodionov [this message]
2021-03-15 7:45 ` [PATCH v1 1/4] ALSA: hda/cirrus: Add error handling into CS8409 I2C functions Takashi Iwai
2021-03-15 15:37 ` Vitaly Rodionov
2021-03-15 15:41 ` Takashi Iwai
2021-03-13 11:34 ` [PATCH v1 2/4] ALSA: hda/cirrus: Cleanup patch_cirrus.c code Vitaly Rodionov
2021-03-13 11:34 ` [PATCH v1 3/4] ALSA: hda/cirrus: Fix CS42L42 Headset Mic volume control name Vitaly Rodionov
2021-03-13 11:34 ` [PATCH v1 4/4] ALSA: hda/cirrus: Make CS8409 driver more generic by using fixups Vitaly Rodionov
2021-03-15 7:49 ` Takashi Iwai
2021-03-15 15:39 ` Vitaly Rodionov
2021-03-14 8:36 ` [PATCH v1 0/4] " Takashi Iwai
2021-03-14 10:18 ` Vitaly Rodionov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210313113410.90088-2-vitalyr@opensource.cirrus.com \
--to=vitalyr@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=perex@perex.cz \
--cc=sbinding@opensource.cirrus.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).