• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/device.h>
4 #include <device/smbus.h>
5 #include <console/console.h>
6 
at24rf08c_init(struct device * dev)7 static void at24rf08c_init(struct device *dev)
8 {
9 	int i, j;
10 
11 	if (!dev->enabled)
12 		return;
13 
14 	/* Ensure that EEPROM/RFID chip is not accessible through RFID.
15 	   Need to do it only on 5c. */
16 	if (dev->path.type != DEVICE_PATH_I2C || dev->path.i2c.device != 0x5c)
17 		return;
18 
19 	printk(BIOS_DEBUG, "Locking EEPROM RFID\n");
20 
21 	for (i = 0; i < 8; i++) {
22 		/* After a register write AT24RF08C sometimes stops responding.
23 		   Retry several times in case of failure. */
24 		for (j = 0; j < 100; j++)
25 			if (smbus_write_byte(dev, i, 0x0f) >= 0)
26 				break;
27 	}
28 
29 	printk(BIOS_DEBUG, "init EEPROM done\n");
30 }
31 
32 static struct device_operations at24rf08c_operations = {
33 	.read_resources = noop_read_resources,
34 	.set_resources = noop_set_resources,
35 	.init = at24rf08c_init,
36 };
37 
enable_dev(struct device * dev)38 static void enable_dev(struct device *dev)
39 {
40 	dev->ops = &at24rf08c_operations;
41 }
42 
43 struct chip_operations drivers_i2c_at24rf08c_ops = {
44 	.name = "AT24RF08C",
45 	.enable_dev = enable_dev,
46 };
47