aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAntti Palosaari <crope@iki.fi>2011-07-31 23:52:11 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-09-21 08:59:06 -0400
commit85bc9b510aae310ac5530ae364b1145b5cc0ce68 (patch)
tree1ac845069474ca4cfacc7d086d26b2c1585cfb13 /drivers
parent88365105d683187e02a4f75220eaf51fd0c0b6e0 (diff)
[media] a8293: Allegro A8293 SEC driver
Signed-off-by: Antti Palosaari <crope@iki.fi> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/dvb/frontends/Kconfig5
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/a8293.c184
-rw-r--r--drivers/media/dvb/frontends/a8293.h41
4 files changed, 231 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 17082df7da39..8e1a18337246 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -621,6 +621,11 @@ config DVB_ISL6423
621 help 621 help
622 A SEC controller chip from Intersil 622 A SEC controller chip from Intersil
623 623
624config DVB_A8293
625 tristate "Allegro A8293"
626 depends on DVB_CORE && I2C
627 default m if DVB_FE_CUSTOMISE
628
624config DVB_LGS8GL5 629config DVB_LGS8GL5
625 tristate "Silicon Legend LGS-8GL5 demodulator (OFDM)" 630 tristate "Silicon Legend LGS-8GL5 demodulator (OFDM)"
626 depends on DVB_CORE && I2C 631 depends on DVB_CORE && I2C
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 18d045d78bdb..08040cf1fd69 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -92,4 +92,5 @@ obj-$(CONFIG_DVB_CXD2820R) += cxd2820r.o
92obj-$(CONFIG_DVB_DRXK) += drxk.o 92obj-$(CONFIG_DVB_DRXK) += drxk.o
93obj-$(CONFIG_DVB_TDA18271C2DD) += tda18271c2dd.o 93obj-$(CONFIG_DVB_TDA18271C2DD) += tda18271c2dd.o
94obj-$(CONFIG_DVB_IT913X_FE) += it913x-fe.o 94obj-$(CONFIG_DVB_IT913X_FE) += it913x-fe.o
95obj-$(CONFIG_DVB_A8293) += a8293.o
95 96
diff --git a/drivers/media/dvb/frontends/a8293.c b/drivers/media/dvb/frontends/a8293.c
new file mode 100644
index 000000000000..bb56497e940a
--- /dev/null
+++ b/drivers/media/dvb/frontends/a8293.c
@@ -0,0 +1,184 @@
1/*
2 * Allegro A8293 SEC driver
3 *
4 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21#include "dvb_frontend.h"
22#include "a8293.h"
23
24static int debug;
25module_param(debug, int, 0644);
26MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
27
28#define LOG_PREFIX "a8293"
29
30#undef dbg
31#define dbg(f, arg...) \
32 if (debug) \
33 printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
34#undef err
35#define err(f, arg...) printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)
36#undef info
37#define info(f, arg...) printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
38#undef warn
39#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
40
41
42struct a8293_priv {
43 struct i2c_adapter *i2c;
44 const struct a8293_config *cfg;
45 u8 reg[2];
46};
47
48static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd)
49{
50 int ret;
51 struct i2c_msg msg[1] = {
52 {
53 .addr = priv->cfg->i2c_addr,
54 .len = len,
55 .buf = val,
56 }
57 };
58
59 if (rd)
60 msg[0].flags = I2C_M_RD;
61 else
62 msg[0].flags = 0;
63
64 ret = i2c_transfer(priv->i2c, msg, 1);
65 if (ret == 1) {
66 ret = 0;
67 } else {
68 warn("i2c failed=%d rd=%d", ret, rd);
69 ret = -EREMOTEIO;
70 }
71
72 return ret;
73}
74
75static int a8293_wr(struct a8293_priv *priv, u8 *val, int len)
76{
77 return a8293_i2c(priv, val, len, 0);
78}
79
80static int a8293_rd(struct a8293_priv *priv, u8 *val, int len)
81{
82 return a8293_i2c(priv, val, len, 1);
83}
84
85static int a8293_set_voltage(struct dvb_frontend *fe,
86 fe_sec_voltage_t fe_sec_voltage)
87{
88 struct a8293_priv *priv = fe->sec_priv;
89 int ret;
90
91 dbg("%s: fe_sec_voltage=%d", __func__, fe_sec_voltage);
92
93 switch (fe_sec_voltage) {
94 case SEC_VOLTAGE_OFF:
95 /* ENB=0 */
96 priv->reg[0] = 0x10;
97 break;
98 case SEC_VOLTAGE_13:
99 /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/
100 priv->reg[0] = 0x31;
101 break;
102 case SEC_VOLTAGE_18:
103 /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/
104 priv->reg[0] = 0x38;
105 break;
106 default:
107 ret = -EINVAL;
108 goto err;
109 };
110
111 ret = a8293_wr(priv, &priv->reg[0], 1);
112 if (ret)
113 goto err;
114
115 return ret;
116err:
117 dbg("%s: failed=%d", __func__, ret);
118 return ret;
119}
120
121static void a8293_release_sec(struct dvb_frontend *fe)
122{
123 dbg("%s:", __func__);
124
125 a8293_set_voltage(fe, SEC_VOLTAGE_OFF);
126
127 kfree(fe->sec_priv);
128 fe->sec_priv = NULL;
129}
130
131struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
132 struct i2c_adapter *i2c, const struct a8293_config *cfg)
133{
134 int ret;
135 struct a8293_priv *priv = NULL;
136 u8 buf[2];
137
138 /* allocate memory for the internal priv */
139 priv = kzalloc(sizeof(struct a8293_priv), GFP_KERNEL);
140 if (priv == NULL) {
141 ret = -ENOMEM;
142 goto err;
143 }
144
145 /* setup the priv */
146 priv->i2c = i2c;
147 priv->cfg = cfg;
148 fe->sec_priv = priv;
149
150 /* check if the SEC is there */
151 ret = a8293_rd(priv, buf, 2);
152 if (ret)
153 goto err;
154
155 /* ENB=0 */
156 priv->reg[0] = 0x10;
157 ret = a8293_wr(priv, &priv->reg[1], 1);
158 if (ret)
159 goto err;
160
161 /* TMODE=0, TGATE=1 */
162 priv->reg[1] = 0x82;
163 ret = a8293_wr(priv, &priv->reg[1], 1);
164 if (ret)
165 goto err;
166
167 info("Allegro A8293 SEC attached.");
168
169 fe->ops.release_sec = a8293_release_sec;
170
171 /* override frontend ops */
172 fe->ops.set_voltage = a8293_set_voltage;
173
174 return fe;
175err:
176 dbg("%s: failed=%d", __func__, ret);
177 kfree(priv);
178 return NULL;
179}
180EXPORT_SYMBOL(a8293_attach);
181
182MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
183MODULE_DESCRIPTION("Allegro A8293 SEC driver");
184MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/a8293.h b/drivers/media/dvb/frontends/a8293.h
new file mode 100644
index 000000000000..ed29e5504f76
--- /dev/null
+++ b/drivers/media/dvb/frontends/a8293.h
@@ -0,0 +1,41 @@
1/*
2 * Allegro A8293 SEC driver
3 *
4 * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21#ifndef A8293_H
22#define A8293_H
23
24struct a8293_config {
25 u8 i2c_addr;
26};
27
28#if defined(CONFIG_DVB_A8293) || \
29 (defined(CONFIG_DVB_A8293_MODULE) && defined(MODULE))
30extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
31 struct i2c_adapter *i2c, const struct a8293_config *cfg);
32#else
33static inline struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,
34 struct i2c_adapter *i2c, const struct a8293_config *cfg)
35{
36 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
37 return NULL;
38}
39#endif
40
41#endif /* A8293_H */