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 <amdblocks/i2c.h>
4 #include <console/console.h>
5 #include <soc/i2c.h>
6 #include <soc/southbridge.h>
7 #include "chip.h"
8 
9 #if ENV_X86
10 static 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
18  { I2C_MASTER_MODE, 0, "" },
19  { I2C_MASTER_MODE, 0, "" },
20  { I2C_MASTER_MODE, 0, "" },
21  { I2C_MASTER_MODE, 0, "" }
22 };
23 
24 void i2c_set_bar(unsigned int bus, uintptr_t bar)
25 {
26  if (bus >= ARRAY_SIZE(i2c_ctrlr)) {
27  printk(BIOS_ERR, "Error: i2c index out of bounds: %u.", bus);
28  return;
29  }
30 
31  i2c_ctrlr[bus].bar = bar;
32 }
33 #endif
34 
35 void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
36 {
38 
39  if (bus >= ARRAY_SIZE(config->i2c_pad))
40  return;
41 
42  fch_i23c_pad_init(bus, cfg->speed, &config->i2c_pad[bus]);
43 }
44 
45 const 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 
51 const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses)
52 {
54 
55  *num_buses = ARRAY_SIZE(config->i2c);
56  return config->i2c;
57 }
#define I2C_CTRLR_COUNT
Definition: iomap.h:9
#define APU_I2C0_BASE
Definition: iomap.h:14
#define APU_I2C3_BASE
Definition: iomap.h:17
#define APU_I2C2_BASE
Definition: iomap.h:16
#define APU_I2C1_BASE
Definition: iomap.h:15
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
void fch_i23c_pad_init(unsigned int bus, enum i2c_speed speed, const struct i2c_pad_control *ctrl)
Definition: i23c_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
static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT]
Definition: i2c.c:17
unsigned long uintptr_t
Definition: stdint.h:21
Definition: device.h:76
enum i2c_speed speed
Definition: dw_i2c.h:53
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