blob: 3511502b76c17cfc5f7ef1af4c398eb13b92c0e4 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +01003
4#include <types.h>
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +01005#include <device/device.h>
6#include <device/smbus.h>
7#include <smbios.h>
8#include <console/console.h>
9
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110010static void at24rf08c_init(struct device *dev)
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010011{
12 int i, j;
13
14 if (!dev->enabled)
15 return;
16
Elyes HAOUAS88607a42018-10-05 10:36:45 +020017 /* Ensure that EEPROM/RFID chip is not accessible through RFID.
Paul Menzel2a6140e2020-01-14 01:16:37 +010018 Need to do it only on 5c. */
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010019 if (dev->path.type != DEVICE_PATH_I2C || dev->path.i2c.device != 0x5c)
20 return;
21
Paul Menzeld778b3b2020-01-14 01:21:06 +010022 printk(BIOS_DEBUG, "Locking EEPROM RFID\n");
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010023
Paul Menzeld778b3b2020-01-14 01:21:06 +010024 for (i = 0; i < 8; i++) {
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010025 /* After a register write AT24RF08C sometimes stops responding.
Paul Menzel2a6140e2020-01-14 01:16:37 +010026 Retry several times in case of failure. */
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010027 for (j = 0; j < 100; j++)
28 if (smbus_write_byte(dev, i, 0x0f) >= 0)
29 break;
30 }
31
Paul Menzeld778b3b2020-01-14 01:21:06 +010032 printk(BIOS_DEBUG, "init EEPROM done\n");
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010033}
34
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010035static struct device_operations at24rf08c_operations = {
Nico Huber2f8ba692020-04-05 14:05:24 +020036 .read_resources = noop_read_resources,
37 .set_resources = noop_set_resources,
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010038 .init = at24rf08c_init,
39};
40
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110041static void enable_dev(struct device *dev)
Vladimir Serbinenko62adc4c2014-01-23 09:06:08 +010042{
43 dev->ops = &at24rf08c_operations;
44}
45
46struct chip_operations drivers_i2c_at24rf08c_ops = {
47 CHIP_NAME("AT24RF08C")
48 .enable_dev = enable_dev,
49};