Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 2 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 3 | #include <console/console.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 4 | #include <amdblocks/acpimmio.h> |
Karthikeyan Ramasubramanian | 0dbea48 | 2021-03-08 23:23:50 -0700 | [diff] [blame] | 5 | #include <amdblocks/i2c.h> |
Martin Roth | 7e78e56 | 2019-11-03 23:29:02 -0700 | [diff] [blame] | 6 | #include <soc/i2c.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 7 | #include <soc/iomap.h> |
| 8 | #include <soc/pci_devs.h> |
| 9 | #include <soc/southbridge.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 10 | #include "chip.h" |
| 11 | |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 12 | #if ENV_X86 |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 13 | /* Preferably keep all the I2C controllers operating in a specific mode together. */ |
| 14 | static const struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
| 15 | { I2C_MASTER_MODE, 0, "" }, |
| 16 | { I2C_MASTER_MODE, 0, "" }, |
| 17 | { I2C_MASTER_MODE, APU_I2C2_BASE, "I2C2" }, |
| 18 | { I2C_MASTER_MODE, APU_I2C3_BASE, "I2C3" }, |
| 19 | { I2C_PERIPHERAL_MODE, APU_I2C4_BASE, "I2C4" } /* Can only be used in peripheral mode */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 20 | }; |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 21 | #else |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 22 | static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
| 23 | { I2C_MASTER_MODE, 0, ""}, |
| 24 | { I2C_MASTER_MODE, 0, "" }, |
| 25 | { I2C_MASTER_MODE, 0, "" }, |
| 26 | { I2C_MASTER_MODE, 0, "" }, |
| 27 | { I2C_PERIPHERAL_MODE, 0, "" }, |
| 28 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 29 | |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 30 | void i2c_set_bar(unsigned int bus, uintptr_t bar) |
| 31 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 32 | if (bus >= ARRAY_SIZE(i2c_ctrlr)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame^] | 33 | printk(BIOS_ERR, "i2c index out of bounds: %u.", bus); |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 34 | return; |
| 35 | } |
| 36 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 37 | i2c_ctrlr[bus].bar = bar; |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 38 | } |
| 39 | #endif |
| 40 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 41 | void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 42 | { |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 43 | /* TODO: Picasso supports I2C RX pad configurations 3.3V, 1.8V and off, so make this |
| 44 | configurable. */ |
| 45 | const struct i2c_pad_control ctrl = { |
| 46 | .rx_level = I2C_PAD_RX_3_3V, |
| 47 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 48 | |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 49 | fch_i2c_pad_init(bus, cfg->speed, &ctrl); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 50 | } |
| 51 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 52 | const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 53 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 54 | *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr); |
| 55 | return i2c_ctrlr; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 56 | } |
| 57 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 58 | const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 59 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 60 | const struct soc_amd_picasso_config *config = config_of_soc(); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 61 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 62 | *num_buses = ARRAY_SIZE(config->i2c); |
| 63 | return config->i2c; |
| 64 | } |