Debian Codegraph @

src/soc/amd/picasso/i2c.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <amdblocks/acpimmio.h>
5 #include <amdblocks/i2c.h>
6 #include <soc/i2c.h>
7 #include <soc/iomap.h>
8 #include <soc/pci_devs.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(I2C2_SCL_PIN, GPIO_I2C2_SCL),
16 I2C_RESET_SCL_PIN(I2C3_SCL_PIN, GPIO_I2C3_SCL),
17 /* I2C4 is a peripheral device only */
18 };
19
20 #if ENV_X86
21 /* Preferably keep all the I2C controllers operating in a specific mode together. */
22 static const struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = {
23 { I2C_MASTER_MODE, 0, "" },
24 { I2C_MASTER_MODE, 0, "" },
25 { I2C_MASTER_MODE, APU_I2C2_BASE, "I2C2" },
26 { I2C_MASTER_MODE, APU_I2C3_BASE, "I2C3" },
27 { I2C_PERIPHERAL_MODE, APU_I2C4_BASE, "I2C4" } /* Can only be used in peripheral mode */
28 };
29 #else
30 static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = {
31 { I2C_MASTER_MODE, 0, ""},
32 { I2C_MASTER_MODE, 0, "" },
33 { I2C_MASTER_MODE, 0, "" },
34 { I2C_MASTER_MODE, 0, "" },
35 { I2C_PERIPHERAL_MODE, 0, "" },
36 };
37
38 void i2c_set_bar(unsigned int bus, uintptr_t bar)
39 {
40 if (bus >= ARRAY_SIZE(i2c_ctrlr)) {
41 printk(BIOS_ERR, "i2c index out of bounds: %u.", bus);
42 return;
43 }
44
45 i2c_ctrlr[bus].bar = bar;
46 }
47 #endif
48
49 void reset_i2c_peripherals(void)
50 {
51 const struct soc_amd_picasso_config *cfg = config_of_soc();
52 struct soc_i2c_peripheral_reset_info reset_info;
53
54 reset_info.i2c_scl_reset_mask = cfg->i2c_scl_reset & GPIO_I2C_MASK;
55 reset_info.i2c_scl = i2c_scl_pins;
56 reset_info.num_pins = ARRAY_SIZE(i2c_scl_pins);
57 sb_reset_i2c_peripherals(&reset_info);
58 }
59
60 void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
61 {
62 /* TODO: Picasso supports I2C RX pad configurations 3.3V, 1.8V and off, so make this
63 configurable. */
64 const struct i2c_pad_control ctrl = {
65 .rx_level = I2C_PAD_RX_3_3V,
66 };
67
68 fch_i2c_pad_init(bus, cfg->speed, &ctrl);
69 }
70
71 const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs)
72 {
73 *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr);
74 return i2c_ctrlr;
75 }
76
77 const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses)
78 {
79 const struct soc_amd_picasso_config *config = config_of_soc();
80
81 *num_buses = ARRAY_SIZE(config->i2c);
82 return config->i2c;
83 }