4 * Driver for LNB supply and control IC LNBH25
6 * Copyright (C) 2014 NetUP Inc.
7 * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
8 * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/string.h>
24 #include <linux/slab.h>
26 #include "dvb_frontend.h"
30 * struct lnbh25_priv - LNBH25 driver private data
31 * @i2c: pointer to the I2C adapter structure
32 * @i2c_address: I2C address of LNBH25 SEC chip
33 * @config: Registers configuration:
34 * offset 0: 1st register address, always 0x02 (DATA1)
35 * offset 1: DATA1 register value
36 * offset 2: DATA2 register value
39 struct i2c_adapter
*i2c
;
44 #define LNBH25_STATUS_OFL 0x1
45 #define LNBH25_STATUS_VMON 0x4
46 #define LNBH25_VSEL_13 0x03
47 #define LNBH25_VSEL_18 0x0a
49 static int lnbh25_read_vmon(struct lnbh25_priv
*priv
)
54 struct i2c_msg msg
[2] = {
56 .addr
= priv
->i2c_address
,
61 .addr
= priv
->i2c_address
,
63 .len
= sizeof(status
),
68 for (i
= 0; i
< 2; i
++) {
69 ret
= i2c_transfer(priv
->i2c
, &msg
[i
], 1);
70 if (ret
>= 0 && ret
!= 1)
73 dev_dbg(&priv
->i2c
->dev
,
74 "%s(): I2C transfer %d failed (%d)\n",
79 print_hex_dump_bytes("lnbh25_read_vmon: ",
80 DUMP_PREFIX_OFFSET
, status
, sizeof(status
));
81 if ((status
[0] & (LNBH25_STATUS_OFL
| LNBH25_STATUS_VMON
)) != 0) {
82 dev_err(&priv
->i2c
->dev
,
83 "%s(): voltage in failure state, status reg 0x%x\n",
90 static int lnbh25_set_voltage(struct dvb_frontend
*fe
,
91 enum fe_sec_voltage voltage
)
96 struct lnbh25_priv
*priv
= fe
->sec_priv
;
97 struct i2c_msg msg
= {
98 .addr
= priv
->i2c_address
,
100 .len
= sizeof(priv
->config
),
105 case SEC_VOLTAGE_OFF
:
110 data1_reg
= LNBH25_VSEL_13
;
114 data1_reg
= LNBH25_VSEL_18
;
120 priv
->config
[1] = data1_reg
;
121 dev_dbg(&priv
->i2c
->dev
,
122 "%s(): %s, I2C 0x%x write [ %02x %02x %02x ]\n",
123 __func__
, vsel
, priv
->i2c_address
,
124 priv
->config
[0], priv
->config
[1], priv
->config
[2]);
125 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
126 if (ret
>= 0 && ret
!= 1)
129 dev_err(&priv
->i2c
->dev
, "%s(): I2C transfer error (%d)\n",
133 if (voltage
!= SEC_VOLTAGE_OFF
) {
135 ret
= lnbh25_read_vmon(priv
);
143 static void lnbh25_release(struct dvb_frontend
*fe
)
145 struct lnbh25_priv
*priv
= fe
->sec_priv
;
147 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
148 lnbh25_set_voltage(fe
, SEC_VOLTAGE_OFF
);
153 struct dvb_frontend
*lnbh25_attach(struct dvb_frontend
*fe
,
154 struct lnbh25_config
*cfg
,
155 struct i2c_adapter
*i2c
)
157 struct lnbh25_priv
*priv
;
159 dev_dbg(&i2c
->dev
, "%s()\n", __func__
);
160 priv
= kzalloc(sizeof(struct lnbh25_priv
), GFP_KERNEL
);
163 priv
->i2c_address
= (cfg
->i2c_address
>> 1);
165 priv
->config
[0] = 0x02;
166 priv
->config
[1] = 0x00;
167 priv
->config
[2] = cfg
->data2_config
;
169 if (lnbh25_set_voltage(fe
, SEC_VOLTAGE_OFF
)) {
171 "%s(): no LNBH25 found at I2C addr 0x%02x\n",
172 __func__
, priv
->i2c_address
);
178 fe
->ops
.release_sec
= lnbh25_release
;
179 fe
->ops
.set_voltage
= lnbh25_set_voltage
;
181 dev_err(&i2c
->dev
, "%s(): attached at I2C addr 0x%02x\n",
182 __func__
, priv
->i2c_address
);
185 EXPORT_SYMBOL(lnbh25_attach
);
187 MODULE_DESCRIPTION("ST LNBH25 driver");
188 MODULE_AUTHOR("info@netup.ru");
189 MODULE_LICENSE("GPL");