1 // SPDX-License-Identifier: GPL-2.0-or-later
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
9 #include <linux/signal.h>
10 #include <linux/sched.h>
11 #include <linux/interrupt.h>
13 #include <media/dmxdev.h>
14 #include <media/dvbdev.h>
15 #include <media/dvb_demux.h>
16 #include <media/dvb_frontend.h>
17 #include <media/dvb_net.h>
20 #include "mantis_common.h"
21 #include "mantis_ioc.h"
22 #include "mantis_dvb.h"
23 #include "mantis_vp2033.h"
25 #define MANTIS_MODEL_NAME "VP-2033"
26 #define MANTIS_DEV_TYPE "DVB-C"
28 static struct tda1002x_config vp2033_tda1002x_cu1216_config
= {
29 .demod_address
= 0x18 >> 1,
33 static struct tda10023_config vp2033_tda10023_cu1216_config
= {
34 .demod_address
= 0x18 >> 1,
38 static u8
read_pwm(struct mantis_pci
*mantis
)
40 struct i2c_adapter
*adapter
= &mantis
->adapter
;
44 struct i2c_msg msg
[] = {
45 {.addr
= 0x50, .flags
= 0, .buf
= &b
, .len
= 1},
46 {.addr
= 0x50, .flags
= I2C_M_RD
, .buf
= &pwm
, .len
= 1}
49 if ((i2c_transfer(adapter
, msg
, 2) != 2)
56 static int tda1002x_cu1216_tuner_set(struct dvb_frontend
*fe
)
58 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
59 struct mantis_pci
*mantis
= fe
->dvb
->priv
;
60 struct i2c_adapter
*adapter
= &mantis
->adapter
;
63 struct i2c_msg msg
= {.addr
= 0x60, .flags
= 0, .buf
= buf
, .len
= sizeof(buf
)};
66 #define CU1216_IF 36125000
67 #define TUNER_MUL 62500
69 u32 div
= (p
->frequency
+ CU1216_IF
+ TUNER_MUL
/ 2) / TUNER_MUL
;
71 buf
[0] = (div
>> 8) & 0x7f;
74 buf
[3] = (p
->frequency
< 150000000 ? 0x01 :
75 p
->frequency
< 445000000 ? 0x02 : 0x04);
79 if (fe
->ops
.i2c_gate_ctrl
)
80 fe
->ops
.i2c_gate_ctrl(fe
, 1);
82 if (i2c_transfer(adapter
, &msg
, 1) != 1)
85 /* wait for the pll lock */
88 for (i
= 0; i
< 20; i
++) {
89 if (fe
->ops
.i2c_gate_ctrl
)
90 fe
->ops
.i2c_gate_ctrl(fe
, 1);
92 if (i2c_transfer(adapter
, &msg
, 1) == 1 && (buf
[0] & 0x40))
98 /* switch the charge pump to the lower current */
103 if (fe
->ops
.i2c_gate_ctrl
)
104 fe
->ops
.i2c_gate_ctrl(fe
, 1);
106 if (i2c_transfer(adapter
, &msg
, 1) != 1)
112 static int vp2033_frontend_init(struct mantis_pci
*mantis
, struct dvb_frontend
*fe
)
114 struct i2c_adapter
*adapter
= &mantis
->adapter
;
118 err
= mantis_frontend_power(mantis
, POWER_ON
);
120 mantis_frontend_soft_reset(mantis
);
123 dprintk(MANTIS_ERROR
, 1, "Probing for CU1216 (DVB-C)");
124 fe
= dvb_attach(tda10021_attach
, &vp2033_tda1002x_cu1216_config
,
129 dprintk(MANTIS_ERROR
, 1,
130 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
131 vp2033_tda1002x_cu1216_config
.demod_address
);
133 fe
= dvb_attach(tda10023_attach
, &vp2033_tda10023_cu1216_config
,
138 dprintk(MANTIS_ERROR
, 1,
139 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
140 vp2033_tda1002x_cu1216_config
.demod_address
);
145 fe
->ops
.tuner_ops
.set_params
= tda1002x_cu1216_tuner_set
;
146 dprintk(MANTIS_ERROR
, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
151 dprintk(MANTIS_ERROR
, 1, "Frontend on <%s> POWER ON failed! <%d>",
159 dprintk(MANTIS_DEBUG
, 1, "Done!");
164 struct mantis_hwconfig vp2033_config
= {
165 .model_name
= MANTIS_MODEL_NAME
,
166 .dev_type
= MANTIS_DEV_TYPE
,
167 .ts_size
= MANTIS_TS_204
,
169 .baud_rate
= MANTIS_BAUD_9600
,
170 .parity
= MANTIS_PARITY_NONE
,
173 .frontend_init
= vp2033_frontend_init
,