aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/isdbt/fc8150/fc8150_i2c.c
blob: 5d264c1e4b8215135e122dfeb33703ed040c5836 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*****************************************************************************
 Copyright(c) 2012 FCI Inc. All Rights Reserved

 File name : fc8150_i2c.c

 Description : fc8150 host interface

*******************************************************************************/

#include "fci_types.h"
#include "fc8150_regs.h"
#include "fci_oal.h"
#include "fci_hal.h"

#define HPIC_READ           0x01 /* read command */
#define HPIC_WRITE          0x02 /* write command */
#define HPIC_AINC           0x04 /* address increment */
#define HPIC_BMODE          0x00 /* byte mode */
#define HPIC_WMODE          0x10 /* word mode */
#define HPIC_LMODE          0x20 /* long mode */
#define HPIC_ENDIAN         0x00 /* little endian */
#define HPIC_CLEAR          0x80 /* currently not used */

#define CHIP_ADDR           0x58

static int i2c_bulkread(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
{
	/* Write your own i2c driver code here for read operation. */

	return BBM_OK;
}

static int i2c_bulkwrite(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
{
	/* Write your own i2c driver code here for Write operation. */

	return BBM_OK;
}

static int i2c_dataread(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u32 length)
{
	return i2c_bulkread(hDevice, chip, addr, data, length);
}

int fc8150_bypass_read(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
{
	int res;
	u8 bypass_addr = 0x03;
	u8 bypass_data = 1;
	u8 bypass_len  = 1;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, bypass_addr
		, &bypass_data, bypass_len);
	res |= i2c_bulkread(hDevice, chip, addr, data, length);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_bypass_write(HANDLE hDevice, u8 chip, u8 addr, u8 *data, u16 length)
{
	int res;
	u8 bypass_addr = 0x03;
	u8 bypass_data = 1;
	u8 bypass_len  = 1;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, bypass_addr
		, &bypass_data, bypass_len);
	res |= i2c_bulkwrite(hDevice, chip, addr, data, length);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_init(HANDLE hDevice, u16 param1, u16 param2)
{
	OAL_CREATE_SEMAPHORE();

	/* for TSIF, you can call here your own TSIF initialization function. */
	/* tsif_initialize(); */

	bbm_write(hDevice, BBM_TS_CLK_DIV, 0x04);
	bbm_write(hDevice, BBM_TS_PAUSE, 0x80);

	bbm_write(hDevice, BBM_TS_CTRL, 0x02);
	bbm_write(hDevice, BBM_TS_SEL, 0x84);

	return BBM_OK;
}

int fc8150_i2c_byteread(HANDLE hDevice, u16 addr, u8 *data)
{
	int res;
	u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, data, 1);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_wordread(HANDLE hDevice, u16 addr, u16 *data)
{
	int res;
	u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)data, 2);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_longread(HANDLE hDevice, u16 addr, u32 *data)
{
	int res;
	u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)data, 4);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
{
	int res;
	u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkread(hDevice, CHIP_ADDR, BBM_DATA_REG, data, length);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_bytewrite(HANDLE hDevice, u16 addr, u8 data)
{
	int res;
	u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)&data, 1);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_wordwrite(HANDLE hDevice, u16 addr, u16 data)
{
	int res;
	u8 command = HPIC_WRITE | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)&data, 2);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_longwrite(HANDLE hDevice, u16 addr, u32 data)
{
	int res;
	u8 command = HPIC_WRITE | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, (u8 *)&data, 4);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
{
	int res;
	u8 command = HPIC_WRITE | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_DATA_REG, data, length);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
{
	int res;
	u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;

	OAL_OBTAIN_SEMAPHORE();
	res = i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_ADDRESS_REG
		, (u8 *)&addr, 2);
	res |= i2c_bulkwrite(hDevice, CHIP_ADDR, BBM_COMMAND_REG, &command, 1);
	res |= i2c_dataread(hDevice, CHIP_ADDR, BBM_DATA_REG, data, length);
	OAL_RELEASE_SEMAPHORE();

	return res;
}

int fc8150_i2c_deinit(HANDLE hDevice)
{
	bbm_write(hDevice, BBM_TS_SEL, 0x00);

	/* tsif_disable(); */

	OAL_DELETE_SEMAPHORE();

	return BBM_OK;
}