lenovo: Handle EEPROM/RFID chip.
[coreboot.git] / src / drivers / i2c / at24rf08c / at24rf08c.c
bloba9cf2c50317337f34ed8464b8234a17809b69ffa
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2013 Vladimir Serbinenko
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <types.h>
21 #include <string.h>
22 #include <arch/io.h>
23 #include <device/device.h>
24 #include <device/smbus.h>
25 #include <smbios.h>
26 #include <console/console.h>
28 static void at24rf08c_init(device_t dev)
30 int i, j;
32 if (!dev->enabled)
33 return;
35 /* Ensure that EEPROM/RFID chip is not accessible through RFID.
36 Need to do it only on 5c. */
37 if (dev->path.type != DEVICE_PATH_I2C || dev->path.i2c.device != 0x5c)
38 return;
40 printk (BIOS_DEBUG, "Locking EEPROM RFID\n");
42 for (i = 0; i < 8; i++)
44 /* After a register write AT24RF08C sometimes stops responding.
45 Retry several times in case of failure.
47 for (j = 0; j < 100; j++)
48 if (smbus_write_byte(dev, i, 0x0f) >= 0)
49 break;
52 printk (BIOS_DEBUG, "init EEPROM done\n");
55 static void at24rf08c_noop(device_t dummy)
59 static struct device_operations at24rf08c_operations = {
60 .read_resources = at24rf08c_noop,
61 .set_resources = at24rf08c_noop,
62 .enable_resources = at24rf08c_noop,
63 .init = at24rf08c_init,
66 static void enable_dev(device_t dev)
68 dev->ops = &at24rf08c_operations;
71 struct chip_operations drivers_i2c_at24rf08c_ops = {
72 CHIP_NAME("AT24RF08C")
73 .enable_dev = enable_dev,