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 <arch/cache.h>
4 #include <boot/coreboot_tables.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <device/device.h>
8 #include <device/i2c_simple.h>
10 #include <soc/clk.h>
11 #include <soc/dp.h>
12 #include <soc/dp-core.h>
13 #include <soc/gpio.h>
14 #include <soc/i2c.h>
15 #include <soc/periph.h>
16 #include <soc/power.h>
17 #include <soc/tmu.h>
18 #include <soc/usb.h>
19 #include <symbols.h>
20 #include <framebuffer_info.h>
21 
22 #include "exynos5250.h"
23 
24 #define MMC0_GPIO_PIN (58)
25 
26 /* convenient shorthand (in MB) */
27 #define DRAM_START ((uintptr_t)_dram/MiB)
28 #define DRAM_SIZE CONFIG_DRAM_SIZE_MB
29 #define DRAM_END (DRAM_START + DRAM_SIZE) /* plus one... */
30 
31 /* TODO: transplanted DP stuff, clean up once we have something that works */
32 static enum exynos5_gpio_pin dp_pd_l = GPIO_Y25; /* active low */
33 static enum exynos5_gpio_pin dp_rst_l = GPIO_X15; /* active low */
34 static enum exynos5_gpio_pin dp_hpd = GPIO_X07; /* active high */
35 
36 static void exynos_dp_bridge_setup(void)
37 {
39 
43 
47  udelay(10);
49 }
50 
51 static void exynos_dp_bridge_init(void)
52 {
53  /* De-assert PD (and possibly RST) to power up the bridge */
56 
57  /*
58  * We need to wait for 90ms after bringing up the bridge since
59  * there is a phantom "high" on the HPD chip during its
60  * bootup. The phantom high comes within 7ms of de-asserting
61  * PD and persists for at least 15ms. The real high comes
62  * roughly 50ms after PD is de-asserted. The phantom high
63  * makes it hard for us to know when the NXP chip is up.
64  */
65  udelay(90000);
66 }
67 
68 static int exynos_dp_hotplug(void)
69 {
70  /* Check HPD. If it's high, we're all good. */
71  return gpio_get_value(dp_hpd) ? 0 : 1;
72 }
73 
74 static void exynos_dp_reset(void)
75 {
78  /* paranoid delay period (300ms) */
79  udelay(300 * 1000);
80 }
81 
82 /*
83  * This delay is T3 in the LCD timing spec (defined as >200ms). We set
84  * this down to 60ms since that's the approximate maximum amount of time
85  * it'll take a bridge to start outputting LVDS data. The delay of
86  * >200ms is just a conservative value to avoid turning on the backlight
87  * when there's random LCD data on the screen. Shaving 140ms off the
88  * boot is an acceptable trade-off.
89  */
90 #define LCD_T3_DELAY_MS 60
91 
92 #define LCD_T5_DELAY_MS 10
93 #define LCD_T6_DELAY_MS 10
94 
95 static void backlight_pwm(void)
96 {
97  /*Configure backlight PWM as a simple output high (100% brightness) */
99  udelay(LCD_T6_DELAY_MS * 1000);
100 }
101 
102 static void backlight_en(void)
103 {
104  /* Configure GPIO for LCD_BL_EN */
106 }
107 
108 #define TPS65090_BUS 4 /* Daisy-specific */
109 
110 #define FET1_CTRL 0x0f
111 #define FET4_CTRL 0x12
112 #define FET6_CTRL 0x14
113 
114 static void lcd_vdd(void)
115 {
116  /* Enable FET6, lcd panel */
118 }
119 
120 static void backlight_vdd(void)
121 {
122  /* Enable FET1, backlight */
124  udelay(LCD_T5_DELAY_MS * 1000);
125 }
126 
127 static void sdmmc_vdd(void)
128 {
129  /* Enable FET4, P3.3V_SDCARD */
131 }
132 
135 /* static enum exynos5_gpio_pin hsic_reset_l = GPIO_E10; */
136 
137 static void prepare_usb(void)
138 {
139  /* Kick this reset off early so it gets at least 100ms to settle */
141 }
142 
143 static void setup_usb(void)
144 {
145  /* HSIC not needed in firmware on this board */
149 
152 }
153 
154 //static struct video_info smdk5250_dp_config = {
155 static struct video_info dp_video_info = {
156  /* FIXME: fix video_info struct to use const for name */
157  .name = (char *)"eDP-LVDS NXP PTN3460",
158 
159  .h_sync_polarity = 0,
160  .v_sync_polarity = 0,
161  .interlaced = 0,
162 
164  .dynamic_range = VESA,
166  .color_depth = COLOR_8,
167 
170 };
171 
172 /* FIXME: move some place more appropriate */
173 #define MAX_DP_TRIES 5
174 
175 /*
176  * This function disables the USB3.0 PLL to save power
177  */
178 static void disable_usb30_pll(void)
179 {
180  enum exynos5_gpio_pin usb3_pll_l = GPIO_Y11;
181 
182  gpio_direction_output(usb3_pll_l, 0);
183 }
184 
185 static void setup_storage(void)
186 {
187  /* MMC0: Fixed, 8 bit mode, connected with GPIO. */
189  printk(BIOS_CRIT, "%s: Failed to set MMC0 clock.\n", __func__);
191  printk(BIOS_CRIT, "%s: Unable to power on MMC0.\n", __func__);
192  }
196 
197  /* MMC2: Removable, 4 bit mode, no GPIO. */
198  /* (Must be after romstage to avoid breaking SDMMC boot.) */
201 }
202 
203 static void gpio_init(void)
204 {
205  /* Set up the I2C buses. */
212 
213  /* Set up the GPIOs used to arbitrate for I2C bus 4. */
218 
219  /* Set up the GPIO used to enable the audio codec. */
224 
225  /* Set up the I2S buses. */
228 }
229 
230 /* this happens after cpu_init where exynos resources are set */
231 static void mainboard_init(struct device *dev)
232 {
233  int dp_tries;
234  struct s5p_dp_device dp_device = {
235  .base = exynos_dp1,
236  .video_info = &dp_video_info,
237  };
238  void *fb_addr = (void *)(get_fb_base_kb() * KiB);
239 
240  prepare_usb();
241  gpio_init();
242  setup_storage();
243 
246 
248 
249  /* Clock Gating all the unused IP's to save power */
250  clock_gate();
251 
252  /* Disable USB3.0 PLL to save 250mW of power */
254 
255  sdmmc_vdd();
256 
257  fb_add_framebuffer_info((uintptr_t)fb_addr, 1366, 768, 2 * 1366, 16);
258 
259  lcd_vdd();
260 
261  // FIXME: should timeout
262  do {
263  udelay(50);
264  } while (!exynos_dp_hotplug());
265 
267  for (dp_tries = 1; dp_tries <= MAX_DP_TRIES; dp_tries++) {
269  if (exynos_dp_hotplug()) {
270  exynos_dp_reset();
271  continue;
272  }
273 
274  if (dp_controller_init(&dp_device))
275  continue;
276 
277  udelay(LCD_T3_DELAY_MS * 1000);
278 
279  backlight_vdd();
280  backlight_pwm();
281  backlight_en();
282  /* if we're here, we're successful */
283  break;
284  }
285 
286  if (dp_tries > MAX_DP_TRIES)
287  printk(BIOS_ERR, "%s: Failed to set up displayport\n", __func__);
288 
289  setup_usb();
290 
291  // Uncomment to get excessive GPIO output:
292  // gpio_info();
293 }
294 
295 static void mainboard_enable(struct device *dev)
296 {
297  dev->ops->init = &mainboard_init;
298 
299  /* set up dcache and MMU */
300  /* FIXME: this should happen via resource allocator */
302  mmu_init();
305  mmu_config_range((uintptr_t)_dma_coherent/MiB,
309 
310  const unsigned int epll_hz = 192000000;
311  const unsigned int sample_rate = 48000;
312  const unsigned int lr_frame_size = 256;
313  clock_epll_set_rate(epll_hz);
315  clock_set_i2s_clk_prescaler(epll_hz, sample_rate * lr_frame_size);
316 
318 }
319 
321  .name = "daisy",
322  .enable_dev = mainboard_enable,
323 };
324 
325 void lb_board(struct lb_header *header)
326 {
327  struct lb_range *dma;
328 
329  dma = (struct lb_range *)lb_new_record(header);
330  dma->tag = LB_TAG_DMA;
331  dma->size = sizeof(*dma);
332  dma->range_start = (uintptr_t)_dma_coherent;
333  dma->range_size = REGION_SIZE(dma_coherent);
334 }
struct chip_operations mainboard_ops
Definition: mainboard.c:19
#define GPIO_OUTPUT
Definition: gpio_ftns.h:23
struct arm64_kernel_header header
Definition: fit_payload.c:30
void dcache_mmu_enable(void)
Definition: cache.c:53
void mmu_config_range(u32 start_mb, u32 size_mb, enum dcache_policy policy)
Definition: mmu.c:221
void mmu_init(void)
Definition: mmu.c:242
@ DCACHE_WRITEBACK
Definition: cache.h:364
@ DCACHE_OFF
Definition: cache.h:363
#define MiB
Definition: helpers.h:76
#define KiB
Definition: helpers.h:75
@ LB_TAG_DMA
#define printk(level,...)
Definition: stdlib.h:16
int dma_coherent(void *ptr)
@ COLOR_RGB
Definition: dp-core.h:37
link_rate
Definition: dp-core.h:15
@ LANE_COUNT2
Definition: dp-core.h:23
color_space
Definition: edp.h:571
color_depth
Definition: edp.h:577
@ COLOR_8
Definition: edp.h:579
@ LINK_RATE_2_70GBPS
Definition: edp.h:586
dynamic_range
Definition: edp.h:543
@ VESA
Definition: edp.h:544
@ COLOR_YCBCR601
Definition: edp.h:539
void clock_gate(void)
Definition: clock_init.c:267
static struct exynos5_dp *const exynos_dp1
Definition: dp.h:153
@ PERIPH_ID_SDMMC2
Definition: periph.h:20
@ PERIPH_ID_SDMMC0
Definition: periph.h:18
#define I2C_SLAVE
Definition: exynos5250.h:5
#define I2C_0_SPEED
Definition: exynos5250.h:4
int dp_controller_init(struct s5p_dp_device *dp_device)
Definition: fb.c:475
struct fb_info * fb_add_framebuffer_info(uintptr_t fb_addr, uint32_t x_resolution, uint32_t y_resolution, uint32_t bytes_per_line, uint8_t bits_per_pixel)
Definition: edid_fill_fb.c:89
#define DRAM_END
Definition: mainboard.c:29
static void mainboard_init(struct device *dev)
Definition: mainboard.c:231
static void exynos_dp_reset(void)
Definition: mainboard.c:74
static void lcd_vdd(void)
Definition: mainboard.c:114
#define MMC0_GPIO_PIN
Definition: mainboard.c:24
static void exynos_dp_bridge_init(void)
Definition: mainboard.c:51
static void backlight_pwm(void)
Definition: mainboard.c:95
static void prepare_usb(void)
Definition: mainboard.c:137
#define DRAM_SIZE
Definition: mainboard.c:28
#define LCD_T3_DELAY_MS
Definition: mainboard.c:90
#define FET4_CTRL
Definition: mainboard.c:111
static void gpio_init(void)
Definition: mainboard.c:203
#define FET1_CTRL
Definition: mainboard.c:110
static void setup_storage(void)
Definition: mainboard.c:185
#define FET6_CTRL
Definition: mainboard.c:112
#define LCD_T6_DELAY_MS
Definition: mainboard.c:93
static enum exynos5_gpio_pin dp_pd_l
Definition: mainboard.c:32
static enum exynos5_gpio_pin dp_rst_l
Definition: mainboard.c:33
static void exynos_dp_bridge_setup(void)
Definition: mainboard.c:36
#define DRAM_START
Definition: mainboard.c:27
static void disable_usb30_pll(void)
Definition: mainboard.c:178
static enum exynos5_gpio_pin dp_hpd
Definition: mainboard.c:34
static struct video_info dp_video_info
Definition: mainboard.c:155
static void sdmmc_vdd(void)
Definition: mainboard.c:127
static int exynos_dp_hotplug(void)
Definition: mainboard.c:68
static void setup_usb(void)
Definition: mainboard.c:143
static enum exynos5_gpio_pin usb_host_vbus
Definition: mainboard.c:133
#define TPS65090_BUS
Definition: mainboard.c:108
#define MAX_DP_TRIES
Definition: mainboard.c:173
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:295
void lb_board(struct lb_header *header)
Definition: mainboard.c:325
static void backlight_vdd(void)
Definition: mainboard.c:120
#define LCD_T5_DELAY_MS
Definition: mainboard.c:92
static enum exynos5_gpio_pin usb_drd_vbus
Definition: mainboard.c:134
static void backlight_en(void)
Definition: mainboard.c:102
struct lb_record * lb_new_record(struct lb_header *header)
#define REGION_SIZE(name)
Definition: symbols.h:10
#define BIOS_CRIT
BIOS_CRIT - Recovery unlikely.
Definition: loglevel.h:56
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
void gpio_set_pull(gpio_t gpio, enum pull_enable enable, enum pull_select select)
Definition: gpio.c:17
struct @1399 * dma
void exynos_pinmux_i2c1(void)
Definition: pinmux.c:184
void exynos_pinmux_sdmmc0(void)
Definition: pinmux.c:60
void exynos_pinmux_i2s1(void)
Definition: pinmux.c:241
void exynos_pinmux_dphpd(void)
Definition: pinmux.c:219
void exynos_pinmux_i2s0(void)
Definition: pinmux.c:231
void exynos_pinmux_i2c2(void)
Definition: pinmux.c:189
void exynos_pinmux_i2c4(void)
Definition: pinmux.c:199
void exynos_pinmux_i2c0(void)
Definition: pinmux.c:179
void exynos_pinmux_i2c7(void)
Definition: pinmux.c:214
void exynos_pinmux_i2c3(void)
Definition: pinmux.c:194
void exynos_pinmux_sdmmc2(void)
Definition: pinmux.c:70
void power_enable_xclkout(void)
Definition: power.c:71
void i2c_init(unsigned int bus)
Definition: i2c.c:198
void clock_select_i2s_clk_source(void)
Definition: clock.c:631
int clock_set_i2s_clk_prescaler(unsigned int src_frq, unsigned int dst_frq)
Definition: clock.c:637
int clock_set_mshci(enum periph_id peripheral)
Definition: clock.c:540
int clock_epll_set_rate(unsigned long rate)
Definition: clock.c:577
void exynos5250_config_l2_cache(void)
Definition: cpu.c:135
void gpio_cfg_pin(int gpio, int cfg)
Set GPIO pin configuration.
Definition: gpio.c:63
int gpio_direction_output(unsigned int gpio, int value)
Make a GPIO an output, and set its value.
Definition: gpio.c:151
int gpio_direction_input(unsigned int gpio)
Make a GPIO an input.
Definition: gpio.c:144
int gpio_set_value(unsigned int gpio, int value)
Set an output GPIO's value.
Definition: gpio.c:176
int gpio_get_value(unsigned int gpio)
Get a GPIO's value.
Definition: gpio.c:167
void gpio_set_drv(int gpio, int mode)
Set GPIO drive strength level.
Definition: gpio.c:102
static u32 get_fb_base_kb(void)
Definition: cpu.h:66
struct tmu_info exynos5250_tmu_info
Definition: tmu.c:33
exynos5_gpio_pin
Definition: gpio.h:102
@ GPIO_Y25
Definition: gpio.h:229
@ GPIO_X11
Definition: gpio.h:276
@ GPIO_X15
Definition: gpio.h:280
@ GPIO_X27
Definition: gpio.h:290
@ GPIO_X17
Definition: gpio.h:282
@ GPIO_E04
Definition: gpio.h:306
@ GPIO_B20
Definition: gpio.h:144
@ GPIO_X30
Definition: gpio.h:291
@ GPIO_Y11
Definition: gpio.h:217
@ GPIO_F03
Definition: gpio.h:321
@ GPIO_X07
Definition: gpio.h:274
#define GPIO_PULL_NONE
Definition: gpio.h:30
#define GPIO_DRV_4X
Definition: gpio.h:38
void setup_usb_host_phy(int hsic_gpio)
Definition: usb.c:119
void setup_usb_drd_dwc3(void)
Definition: usb.c:55
void reset_usb_drd_dwc3(void)
Definition: usb.c:19
void setup_usb_drd_phy(void)
Definition: usb.c:112
unsigned long uintptr_t
Definition: stdint.h:21
const char * name
Definition: device.h:29
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
struct exynos5_dp * base
Definition: dp-core.h:97
enum color_coefficient ycbcr_coeff
Definition: dp-core.h:77
char * name
Definition: dp-core.h:83
enum link_lane_count lane_count
Definition: dp-core.h:81
unsigned int h_sync_polarity
Definition: dp-core.h:85
unsigned int v_sync_polarity
Definition: dp-core.h:86
unsigned int interlaced
Definition: dp-core.h:87
int tmu_init(struct tmu_info *info)
Definition: tmu.c:189
int tps65090_fet_enable(unsigned int bus, enum fet_id fet_id)
Enable FET.
Definition: tps65090.c:95
void udelay(uint32_t us)
Definition: udelay.c:15