Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 3 | |
| 4 | #include <types.h> |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/smbus.h> |
| 7 | #include <smbios.h> |
| 8 | #include <console/console.h> |
| 9 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 10 | static void at24rf08c_init(struct device *dev) |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 11 | { |
| 12 | int i, j; |
| 13 | |
| 14 | if (!dev->enabled) |
| 15 | return; |
| 16 | |
Elyes HAOUAS | 88607a4 | 2018-10-05 10:36:45 +0200 | [diff] [blame] | 17 | /* Ensure that EEPROM/RFID chip is not accessible through RFID. |
Paul Menzel | 2a6140e | 2020-01-14 01:16:37 +0100 | [diff] [blame] | 18 | Need to do it only on 5c. */ |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 19 | if (dev->path.type != DEVICE_PATH_I2C || dev->path.i2c.device != 0x5c) |
| 20 | return; |
| 21 | |
Paul Menzel | d778b3b | 2020-01-14 01:21:06 +0100 | [diff] [blame] | 22 | printk(BIOS_DEBUG, "Locking EEPROM RFID\n"); |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 23 | |
Paul Menzel | d778b3b | 2020-01-14 01:21:06 +0100 | [diff] [blame] | 24 | for (i = 0; i < 8; i++) { |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 25 | /* After a register write AT24RF08C sometimes stops responding. |
Paul Menzel | 2a6140e | 2020-01-14 01:16:37 +0100 | [diff] [blame] | 26 | Retry several times in case of failure. */ |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 27 | for (j = 0; j < 100; j++) |
| 28 | if (smbus_write_byte(dev, i, 0x0f) >= 0) |
| 29 | break; |
| 30 | } |
| 31 | |
Paul Menzel | d778b3b | 2020-01-14 01:21:06 +0100 | [diff] [blame] | 32 | printk(BIOS_DEBUG, "init EEPROM done\n"); |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 33 | } |
| 34 | |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 35 | static struct device_operations at24rf08c_operations = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame^] | 36 | .read_resources = noop_read_resources, |
| 37 | .set_resources = noop_set_resources, |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 38 | .init = at24rf08c_init, |
| 39 | }; |
| 40 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 41 | static void enable_dev(struct device *dev) |
Vladimir Serbinenko | 62adc4c | 2014-01-23 09:06:08 +0100 | [diff] [blame] | 42 | { |
| 43 | dev->ops = &at24rf08c_operations; |
| 44 | } |
| 45 | |
| 46 | struct chip_operations drivers_i2c_at24rf08c_ops = { |
| 47 | CHIP_NAME("AT24RF08C") |
| 48 | .enable_dev = enable_dev, |
| 49 | }; |