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