2 * lnbp21.c - driver for lnb supply and control ic lnbp21
4 * Copyright (C) 2006, 2009 Oliver Endriss <o.endriss@gmx.de>
5 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru>
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>
40 struct i2c_adapter
*i2c
;
44 static int lnbp21_set_voltage(struct dvb_frontend
*fe
,
45 enum fe_sec_voltage voltage
)
47 struct lnbp21
*lnbp21
= (struct lnbp21
*) fe
->sec_priv
;
48 struct i2c_msg msg
= { .addr
= lnbp21
->i2c_addr
, .flags
= 0,
49 .buf
= &lnbp21
->config
,
50 .len
= sizeof(lnbp21
->config
) };
52 lnbp21
->config
&= ~(LNBP21_VSEL
| LNBP21_EN
);
58 lnbp21
->config
|= LNBP21_EN
;
61 lnbp21
->config
|= (LNBP21_EN
| LNBP21_VSEL
);
67 lnbp21
->config
|= lnbp21
->override_or
;
68 lnbp21
->config
&= lnbp21
->override_and
;
70 return (i2c_transfer(lnbp21
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
73 static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend
*fe
, long arg
)
75 struct lnbp21
*lnbp21
= (struct lnbp21
*) fe
->sec_priv
;
76 struct i2c_msg msg
= { .addr
= lnbp21
->i2c_addr
, .flags
= 0,
77 .buf
= &lnbp21
->config
,
78 .len
= sizeof(lnbp21
->config
) };
81 lnbp21
->config
|= LNBP21_LLC
;
83 lnbp21
->config
&= ~LNBP21_LLC
;
85 lnbp21
->config
|= lnbp21
->override_or
;
86 lnbp21
->config
&= lnbp21
->override_and
;
88 return (i2c_transfer(lnbp21
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
91 static int lnbp21_set_tone(struct dvb_frontend
*fe
,
92 enum fe_sec_tone_mode tone
)
94 struct lnbp21
*lnbp21
= (struct lnbp21
*) fe
->sec_priv
;
95 struct i2c_msg msg
= { .addr
= lnbp21
->i2c_addr
, .flags
= 0,
96 .buf
= &lnbp21
->config
,
97 .len
= sizeof(lnbp21
->config
) };
101 lnbp21
->config
&= ~LNBP21_TEN
;
104 lnbp21
->config
|= LNBP21_TEN
;
110 lnbp21
->config
|= lnbp21
->override_or
;
111 lnbp21
->config
&= lnbp21
->override_and
;
113 return (i2c_transfer(lnbp21
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
116 static void lnbp21_release(struct dvb_frontend
*fe
)
119 lnbp21_set_voltage(fe
, SEC_VOLTAGE_OFF
);
126 static struct dvb_frontend
*lnbx2x_attach(struct dvb_frontend
*fe
,
127 struct i2c_adapter
*i2c
, u8 override_set
,
128 u8 override_clear
, u8 i2c_addr
, u8 config
)
130 struct lnbp21
*lnbp21
= kmalloc(sizeof(struct lnbp21
), GFP_KERNEL
);
134 /* default configuration */
135 lnbp21
->config
= config
;
137 lnbp21
->i2c_addr
= i2c_addr
;
138 fe
->sec_priv
= lnbp21
;
140 /* bits which should be forced to '1' */
141 lnbp21
->override_or
= override_set
;
143 /* bits which should be forced to '0' */
144 lnbp21
->override_and
= ~override_clear
;
146 /* detect if it is present or not */
147 if (lnbp21_set_voltage(fe
, SEC_VOLTAGE_OFF
)) {
152 /* install release callback */
153 fe
->ops
.release_sec
= lnbp21_release
;
155 /* override frontend ops */
156 fe
->ops
.set_voltage
= lnbp21_set_voltage
;
157 fe
->ops
.enable_high_lnb_voltage
= lnbp21_enable_high_lnb_voltage
;
158 if (!(override_clear
& LNBH24_TEN
)) /*22kHz logic controlled by demod*/
159 fe
->ops
.set_tone
= lnbp21_set_tone
;
160 printk(KERN_INFO
"LNBx2x attached on addr=%x\n", lnbp21
->i2c_addr
);
165 struct dvb_frontend
*lnbh24_attach(struct dvb_frontend
*fe
,
166 struct i2c_adapter
*i2c
, u8 override_set
,
167 u8 override_clear
, u8 i2c_addr
)
169 return lnbx2x_attach(fe
, i2c
, override_set
, override_clear
,
170 i2c_addr
, LNBH24_TTX
);
172 EXPORT_SYMBOL(lnbh24_attach
);
174 struct dvb_frontend
*lnbp21_attach(struct dvb_frontend
*fe
,
175 struct i2c_adapter
*i2c
, u8 override_set
,
178 return lnbx2x_attach(fe
, i2c
, override_set
, override_clear
,
181 EXPORT_SYMBOL(lnbp21_attach
);
183 MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp21, lnbh24");
184 MODULE_AUTHOR("Oliver Endriss, Igor M. Liplianin");
185 MODULE_LICENSE("GPL");