[PATCH v3] media: i2c: ADV7604: Migrate to regmap

2015-06-19 Thread Pablo Anton
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
Acked-by: Hans Verkuil hans.verk...@cisco.com
Tested-by: Hans Verkuil hans.verk...@cisco.com
---
v3: check return value of regmap_read
start configure_regmaps from ADV7604_PAGE_AVLINK
add Acked-by and Tested-by
change some v4l2_info to v4l2_err

 drivers/media/i2c/adv7604.c | 351 
 1 file changed, 256 insertions(+), 95 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 60ffcf0..0bbf800 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);
 }
 
 /* --- */
@@ -414,14 +391,14

[PATCH v2] media: i2c: ADV7604: Migrate to regmap

2015-06-16 Thread Pablo Anton
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
---
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);
 }
 
 /* --- */
@@ -414,14 +391,14 @@ static inline int io_read(struct v4l2_subdev *sd, u8 reg)
 {
struct adv76xx_state *state = to_state(sd);
 
-   return adv_smbus_read_byte_data(state, ADV76XX_PAGE_IO, reg);
+   return adv76xx_read_check

[PATCH] media: i2c: ADV7604: Rename adv7604 prefixes.

2015-02-03 Thread Pablo Anton
It is confusing which parts of the driver are adv7604 specific, adv7611 
specific or common for both.
This patch renames any adv7604 prefixes (both for functions and defines) to 
adv76xx whenever they are common.

Signed-off-by: Pablo Anton pablo.an...@vodalys-labs.com
Signed-off-by: Jean-Michel Hautbois jean-michel.hautb...@vodalys.com
---
 drivers/media/i2c/adv7604.c | 916 ++--
 include/media/adv7604.h |  83 ++--
 2 files changed, 500 insertions(+), 499 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index e43dd2e..4837e71 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -53,41 +53,41 @@ MODULE_AUTHOR(Mats Randgaard mats.randga...@cisco.com);
 MODULE_LICENSE(GPL);
 
 /* ADV7604 system clock frequency */
-#define ADV7604_fsc (28636360)
+#define ADV76xx_fsc (28636360)
 
-#define ADV7604_RGB_OUT(1  1)
+#define ADV76XX_RGB_OUT(1  1)
 
-#define ADV7604_OP_FORMAT_SEL_8BIT (0  0)
+#define ADV76XX_OP_FORMAT_SEL_8BIT (0  0)
 #define ADV7604_OP_FORMAT_SEL_10BIT(1  0)
-#define ADV7604_OP_FORMAT_SEL_12BIT(2  0)
+#define ADV76XX_OP_FORMAT_SEL_12BIT(2  0)
 
-#define ADV7604_OP_MODE_SEL_SDR_422(0  5)
+#define ADV76XX_OP_MODE_SEL_SDR_422(0  5)
 #define ADV7604_OP_MODE_SEL_DDR_422(1  5)
-#define ADV7604_OP_MODE_SEL_SDR_444(2  5)
+#define ADV76XX_OP_MODE_SEL_SDR_444(2  5)
 #define ADV7604_OP_MODE_SEL_DDR_444(3  5)
-#define ADV7604_OP_MODE_SEL_SDR_422_2X (4  5)
+#define ADV76XX_OP_MODE_SEL_SDR_422_2X (4  5)
 #define ADV7604_OP_MODE_SEL_ADI_CM (5  5)
 
-#define ADV7604_OP_CH_SEL_GBR  (0  5)
-#define ADV7604_OP_CH_SEL_GRB  (1  5)
-#define ADV7604_OP_CH_SEL_BGR  (2  5)
-#define ADV7604_OP_CH_SEL_RGB  (3  5)
-#define ADV7604_OP_CH_SEL_BRG  (4  5)
-#define ADV7604_OP_CH_SEL_RBG  (5  5)
+#define ADV76XX_OP_CH_SEL_GBR  (0  5)
+#define ADV76XX_OP_CH_SEL_GRB  (1  5)
+#define ADV76XX_OP_CH_SEL_BGR  (2  5)
+#define ADV76XX_OP_CH_SEL_RGB  (3  5)
+#define ADV76XX_OP_CH_SEL_BRG  (4  5)
+#define ADV76XX_OP_CH_SEL_RBG  (5  5)
 
-#define ADV7604_OP_SWAP_CB_CR  (1  0)
+#define ADV76XX_OP_SWAP_CB_CR  (1  0)
 
-enum adv7604_type {
+enum adv76xx_type {
ADV7604,
ADV7611,
 };
 
-struct adv7604_reg_seq {
+struct adv76xx_reg_seq {
unsigned int reg;
u8 val;
 };
 
-struct adv7604_format_info {
+struct adv76xx_format_info {
u32 code;
u8 op_ch_sel;
bool rgb_out;
@@ -95,8 +95,8 @@ struct adv7604_format_info {
u8 op_format_sel;
 };
 
-struct adv7604_chip_info {
-   enum adv7604_type type;
+struct adv76xx_chip_info {
+   enum adv76xx_type type;
 
bool has_afe;
unsigned int max_port;
@@ -110,7 +110,7 @@ struct adv7604_chip_info {
unsigned int tdms_lock_mask;
unsigned int fmt_change_digital_mask;
 
-   const struct adv7604_format_info *formats;
+   const struct adv76xx_format_info *formats;
unsigned int nformats;
 
void (*set_termination)(struct v4l2_subdev *sd, bool enable);
@@ -119,7 +119,7 @@ struct adv7604_chip_info {
unsigned int (*read_cable_det)(struct v4l2_subdev *sd);
 
/* 0 = AFE, 1 = HDMI */
-   const struct adv7604_reg_seq *recommended_settings[2];
+   const struct adv76xx_reg_seq *recommended_settings[2];
unsigned int num_recommended_settings[2];
 
unsigned long page_mask;
@@ -133,22 +133,22 @@ struct adv7604_chip_info {
  **
  */
 
-struct adv7604_state {
-   const struct adv7604_chip_info *info;
-   struct adv7604_platform_data pdata;
+struct adv76xx_state {
+   const struct adv76xx_chip_info *info;
+   struct adv76xx_platform_data pdata;
 
struct gpio_desc *hpd_gpio[4];
 
struct v4l2_subdev sd;
-   struct media_pad pads[ADV7604_PAD_MAX];
+   struct media_pad pads[ADV76XX_PAD_MAX];
unsigned int source_pad;
 
struct v4l2_ctrl_handler hdl;
 
-   enum adv7604_pad selected_input;
+   enum adv76xx_pad selected_input;
 
struct v4l2_dv_timings timings;
-   const struct adv7604_format_info *format;
+   const struct adv76xx_format_info *format;
 
struct {
u8 edid[256];
@@ -163,7 +163,7 @@ struct adv7604_state {
bool