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
|
/*****************************************************************************
Copyright(c) 2014 FCI Inc. All Rights Reserved
File name : fci_tun.c
Description : source of tuner control driver
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
History :
----------------------------------------------------------------------
*******************************************************************************/
#include "fci_types.h"
#include "fc8180_regs.h"
#include "fci_hal.h"
#include "fci_tun.h"
#include "fci_hpi.h"
#include "fc8180_bb.h"
#include "fc8180_tun.h"
#define FC8180_TUNER_ADDR 0xaa
struct I2C_DRV {
s32 (*init)(HANDLE handle, s32 speed, s32 slaveaddr);
s32 (*read)(HANDLE handle, u8 chip, u8 addr, u8 alen, u8 *data,
u8 len);
s32 (*write)(HANDLE handle, u8 chip, u8 addr, u8 alen, u8 *data,
u8 len);
s32 (*deinit)(HANDLE handle);
};
static struct I2C_DRV fcihpi = {
&fci_hpi_init,
&fci_hpi_read,
&fci_hpi_write,
&fci_hpi_deinit
};
struct TUNER_DRV {
s32 (*init)(HANDLE handle, enum BAND_TYPE band);
s32 (*set_freq)(HANDLE handle, u32 freq);
s32 (*get_rssi)(HANDLE handle, s32 *rssi);
s32 (*deinit)(HANDLE handle);
};
static struct TUNER_DRV fc8180_tuner = {
&fc8180_tuner_init,
&fc8180_set_freq,
&fc8180_get_rssi,
&fc8180_tuner_deinit
};
static u8 tuner_addr = FC8180_TUNER_ADDR;
static enum BAND_TYPE tuner_band = ISDBT_1_SEG_TYPE;
static enum I2C_TYPE tuner_i2c = FCI_HPI_TYPE;
static struct I2C_DRV *tuner_ctrl = &fcihpi;
static struct TUNER_DRV *tuner = &fc8180_tuner;
s32 tuner_ctrl_select(HANDLE handle, enum I2C_TYPE type)
{
switch (type) {
case FCI_HPI_TYPE:
tuner_ctrl = &fcihpi;
break;
default:
return BBM_E_TN_CTRL_SELECT;
}
if (tuner_ctrl->init(handle, 400, 0))
return BBM_E_TN_CTRL_INIT;
tuner_i2c = type;
return BBM_OK;
}
s32 tuner_ctrl_deselect(HANDLE handle)
{
if (tuner_ctrl == NULL)
return BBM_E_TN_CTRL_SELECT;
tuner_ctrl->deinit(handle);
tuner_i2c = FCI_HPI_TYPE;
tuner_ctrl = &fcihpi;
return BBM_OK;
}
s32 tuner_i2c_read(HANDLE handle, u8 addr, u8 alen, u8 *data, u8 len)
{
if (tuner_ctrl == NULL)
return BBM_E_TN_CTRL_SELECT;
if (tuner_ctrl->read(handle, tuner_addr, addr, alen, data, len))
return BBM_E_TN_READ;
return BBM_OK;
}
s32 tuner_i2c_write(HANDLE handle, u8 addr, u8 alen, u8 *data, u8 len)
{
if (tuner_ctrl == NULL)
return BBM_E_TN_CTRL_SELECT;
if (tuner_ctrl->write(handle, tuner_addr, addr, alen, data, len))
return BBM_E_TN_WRITE;
return BBM_OK;
}
s32 tuner_set_freq(HANDLE handle, u32 freq)
{
if (tuner == NULL)
return BBM_E_TN_SELECT;
#if (BBM_BAND_WIDTH == 8)
freq -= 460;
#else
freq -= 380;
#endif
if (tuner->set_freq(handle, freq))
return BBM_E_TN_SET_FREQ;
fc8180_reset(handle);
return BBM_OK;
}
s32 tuner_select(HANDLE handle, enum PRODUCT_TYPE product, enum BAND_TYPE band)
{
switch (product) {
case FC8180_TUNER:
tuner = &fc8180_tuner;
tuner_addr = FC8180_TUNER_ADDR;
tuner_band = band;
break;
default:
return BBM_E_TN_SELECT;
}
if (tuner == NULL)
return BBM_E_TN_SELECT;
if (tuner->init(handle, tuner_band))
return BBM_E_TN_INIT;
return BBM_OK;
}
s32 tuner_deselect(HANDLE handle)
{
if (tuner == NULL)
return BBM_E_TN_SELECT;
if (tuner->deinit(handle))
return BBM_NOK;
return BBM_OK;
}
s32 tuner_get_rssi(HANDLE handle, s32 *rssi)
{
if (tuner == NULL)
return BBM_E_TN_SELECT;
if (tuner->get_rssi(handle, rssi))
return BBM_E_TN_RSSI;
return BBM_OK;
}
|