blob: 684c8ec166cbc7bfbdaed883a18c664ec59dd428 [file] [log] [blame]
Andrew de Quincey21c28582006-04-27 21:45:09 -03001/*
2 * isl6421.h - driver for lnb supply and control ic ISL6421
3 *
4 * Copyright (C) 2006 Andrew de Quincey
5 * Copyright (C) 2006 Oliver Endriss
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 *
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
23 *
24 *
25 * the project's page is at http://www.linuxtv.org
26 */
27#include <linux/delay.h>
28#include <linux/errno.h>
29#include <linux/init.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
Andrew de Quincey21c28582006-04-27 21:45:09 -030032#include <linux/string.h>
33#include <linux/slab.h>
34
35#include "dvb_frontend.h"
36#include "isl6421.h"
37
38struct isl6421 {
39 u8 config;
40 u8 override_or;
41 u8 override_and;
42 struct i2c_adapter *i2c;
43 u8 i2c_addr;
Andrew de Quincey21c28582006-04-27 21:45:09 -030044};
45
46static int isl6421_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
47{
Andrew de Quincey13fef932006-08-08 09:10:08 -030048 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
Andrew de Quincey21c28582006-04-27 21:45:09 -030049 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
50 .buf = &isl6421->config,
51 .len = sizeof(isl6421->config) };
52
53 isl6421->config &= ~(ISL6421_VSEL1 | ISL6421_EN1);
54
55 switch(voltage) {
56 case SEC_VOLTAGE_OFF:
57 break;
58 case SEC_VOLTAGE_13:
59 isl6421->config |= ISL6421_EN1;
60 break;
61 case SEC_VOLTAGE_18:
62 isl6421->config |= (ISL6421_EN1 | ISL6421_VSEL1);
63 break;
64 default:
65 return -EINVAL;
66 };
67
68 isl6421->config |= isl6421->override_or;
69 isl6421->config &= isl6421->override_and;
70
71 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
72}
73
74static int isl6421_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
75{
Andrew de Quincey13fef932006-08-08 09:10:08 -030076 struct isl6421 *isl6421 = (struct isl6421 *) fe->sec_priv;
Andrew de Quincey21c28582006-04-27 21:45:09 -030077 struct i2c_msg msg = { .addr = isl6421->i2c_addr, .flags = 0,
78 .buf = &isl6421->config,
79 .len = sizeof(isl6421->config) };
80
81 if (arg)
82 isl6421->config |= ISL6421_LLC1;
83 else
84 isl6421->config &= ~ISL6421_LLC1;
85
86 isl6421->config |= isl6421->override_or;
87 isl6421->config &= isl6421->override_and;
88
89 return (i2c_transfer(isl6421->i2c, &msg, 1) == 1) ? 0 : -EIO;
90}
91
92static void isl6421_release(struct dvb_frontend *fe)
93{
Andrew de Quincey21c28582006-04-27 21:45:09 -030094 /* power off */
95 isl6421_set_voltage(fe, SEC_VOLTAGE_OFF);
96
Andrew de Quincey13fef932006-08-08 09:10:08 -030097 /* free */
98 kfree(fe->sec_priv);
99 fe->sec_priv = NULL;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300100}
101
Andrew de Quincey13fef932006-08-08 09:10:08 -0300102struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
Andrew de Quincey21c28582006-04-27 21:45:09 -0300103 u8 override_set, u8 override_clear)
104{
105 struct isl6421 *isl6421 = kmalloc(sizeof(struct isl6421), GFP_KERNEL);
106 if (!isl6421)
Andrew de Quincey13fef932006-08-08 09:10:08 -0300107 return NULL;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300108
109 /* default configuration */
110 isl6421->config = ISL6421_ISEL1;
111 isl6421->i2c = i2c;
112 isl6421->i2c_addr = i2c_addr;
Andrew de Quincey13fef932006-08-08 09:10:08 -0300113 fe->sec_priv = isl6421;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300114
115 /* bits which should be forced to '1' */
116 isl6421->override_or = override_set;
117
118 /* bits which should be forced to '0' */
119 isl6421->override_and = ~override_clear;
120
121 /* detect if it is present or not */
122 if (isl6421_set_voltage(fe, SEC_VOLTAGE_OFF)) {
123 kfree(isl6421);
Thomas Viehweger09d48952007-03-22 11:20:32 -0300124 fe->sec_priv = NULL;
Andrew de Quincey13fef932006-08-08 09:10:08 -0300125 return NULL;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300126 }
127
128 /* install release callback */
Trent Piepho62a7b3e2006-08-24 22:43:16 -0300129 fe->ops.release_sec = isl6421_release;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300130
131 /* override frontend ops */
Patrick Boettcherdea74862006-05-14 05:01:31 -0300132 fe->ops.set_voltage = isl6421_set_voltage;
133 fe->ops.enable_high_lnb_voltage = isl6421_enable_high_lnb_voltage;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300134
Andrew de Quincey13fef932006-08-08 09:10:08 -0300135 return fe;
Andrew de Quincey21c28582006-04-27 21:45:09 -0300136}
137EXPORT_SYMBOL(isl6421_attach);
138
139MODULE_DESCRIPTION("Driver for lnb supply and control ic isl6421");
140MODULE_AUTHOR("Andrew de Quincey & Oliver Endriss");
141MODULE_LICENSE("GPL");