-
Notifications
You must be signed in to change notification settings - Fork 0
/
netx.c
211 lines (172 loc) · 3.86 KB
/
netx.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
/*
* Copyright (c) 2017 Andreas Färber
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_gpio.h>
#include <linux/spi/spi.h>
struct netx_ops {
const char *name;
int (*init)(struct spi_device *spi);
int (*read)(struct spi_device *spi, u32 addr, u8 len, void *buf);
};
struct netx_packet_head {
u32 dest;
u32 src;
u32 dest_id;
u32 src_id;
u32 len;
u32 id;
u32 state;
u32 cmd;
u32 ext;
u32 rout;
};
struct netx_packet {
struct netx_packet_head head;
};
static int netx10_init(struct spi_device *spi)
{
return -ENOTSUPP;
}
static const struct netx_ops netx10_ops = {
.name = "netX10",
.init = netx10_init,
};
static int netx50_init(struct spi_device *spi)
{
return -ENOTSUPP;
}
static const struct netx_ops netx50_ops = {
.name = "netX50",
.init = netx50_init,
};
static int netx100_init(struct spi_device *spi)
{
return -ENOTSUPP;
}
static const struct netx_ops netx100_ops = {
.name = "netX100",
.init = netx100_init,
};
static int netx51_read(struct spi_device *spi, u32 addr, u8 len, void *val)
{
struct spi_transfer xfers[2];
u8 buf[4], rxbuf[4];
int ret;
buf[0] = ((addr >> 16) & 0xf) | BIT(7);
buf[1] = (addr >> 8) & 0xff;
buf[2] = addr & 0xff;
buf[3] = len;
memset(xfers, 0, 2 * sizeof(struct spi_transfer));
xfers[0].tx_buf = buf;
xfers[0].rx_buf = rxbuf;
xfers[0].len = 4;
xfers[1].rx_buf = val;
xfers[1].len = len;
ret = spi_sync_transfer(spi, xfers, 2);
if (ret < 0)
return ret;
dev_dbg(&spi->dev, "read status: %02x\n",
(unsigned)rxbuf[0]);
return 0;
}
static int netx51_init(struct spi_device *spi)
{
char sz[5];
int ret;
/* Two dummy reads for sDPM initialization */
ret = netx51_read(spi, 0x0, 1, sz);
if (ret < 0)
return ret;
ret = netx51_read(spi, 0x0, 1, sz);
if (ret < 0)
return ret;
memset(sz, 0, 5);
ret = netx51_read(spi, 0x0, 4, sz);
if (ret < 0)
return ret;
sz[4] = '\0';
dev_info(&spi->dev, "abCookie = %s\n", sz);
return 0;
}
static const struct netx_ops netx51_ops = {
.name = "netX51",
.init = netx51_init,
.read = netx51_read,
};
static int netx_probe(struct spi_device *spi)
{
u8 buf[3], rxbuf[3];
struct spi_transfer xfer = {
.tx_buf = buf,
.rx_buf = rxbuf,
.len = 3,
};
const struct netx_ops *ops;
u32 val;
int ret;
dev_info(&spi->dev, "netx probe\n");
buf[0] = 0x00;
buf[1] = 0xFF;
buf[2] = 0x84;
ret = spi_sync_transfer(spi, &xfer, 1);
if (ret < 0)
return ret;
dev_dbg(&spi->dev, "read: %02x %02x %02x\n",
(unsigned)rxbuf[0], (unsigned)rxbuf[1], (unsigned)rxbuf[2]);
if (rxbuf[0] == 0x00 && rxbuf[1] == 0x00 && rxbuf[2] == 0x00) {
ops = &netx10_ops;
} else if (rxbuf[0] == 0xFF && rxbuf[1] == 0xFF && rxbuf[2] == 0xFF) {
ops = &netx50_ops;
} else if ((rxbuf[0] & GENMASK(4, 0)) == 0x11) {
ops = &netx51_ops;
} else if (rxbuf[0] == 0x64) {
ops = &netx100_ops;
} else {
dev_err(&spi->dev, "netX model not recognized\n");
return -EINVAL;
}
dev_info(&spi->dev, "%s family\n", ops->name);
if (ops->init) {
ret = ops->init(spi);
if (ret < 0)
return ret;
}
ret = ops->read(spi, 0x00C4, 4, &val);
if (ret < 0)
return ret;
le32_to_cpus(&val);
dev_info(&spi->dev, "status = %08x\n", val);
#define RCX_SYS_STATUS_NXO_SUPPORTED BIT(31)
if (val & RCX_SYS_STATUS_NXO_SUPPORTED) {
}
return 0;
}
static int netx_remove(struct spi_device *spi)
{
dev_info(&spi->dev, "netx removed\n");
return 0;
}
#ifdef CONFIG_OF
static const struct of_device_id netx_dt_ids[] = {
{ .compatible = "hilscher,netx52" },
{}
};
MODULE_DEVICE_TABLE(of, netx_dt_ids);
#endif
static struct spi_driver netx_spi_driver = {
.driver = {
.name = "netx",
.of_match_table = of_match_ptr(netx_dt_ids),
},
.probe = netx_probe,
.remove = netx_remove,
};
module_spi_driver(netx_spi_driver);
MODULE_DESCRIPTION("netX SPI driver");
MODULE_AUTHOR("Andreas Färber <[email protected]>");
MODULE_LICENSE("GPL");