From: Greg Kroah-Hartman Date: Sun, 16 Oct 2022 07:28:07 +0000 (+0200) Subject: 4.9-stable patches X-Git-Tag: v5.4.219~177 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1e6749740b4b75aed0973822c10d94db5b82825e;p=thirdparty%2Fkernel%2Fstable-queue.git 4.9-stable patches added patches: iio-dac-ad5593r-fix-i2c-read-protocol-requirements.patch --- diff --git a/queue-4.9/iio-dac-ad5593r-fix-i2c-read-protocol-requirements.patch b/queue-4.9/iio-dac-ad5593r-fix-i2c-read-protocol-requirements.patch new file mode 100644 index 00000000000..b4088dfa9b8 --- /dev/null +++ b/queue-4.9/iio-dac-ad5593r-fix-i2c-read-protocol-requirements.patch @@ -0,0 +1,113 @@ +From 558a25f903b4af6361b7fbeea08a6446a0745653 Mon Sep 17 00:00:00 2001 +From: Michael Hennerich +Date: Tue, 13 Sep 2022 09:34:12 +0200 +Subject: iio: dac: ad5593r: Fix i2c read protocol requirements +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Michael Hennerich + +commit 558a25f903b4af6361b7fbeea08a6446a0745653 upstream. + +For reliable operation across the full range of supported +interface rates, the AD5593R needs a STOP condition between +address write, and data read (like show in the datasheet Figure 40) +so in turn i2c_smbus_read_word_swapped cannot be used. + +While at it, a simple helper was added to make the code simpler. + +Fixes: 56ca9db862bf ("iio: dac: Add support for the AD5592R/AD5593R ADCs/DACs") +Signed-off-by: Michael Hennerich +Signed-off-by: Nuno Sá +Cc: +Link: https://lore.kernel.org/r/20220913073413.140475-2-nuno.sa@analog.com +Signed-off-by: Jonathan Cameron +Signed-off-by: Greg Kroah-Hartman +--- + drivers/iio/dac/ad5593r.c | 46 +++++++++++++++++++++++++++------------------- + 1 file changed, 27 insertions(+), 19 deletions(-) + +--- a/drivers/iio/dac/ad5593r.c ++++ b/drivers/iio/dac/ad5593r.c +@@ -14,6 +14,8 @@ + #include + #include + ++#include ++ + #define AD5593R_MODE_CONF (0 << 4) + #define AD5593R_MODE_DAC_WRITE (1 << 4) + #define AD5593R_MODE_ADC_READBACK (4 << 4) +@@ -21,6 +23,24 @@ + #define AD5593R_MODE_GPIO_READBACK (6 << 4) + #define AD5593R_MODE_REG_READBACK (7 << 4) + ++static int ad5593r_read_word(struct i2c_client *i2c, u8 reg, u16 *value) ++{ ++ int ret; ++ u8 buf[2]; ++ ++ ret = i2c_smbus_write_byte(i2c, reg); ++ if (ret < 0) ++ return ret; ++ ++ ret = i2c_master_recv(i2c, buf, sizeof(buf)); ++ if (ret < 0) ++ return ret; ++ ++ *value = get_unaligned_be16(buf); ++ ++ return 0; ++} ++ + static int ad5593r_write_dac(struct ad5592r_state *st, unsigned chan, u16 value) + { + struct i2c_client *i2c = to_i2c_client(st->dev); +@@ -39,13 +59,7 @@ static int ad5593r_read_adc(struct ad559 + if (val < 0) + return (int) val; + +- val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_ADC_READBACK); +- if (val < 0) +- return (int) val; +- +- *value = (u16) val; +- +- return 0; ++ return ad5593r_read_word(i2c, AD5593R_MODE_ADC_READBACK, value); + } + + static int ad5593r_reg_write(struct ad5592r_state *st, u8 reg, u16 value) +@@ -59,25 +73,19 @@ static int ad5593r_reg_write(struct ad55 + static int ad5593r_reg_read(struct ad5592r_state *st, u8 reg, u16 *value) + { + struct i2c_client *i2c = to_i2c_client(st->dev); +- s32 val; +- +- val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_REG_READBACK | reg); +- if (val < 0) +- return (int) val; + +- *value = (u16) val; +- +- return 0; ++ return ad5593r_read_word(i2c, AD5593R_MODE_REG_READBACK | reg, value); + } + + static int ad5593r_gpio_read(struct ad5592r_state *st, u8 *value) + { + struct i2c_client *i2c = to_i2c_client(st->dev); +- s32 val; ++ u16 val; ++ int ret; + +- val = i2c_smbus_read_word_swapped(i2c, AD5593R_MODE_GPIO_READBACK); +- if (val < 0) +- return (int) val; ++ ret = ad5593r_read_word(i2c, AD5593R_MODE_GPIO_READBACK, &val); ++ if (ret) ++ return ret; + + *value = (u8) val; + diff --git a/queue-4.9/series b/queue-4.9/series index e8225e91911..984c05e23ff 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -42,3 +42,4 @@ alsa-oss-fix-potential-deadlock-at-unregistration.patch alsa-rawmidi-drop-register_mutex-in-snd_rawmidi_free.patch alsa-usb-audio-fix-potential-memory-leaks.patch alsa-usb-audio-fix-null-dererence-at-error-path.patch +iio-dac-ad5593r-fix-i2c-read-protocol-requirements.patch