diff options
author | Antti Palosaari <crope@iki.fi> | 2014-08-26 17:56:46 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2014-09-21 17:17:42 -0400 |
commit | 8da55c94dd85474a9925bd07a73959ae77a5aa6d (patch) | |
tree | 9c8d51a598f2b2ab61eb8aabb0047772bcd8915b /drivers/media/tuners | |
parent | 3b2a5e8c080da37be6135f44d236fe6b796666d9 (diff) |
[media] it913x: change reg read/write routines more common
Change register write and read routines to similar which are
typically used. We have to add processor core as a part of register
address in order to simplify register access. Chip has two cores,
called link and ofdm. As for now, use address bit 24 to address used
core. Bits 15:0 are register address in given core.
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/tuners')
-rw-r--r-- | drivers/media/tuners/it913x.c | 58 | ||||
-rw-r--r-- | drivers/media/tuners/it913x_priv.h | 69 |
2 files changed, 60 insertions, 67 deletions
diff --git a/drivers/media/tuners/it913x.c b/drivers/media/tuners/it913x.c index 72fefb753af1..7664878c9454 100644 --- a/drivers/media/tuners/it913x.c +++ b/drivers/media/tuners/it913x.c | |||
@@ -49,7 +49,6 @@ static int it913x_rd_regs(struct it913x_state *state, | |||
49 | b[0] = (u8)(reg >> 16) & 0xff; | 49 | b[0] = (u8)(reg >> 16) & 0xff; |
50 | b[1] = (u8)(reg >> 8) & 0xff; | 50 | b[1] = (u8)(reg >> 8) & 0xff; |
51 | b[2] = (u8) reg & 0xff; | 51 | b[2] = (u8) reg & 0xff; |
52 | b[0] |= 0x80; /* All reads from demodulator */ | ||
53 | 52 | ||
54 | ret = i2c_transfer(state->client->adapter, msg, 2); | 53 | ret = i2c_transfer(state->client->adapter, msg, 2); |
55 | 54 | ||
@@ -57,18 +56,21 @@ static int it913x_rd_regs(struct it913x_state *state, | |||
57 | } | 56 | } |
58 | 57 | ||
59 | /* read single register */ | 58 | /* read single register */ |
60 | static int it913x_rd_reg(struct it913x_state *state, u32 reg) | 59 | static int it913x_rd_reg(struct it913x_state *state, u32 reg, u8 *val) |
61 | { | 60 | { |
62 | int ret; | 61 | int ret; |
63 | u8 b[1]; | 62 | u8 b[1]; |
64 | 63 | ||
65 | ret = it913x_rd_regs(state, reg, &b[0], sizeof(b)); | 64 | ret = it913x_rd_regs(state, reg, &b[0], sizeof(b)); |
66 | return (ret < 0) ? -ENODEV : b[0]; | 65 | if (ret < 0) |
66 | return -ENODEV; | ||
67 | *val = b[0]; | ||
68 | return 0; | ||
67 | } | 69 | } |
68 | 70 | ||
69 | /* write multiple registers */ | 71 | /* write multiple registers */ |
70 | static int it913x_wr_regs(struct it913x_state *state, | 72 | static int it913x_wr_regs(struct it913x_state *state, |
71 | u8 pro, u32 reg, u8 buf[], u8 count) | 73 | u32 reg, u8 buf[], u8 count) |
72 | { | 74 | { |
73 | u8 b[256]; | 75 | u8 b[256]; |
74 | struct i2c_msg msg[1] = { | 76 | struct i2c_msg msg[1] = { |
@@ -82,9 +84,6 @@ static int it913x_wr_regs(struct it913x_state *state, | |||
82 | b[2] = (u8) reg & 0xff; | 84 | b[2] = (u8) reg & 0xff; |
83 | memcpy(&b[3], buf, count); | 85 | memcpy(&b[3], buf, count); |
84 | 86 | ||
85 | if (pro == PRO_DMOD) | ||
86 | b[0] |= 0x80; | ||
87 | |||
88 | ret = i2c_transfer(state->client->adapter, msg, 1); | 87 | ret = i2c_transfer(state->client->adapter, msg, 1); |
89 | 88 | ||
90 | if (ret < 0) | 89 | if (ret < 0) |
@@ -95,7 +94,7 @@ static int it913x_wr_regs(struct it913x_state *state, | |||
95 | 94 | ||
96 | /* write single register */ | 95 | /* write single register */ |
97 | static int it913x_wr_reg(struct it913x_state *state, | 96 | static int it913x_wr_reg(struct it913x_state *state, |
98 | u8 pro, u32 reg, u32 data) | 97 | u32 reg, u32 data) |
99 | { | 98 | { |
100 | int ret; | 99 | int ret; |
101 | u8 b[4]; | 100 | u8 b[4]; |
@@ -115,7 +114,7 @@ static int it913x_wr_reg(struct it913x_state *state, | |||
115 | else | 114 | else |
116 | s = 0; | 115 | s = 0; |
117 | 116 | ||
118 | ret = it913x_wr_regs(state, pro, reg, &b[s], sizeof(b) - s); | 117 | ret = it913x_wr_regs(state, reg, &b[s], sizeof(b) - s); |
119 | 118 | ||
120 | return ret; | 119 | return ret; |
121 | } | 120 | } |
@@ -129,9 +128,9 @@ static int it913x_script_loader(struct it913x_state *state, | |||
129 | return -EINVAL; | 128 | return -EINVAL; |
130 | 129 | ||
131 | for (i = 0; i < 1000; ++i) { | 130 | for (i = 0; i < 1000; ++i) { |
132 | if (loadscript[i].pro == 0xff) | 131 | if (loadscript[i].address == 0x000000) |
133 | break; | 132 | break; |
134 | ret = it913x_wr_regs(state, loadscript[i].pro, | 133 | ret = it913x_wr_regs(state, |
135 | loadscript[i].address, | 134 | loadscript[i].address, |
136 | loadscript[i].reg, loadscript[i].count); | 135 | loadscript[i].reg, loadscript[i].count); |
137 | if (ret < 0) | 136 | if (ret < 0) |
@@ -143,12 +142,13 @@ static int it913x_script_loader(struct it913x_state *state, | |||
143 | static int it913x_init(struct dvb_frontend *fe) | 142 | static int it913x_init(struct dvb_frontend *fe) |
144 | { | 143 | { |
145 | struct it913x_state *state = fe->tuner_priv; | 144 | struct it913x_state *state = fe->tuner_priv; |
146 | int ret, i, reg; | 145 | int ret, i; |
146 | u8 reg = 0; | ||
147 | u8 val, nv_val; | 147 | u8 val, nv_val; |
148 | u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2}; | 148 | u8 nv[] = {48, 32, 24, 16, 12, 8, 6, 4, 2}; |
149 | u8 b[2]; | 149 | u8 b[2]; |
150 | 150 | ||
151 | reg = it913x_rd_reg(state, 0xec86); | 151 | ret = it913x_rd_reg(state, 0x80ec86, ®); |
152 | switch (reg) { | 152 | switch (reg) { |
153 | case 0: | 153 | case 0: |
154 | state->tun_clk_mode = reg; | 154 | state->tun_clk_mode = reg; |
@@ -156,13 +156,8 @@ static int it913x_init(struct dvb_frontend *fe) | |||
156 | state->tun_fdiv = 3; | 156 | state->tun_fdiv = 3; |
157 | val = 16; | 157 | val = 16; |
158 | break; | 158 | break; |
159 | case -ENODEV: | ||
160 | /* FIXME: these are just avoid divide by 0 */ | ||
161 | state->tun_xtal = 2000; | ||
162 | state->tun_fdiv = 3; | ||
163 | return -ENODEV; | ||
164 | case 1: | 159 | case 1: |
165 | default: | 160 | default: /* I/O error too */ |
166 | state->tun_clk_mode = reg; | 161 | state->tun_clk_mode = reg; |
167 | state->tun_xtal = 640; | 162 | state->tun_xtal = 640; |
168 | state->tun_fdiv = 1; | 163 | state->tun_fdiv = 1; |
@@ -170,7 +165,7 @@ static int it913x_init(struct dvb_frontend *fe) | |||
170 | break; | 165 | break; |
171 | } | 166 | } |
172 | 167 | ||
173 | reg = it913x_rd_reg(state, 0xed03); | 168 | ret = it913x_rd_reg(state, 0x80ed03, ®); |
174 | 169 | ||
175 | if (reg < 0) | 170 | if (reg < 0) |
176 | return -ENODEV; | 171 | return -ENODEV; |
@@ -180,7 +175,7 @@ static int it913x_init(struct dvb_frontend *fe) | |||
180 | nv_val = 2; | 175 | nv_val = 2; |
181 | 176 | ||
182 | for (i = 0; i < 50; i++) { | 177 | for (i = 0; i < 50; i++) { |
183 | ret = it913x_rd_regs(state, 0xed23, &b[0], sizeof(b)); | 178 | ret = it913x_rd_regs(state, 0x80ed23, &b[0], sizeof(b)); |
184 | reg = (b[1] << 8) + b[0]; | 179 | reg = (b[1] << 8) + b[0]; |
185 | if (reg > 0) | 180 | if (reg > 0) |
186 | break; | 181 | break; |
@@ -196,21 +191,21 @@ static int it913x_init(struct dvb_frontend *fe) | |||
196 | msleep(50); | 191 | msleep(50); |
197 | else { | 192 | else { |
198 | for (i = 0; i < 50; i++) { | 193 | for (i = 0; i < 50; i++) { |
199 | reg = it913x_rd_reg(state, 0xec82); | 194 | ret = it913x_rd_reg(state, 0x80ec82, ®); |
195 | if (ret < 0) | ||
196 | return -ENODEV; | ||
200 | if (reg > 0) | 197 | if (reg > 0) |
201 | break; | 198 | break; |
202 | if (reg < 0) | ||
203 | return -ENODEV; | ||
204 | udelay(2000); | 199 | udelay(2000); |
205 | } | 200 | } |
206 | } | 201 | } |
207 | 202 | ||
208 | /* Power Up Tuner - common all versions */ | 203 | /* Power Up Tuner - common all versions */ |
209 | ret = it913x_wr_reg(state, PRO_DMOD, 0xec40, 0x1); | 204 | ret = it913x_wr_reg(state, 0x80ec40, 0x1); |
210 | ret |= it913x_wr_reg(state, PRO_DMOD, 0xec57, 0x0); | 205 | ret |= it913x_wr_reg(state, 0x80ec57, 0x0); |
211 | ret |= it913x_wr_reg(state, PRO_DMOD, 0xec58, 0x0); | 206 | ret |= it913x_wr_reg(state, 0x80ec58, 0x0); |
212 | 207 | ||
213 | return it913x_wr_reg(state, PRO_DMOD, 0xed81, val); | 208 | return it913x_wr_reg(state, 0x80ed81, val); |
214 | } | 209 | } |
215 | 210 | ||
216 | static int it9137_set_params(struct dvb_frontend *fe) | 211 | static int it9137_set_params(struct dvb_frontend *fe) |
@@ -220,7 +215,8 @@ static int it9137_set_params(struct dvb_frontend *fe) | |||
220 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; | 215 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
221 | u32 bandwidth = p->bandwidth_hz; | 216 | u32 bandwidth = p->bandwidth_hz; |
222 | u32 frequency_m = p->frequency; | 217 | u32 frequency_m = p->frequency; |
223 | int ret, reg; | 218 | int ret; |
219 | u8 reg = 0; | ||
224 | u32 frequency = frequency_m / 1000; | 220 | u32 frequency = frequency_m / 1000; |
225 | u32 freq, temp_f, tmp; | 221 | u32 freq, temp_f, tmp; |
226 | u16 iqik_m_cal; | 222 | u16 iqik_m_cal; |
@@ -321,7 +317,7 @@ static int it9137_set_params(struct dvb_frontend *fe) | |||
321 | } else | 317 | } else |
322 | return -EINVAL; | 318 | return -EINVAL; |
323 | 319 | ||
324 | reg = it913x_rd_reg(state, 0xed81); | 320 | ret = it913x_rd_reg(state, 0x80ed81, ®); |
325 | iqik_m_cal = (u16)reg * n_div; | 321 | iqik_m_cal = (u16)reg * n_div; |
326 | 322 | ||
327 | if (reg < 0x20) { | 323 | if (reg < 0x20) { |
@@ -412,7 +408,7 @@ static int it913x_probe(struct i2c_client *client, | |||
412 | state->firmware_ver = 1; | 408 | state->firmware_ver = 1; |
413 | 409 | ||
414 | /* tuner RF initial */ | 410 | /* tuner RF initial */ |
415 | ret = it913x_wr_reg(state, PRO_DMOD, 0xec4c, 0x68); | 411 | ret = it913x_wr_reg(state, 0x80ec4c, 0x68); |
416 | if (ret < 0) | 412 | if (ret < 0) |
417 | goto err; | 413 | goto err; |
418 | 414 | ||
diff --git a/drivers/media/tuners/it913x_priv.h b/drivers/media/tuners/it913x_priv.h index d624efde80aa..32af24c69cbb 100644 --- a/drivers/media/tuners/it913x_priv.h +++ b/drivers/media/tuners/it913x_priv.h | |||
@@ -25,63 +25,60 @@ | |||
25 | 25 | ||
26 | #include "it913x.h" | 26 | #include "it913x.h" |
27 | 27 | ||
28 | #define PRO_LINK 0x0 | ||
29 | #define PRO_DMOD 0x1 | ||
30 | #define TRIGGER_OFSM 0x0000 | 28 | #define TRIGGER_OFSM 0x0000 |
31 | 29 | ||
32 | struct it913xset { u32 pro; | 30 | struct it913xset { u32 address; |
33 | u32 address; | ||
34 | u8 reg[15]; | 31 | u8 reg[15]; |
35 | u8 count; | 32 | u8 count; |
36 | }; | 33 | }; |
37 | 34 | ||
38 | /* Tuner setting scripts for IT9135 AX */ | 35 | /* Tuner setting scripts for IT9135 AX */ |
39 | static struct it913xset it9135ax_tuner_off[] = { | 36 | static struct it913xset it9135ax_tuner_off[] = { |
40 | {PRO_DMOD, 0xec40, {0x00}, 0x01}, /* Power Down Tuner */ | 37 | {0x80ec40, {0x00}, 0x01}, /* Power Down Tuner */ |
41 | {PRO_DMOD, 0xec02, {0x3f}, 0x01}, | 38 | {0x80ec02, {0x3f}, 0x01}, |
42 | {PRO_DMOD, 0xec03, {0x1f}, 0x01}, | 39 | {0x80ec03, {0x1f}, 0x01}, |
43 | {PRO_DMOD, 0xec04, {0x3f}, 0x01}, | 40 | {0x80ec04, {0x3f}, 0x01}, |
44 | {PRO_DMOD, 0xec05, {0x3f}, 0x01}, | 41 | {0x80ec05, {0x3f}, 0x01}, |
45 | {PRO_DMOD, 0xec3f, {0x01}, 0x01}, | 42 | {0x80ec3f, {0x01}, 0x01}, |
46 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | 43 | {0x000000, {0x00}, 0x00}, /* Terminating Entry */ |
47 | }; | 44 | }; |
48 | 45 | ||
49 | /* Tuner setting scripts (still keeping it9137) */ | 46 | /* Tuner setting scripts (still keeping it9137) */ |
50 | static struct it913xset it9137_tuner_off[] = { | 47 | static struct it913xset it9137_tuner_off[] = { |
51 | {PRO_DMOD, 0xec40, {0x00}, 0x01}, /* Power Down Tuner */ | 48 | {0x80ec40, {0x00}, 0x01}, /* Power Down Tuner */ |
52 | {PRO_DMOD, 0xec02, {0x3f, 0x1f, 0x3f, 0x3f}, 0x04}, | 49 | {0x80ec02, {0x3f, 0x1f, 0x3f, 0x3f}, 0x04}, |
53 | {PRO_DMOD, 0xec06, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 50 | {0x80ec06, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
54 | 0x00, 0x00, 0x00, 0x00}, 0x0c}, | 51 | 0x00, 0x00, 0x00, 0x00}, 0x0c}, |
55 | {PRO_DMOD, 0xec12, {0x00, 0x00, 0x00, 0x00}, 0x04}, | 52 | {0x80ec12, {0x00, 0x00, 0x00, 0x00}, 0x04}, |
56 | {PRO_DMOD, 0xec17, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 53 | {0x80ec17, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
57 | 0x00}, 0x09}, | 54 | 0x00}, 0x09}, |
58 | {PRO_DMOD, 0xec22, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 55 | {0x80ec22, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
59 | 0x00, 0x00}, 0x0a}, | 56 | 0x00, 0x00}, 0x0a}, |
60 | {PRO_DMOD, 0xec20, {0x00}, 0x01}, | 57 | {0x80ec20, {0x00}, 0x01}, |
61 | {PRO_DMOD, 0xec3f, {0x01}, 0x01}, | 58 | {0x80ec3f, {0x01}, 0x01}, |
62 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | 59 | {0x000000, {0x00}, 0x00}, /* Terminating Entry */ |
63 | }; | 60 | }; |
64 | 61 | ||
65 | static struct it913xset set_it9135_template[] = { | 62 | static struct it913xset set_it9135_template[] = { |
66 | {PRO_DMOD, 0xee06, {0x00}, 0x01}, | 63 | {0x80ee06, {0x00}, 0x01}, |
67 | {PRO_DMOD, 0xec56, {0x00}, 0x01}, | 64 | {0x80ec56, {0x00}, 0x01}, |
68 | {PRO_DMOD, 0xec4c, {0x00}, 0x01}, | 65 | {0x80ec4c, {0x00}, 0x01}, |
69 | {PRO_DMOD, 0xec4d, {0x00}, 0x01}, | 66 | {0x80ec4d, {0x00}, 0x01}, |
70 | {PRO_DMOD, 0xec4e, {0x00}, 0x01}, | 67 | {0x80ec4e, {0x00}, 0x01}, |
71 | {PRO_DMOD, 0x011e, {0x00}, 0x01}, /* Older Devices */ | 68 | {0x80011e, {0x00}, 0x01}, /* Older Devices */ |
72 | {PRO_DMOD, 0x011f, {0x00}, 0x01}, | 69 | {0x80011f, {0x00}, 0x01}, |
73 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | 70 | {0x000000, {0x00}, 0x00}, /* Terminating Entry */ |
74 | }; | 71 | }; |
75 | 72 | ||
76 | static struct it913xset set_it9137_template[] = { | 73 | static struct it913xset set_it9137_template[] = { |
77 | {PRO_DMOD, 0xee06, {0x00}, 0x01}, | 74 | {0x80ee06, {0x00}, 0x01}, |
78 | {PRO_DMOD, 0xec56, {0x00}, 0x01}, | 75 | {0x80ec56, {0x00}, 0x01}, |
79 | {PRO_DMOD, 0xec4c, {0x00}, 0x01}, | 76 | {0x80ec4c, {0x00}, 0x01}, |
80 | {PRO_DMOD, 0xec4d, {0x00}, 0x01}, | 77 | {0x80ec4d, {0x00}, 0x01}, |
81 | {PRO_DMOD, 0xec4e, {0x00}, 0x01}, | 78 | {0x80ec4e, {0x00}, 0x01}, |
82 | {PRO_DMOD, 0xec4f, {0x00}, 0x01}, | 79 | {0x80ec4f, {0x00}, 0x01}, |
83 | {PRO_DMOD, 0xec50, {0x00}, 0x01}, | 80 | {0x80ec50, {0x00}, 0x01}, |
84 | {0xff, 0x0000, {0x00}, 0x00}, /* Terminating Entry */ | 81 | {0x000000, {0x00}, 0x00}, /* Terminating Entry */ |
85 | }; | 82 | }; |
86 | 83 | ||
87 | #endif | 84 | #endif |