Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 3 | #include <amdblocks/i2c.h> |
Kangheui Won | 62047e5 | 2021-04-15 17:34:09 +1000 | [diff] [blame] | 4 | #include <console/console.h> |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 5 | #include <soc/i2c.h> |
| 6 | #include <soc/southbridge.h> |
| 7 | #include "chip.h" |
| 8 | |
Fred Reitberger | 1383122 | 2022-10-17 11:49:55 -0400 | [diff] [blame] | 9 | /* Table to switch SCL pins to outputs to initially reset the I2C peripherals */ |
| 10 | static const struct soc_i2c_scl_pin i2c_scl_pins[] = { |
| 11 | I2C_RESET_SCL_PIN(I2C0_SCL_PIN, GPIO_I2C0_SCL), |
| 12 | I2C_RESET_SCL_PIN(I2C1_SCL_PIN, GPIO_I2C1_SCL), |
| 13 | I2C_RESET_SCL_PIN(I2C2_SCL_PIN, GPIO_I2C2_SCL), |
| 14 | I2C_RESET_SCL_PIN(I2C3_SCL_PIN, GPIO_I2C3_SCL), |
| 15 | }; |
| 16 | |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 17 | #if ENV_X86 |
| 18 | static const struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
| 19 | { I2C_MASTER_MODE, APU_I2C0_BASE, "I2C0" }, |
| 20 | { I2C_MASTER_MODE, APU_I2C1_BASE, "I2C1" }, |
| 21 | { I2C_MASTER_MODE, APU_I2C2_BASE, "I2C2" }, |
| 22 | { I2C_MASTER_MODE, APU_I2C3_BASE, "I2C3" } |
| 23 | }; |
| 24 | #else |
Kangheui Won | 62047e5 | 2021-04-15 17:34:09 +1000 | [diff] [blame] | 25 | static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 26 | { I2C_MASTER_MODE, 0, "" }, |
| 27 | { I2C_MASTER_MODE, 0, "" }, |
| 28 | { I2C_MASTER_MODE, 0, "" }, |
| 29 | { I2C_MASTER_MODE, 0, "" } |
| 30 | }; |
| 31 | |
| 32 | void i2c_set_bar(unsigned int bus, uintptr_t bar) |
| 33 | { |
| 34 | if (bus >= ARRAY_SIZE(i2c_ctrlr)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 35 | printk(BIOS_ERR, "i2c index out of bounds: %u.", bus); |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 36 | return; |
| 37 | } |
| 38 | |
| 39 | i2c_ctrlr[bus].bar = bar; |
| 40 | } |
| 41 | #endif |
| 42 | |
Fred Reitberger | 1383122 | 2022-10-17 11:49:55 -0400 | [diff] [blame] | 43 | void reset_i2c_peripherals(void) |
| 44 | { |
| 45 | const struct soc_amd_cezanne_config *cfg = config_of_soc(); |
| 46 | struct soc_i2c_peripheral_reset_info reset_info; |
| 47 | |
| 48 | reset_info.i2c_scl_reset_mask = cfg->i2c_scl_reset & GPIO_I2C_MASK; |
| 49 | reset_info.i2c_scl = i2c_scl_pins; |
| 50 | reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins); |
| 51 | sb_reset_i2c_peripherals(&reset_info); |
| 52 | } |
| 53 | |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 54 | void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg) |
| 55 | { |
Karthikeyan Ramasubramanian | fec4db9 | 2021-06-02 16:14:39 -0600 | [diff] [blame] | 56 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 57 | |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 58 | if (bus >= ARRAY_SIZE(config->i2c_pad)) |
Karthikeyan Ramasubramanian | fec4db9 | 2021-06-02 16:14:39 -0600 | [diff] [blame] | 59 | return; |
| 60 | |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 61 | fch_i2c_pad_init(bus, cfg->speed, &config->i2c_pad[bus]); |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs) |
| 65 | { |
| 66 | *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr); |
| 67 | return i2c_ctrlr; |
| 68 | } |
| 69 | |
| 70 | const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses) |
| 71 | { |
| 72 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
| 73 | |
| 74 | *num_buses = ARRAY_SIZE(config->i2c); |
| 75 | return config->i2c; |
| 76 | } |