diff options
author | Antti Palosaari <crope@iki.fi> | 2012-03-30 05:37:26 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-04-09 13:31:34 -0400 |
commit | f9263747b1669cbe21b7e21fe4316559cf5138f7 (patch) | |
tree | 8e34f9a7d6a6c47a7706c4eb1e99024bc791772e /drivers/media/common | |
parent | 3f1bfef8e79c53d5d697119a7e11e5db80c2d371 (diff) |
[media] Infineon TUA 9001 silicon tuner driver
Signed-off-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/common')
-rw-r--r-- | drivers/media/common/tuners/Kconfig | 6 | ||||
-rw-r--r-- | drivers/media/common/tuners/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/common/tuners/tua9001.c | 215 | ||||
-rw-r--r-- | drivers/media/common/tuners/tua9001.h | 46 | ||||
-rw-r--r-- | drivers/media/common/tuners/tua9001_priv.h | 34 |
5 files changed, 302 insertions, 0 deletions
diff --git a/drivers/media/common/tuners/Kconfig b/drivers/media/common/tuners/Kconfig index 4a6d5cef3964..ae8ebcfa6fa2 100644 --- a/drivers/media/common/tuners/Kconfig +++ b/drivers/media/common/tuners/Kconfig | |||
@@ -211,4 +211,10 @@ config MEDIA_TUNER_TDA18212 | |||
211 | help | 211 | help |
212 | NXP TDA18212 silicon tuner driver. | 212 | NXP TDA18212 silicon tuner driver. |
213 | 213 | ||
214 | config MEDIA_TUNER_TUA9001 | ||
215 | tristate "Infineon TUA 9001 silicon tuner" | ||
216 | depends on VIDEO_MEDIA && I2C | ||
217 | default m if MEDIA_TUNER_CUSTOMISE | ||
218 | help | ||
219 | Infineon TUA 9001 silicon tuner driver. | ||
214 | endmenu | 220 | endmenu |
diff --git a/drivers/media/common/tuners/Makefile b/drivers/media/common/tuners/Makefile index f80407eb8998..6c3040501c45 100644 --- a/drivers/media/common/tuners/Makefile +++ b/drivers/media/common/tuners/Makefile | |||
@@ -28,6 +28,7 @@ obj-$(CONFIG_MEDIA_TUNER_MC44S803) += mc44s803.o | |||
28 | obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o | 28 | obj-$(CONFIG_MEDIA_TUNER_MAX2165) += max2165.o |
29 | obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o | 29 | obj-$(CONFIG_MEDIA_TUNER_TDA18218) += tda18218.o |
30 | obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o | 30 | obj-$(CONFIG_MEDIA_TUNER_TDA18212) += tda18212.o |
31 | obj-$(CONFIG_MEDIA_TUNER_TUA9001) += tua9001.o | ||
31 | 32 | ||
32 | ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core | 33 | ccflags-y += -I$(srctree)/drivers/media/dvb/dvb-core |
33 | ccflags-y += -I$(srctree)/drivers/media/dvb/frontends | 34 | ccflags-y += -I$(srctree)/drivers/media/dvb/frontends |
diff --git a/drivers/media/common/tuners/tua9001.c b/drivers/media/common/tuners/tua9001.c new file mode 100644 index 000000000000..de2607084672 --- /dev/null +++ b/drivers/media/common/tuners/tua9001.c | |||
@@ -0,0 +1,215 @@ | |||
1 | /* | ||
2 | * Infineon TUA 9001 silicon tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #include "tua9001.h" | ||
22 | #include "tua9001_priv.h" | ||
23 | |||
24 | /* write register */ | ||
25 | static int tua9001_wr_reg(struct tua9001_priv *priv, u8 reg, u16 val) | ||
26 | { | ||
27 | int ret; | ||
28 | u8 buf[3] = { reg, (val >> 8) & 0xff, (val >> 0) & 0xff }; | ||
29 | struct i2c_msg msg[1] = { | ||
30 | { | ||
31 | .addr = priv->cfg->i2c_addr, | ||
32 | .flags = 0, | ||
33 | .len = sizeof(buf), | ||
34 | .buf = buf, | ||
35 | } | ||
36 | }; | ||
37 | |||
38 | ret = i2c_transfer(priv->i2c, msg, 1); | ||
39 | if (ret == 1) { | ||
40 | ret = 0; | ||
41 | } else { | ||
42 | printk(KERN_WARNING "%s: I2C wr failed=%d reg=%02x\n", | ||
43 | __func__, ret, reg); | ||
44 | ret = -EREMOTEIO; | ||
45 | } | ||
46 | |||
47 | return ret; | ||
48 | } | ||
49 | |||
50 | static int tua9001_release(struct dvb_frontend *fe) | ||
51 | { | ||
52 | kfree(fe->tuner_priv); | ||
53 | fe->tuner_priv = NULL; | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static int tua9001_init(struct dvb_frontend *fe) | ||
59 | { | ||
60 | struct tua9001_priv *priv = fe->tuner_priv; | ||
61 | int ret = 0; | ||
62 | u8 i; | ||
63 | struct reg_val data[] = { | ||
64 | { 0x1e, 0x6512 }, | ||
65 | { 0x25, 0xb888 }, | ||
66 | { 0x39, 0x5460 }, | ||
67 | { 0x3b, 0x00c0 }, | ||
68 | { 0x3a, 0xf000 }, | ||
69 | { 0x08, 0x0000 }, | ||
70 | { 0x32, 0x0030 }, | ||
71 | { 0x41, 0x703a }, | ||
72 | { 0x40, 0x1c78 }, | ||
73 | { 0x2c, 0x1c00 }, | ||
74 | { 0x36, 0xc013 }, | ||
75 | { 0x37, 0x6f18 }, | ||
76 | { 0x27, 0x0008 }, | ||
77 | { 0x2a, 0x0001 }, | ||
78 | { 0x34, 0x0a40 }, | ||
79 | }; | ||
80 | |||
81 | if (fe->ops.i2c_gate_ctrl) | ||
82 | fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */ | ||
83 | |||
84 | for (i = 0; i < ARRAY_SIZE(data); i++) { | ||
85 | ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); | ||
86 | if (ret) | ||
87 | break; | ||
88 | } | ||
89 | |||
90 | if (fe->ops.i2c_gate_ctrl) | ||
91 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */ | ||
92 | |||
93 | if (ret < 0) | ||
94 | pr_debug("%s: failed=%d\n", __func__, ret); | ||
95 | |||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | static int tua9001_set_params(struct dvb_frontend *fe) | ||
100 | { | ||
101 | struct tua9001_priv *priv = fe->tuner_priv; | ||
102 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; | ||
103 | int ret, i; | ||
104 | u16 val; | ||
105 | u32 frequency; | ||
106 | struct reg_val data[2]; | ||
107 | |||
108 | pr_debug("%s: delivery_system=%d frequency=%d bandwidth_hz=%d\n", | ||
109 | __func__, c->delivery_system, c->frequency, | ||
110 | c->bandwidth_hz); | ||
111 | |||
112 | switch (c->delivery_system) { | ||
113 | case SYS_DVBT: | ||
114 | switch (c->bandwidth_hz) { | ||
115 | case 8000000: | ||
116 | val = 0x0000; | ||
117 | break; | ||
118 | case 7000000: | ||
119 | val = 0x1000; | ||
120 | break; | ||
121 | case 6000000: | ||
122 | val = 0x2000; | ||
123 | break; | ||
124 | case 5000000: | ||
125 | val = 0x3000; | ||
126 | break; | ||
127 | default: | ||
128 | ret = -EINVAL; | ||
129 | goto err; | ||
130 | } | ||
131 | break; | ||
132 | default: | ||
133 | ret = -EINVAL; | ||
134 | goto err; | ||
135 | } | ||
136 | |||
137 | data[0].reg = 0x04; | ||
138 | data[0].val = val; | ||
139 | |||
140 | frequency = (c->frequency - 150000000); | ||
141 | frequency /= 100; | ||
142 | frequency *= 48; | ||
143 | frequency /= 10000; | ||
144 | |||
145 | data[1].reg = 0x1f; | ||
146 | data[1].val = frequency; | ||
147 | |||
148 | if (fe->ops.i2c_gate_ctrl) | ||
149 | fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c-gate */ | ||
150 | |||
151 | for (i = 0; i < ARRAY_SIZE(data); i++) { | ||
152 | ret = tua9001_wr_reg(priv, data[i].reg, data[i].val); | ||
153 | if (ret < 0) | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | if (fe->ops.i2c_gate_ctrl) | ||
158 | fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c-gate */ | ||
159 | |||
160 | err: | ||
161 | if (ret < 0) | ||
162 | pr_debug("%s: failed=%d\n", __func__, ret); | ||
163 | |||
164 | return ret; | ||
165 | } | ||
166 | |||
167 | static int tua9001_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) | ||
168 | { | ||
169 | *frequency = 0; /* Zero-IF */ | ||
170 | |||
171 | return 0; | ||
172 | } | ||
173 | |||
174 | static const struct dvb_tuner_ops tua9001_tuner_ops = { | ||
175 | .info = { | ||
176 | .name = "Infineon TUA 9001", | ||
177 | |||
178 | .frequency_min = 170000000, | ||
179 | .frequency_max = 862000000, | ||
180 | .frequency_step = 0, | ||
181 | }, | ||
182 | |||
183 | .release = tua9001_release, | ||
184 | |||
185 | .init = tua9001_init, | ||
186 | .set_params = tua9001_set_params, | ||
187 | |||
188 | .get_if_frequency = tua9001_get_if_frequency, | ||
189 | }; | ||
190 | |||
191 | struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | ||
192 | struct i2c_adapter *i2c, struct tua9001_config *cfg) | ||
193 | { | ||
194 | struct tua9001_priv *priv = NULL; | ||
195 | |||
196 | priv = kzalloc(sizeof(struct tua9001_priv), GFP_KERNEL); | ||
197 | if (priv == NULL) | ||
198 | return NULL; | ||
199 | |||
200 | priv->cfg = cfg; | ||
201 | priv->i2c = i2c; | ||
202 | |||
203 | printk(KERN_INFO "Infineon TUA 9001 successfully attached."); | ||
204 | |||
205 | memcpy(&fe->ops.tuner_ops, &tua9001_tuner_ops, | ||
206 | sizeof(struct dvb_tuner_ops)); | ||
207 | |||
208 | fe->tuner_priv = priv; | ||
209 | return fe; | ||
210 | } | ||
211 | EXPORT_SYMBOL(tua9001_attach); | ||
212 | |||
213 | MODULE_DESCRIPTION("Infineon TUA 9001 silicon tuner driver"); | ||
214 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); | ||
215 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/media/common/tuners/tua9001.h b/drivers/media/common/tuners/tua9001.h new file mode 100644 index 000000000000..38d6ae76b1d6 --- /dev/null +++ b/drivers/media/common/tuners/tua9001.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Infineon TUA 9001 silicon tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef TUA9001_H | ||
22 | #define TUA9001_H | ||
23 | |||
24 | #include "dvb_frontend.h" | ||
25 | |||
26 | struct tua9001_config { | ||
27 | /* | ||
28 | * I2C address | ||
29 | */ | ||
30 | u8 i2c_addr; | ||
31 | }; | ||
32 | |||
33 | #if defined(CONFIG_MEDIA_TUNER_TUA9001) || \ | ||
34 | (defined(CONFIG_MEDIA_TUNER_TUA9001_MODULE) && defined(MODULE)) | ||
35 | extern struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | ||
36 | struct i2c_adapter *i2c, struct tua9001_config *cfg); | ||
37 | #else | ||
38 | static inline struct dvb_frontend *tua9001_attach(struct dvb_frontend *fe, | ||
39 | struct i2c_adapter *i2c, struct tua9001_config *cfg) | ||
40 | { | ||
41 | printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); | ||
42 | return NULL; | ||
43 | } | ||
44 | #endif | ||
45 | |||
46 | #endif | ||
diff --git a/drivers/media/common/tuners/tua9001_priv.h b/drivers/media/common/tuners/tua9001_priv.h new file mode 100644 index 000000000000..73cc1ce0575c --- /dev/null +++ b/drivers/media/common/tuners/tua9001_priv.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * Infineon TUA 9001 silicon tuner driver | ||
3 | * | ||
4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License along | ||
17 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | */ | ||
20 | |||
21 | #ifndef TUA9001_PRIV_H | ||
22 | #define TUA9001_PRIV_H | ||
23 | |||
24 | struct reg_val { | ||
25 | u8 reg; | ||
26 | u16 val; | ||
27 | }; | ||
28 | |||
29 | struct tua9001_priv { | ||
30 | struct tua9001_config *cfg; | ||
31 | struct i2c_adapter *i2c; | ||
32 | }; | ||
33 | |||
34 | #endif | ||