0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/delay.h>
0011 #include <linux/errno.h>
0012 #include <linux/init.h>
0013 #include <linux/kernel.h>
0014 #include <linux/module.h>
0015 #include <linux/moduleparam.h>
0016 #include <linux/string.h>
0017 #include <linux/slab.h>
0018
0019 #include <media/dvb_frontend.h>
0020 #include "lnbp22.h"
0021
0022 static int debug;
0023 module_param(debug, int, 0644);
0024 MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
0025
0026
0027 #define dprintk(lvl, arg...) if (debug >= (lvl)) printk(arg)
0028
0029 struct lnbp22 {
0030 u8 config[4];
0031 struct i2c_adapter *i2c;
0032 };
0033
0034 static int lnbp22_set_voltage(struct dvb_frontend *fe,
0035 enum fe_sec_voltage voltage)
0036 {
0037 struct lnbp22 *lnbp22 = (struct lnbp22 *)fe->sec_priv;
0038 struct i2c_msg msg = {
0039 .addr = 0x08,
0040 .flags = 0,
0041 .buf = (char *)&lnbp22->config,
0042 .len = sizeof(lnbp22->config),
0043 };
0044
0045 dprintk(1, "%s: %d (18V=%d 13V=%d)\n", __func__, voltage,
0046 SEC_VOLTAGE_18, SEC_VOLTAGE_13);
0047
0048 lnbp22->config[3] = 0x60;
0049 switch (voltage) {
0050 case SEC_VOLTAGE_OFF:
0051 break;
0052 case SEC_VOLTAGE_13:
0053 lnbp22->config[3] |= LNBP22_EN;
0054 break;
0055 case SEC_VOLTAGE_18:
0056 lnbp22->config[3] |= (LNBP22_EN | LNBP22_VSEL);
0057 break;
0058 default:
0059 return -EINVAL;
0060 }
0061
0062 dprintk(1, "%s: 0x%02x)\n", __func__, lnbp22->config[3]);
0063 return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
0064 }
0065
0066 static int lnbp22_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
0067 {
0068 struct lnbp22 *lnbp22 = (struct lnbp22 *) fe->sec_priv;
0069 struct i2c_msg msg = {
0070 .addr = 0x08,
0071 .flags = 0,
0072 .buf = (char *)&lnbp22->config,
0073 .len = sizeof(lnbp22->config),
0074 };
0075
0076 dprintk(1, "%s: %d\n", __func__, (int)arg);
0077 if (arg)
0078 lnbp22->config[3] |= LNBP22_LLC;
0079 else
0080 lnbp22->config[3] &= ~LNBP22_LLC;
0081
0082 return (i2c_transfer(lnbp22->i2c, &msg, 1) == 1) ? 0 : -EIO;
0083 }
0084
0085 static void lnbp22_release(struct dvb_frontend *fe)
0086 {
0087 dprintk(1, "%s\n", __func__);
0088
0089 lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF);
0090
0091
0092 kfree(fe->sec_priv);
0093 fe->sec_priv = NULL;
0094 }
0095
0096 struct dvb_frontend *lnbp22_attach(struct dvb_frontend *fe,
0097 struct i2c_adapter *i2c)
0098 {
0099 struct lnbp22 *lnbp22 = kmalloc(sizeof(struct lnbp22), GFP_KERNEL);
0100 if (!lnbp22)
0101 return NULL;
0102
0103
0104 lnbp22->config[0] = 0x00;
0105 lnbp22->config[1] = 0x28;
0106 lnbp22->config[2] = 0x48;
0107 lnbp22->config[3] = 0x60;
0108 lnbp22->i2c = i2c;
0109 fe->sec_priv = lnbp22;
0110
0111
0112 if (lnbp22_set_voltage(fe, SEC_VOLTAGE_OFF)) {
0113 dprintk(0, "%s LNBP22 not found\n", __func__);
0114 kfree(lnbp22);
0115 fe->sec_priv = NULL;
0116 return NULL;
0117 }
0118
0119
0120 fe->ops.release_sec = lnbp22_release;
0121
0122
0123 fe->ops.set_voltage = lnbp22_set_voltage;
0124 fe->ops.enable_high_lnb_voltage = lnbp22_enable_high_lnb_voltage;
0125
0126 return fe;
0127 }
0128 EXPORT_SYMBOL(lnbp22_attach);
0129
0130 MODULE_DESCRIPTION("Driver for lnb supply and control ic lnbp22");
0131 MODULE_AUTHOR("Dominik Kuhlen");
0132 MODULE_LICENSE("GPL");