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)) { |
Martin Roth | ac41f58 | 2020-06-14 17:24:12 -0600 | [diff] [blame] | 33 | printk(BIOS_ERR, "Error: i2c index out of bounds: %u.", bus); |
| 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 | |
Marshall Dawson | e2c24f7 | 2019-06-20 08:47:58 -0600 | [diff] [blame] | 41 | __weak void mainboard_i2c_override(int bus, uint32_t *pad_settings) { } |
| 42 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 43 | 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] | 44 | { |
Marshall Dawson | e2c24f7 | 2019-06-20 08:47:58 -0600 | [diff] [blame] | 45 | uint32_t pad_ctrl; |
| 46 | int misc_reg; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 47 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 48 | misc_reg = MISC_I2C0_PAD_CTRL + sizeof(uint32_t) * bus; |
| 49 | pad_ctrl = misc_read32(misc_reg); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 50 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 51 | pad_ctrl &= ~I2C_PAD_CTRL_NG_MASK; |
| 52 | pad_ctrl |= I2C_PAD_CTRL_NG_NORMAL; |
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 | pad_ctrl &= ~I2C_PAD_CTRL_RX_SEL_MASK; |
| 55 | pad_ctrl |= I2C_PAD_CTRL_RX_SEL_3_3V; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 56 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 57 | pad_ctrl &= ~I2C_PAD_CTRL_FALLSLEW_MASK; |
Zheng Bao | 7a0b9c5 | 2021-03-19 17:31:32 +0800 | [diff] [blame] | 58 | pad_ctrl |= cfg->speed == I2C_SPEED_STANDARD ? |
| 59 | I2C_PAD_CTRL_FALLSLEW_STD : I2C_PAD_CTRL_FALLSLEW_LOW; |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 60 | pad_ctrl |= I2C_PAD_CTRL_FALLSLEW_EN; |
Marshall Dawson | e2c24f7 | 2019-06-20 08:47:58 -0600 | [diff] [blame] | 61 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 62 | mainboard_i2c_override(bus, &pad_ctrl); |
| 63 | misc_write32(misc_reg, pad_ctrl); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 66 | 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] | 67 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 68 | *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr); |
| 69 | return i2c_ctrlr; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 70 | } |
| 71 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 72 | 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] | 73 | { |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 74 | const struct soc_amd_picasso_config *config = config_of_soc(); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 75 | |
Karthikeyan Ramasubramanian | 4f87ae1 | 2021-03-18 23:16:29 -0600 | [diff] [blame] | 76 | *num_buses = ARRAY_SIZE(config->i2c); |
| 77 | return config->i2c; |
| 78 | } |