blob: ae49a064e05863bdbfbc6054847ad8817f7ada76 [file] [log] [blame]
Zheng Baob0f00ed2021-03-16 15:28:49 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
Zheng Baob0f00ed2021-03-16 15:28:49 +08003#include <amdblocks/i2c.h>
Kangheui Won62047e52021-04-15 17:34:09 +10004#include <console/console.h>
Zheng Baob0f00ed2021-03-16 15:28:49 +08005#include <soc/i2c.h>
6#include <soc/southbridge.h>
7#include "chip.h"
8
9#if ENV_X86
10static 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 Won62047e52021-04-15 17:34:09 +100017static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = {
Zheng Baob0f00ed2021-03-16 15:28:49 +080018 { I2C_MASTER_MODE, 0, "" },
19 { I2C_MASTER_MODE, 0, "" },
20 { I2C_MASTER_MODE, 0, "" },
21 { I2C_MASTER_MODE, 0, "" }
22};
23
24void i2c_set_bar(unsigned int bus, uintptr_t bar)
25{
26 if (bus >= ARRAY_SIZE(i2c_ctrlr)) {
Julius Wernere9665952022-01-21 17:06:20 -080027 printk(BIOS_ERR, "i2c index out of bounds: %u.", bus);
Zheng Baob0f00ed2021-03-16 15:28:49 +080028 return;
29 }
30
31 i2c_ctrlr[bus].bar = bar;
32}
33#endif
34
Zheng Baob0f00ed2021-03-16 15:28:49 +080035void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
36{
Karthikeyan Ramasubramanianfec4db92021-06-02 16:14:39 -060037 const struct soc_amd_cezanne_config *config = config_of_soc();
Zheng Baob0f00ed2021-03-16 15:28:49 +080038
Felix Held556d1cc2022-02-02 22:11:52 +010039 if (bus >= ARRAY_SIZE(config->i2c_pad))
Karthikeyan Ramasubramanianfec4db92021-06-02 16:14:39 -060040 return;
41
Felix Held556d1cc2022-02-02 22:11:52 +010042 fch_i2c_pad_init(bus, cfg->speed, &config->i2c_pad[bus]);
Zheng Baob0f00ed2021-03-16 15:28:49 +080043}
44
45const 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
51const 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}