* [PATCH V3 01/13] cx231xx: let i2c bus scanning use its own i2c_client
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 02/13] cx231xx: use own i2c_client for eeprom access Matthias Schwarzott
` (11 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
This is a preparation for deleting the otherwise useless i2c_clients
that are allocated for all the i2c master adapters.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-i2c.c | 17 +++++++++++------
drivers/media/usb/cx231xx/cx231xx.h | 2 +-
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 7c0f797..67a1391 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -480,22 +480,27 @@ static char *i2c_devs[128] = {
* cx231xx_do_i2c_scan()
* check i2c address range for devices
*/
-void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c)
+void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
{
unsigned char buf;
int i, rc;
+ struct i2c_client client;
- cx231xx_info(": Checking for I2C devices ..\n");
+ memset(&client, 0, sizeof(client));
+ client.adapter = &dev->i2c_bus[i2c_port].i2c_adap;
+
+ cx231xx_info(": Checking for I2C devices on port=%d ..\n", i2c_port);
for (i = 0; i < 128; i++) {
- c->addr = i;
- rc = i2c_master_recv(c, &buf, 0);
+ client.addr = i;
+ rc = i2c_master_recv(&client, &buf, 0);
if (rc < 0)
continue;
cx231xx_info("%s: i2c scan: found device @ 0x%x [%s]\n",
dev->name, i << 1,
i2c_devs[i] ? i2c_devs[i] : "???");
}
- cx231xx_info(": Completed Checking for I2C devices.\n");
+ cx231xx_info(": Completed Checking for I2C devices on port=%d.\n",
+ i2c_port);
}
/*
@@ -522,7 +527,7 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
if (0 == bus->i2c_rc) {
if (i2c_scan)
- cx231xx_do_i2c_scan(dev, &bus->i2c_client);
+ cx231xx_do_i2c_scan(dev, bus->nr);
} else
cx231xx_warn("%s: i2c bus %d register FAILED\n",
dev->name, bus->nr);
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index aeb1bf4..5efc93e 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -751,7 +751,7 @@ int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
int cx231xx_reset_analog_tuner(struct cx231xx *dev);
/* Provided by cx231xx-i2c.c */
-void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
+void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
int cx231xx_i2c_register(struct cx231xx_i2c *bus);
int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 02/13] cx231xx: use own i2c_client for eeprom access
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 01/13] cx231xx: let i2c bus scanning use its own i2c_client Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 03/13] cx231xx: delete i2c_client per bus Matthias Schwarzott
` (10 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
This is a preparation for deleting the otherwise useless i2c_clients
that are allocated for all the i2c master adapters.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-cards.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 791f00c..092fb85 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -980,23 +980,20 @@ static void cx231xx_config_tuner(struct cx231xx *dev)
}
-static int read_eeprom(struct cx231xx *dev, u8 *eedata, int len)
+static int read_eeprom(struct cx231xx *dev, struct i2c_client *client,
+ u8 *eedata, int len)
{
int ret = 0;
- u8 addr = 0xa0 >> 1;
u8 start_offset = 0;
int len_todo = len;
u8 *eedata_cur = eedata;
int i;
- struct i2c_msg msg_write = { .addr = addr, .flags = 0,
+ struct i2c_msg msg_write = { .addr = client->addr, .flags = 0,
.buf = &start_offset, .len = 1 };
- struct i2c_msg msg_read = { .addr = addr, .flags = I2C_M_RD };
-
- /* mutex_lock(&dev->i2c_lock); */
- cx231xx_enable_i2c_port_3(dev, false);
+ struct i2c_msg msg_read = { .addr = client->addr, .flags = I2C_M_RD };
/* start reading at offset 0 */
- ret = i2c_transfer(&dev->i2c_bus[1].i2c_adap, &msg_write, 1);
+ ret = i2c_transfer(client->adapter, &msg_write, 1);
if (ret < 0) {
cx231xx_err("Can't read eeprom\n");
return ret;
@@ -1006,7 +1003,7 @@ static int read_eeprom(struct cx231xx *dev, u8 *eedata, int len)
msg_read.len = (len_todo > 64) ? 64 : len_todo;
msg_read.buf = eedata_cur;
- ret = i2c_transfer(&dev->i2c_bus[1].i2c_adap, &msg_read, 1);
+ ret = i2c_transfer(client->adapter, &msg_read, 1);
if (ret < 0) {
cx231xx_err("Can't read eeprom\n");
return ret;
@@ -1062,9 +1059,14 @@ void cx231xx_card_setup(struct cx231xx *dev)
{
struct tveeprom tvee;
static u8 eeprom[256];
+ struct i2c_client client;
+
+ memset(&client, 0, sizeof(client));
+ client.adapter = &dev->i2c_bus[1].i2c_adap;
+ client.addr = 0xa0 >> 1;
- read_eeprom(dev, eeprom, sizeof(eeprom));
- tveeprom_hauppauge_analog(&dev->i2c_bus[1].i2c_client,
+ read_eeprom(dev, &client, eeprom, sizeof(eeprom));
+ tveeprom_hauppauge_analog(&client,
&tvee, eeprom + 0xc0);
break;
}
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 03/13] cx231xx: delete i2c_client per bus
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 01/13] cx231xx: let i2c bus scanning use its own i2c_client Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 02/13] cx231xx: use own i2c_client for eeprom access Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 04/13] cx231xx: give each master i2c bus a seperate name Matthias Schwarzott
` (9 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
For each i2c master there is a i2c_client allocated that could be
deleted now that its only two users have been changed to use their
own i2c_client.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-i2c.c | 7 -------
drivers/media/usb/cx231xx/cx231xx.h | 1 -
2 files changed, 8 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 67a1391..a30d400 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -455,10 +455,6 @@ static struct i2c_adapter cx231xx_adap_template = {
.algo = &cx231xx_algo,
};
-static struct i2c_client cx231xx_client_template = {
- .name = "cx231xx internal",
-};
-
/* ----------------------------------------------------------- */
/*
@@ -514,7 +510,6 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
BUG_ON(!dev->cx231xx_send_usb_command);
bus->i2c_adap = cx231xx_adap_template;
- bus->i2c_client = cx231xx_client_template;
bus->i2c_adap.dev.parent = &dev->udev->dev;
strlcpy(bus->i2c_adap.name, bus->dev->name, sizeof(bus->i2c_adap.name));
@@ -523,8 +518,6 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
i2c_add_adapter(&bus->i2c_adap);
- bus->i2c_client.adapter = &bus->i2c_adap;
-
if (0 == bus->i2c_rc) {
if (i2c_scan)
cx231xx_do_i2c_scan(dev, bus->nr);
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 5efc93e..c92382f 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -472,7 +472,6 @@ struct cx231xx_i2c {
/* i2c i/o */
struct i2c_adapter i2c_adap;
- struct i2c_client i2c_client;
u32 i2c_rc;
/* different settings for each bus */
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 04/13] cx231xx: give each master i2c bus a seperate name
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (2 preceding siblings ...)
2014-10-02 5:20 ` [PATCH V3 03/13] cx231xx: delete i2c_client per bus Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:25 ` Antti Palosaari
2014-10-02 5:20 ` [PATCH V3 05/13] cx231xx: Modifiy the symbolic constants for i2c ports and describe Matthias Schwarzott
` (8 subsequent siblings)
12 siblings, 1 reply; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
V2: Use snprintf to construct the complete name
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/usb/cx231xx/cx231xx-i2c.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index a30d400..b10f482 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -506,13 +506,14 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
int cx231xx_i2c_register(struct cx231xx_i2c *bus)
{
struct cx231xx *dev = bus->dev;
+ char bus_name[3];
BUG_ON(!dev->cx231xx_send_usb_command);
bus->i2c_adap = cx231xx_adap_template;
bus->i2c_adap.dev.parent = &dev->udev->dev;
- strlcpy(bus->i2c_adap.name, bus->dev->name, sizeof(bus->i2c_adap.name));
+ snprintf(bus->i2c_adap.name, sizeof(bus->i2c_adap.name), "%s-%d", bus->dev->name, bus->nr);
bus->i2c_adap.algo_data = bus;
i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH V3 04/13] cx231xx: give each master i2c bus a seperate name
2014-10-02 5:20 ` [PATCH V3 04/13] cx231xx: give each master i2c bus a seperate name Matthias Schwarzott
@ 2014-10-02 5:25 ` Antti Palosaari
0 siblings, 0 replies; 17+ messages in thread
From: Antti Palosaari @ 2014-10-02 5:25 UTC (permalink / raw)
To: Matthias Schwarzott, linux-media, mchehab
On 10/02/2014 08:20 AM, Matthias Schwarzott wrote:
> V2: Use snprintf to construct the complete name
>
> Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
> ---
> drivers/media/usb/cx231xx/cx231xx-i2c.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
> index a30d400..b10f482 100644
> --- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
> +++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
> @@ -506,13 +506,14 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
> int cx231xx_i2c_register(struct cx231xx_i2c *bus)
> {
> struct cx231xx *dev = bus->dev;
> + char bus_name[3];
you don't need that variable anymore :]
>
> BUG_ON(!dev->cx231xx_send_usb_command);
>
> bus->i2c_adap = cx231xx_adap_template;
> bus->i2c_adap.dev.parent = &dev->udev->dev;
>
> - strlcpy(bus->i2c_adap.name, bus->dev->name, sizeof(bus->i2c_adap.name));
> + snprintf(bus->i2c_adap.name, sizeof(bus->i2c_adap.name), "%s-%d", bus->dev->name, bus->nr);
>
> bus->i2c_adap.algo_data = bus;
> i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
>
With a correction for small mistake I mentioned:
Reviewed-by: Antti Palosaari <crope@iki.fi>
regards
Antti
--
http://palosaari.fi/
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH V3 05/13] cx231xx: Modifiy the symbolic constants for i2c ports and describe
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (3 preceding siblings ...)
2014-10-02 5:20 ` [PATCH V3 04/13] cx231xx: give each master i2c bus a seperate name Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 06/13] cx231xx: Use symbolic constants for i2c ports instead of numbers Matthias Schwarzott
` (7 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
Change to I2C_0 ... I2C_2 for the master ports
and add I2C_1_MUX_1 and I2C_1_MUX_3 for the muxed ones.
V2: Renamed mux adapters to seperate them from master adapters.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx.h | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index c92382f..377216b 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -322,10 +322,11 @@ enum cx231xx_decoder {
};
enum CX231XX_I2C_MASTER_PORT {
- I2C_0 = 0,
- I2C_1 = 1,
- I2C_2 = 2,
- I2C_3 = 3
+ I2C_0 = 0, /* master 0 - internal connection */
+ I2C_1 = 1, /* master 1 - used with mux */
+ I2C_2 = 2, /* master 2 */
+ I2C_1_MUX_1 = 3, /* master 1 - port 1 (I2C_DEMOD_EN = 0) */
+ I2C_1_MUX_3 = 4 /* master 1 - port 3 (I2C_DEMOD_EN = 1) */
};
struct cx231xx_board {
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 06/13] cx231xx: Use symbolic constants for i2c ports instead of numbers
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (4 preceding siblings ...)
2014-10-02 5:20 ` [PATCH V3 05/13] cx231xx: Modifiy the symbolic constants for i2c ports and describe Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:20 ` [PATCH V3 07/13] cx231xx: add wrapper to get the i2c_adapter pointer Matthias Schwarzott
` (6 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
Replace numbers by the constants of same value and same meaning.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-cards.c | 62 +++++++++++++++----------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 092fb85..2f027c7 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -104,8 +104,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -144,8 +144,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
.norm = V4L2_STD_NTSC,
@@ -184,8 +184,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -225,8 +225,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -297,8 +297,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
.norm = V4L2_STD_PAL,
@@ -325,8 +325,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
.norm = V4L2_STD_NTSC,
@@ -353,8 +353,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
.norm = V4L2_STD_NTSC,
@@ -418,9 +418,9 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_scl_gpio = -1,
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 2,
- .demod_i2c_master = 1,
- .ir_i2c_master = 2,
+ .tuner_i2c_master = I2C_2,
+ .demod_i2c_master = I2C_1,
+ .ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
.norm = V4L2_STD_PAL_M,
@@ -456,9 +456,9 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_scl_gpio = -1,
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 2,
- .demod_i2c_master = 1,
- .ir_i2c_master = 2,
+ .tuner_i2c_master = I2C_2,
+ .demod_i2c_master = I2C_1,
+ .ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
.norm = V4L2_STD_NTSC_M,
@@ -494,9 +494,9 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_scl_gpio = -1,
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 2,
- .demod_i2c_master = 1,
- .ir_i2c_master = 2,
+ .tuner_i2c_master = I2C_2,
+ .demod_i2c_master = I2C_1,
+ .ir_i2c_master = I2C_2,
.rc_map_name = RC_MAP_PIXELVIEW_002T,
.has_dvb = 1,
.demod_addr = 0x10,
@@ -587,7 +587,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
+ .tuner_i2c_master = I2C_1,
.norm = V4L2_STD_PAL,
.input = {{
@@ -622,7 +622,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
+ .tuner_i2c_master = I2C_1,
.norm = V4L2_STD_NTSC,
.input = {{
@@ -718,8 +718,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
.norm = V4L2_STD_PAL,
@@ -757,8 +757,8 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = 1,
- .demod_i2c_master = 2,
+ .tuner_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
.norm = V4L2_STD_PAL,
@@ -1033,7 +1033,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
/* request some modules */
if (dev->board.decoder == CX231XX_AVDECODER) {
dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
- &dev->i2c_bus[0].i2c_adap,
+ &dev->i2c_bus[I2C_0].i2c_adap,
"cx25840", 0x88 >> 1, NULL);
if (dev->sd_cx25840 == NULL)
cx231xx_info("cx25840 subdev registration failure\n");
@@ -1062,7 +1062,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
struct i2c_client client;
memset(&client, 0, sizeof(client));
- client.adapter = &dev->i2c_bus[1].i2c_adap;
+ client.adapter = &dev->i2c_bus[I2C_1].i2c_adap;
client.addr = 0xa0 >> 1;
read_eeprom(dev, &client, eeprom, sizeof(eeprom));
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 07/13] cx231xx: add wrapper to get the i2c_adapter pointer
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (5 preceding siblings ...)
2014-10-02 5:20 ` [PATCH V3 06/13] cx231xx: Use symbolic constants for i2c ports instead of numbers Matthias Schwarzott
@ 2014-10-02 5:20 ` Matthias Schwarzott
2014-10-02 5:21 ` [PATCH V3 08/13] cx231xx: remember status of i2c port_3 switch Matthias Schwarzott
` (5 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:20 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
This is a preparation for mapping I2C_1_MUX_1 and I2C_1_MUX_3 later to the seperate
muxed i2c adapters.
Map mux adapters to I2C_1 for now.
Add local variables for i2c_adapters in dvb_init to get line lengths
shorter.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-cards.c | 8 +++---
drivers/media/usb/cx231xx/cx231xx-dvb.c | 42 +++++++++++++++++--------------
drivers/media/usb/cx231xx/cx231xx-i2c.c | 20 ++++++++++++++-
drivers/media/usb/cx231xx/cx231xx-input.c | 3 ++-
drivers/media/usb/cx231xx/cx231xx.h | 1 +
5 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 2f027c7..f5fb93a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1033,7 +1033,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
/* request some modules */
if (dev->board.decoder == CX231XX_AVDECODER) {
dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
- &dev->i2c_bus[I2C_0].i2c_adap,
+ cx231xx_get_i2c_adap(dev, I2C_0),
"cx25840", 0x88 >> 1, NULL);
if (dev->sd_cx25840 == NULL)
cx231xx_info("cx25840 subdev registration failure\n");
@@ -1043,8 +1043,10 @@ void cx231xx_card_setup(struct cx231xx *dev)
/* Initialize the tuner */
if (dev->board.tuner_type != TUNER_ABSENT) {
+ struct i2c_adapter *tuner_i2c = cx231xx_get_i2c_adap(dev,
+ dev->board.tuner_i2c_master);
dev->sd_tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ tuner_i2c,
"tuner",
dev->tuner_addr, NULL);
if (dev->sd_tuner == NULL)
@@ -1062,7 +1064,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
struct i2c_client client;
memset(&client, 0, sizeof(client));
- client.adapter = &dev->i2c_bus[I2C_1].i2c_adap;
+ client.adapter = cx231xx_get_i2c_adap(dev, I2C_1);
client.addr = 0xa0 >> 1;
read_eeprom(dev, &client, eeprom, sizeof(eeprom));
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 6c7b5e2..869c433 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -378,7 +378,7 @@ static int attach_xc5000(u8 addr, struct cx231xx *dev)
struct xc5000_config cfg;
memset(&cfg, 0, sizeof(cfg));
- cfg.i2c_adap = &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap;
+ cfg.i2c_adap = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master);
cfg.i2c_addr = addr;
if (!dev->dvb->frontend) {
@@ -583,6 +583,8 @@ static int dvb_init(struct cx231xx *dev)
{
int result = 0;
struct cx231xx_dvb *dvb;
+ struct i2c_adapter *tuner_i2c;
+ struct i2c_adapter *demod_i2c;
if (!dev->board.has_dvb) {
/* This device does not support the extension */
@@ -599,6 +601,8 @@ static int dvb_init(struct cx231xx *dev)
dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq;
dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner;
+ tuner_i2c = cx231xx_get_i2c_adap(dev, dev->board.tuner_i2c_master);
+ demod_i2c = cx231xx_get_i2c_adap(dev, dev->board.demod_i2c_master);
mutex_lock(&dev->lock);
cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
cx231xx_demod_reset(dev);
@@ -609,7 +613,7 @@ static int dvb_init(struct cx231xx *dev)
dev->dvb->frontend = dvb_attach(s5h1432_attach,
&dvico_s5h1432_config,
- &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap);
+ demod_i2c);
if (dev->dvb->frontend == NULL) {
printk(DRIVER_NAME
@@ -622,7 +626,7 @@ static int dvb_init(struct cx231xx *dev)
dvb->frontend->callback = cx231xx_tuner_callback;
if (!dvb_attach(xc5000_attach, dev->dvb->frontend,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ tuner_i2c,
&cnxt_rde250_tunerconfig)) {
result = -EINVAL;
goto out_free;
@@ -634,7 +638,7 @@ static int dvb_init(struct cx231xx *dev)
dev->dvb->frontend = dvb_attach(s5h1411_attach,
&xc5000_s5h1411_config,
- &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap);
+ demod_i2c);
if (dev->dvb->frontend == NULL) {
printk(DRIVER_NAME
@@ -647,7 +651,7 @@ static int dvb_init(struct cx231xx *dev)
dvb->frontend->callback = cx231xx_tuner_callback;
if (!dvb_attach(xc5000_attach, dev->dvb->frontend,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ tuner_i2c,
&cnxt_rdu250_tunerconfig)) {
result = -EINVAL;
goto out_free;
@@ -657,7 +661,7 @@ static int dvb_init(struct cx231xx *dev)
dev->dvb->frontend = dvb_attach(s5h1432_attach,
&dvico_s5h1432_config,
- &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap);
+ demod_i2c);
if (dev->dvb->frontend == NULL) {
printk(DRIVER_NAME
@@ -670,7 +674,7 @@ static int dvb_init(struct cx231xx *dev)
dvb->frontend->callback = cx231xx_tuner_callback;
if (!dvb_attach(tda18271_attach, dev->dvb->frontend,
- 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ 0x60, tuner_i2c,
&cnxt_rde253s_tunerconfig)) {
result = -EINVAL;
goto out_free;
@@ -681,7 +685,7 @@ static int dvb_init(struct cx231xx *dev)
dev->dvb->frontend = dvb_attach(s5h1411_attach,
&tda18271_s5h1411_config,
- &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap);
+ demod_i2c);
if (dev->dvb->frontend == NULL) {
printk(DRIVER_NAME
@@ -694,7 +698,7 @@ static int dvb_init(struct cx231xx *dev)
dvb->frontend->callback = cx231xx_tuner_callback;
if (!dvb_attach(tda18271_attach, dev->dvb->frontend,
- 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ 0x60, tuner_i2c,
&cnxt_rde253s_tunerconfig)) {
result = -EINVAL;
goto out_free;
@@ -703,11 +707,11 @@ static int dvb_init(struct cx231xx *dev)
case CX231XX_BOARD_HAUPPAUGE_EXETER:
printk(KERN_INFO "%s: looking for tuner / demod on i2c bus: %d\n",
- __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap));
+ __func__, i2c_adapter_id(tuner_i2c));
dev->dvb->frontend = dvb_attach(lgdt3305_attach,
&hcw_lgdt3305_config,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap);
+ tuner_i2c);
if (dev->dvb->frontend == NULL) {
printk(DRIVER_NAME
@@ -720,7 +724,7 @@ static int dvb_init(struct cx231xx *dev)
dvb->frontend->callback = cx231xx_tuner_callback;
dvb_attach(tda18271_attach, dev->dvb->frontend,
- 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ 0x60, tuner_i2c,
&hcw_tda18271_config);
break;
@@ -728,7 +732,7 @@ static int dvb_init(struct cx231xx *dev)
dev->dvb->frontend = dvb_attach(si2165_attach,
&hauppauge_930C_HD_1113xx_si2165_config,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap
+ tuner_i2c
);
if (dev->dvb->frontend == NULL) {
@@ -745,7 +749,7 @@ static int dvb_init(struct cx231xx *dev)
dvb_attach(tda18271_attach, dev->dvb->frontend,
0x60,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ tuner_i2c,
&hcw_tda18271_config);
dev->cx231xx_reset_analog_tuner = NULL;
@@ -761,7 +765,7 @@ static int dvb_init(struct cx231xx *dev)
dev->dvb->frontend = dvb_attach(si2165_attach,
&pctv_quatro_stick_1114xx_si2165_config,
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap
+ tuner_i2c
);
if (dev->dvb->frontend == NULL) {
@@ -786,7 +790,7 @@ static int dvb_init(struct cx231xx *dev)
request_module("si2157");
client = i2c_new_device(
- &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ tuner_i2c,
&info);
if (client == NULL || client->dev.driver == NULL) {
dvb_frontend_detach(dev->dvb->frontend);
@@ -811,11 +815,11 @@ static int dvb_init(struct cx231xx *dev)
case CX231XX_BOARD_KWORLD_UB430_USB_HYBRID:
printk(KERN_INFO "%s: looking for demod on i2c bus: %d\n",
- __func__, i2c_adapter_id(&dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap));
+ __func__, i2c_adapter_id(tuner_i2c));
dev->dvb->frontend = dvb_attach(mb86a20s_attach,
&pv_mb86a20s_config,
- &dev->i2c_bus[dev->board.demod_i2c_master].i2c_adap);
+ demod_i2c);
if (dev->dvb->frontend == NULL) {
printk(DRIVER_NAME
@@ -828,7 +832,7 @@ static int dvb_init(struct cx231xx *dev)
dvb->frontend->callback = cx231xx_tuner_callback;
dvb_attach(tda18271_attach, dev->dvb->frontend,
- 0x60, &dev->i2c_bus[dev->board.tuner_i2c_master].i2c_adap,
+ 0x60, tuner_i2c,
&pv_tda18271_config);
break;
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index b10f482..13bf2d7 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -483,7 +483,7 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
struct i2c_client client;
memset(&client, 0, sizeof(client));
- client.adapter = &dev->i2c_bus[i2c_port].i2c_adap;
+ client.adapter = cx231xx_get_i2c_adap(dev, i2c_port);
cx231xx_info(": Checking for I2C devices on port=%d ..\n", i2c_port);
for (i = 0; i < 128; i++) {
@@ -538,3 +538,21 @@ int cx231xx_i2c_unregister(struct cx231xx_i2c *bus)
i2c_del_adapter(&bus->i2c_adap);
return 0;
}
+
+struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port)
+{
+ switch (i2c_port) {
+ case I2C_0:
+ return &dev->i2c_bus[0].i2c_adap;
+ case I2C_1:
+ return &dev->i2c_bus[1].i2c_adap;
+ case I2C_2:
+ return &dev->i2c_bus[2].i2c_adap;
+ case I2C_1_MUX_1:
+ case I2C_1_MUX_3:
+ return &dev->i2c_bus[1].i2c_adap;
+ default:
+ return NULL;
+ }
+}
+EXPORT_SYMBOL_GPL(cx231xx_get_i2c_adap);
diff --git a/drivers/media/usb/cx231xx/cx231xx-input.c b/drivers/media/usb/cx231xx/cx231xx-input.c
index 05f0434..5ae2ce3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-input.c
+++ b/drivers/media/usb/cx231xx/cx231xx-input.c
@@ -100,7 +100,8 @@ int cx231xx_ir_init(struct cx231xx *dev)
ir_i2c_bus = cx231xx_boards[dev->model].ir_i2c_master;
dev_dbg(&dev->udev->dev, "Trying to bind ir at bus %d, addr 0x%02x\n",
ir_i2c_bus, info.addr);
- dev->ir_i2c_client = i2c_new_device(&dev->i2c_bus[ir_i2c_bus].i2c_adap, &info);
+ dev->ir_i2c_client = i2c_new_device(
+ cx231xx_get_i2c_adap(dev, ir_i2c_bus), &info);
return 0;
}
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 377216b..f03338b 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -754,6 +754,7 @@ int cx231xx_reset_analog_tuner(struct cx231xx *dev);
void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
int cx231xx_i2c_register(struct cx231xx_i2c *bus);
int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
+struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port);
/* Internal block control functions */
int cx231xx_read_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 08/13] cx231xx: remember status of i2c port_3 switch
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (6 preceding siblings ...)
2014-10-02 5:20 ` [PATCH V3 07/13] cx231xx: add wrapper to get the i2c_adapter pointer Matthias Schwarzott
@ 2014-10-02 5:21 ` Matthias Schwarzott
2014-10-02 5:34 ` Antti Palosaari
2014-10-02 5:21 ` [PATCH V3 09/13] cx231xx: let is_tuner check the real i2c port and not the i2c master number Matthias Schwarzott
` (4 subsequent siblings)
12 siblings, 1 reply; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:21 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
This is used later for is_tuner function that switches i2c behaviour for
some tuners.
V2: Add comments about possible improvements for port_3 switch function.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/usb/cx231xx/cx231xx-avcore.c | 10 ++++++++++
drivers/media/usb/cx231xx/cx231xx.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 40a6987..148b5fa 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -1272,6 +1272,12 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
if (dev->board.dont_use_port_3)
is_port_3 = false;
+
+ /* Should this code check dev->port_3_switch_enabled first */
+ /* to skip unnecessary reading of the register? */
+ /* If yes, the flag dev->port_3_switch_enabled must be initialized */
+ /* correctly. */
+
status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
PWR_CTL_EN, value, 4);
if (status < 0)
@@ -1294,6 +1300,10 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
PWR_CTL_EN, value, 4);
+ /* remember status of the switch for usage in is_tuner */
+ if (status >= 0)
+ dev->port_3_switch_enabled = is_port_3;
+
return status;
}
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index f03338b..8a3c97b 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -629,6 +629,7 @@ struct cx231xx {
/* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
struct cx231xx_i2c i2c_bus[3];
unsigned int xc_fw_load_done:1;
+ unsigned int port_3_switch_enabled:1;
/* locks */
struct mutex gpio_i2c_lock;
struct mutex i2c_lock;
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH V3 08/13] cx231xx: remember status of i2c port_3 switch
2014-10-02 5:21 ` [PATCH V3 08/13] cx231xx: remember status of i2c port_3 switch Matthias Schwarzott
@ 2014-10-02 5:34 ` Antti Palosaari
0 siblings, 0 replies; 17+ messages in thread
From: Antti Palosaari @ 2014-10-02 5:34 UTC (permalink / raw)
To: Matthias Schwarzott, linux-media, mchehab
On 10/02/2014 08:21 AM, Matthias Schwarzott wrote:
> This is used later for is_tuner function that switches i2c behaviour for
> some tuners.
>
> V2: Add comments about possible improvements for port_3 switch function.
>
> Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
> ---
> drivers/media/usb/cx231xx/cx231xx-avcore.c | 10 ++++++++++
> drivers/media/usb/cx231xx/cx231xx.h | 1 +
> 2 files changed, 11 insertions(+)
>
> diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
> index 40a6987..148b5fa 100644
> --- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
> +++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
> @@ -1272,6 +1272,12 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
>
> if (dev->board.dont_use_port_3)
> is_port_3 = false;
> +
> + /* Should this code check dev->port_3_switch_enabled first */
> + /* to skip unnecessary reading of the register? */
> + /* If yes, the flag dev->port_3_switch_enabled must be initialized */
> + /* correctly. */
That multiline comment is violates Linux CodingStyle. See
Documentation/CodingStyle
> +
> status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
> PWR_CTL_EN, value, 4);
> if (status < 0)
> @@ -1294,6 +1300,10 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
> status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
> PWR_CTL_EN, value, 4);
>
> + /* remember status of the switch for usage in is_tuner */
> + if (status >= 0)
> + dev->port_3_switch_enabled = is_port_3;
> +
> return status;
>
> }
> diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
> index f03338b..8a3c97b 100644
> --- a/drivers/media/usb/cx231xx/cx231xx.h
> +++ b/drivers/media/usb/cx231xx/cx231xx.h
> @@ -629,6 +629,7 @@ struct cx231xx {
> /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
> struct cx231xx_i2c i2c_bus[3];
> unsigned int xc_fw_load_done:1;
> + unsigned int port_3_switch_enabled:1;
> /* locks */
> struct mutex gpio_i2c_lock;
> struct mutex i2c_lock;
>
I trust functionality is correct. However, I expected to see mux
switching logic inside mux select() / deselect(), maybe with caching mux
switch position in order to avoid I/O needed for checking mux switch
position.
But as I don't know that driver internals very well, I am not adding
reviewed by tag, which does not mean that is wrong. It is simply because
I don't know.
regards
Antti
--
http://palosaari.fi/
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH V3 09/13] cx231xx: let is_tuner check the real i2c port and not the i2c master number
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (7 preceding siblings ...)
2014-10-02 5:21 ` [PATCH V3 08/13] cx231xx: remember status of i2c port_3 switch Matthias Schwarzott
@ 2014-10-02 5:21 ` Matthias Schwarzott
2014-10-02 5:21 ` [PATCH V3 10/13] cx231xx: change usage of I2C_1 to the real i2c port Matthias Schwarzott
` (3 subsequent siblings)
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:21 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
Get used i2c port from bus_nr and status of port_3 switch.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/usb/cx231xx/cx231xx-i2c.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index 13bf2d7..effd12c 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -54,10 +54,19 @@ do { \
} \
} while (0)
+static inline int get_real_i2c_port(struct cx231xx *dev, int bus_nr)
+{
+ if (bus_nr == 1)
+ return dev->port_3_switch_enabled ? I2C_1_MUX_3 : I2C_1_MUX_1;
+ return bus_nr;
+}
+
static inline bool is_tuner(struct cx231xx *dev, struct cx231xx_i2c *bus,
const struct i2c_msg *msg, int tuner_type)
{
- if (bus->nr != dev->board.tuner_i2c_master)
+ int i2c_port = get_real_i2c_port(dev, bus->nr);
+
+ if (i2c_port != dev->board.tuner_i2c_master)
return false;
if (msg->addr != dev->board.tuner_addr)
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 10/13] cx231xx: change usage of I2C_1 to the real i2c port
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (8 preceding siblings ...)
2014-10-02 5:21 ` [PATCH V3 09/13] cx231xx: let is_tuner check the real i2c port and not the i2c master number Matthias Schwarzott
@ 2014-10-02 5:21 ` Matthias Schwarzott
2014-10-30 19:27 ` Mauro Carvalho Chehab
2014-10-02 5:21 ` [PATCH V3 11/13] cx231xx: register i2c mux adapters for master1 and use as I2C_1_MUX_1 and I2C_1_MUX_3 Matthias Schwarzott
` (2 subsequent siblings)
12 siblings, 1 reply; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:21 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
change almost all instances of I2C_1 to I2C_1_MUX_3
Only these cases are changed to I2C_1_MUX_1:
* All that have dont_use_port_3 set.
* CX231XX_BOARD_HAUPPAUGE_EXETER, old code did explicitly not switch to port3.
* eeprom access for 930C
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index f5fb93a..4eb2057 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -104,7 +104,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -144,7 +144,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
@@ -184,7 +184,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -225,7 +225,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x1c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -297,7 +297,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x02,
@@ -325,7 +325,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x32,
@@ -353,7 +353,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_1,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
@@ -419,7 +419,7 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
.tuner_i2c_master = I2C_2,
- .demod_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_1_MUX_3,
.ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
@@ -457,7 +457,7 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
.tuner_i2c_master = I2C_2,
- .demod_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_1_MUX_3,
.ir_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x10,
@@ -495,7 +495,7 @@ struct cx231xx_board cx231xx_boards[] = {
.tuner_sda_gpio = -1,
.gpio_pin_status_mask = 0x4001000,
.tuner_i2c_master = I2C_2,
- .demod_i2c_master = I2C_1,
+ .demod_i2c_master = I2C_1_MUX_3,
.ir_i2c_master = I2C_2,
.rc_map_name = RC_MAP_PIXELVIEW_002T,
.has_dvb = 1,
@@ -587,7 +587,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.norm = V4L2_STD_PAL,
.input = {{
@@ -622,7 +622,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.norm = V4L2_STD_NTSC,
.input = {{
@@ -718,7 +718,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
@@ -757,7 +757,7 @@ struct cx231xx_board cx231xx_boards[] = {
.ctl_pin_status_mask = 0xFFFFFFC4,
.agc_analog_digital_select_gpio = 0x0c,
.gpio_pin_status_mask = 0x4001000,
- .tuner_i2c_master = I2C_1,
+ .tuner_i2c_master = I2C_1_MUX_3,
.demod_i2c_master = I2C_2,
.has_dvb = 1,
.demod_addr = 0x0e,
@@ -1064,7 +1064,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
struct i2c_client client;
memset(&client, 0, sizeof(client));
- client.adapter = cx231xx_get_i2c_adap(dev, I2C_1);
+ client.adapter = cx231xx_get_i2c_adap(dev, I2C_1_MUX_1);
client.addr = 0xa0 >> 1;
read_eeprom(dev, &client, eeprom, sizeof(eeprom));
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH V3 10/13] cx231xx: change usage of I2C_1 to the real i2c port
2014-10-02 5:21 ` [PATCH V3 10/13] cx231xx: change usage of I2C_1 to the real i2c port Matthias Schwarzott
@ 2014-10-30 19:27 ` Mauro Carvalho Chehab
0 siblings, 0 replies; 17+ messages in thread
From: Mauro Carvalho Chehab @ 2014-10-30 19:27 UTC (permalink / raw)
To: Matthias Schwarzott; +Cc: linux-media, crope
Em Thu, 2 Oct 2014 07:21:02 +0200
Matthias Schwarzott <zzam@gentoo.org> escreveu:
> change almost all instances of I2C_1 to I2C_1_MUX_3
So far, this is likely the most dangerous patch on this series ;)
>
> Only these cases are changed to I2C_1_MUX_1:
> * All that have dont_use_port_3 set.
> * CX231XX_BOARD_HAUPPAUGE_EXETER, old code did explicitly not switch to port3.
> * eeprom access for 930C
I think Pixelview SBTVD Hybrid also doesn't use MUX_3 for tuner. Thankfully,
I have such tuner. So, I'll test and fix it if needed.
>
> Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
> Reviewed-by: Antti Palosaari <crope@iki.fi>
> ---
> drivers/media/usb/cx231xx/cx231xx-cards.c | 30 +++++++++++++++---------------
> 1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
> index f5fb93a..4eb2057 100644
> --- a/drivers/media/usb/cx231xx/cx231xx-cards.c
> +++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
> @@ -104,7 +104,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x02,
> @@ -144,7 +144,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x32,
> @@ -184,7 +184,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x1c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x02,
> @@ -225,7 +225,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x1c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x02,
> @@ -297,7 +297,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x02,
> @@ -325,7 +325,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x32,
> @@ -353,7 +353,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_1,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x0e,
> @@ -419,7 +419,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .tuner_sda_gpio = -1,
> .gpio_pin_status_mask = 0x4001000,
> .tuner_i2c_master = I2C_2,
> - .demod_i2c_master = I2C_1,
> + .demod_i2c_master = I2C_1_MUX_3,
> .ir_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x10,
> @@ -457,7 +457,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .tuner_sda_gpio = -1,
> .gpio_pin_status_mask = 0x4001000,
> .tuner_i2c_master = I2C_2,
> - .demod_i2c_master = I2C_1,
> + .demod_i2c_master = I2C_1_MUX_3,
> .ir_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x10,
> @@ -495,7 +495,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .tuner_sda_gpio = -1,
> .gpio_pin_status_mask = 0x4001000,
> .tuner_i2c_master = I2C_2,
> - .demod_i2c_master = I2C_1,
> + .demod_i2c_master = I2C_1_MUX_3,
> .ir_i2c_master = I2C_2,
> .rc_map_name = RC_MAP_PIXELVIEW_002T,
> .has_dvb = 1,
> @@ -587,7 +587,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .norm = V4L2_STD_PAL,
>
> .input = {{
> @@ -622,7 +622,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .norm = V4L2_STD_NTSC,
>
> .input = {{
> @@ -718,7 +718,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x0e,
> @@ -757,7 +757,7 @@ struct cx231xx_board cx231xx_boards[] = {
> .ctl_pin_status_mask = 0xFFFFFFC4,
> .agc_analog_digital_select_gpio = 0x0c,
> .gpio_pin_status_mask = 0x4001000,
> - .tuner_i2c_master = I2C_1,
> + .tuner_i2c_master = I2C_1_MUX_3,
> .demod_i2c_master = I2C_2,
> .has_dvb = 1,
> .demod_addr = 0x0e,
> @@ -1064,7 +1064,7 @@ void cx231xx_card_setup(struct cx231xx *dev)
> struct i2c_client client;
>
> memset(&client, 0, sizeof(client));
> - client.adapter = cx231xx_get_i2c_adap(dev, I2C_1);
> + client.adapter = cx231xx_get_i2c_adap(dev, I2C_1_MUX_1);
> client.addr = 0xa0 >> 1;
>
> read_eeprom(dev, &client, eeprom, sizeof(eeprom));
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH V3 11/13] cx231xx: register i2c mux adapters for master1 and use as I2C_1_MUX_1 and I2C_1_MUX_3
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (9 preceding siblings ...)
2014-10-02 5:21 ` [PATCH V3 10/13] cx231xx: change usage of I2C_1 to the real i2c port Matthias Schwarzott
@ 2014-10-02 5:21 ` Matthias Schwarzott
2014-10-02 5:21 ` [PATCH V3 12/13] cx231xx: drop unconditional port3 switching Matthias Schwarzott
2014-10-02 5:21 ` [PATCH V3 13/13] cx231xx: scan all four existing i2c busses instead of the 3 masters Matthias Schwarzott
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:21 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/Kconfig | 1 +
drivers/media/usb/cx231xx/cx231xx-core.c | 5 ++++
drivers/media/usb/cx231xx/cx231xx-i2c.c | 44 +++++++++++++++++++++++++++++++-
drivers/media/usb/cx231xx/cx231xx.h | 4 +++
4 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/cx231xx/Kconfig b/drivers/media/usb/cx231xx/Kconfig
index 569aa29..173c0e2 100644
--- a/drivers/media/usb/cx231xx/Kconfig
+++ b/drivers/media/usb/cx231xx/Kconfig
@@ -7,6 +7,7 @@ config VIDEO_CX231XX
select VIDEOBUF_VMALLOC
select VIDEO_CX25840
select VIDEO_CX2341X
+ select I2C_MUX
---help---
This is a video4linux driver for Conexant 231xx USB based TV cards.
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index 180103e..c8a6d20 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -1300,6 +1300,9 @@ int cx231xx_dev_init(struct cx231xx *dev)
cx231xx_i2c_register(&dev->i2c_bus[1]);
cx231xx_i2c_register(&dev->i2c_bus[2]);
+ cx231xx_i2c_mux_register(dev, 0);
+ cx231xx_i2c_mux_register(dev, 1);
+
/* init hardware */
/* Note : with out calling set power mode function,
afe can not be set up correctly */
@@ -1414,6 +1417,8 @@ EXPORT_SYMBOL_GPL(cx231xx_dev_init);
void cx231xx_dev_uninit(struct cx231xx *dev)
{
/* Un Initialize I2C bus */
+ cx231xx_i2c_mux_unregister(dev, 1);
+ cx231xx_i2c_mux_unregister(dev, 0);
cx231xx_i2c_unregister(&dev->i2c_bus[2]);
cx231xx_i2c_unregister(&dev->i2c_bus[1]);
cx231xx_i2c_unregister(&dev->i2c_bus[0]);
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index effd12c..dc9c478 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -24,6 +24,7 @@
#include <linux/kernel.h>
#include <linux/usb.h>
#include <linux/i2c.h>
+#include <linux/i2c-mux.h>
#include <media/v4l2-common.h>
#include <media/tuner.h>
@@ -548,6 +549,46 @@ int cx231xx_i2c_unregister(struct cx231xx_i2c *bus)
return 0;
}
+/*
+ * cx231xx_i2c_mux_select()
+ * switch i2c master number 1 between port1 and port3
+ */
+static int cx231xx_i2c_mux_select(struct i2c_adapter *adap,
+ void *mux_priv, u32 chan_id)
+{
+ struct cx231xx *dev = mux_priv;
+
+ return cx231xx_enable_i2c_port_3(dev, chan_id);
+}
+
+int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no)
+{
+ struct i2c_adapter *i2c_parent = &dev->i2c_bus[1].i2c_adap;
+ /* what is the correct mux_dev? */
+ struct device *mux_dev = &dev->udev->dev;
+
+ dev->i2c_mux_adap[mux_no] = i2c_add_mux_adapter(i2c_parent,
+ mux_dev,
+ dev /* mux_priv */,
+ 0,
+ mux_no /* chan_id */,
+ 0 /* class */,
+ &cx231xx_i2c_mux_select,
+ NULL);
+
+ if (!dev->i2c_mux_adap[mux_no])
+ cx231xx_warn("%s: i2c mux %d register FAILED\n",
+ dev->name, mux_no);
+
+ return 0;
+}
+
+void cx231xx_i2c_mux_unregister(struct cx231xx *dev, int mux_no)
+{
+ i2c_del_mux_adapter(dev->i2c_mux_adap[mux_no]);
+ dev->i2c_mux_adap[mux_no] = NULL;
+}
+
struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port)
{
switch (i2c_port) {
@@ -558,8 +599,9 @@ struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port)
case I2C_2:
return &dev->i2c_bus[2].i2c_adap;
case I2C_1_MUX_1:
+ return dev->i2c_mux_adap[0];
case I2C_1_MUX_3:
- return &dev->i2c_bus[1].i2c_adap;
+ return dev->i2c_mux_adap[1];
default:
return NULL;
}
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 8a3c97b..c90aa44 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -628,6 +628,8 @@ struct cx231xx {
/* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
struct cx231xx_i2c i2c_bus[3];
+ struct i2c_adapter *i2c_mux_adap[2];
+
unsigned int xc_fw_load_done:1;
unsigned int port_3_switch_enabled:1;
/* locks */
@@ -755,6 +757,8 @@ int cx231xx_reset_analog_tuner(struct cx231xx *dev);
void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
int cx231xx_i2c_register(struct cx231xx_i2c *bus);
int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
+int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no);
+void cx231xx_i2c_mux_unregister(struct cx231xx *dev, int mux_no);
struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port);
/* Internal block control functions */
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 12/13] cx231xx: drop unconditional port3 switching
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (10 preceding siblings ...)
2014-10-02 5:21 ` [PATCH V3 11/13] cx231xx: register i2c mux adapters for master1 and use as I2C_1_MUX_1 and I2C_1_MUX_3 Matthias Schwarzott
@ 2014-10-02 5:21 ` Matthias Schwarzott
2014-10-02 5:21 ` [PATCH V3 13/13] cx231xx: scan all four existing i2c busses instead of the 3 masters Matthias Schwarzott
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:21 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
All switching should be done by i2c mux adapters.
Drop explicit dont_use_port_3 flag.
Drop info message about switch.
Only the removed code in start_streaming is questionable:
It did switch the port_3 flag without accessing i2c in between.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-avcore.c | 18 ------------------
drivers/media/usb/cx231xx/cx231xx-cards.c | 8 --------
drivers/media/usb/cx231xx/cx231xx-core.c | 4 +---
drivers/media/usb/cx231xx/cx231xx-dvb.c | 4 ----
drivers/media/usb/cx231xx/cx231xx.h | 1 -
5 files changed, 1 insertion(+), 34 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 148b5fa..20bb96a 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -1270,9 +1270,6 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
int status = 0;
bool current_is_port_3;
- if (dev->board.dont_use_port_3)
- is_port_3 = false;
-
/* Should this code check dev->port_3_switch_enabled first */
/* to skip unnecessary reading of the register? */
/* If yes, the flag dev->port_3_switch_enabled must be initialized */
@@ -1294,9 +1291,6 @@ int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3)
else
value[0] &= ~I2C_DEMOD_EN;
- cx231xx_info("Changing the i2c master port to %d\n",
- is_port_3 ? 3 : 1);
-
status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
PWR_CTL_EN, value, 4);
@@ -2327,9 +2321,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode)
}
if (dev->board.tuner_type != TUNER_ABSENT) {
- /* Enable tuner */
- cx231xx_enable_i2c_port_3(dev, true);
-
/* reset the Tuner */
if (dev->board.tuner_gpio)
cx231xx_gpio_set(dev, dev->board.tuner_gpio);
@@ -2394,15 +2385,6 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode)
}
if (dev->board.tuner_type != TUNER_ABSENT) {
- /*
- * Enable tuner
- * Hauppauge Exeter seems to need to do something different!
- */
- if (dev->model == CX231XX_BOARD_HAUPPAUGE_EXETER)
- cx231xx_enable_i2c_port_3(dev, false);
- else
- cx231xx_enable_i2c_port_3(dev, true);
-
/* reset the Tuner */
if (dev->board.tuner_gpio)
cx231xx_gpio_set(dev, dev->board.tuner_gpio);
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4eb2057..432cbcf 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -262,7 +262,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_PAL,
.no_alt_vanc = 1,
.external_av = 1,
- .dont_use_port_3 = 1,
/* Actually, it has a 417, but it isn't working correctly.
* So set to 0 for now until someone can manage to get this
* to work reliably. */
@@ -390,7 +389,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
- .dont_use_port_3 = 1,
.input = {{
.type = CX231XX_VMUX_COMPOSITE1,
.vmux = CX231XX_VIN_2_1,
@@ -532,7 +530,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
- .dont_use_port_3 = 1,
.input = {{
.type = CX231XX_VMUX_COMPOSITE1,
@@ -656,7 +653,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
- .dont_use_port_3 = 1,
.input = {{
.type = CX231XX_VMUX_COMPOSITE1,
.vmux = CX231XX_VIN_2_1,
@@ -683,7 +679,6 @@ struct cx231xx_board cx231xx_boards[] = {
.norm = V4L2_STD_NTSC,
.no_alt_vanc = 1,
.external_av = 1,
- .dont_use_port_3 = 1,
/*.has_417 = 1, */
/* This board is believed to have a hardware encoding chip
* supporting mpeg1/2/4, but as the 417 is apparently not
@@ -1012,9 +1007,6 @@ static int read_eeprom(struct cx231xx *dev, struct i2c_client *client,
len_todo -= msg_read.len;
}
- cx231xx_enable_i2c_port_3(dev, true);
- /* mutex_unlock(&dev->i2c_lock); */
-
for (i = 0; i + 15 < len; i += 16)
cx231xx_info("i2c eeprom %02x: %*ph\n", i, 16, &eedata[i]);
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index c8a6d20..c49022f 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -1407,9 +1407,7 @@ int cx231xx_dev_init(struct cx231xx *dev)
if (dev->board.has_dvb)
cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
- /* set the I2C master port to 3 on channel 1 */
- errCode = cx231xx_enable_i2c_port_3(dev, true);
-
+ errCode = 0;
return errCode;
}
EXPORT_SYMBOL_GPL(cx231xx_dev_init);
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index 869c433..2ea6946 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -266,11 +266,7 @@ static int start_streaming(struct cx231xx_dvb *dvb)
if (dev->USE_ISO) {
cx231xx_info("DVB transfer mode is ISO.\n");
- mutex_lock(&dev->i2c_lock);
- cx231xx_enable_i2c_port_3(dev, false);
cx231xx_set_alt_setting(dev, INDEX_TS1, 4);
- cx231xx_enable_i2c_port_3(dev, true);
- mutex_unlock(&dev->i2c_lock);
rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
if (rc < 0)
return rc;
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index c90aa44..a0ec241 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -368,7 +368,6 @@ struct cx231xx_board {
unsigned int valid:1;
unsigned int no_alt_vanc:1;
unsigned int external_av:1;
- unsigned int dont_use_port_3:1;
unsigned char xclk, i2c_speed;
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH V3 13/13] cx231xx: scan all four existing i2c busses instead of the 3 masters
2014-10-02 5:20 cx231xx: Use muxed i2c adapters instead of custom switching Matthias Schwarzott
` (11 preceding siblings ...)
2014-10-02 5:21 ` [PATCH V3 12/13] cx231xx: drop unconditional port3 switching Matthias Schwarzott
@ 2014-10-02 5:21 ` Matthias Schwarzott
12 siblings, 0 replies; 17+ messages in thread
From: Matthias Schwarzott @ 2014-10-02 5:21 UTC (permalink / raw)
To: linux-media, mchehab, crope; +Cc: Matthias Schwarzott
The scanning itself just fails (as before this series) but now the correct busses are scanned.
V2: Changed to symbolic names where muxed adapters can be seen directly.
V3: Comment about scanning busses ordered by physical port numbers.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
Reviewed-by: Antti Palosaari <crope@iki.fi>
---
drivers/media/usb/cx231xx/cx231xx-core.c | 6 ++++++
drivers/media/usb/cx231xx/cx231xx-i2c.c | 8 ++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-core.c b/drivers/media/usb/cx231xx/cx231xx-core.c
index c49022f..9b5cd9e 100644
--- a/drivers/media/usb/cx231xx/cx231xx-core.c
+++ b/drivers/media/usb/cx231xx/cx231xx-core.c
@@ -1303,6 +1303,12 @@ int cx231xx_dev_init(struct cx231xx *dev)
cx231xx_i2c_mux_register(dev, 0);
cx231xx_i2c_mux_register(dev, 1);
+ /* scan the real bus segments in the order of physical port numbers */
+ cx231xx_do_i2c_scan(dev, I2C_0);
+ cx231xx_do_i2c_scan(dev, I2C_1_MUX_1);
+ cx231xx_do_i2c_scan(dev, I2C_2);
+ cx231xx_do_i2c_scan(dev, I2C_1_MUX_3);
+
/* init hardware */
/* Note : with out calling set power mode function,
afe can not be set up correctly */
diff --git a/drivers/media/usb/cx231xx/cx231xx-i2c.c b/drivers/media/usb/cx231xx/cx231xx-i2c.c
index dc9c478..ec51bde 100644
--- a/drivers/media/usb/cx231xx/cx231xx-i2c.c
+++ b/drivers/media/usb/cx231xx/cx231xx-i2c.c
@@ -492,6 +492,9 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port)
int i, rc;
struct i2c_client client;
+ if (!i2c_scan)
+ return;
+
memset(&client, 0, sizeof(client));
client.adapter = cx231xx_get_i2c_adap(dev, i2c_port);
@@ -529,10 +532,7 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus)
i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev);
i2c_add_adapter(&bus->i2c_adap);
- if (0 == bus->i2c_rc) {
- if (i2c_scan)
- cx231xx_do_i2c_scan(dev, bus->nr);
- } else
+ if (0 != bus->i2c_rc)
cx231xx_warn("%s: i2c bus %d register FAILED\n",
dev->name, bus->nr);
--
2.1.1
^ permalink raw reply related [flat|nested] 17+ messages in thread