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 | |
| 9 | #if ENV_X86 |
| 10 | static const struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
| 11 | { I2C_MASTER_MODE, APU_I2C0_BASE, "I2C0" }, |
| 12 | { I2C_MASTER_MODE, APU_I2C1_BASE, "I2C1" }, |
| 13 | { I2C_MASTER_MODE, APU_I2C2_BASE, "I2C2" }, |
| 14 | { I2C_MASTER_MODE, APU_I2C3_BASE, "I2C3" } |
| 15 | }; |
| 16 | #else |
Kangheui Won | 62047e5 | 2021-04-15 17:34:09 +1000 | [diff] [blame] | 17 | static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = { |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 18 | { I2C_MASTER_MODE, 0, "" }, |
| 19 | { I2C_MASTER_MODE, 0, "" }, |
| 20 | { I2C_MASTER_MODE, 0, "" }, |
| 21 | { I2C_MASTER_MODE, 0, "" } |
| 22 | }; |
| 23 | |
| 24 | void i2c_set_bar(unsigned int bus, uintptr_t bar) |
| 25 | { |
| 26 | if (bus >= ARRAY_SIZE(i2c_ctrlr)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame^] | 27 | printk(BIOS_ERR, "i2c index out of bounds: %u.", bus); |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 28 | return; |
| 29 | } |
| 30 | |
| 31 | i2c_ctrlr[bus].bar = bar; |
| 32 | } |
| 33 | #endif |
| 34 | |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 35 | void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg) |
| 36 | { |
Karthikeyan Ramasubramanian | fec4db9 | 2021-06-02 16:14:39 -0600 | [diff] [blame] | 37 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 38 | |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 39 | if (bus >= ARRAY_SIZE(config->i2c_pad)) |
Karthikeyan Ramasubramanian | fec4db9 | 2021-06-02 16:14:39 -0600 | [diff] [blame] | 40 | return; |
| 41 | |
Felix Held | 556d1cc | 2022-02-02 22:11:52 +0100 | [diff] [blame] | 42 | fch_i2c_pad_init(bus, cfg->speed, &config->i2c_pad[bus]); |
Zheng Bao | b0f00ed | 2021-03-16 15:28:49 +0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs) |
| 46 | { |
| 47 | *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr); |
| 48 | return i2c_ctrlr; |
| 49 | } |
| 50 | |
| 51 | const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses) |
| 52 | { |
| 53 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
| 54 | |
| 55 | *num_buses = ARRAY_SIZE(config->i2c); |
| 56 | return config->i2c; |
| 57 | } |