blob: afbc8bd37952a868d9403be30ff5c6ffd017bbbb [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth5c354b92019-04-22 14:55:16 -06002
Martin Roth5c354b92019-04-22 14:55:16 -06003#include <console/console.h>
Martin Roth5c354b92019-04-22 14:55:16 -06004#include <amdblocks/acpimmio.h>
Karthikeyan Ramasubramanian0dbea482021-03-08 23:23:50 -07005#include <amdblocks/i2c.h>
Martin Roth7e78e562019-11-03 23:29:02 -07006#include <soc/i2c.h>
Martin Roth5c354b92019-04-22 14:55:16 -06007#include <soc/iomap.h>
8#include <soc/pci_devs.h>
9#include <soc/southbridge.h>
Martin Roth5c354b92019-04-22 14:55:16 -060010#include "chip.h"
11
Martin Rothac41f582020-06-14 17:24:12 -060012#if ENV_X86
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060013/* Preferably keep all the I2C controllers operating in a specific mode together. */
14static 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 */
Martin Roth5c354b92019-04-22 14:55:16 -060020};
Martin Rothac41f582020-06-14 17:24:12 -060021#else
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060022static struct soc_i2c_ctrlr_info i2c_ctrlr[I2C_CTRLR_COUNT] = {
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};
Martin Roth5c354b92019-04-22 14:55:16 -060029
Martin Rothac41f582020-06-14 17:24:12 -060030void i2c_set_bar(unsigned int bus, uintptr_t bar)
31{
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060032 if (bus >= ARRAY_SIZE(i2c_ctrlr)) {
Julius Wernere9665952022-01-21 17:06:20 -080033 printk(BIOS_ERR, "i2c index out of bounds: %u.", bus);
Martin Rothac41f582020-06-14 17:24:12 -060034 return;
35 }
36
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060037 i2c_ctrlr[bus].bar = bar;
Martin Rothac41f582020-06-14 17:24:12 -060038}
39#endif
40
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060041void soc_i2c_misc_init(unsigned int bus, const struct dw_i2c_bus_config *cfg)
Martin Roth5c354b92019-04-22 14:55:16 -060042{
Felix Held556d1cc2022-02-02 22:11:52 +010043 /* 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 = {
46 .rx_level = I2C_PAD_RX_3_3V,
47 };
Martin Roth5c354b92019-04-22 14:55:16 -060048
Felix Held556d1cc2022-02-02 22:11:52 +010049 fch_i2c_pad_init(bus, cfg->speed, &ctrl);
Martin Roth5c354b92019-04-22 14:55:16 -060050}
51
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060052const struct soc_i2c_ctrlr_info *soc_get_i2c_ctrlr_info(size_t *num_ctrlrs)
Martin Roth5c354b92019-04-22 14:55:16 -060053{
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060054 *num_ctrlrs = ARRAY_SIZE(i2c_ctrlr);
55 return i2c_ctrlr;
Martin Roth5c354b92019-04-22 14:55:16 -060056}
57
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060058const struct dw_i2c_bus_config *soc_get_i2c_bus_config(size_t *num_buses)
Martin Roth5c354b92019-04-22 14:55:16 -060059{
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060060 const struct soc_amd_picasso_config *config = config_of_soc();
Martin Roth5c354b92019-04-22 14:55:16 -060061
Karthikeyan Ramasubramanian4f87ae12021-03-18 23:16:29 -060062 *num_buses = ARRAY_SIZE(config->i2c);
63 return config->i2c;
64}