coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
i2c.c
Go to the documentation of this file.
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 "chip.h"
11 
12 #if ENV_X86
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 */
20 };
21 #else
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 };
29 
30 void i2c_set_bar(unsigned int bus, uintptr_t bar)
31 {
32  if (bus >= ARRAY_SIZE(i2c_ctrlr)) {
33  printk(BIOS_ERR, "i2c index out of bounds: %u.", bus);
34  return;
35  }
36 
37  i2c_ctrlr[bus].bar = bar;
38 }
39 #endif
40 
41 void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
42 {
43  /* TODO: Picasso supports I2C RX pad configurations 3.3V, 1.8V and off, so make this
44  configurable. */
45  const struct i2c_pad_control ctrl = {
47  };
48 
49  fch_i2c_pad_init(bus, cfg->speed, &ctrl);
50 }
51 
52 const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs)
53 {
54  *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr);
55  return i2c_ctrlr;
56 }
57 
58 const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses)
59 {
61 
62  *num_buses = ARRAY_SIZE(config->i2c);
63  return config->i2c;
64 }
#define I2C_CTRLR_COUNT
Definition: iomap.h:9
#define APU_I2C3_BASE
Definition: iomap.h:17
#define APU_I2C2_BASE
Definition: iomap.h:16
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
void fch_i2c_pad_init(unsigned int bus, enum i2c_speed speed, const struct i2c_pad_control *ctrl)
Definition: i2c_pad_ctrl.c:9
#define config_of_soc()
Definition: device.h:394
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
enum board_config config
Definition: memory.c:448
void i2c_set_bar(unsigned int bus, uintptr_t bar)
Definition: i2c.c:24
const struct soc_i2c_ctrlr_info * soc_get_i2c_ctrlr_info(size_t *num_ctrlrs)
Definition: i2c.c:45
void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
Definition: i2c.c:35
const struct dw_i2c_bus_config * soc_get_i2c_bus_config(size_t *num_buses)
Definition: i2c.c:51
@ I2C_MASTER_MODE
Definition: i2c.h:13
@ I2C_PERIPHERAL_MODE
Definition: i2c.h:14
@ I2C_PAD_RX_3_3V
Definition: i2c.h:62
static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT]
Definition: i2c.c:22
unsigned long uintptr_t
Definition: stdint.h:21
Definition: device.h:76
enum i2c_speed speed
Definition: dw_i2c.h:53
enum i2c_pad_rx_level rx_level
Definition: i2c.h:68
Data structure to hold SoC I2C controller information @bar: MMIO base address for the I2C bus.
Definition: i2c.h:22
uintptr_t bar
Definition: i2c.h:24