WIP FPC-III support
[linux/fpc-iii.git] / drivers / media / pci / mantis / mantis_vp2033.c
blob861c1e49358b54117f721f7e4f622c815f608d48
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 Mantis VP-2033 driver
5 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
7 */
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>
19 #include "tda1002x.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,
30 .invert = 1,
33 static struct tda10023_config vp2033_tda10023_cu1216_config = {
34 .demod_address = 0x18 >> 1,
35 .invert = 1,
38 static u8 read_pwm(struct mantis_pci *mantis)
40 struct i2c_adapter *adapter = &mantis->adapter;
42 u8 b = 0xff;
43 u8 pwm;
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)
50 || (pwm == 0xff))
51 pwm = 0x48;
53 return pwm;
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;
62 u8 buf[6];
63 struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
64 int i;
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;
72 buf[1] = div & 0xff;
73 buf[2] = 0xce;
74 buf[3] = (p->frequency < 150000000 ? 0x01 :
75 p->frequency < 445000000 ? 0x02 : 0x04);
76 buf[4] = 0xde;
77 buf[5] = 0x20;
79 if (fe->ops.i2c_gate_ctrl)
80 fe->ops.i2c_gate_ctrl(fe, 1);
82 if (i2c_transfer(adapter, &msg, 1) != 1)
83 return -EIO;
85 /* wait for the pll lock */
86 msg.flags = I2C_M_RD;
87 msg.len = 1;
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))
93 break;
95 msleep(10);
98 /* switch the charge pump to the lower current */
99 msg.flags = 0;
100 msg.len = 2;
101 msg.buf = &buf[2];
102 buf[2] &= ~0x40;
103 if (fe->ops.i2c_gate_ctrl)
104 fe->ops.i2c_gate_ctrl(fe, 1);
106 if (i2c_transfer(adapter, &msg, 1) != 1)
107 return -EIO;
109 return 0;
112 static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
114 struct i2c_adapter *adapter = &mantis->adapter;
116 int err = 0;
118 err = mantis_frontend_power(mantis, POWER_ON);
119 if (err == 0) {
120 mantis_frontend_soft_reset(mantis);
121 msleep(250);
123 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
124 fe = dvb_attach(tda10021_attach, &vp2033_tda1002x_cu1216_config,
125 adapter,
126 read_pwm(mantis));
128 if (fe) {
129 dprintk(MANTIS_ERROR, 1,
130 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
131 vp2033_tda1002x_cu1216_config.demod_address);
132 } else {
133 fe = dvb_attach(tda10023_attach, &vp2033_tda10023_cu1216_config,
134 adapter,
135 read_pwm(mantis));
137 if (fe) {
138 dprintk(MANTIS_ERROR, 1,
139 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
140 vp2033_tda1002x_cu1216_config.demod_address);
144 if (fe) {
145 fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
146 dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
147 } else {
148 return -1;
150 } else {
151 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
152 adapter->name,
153 err);
155 return -EIO;
158 mantis->fe = fe;
159 dprintk(MANTIS_DEBUG, 1, "Done!");
161 return 0;
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,
171 .bytes = 0,
173 .frontend_init = vp2033_frontend_init,
174 .power = GPIF_A12,
175 .reset = GPIF_A13,