1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/delay.h>
25#include <linux/errno.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/string.h>
30#include <linux/slab.h>
31
32#include <media/dvb_frontend.h>
33#include "isl6421.h"
34
35struct isl6421 {
36 u8 config;
37 u8 override_or;
38 u8 override_and;
39 struct i2c_adapter *i2c;
40 u8 i2c_addr;
41 bool is_off;
42};
43
44static int isl6421_set_voltage(struct dvb_frontend *fe,
45 enum fe_sec_voltage voltage)
46{
47 int ret;
48 u8 buf;
49 bool is_off;
50 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
51 struct i2c_msg msg[2] = {
52 {
53 .addr = isl6421->i2c_addr,
54 .flags = 0,
55 .buf = &isl6421->config,
56 .len = 1,
57 }, {
58 .addr = isl6421->i2c_addr,
59 .flags = I2C_M_RD,
60 .buf = &buf,
61 .len = 1,
62 }
63
64 };
65
66 isl6421->config &= ~(ISL6421_VSEL1 | ISL6421_EN1);
67
68 switch(voltage) {
69 case SEC_VOLTAGE_OFF:
70 is_off = true;
71 break;
72 case SEC_VOLTAGE_13:
73 is_off = false;
74 isl6421->config |= ISL6421_EN1;
75 break;
76 case SEC_VOLTAGE_18:
77 is_off = false;
78 isl6421->config |= (ISL6421_EN1 | ISL6421_VSEL1);
79 break;
80 default:
81 return -EINVAL;
82 }
83
84
85
86
87
88
89 if (isl6421->is_off && !is_off)
90 isl6421->config |= ISL6421_DCL;
91
92 isl6421->config |= isl6421->override_or;
93 isl6421->config &= isl6421->override_and;
94
95 ret = i2c_transfer(isl6421->i2c, msg, 2);
96 if (ret < 0)
97 return ret;
98 if (ret != 2)
99 return -EIO;
100
101
102 isl6421->is_off = is_off;
103
104
105 if (!is_off && (buf & ISL6421_OLF1))
106 msleep(1000);
107
108
109 if ((isl6421->config & ISL6421_DCL) &&
110 !(isl6421->override_or & ISL6421_DCL)) {
111 isl6421->config &= ~ISL6421_DCL;
112
113 ret = i2c_transfer(isl6421->i2c, msg, 2);
114 if (ret < 0)
115 return ret;
116 if (ret != 2)
117 return -EIO;
118 }
119
120
121 if (!is_off && (buf & ISL6421_OLF1)) {
122 isl6421->config &= ~(ISL6421_VSEL1 | ISL6421_EN1);
123 ret = i2c_transfer(isl6421->i2c, msg, 1);
124 if (ret < 0)
125 return ret;
126 if (ret != 1)
127 return -EIO;
128 isl6421->is_off = true;
129
130 dev_warn(&isl6421->i2c->dev,
131 "Overload current detected. disabling LNBf power\n");
132 return -EINVAL;
133 }
134
135 return 0;
136}
137
138static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
139{
140 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
141 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
142 .buf = &isl6421->config,
143 .len = sizeof(isl6421->config) };
144
145 if (arg)
146 isl6421->config |= ISL6421_LLC1;
147 else
148 isl6421->config &= ~ISL6421_LLC1;
149
150 isl6421->config |= isl6421->override_or;
151 isl6421->config &= isl6421->override_and;
152
153 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
154}
155
156static int isl6421_set_tone(struct dvb_frontend *fe,
157 enum fe_sec_tone_mode tone)
158{
159 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
160 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
161 .buf = &isl6421->config,
162 .len = sizeof(isl6421->config) };
163
164 switch (tone) {
165 case SEC_TONE_ON:
166 isl6421->config |= ISL6421_ENT1;
167 break;
168 case SEC_TONE_OFF:
169 isl6421->config &= ~ISL6421_ENT1;
170 break;
171 default:
172 return -EINVAL;
173 }
174
175 isl6421->config |= isl6421->override_or;
176 isl6421->config &= isl6421->override_and;
177
178 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
179}
180
181static void isl6421_release(struct dvb_frontend *fe)
182{
183
184 isl6421_set_voltage(fe, SEC_VOLTAGE_OFF);
185
186
187 kfree(fe->sec_priv);
188 fe->sec_priv = NULL;
189}
190
191struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
192 u8 override_set, u8 override_clear, bool override_tone)
193{
194 struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL);
195 if (!isl6421)
196 return NULL;
197
198
199 isl6421->config = ISL6421_ISEL1;
200 isl6421->i2c = i2c;
201 isl6421->i2c_addr = i2c_addr;
202 fe->sec_priv = isl6421;
203
204
205 isl6421->override_or = override_set;
206
207
208 isl6421->override_and = ~override_clear;
209
210
211 if (isl6421_set_voltage(fe, SEC_VOLTAGE_OFF)) {
212 kfree(isl6421);
213 fe->sec_priv = NULL;
214 return NULL;
215 }
216
217 isl6421->is_off = true;
218
219
220 fe->ops.release_sec = isl6421_release;
221
222
223 fe->ops.set_voltage = isl6421_set_voltage;
224 fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage;
225 if (override_tone)
226 fe->ops.set_tone = isl6421_set_tone;
227
228 return fe;
229}
230EXPORT_SYMBOL(isl6421_attach);
231
232MODULE_DESCRIPTION("Driver for lnb supply and control ic isl6421");
233MODULE_AUTHOR("Andrew de Quincey & Oliver Endriss");
234MODULE_LICENSE("GPL");
235