2 * isl6421.h - driver for lnb supply and control ic ISL6421
4 * Copyright (C) 2006 Andrew de Quincey
5 * Copyright (C) 2006 Oliver Endriss
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * To obtain the license, point your browser to
19 * http://www.gnu.org/copyleft/gpl.html
22 * the project's page is at https://linuxtv.org
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>
32 #include <media/dvb_frontend.h>
39 struct i2c_adapter
*i2c
;
44 static int isl6421_set_voltage(struct dvb_frontend
*fe
,
45 enum fe_sec_voltage voltage
)
50 struct isl6421
*isl6421
= (struct isl6421
*) fe
->sec_priv
;
51 struct i2c_msg msg
[2] = {
53 .addr
= isl6421
->i2c_addr
,
55 .buf
= &isl6421
->config
,
58 .addr
= isl6421
->i2c_addr
,
66 isl6421
->config
&= ~(ISL6421_VSEL1
| ISL6421_EN1
);
74 isl6421
->config
|= ISL6421_EN1
;
78 isl6421
->config
|= (ISL6421_EN1
| ISL6421_VSEL1
);
85 * If LNBf were not powered on, disable dynamic current limit, as,
86 * according with datasheet, highly capacitive load on the output may
87 * cause a difficult start-up.
89 if (isl6421
->is_off
&& !is_off
)
90 isl6421
->config
|= ISL6421_DCL
;
92 isl6421
->config
|= isl6421
->override_or
;
93 isl6421
->config
&= isl6421
->override_and
;
95 ret
= i2c_transfer(isl6421
->i2c
, msg
, 2);
101 /* Store off status now incase future commands fail */
102 isl6421
->is_off
= is_off
;
104 /* On overflow, the device will try again after 900 ms (typically) */
105 if (!is_off
&& (buf
& ISL6421_OLF1
))
108 /* Re-enable dynamic current limit */
109 if ((isl6421
->config
& ISL6421_DCL
) &&
110 !(isl6421
->override_or
& ISL6421_DCL
)) {
111 isl6421
->config
&= ~ISL6421_DCL
;
113 ret
= i2c_transfer(isl6421
->i2c
, msg
, 2);
120 /* Check if overload flag is active. If so, disable power */
121 if (!is_off
&& (buf
& ISL6421_OLF1
)) {
122 isl6421
->config
&= ~(ISL6421_VSEL1
| ISL6421_EN1
);
123 ret
= i2c_transfer(isl6421
->i2c
, msg
, 1);
128 isl6421
->is_off
= true;
130 dev_warn(&isl6421
->i2c
->dev
,
131 "Overload current detected. disabling LNBf power\n");
138 static int isl6421_enable_high_lnb_voltage(struct dvb_frontend
*fe
, long arg
)
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
) };
146 isl6421
->config
|= ISL6421_LLC1
;
148 isl6421
->config
&= ~ISL6421_LLC1
;
150 isl6421
->config
|= isl6421
->override_or
;
151 isl6421
->config
&= isl6421
->override_and
;
153 return (i2c_transfer(isl6421
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
156 static int isl6421_set_tone(struct dvb_frontend
*fe
,
157 enum fe_sec_tone_mode tone
)
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
) };
166 isl6421
->config
|= ISL6421_ENT1
;
169 isl6421
->config
&= ~ISL6421_ENT1
;
175 isl6421
->config
|= isl6421
->override_or
;
176 isl6421
->config
&= isl6421
->override_and
;
178 return (i2c_transfer(isl6421
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
181 static void isl6421_release(struct dvb_frontend
*fe
)
184 isl6421_set_voltage(fe
, SEC_VOLTAGE_OFF
);
191 struct 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
)
194 struct isl6421
*isl6421
= kmalloc(sizeof(struct isl6421
), GFP_KERNEL
);
198 /* default configuration */
199 isl6421
->config
= ISL6421_ISEL1
;
201 isl6421
->i2c_addr
= i2c_addr
;
202 fe
->sec_priv
= isl6421
;
204 /* bits which should be forced to '1' */
205 isl6421
->override_or
= override_set
;
207 /* bits which should be forced to '0' */
208 isl6421
->override_and
= ~override_clear
;
210 /* detect if it is present or not */
211 if (isl6421_set_voltage(fe
, SEC_VOLTAGE_OFF
)) {
217 isl6421
->is_off
= true;
219 /* install release callback */
220 fe
->ops
.release_sec
= isl6421_release
;
222 /* override frontend ops */
223 fe
->ops
.set_voltage
= isl6421_set_voltage
;
224 fe
->ops
.enable_high_lnb_voltage
= isl6421_enable_high_lnb_voltage
;
226 fe
->ops
.set_tone
= isl6421_set_tone
;
230 EXPORT_SYMBOL(isl6421_attach
);
232 MODULE_DESCRIPTION("Driver for lnb supply and control ic isl6421");
233 MODULE_AUTHOR("Andrew de Quincey & Oliver Endriss");
234 MODULE_LICENSE("GPL");