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 | |
Fred Reitberger | 1383122 | 2022-10-17 11:49:55 -0400 | [diff] [blame] | 12 | /* Table to switch SCL pins to outputs to initially reset the I2C peripherals */ |
| 13 | static const struct soc_i2c_scl_pin i2c_scl_pins[] = { |
| 14 | I2C_RESET_SCL_PIN(I2C2_SCL_PIN, GPIO_I2C2_SCL), |
| 15 | I2C_RESET_SCL_PIN(I2C3_SCL_PIN, GPIO_I2C3_SCL), |
| 16 | /* I2C4 is a peripheral device only */ |
| 17 | }; |
| 18 | |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 19 | #if ENV_X86 |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 20 | /* Preferably keep all the I2C controllers operating in a specific mode together. */ |
| 21 | static const struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
| 22 | { I2C_MASTER_MODE, 0, "" }, |
| 23 | { I2C_MASTER_MODE, 0, "" }, |
| 24 | { I2C_MASTER_MODE, APU_I2C2_BASE, "I2C2" }, |
| 25 | { I2C_MASTER_MODE, APU_I2C3_BASE, "I2C3" }, |
| 26 | { 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] | 27 | }; |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 28 | #else |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 29 | static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
| 30 | { I2C_MASTER_MODE, 0, ""}, |
| 31 | { I2C_MASTER_MODE, 0, "" }, |
| 32 | { I2C_MASTER_MODE, 0, "" }, |
| 33 | { I2C_MASTER_MODE, 0, "" }, |
| 34 | { I2C_PERIPHERAL_MODE, 0, "" }, |
| 35 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 36 | |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 37 | void i2c_set_bar(unsigned int bus, uintptr_t bar) |
| 38 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 39 | if (bus >= ARRAY_SIZE(i2c_ctrlr)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 40 | printk(BIOS_ERR, "i2c index out of bounds: %u.", bus); |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 41 | return; |
| 42 | } |
| 43 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 44 | i2c_ctrlr[bus].bar = bar; |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 45 | } |
| 46 | #endif |
| 47 | |
Fred Reitberger | 1383122 | 2022-10-17 11:49:55 -0400 | [diff] [blame] | 48 | void reset_i2c_peripherals(void) |
| 49 | { |
| 50 | const struct soc_amd_picasso_config *cfg = config_of_soc(); |
| 51 | struct soc_i2c_peripheral_reset_info reset_info; |
| 52 | |
| 53 | reset_info.i2c_scl_reset_mask = cfg->i2c_scl_reset & GPIO_I2C_MASK; |
| 54 | reset_info.i2c_scl = i2c_scl_pins; |
| 55 | reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins); |
| 56 | sb_reset_i2c_peripherals(&reset_info); |
| 57 | } |
| 58 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 59 | 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] | 60 | { |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 61 | /* TODO: Picasso supports I2C RX pad configurations 3.3V, 1.8V and off, so make this |
| 62 | configurable. */ |
| 63 | const struct i2c_pad_control ctrl = { |
| 64 | .rx_level = I2C_PAD_RX_3_3V, |
| 65 | }; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 66 | |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 67 | fch_i2c_pad_init(bus, cfg->speed, &ctrl); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 68 | } |
| 69 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 70 | 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] | 71 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 72 | *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr); |
| 73 | return i2c_ctrlr; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 74 | } |
| 75 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 76 | 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] | 77 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 78 | const struct soc_amd_picasso_config *config = config_of_soc(); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 79 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 80 | *num_buses = ARRAY_SIZE(config->i2c); |
| 81 | return config->i2c; |
| 82 | } |