~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 7b127986da7e2e671af0bf17f6845b140545db82 (plain)
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
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2021 Marek Vasut <marek.vasut+renesas@gmail.com>
 */

#include <common.h>
#include <dm.h>
#include <i2c_eeprom.h>
#include <log.h>
#include <sysinfo.h>

#define BOARD_CODE_MASK		0xF8
#define BOARD_REV_MASK		0x07
#define BOARD_CODE_SHIFT	0x03

#define BOARD_SALVATOR_X	0x0
#define BOARD_KRIEK		0x1
#define BOARD_STARTER_KIT	0x2
#define BOARD_EAGLE		0x3
#define BOARD_SALVATOR_XS	0x4
#define BOARD_CONDOR		0x6
#define BOARD_DRAAK		0x7
#define BOARD_EBISU		0x8
#define BOARD_STARTER_KIT_PRE	0xB
#define BOARD_EBISU_4D		0xD
#define BOARD_CONDOR_I		0x10

/**
 * struct sysinfo_rcar_priv - sysinfo private data
 * @boardname: board model and revision
 * @val: board ID value from eeprom
 */
struct sysinfo_rcar_priv {
	char	boardmodel[64];
	u8	val;
};

static int sysinfo_rcar_detect(struct udevice *dev)
{
	struct sysinfo_rcar_priv *priv = dev_get_priv(dev);

	return priv->val == 0xff;
}

static int sysinfo_rcar_get_str(struct udevice *dev, int id, size_t size, char *val)
{
	struct sysinfo_rcar_priv *priv = dev_get_priv(dev);

	switch (id) {
	case SYSINFO_ID_BOARD_MODEL:
		strncpy(val, priv->boardmodel, size);
		val[size - 1] = '\0';
		return 0;
	default:
		return -EINVAL;
	};
}

static const struct sysinfo_ops sysinfo_rcar_ops = {
	.detect = sysinfo_rcar_detect,
	.get_str = sysinfo_rcar_get_str,
};

static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
{
	const u8 board_id = (priv->val & BOARD_CODE_MASK) >> BOARD_CODE_SHIFT;
	const u8 board_rev = priv->val & BOARD_REV_MASK;
	bool salvator_xs = false;
	bool ebisu_4d = false;
	bool condor_i = false;
	char rev_major = '?';
	char rev_minor = '?';

	switch (board_id) {
	case BOARD_SALVATOR_XS:
		salvator_xs = true;
		fallthrough;
	case BOARD_SALVATOR_X:
		if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
			rev_major = '1';
			rev_minor = '0' + (board_rev & BIT(0));
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Salvator-X%s board rev %c.%c",
			 salvator_xs ? "S" : "", rev_major, rev_minor);
		return;
	case BOARD_STARTER_KIT:
		if (!(board_rev & ~1)) { /* Only rev 0 and 1 is valid */
			rev_major = (board_rev & BIT(0)) ? '3' : '1';
			rev_minor = '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Starter Kit board rev %c.%c",
			 rev_major, rev_minor);
		return;
	case BOARD_STARTER_KIT_PRE:
		if (!(board_rev & ~3)) { /* Only rev 0..3 is valid */
			rev_major = (board_rev & BIT(1)) ? '2' : '1';
			rev_minor = (board_rev == 3) ? '1' : '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Starter Kit Premier board rev %c.%c",
			 rev_major, rev_minor);
		return;
	case BOARD_EAGLE:
		if (!board_rev) { /* Only rev 0 is valid */
			rev_major = '1';
			rev_minor = '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Eagle board rev %c.%c",
			 rev_major, rev_minor);
		return;
	case BOARD_EBISU_4D:
		ebisu_4d = true;
		fallthrough;
	case BOARD_EBISU:
		if (!board_rev) { /* Only rev 0 is valid */
			rev_major = '1';
			rev_minor = '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Ebisu%s board rev %c.%c",
			 ebisu_4d ? "-4D" : "", rev_major, rev_minor);
		return;
	case BOARD_DRAAK:
		if (!board_rev) { /* Only rev 0 is valid */
			rev_major = '1';
			rev_minor = '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Draak board rev %c.%c",
			 rev_major, rev_minor);
		return;
	case BOARD_KRIEK:
		if (!board_rev) { /* Only rev 0 is valid */
			rev_major = '1';
			rev_minor = '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas Kriek board rev %c.%c",
			 rev_major, rev_minor);
		return;
	case BOARD_CONDOR_I:
		condor_i = true;
		fallthrough;
	case BOARD_CONDOR:
		if (!board_rev) { /* Only rev 0 is valid */
			rev_major = '1';
			rev_minor = '0';
		}
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			"Renesas Condor%s board rev %c.%c",
			condor_i ? "-I" : "", rev_major, rev_minor);
		return;
	default:
		snprintf(priv->boardmodel, sizeof(priv->boardmodel),
			 "Renesas -Unknown- board rev ?.?");
		priv->val = 0xff;
		return;
	}
}

static int sysinfo_rcar_probe(struct udevice *dev)
{
	struct sysinfo_rcar_priv *priv = dev_get_priv(dev);
	struct ofnode_phandle_args phandle_args;
	struct udevice *i2c_eeprom;
	u32 offset;
	int ret;

	offset = dev_read_u32_default(dev, "offset", 0x70);

	ret = dev_read_phandle_with_args(dev, "i2c-eeprom", NULL,
					 0, 0, &phandle_args);
	if (ret) {
		debug("%s: i2c-eeprom backing device not specified\n",
		      dev->name);
		return ret;
	}

	ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, phandle_args.node,
					  &i2c_eeprom);
	if (ret) {
		debug("%s: could not get backing device\n", dev->name);
		return ret;
	}

	ret = i2c_eeprom_read(i2c_eeprom, offset, &priv->val, 1);
	if (ret < 0) {
		debug("%s: read failed\n", __func__);
		return -EIO;
	}

	sysinfo_rcar_parse(priv);

	return 0;
}

static const struct udevice_id sysinfo_rcar_ids[] = {
	{ .compatible = "renesas,rcar-sysinfo" },
	{ /* sentinel */ }
};

U_BOOT_DRIVER(sysinfo_rcar) = {
	.name           = "sysinfo_rcar",
	.id             = UCLASS_SYSINFO,
	.of_match       = sysinfo_rcar_ids,
	.ops		= &sysinfo_rcar_ops,
	.priv_auto	= sizeof(struct sysinfo_rcar_priv),
	.probe          = sysinfo_rcar_probe,
};