1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "cx23885.h"
18#include "cx23885-f300.h"
19
20#define F300_DATA GPIO_0
21#define F300_RESET GPIO_1
22#define F300_CLK GPIO_2
23#define F300_BUSY GPIO_3
24
25static void f300_set_line(struct cx23885_dev *dev, u32 line, u8 lvl)
26{
27 cx23885_gpio_enable(dev, line, 1);
28 if (lvl == 1)
29 cx23885_gpio_set(dev, line);
30 else
31 cx23885_gpio_clear(dev, line);
32}
33
34static u8 f300_get_line(struct cx23885_dev *dev, u32 line)
35{
36 cx23885_gpio_enable(dev, line, 0);
37
38 return cx23885_gpio_get(dev, line);
39}
40
41static void f300_send_byte(struct cx23885_dev *dev, u8 dta)
42{
43 u8 i;
44
45 for (i = 0; i < 8; i++) {
46 f300_set_line(dev, F300_CLK, 0);
47 udelay(30);
48 f300_set_line(dev, F300_DATA, (dta & 0x80) >> 7);
49 udelay(30);
50 dta <<= 1;
51 f300_set_line(dev, F300_CLK, 1);
52 udelay(30);
53 }
54}
55
56static u8 f300_get_byte(struct cx23885_dev *dev)
57{
58 u8 i, dta = 0;
59
60 for (i = 0; i < 8; i++) {
61 f300_set_line(dev, F300_CLK, 0);
62 udelay(30);
63 dta <<= 1;
64 f300_set_line(dev, F300_CLK, 1);
65 udelay(30);
66 dta |= f300_get_line(dev, F300_DATA);
67
68 }
69
70 return dta;
71}
72
73static u8 f300_xfer(struct dvb_frontend *fe, u8 *buf)
74{
75 struct cx23885_tsport *port = fe->dvb->priv;
76 struct cx23885_dev *dev = port->dev;
77 u8 i, temp, ret = 0;
78
79 temp = buf[0];
80 for (i = 0; i < buf[0]; i++)
81 temp += buf[i + 1];
82 temp = (~temp + 1);
83 buf[1 + buf[0]] = temp;
84
85 f300_set_line(dev, F300_RESET, 1);
86 f300_set_line(dev, F300_CLK, 1);
87 udelay(30);
88 f300_set_line(dev, F300_DATA, 1);
89 msleep(1);
90
91
92 f300_set_line(dev, F300_RESET, 0);
93 msleep(1);
94
95 f300_send_byte(dev, 0xe0);
96 msleep(1);
97
98 temp = buf[0];
99 temp += 2;
100 for (i = 0; i < temp; i++)
101 f300_send_byte(dev, buf[i]);
102
103 f300_set_line(dev, F300_RESET, 1);
104 f300_set_line(dev, F300_DATA, 1);
105
106
107 temp = 0;
108 for (i = 0; ((i < 8) & (temp == 0)); i++) {
109 msleep(1);
110 if (f300_get_line(dev, F300_BUSY) == 0)
111 temp = 1;
112 }
113
114 if (i > 7) {
115 pr_err("%s: timeout, the slave no response\n",
116 __func__);
117 ret = 1;
118 } else {
119 f300_set_line(dev, F300_RESET, 0);
120 msleep(1);
121 f300_send_byte(dev, 0xe1);
122 msleep(1);
123 temp = f300_get_byte(dev);
124 if (temp > 14)
125 temp = 14;
126
127 for (i = 0; i < (temp + 1); i++)
128 f300_get_byte(dev);
129
130 f300_set_line(dev, F300_RESET, 1);
131 f300_set_line(dev, F300_DATA, 1);
132 }
133
134 return ret;
135}
136
137int f300_set_voltage(struct dvb_frontend *fe, enum fe_sec_voltage voltage)
138{
139 u8 buf[16];
140
141 buf[0] = 0x05;
142 buf[1] = 0x38;
143 buf[2] = 0x01;
144
145 switch (voltage) {
146 case SEC_VOLTAGE_13:
147 buf[3] = 0x01;
148 buf[4] = 0x02;
149 buf[5] = 0x00;
150 break;
151 case SEC_VOLTAGE_18:
152 buf[3] = 0x01;
153 buf[4] = 0x02;
154 buf[5] = 0x01;
155 break;
156 case SEC_VOLTAGE_OFF:
157 buf[3] = 0x00;
158 buf[4] = 0x00;
159 buf[5] = 0x00;
160 break;
161 }
162
163 return f300_xfer(fe, buf);
164}
165