Debian Codegraph @

src/soc/amd/glinda/i2c.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 /* TODO: Update for Glinda */
4
5 #include <amdblocks/i2c.h>
6 #include <console/console.h>
7 #include <soc/i2c.h>
8 #include <soc/iomap.h>
9 #include <soc/southbridge.h>
10 #include <static.h>
11 #include "chip.h"
12
13 /* Table to switch SCL pins to outputs to initially reset the I2C peripherals */
14 static const struct soc_i2c_scl_pin i2c_scl_pins[] = {
15 I2C_RESET_SCL_PIN(I2C0_SCL_PIN, GPIO_I2C0_SCL),
16 I2C_RESET_SCL_PIN(I2C1_SCL_PIN, GPIO_I2C1_SCL),
17 I2C_RESET_SCL_PIN(I2C2_SCL_PIN, GPIO_I2C2_SCL),
18 I2C_RESET_SCL_PIN(I2C3_SCL_PIN, GPIO_I2C3_SCL),
19 };
20
21 #if ENV_X86
22 static const struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = {
23 { I2C_MASTER_MODE, APU_I2C0_BASE, "I2C0" },
24 { I2C_MASTER_MODE, APU_I2C1_BASE, "I2C1" },
25 { I2C_MASTER_MODE, APU_I2C2_BASE, "I2C2" },
26 { I2C_MASTER_MODE, APU_I2C3_BASE, "I2C3" }
27 };
28 #else
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 };
35
36 void i2c_set_bar(unsigned int bus, uintptr_t bar)
37 {
38 if (bus >= ARRAY_SIZE(i2c_ctrlr)) {
39 printk(BIOS_ERR, "i2c index out of bounds: %u.", bus);
40 return;
41 }
42
43 i2c_ctrlr[bus].bar = bar;
44 }
45 #endif
46
47 void reset_i2c_peripherals(void)
48 {
49 const struct soc_amd_glinda_config *cfg = config_of_soc();
50 struct soc_i2c_peripheral_reset_info reset_info;
51
52 reset_info.i2c_scl_reset_mask = cfg->i2c_scl_reset & GPIO_I2C_MASK;
53 reset_info.i2c_scl = i2c_scl_pins;
54 reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins);
55 sb_reset_i2c_peripherals(&reset_info);
56 }
57
58 void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
59 {
60 const struct soc_amd_glinda_config *config = config_of_soc();
61
62 if (bus >= ARRAY_SIZE(config->i2c_pad))
63 return;
64
65 fch_i23c_pad_init(bus, cfg->speed, &config->i2c_pad[bus]);
66 }
67
68 const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs)
69 {
70 *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr);
71 return i2c_ctrlr;
72 }
73
74 const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses)
75 {
76 const struct soc_amd_glinda_config *config = config_of_soc();
77
78 *num_buses = ARRAY_SIZE(config->i2c);
79 return config->i2c;
80 }