···11+/*22+ * Allegro A8293 SEC driver33+ *44+ * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License as published by88+ * the Free Software Foundation; either version 2 of the License, or99+ * (at your option) any later version.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414+ * GNU General Public License for more details.1515+ *1616+ * You should have received a copy of the GNU General Public License along1717+ * with this program; if not, write to the Free Software Foundation, Inc.,1818+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.1919+ */2020+2121+#include "dvb_frontend.h"2222+#include "a8293.h"2323+2424+static int debug;2525+module_param(debug, int, 0644);2626+MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");2727+2828+#define LOG_PREFIX "a8293"2929+3030+#undef dbg3131+#define dbg(f, arg...) \3232+ if (debug) \3333+ printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)3434+#undef err3535+#define err(f, arg...) printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)3636+#undef info3737+#define info(f, arg...) printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)3838+#undef warn3939+#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)4040+4141+4242+struct a8293_priv {4343+ struct i2c_adapter *i2c;4444+ const struct a8293_config *cfg;4545+ u8 reg[2];4646+};4747+4848+static int a8293_i2c(struct a8293_priv *priv, u8 *val, int len, bool rd)4949+{5050+ int ret;5151+ struct i2c_msg msg[1] = {5252+ {5353+ .addr = priv->cfg->i2c_addr,5454+ .len = len,5555+ .buf = val,5656+ }5757+ };5858+5959+ if (rd)6060+ msg[0].flags = I2C_M_RD;6161+ else6262+ msg[0].flags = 0;6363+6464+ ret = i2c_transfer(priv->i2c, msg, 1);6565+ if (ret == 1) {6666+ ret = 0;6767+ } else {6868+ warn("i2c failed=%d rd=%d", ret, rd);6969+ ret = -EREMOTEIO;7070+ }7171+7272+ return ret;7373+}7474+7575+static int a8293_wr(struct a8293_priv *priv, u8 *val, int len)7676+{7777+ return a8293_i2c(priv, val, len, 0);7878+}7979+8080+static int a8293_rd(struct a8293_priv *priv, u8 *val, int len)8181+{8282+ return a8293_i2c(priv, val, len, 1);8383+}8484+8585+static int a8293_set_voltage(struct dvb_frontend *fe,8686+ fe_sec_voltage_t fe_sec_voltage)8787+{8888+ struct a8293_priv *priv = fe->sec_priv;8989+ int ret;9090+9191+ dbg("%s: fe_sec_voltage=%d", __func__, fe_sec_voltage);9292+9393+ switch (fe_sec_voltage) {9494+ case SEC_VOLTAGE_OFF:9595+ /* ENB=0 */9696+ priv->reg[0] = 0x10;9797+ break;9898+ case SEC_VOLTAGE_13:9999+ /* VSEL0=1, VSEL1=0, VSEL2=0, VSEL3=0, ENB=1*/100100+ priv->reg[0] = 0x31;101101+ break;102102+ case SEC_VOLTAGE_18:103103+ /* VSEL0=0, VSEL1=0, VSEL2=0, VSEL3=1, ENB=1*/104104+ priv->reg[0] = 0x38;105105+ break;106106+ default:107107+ ret = -EINVAL;108108+ goto err;109109+ };110110+111111+ ret = a8293_wr(priv, &priv->reg[0], 1);112112+ if (ret)113113+ goto err;114114+115115+ return ret;116116+err:117117+ dbg("%s: failed=%d", __func__, ret);118118+ return ret;119119+}120120+121121+static void a8293_release_sec(struct dvb_frontend *fe)122122+{123123+ dbg("%s:", __func__);124124+125125+ a8293_set_voltage(fe, SEC_VOLTAGE_OFF);126126+127127+ kfree(fe->sec_priv);128128+ fe->sec_priv = NULL;129129+}130130+131131+struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,132132+ struct i2c_adapter *i2c, const struct a8293_config *cfg)133133+{134134+ int ret;135135+ struct a8293_priv *priv = NULL;136136+ u8 buf[2];137137+138138+ /* allocate memory for the internal priv */139139+ priv = kzalloc(sizeof(struct a8293_priv), GFP_KERNEL);140140+ if (priv == NULL) {141141+ ret = -ENOMEM;142142+ goto err;143143+ }144144+145145+ /* setup the priv */146146+ priv->i2c = i2c;147147+ priv->cfg = cfg;148148+ fe->sec_priv = priv;149149+150150+ /* check if the SEC is there */151151+ ret = a8293_rd(priv, buf, 2);152152+ if (ret)153153+ goto err;154154+155155+ /* ENB=0 */156156+ priv->reg[0] = 0x10;157157+ ret = a8293_wr(priv, &priv->reg[1], 1);158158+ if (ret)159159+ goto err;160160+161161+ /* TMODE=0, TGATE=1 */162162+ priv->reg[1] = 0x82;163163+ ret = a8293_wr(priv, &priv->reg[1], 1);164164+ if (ret)165165+ goto err;166166+167167+ info("Allegro A8293 SEC attached.");168168+169169+ fe->ops.release_sec = a8293_release_sec;170170+171171+ /* override frontend ops */172172+ fe->ops.set_voltage = a8293_set_voltage;173173+174174+ return fe;175175+err:176176+ dbg("%s: failed=%d", __func__, ret);177177+ kfree(priv);178178+ return NULL;179179+}180180+EXPORT_SYMBOL(a8293_attach);181181+182182+MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");183183+MODULE_DESCRIPTION("Allegro A8293 SEC driver");184184+MODULE_LICENSE("GPL");
+41
drivers/media/dvb/frontends/a8293.h
···11+/*22+ * Allegro A8293 SEC driver33+ *44+ * Copyright (C) 2011 Antti Palosaari <crope@iki.fi>55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License as published by88+ * the Free Software Foundation; either version 2 of the License, or99+ * (at your option) any later version.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414+ * GNU General Public License for more details.1515+ *1616+ * You should have received a copy of the GNU General Public License along1717+ * with this program; if not, write to the Free Software Foundation, Inc.,1818+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.1919+ */2020+2121+#ifndef A8293_H2222+#define A8293_H2323+2424+struct a8293_config {2525+ u8 i2c_addr;2626+};2727+2828+#if defined(CONFIG_DVB_A8293) || \2929+ (defined(CONFIG_DVB_A8293_MODULE) && defined(MODULE))3030+extern struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,3131+ struct i2c_adapter *i2c, const struct a8293_config *cfg);3232+#else3333+static inline struct dvb_frontend *a8293_attach(struct dvb_frontend *fe,3434+ struct i2c_adapter *i2c, const struct a8293_config *cfg)3535+{3636+ printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);3737+ return NULL;3838+}3939+#endif4040+4141+#endif /* A8293_H */