aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schwarzott <zzam@gentoo.org>2016-07-26 03:09:08 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-09-22 11:56:35 -0400
commite3ea5e94489bc8c711d422dfa311cfa310553a1b (patch)
tree0ea260a3438207b883db847bce4e24d60c8487ef
parentaa15544909918f55299b49bd51042e242e64c425 (diff)
[media] si2165: switch to regmap
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> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--drivers/media/dvb-frontends/Kconfig1
-rw-r--r--drivers/media/dvb-frontends/si2165.c70
2 files changed, 25 insertions, 46 deletions
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index c4b67f71d979..012225587c25 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -67,6 +67,7 @@ config DVB_TDA18271C2DD
67config DVB_SI2165 67config DVB_SI2165
68 tristate "Silicon Labs si2165 based" 68 tristate "Silicon Labs si2165 based"
69 depends on DVB_CORE && I2C 69 depends on DVB_CORE && I2C
70 select REGMAP_I2C
70 default m if !MEDIA_SUBDRV_AUTOSELECT 71 default m if !MEDIA_SUBDRV_AUTOSELECT
71 help 72 help
72 A DVB-C/T demodulator. 73 A DVB-C/T demodulator.
diff --git a/drivers/media/dvb-frontends/si2165.c b/drivers/media/dvb-frontends/si2165.c
index 78543872d89d..78669ea68c61 100644
--- a/drivers/media/dvb-frontends/si2165.c
+++ b/drivers/media/dvb-frontends/si2165.c
@@ -25,6 +25,7 @@
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28#include <linux/regmap.h>
28 29
29#include "dvb_frontend.h" 30#include "dvb_frontend.h"
30#include "dvb_math.h" 31#include "dvb_math.h"
@@ -42,7 +43,7 @@
42struct si2165_state { 43struct si2165_state {
43 struct i2c_client *client; 44 struct i2c_client *client;
44 45
45 struct i2c_adapter *i2c; 46 struct regmap *regmap;
46 47
47 struct dvb_frontend fe; 48 struct dvb_frontend fe;
48 49
@@ -110,61 +111,27 @@ static int si2165_write(struct si2165_state *state, const u16 reg,
110 const u8 *src, const int count) 111 const u8 *src, const int count)
111{ 112{
112 int ret; 113 int ret;
113 struct i2c_msg msg;
114 u8 buf[2 + 4]; /* write a maximum of 4 bytes of data */
115
116 if (count + 2 > sizeof(buf)) {
117 dev_warn(&state->client->dev,
118 "%s: i2c wr reg=%04x: count=%d is too big!\n",
119 KBUILD_MODNAME, reg, count);
120 return -EINVAL;
121 }
122 buf[0] = reg >> 8;
123 buf[1] = reg & 0xff;
124 memcpy(buf + 2, src, count);
125
126 msg.addr = state->config.i2c_addr;
127 msg.flags = 0;
128 msg.buf = buf;
129 msg.len = count + 2;
130 114
131 if (debug & DEBUG_I2C_WRITE) 115 if (debug & DEBUG_I2C_WRITE)
132 deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg, count, src); 116 deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg, count, src);
133 117
134 ret = i2c_transfer(state->i2c, &msg, 1); 118 ret = regmap_bulk_write(state->regmap, reg, src, count);
135 119
136 if (ret != 1) { 120 if (ret)
137 dev_err(&state->client->dev, "%s: ret == %d\n", __func__, ret); 121 dev_err(&state->client->dev, "%s: ret == %d\n", __func__, ret);
138 if (ret < 0)
139 return ret;
140 else
141 return -EREMOTEIO;
142 }
143 122
144 return 0; 123 return ret;
145} 124}
146 125
147static int si2165_read(struct si2165_state *state, 126static int si2165_read(struct si2165_state *state,
148 const u16 reg, u8 *val, const int count) 127 const u16 reg, u8 *val, const int count)
149{ 128{
150 int ret; 129 int ret = regmap_bulk_read(state->regmap, reg, val, count);
151 u8 reg_buf[] = { reg >> 8, reg & 0xff };
152 struct i2c_msg msg[] = {
153 { .addr = state->config.i2c_addr,
154 .flags = 0, .buf = reg_buf, .len = 2 },
155 { .addr = state->config.i2c_addr,
156 .flags = I2C_M_RD, .buf = val, .len = count },
157 };
158 130
159 ret = i2c_transfer(state->i2c, msg, 2); 131 if (ret) {
160
161 if (ret != 2) {
162 dev_err(&state->client->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n", 132 dev_err(&state->client->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n",
163 __func__, state->config.i2c_addr, reg, ret); 133 __func__, state->config.i2c_addr, reg, ret);
164 if (ret < 0) 134 return ret;
165 return ret;
166 else
167 return -EREMOTEIO;
168 } 135 }
169 136
170 if (debug & DEBUG_I2C_READ) 137 if (debug & DEBUG_I2C_READ)
@@ -176,9 +143,9 @@ static int si2165_read(struct si2165_state *state,
176static int si2165_readreg8(struct si2165_state *state, 143static int si2165_readreg8(struct si2165_state *state,
177 const u16 reg, u8 *val) 144 const u16 reg, u8 *val)
178{ 145{
179 int ret; 146 unsigned int val_tmp;
180 147 int ret = regmap_read(state->regmap, reg, &val_tmp);
181 ret = si2165_read(state, reg, val, 1); 148 *val = (u8)val_tmp;
182 deb_readreg("R(0x%04x)=0x%02x\n", reg, *val); 149 deb_readreg("R(0x%04x)=0x%02x\n", reg, *val);
183 return ret; 150 return ret;
184} 151}
@@ -196,7 +163,7 @@ static int si2165_readreg16(struct si2165_state *state,
196 163
197static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val) 164static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val)
198{ 165{
199 return si2165_write(state, reg, &val, 1); 166 return regmap_write(state->regmap, reg, val);
200} 167}
201 168
202static int si2165_writereg16(struct si2165_state *state, const u16 reg, u16 val) 169static int si2165_writereg16(struct si2165_state *state, const u16 reg, u16 val)
@@ -1058,6 +1025,11 @@ static int si2165_probe(struct i2c_client *client,
1058 u8 val; 1025 u8 val;
1059 char rev_char; 1026 char rev_char;
1060 const char *chip_name; 1027 const char *chip_name;
1028 static const struct regmap_config regmap_config = {
1029 .reg_bits = 16,
1030 .val_bits = 8,
1031 .max_register = 0x08ff,
1032 };
1061 1033
1062 /* allocate memory for the internal state */ 1034 /* allocate memory for the internal state */
1063 state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL); 1035 state = kzalloc(sizeof(struct si2165_state), GFP_KERNEL);
@@ -1066,9 +1038,15 @@ static int si2165_probe(struct i2c_client *client,
1066 goto error; 1038 goto error;
1067 } 1039 }
1068 1040
1041 /* create regmap */
1042 state->regmap = devm_regmap_init_i2c(client, &regmap_config);
1043 if (IS_ERR(state->regmap)) {
1044 ret = PTR_ERR(state->regmap);
1045 goto error;
1046 }
1047
1069 /* setup the state */ 1048 /* setup the state */
1070 state->client = client; 1049 state->client = client;
1071 state->i2c = client->adapter;
1072 state->config.i2c_addr = client->addr; 1050 state->config.i2c_addr = client->addr;
1073 state->config.chip_mode = pdata->chip_mode; 1051 state->config.chip_mode = pdata->chip_mode;
1074 state->config.ref_freq_Hz = pdata->ref_freq_Hz; 1052 state->config.ref_freq_Hz = pdata->ref_freq_Hz;