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
|
#include <rtdevice.h>
#include <string.h>
#include "platform.h"
#ifdef RT_USING_I2C
#include "drv_i2c.h"
#endif
#ifdef RT_USING_SPI
#include "drv_ssi.h"
#endif
#include "gd_gpio.h"
#ifdef RT_USING_ADC
#include "drv_adc.h"
#endif
#ifdef RT_USING_PWM
#include "drv_pwm.h"
#endif
#ifdef RT_USING_WDT
#include "drv_wdt.h"
#endif
#ifdef RT_USING_SDIO
#include "drv_sdio.h"
#endif
struct gk_platform_device
{
char *name;
void *private_data;
};
#ifdef RT_USING_I2C
static struct gk_i2c_obj i2c0_obj = {
.id = 0,
.config = {
.i2cInitParams.priority = 1,//!< Interrupt Request (IRQ) for more general interrupts
.i2cInitParams.mode = 2,//!< Auto master mode.
.i2cInitParams.gpioSclPinCh1 = -1,
.i2cInitParams.gpioSdaPinCh1 = -1,
.i2cInitParams.gpioSclPinCh2 = -1,
.i2cInitParams.gpioSdaPinCh2 = -1,
},
};
static struct gk_i2c_obj i2c1_obj = {
.id = 1,
.config = {
.i2cInitParams.priority = 1,//!< Interrupt Request (IRQ) for more general interrupts
.i2cInitParams.mode = 2,//!< Auto master mode.
.i2cInitParams.gpioSclPinCh1 = -1,
.i2cInitParams.gpioSdaPinCh1 = -1,
.i2cInitParams.gpioSclPinCh2 = -1,
.i2cInitParams.gpioSdaPinCh2 = -1,
},
};
struct gk_platform_device plat_i2c0 = {
.name = "i2c", .private_data = &i2c0_obj,
};
struct gk_platform_device plat_i2c1 = {
.name = "i2c", .private_data = &i2c1_obj,
};
#endif
#ifdef RT_USING_SPI
static struct gk_spi_controller_data spi0_controller_data =
{
.id = 0,
.total_slave = 1,
.slave_cs_pin[0] = GD_GPIO_14,//AT25640B eeprom
.slave_cs_pin[1] = GD_GPIO_NUM,
};
static struct gk_spi_controller_data spi1_controller_data =
{
.id = 1,
.total_slave = 2,
.slave_cs_pin[0] = GD_GPIO_13,//rgb_my280h45p01
.slave_cs_pin[1] = GD_GPIO_18,//rgb_tpo990000072
};
struct gk_platform_device plat_spi0 =
{
.name = "spi", .private_data = &spi0_controller_data,
};
struct gk_platform_device plat_spi1 =
{
.name = "spi", .private_data = &spi1_controller_data,
};
#endif
#ifdef RT_USING_WDT
static struct wdt_driver wdt_obj = {
.in_use = 0,
};
#endif
#ifdef RT_USING_ADC
static struct wrap_adc_obj adc_obj = {
.id = 0, .active_channel_no = 0,
};
#endif
#ifdef RT_USING_PWM
static struct pwm_driver pwm_obj = {
.pwm[0].id = 0, .pwm[0].gpio_id = GD_GPIO_42,
};
#endif
struct gk_platform_device plat_pwm = {
.name = "pwm", .private_data = &pwm_obj,
};
struct gk_platform_device plat_wdt = {
.name = "wdt", .private_data = &wdt_obj,
};
struct gk_platform_device plat_adc = {
.name = "adc", .private_data = &adc_obj,
};
#ifdef RT_USING_SDIO
static struct gk_sdio_info sdio0 =
{
.id = 0,
#ifdef GK7102C_JH
.type = SDIO_DEVICE_TYPE_WIFI,
#else
.type = SDIO_DEVICE_TYPE_NORMAL,
#endif
};
#ifdef CODEC_710XS
static struct gk_sdio_info sdio1 =
{
.id = 1,
.type = SDIO_DEVICE_TYPE_NORMAL,
};
#endif
struct gk_platform_device plat_sdio0 = {
.name = "gk-sdio", .private_data = &sdio0,
};
#ifdef CODEC_710XS
struct gk_platform_device plat_sdio1 = {
.name = "gk-sdio", .private_data = &sdio1,
};
#endif
#endif
const static struct gk_platform_device *platform_device[] = {
#ifdef RT_USING_I2C
&plat_i2c0,
&plat_i2c1,
#endif
#ifdef RT_USING_SPI
&plat_spi0,
&plat_spi1,
#endif
#ifdef RT_USING_WDT
&plat_wdt,
#endif
#ifdef RT_USING_ADC
&plat_adc,
#endif
#ifdef RT_USING_PWM
&plat_pwm,
#endif
#ifdef RT_USING_SDIO
&plat_sdio0,
#ifdef CODEC_710XS
&plat_sdio1,
#endif
#endif
};
int gk_platform_driver_init(struct gk_platform_driver *plat_drv)
{
int i,ret = RT_EOK;
int device_cnt = sizeof(platform_device) / sizeof(platform_device[0]);
if(!plat_drv || !plat_drv->name || !plat_drv->probe)
return -RT_EINVAL;
for (i = 0; i < device_cnt; i++)
{
if (!strcmp(plat_drv->name, platform_device[i]->name))
{
ret = plat_drv->probe(platform_device[i]->private_data);
}
}
return ret;
}
int gk_platform_driver_uninit(struct gk_platform_driver *plat_drv)
{
int i,ret = RT_EOK;
int device_cnt = sizeof(platform_device) / sizeof(platform_device[0]);
if(!plat_drv || !plat_drv->name || !plat_drv->probe)
return -RT_EINVAL;
for (i = 0; i < device_cnt; i++)
{
if (!strcmp(plat_drv->name, platform_device[i]->name))
{
ret = plat_drv->remove(platform_device[i]->private_data);
}
}
return ret;
}
|