coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mainboard.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <arch/mmu.h>
5 #include <bootmode.h>
6 #include <boot/coreboot_tables.h>
7 #include <delay.h>
8 #include <device/device.h>
9 #include <device/i2c_simple.h>
10 #include <soc/addressmap.h>
11 #include <soc/clk_rst.h>
12 #include <soc/clock.h>
13 #include <soc/funitcfg.h>
14 #include <soc/padconfig.h>
15 #include <soc/nvidia/tegra/i2c.h>
17 #include <soc/nvidia/tegra/dc.h>
18 #include <soc/display.h>
19 #include <soc/mtc.h>
20 #include <soc/pmc.h>
21 #include <soc/power.h>
22 
23 #include "gpio.h"
24 #include "pmic.h"
25 
26 static const struct pad_config padcfgs[] = {
29 };
30 
31 static const struct pad_config audio_codec_pads[] = {
32  /* GPIO_X1_AUD(BB3) is CODEC_RST_L and DMIC1_DAT(E1) is AUDIO_ENABLE */
33  PAD_CFG_GPIO_OUT1(GPIO_X1_AUD, PINMUX_PULL_DOWN),
35 };
36 
37 static const struct pad_config i2s1_pad[] = {
38  /* I2S1 */
39  PAD_CFG_SFIO(DAP1_SCLK, PINMUX_INPUT_ENABLE, I2S1),
40  PAD_CFG_SFIO(DAP1_FS, PINMUX_INPUT_ENABLE, I2S1),
41  PAD_CFG_SFIO(DAP1_DOUT, PINMUX_INPUT_ENABLE, I2S1),
43  /* codec MCLK via AUD SFIO */
44  PAD_CFG_SFIO(AUD_MCLK, PINMUX_PULL_NONE, AUD),
45 };
46 
47 static const struct funit_cfg audio_funit[] = {
48  /* We need 1.5MHz for I2S1. So we use CLK_M */
49  FUNIT_CFG(I2S1, CLK_M, 1500, i2s1_pad, ARRAY_SIZE(i2s1_pad)),
50 };
51 
52 static const struct funit_cfg funits[] = {
53  FUNIT_CFG_USB(USBD),
54  FUNIT_CFG(SDMMC4, PLLP, 48000, NULL, 0),
55  /* I2C6 for audio, temp sensor, etc. Enable codec via GPIOs/muxes */
57 };
58 
59 /* Audio init: clocks and enables/resets */
60 static void setup_audio(void)
61 {
62  /* Audio codec (RT5677) uses 12MHz CLK1/EXTPERIPH1 */
63  clock_configure_source(extperiph1, PLLP, 12000);
64 
65  /* Configure AUD_MCLK pad drive strength */
66  write32((unsigned int *)TEGRA_APB_MISC_GP_BASE + 0xF4,
67  (0x10 << PINGROUP_DRVUP_SHIFT | 0x10 << PINGROUP_DRVDN_SHIFT));
68 
69  /* Set up audio peripheral clocks/muxes */
71 
72  /* Enable CLK1_OUT */
74 
75  /*
76  * As per NVIDIA hardware team, we need to take ALL audio devices
77  * connected to AHUB (AUDIO, APB2APE, I2S, SPDIF, etc.) out of reset
78  * and clock-enabled, otherwise reading AHUB devices (in our case,
79  * I2S/APBIF/AUDIO<XBAR>) will hang.
80  */
83 }
84 
85 static const struct pad_config lcd_gpio_padcfgs[] = {
86  /* LCD_EN */
88  /* LCD_RST_L */
90  /* EN_VDD_LCD */
92  /* EN_VDD18_LCD */
94 };
95 
96 static void configure_display_clocks(void)
97 {
98  u32 lclks = CLK_L_HOST1X | CLK_L_DISP1; /* dc */
99  u32 hclks = CLK_H_MIPI_CAL | CLK_H_DSI; /* mipi phy, mipi-dsi a */
100  u32 uclks = CLK_U_DSIB; /* mipi-dsi b */
101  u32 xclks = CLK_X_UART_FST_MIPI_CAL; /* uart_fst_mipi_cal */
102 
103  clock_enable_clear_reset(lclks, hclks, uclks, 0, 0, xclks, 0);
104 
105  /* Give clocks time to stabilize. */
107 
108  /* CLK72MHZ_CLK_SRC */
109  clock_configure_source(uart_fst_mipi_cal, PLLP_OUT3, 68000);
110 }
111 
112 static int enable_lcd_vdd(void)
113 {
114  /* Set 1.20V to power AVDD_DSI_CSI */
115  /* LD0: 1.20v CNF1: 0x0d */
117 
118  /* Enable VDD_LCD */
119  gpio_set(EN_VDD_LCD, 1);
120  /* wait for 2ms */
121  mdelay(2);
122 
123  /* Enable PP1800_LCDIO to panel */
125  /* wait for 1ms */
126  mdelay(1);
127 
128  /* Set panel EN and RST signals */
129  gpio_set(LCD_EN, 1); /* enable */
130  /* wait for min 10ms */
131  mdelay(10);
132  gpio_set(LCD_RST_L, 1); /* clear reset */
133  /* wait for min 3ms */
134  mdelay(3);
135 
136  return 0;
137 }
138 
139 static int configure_display_blocks(void)
140 {
141  /* enable display related clocks */
143 
144  /* configure panel gpio pads */
146 
147  /* set and enable panel related vdd */
148  if (enable_lcd_vdd())
149  return -1;
150 
151  return 0;
152 }
153 
155 {
156  static const uint32_t partitions[] = {
165  };
166 
167  int i;
168  for (i = 0; i < ARRAY_SIZE(partitions); i++)
169  power_gate_partition(partitions[i]);
170 }
171 
172 static void mainboard_init(struct device *dev)
173 {
176 
177  /* I2C6 bus (audio, etc.) */
180  setup_audio();
181 
182  /* if panel needs to bringup */
183  if (display_init_required())
185 
187 }
188 
189 void display_startup(struct device *dev)
190 {
191  dsi_display_startup(dev);
192 }
193 
194 static void mainboard_enable(struct device *dev)
195 {
196  dev->ops->init = &mainboard_init;
197 }
198 
201 };
202 
203 void lb_board(struct lb_header *header)
204 {
205  if (CONFIG(CHROMEOS))
207 
209 }
struct chip_operations mainboard_ops
Definition: mainboard.c:19
void soc_configure_ape(void)
Definition: ape.c:31
struct arm64_kernel_header header
Definition: fit_payload.c:30
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
int display_init_required(void)
Definition: bootmode.c:22
#define ARRAY_SIZE(a)
Definition: helpers.h:12
void mdelay(unsigned int msecs)
Definition: delay.c:2
@ CONFIG
Definition: dsi_common.h:201
#define MAX77620_CNFG1_L0_REG
Definition: pmic.h:12
void soc_configure_funits(const struct funit_cfg *const entries, size_t num)
Definition: funitcfg.c:132
#define FUNIT_CFG(_funit, _clk_src, _clk_freq, _cfg, _cfg_size)
Definition: funitcfg.h:55
#define FUNIT_CFG_USB(_funit)
Definition: funitcfg.h:65
@ I2C6_BUS
Definition: funitcfg.h:39
@ I2CPWR_BUS
Definition: funitcfg.h:38
void lb_board(struct lb_header *header)
Definition: mainboard.c:325
static void mainboard_init(struct device *dev)
Definition: mainboard.c:172
static void setup_audio(void)
Definition: mainboard.c:60
static int enable_lcd_vdd(void)
Definition: mainboard.c:112
static const struct funit_cfg funits[]
Definition: mainboard.c:52
static const struct pad_config i2s1_pad[]
Definition: mainboard.c:37
static const struct funit_cfg audio_funit[]
Definition: mainboard.c:47
static const struct pad_config audio_codec_pads[]
Definition: mainboard.c:31
static const struct pad_config lcd_gpio_padcfgs[]
Definition: mainboard.c:85
static void powergate_unused_partitions(void)
Definition: mainboard.c:154
void display_startup(struct device *dev)
Definition: mainboard.c:189
static const struct pad_config padcfgs[]
Definition: mainboard.c:26
static int configure_display_blocks(void)
Definition: mainboard.c:139
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:194
static void configure_display_clocks(void)
Definition: mainboard.c:96
void soc_configure_i2c6pad(void)
Definition: i2c6.c:37
void lb_table_add_serialno_from_vpd(struct lb_header *header)
void gpio_set(gpio_t gpio, int value)
Definition: gpio.c:174
@ EN_VDD_LCD
Definition: gpio.h:52
@ LCD_EN
Definition: gpio.h:49
@ LCD_RST_L
Definition: gpio.h:50
@ EN_VDD18_LCD
Definition: gpio.h:51
void soc_add_mtc(struct lb_header *header)
Definition: mtc.c:54
@ PINMUX_INPUT_ENABLE
Definition: pinmux.h:17
@ PINMUX_PULL_NONE
Definition: pinmux.h:12
@ PINMUX_PULL_DOWN
Definition: pinmux.h:13
@ PINMUX_PULL_UP
Definition: pinmux.h:14
@ PINMUX_TRISTATE
Definition: pinmux.h:16
@ POWER_PARTID_XUSBB
Definition: pmc.h:26
@ POWER_PARTID_XUSBA
Definition: pmc.h:25
@ POWER_PARTID_XUSBC
Definition: pmc.h:27
void dsi_display_startup(struct device *dev)
Definition: dsi.c:952
@ PINMUX_IO_HV
Definition: pinmux.h:23
@ PINMUX_PARKED
Definition: pinmux.h:18
@ PINMUX_LPDR
Definition: pinmux.h:21
@ POWER_PARTID_NVJPG
Definition: pmc.h:33
@ POWER_PARTID_PCX
Definition: pmc.h:12
@ POWER_PARTID_SAX
Definition: pmc.h:16
@ POWER_PARTID_DFD
Definition: pmc.h:35
@ POWER_PARTID_NVDEC
Definition: pmc.h:32
void power_gate_partition(uint32_t id)
Definition: power.c:64
#define PAD_CFG_GPIO_OUT1(ball_, pinmux_flgs_)
Definition: padconfig.h:40
#define PAD_CFG_GPIO_INPUT(ball_, pinmux_flgs_)
Definition: padconfig.h:21
#define PAD_CFG_SFIO(ball_, pinmux_flgs_, sfio_)
Definition: padconfig.h:50
void soc_configure_pads(const struct pad_config *const entries, size_t num)
Definition: padconfig.c:105
#define PAD_CFG_GPIO_OUT0(ball_, pinmux_flgs_)
Definition: padconfig.h:30
void pmic_write_reg_77620(unsigned int bus, uint8_t reg, uint8_t val, int delay)
Definition: pmic.c:37
@ I2C6
Definition: i2c.h:56
void clock_external_output(int clk_id)
Definition: clock.c:396
void clock_enable_clear_reset(u32 l, u32 h, u32 u, u32 v, u32 w, u32 x)
Definition: clock.c:600
@ TEGRA_APB_MISC_GP_BASE
Definition: addressmap.h:27
@ CLK_U_DSIB
Definition: clock.h:88
@ CLK_L_HOST1X
Definition: clock.h:38
@ CLK_H_MIPI_CAL
Definition: clock.h:63
@ CLK_L_DISP1
Definition: clock.h:37
@ CLK_H_DSI
Definition: clock.h:57
#define IO_STABILIZATION_DELAY
Definition: clock.h:165
#define clock_configure_source(device, src, freq)
Definition: clock.h:229
@ PLLP
Definition: clock.h:245
@ CLK_M
Definition: clock.h:253
void clock_enable_audio(void)
Definition: clock.c:772
@ PLLP_OUT3
Definition: clock.h:170
@ CLK_X_UART_FST_MIPI_CAL
Definition: clock.h:138
void i2c_init(unsigned int bus)
Definition: i2c.c:198
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
void(* enable_dev)(struct device *dev)
Definition: device.h:24
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
@ PINGROUP_DRVDN_SHIFT
Definition: pingroup.h:16
@ PINGROUP_DRVUP_SHIFT
Definition: pingroup.h:18
void udelay(uint32_t us)
Definition: udelay.c:15