]>
Commit | Line | Data |
---|---|---|
d020542f | 1 | /* |
8c1a2331 | 2 | * lnbp21.c - driver for lnb supply and control ic lnbp21 |
d020542f | 3 | * |
9efc1bdd | 4 | * Copyright (C) 2006, 2009 Oliver Endriss <o.endriss@gmx.de> |
8c1a2331 | 5 | * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru> |
d020542f AQ |
6 | * |
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. | |
11 | * | |
12 | * | |
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. | |
17 | * | |
bcb63314 SA |
18 | * To obtain the license, point your browser to |
19 | * http://www.gnu.org/copyleft/gpl.html | |
d020542f AQ |
20 | * |
21 | * | |
991ce92f | 22 | * the project's page is at https://linuxtv.org |
d020542f AQ |
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> | |
d020542f AQ |
29 | #include <linux/string.h> |
30 | #include <linux/slab.h> | |
31 | ||
32 | #include "dvb_frontend.h" | |
33 | #include "lnbp21.h" | |
8c1a2331 | 34 | #include "lnbh24.h" |
d020542f AQ |
35 | |
36 | struct lnbp21 { | |
37 | u8 config; | |
38 | u8 override_or; | |
39 | u8 override_and; | |
40 | struct i2c_adapter *i2c; | |
8c1a2331 | 41 | u8 i2c_addr; |
d020542f AQ |
42 | }; |
43 | ||
8c1a2331 | 44 | static int lnbp21_set_voltage(struct dvb_frontend *fe, |
0df289a2 | 45 | enum fe_sec_voltage voltage) |
d020542f | 46 | { |
13fef933 | 47 | struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv; |
8c1a2331 | 48 | struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0, |
d020542f AQ |
49 | .buf = &lnbp21->config, |
50 | .len = sizeof(lnbp21->config) }; | |
51 | ||
52 | lnbp21->config &= ~(LNBP21_VSEL | LNBP21_EN); | |
53 | ||
54 | switch(voltage) { | |
55 | case SEC_VOLTAGE_OFF: | |
56 | break; | |
57 | case SEC_VOLTAGE_13: | |
58 | lnbp21->config |= LNBP21_EN; | |
59 | break; | |
60 | case SEC_VOLTAGE_18: | |
61 | lnbp21->config |= (LNBP21_EN | LNBP21_VSEL); | |
62 | break; | |
63 | default: | |
64 | return -EINVAL; | |
c2c1b415 | 65 | } |
d020542f AQ |
66 | |
67 | lnbp21->config |= lnbp21->override_or; | |
68 | lnbp21->config &= lnbp21->override_and; | |
69 | ||
70 | return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO; | |
71 | } | |
72 | ||
73 | static int lnbp21_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg) | |
74 | { | |
13fef933 | 75 | struct lnbp21 *lnbp21 = (struct lnbp21 *) fe->sec_priv; |
8c1a2331 | 76 | struct i2c_msg msg = { .addr = lnbp21->i2c_addr, .flags = 0, |
d020542f AQ |
77 | .buf = &lnbp21->config, |
78 | .len = sizeof(lnbp21->config) }; | |
79 | ||
80 | if (arg) | |
81 | lnbp21->config |= LNBP21_LLC; | |
82 | else | |
83 | lnbp21->config &= ~LNBP21_LLC; | |
84 | ||
85 | lnbp21->config |= lnbp21->override_or; | |
86 | lnbp21->config &= lnbp21->override_and; | |
87 | ||
88 | return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO; | |
89 | } | |
90 | ||
9efc1bdd | 91 | static int lnbp21_set_tone(struct dvb_frontend *fe, |
0df289a2 | 92 | enum fe_sec_tone_mode tone) |
9efc1bdd OE |
93 | { |
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) }; | |
98 | ||
99 | switch (tone) { | |
100 | case SEC_TONE_OFF: | |
101 | lnbp21->config &= ~LNBP21_TEN; | |
102 | break; | |
103 | case SEC_TONE_ON: | |
104 | lnbp21->config |= LNBP21_TEN; | |
105 | break; | |
106 | default: | |
107 | return -EINVAL; | |
c2c1b415 | 108 | } |
9efc1bdd OE |
109 | |
110 | lnbp21->config |= lnbp21->override_or; | |
111 | lnbp21->config &= lnbp21->override_and; | |
112 | ||
113 | return (i2c_transfer(lnbp21->i2c, &msg, 1) == 1) ? 0 : -EIO; | |
114 | } | |
115 | ||
d020542f AQ |
116 | static void lnbp21_release(struct dvb_frontend *fe) |
117 | { | |
d020542f AQ |
118 | /* LNBP power off */ |
119 | lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF); | |
120 | ||
13fef933 AQ |
121 | /* free data */ |
122 | kfree(fe->sec_priv); | |
123 | fe->sec_priv = NULL; | |
d020542f AQ |
124 | } |
125 | ||
8c1a2331 IL |
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) | |
d020542f AQ |
129 | { |
130 | struct lnbp21 *lnbp21 = kmalloc(sizeof(struct lnbp21), GFP_KERNEL); | |
131 | if (!lnbp21) | |
13fef933 | 132 | return NULL; |
d020542f AQ |
133 | |
134 | /* default configuration */ | |
8c1a2331 | 135 | lnbp21->config = config; |
d020542f | 136 | lnbp21->i2c = i2c; |
8c1a2331 | 137 | lnbp21->i2c_addr = i2c_addr; |
13fef933 | 138 | fe->sec_priv = lnbp21; |
d020542f AQ |
139 | |
140 | /* bits which should be forced to '1' */ | |
141 | lnbp21->override_or = override_set; | |
142 | ||
143 | /* bits which should be forced to '0' */ | |
144 | lnbp21->override_and = ~override_clear; | |
145 | ||
146 | /* detect if it is present or not */ | |
147 | if (lnbp21_set_voltage(fe, SEC_VOLTAGE_OFF)) { | |
148 | kfree(lnbp21); | |
13fef933 | 149 | return NULL; |
d020542f AQ |
150 | } |
151 | ||
152 | /* install release callback */ | |
b5b168d7 | 153 | fe->ops.release_sec = lnbp21_release; |
d020542f AQ |
154 | |
155 | /* override frontend ops */ | |
dea74869 PB |
156 | fe->ops.set_voltage = lnbp21_set_voltage; |
157 | fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; | |
0726681a | 158 | if (!(override_clear & LNBH24_TEN)) /*22kHz logic controlled by demod*/ |
ceb59cf0 | 159 | fe->ops.set_tone = lnbp21_set_tone; |
3cd5270c | 160 | printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr); |
d020542f | 161 | |
13fef933 | 162 | return fe; |
d020542f | 163 | } |
8c1a2331 | 164 | |
55d5834d | 165 | struct dvb_frontend *lnbh24_attach(struct dvb_frontend *fe, |
8c1a2331 IL |
166 | struct i2c_adapter *i2c, u8 override_set, |
167 | u8 override_clear, u8 i2c_addr) | |
168 | { | |
169 | return lnbx2x_attach(fe, i2c, override_set, override_clear, | |
170 | i2c_addr, LNBH24_TTX); | |
171 | } | |
172 | EXPORT_SYMBOL(lnbh24_attach); | |
173 | ||
174 | struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, | |
175 | struct i2c_adapter *i2c, u8 override_set, | |
176 | u8 override_clear) | |
177 | { | |
178 | return lnbx2x_attach(fe, i2c, override_set, override_clear, | |
179 | 0x08, LNBP21_ISEL); | |
180 | } | |
d020542f AQ |
181 | EXPORT_SYMBOL(lnbp21_attach); |
182 | ||
8c1a2331 IL |
183 | MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp21, lnbh24"); |
184 | MODULE_AUTHOR("Oliver Endriss, Igor M. Liplianin"); | |
d020542f | 185 | MODULE_LICENSE("GPL"); |