On 06/16/2015 10:38 AM, Pablo Anton wrote:
This is a preliminary patch in order to add support for ALSA.
It replaces all current i2c access with regmap.
Signed-off-by: Pablo Anton pablo.an...@veo-labs.com
Signed-off-by: Jean-Michel Hautbois jean-michel.hautb...@veo-labs.com
After fixing the missing return value check that Lars-Peter found you can
add my:
Acked-by: Hans Verkuil hans.verk...@cisco.com
Tested-by: Hans Verkuil hans.verk...@cisco.com
Regards,
Hans
---
v2: Rebase after renaming
drivers/media/i2c/adv7604.c | 337
1 file changed, 244 insertions(+), 93 deletions(-)
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 60ffcf0..38ae454 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -36,6 +36,7 @@
#include linux/v4l2-dv-timings.h
#include linux/videodev2.h
#include linux/workqueue.h
+#include linux/regmap.h
#include media/adv7604.h
#include media/v4l2-ctrls.h
@@ -166,6 +167,9 @@ struct adv76xx_state {
/* i2c clients */
struct i2c_client *i2c_clients[ADV76XX_PAGE_MAX];
+ /* Regmaps */
+ struct regmap *regmap[ADV76XX_PAGE_MAX];
+
/* controls */
struct v4l2_ctrl *detect_tx_5v_ctrl;
struct v4l2_ctrl *analog_sampling_phase_ctrl;
@@ -346,66 +350,39 @@ static inline unsigned vtotal(const struct
v4l2_bt_timings *t)
/* --- */
-static s32 adv_smbus_read_byte_data_check(struct i2c_client *client,
- u8 command, bool check)
-{
- union i2c_smbus_data data;
-
- if (!i2c_smbus_xfer(client-adapter, client-addr, client-flags,
- I2C_SMBUS_READ, command,
- I2C_SMBUS_BYTE_DATA, data))
- return data.byte;
- if (check)
- v4l_err(client, error reading %02x, %02x\n,
- client-addr, command);
- return -EIO;
-}
-
-static s32 adv_smbus_read_byte_data(struct adv76xx_state *state,
- enum adv76xx_page page, u8 command)
+static int adv76xx_read_check(struct adv76xx_state *state,
+ int client_page, u8 reg)
{
- return adv_smbus_read_byte_data_check(state-i2c_clients[page],
- command, true);
-}
-
-static s32 adv_smbus_write_byte_data(struct adv76xx_state *state,
- enum adv76xx_page page, u8 command,
- u8 value)
-{
- struct i2c_client *client = state-i2c_clients[page];
- union i2c_smbus_data data;
+ struct i2c_client *client = state-i2c_clients[client_page];
int err;
- int i;
+ unsigned int val;
- data.byte = value;
- for (i = 0; i 3; i++) {
- err = i2c_smbus_xfer(client-adapter, client-addr,
- client-flags,
- I2C_SMBUS_WRITE, command,
- I2C_SMBUS_BYTE_DATA, data);
- if (!err)
- break;
+ err = regmap_read(state-regmap[client_page], reg, val);
+
+ if (err) {
+ v4l_err(client, error reading %02x, %02x\n,
+ client-addr, reg);
+ return err;
}
- if (err 0)
- v4l_err(client, error writing %02x, %02x, %02x\n,
- client-addr, command, value);
- return err;
+ return val;
}
-static s32 adv_smbus_write_i2c_block_data(struct adv76xx_state *state,
- enum adv76xx_page page, u8 command,
- unsigned length, const u8 *values)
+/* adv76xx_write_block(): Write raw data with a maximum of
I2C_SMBUS_BLOCK_MAX
+ * size to one or more registers.
+ *
+ * A value of zero will be returned on success, a negative errno will
+ * be returned in error cases.
+ */
+static int adv76xx_write_block(struct adv76xx_state *state, int client_page,
+ unsigned int init_reg, const void *val,
+ size_t val_len)
{
- struct i2c_client *client = state-i2c_clients[page];
- union i2c_smbus_data data;
+ struct regmap *regmap = state-regmap[client_page];
+
+ if (val_len I2C_SMBUS_BLOCK_MAX)
+ val_len = I2C_SMBUS_BLOCK_MAX;
- if (length I2C_SMBUS_BLOCK_MAX)
- length = I2C_SMBUS_BLOCK_MAX;
- data.block[0] = length;
- memcpy(data.block + 1, values, length);
- return i2c_smbus_xfer(client-adapter, client-addr, client-flags,
- I2C_SMBUS_WRITE, command,
- I2C_SMBUS_I2C_BLOCK_DATA, data);
+ return regmap_raw_write(regmap, init_reg, val, val_len);
}
/* --- */