1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Intersil ISL6423 SEC and LNB Power supply controller
5 Copyright (C) Manu Abraham <abraham.manu@gmail.com>
9 #include <linux/delay.h>
10 #include <linux/errno.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/slab.h>
17 #include <media/dvb_frontend.h>
20 static unsigned int verbose
;
21 module_param(verbose
, int, 0644);
22 MODULE_PARM_DESC(verbose
, "Set Verbosity level");
30 #define dprintk(__y, __z, format, arg...) do { \
32 if ((verbose > FE_ERROR) && (verbose > __y)) \
33 printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
34 else if ((verbose > FE_NOTICE) && (verbose > __y)) \
35 printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
36 else if ((verbose > FE_INFO) && (verbose > __y)) \
37 printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
38 else if ((verbose > FE_DEBUG) && (verbose > __y)) \
39 printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
42 printk(format, ##arg); \
47 const struct isl6423_config
*config
;
48 struct i2c_adapter
*i2c
;
56 static int isl6423_write(struct isl6423_dev
*isl6423
, u8 reg
)
58 struct i2c_adapter
*i2c
= isl6423
->i2c
;
59 u8 addr
= isl6423
->config
->addr
;
62 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= ®
, .len
= 1 };
64 dprintk(FE_DEBUG
, 1, "write reg %02X", reg
);
65 err
= i2c_transfer(i2c
, &msg
, 1);
71 dprintk(FE_ERROR
, 1, "I/O error <%d>", err
);
75 static int isl6423_set_modulation(struct dvb_frontend
*fe
)
77 struct isl6423_dev
*isl6423
= (struct isl6423_dev
*) fe
->sec_priv
;
78 const struct isl6423_config
*config
= isl6423
->config
;
84 if (config
->mod_extern
)
89 err
= isl6423_write(isl6423
, reg_2
);
95 dprintk(FE_ERROR
, 1, "I/O error <%d>", err
);
99 static int isl6423_voltage_boost(struct dvb_frontend
*fe
, long arg
)
101 struct isl6423_dev
*isl6423
= (struct isl6423_dev
*) fe
->sec_priv
;
102 u8 reg_3
= isl6423
->reg_3
;
103 u8 reg_4
= isl6423
->reg_4
;
107 /* EN = 1, VSPEN = 1, VBOT = 1 */
112 /* EN = 1, VSPEN = 1, VBOT = 0 */
117 err
= isl6423_write(isl6423
, reg_3
);
121 err
= isl6423_write(isl6423
, reg_4
);
125 isl6423
->reg_3
= reg_3
;
126 isl6423
->reg_4
= reg_4
;
130 dprintk(FE_ERROR
, 1, "I/O error <%d>", err
);
135 static int isl6423_set_voltage(struct dvb_frontend
*fe
,
136 enum fe_sec_voltage voltage
)
138 struct isl6423_dev
*isl6423
= (struct isl6423_dev
*) fe
->sec_priv
;
139 u8 reg_3
= isl6423
->reg_3
;
140 u8 reg_4
= isl6423
->reg_4
;
144 case SEC_VOLTAGE_OFF
:
150 /* EN = 1, VSPEN = 1, VTOP = 0, VBOT = 0 */
157 /* EN = 1, VSPEN = 1, VTOP = 1, VBOT = 0 */
167 err
= isl6423_write(isl6423
, reg_3
);
171 err
= isl6423_write(isl6423
, reg_4
);
175 isl6423
->reg_3
= reg_3
;
176 isl6423
->reg_4
= reg_4
;
180 dprintk(FE_ERROR
, 1, "I/O error <%d>", err
);
184 static int isl6423_set_current(struct dvb_frontend
*fe
)
186 struct isl6423_dev
*isl6423
= (struct isl6423_dev
*) fe
->sec_priv
;
187 u8 reg_3
= isl6423
->reg_3
;
188 const struct isl6423_config
*config
= isl6423
->config
;
191 switch (config
->current_max
) {
192 case SEC_CURRENT_275m
:
194 /* ISELH = 0, ISELL = 0 */
198 case SEC_CURRENT_515m
:
200 /* ISELH = 0, ISELL = 1 */
205 case SEC_CURRENT_635m
:
207 /* ISELH = 1, ISELL = 0 */
212 case SEC_CURRENT_800m
:
214 /* ISELH = 1, ISELL = 1 */
219 err
= isl6423_write(isl6423
, reg_3
);
223 switch (config
->curlim
) {
224 case SEC_CURRENT_LIM_ON
:
229 case SEC_CURRENT_LIM_OFF
:
235 err
= isl6423_write(isl6423
, reg_3
);
239 isl6423
->reg_3
= reg_3
;
243 dprintk(FE_ERROR
, 1, "I/O error <%d>", err
);
247 static void isl6423_release(struct dvb_frontend
*fe
)
249 isl6423_set_voltage(fe
, SEC_VOLTAGE_OFF
);
255 struct dvb_frontend
*isl6423_attach(struct dvb_frontend
*fe
,
256 struct i2c_adapter
*i2c
,
257 const struct isl6423_config
*config
)
259 struct isl6423_dev
*isl6423
;
261 isl6423
= kzalloc(sizeof(struct isl6423_dev
), GFP_KERNEL
);
265 isl6423
->config
= config
;
267 fe
->sec_priv
= isl6423
;
269 /* SR3H = 0, SR3M = 1, SR3L = 0 */
270 isl6423
->reg_3
= 0x02 << 5;
271 /* SR4H = 0, SR4M = 1, SR4L = 1 */
272 isl6423
->reg_4
= 0x03 << 5;
274 if (isl6423_set_current(fe
))
277 if (isl6423_set_modulation(fe
))
280 fe
->ops
.release_sec
= isl6423_release
;
281 fe
->ops
.set_voltage
= isl6423_set_voltage
;
282 fe
->ops
.enable_high_lnb_voltage
= isl6423_voltage_boost
;
283 isl6423
->verbose
= verbose
;
292 EXPORT_SYMBOL(isl6423_attach
);
294 MODULE_DESCRIPTION("ISL6423 SEC");
295 MODULE_AUTHOR("Manu Abraham");
296 MODULE_LICENSE("GPL");