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_vp2040.h"
25 #define MANTIS_MODEL_NAME "VP-2040"
26 #define MANTIS_DEV_TYPE "DVB-C"
28 static struct tda1002x_config vp2040_tda1002x_cu1216_config = {
29 .demod_address = 0x18 >> 1,
33 static struct tda10023_config vp2040_tda10023_cu1216_config = {
34 .demod_address = 0x18 >> 1,
38 static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe)
40 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
41 struct mantis_pci *mantis = fe->dvb->priv;
42 struct i2c_adapter *adapter = &mantis->adapter;
45 struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
48 #define CU1216_IF 36125000
49 #define TUNER_MUL 62500
51 u32 div = (p->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
53 buf[0] = (div >> 8) & 0x7f;
56 buf[3] = (p->frequency < 150000000 ? 0x01 :
57 p->frequency < 445000000 ? 0x02 : 0x04);
61 if (fe->ops.i2c_gate_ctrl)
62 fe->ops.i2c_gate_ctrl(fe, 1);
64 if (i2c_transfer(adapter, &msg, 1) != 1)
67 /* wait for the pll lock */
70 for (i = 0; i < 20; i++) {
71 if (fe->ops.i2c_gate_ctrl)
72 fe->ops.i2c_gate_ctrl(fe, 1);
74 if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
80 /* switch the charge pump to the lower current */
85 if (fe->ops.i2c_gate_ctrl)
86 fe->ops.i2c_gate_ctrl(fe, 1);
88 if (i2c_transfer(adapter, &msg, 1) != 1)
94 static u8 read_pwm(struct mantis_pci *mantis)
96 struct i2c_adapter *adapter = &mantis->adapter;
100 struct i2c_msg msg[] = {
101 {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
102 {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
105 if ((i2c_transfer(adapter, msg, 2) != 2)
112 static int vp2040_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, &vp2040_tda1002x_cu1216_config,
129 dprintk(MANTIS_ERROR, 1,
130 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
131 vp2040_tda1002x_cu1216_config.demod_address);
133 fe = dvb_attach(tda10023_attach, &vp2040_tda10023_cu1216_config,
138 dprintk(MANTIS_ERROR, 1,
139 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
140 vp2040_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>",
158 dprintk(MANTIS_DEBUG, 1, "Done!");
163 struct mantis_hwconfig vp2040_config = {
164 .model_name = MANTIS_MODEL_NAME,
165 .dev_type = MANTIS_DEV_TYPE,
166 .ts_size = MANTIS_TS_204,
168 .baud_rate = MANTIS_BAUD_9600,
169 .parity = MANTIS_PARITY_NONE,
172 .frontend_init = vp2040_frontend_init,