2 * lnbp22.h - driver for lnb supply and control ic lnbp22
4 * Copyright (C) 2006 Dominik Kuhlen
5 * Based on lnbp21 driver
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/moduleparam.h>
30 #include <linux/string.h>
31 #include <linux/slab.h>
33 #include <media/dvb_frontend.h>
37 module_param(debug
, int, 0644);
38 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
41 #define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
45 struct i2c_adapter
*i2c
;
48 static int lnbp22_set_voltage(struct dvb_frontend
*fe
,
49 enum fe_sec_voltage voltage
)
51 struct lnbp22
*lnbp22
= (struct lnbp22
*)fe
->sec_priv
;
52 struct i2c_msg msg
= {
55 .buf
= (char *)&lnbp22
->config
,
56 .len
= sizeof(lnbp22
->config
),
59 dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__
, voltage
,
60 SEC_VOLTAGE_18
, SEC_VOLTAGE_13
);
62 lnbp22
->config
[3] = 0x60; /* Power down */
67 lnbp22
->config
[3] |= LNBP22_EN
;
70 lnbp22
->config
[3] |= (LNBP22_EN
| LNBP22_VSEL
);
76 dprintk(1, "%s: 0x%02x)\n", __func__
, lnbp22
->config
[3]);
77 return (i2c_transfer(lnbp22
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
80 static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend
*fe
, long arg
)
82 struct lnbp22
*lnbp22
= (struct lnbp22
*) fe
->sec_priv
;
83 struct i2c_msg msg
= {
86 .buf
= (char *)&lnbp22
->config
,
87 .len
= sizeof(lnbp22
->config
),
90 dprintk(1, "%s: %d\n", __func__
, (int)arg
);
92 lnbp22
->config
[3] |= LNBP22_LLC
;
94 lnbp22
->config
[3] &= ~LNBP22_LLC
;
96 return (i2c_transfer(lnbp22
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
99 static void lnbp22_release(struct dvb_frontend
*fe
)
101 dprintk(1, "%s\n", __func__
);
103 lnbp22_set_voltage(fe
, SEC_VOLTAGE_OFF
);
110 struct dvb_frontend
*lnbp22_attach(struct dvb_frontend
*fe
,
111 struct i2c_adapter
*i2c
)
113 struct lnbp22
*lnbp22
= kmalloc(sizeof(struct lnbp22
), GFP_KERNEL
);
117 /* default configuration */
118 lnbp22
->config
[0] = 0x00; /* ? */
119 lnbp22
->config
[1] = 0x28; /* ? */
120 lnbp22
->config
[2] = 0x48; /* ? */
121 lnbp22
->config
[3] = 0x60; /* Power down */
123 fe
->sec_priv
= lnbp22
;
125 /* detect if it is present or not */
126 if (lnbp22_set_voltage(fe
, SEC_VOLTAGE_OFF
)) {
127 dprintk(0, "%s LNBP22 not found\n", __func__
);
133 /* install release callback */
134 fe
->ops
.release_sec
= lnbp22_release
;
136 /* override frontend ops */
137 fe
->ops
.set_voltage
= lnbp22_set_voltage
;
138 fe
->ops
.enable_high_lnb_voltage
= lnbp22_enable_high_lnb_voltage
;
142 EXPORT_SYMBOL(lnbp22_attach
);
144 MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
145 MODULE_AUTHOR("Dominik Kuhlen");
146 MODULE_LICENSE("GPL");