diff options
author | Antti Palosaari <crope@iki.fi> | 2012-09-11 21:27:07 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-09-23 18:41:38 -0400 |
commit | 89054e37a8bb48c1633149122a538eb50f3c0d34 (patch) | |
tree | 27f724d9d661c3501b9cdc2062394fe216269913 /drivers/media/tuners | |
parent | 1835af1003655ab89fd78fc8e8fe69f4e5dcc465 (diff) |
[media] tua9001: implement control pin callbacks
There is three pins used for controlling that tuner.
Implement those using frontend callback.
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/tuners')
-rw-r--r-- | drivers/media/tuners/tua9001.c | 66 | ||||
-rw-r--r-- | drivers/media/tuners/tua9001.h | 20 |
2 files changed, 81 insertions, 5 deletions
diff --git a/drivers/media/tuners/tua9001.c b/drivers/media/tuners/tua9001.c index de2607084672..6147eeef4a66 100644 --- a/drivers/media/tuners/tua9001.c +++ b/drivers/media/tuners/tua9001.c | |||
@@ -49,10 +49,17 @@ static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val) | |||
49 | 49 | ||
50 | static int tua9001_release(struct dvb_frontend *fe) | 50 | static int tua9001_release(struct dvb_frontend *fe) |
51 | { | 51 | { |
52 | struct tua9001_priv *priv = fe->tuner_priv; | ||
53 | int ret = 0; | ||
54 | |||
55 | if (fe->callback) | ||
56 | ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, | ||
57 | TUA9001_CMD_CEN, 0); | ||
58 | |||
52 | kfree(fe->tuner_priv); | 59 | kfree(fe->tuner_priv); |
53 | fe->tuner_priv = NULL; | 60 | fe->tuner_priv = NULL; |
54 | 61 | ||
55 | return 0; | 62 | return ret; |
56 | } | 63 | } |
57 | 64 | ||
58 | static int tua9001_init(struct dvb_frontend *fe) | 65 | static int tua9001_init(struct dvb_frontend *fe) |
@@ -78,17 +85,40 @@ static int tua9001_init(struct dvb_frontend *fe) | |||
78 | { 0x34, 0x0a40 }, | 85 | { 0x34, 0x0a40 }, |
79 | }; | 86 | }; |
80 | 87 | ||
88 | if (fe->callback) { | ||
89 | ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, | ||
90 | TUA9001_CMD_RESETN, 0); | ||
91 | if (ret < 0) | ||
92 | goto err; | ||
93 | } | ||
94 | |||
81 | if (fe->ops.i2c_gate_ctrl) | 95 | if (fe->ops.i2c_gate_ctrl) |
82 | fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */ | 96 | fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */ |
83 | 97 | ||
84 | for (i = 0; i < ARRAY_SIZE(data); i++) { | 98 | for (i = 0; i < ARRAY_SIZE(data); i++) { |
85 | ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); | 99 | ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); |
86 | if (ret) | 100 | if (ret < 0) |
87 | break; | 101 | goto err_i2c_gate_ctrl; |
88 | } | 102 | } |
89 | 103 | ||
104 | err_i2c_gate_ctrl: | ||
90 | if (fe->ops.i2c_gate_ctrl) | 105 | if (fe->ops.i2c_gate_ctrl) |
91 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */ | 106 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */ |
107 | err: | ||
108 | if (ret < 0) | ||
109 | pr_debug("%s: failed=%d\n", __func__, ret); | ||
110 | |||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | static int tua9001_sleep(struct dvb_frontend *fe) | ||
115 | { | ||
116 | struct tua9001_priv *priv = fe->tuner_priv; | ||
117 | int ret = 0; | ||
118 | |||
119 | if (fe->callback) | ||
120 | ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, | ||
121 | TUA9001_CMD_RESETN, 1); | ||
92 | 122 | ||
93 | if (ret < 0) | 123 | if (ret < 0) |
94 | pr_debug("%s: failed=%d\n", __func__, ret); | 124 | pr_debug("%s: failed=%d\n", __func__, ret); |
@@ -148,15 +178,29 @@ static int tua9001_set_params(struct dvb_frontend *fe) | |||
148 | if (fe->ops.i2c_gate_ctrl) | 178 | if (fe->ops.i2c_gate_ctrl) |
149 | fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */ | 179 | fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */ |
150 | 180 | ||
181 | if (fe->callback) { | ||
182 | ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, | ||
183 | TUA9001_CMD_RXEN, 0); | ||
184 | if (ret < 0) | ||
185 | goto err_i2c_gate_ctrl; | ||
186 | } | ||
187 | |||
151 | for (i = 0; i < ARRAY_SIZE(data); i++) { | 188 | for (i = 0; i < ARRAY_SIZE(data); i++) { |
152 | ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); | 189 | ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); |
153 | if (ret < 0) | 190 | if (ret < 0) |
154 | break; | 191 | goto err_i2c_gate_ctrl; |
192 | } | ||
193 | |||
194 | if (fe->callback) { | ||
195 | ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, | ||
196 | TUA9001_CMD_RXEN, 1); | ||
197 | if (ret < 0) | ||
198 | goto err_i2c_gate_ctrl; | ||
155 | } | 199 | } |
156 | 200 | ||
201 | err_i2c_gate_ctrl: | ||
157 | if (fe->ops.i2c_gate_ctrl) | 202 | if (fe->ops.i2c_gate_ctrl) |
158 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */ | 203 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */ |
159 | |||
160 | err: | 204 | err: |
161 | if (ret < 0) | 205 | if (ret < 0) |
162 | pr_debug("%s: failed=%d\n", __func__, ret); | 206 | pr_debug("%s: failed=%d\n", __func__, ret); |
@@ -183,6 +227,7 @@ static const struct dvb_tuner_ops tua9001_tuner_ops = { | |||
183 | .release = tua9001_release, | 227 | .release = tua9001_release, |
184 | 228 | ||
185 | .init = tua9001_init, | 229 | .init = tua9001_init, |
230 | .sleep = tua9001_sleep, | ||
186 | .set_params = tua9001_set_params, | 231 | .set_params = tua9001_set_params, |
187 | 232 | ||
188 | .get_if_frequency = tua9001_get_if_frequency, | 233 | .get_if_frequency = tua9001_get_if_frequency, |
@@ -192,6 +237,7 @@ struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | |||
192 | struct i2c_adapter *i2c, struct tua9001_config *cfg) | 237 | struct i2c_adapter *i2c, struct tua9001_config *cfg) |
193 | { | 238 | { |
194 | struct tua9001_priv *priv = NULL; | 239 | struct tua9001_priv *priv = NULL; |
240 | int ret; | ||
195 | 241 | ||
196 | priv = kzalloc(sizeof(struct tua9001_priv), GFP_KERNEL); | 242 | priv = kzalloc(sizeof(struct tua9001_priv), GFP_KERNEL); |
197 | if (priv == NULL) | 243 | if (priv == NULL) |
@@ -200,6 +246,13 @@ struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | |||
200 | priv->cfg = cfg; | 246 | priv->cfg = cfg; |
201 | priv->i2c = i2c; | 247 | priv->i2c = i2c; |
202 | 248 | ||
249 | if (fe->callback) { | ||
250 | ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, | ||
251 | TUA9001_CMD_CEN, 1); | ||
252 | if (ret < 0) | ||
253 | goto err; | ||
254 | } | ||
255 | |||
203 | printk(KERN_INFO "Infineon TUA 9001 successfully attached."); | 256 | printk(KERN_INFO "Infineon TUA 9001 successfully attached."); |
204 | 257 | ||
205 | memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops, | 258 | memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops, |
@@ -207,6 +260,9 @@ struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | |||
207 | 260 | ||
208 | fe->tuner_priv = priv; | 261 | fe->tuner_priv = priv; |
209 | return fe; | 262 | return fe; |
263 | err: | ||
264 | kfree(priv); | ||
265 | return NULL; | ||
210 | } | 266 | } |
211 | EXPORT_SYMBOL(tua9001_attach); | 267 | EXPORT_SYMBOL(tua9001_attach); |
212 | 268 | ||
diff --git a/drivers/media/tuners/tua9001.h b/drivers/media/tuners/tua9001.h index 38d6ae76b1d6..cf5b815feff9 100644 --- a/drivers/media/tuners/tua9001.h +++ b/drivers/media/tuners/tua9001.h | |||
@@ -30,6 +30,26 @@ struct tua9001_config { | |||
30 | u8 i2c_addr; | 30 | u8 i2c_addr; |
31 | }; | 31 | }; |
32 | 32 | ||
33 | /* | ||
34 | * TUA9001 I/O PINs: | ||
35 | * | ||
36 | * CEN - chip enable | ||
37 | * 0 = chip disabled (chip off) | ||
38 | * 1 = chip enabled (chip on) | ||
39 | * | ||
40 | * RESETN - chip reset | ||
41 | * 0 = reset disabled (chip reset off) | ||
42 | * 1 = reset enabled (chip reset on) | ||
43 | * | ||
44 | * RXEN - RX enable | ||
45 | * 0 = RX disabled (chip idle) | ||
46 | * 1 = RX enabled (chip tuned) | ||
47 | */ | ||
48 | |||
49 | #define TUA9001_CMD_CEN 0 | ||
50 | #define TUA9001_CMD_RESETN 1 | ||
51 | #define TUA9001_CMD_RXEN 2 | ||
52 | |||
33 | #if defined(CONFIG_MEDIA_TUNER_TUA9001) || \ | 53 | #if defined(CONFIG_MEDIA_TUNER_TUA9001) || \ |
34 | (defined(CONFIG_MEDIA_TUNER_TUA9001_MODULE) && defined(MODULE)) | 54 | (defined(CONFIG_MEDIA_TUNER_TUA9001_MODULE) && defined(MODULE)) |
35 | extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | 55 | extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, |