1 /* SPDX-License-Identifier: GPL-2.0-only */
6 #include <device/device.h>
7 #include <device/smbus.h>
9 #include <console/console.h>
13 #define ERROR_STRING "*INVALID*"
15 static struct device
*at24rf08c_find_bank(u8 bank
)
18 dev
= dev_find_slot_on_smbus(1, 0x54 | bank
);
20 printk(BIOS_WARNING
, "EEPROM not found\n");
24 static int at24rf08c_read_byte(struct device
*dev
, u8 addr
)
29 /* After a register write AT24RF08C (which we issued in init function)
30 sometimes stops responding. Retry several times in case of failure.
32 for (j
= 0; j
< 100; j
++) {
33 t
= smbus_read_byte(dev
, addr
);
41 static void at24rf08c_read_string_dev(struct device
*dev
, u8 start
,
45 for (i
= 0; i
< len
; i
++) {
46 int t
= at24rf08c_read_byte(dev
, start
+ i
);
48 if (t
< 0x20 || t
> 0x7f) {
49 memcpy(result
, ERROR_STRING
, sizeof(ERROR_STRING
));
57 static void at24rf08c_read_string(u8 bank
, u8 start
, u8 len
, char *result
)
61 dev
= at24rf08c_find_bank(bank
);
63 printk(BIOS_WARNING
, "EEPROM not found\n");
64 memcpy(result
, ERROR_STRING
, sizeof(ERROR_STRING
));
68 at24rf08c_read_string_dev(dev
, start
, len
, result
);
71 const char *smbios_mainboard_serial_number(void)
73 static char result
[12];
74 static int already_read
;
79 memset(result
, 0, sizeof(result
));
80 at24rf08c_read_string(0, 0x2e, 7, result
);
86 const char *lenovo_mainboard_partnumber(void)
88 static char result
[12];
89 static int already_read
;
94 memset(result
, 0, sizeof(result
));
95 at24rf08c_read_string(0, 0x27, 7, result
);
101 const char *smbios_mainboard_product_name(void)
103 return lenovo_mainboard_partnumber();
106 void smbios_system_set_uuid(u8
*uuid
)
108 static char result
[16];
110 static int already_read
;
112 const int remap
[16] = {
114 3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15
118 memcpy(uuid
, result
, 16);
122 memset(result
, 0, sizeof(result
));
124 dev
= dev_find_slot_on_smbus(1, 0x56);
126 printk(BIOS_WARNING
, "EEPROM not found\n");
132 for (i
= 0; i
< 16; i
++) {
135 /* After a register write AT24RF08C (which we issued in init function) sometimes stops responding.
136 Retry several times in case of failure.
138 for (j
= 0; j
< 100; j
++) {
139 t
= smbus_read_byte(dev
, 0x12 + i
);
144 memset(result
, 0, sizeof(result
));
147 result
[remap
[i
]] = t
;
152 memcpy(uuid
, result
, 16);
155 const char *smbios_mainboard_version(void)
157 static char result
[100];
158 static int already_read
;
165 memset(result
, 0, sizeof(result
));
167 dev
= at24rf08c_find_bank(2);
169 memcpy(result
, ERROR_STRING
, sizeof(ERROR_STRING
));
173 len
= at24rf08c_read_byte(dev
, 0x26) - 2;
174 if (len
< 0 || len
> sizeof(result
) - 1) {
175 memcpy(result
, ERROR_STRING
, sizeof(ERROR_STRING
));
179 at24rf08c_read_string_dev(dev
, 0x27, len
, result
);
185 const char *smbios_mainboard_bios_version(void)
187 /* Satisfy thinkpad_acpi. */
188 if (strlen(CONFIG_LOCALVERSION
))
189 return "CBET4000 " CONFIG_LOCALVERSION
;
191 return "CBET4000 " COREBOOT_VERSION
;
194 const char *smbios_mainboard_manufacturer(void)