2 * Allegro A8293 SEC driver
4 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "dvb_frontend.h"
25 module_param(debug, int, 0644);
26 MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
28 #define LOG_PREFIX "a8293"
31 #define dbg(f, arg...) \
33 printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
35 #define err(f, arg...) printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)
37 #define info(f, arg...) printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
39 #define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
43 struct i2c_adapter *i2c;
44 const struct a8293_config *cfg;
48 static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd)
51 struct i2c_msg msg[1] = {
53 .addr = priv->cfg->i2c_addr,
60 msg[0].flags = I2C_M_RD;
64 ret = i2c_transfer(priv->i2c, msg, 1);
68 warn("i2c failed=%d rd=%d", ret, rd);
75 static int a8293_wr(struct a8293_priv *priv, u8 *val, int len)
77 return a8293_i2c(priv, val, len, 0);
80 static int a8293_rd(struct a8293_priv *priv, u8 *val, int len)
82 return a8293_i2c(priv, val, len, 1);
85 static int a8293_set_voltage(struct dvb_frontend *fe,
86 fe_sec_voltage_t fe_sec_voltage)
88 struct a8293_priv *priv = fe->sec_priv;
91 dbg("%s: fe_sec_voltage=%d", __func__, fe_sec_voltage);
93 switch (fe_sec_voltage) {
99 /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
103 /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
111 ret = a8293_wr(priv, &priv->reg[0], 1);
117 dbg("%s: failed=%d", __func__, ret);
121 static void a8293_release_sec(struct dvb_frontend *fe)
123 dbg("%s:", __func__);
125 a8293_set_voltage(fe, SEC_VOLTAGE_OFF);
131 struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
132 struct i2c_adapter *i2c, const struct a8293_config *cfg)
135 struct a8293_priv *priv = NULL;
138 /* allocate memory for the internal priv */
139 priv = kzalloc(sizeof(struct a8293_priv), GFP_KERNEL);
150 /* check if the SEC is there */
151 ret = a8293_rd(priv, buf, 2);
157 ret = a8293_wr(priv, &priv->reg[1], 1);
161 /* TMODE=0, TGATE=1 */
163 ret = a8293_wr(priv, &priv->reg[1], 1);
167 info("Allegro A8293 SEC attached.");
169 fe->ops.release_sec = a8293_release_sec;
171 /* override frontend ops */
172 fe->ops.set_voltage = a8293_set_voltage;
176 dbg("%s: failed=%d", __func__, ret);
180 EXPORT_SYMBOL(a8293_attach);
182 MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
183 MODULE_DESCRIPTION("Allegro A8293 SEC driver");
184 MODULE_LICENSE("GPL");