* [PATCH 1/7] si2165: support i2c_client attach
@ 2016-07-26 7:09 Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 2/7] cx23885: attach si2165 driver via i2c_client Matthias Schwarzott
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
Afterwards it is possible to convert attaching in card drivers.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/dvb-frontends/si2165.c | 149 +++++++++++++++++++++++++++++++++++
drivers/media/dvb-frontends/si2165.h | 22 ++++++
2 files changed, 171 insertions(+)
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index 8bf716a..2d9bbdd 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -40,6 +40,8 @@
*/
struct si2165_state {
+ struct i2c_client *client;
+
struct i2c_adapter *i2c;
struct dvb_frontend fe;
@@ -1157,6 +1159,153 @@ error:
}
EXPORT_SYMBOL(si2165_attach);
+static int si2165_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct si2165_state *state = NULL;
+ struct si2165_platform_data *pdata = client->dev.platform_data;
+ int n;
+ int ret = 0;
+ u8 val;
+ char rev_char;
+ const char *chip_name;
+
+ /* allocate memory for the internal state */
+ state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
+ if (state == NULL) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ /* setup the state */
+ state->client = client;
+ state->i2c = client->adapter;
+ state->config.i2c_addr = client->addr;
+ state->config.chip_mode = pdata->chip_mode;
+ state->config.ref_freq_Hz = pdata->ref_freq_Hz;
+ state->config.inversion = pdata->inversion;
+
+ if (state->config.ref_freq_Hz < 4000000
+ || state->config.ref_freq_Hz > 27000000) {
+ dev_err(&state->i2c->dev, "%s: ref_freq of %d Hz not supported by this driver\n",
+ KBUILD_MODNAME, state->config.ref_freq_Hz);
+ ret = -EINVAL;
+ goto error;
+ }
+
+ /* create dvb_frontend */
+ memcpy(&state->fe.ops, &si2165_ops,
+ sizeof(struct dvb_frontend_ops));
+ state->fe.ops.release = NULL;
+ state->fe.demodulator_priv = state;
+ i2c_set_clientdata(client, state);
+
+ /* powerup */
+ ret = si2165_writereg8(state, 0x0000, state->config.chip_mode);
+ if (ret < 0)
+ goto nodev_error;
+
+ ret = si2165_readreg8(state, 0x0000, &val);
+ if (ret < 0)
+ goto nodev_error;
+ if (val != state->config.chip_mode)
+ goto nodev_error;
+
+ ret = si2165_readreg8(state, 0x0023, &state->chip_revcode);
+ if (ret < 0)
+ goto nodev_error;
+
+ ret = si2165_readreg8(state, 0x0118, &state->chip_type);
+ if (ret < 0)
+ goto nodev_error;
+
+ /* powerdown */
+ ret = si2165_writereg8(state, 0x0000, SI2165_MODE_OFF);
+ if (ret < 0)
+ goto nodev_error;
+
+ if (state->chip_revcode < 26)
+ rev_char = 'A' + state->chip_revcode;
+ else
+ rev_char = '?';
+
+ switch (state->chip_type) {
+ case 0x06:
+ chip_name = "Si2161";
+ state->has_dvbt = true;
+ break;
+ case 0x07:
+ chip_name = "Si2165";
+ state->has_dvbt = true;
+ state->has_dvbc = true;
+ break;
+ default:
+ dev_err(&state->i2c->dev, "%s: Unsupported Silicon Labs chip (type %d, rev %d)\n",
+ KBUILD_MODNAME, state->chip_type, state->chip_revcode);
+ goto nodev_error;
+ }
+
+ dev_info(&state->i2c->dev,
+ "%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
+ KBUILD_MODNAME, chip_name, rev_char, state->chip_type,
+ state->chip_revcode);
+
+ strlcat(state->fe.ops.info.name, chip_name,
+ sizeof(state->fe.ops.info.name));
+
+ n = 0;
+ if (state->has_dvbt) {
+ state->fe.ops.delsys[n++] = SYS_DVBT;
+ strlcat(state->fe.ops.info.name, " DVB-T",
+ sizeof(state->fe.ops.info.name));
+ }
+ if (state->has_dvbc) {
+ state->fe.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
+ strlcat(state->fe.ops.info.name, " DVB-C",
+ sizeof(state->fe.ops.info.name));
+ }
+
+ /* return fe pointer */
+ *pdata->fe = &state->fe;
+
+ return 0;
+
+nodev_error:
+ ret = -ENODEV;
+error:
+ kfree(state);
+ dev_dbg(&client->dev, "failed=%d\n", ret);
+ return ret;
+}
+
+static int si2165_remove(struct i2c_client *client)
+{
+ struct si2165_state *state = i2c_get_clientdata(client);
+
+ dev_dbg(&client->dev, "\n");
+
+ kfree(state);
+ return 0;
+}
+
+static const struct i2c_device_id si2165_id_table[] = {
+ {"si2165", 0},
+ {}
+};
+MODULE_DEVICE_TABLE(i2c, si2165_id_table);
+
+static struct i2c_driver si2165_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "si2165",
+ },
+ .probe = si2165_probe,
+ .remove = si2165_remove,
+ .id_table = si2165_id_table,
+};
+
+module_i2c_driver(si2165_driver);
+
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
diff --git a/drivers/media/dvb-frontends/si2165.h b/drivers/media/dvb-frontends/si2165.h
index 8a15d6a..abbebc9 100644
--- a/drivers/media/dvb-frontends/si2165.h
+++ b/drivers/media/dvb-frontends/si2165.h
@@ -28,6 +28,28 @@ enum {
SI2165_MODE_PLL_XTAL = 0x21
};
+/* I2C addresses
+ * possible values: 0x64,0x65,0x66,0x67
+ */
+struct si2165_platform_data {
+ /*
+ * frontend
+ * returned by driver
+ */
+ struct dvb_frontend **fe;
+
+ /* external clock or XTAL */
+ u8 chip_mode;
+
+ /* frequency of external clock or xtal in Hz
+ * possible values: 4000000, 16000000, 20000000, 240000000, 27000000
+ */
+ u32 ref_freq_Hz;
+
+ /* invert the spectrum */
+ bool inversion;
+};
+
struct si2165_config {
/* i2c addr
* possible values: 0x64,0x65,0x66,0x67 */
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/7] cx23885: attach si2165 driver via i2c_client
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
@ 2016-07-26 7:09 ` Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 3/7] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers Matthias Schwarzott
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
Use new style attach.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/pci/cx23885/cx23885-dvb.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index e5748a9..5d0bbe4 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -867,12 +867,6 @@ static const struct tda10071_platform_data hauppauge_tda10071_pdata = {
.tuner_i2c_addr = 0x54,
};
-static const struct si2165_config hauppauge_hvr4400_si2165_config = {
- .i2c_addr = 0x64,
- .chip_mode = SI2165_MODE_PLL_XTAL,
- .ref_freq_Hz = 16000000,
-};
-
static const struct m88ds3103_config dvbsky_t9580_m88ds3103_config = {
.i2c_addr = 0x68,
.clock = 27000000,
@@ -1182,6 +1176,7 @@ static int dvb_register(struct cx23885_tsport *port)
struct cx23885_i2c *i2c_bus = NULL, *i2c_bus2 = NULL;
struct vb2_dvb_frontend *fe0, *fe1 = NULL;
struct si2168_config si2168_config;
+ struct si2165_platform_data si2165_pdata;
struct si2157_config si2157_config;
struct ts2020_config ts2020_config;
struct i2c_board_info info;
@@ -1839,9 +1834,26 @@ static int dvb_register(struct cx23885_tsport *port)
break;
/* port c */
case 2:
- fe0->dvb.frontend = dvb_attach(si2165_attach,
- &hauppauge_hvr4400_si2165_config,
- &i2c_bus->i2c_adap);
+ /* attach frontend */
+ memset(&si2165_pdata, 0, sizeof(si2165_pdata));
+ si2165_pdata.fe = &fe0->dvb.frontend;
+ si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
+ si2165_pdata.ref_freq_Hz = 16000000,
+ memset(&info, 0, sizeof(struct i2c_board_info));
+ strlcpy(info.type, "si2165", I2C_NAME_SIZE);
+ info.addr = 0x64;
+ info.platform_data = &si2165_pdata;
+ request_module(info.type);
+ client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
+ if (client_demod == NULL ||
+ client_demod->dev.driver == NULL)
+ goto frontend_detach;
+ if (!try_module_get(client_demod->dev.driver->owner)) {
+ i2c_unregister_device(client_demod);
+ goto frontend_detach;
+ }
+ port->i2c_client_demod = client_demod;
+
if (fe0->dvb.frontend == NULL)
break;
fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL;
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/7] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 2/7] cx23885: attach si2165 driver via i2c_client Matthias Schwarzott
@ 2016-07-26 7:09 ` Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 4/7] cx231xx: attach si2165 driver via i2c_client Matthias Schwarzott
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
cx231xx does not yet support attaching new-style i2c_client DVB demod
drivers. Add necessary code base on tuner support for i2c_client.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/usb/cx231xx/cx231xx-dvb.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index ab2fb9f..f030345 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -65,6 +65,7 @@ struct cx231xx_dvb {
struct dmx_frontend fe_hw;
struct dmx_frontend fe_mem;
struct dvb_net net;
+ struct i2c_client *i2c_client_demod;
struct i2c_client *i2c_client_tuner;
};
@@ -586,8 +587,14 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
dvb_dmxdev_release(&dvb->dmxdev);
dvb_dmx_release(&dvb->demux);
- client = dvb->i2c_client_tuner;
/* remove I2C tuner */
+ client = dvb->i2c_client_tuner;
+ if (client) {
+ module_put(client->dev.driver->owner);
+ i2c_unregister_device(client);
+ }
+ /* remove I2C demod */
+ client = dvb->i2c_client_demod;
if (client) {
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/7] cx231xx: attach si2165 driver via i2c_client
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 2/7] cx23885: attach si2165 driver via i2c_client Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 3/7] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers Matthias Schwarzott
@ 2016-07-26 7:09 ` Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 5/7] si2165: Remove legacy attach Matthias Schwarzott
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
Use new style attach.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/usb/cx231xx/cx231xx-dvb.c | 73 ++++++++++++++++++++++-----------
1 file changed, 48 insertions(+), 25 deletions(-)
diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index f030345..1417515 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -151,18 +151,6 @@ static struct tda18271_config pv_tda18271_config = {
.small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
};
-static const struct si2165_config hauppauge_930C_HD_1113xx_si2165_config = {
- .i2c_addr = 0x64,
- .chip_mode = SI2165_MODE_PLL_XTAL,
- .ref_freq_Hz = 16000000,
-};
-
-static const struct si2165_config pctv_quatro_stick_1114xx_si2165_config = {
- .i2c_addr = 0x64,
- .chip_mode = SI2165_MODE_PLL_EXT,
- .ref_freq_Hz = 24000000,
-};
-
static struct lgdt3306a_config hauppauge_955q_lgdt3306a_config = {
.i2c_addr = 0x59,
.qam_if_khz = 4000,
@@ -756,19 +744,38 @@ static int dvb_init(struct cx231xx *dev)
break;
case CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx:
+ {
+ struct i2c_client *client;
+ struct i2c_board_info info;
+ struct si2165_platform_data si2165_pdata;
- dev->dvb->frontend = dvb_attach(si2165_attach,
- &hauppauge_930C_HD_1113xx_si2165_config,
- demod_i2c
- );
+ /* attach demod */
+ memset(&si2165_pdata, 0, sizeof(si2165_pdata));
+ si2165_pdata.fe = &dev->dvb->frontend;
+ si2165_pdata.chip_mode = SI2165_MODE_PLL_XTAL,
+ si2165_pdata.ref_freq_Hz = 16000000,
- if (dev->dvb->frontend == NULL) {
+ memset(&info, 0, sizeof(struct i2c_board_info));
+ strlcpy(info.type, "si2165", I2C_NAME_SIZE);
+ info.addr = 0x64;
+ info.platform_data = &si2165_pdata;
+ request_module(info.type);
+ client = i2c_new_device(demod_i2c, &info);
+ if (client == NULL || client->dev.driver == NULL || dev->dvb->frontend == NULL) {
dev_err(dev->dev,
"Failed to attach SI2165 front end\n");
result = -EINVAL;
goto out_free;
}
+ if (!try_module_get(client->dev.driver->owner)) {
+ i2c_unregister_device(client);
+ result = -ENODEV;
+ goto out_free;
+ }
+
+ dvb->i2c_client_demod = client;
+
dev->dvb->frontend->ops.i2c_gate_ctrl = NULL;
/* define general-purpose callback pointer */
@@ -781,27 +788,43 @@ static int dvb_init(struct cx231xx *dev)
dev->cx231xx_reset_analog_tuner = NULL;
break;
-
+ }
case CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx:
{
struct i2c_client *client;
struct i2c_board_info info;
+ struct si2165_platform_data si2165_pdata;
struct si2157_config si2157_config;
- memset(&info, 0, sizeof(struct i2c_board_info));
+ /* attach demod */
+ memset(&si2165_pdata, 0, sizeof(si2165_pdata));
+ si2165_pdata.fe = &dev->dvb->frontend;
+ si2165_pdata.chip_mode = SI2165_MODE_PLL_EXT,
+ si2165_pdata.ref_freq_Hz = 24000000,
- dev->dvb->frontend = dvb_attach(si2165_attach,
- &pctv_quatro_stick_1114xx_si2165_config,
- demod_i2c
- );
-
- if (dev->dvb->frontend == NULL) {
+ memset(&info, 0, sizeof(struct i2c_board_info));
+ strlcpy(info.type, "si2165", I2C_NAME_SIZE);
+ info.addr = 0x64;
+ info.platform_data = &si2165_pdata;
+ request_module(info.type);
+ client = i2c_new_device(demod_i2c, &info);
+ if (client == NULL || client->dev.driver == NULL || dev->dvb->frontend == NULL) {
dev_err(dev->dev,
"Failed to attach SI2165 front end\n");
result = -EINVAL;
goto out_free;
}
+ if (!try_module_get(client->dev.driver->owner)) {
+ i2c_unregister_device(client);
+ result = -ENODEV;
+ goto out_free;
+ }
+
+ dvb->i2c_client_demod = client;
+
+ memset(&info, 0, sizeof(struct i2c_board_info));
+
dev->dvb->frontend->ops.i2c_gate_ctrl = NULL;
/* define general-purpose callback pointer */
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/7] si2165: Remove legacy attach
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
` (2 preceding siblings ...)
2016-07-26 7:09 ` [PATCH 4/7] cx231xx: attach si2165 driver via i2c_client Matthias Schwarzott
@ 2016-07-26 7:09 ` Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 6/7] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 7/7] si2165: switch to regmap Matthias Schwarzott
5 siblings, 0 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
Now that all users of legacy attach are converted it can be removed.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/dvb-frontends/si2165.c | 117 ------------------------------
drivers/media/dvb-frontends/si2165.h | 31 --------
drivers/media/dvb-frontends/si2165_priv.h | 17 +++++
3 files changed, 17 insertions(+), 148 deletions(-)
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index 2d9bbdd..e979fc0 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -1005,14 +1005,6 @@ static int si2165_set_frontend(struct dvb_frontend *fe)
return 0;
}
-static void si2165_release(struct dvb_frontend *fe)
-{
- struct si2165_state *state = fe->demodulator_priv;
-
- dprintk("%s: called\n", __func__);
- kfree(state);
-}
-
static struct dvb_frontend_ops si2165_ops = {
.info = {
.name = "Silicon Labs ",
@@ -1048,117 +1040,8 @@ static struct dvb_frontend_ops si2165_ops = {
.set_frontend = si2165_set_frontend,
.read_status = si2165_read_status,
-
- .release = si2165_release,
};
-struct dvb_frontend *si2165_attach(const struct si2165_config *config,
- struct i2c_adapter *i2c)
-{
- struct si2165_state *state = NULL;
- int n;
- int io_ret;
- u8 val;
- char rev_char;
- const char *chip_name;
-
- if (config == NULL || i2c == NULL)
- goto error;
-
- /* allocate memory for the internal state */
- state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
- if (state == NULL)
- goto error;
-
- /* setup the state */
- state->i2c = i2c;
- state->config = *config;
-
- if (state->config.ref_freq_Hz < 4000000
- || state->config.ref_freq_Hz > 27000000) {
- dev_err(&state->i2c->dev, "%s: ref_freq of %d Hz not supported by this driver\n",
- KBUILD_MODNAME, state->config.ref_freq_Hz);
- goto error;
- }
-
- /* create dvb_frontend */
- memcpy(&state->fe.ops, &si2165_ops,
- sizeof(struct dvb_frontend_ops));
- state->fe.demodulator_priv = state;
-
- /* powerup */
- io_ret = si2165_writereg8(state, 0x0000, state->config.chip_mode);
- if (io_ret < 0)
- goto error;
-
- io_ret = si2165_readreg8(state, 0x0000, &val);
- if (io_ret < 0)
- goto error;
- if (val != state->config.chip_mode)
- goto error;
-
- io_ret = si2165_readreg8(state, 0x0023, &state->chip_revcode);
- if (io_ret < 0)
- goto error;
-
- io_ret = si2165_readreg8(state, 0x0118, &state->chip_type);
- if (io_ret < 0)
- goto error;
-
- /* powerdown */
- io_ret = si2165_writereg8(state, 0x0000, SI2165_MODE_OFF);
- if (io_ret < 0)
- goto error;
-
- if (state->chip_revcode < 26)
- rev_char = 'A' + state->chip_revcode;
- else
- rev_char = '?';
-
- switch (state->chip_type) {
- case 0x06:
- chip_name = "Si2161";
- state->has_dvbt = true;
- break;
- case 0x07:
- chip_name = "Si2165";
- state->has_dvbt = true;
- state->has_dvbc = true;
- break;
- default:
- dev_err(&state->i2c->dev, "%s: Unsupported Silicon Labs chip (type %d, rev %d)\n",
- KBUILD_MODNAME, state->chip_type, state->chip_revcode);
- goto error;
- }
-
- dev_info(&state->i2c->dev,
- "%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
- KBUILD_MODNAME, chip_name, rev_char, state->chip_type,
- state->chip_revcode);
-
- strlcat(state->fe.ops.info.name, chip_name,
- sizeof(state->fe.ops.info.name));
-
- n = 0;
- if (state->has_dvbt) {
- state->fe.ops.delsys[n++] = SYS_DVBT;
- strlcat(state->fe.ops.info.name, " DVB-T",
- sizeof(state->fe.ops.info.name));
- }
- if (state->has_dvbc) {
- state->fe.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
- strlcat(state->fe.ops.info.name, " DVB-C",
- sizeof(state->fe.ops.info.name));
- }
-
- return &state->fe;
-
-error:
- kfree(state);
- return NULL;
-}
-EXPORT_SYMBOL(si2165_attach);
-
static int si2165_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
diff --git a/drivers/media/dvb-frontends/si2165.h b/drivers/media/dvb-frontends/si2165.h
index abbebc9..76c2ca7 100644
--- a/drivers/media/dvb-frontends/si2165.h
+++ b/drivers/media/dvb-frontends/si2165.h
@@ -50,35 +50,4 @@ struct si2165_platform_data {
bool inversion;
};
-struct si2165_config {
- /* i2c addr
- * possible values: 0x64,0x65,0x66,0x67 */
- u8 i2c_addr;
-
- /* external clock or XTAL */
- u8 chip_mode;
-
- /* frequency of external clock or xtal in Hz
- * possible values: 4000000, 16000000, 20000000, 240000000, 27000000
- */
- u32 ref_freq_Hz;
-
- /* invert the spectrum */
- bool inversion;
-};
-
-#if IS_REACHABLE(CONFIG_DVB_SI2165)
-struct dvb_frontend *si2165_attach(
- const struct si2165_config *config,
- struct i2c_adapter *i2c);
-#else
-static inline struct dvb_frontend *si2165_attach(
- const struct si2165_config *config,
- struct i2c_adapter *i2c)
-{
- pr_warn("%s: driver disabled by Kconfig\n", __func__);
- return NULL;
-}
-#endif /* CONFIG_DVB_SI2165 */
-
#endif /* _DVB_SI2165_H */
diff --git a/drivers/media/dvb-frontends/si2165_priv.h b/drivers/media/dvb-frontends/si2165_priv.h
index 2b70cf1..e593211 100644
--- a/drivers/media/dvb-frontends/si2165_priv.h
+++ b/drivers/media/dvb-frontends/si2165_priv.h
@@ -20,4 +20,21 @@
#define SI2165_FIRMWARE_REV_D "dvb-demod-si2165.fw"
+struct si2165_config {
+ /* i2c addr
+ * possible values: 0x64,0x65,0x66,0x67 */
+ u8 i2c_addr;
+
+ /* external clock or XTAL */
+ u8 chip_mode;
+
+ /* frequency of external clock or xtal in Hz
+ * possible values: 4000000, 16000000, 20000000, 240000000, 27000000
+ */
+ u32 ref_freq_Hz;
+
+ /* invert the spectrum */
+ bool inversion;
+};
+
#endif /* _DVB_SI2165_PRIV */
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/7] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
` (3 preceding siblings ...)
2016-07-26 7:09 ` [PATCH 5/7] si2165: Remove legacy attach Matthias Schwarzott
@ 2016-07-26 7:09 ` Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 7/7] si2165: switch to regmap Matthias Schwarzott
5 siblings, 0 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
Now that there is a i2c_client, use the more specific dev for logging.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/dvb-frontends/si2165.c | 46 ++++++++++++++++++------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index e979fc0..9bf6609 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -114,7 +114,7 @@ static int si2165_write(struct si2165_state *state, const u16 reg,
u8 buf[2 + 4]; /* write a maximum of 4 bytes of data */
if (count + 2 > sizeof(buf)) {
- dev_warn(&state->i2c->dev,
+ dev_warn(&state->client->dev,
"%s: i2c wr reg=%04x: count=%d is too big!\n",
KBUILD_MODNAME, reg, count);
return -EINVAL;
@@ -134,7 +134,7 @@ static int si2165_write(struct si2165_state *state, const u16 reg,
ret = i2c_transfer(state->i2c, &msg, 1);
if (ret != 1) {
- dev_err(&state->i2c->dev, "%s: ret == %d\n", __func__, ret);
+ dev_err(&state->client->dev, "%s: ret == %d\n", __func__, ret);
if (ret < 0)
return ret;
else
@@ -159,7 +159,7 @@ static int si2165_read(struct si2165_state *state,
ret = i2c_transfer(state->i2c, msg, 2);
if (ret != 2) {
- dev_err(&state->i2c->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n",
+ dev_err(&state->client->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n",
__func__, state->config.i2c_addr, reg, ret);
if (ret < 0)
return ret;
@@ -347,7 +347,7 @@ static int si2165_wait_init_done(struct si2165_state *state)
return 0;
usleep_range(1000, 50000);
}
- dev_err(&state->i2c->dev, "%s: init_done was not set\n",
+ dev_err(&state->client->dev, "%s: init_done was not set\n",
KBUILD_MODNAME);
return ret;
}
@@ -376,14 +376,14 @@ static int si2165_upload_firmware_block(struct si2165_state *state,
wordcount = data[offset];
if (wordcount < 1 || data[offset+1] ||
data[offset+2] || data[offset+3]) {
- dev_warn(&state->i2c->dev,
+ dev_warn(&state->client->dev,
"%s: bad fw data[0..3] = %*ph\n",
KBUILD_MODNAME, 4, data);
return -EINVAL;
}
if (offset + 8 + wordcount * 4 > len) {
- dev_warn(&state->i2c->dev,
+ dev_warn(&state->client->dev,
"%s: len is too small for block len=%d, wordcount=%d\n",
KBUILD_MODNAME, len, wordcount);
return -EINVAL;
@@ -446,15 +446,15 @@ static int si2165_upload_firmware(struct si2165_state *state)
fw_file = SI2165_FIRMWARE_REV_D;
break;
default:
- dev_info(&state->i2c->dev, "%s: no firmware file for revision=%d\n",
+ dev_info(&state->client->dev, "%s: no firmware file for revision=%d\n",
KBUILD_MODNAME, state->chip_revcode);
return 0;
}
/* request the firmware, this will block and timeout */
- ret = request_firmware(&fw, fw_file, state->i2c->dev.parent);
+ ret = request_firmware(&fw, fw_file, &state->client->dev);
if (ret) {
- dev_warn(&state->i2c->dev, "%s: firmware file '%s' not found\n",
+ dev_warn(&state->client->dev, "%s: firmware file '%s' not found\n",
KBUILD_MODNAME, fw_file);
goto error;
}
@@ -462,11 +462,11 @@ static int si2165_upload_firmware(struct si2165_state *state)
data = fw->data;
len = fw->size;
- dev_info(&state->i2c->dev, "%s: downloading firmware from file '%s' size=%d\n",
+ dev_info(&state->client->dev, "%s: downloading firmware from file '%s' size=%d\n",
KBUILD_MODNAME, fw_file, len);
if (len % 4 != 0) {
- dev_warn(&state->i2c->dev, "%s: firmware size is not multiple of 4\n",
+ dev_warn(&state->client->dev, "%s: firmware size is not multiple of 4\n",
KBUILD_MODNAME);
ret = -EINVAL;
goto error;
@@ -474,14 +474,14 @@ static int si2165_upload_firmware(struct si2165_state *state)
/* check header (8 bytes) */
if (len < 8) {
- dev_warn(&state->i2c->dev, "%s: firmware header is missing\n",
+ dev_warn(&state->client->dev, "%s: firmware header is missing\n",
KBUILD_MODNAME);
ret = -EINVAL;
goto error;
}
if (data[0] != 1 || data[1] != 0) {
- dev_warn(&state->i2c->dev, "%s: firmware file version is wrong\n",
+ dev_warn(&state->client->dev, "%s: firmware file version is wrong\n",
KBUILD_MODNAME);
ret = -EINVAL;
goto error;
@@ -519,7 +519,7 @@ static int si2165_upload_firmware(struct si2165_state *state)
/* start right after the header */
offset = 8;
- dev_info(&state->i2c->dev, "%s: si2165_upload_firmware extracted patch_version=0x%02x, block_count=0x%02x, crc_expected=0x%04x\n",
+ dev_info(&state->client->dev, "%s: si2165_upload_firmware extracted patch_version=0x%02x, block_count=0x%02x, crc_expected=0x%04x\n",
KBUILD_MODNAME, patch_version, block_count, crc_expected);
ret = si2165_upload_firmware_block(state, data, len, &offset, 1);
@@ -538,7 +538,7 @@ static int si2165_upload_firmware(struct si2165_state *state)
ret = si2165_upload_firmware_block(state, data, len,
&offset, block_count);
if (ret < 0) {
- dev_err(&state->i2c->dev,
+ dev_err(&state->client->dev,
"%s: firmware could not be uploaded\n",
KBUILD_MODNAME);
goto error;
@@ -550,7 +550,7 @@ static int si2165_upload_firmware(struct si2165_state *state)
goto error;
if (val16 != crc_expected) {
- dev_err(&state->i2c->dev,
+ dev_err(&state->client->dev,
"%s: firmware crc mismatch %04x != %04x\n",
KBUILD_MODNAME, val16, crc_expected);
ret = -EINVAL;
@@ -562,7 +562,7 @@ static int si2165_upload_firmware(struct si2165_state *state)
goto error;
if (len != offset) {
- dev_err(&state->i2c->dev,
+ dev_err(&state->client->dev,
"%s: firmware len mismatch %04x != %04x\n",
KBUILD_MODNAME, len, offset);
ret = -EINVAL;
@@ -579,7 +579,7 @@ static int si2165_upload_firmware(struct si2165_state *state)
if (ret < 0)
goto error;
- dev_info(&state->i2c->dev, "%s: fw load finished\n", KBUILD_MODNAME);
+ dev_info(&state->client->dev, "%s: fw load finished\n", KBUILD_MODNAME);
ret = 0;
state->firmware_loaded = true;
@@ -613,7 +613,7 @@ static int si2165_init(struct dvb_frontend *fe)
if (ret < 0)
goto error;
if (val != state->config.chip_mode) {
- dev_err(&state->i2c->dev, "%s: could not set chip_mode\n",
+ dev_err(&state->client->dev, "%s: could not set chip_mode\n",
KBUILD_MODNAME);
return -EINVAL;
}
@@ -771,7 +771,7 @@ static int si2165_set_if_freq_shift(struct si2165_state *state)
u32 IF = 0;
if (!fe->ops.tuner_ops.get_if_frequency) {
- dev_err(&state->i2c->dev,
+ dev_err(&state->client->dev,
"%s: Error: get_if_frequency() not defined at tuner. Can't work without it!\n",
KBUILD_MODNAME);
return -EINVAL;
@@ -1070,7 +1070,7 @@ static int si2165_probe(struct i2c_client *client,
if (state->config.ref_freq_Hz < 4000000
|| state->config.ref_freq_Hz > 27000000) {
- dev_err(&state->i2c->dev, "%s: ref_freq of %d Hz not supported by this driver\n",
+ dev_err(&state->client->dev, "%s: ref_freq of %d Hz not supported by this driver\n",
KBUILD_MODNAME, state->config.ref_freq_Hz);
ret = -EINVAL;
goto error;
@@ -1123,12 +1123,12 @@ static int si2165_probe(struct i2c_client *client,
state->has_dvbc = true;
break;
default:
- dev_err(&state->i2c->dev, "%s: Unsupported Silicon Labs chip (type %d, rev %d)\n",
+ dev_err(&state->client->dev, "%s: Unsupported Silicon Labs chip (type %d, rev %d)\n",
KBUILD_MODNAME, state->chip_type, state->chip_revcode);
goto nodev_error;
}
- dev_info(&state->i2c->dev,
+ dev_info(&state->client->dev,
"%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
KBUILD_MODNAME, chip_name, rev_char, state->chip_type,
state->chip_revcode);
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 7/7] si2165: switch to regmap
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
` (4 preceding siblings ...)
2016-07-26 7:09 ` [PATCH 6/7] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging Matthias Schwarzott
@ 2016-07-26 7:09 ` Matthias Schwarzott
5 siblings, 0 replies; 7+ messages in thread
From: Matthias Schwarzott @ 2016-07-26 7:09 UTC (permalink / raw)
To: linux-media; +Cc: mchehab, crope, Matthias Schwarzott
This avoids some low-level operations.
It has the benefit that now register values van be read from /sys/kernel/debug/regmap
The maximum register value is just a guess - all higher addresses read as zero.
Signed-off-by: Matthias Schwarzott <zzam@gentoo.org>
---
drivers/media/dvb-frontends/Kconfig | 1 +
drivers/media/dvb-frontends/si2165.c | 70 +++++++++++++-----------------------
2 files changed, 25 insertions(+), 46 deletions(-)
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index c645aa8..8272c08 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -67,6 +67,7 @@ config DVB_TDA18271C2DD
config DVB_SI2165
tristate "Silicon Labs si2165 based"
depends on DVB_CORE && I2C
+ select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
A DVB-C/T demodulator.
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index 9bf6609..d63cd73 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -25,6 +25,7 @@
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/firmware.h>
+#include <linux/regmap.h>
#include "dvb_frontend.h"
#include "dvb_math.h"
@@ -42,7 +43,7 @@
struct si2165_state {
struct i2c_client *client;
- struct i2c_adapter *i2c;
+ struct regmap *regmap;
struct dvb_frontend fe;
@@ -110,61 +111,27 @@ static int si2165_write(struct si2165_state *state, const u16 reg,
const u8 *src, const int count)
{
int ret;
- struct i2c_msg msg;
- u8 buf[2 + 4]; /* write a maximum of 4 bytes of data */
-
- if (count + 2 > sizeof(buf)) {
- dev_warn(&state->client->dev,
- "%s: i2c wr reg=%04x: count=%d is too big!\n",
- KBUILD_MODNAME, reg, count);
- return -EINVAL;
- }
- buf[0] = reg >> 8;
- buf[1] = reg & 0xff;
- memcpy(buf + 2, src, count);
-
- msg.addr = state->config.i2c_addr;
- msg.flags = 0;
- msg.buf = buf;
- msg.len = count + 2;
if (debug & DEBUG_I2C_WRITE)
deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg, count, src);
- ret = i2c_transfer(state->i2c, &msg, 1);
+ ret = regmap_bulk_write(state->regmap, reg, src, count);
- if (ret != 1) {
+ if (ret)
dev_err(&state->client->dev, "%s: ret == %d\n", __func__, ret);
- if (ret < 0)
- return ret;
- else
- return -EREMOTEIO;
- }
- return 0;
+ return ret;
}
static int si2165_read(struct si2165_state *state,
const u16 reg, u8 *val, const int count)
{
- int ret;
- u8 reg_buf[] = { reg >> 8, reg & 0xff };
- struct i2c_msg msg[] = {
- { .addr = state->config.i2c_addr,
- .flags = 0, .buf = reg_buf, .len = 2 },
- { .addr = state->config.i2c_addr,
- .flags = I2C_M_RD, .buf = val, .len = count },
- };
+ int ret = regmap_bulk_read(state->regmap, reg, val, count);
- ret = i2c_transfer(state->i2c, msg, 2);
-
- if (ret != 2) {
+ if (ret) {
dev_err(&state->client->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n",
__func__, state->config.i2c_addr, reg, ret);
- if (ret < 0)
- return ret;
- else
- return -EREMOTEIO;
+ return ret;
}
if (debug & DEBUG_I2C_READ)
@@ -176,9 +143,9 @@ static int si2165_read(struct si2165_state *state,
static int si2165_readreg8(struct si2165_state *state,
const u16 reg, u8 *val)
{
- int ret;
-
- ret = si2165_read(state, reg, val, 1);
+ unsigned int val_tmp;
+ int ret = regmap_read(state->regmap, reg, &val_tmp);
+ *val = (u8)val_tmp;
deb_readreg("R(0x%04x)=0x%02x\n", reg, *val);
return ret;
}
@@ -196,7 +163,7 @@ static int si2165_readreg16(struct si2165_state *state,
static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val)
{
- return si2165_write(state, reg, &val, 1);
+ return regmap_write(state->regmap, reg, val);
}
static int si2165_writereg16(struct si2165_state *state, const u16 reg, u16 val)
@@ -1052,6 +1019,11 @@ static int si2165_probe(struct i2c_client *client,
u8 val;
char rev_char;
const char *chip_name;
+ static const struct regmap_config regmap_config = {
+ .reg_bits = 16,
+ .val_bits = 8,
+ .max_register = 0x08ff,
+ };
/* allocate memory for the internal state */
state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
@@ -1060,9 +1032,15 @@ static int si2165_probe(struct i2c_client *client,
goto error;
}
+ /* create regmap */
+ state->regmap = devm_regmap_init_i2c(client, ®map_config);
+ if (IS_ERR(state->regmap)) {
+ ret = PTR_ERR(state->regmap);
+ goto error;
+ }
+
/* setup the state */
state->client = client;
- state->i2c = client->adapter;
state->config.i2c_addr = client->addr;
state->config.chip_mode = pdata->chip_mode;
state->config.ref_freq_Hz = pdata->ref_freq_Hz;
--
2.9.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-07-26 7:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-26 7:09 [PATCH 1/7] si2165: support i2c_client attach Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 2/7] cx23885: attach si2165 driver via i2c_client Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 3/7] cx231xx: Prepare for attaching new style i2c_client DVB demod drivers Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 4/7] cx231xx: attach si2165 driver via i2c_client Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 5/7] si2165: Remove legacy attach Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 6/7] si2165: use i2c_client->dev instead of i2c_adapter->dev for logging Matthias Schwarzott
2016-07-26 7:09 ` [PATCH 7/7] si2165: switch to regmap Matthias Schwarzott
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).