1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * lnbp22.h - driver for lnb supply and control ic lnbp22
5 * Copyright (C) 2006 Dominik Kuhlen
6 * Based on lnbp21 driver
8 * the project's page is at https://linuxtv.org
10 #include <linux/delay.h>
11 #include <linux/errno.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/slab.h>
19 #include <media/dvb_frontend.h>
23 module_param(debug
, int, 0644);
24 MODULE_PARM_DESC(debug
, "Turn on/off debugging (default:off).");
27 #define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
31 struct i2c_adapter
*i2c
;
34 static int lnbp22_set_voltage(struct dvb_frontend
*fe
,
35 enum fe_sec_voltage voltage
)
37 struct lnbp22
*lnbp22
= (struct lnbp22
*)fe
->sec_priv
;
38 struct i2c_msg msg
= {
41 .buf
= (char *)&lnbp22
->config
,
42 .len
= sizeof(lnbp22
->config
),
45 dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__
, voltage
,
46 SEC_VOLTAGE_18
, SEC_VOLTAGE_13
);
48 lnbp22
->config
[3] = 0x60; /* Power down */
53 lnbp22
->config
[3] |= LNBP22_EN
;
56 lnbp22
->config
[3] |= (LNBP22_EN
| LNBP22_VSEL
);
62 dprintk(1, "%s: 0x%02x)\n", __func__
, lnbp22
->config
[3]);
63 return (i2c_transfer(lnbp22
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
66 static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend
*fe
, long arg
)
68 struct lnbp22
*lnbp22
= (struct lnbp22
*) fe
->sec_priv
;
69 struct i2c_msg msg
= {
72 .buf
= (char *)&lnbp22
->config
,
73 .len
= sizeof(lnbp22
->config
),
76 dprintk(1, "%s: %d\n", __func__
, (int)arg
);
78 lnbp22
->config
[3] |= LNBP22_LLC
;
80 lnbp22
->config
[3] &= ~LNBP22_LLC
;
82 return (i2c_transfer(lnbp22
->i2c
, &msg
, 1) == 1) ? 0 : -EIO
;
85 static void lnbp22_release(struct dvb_frontend
*fe
)
87 dprintk(1, "%s\n", __func__
);
89 lnbp22_set_voltage(fe
, SEC_VOLTAGE_OFF
);
96 struct dvb_frontend
*lnbp22_attach(struct dvb_frontend
*fe
,
97 struct i2c_adapter
*i2c
)
99 struct lnbp22
*lnbp22
= kmalloc(sizeof(struct lnbp22
), GFP_KERNEL
);
103 /* default configuration */
104 lnbp22
->config
[0] = 0x00; /* ? */
105 lnbp22
->config
[1] = 0x28; /* ? */
106 lnbp22
->config
[2] = 0x48; /* ? */
107 lnbp22
->config
[3] = 0x60; /* Power down */
109 fe
->sec_priv
= lnbp22
;
111 /* detect if it is present or not */
112 if (lnbp22_set_voltage(fe
, SEC_VOLTAGE_OFF
)) {
113 dprintk(0, "%s LNBP22 not found\n", __func__
);
119 /* install release callback */
120 fe
->ops
.release_sec
= lnbp22_release
;
122 /* override frontend ops */
123 fe
->ops
.set_voltage
= lnbp22_set_voltage
;
124 fe
->ops
.enable_high_lnb_voltage
= lnbp22_enable_high_lnb_voltage
;
128 EXPORT_SYMBOL(lnbp22_attach
);
130 MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
131 MODULE_AUTHOR("Dominik Kuhlen");
132 MODULE_LICENSE("GPL");