diff options
author | Manu Abraham <abraham.manu@gmail.com> | 2009-04-06 14:45:20 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-06-16 17:20:37 -0400 |
commit | e415c689a8842670e161581f060575c14957f073 (patch) | |
tree | ed18153bcad93a377f0ab6b5ac27554de9a9b614 /drivers/media/dvb/frontends/isl6423.c | |
parent | 2460cdac94082c7046ab595bf643338e6faed6cb (diff) |
V4L/DVB (11579): Initial go at TT S2-1600
[mchehab@redhat.com: fix compilation when the new drivers aren't selected]
Signed-off-by: Manu Abraham <manu@linuxtv.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/frontends/isl6423.c')
-rw-r--r-- | drivers/media/dvb/frontends/isl6423.c | 293 |
1 files changed, 293 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/isl6423.c b/drivers/media/dvb/frontends/isl6423.c new file mode 100644 index 000000000000..c1943dcb8db6 --- /dev/null +++ b/drivers/media/dvb/frontends/isl6423.c | |||
@@ -0,0 +1,293 @@ | |||
1 | /* | ||
2 | Intersil ISL6423 SEC and LNB Power supply controller | ||
3 | |||
4 | Copyright (C) Manu Abraham <abraham.manu@gmail.com> | ||
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 | ||
17 | along with this program; if not, write to the Free Software | ||
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | #include <linux/delay.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/string.h> | ||
27 | #include <linux/slab.h> | ||
28 | |||
29 | #include "dvb_frontend.h" | ||
30 | #include "isl6423.h" | ||
31 | |||
32 | static unsigned int verbose; | ||
33 | module_param(verbose, int, 0644); | ||
34 | MODULE_PARM_DESC(verbose, "Set Verbosity level"); | ||
35 | |||
36 | #define FE_ERROR 0 | ||
37 | #define FE_NOTICE 1 | ||
38 | #define FE_INFO 2 | ||
39 | #define FE_DEBUG 3 | ||
40 | #define FE_DEBUGREG 4 | ||
41 | |||
42 | #define dprintk(__y, __z, format, arg...) do { \ | ||
43 | if (__z) { \ | ||
44 | if ((verbose > FE_ERROR) && (verbose > __y)) \ | ||
45 | printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \ | ||
46 | else if ((verbose > FE_NOTICE) && (verbose > __y)) \ | ||
47 | printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \ | ||
48 | else if ((verbose > FE_INFO) && (verbose > __y)) \ | ||
49 | printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \ | ||
50 | else if ((verbose > FE_DEBUG) && (verbose > __y)) \ | ||
51 | printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \ | ||
52 | } else { \ | ||
53 | if (verbose > __y) \ | ||
54 | printk(format, ##arg); \ | ||
55 | } \ | ||
56 | } while (0) | ||
57 | |||
58 | struct isl6423_dev { | ||
59 | const struct isl6423_config *config; | ||
60 | struct i2c_adapter *i2c; | ||
61 | |||
62 | u8 reg_3; | ||
63 | u8 reg_4; | ||
64 | |||
65 | unsigned int verbose; | ||
66 | }; | ||
67 | |||
68 | static int isl6423_write(struct isl6423_dev *isl6423, u8 reg) | ||
69 | { | ||
70 | struct i2c_adapter *i2c = isl6423->i2c; | ||
71 | u8 addr = isl6423->config->addr; | ||
72 | int err = 0; | ||
73 | |||
74 | struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = ®, .len = 1 }; | ||
75 | |||
76 | err = i2c_transfer(i2c, &msg, 1); | ||
77 | if (err < 0) | ||
78 | goto exit; | ||
79 | return 0; | ||
80 | |||
81 | exit: | ||
82 | dprintk(FE_ERROR, 1, "I/O error <%d>", err); | ||
83 | return err; | ||
84 | } | ||
85 | |||
86 | static int isl6423_set_modulation(struct dvb_frontend *fe) | ||
87 | { | ||
88 | struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv; | ||
89 | const struct isl6423_config *config = isl6423->config; | ||
90 | int err = 0; | ||
91 | u8 reg_2 = 0; | ||
92 | |||
93 | reg_2 = 0x01 << 5; | ||
94 | |||
95 | if (config->mod_extern) | ||
96 | reg_2 |= (1 << 3); | ||
97 | else | ||
98 | reg_2 |= (1 << 4); | ||
99 | |||
100 | err = isl6423_write(isl6423, reg_2); | ||
101 | if (err < 0) | ||
102 | goto exit; | ||
103 | return 0; | ||
104 | |||
105 | exit: | ||
106 | dprintk(FE_ERROR, 1, "I/O error <%d>", err); | ||
107 | return err; | ||
108 | } | ||
109 | |||
110 | static int isl6423_voltage_boost(struct dvb_frontend *fe, long arg) | ||
111 | { | ||
112 | struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv; | ||
113 | u8 reg_3 = isl6423->reg_3; | ||
114 | u8 reg_4 = isl6423->reg_4; | ||
115 | int err = 0; | ||
116 | |||
117 | if (arg) { | ||
118 | /* EN = 1, VSPEN = 1, VBOT = 1 */ | ||
119 | reg_4 |= (1 << 4); | ||
120 | reg_4 |= 0x1; | ||
121 | reg_3 |= (1 << 3); | ||
122 | } else { | ||
123 | /* EN = 1, VSPEN = 1, VBOT = 0 */ | ||
124 | reg_4 |= (1 << 4); | ||
125 | reg_4 &= ~0x1; | ||
126 | reg_3 |= (1 << 3); | ||
127 | } | ||
128 | err = isl6423_write(isl6423, reg_3); | ||
129 | if (err < 0) | ||
130 | goto exit; | ||
131 | |||
132 | err = isl6423_write(isl6423, reg_4); | ||
133 | if (err < 0) | ||
134 | goto exit; | ||
135 | |||
136 | return 0; | ||
137 | exit: | ||
138 | dprintk(FE_ERROR, 1, "I/O error <%d>", err); | ||
139 | return err; | ||
140 | } | ||
141 | |||
142 | |||
143 | static int isl6423_set_voltage(struct dvb_frontend *fe, | ||
144 | enum fe_sec_voltage voltage) | ||
145 | { | ||
146 | struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv; | ||
147 | u8 reg_4 = isl6423->reg_4; | ||
148 | int err = 0; | ||
149 | |||
150 | /* SR4H = 0, SR4M = 1, SR4L = 1 */ | ||
151 | reg_4 = 0x03 << 5; | ||
152 | |||
153 | switch (voltage) { | ||
154 | case SEC_VOLTAGE_OFF: | ||
155 | /* EN = 0 */ | ||
156 | reg_4 &= ~(1 << 4); | ||
157 | break; | ||
158 | |||
159 | case SEC_VOLTAGE_13: | ||
160 | /* EN = 1, VSPEN = 1, VTOP = 0, VBOT = 0 */ | ||
161 | reg_4 |= (1 << 4); | ||
162 | reg_4 &= ~0x3; | ||
163 | break; | ||
164 | |||
165 | case SEC_VOLTAGE_18: | ||
166 | /* EN = 1, VSPEN = 1, VTOP = 1, VBOT = 0 */ | ||
167 | reg_4 |= (1 << 4); | ||
168 | reg_4 |= 0x2; | ||
169 | reg_4 &= ~0x1; | ||
170 | break; | ||
171 | |||
172 | default: | ||
173 | break; | ||
174 | } | ||
175 | err = isl6423_write(isl6423, reg_4); | ||
176 | if (err < 0) | ||
177 | goto exit; | ||
178 | |||
179 | return 0; | ||
180 | exit: | ||
181 | dprintk(FE_ERROR, 1, "I/O error <%d>", err); | ||
182 | return err; | ||
183 | } | ||
184 | |||
185 | static int isl6423_set_current(struct dvb_frontend *fe) | ||
186 | { | ||
187 | struct isl6423_dev *isl6423 = (struct isl6423_dev *) fe->sec_priv; | ||
188 | u8 reg_3 = isl6423->reg_3; | ||
189 | const struct isl6423_config *config = isl6423->config; | ||
190 | int err = 0; | ||
191 | |||
192 | /* SR3H = 0, SR3M = 1, SR3L = 0 */ | ||
193 | reg_3 = 0x02 << 5; | ||
194 | |||
195 | switch (config->current_max) { | ||
196 | case SEC_CURRENT_275m: | ||
197 | /* 275mA */ | ||
198 | /* ISELH = 0, ISELL = 0 */ | ||
199 | reg_3 &= ~0x3; | ||
200 | break; | ||
201 | |||
202 | case SEC_CURRENT_515m: | ||
203 | /* 515mA */ | ||
204 | /* ISELH = 0, ISELL = 1 */ | ||
205 | reg_3 &= ~0x2; | ||
206 | reg_3 |= 0x1; | ||
207 | break; | ||
208 | |||
209 | case SEC_CURRENT_635m: | ||
210 | /* 635mA */ | ||
211 | /* ISELH = 1, ISELL = 0 */ | ||
212 | reg_3 &= ~0x1; | ||
213 | reg_3 |= 0x2; | ||
214 | break; | ||
215 | |||
216 | case SEC_CURRENT_800m: | ||
217 | /* 800mA */ | ||
218 | /* ISELH = 1, ISELL = 1 */ | ||
219 | reg_3 |= 0x3; | ||
220 | break; | ||
221 | } | ||
222 | |||
223 | err = isl6423_write(isl6423, reg_3); | ||
224 | if (err < 0) | ||
225 | goto exit; | ||
226 | |||
227 | switch (config->curlim) { | ||
228 | case SEC_CURRENT_LIM_ON: | ||
229 | /* DCL = 1 */ | ||
230 | reg_3 |= 0x10; | ||
231 | break; | ||
232 | |||
233 | case SEC_CURRENT_LIM_OFF: | ||
234 | /* DCL = 0 */ | ||
235 | reg_3 &= ~0x10; | ||
236 | break; | ||
237 | } | ||
238 | |||
239 | err = isl6423_write(isl6423, reg_3); | ||
240 | if (err < 0) | ||
241 | goto exit; | ||
242 | |||
243 | return 0; | ||
244 | exit: | ||
245 | dprintk(FE_ERROR, 1, "I/O error <%d>", err); | ||
246 | return err; | ||
247 | } | ||
248 | |||
249 | static void isl6423_release(struct dvb_frontend *fe) | ||
250 | { | ||
251 | isl6423_set_voltage(fe, SEC_VOLTAGE_OFF); | ||
252 | |||
253 | kfree(fe->sec_priv); | ||
254 | fe->sec_priv = NULL; | ||
255 | } | ||
256 | |||
257 | struct dvb_frontend *isl6423_attach(struct dvb_frontend *fe, | ||
258 | struct i2c_adapter *i2c, | ||
259 | const struct isl6423_config *config) | ||
260 | { | ||
261 | struct isl6423_dev *isl6423; | ||
262 | |||
263 | isl6423 = kzalloc(sizeof(struct isl6423_dev), GFP_KERNEL); | ||
264 | if (!isl6423) | ||
265 | return NULL; | ||
266 | |||
267 | isl6423->config = config; | ||
268 | isl6423->i2c = i2c; | ||
269 | fe->sec_priv = isl6423; | ||
270 | |||
271 | if (isl6423_set_current(fe)) | ||
272 | goto exit; | ||
273 | |||
274 | if (isl6423_set_modulation(fe)) | ||
275 | goto exit; | ||
276 | |||
277 | fe->ops.release_sec = isl6423_release; | ||
278 | fe->ops.set_voltage = isl6423_set_voltage; | ||
279 | fe->ops.enable_high_lnb_voltage = isl6423_voltage_boost; | ||
280 | isl6423->verbose = verbose; | ||
281 | |||
282 | return fe; | ||
283 | |||
284 | exit: | ||
285 | kfree(isl6423); | ||
286 | fe->sec_priv = NULL; | ||
287 | return NULL; | ||
288 | } | ||
289 | EXPORT_SYMBOL(isl6423_attach); | ||
290 | |||
291 | MODULE_DESCRIPTION("ISL6423 SEC"); | ||
292 | MODULE_AUTHOR("Manu Abraham"); | ||
293 | MODULE_LICENSE("GPL"); | ||