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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
#include <device.h>
#include <cpu.h>
#include <vpd.h>
#include <interrupts.h>
#include <ccan/str/str.h>
#include <chip.h>
#include "spira.h"
#include "hdata.h"
struct i2c_dev {
uint8_t i2cm_engine;
uint8_t i2cm_port;
__be16 i2c_bus_freq;
/* i2c slave info */
uint8_t type;
uint8_t i2c_addr;
uint8_t i2c_port;
uint8_t __reserved;
__be32 purpose;
__be32 i2c_link;
__be16 slca_index;
};
#define P9_I2CM_XSCOM_SIZE 0x1000
#define P9_I2CM_XSCOM_BASE 0xa0000
static struct dt_node *get_i2cm_node(struct dt_node *xscom, int engine)
{
uint64_t xscom_base = P9_I2CM_XSCOM_BASE + P9_I2CM_XSCOM_SIZE * (uint64_t)engine;
struct dt_node *i2cm;
uint64_t freq, clock;
i2cm = dt_find_by_name_addr(xscom, "i2cm", xscom_base);
if (!i2cm) {
i2cm = dt_new_addr(xscom, "i2cm", xscom_base);
dt_add_property_cells(i2cm, "reg", xscom_base,
P9_I2CM_XSCOM_SIZE);
dt_add_property_strings(i2cm, "compatible",
"ibm,power8-i2cm", "ibm,power9-i2cm");
dt_add_property_cells(i2cm, "#size-cells", 0);
dt_add_property_cells(i2cm, "#address-cells", 1);
dt_add_property_cells(i2cm, "chip-engine#", engine);
freq = dt_prop_get_u64_def(xscom, "bus-frequency", 0);
clock = (u32)(freq / 4);
if (clock)
dt_add_property_cells(i2cm, "clock-frequency", clock);
else
dt_add_property_cells(i2cm, "clock-frequency", 150000000);
}
return i2cm;
}
static struct dt_node *get_bus_node(struct dt_node *i2cm, int port, int freq)
{
struct dt_node *bus;
bus = dt_find_by_name_addr(i2cm, "i2c-bus", port);
if (!bus) {
bus = dt_new_addr(i2cm, "i2c-bus", port);
dt_add_property_cells(bus, "reg", port);
dt_add_property_cells(bus, "#size-cells", 0);
dt_add_property_cells(bus, "#address-cells", 1);
/* The P9 I2C master is fully compatible with the P8 one */
dt_add_property_strings(bus, "compatible", "ibm,opal-i2c",
"ibm,power8-i2c-port", "ibm,power9-i2c-port");
/*
* use the clock frequency as the bus frequency until we
* have actual devices on the bus. Adding a device will
* reduce the frequency to something that all devices
* can tolerate.
*/
dt_add_property_cells(bus, "bus-frequency", freq * 1000);
}
return bus;
}
struct hdat_i2c_type {
uint32_t id;
const char *name;
const char *compat;
};
static struct hdat_i2c_type hdat_i2c_devs[] = {
/* XXX: Please verify that all VPD EEPROMs are of this type */
{ 0x2, "eeprom", "atmel,24c128" }
};
struct hdat_i2c_label {
uint32_t id;
const char *label;
};
static struct hdat_i2c_label hdat_i2c_labels[] = {
{ 0x1, "9551-led-controller" },
{ 0x2, "seeprom" },
{ 0x5, "module-vpd" },
{ 0x6, "dimm SPD" },
{ 0x7, "proc-vpd" },
{ 0x8, "sbe-eeprom" },
{ 0x9, "planar-vpd" }
};
/*
* this is pretty half-assed, to generate the labels properly we need to look
* up associated SLCA index and determine what kind of module the device is on
* and why
*/
static struct hdat_i2c_type *map_type(uint32_t type)
{
int i;
for (i = 0; i < ARRAY_SIZE(hdat_i2c_devs); i++)
if (hdat_i2c_devs[i].id == type)
return &hdat_i2c_devs[i];
return NULL;
}
static const char *map_label(uint32_t type)
{
int i;
for (i = 0; i < ARRAY_SIZE(hdat_i2c_labels); i++)
if (hdat_i2c_labels[i].id == type)
return hdat_i2c_labels[i].label;
return NULL;
}
static bool is_zeros(const void *p, size_t size)
{
const char *c = p;
size_t i;
for (i = 0; i < size; i++)
if (c[i] != 0)
return false;
return true;
}
struct host_i2c_hdr {
const struct HDIF_array_hdr hdr;
__be32 version;
};
int parse_i2c_devs(const struct HDIF_common_hdr *hdr, int idata_index,
struct dt_node *xscom)
{
struct dt_node *i2cm, *bus, *node;
const struct hdat_i2c_type *type;
const struct i2c_dev *dev;
const char *label, *name, *compat;
const struct host_i2c_hdr *ahdr;
uint32_t i2c_addr;
uint32_t version;
uint32_t size;
int i, count;
/*
* This code makes a few assumptions about XSCOM addrs, etc
* and will need updating for new processors
*/
assert(proc_gen == proc_gen_p9);
/*
* Emit an error if we get a newer version. This is an interim measure
* until the new version format is finalised.
*/
ahdr = HDIF_get_idata(hdr, idata_index, &size);
if (!ahdr || !size)
return -1;
/*
* Some hostboots don't correctly fill the version field. On these
* the offset from the start of the header to the start of the array
* is 16 bytes.
*/
if (be32_to_cpu(ahdr->hdr.offset) == 16) {
version = 1;
prerror("I2C: HDAT device array has no version! Assuming v1\n");
} else {
version = be32_to_cpu(ahdr->version);
}
if (version == 2) {
prerror("I2C: v%d found, but not supported. Parsing as v1\n",
version);
} else if (version > 2) {
prerror("I2C: v%d found, but not supported! THIS IS A BUG\n",
version);
return -1;
}
count = HDIF_get_iarray_size(hdr, idata_index);
for (i = 0; i < count; i++) {
dev = HDIF_get_iarray_item(hdr, idata_index, i, &size);
/*
* XXX: Some broken hostboots populate i2c devs with zeros.
* Workaround them for now.
*/
if (is_zeros(dev, size)) {
prerror("I2C: Ignoring broken i2c dev %d\n", i);
continue;
}
i2cm = get_i2cm_node(xscom, dev->i2cm_engine);
bus = get_bus_node(i2cm, dev->i2cm_port,
be16_to_cpu(dev->i2c_bus_freq));
/*
* Looks like hostboot gives the address as an 8 bit, left
* justified quantity (i.e it includes the R/W bit). So we need
* to strip it off to get an address linux can use.
*/
i2c_addr = dev->i2c_addr >> 1;
prlog(PR_TRACE, "HDAT I2C: found e%dp%d - %x\n",
dev->i2cm_engine, dev->i2cm_port, i2c_addr);
type = map_type(dev->type);
label = map_label(be32_to_cpu(dev->purpose));
if (type) {
compat = type->compat;
name = type->name;
} else {
name = "unknown";
compat = NULL;
}
node = dt_new_addr(bus, name, i2c_addr);
if (!node)
continue;
dt_add_property_cells(node, "reg", i2c_addr);
dt_add_property_cells(node, "link-id",
be32_to_cpu(dev->i2c_link));
if (compat)
dt_add_property_string(node, "compatible", compat);
if (label)
dt_add_property_string(node, "label", label);
/* XXX: SLCA index? */
}
return 0;
}
|