forked from Evlers/esp8089_wifi_drivers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spi_stub.c
212 lines (174 loc) · 4.02 KB
/
spi_stub.c
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
#include "esp_sif.h"
#include "esp_debug.h"
#include "ESP8089_dts.h"
#include "linux/interrupt.h"
#include "linux/spi/spi.h"
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
/*
HSPI:
GPIO12 HMISO
GPIO13 HMOSI
GPIO14 HSCLK
GPIO15 HCS
SPI:
GPIO6 SCLK
GPIO7 MISO
GPIO8 MOSI
GPIO11 CS
SDIO:
GPIO6 SDCLK
GPIO7 SDD0
GPIO8 SDD1
GPIO9 SDD2
GPIO10 SDD3
GPIO11 SDCMD
*/
static int esp_cs_gpio = 135;//PE7 128 + 7 = 135
static int esp_interrupt = 133;//PE5 128 + 5 = 133
static int esp_reset_gpio = 132;//PE4 128 + 4 = 132
/* *** *** Board info *** *** */
#ifdef REGISTER_SPI_BOARD_INFO
#define MAX_SPEED_HZ (10*MHz)
static struct spi_board_info esp_board_spi_devices[] = {
{
.modalias = "espressif,esp8089",
.max_speed_hz = MAX_SPEED_HZ,
.bus_num = 1,
.chip_select = 0,
.mode = SPI_MODE_3,
},
};
void sif_platform_register_board_info(void)
{
//spi_register_board_info(esp_board_spi_devices, ARRAY_SIZE(esp_board_spi_devices));
}
struct spi_device* sif_platform_new_device(void)
{
struct device *dev;
char str [32];
static struct spi_master *master;
static struct spi_device *spi;
master = spi_busnum_to_master(esp_board_spi_devices[0].bus_num);
if(!master)
esp_dbg(ESP_DBG_ERROR, "esp8089_spi: FAILED to find master\n");
snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), esp_board_spi_devices[0].chip_select);
dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
if(dev)
{
esp_dbg(ESP_DBG_ERROR, "esp8089_spi: Find a dev using spi, deleting!\n");
device_del(dev);
}
else
{
esp_dbg(ESP_SHOW, "esp8089_spi: No dev using spi!\n");
}
spi = spi_new_device( master, esp_board_spi_devices );
if(!spi)
esp_dbg(ESP_DBG_ERROR, "esp8089_spi: FAILED to create slave\n");
if(spi_setup(spi))
esp_dbg(ESP_DBG_ERROR, "esp8089_spi: FAILED to setup slave\n");
return spi;
}
#endif
void esp8089_set_interrupt_gpio(int numss)
{
esp_interrupt = numss;
}
void esp8089_set_reset_gpio(int numss)
{
esp_reset_gpio = numss;
}
void esp8089_set_cs_gpio(int numss)
{
esp_cs_gpio = numss;
}
int sif_platform_irq_init(void)
{
int ret;
esp_dbg(ESP_SHOW, "esp8089_spi: %s enter\n", __func__);
if ( (ret = gpio_request(esp_interrupt, "esp_interrupt")) != 0)
{
esp_dbg(ESP_DBG_ERROR, "esp8089_spi: request gpio error\n");
return ret;
}
gpio_direction_input(esp_interrupt);
sif_platform_irq_clear();
sif_platform_irq_mask(1);
udelay(1);
return 0;
}
void sif_platform_irq_deinit(void)
{
gpio_free(esp_interrupt);
}
int sif_platform_get_irq_no(void)
{
return gpio_to_irq(esp_interrupt);
}
int sif_platform_is_irq_occur(void)
{
return 1;
}
void sif_platform_irq_clear(void)
{
}
void sif_platform_irq_mask(int mask)
{
if (mask)
disable_irq_nosync(sif_platform_get_irq_no());
else
enable_irq(sif_platform_get_irq_no());
}
void sif_platform_target_speed(int high_speed)
{
}
#ifdef ESP_ACK_INTERRUPT
void sif_platform_ack_interrupt(struct esp_pub *epub)
{
sif_platform_irq_clear();
}
#endif
/* *** *** Platform power *** *** */
void sif_platform_cs_enable(void)
{
gpio_request(esp_cs_gpio, "esp_cs_gpio");
gpio_direction_output(esp_cs_gpio, 0);
gpio_free(esp_cs_gpio);
}
void sif_platform_cs_disable(void)
{
gpio_request(esp_cs_gpio, "esp_cs_gpio");
gpio_direction_output(esp_cs_gpio, 1);
gpio_free(esp_cs_gpio);
}
void sif_platform_reset_target(void)
{
gpio_request(esp_reset_gpio, "esp_reset_gpio");
gpio_direction_output(esp_reset_gpio, 1);
mdelay(1000);
gpio_direction_output(esp_reset_gpio, 0);
mdelay(200);
gpio_direction_output(esp_reset_gpio, 1);
mdelay(200);
gpio_free(esp_reset_gpio);
}
void sif_platform_target_poweroff(void)
{
gpio_direction_output(esp_reset_gpio, 0);
}
void sif_platform_target_poweron(void)
{
gpio_request(esp_reset_gpio, "esp_reset_gpio");
mdelay(200);
gpio_direction_output(esp_reset_gpio, 1);
mdelay(1000);
gpio_direction_output(esp_reset_gpio, 0);
mdelay(200);
gpio_direction_output(esp_reset_gpio, 1);
mdelay(200);
gpio_free(esp_reset_gpio);
}