coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
clock.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #include <device/mmio.h>
4 #include <delay.h>
5 #include <soc/blsp.h>
6 #include <soc/clock.h>
7 #include <types.h>
8 #include <console/console.h>
9 
10 #define CLOCK_UPDATE_DELAY 1000
11 
12 /**
13  * uart_clock_config - configures UART clocks
14  *
15  * Configures GSBI UART dividers, enable root and branch clocks.
16  */
17 void uart_clock_config(unsigned int blsp_uart, unsigned int m,
18  unsigned int n, unsigned int d)
19 {
20  int i;
21 
22  /* Setup M, N & D */
23  write32(GCC_BLSP1_UART_APPS_M(blsp_uart), m);
24  write32(GCC_BLSP1_UART_APPS_N(blsp_uart), ~(n - m));
25  write32(GCC_BLSP1_UART_APPS_D(blsp_uart), ~d);
26  write32(GCC_BLSP1_UART_MISC(blsp_uart), 0);
27 
28  /* Setup source sel etc. */
30  0 | /* 0: 4 SRC_DIV = Bypass */
31  0 << 8 | /* 8:10 SRC_SEL = CxO */
32  2 << 12); /* 13:12 Mode = Dual Edge */
33 
34  /* Trigger update */
36 
37  /* Wait for update */
38  for (i = 0; i < CLOCK_UPDATE_DELAY; i++) {
39  if (!(read32(GCC_BLSP1_UART_APPS_CMD_RCGR(blsp_uart)) & 1)) {
40  /* Updated */
41  break;
42  }
43  udelay(1);
44  }
45 
46  /* Please refer to the comments in blsp_i2c_clock_config() */
48 }
49 
50 /**
51  * nand_clock_config - configure NAND controller clocks
52  *
53  * Enable clocks to EBI2. Must be invoked before touching EBI2
54  * registers.
55  */
57 {
60 
61  /* Wait for clock to stabilize. */
62  udelay(10);
63 }
64 
65 /**
66  * usb_clock_config - configure USB controller clocks and reset the controller
67  */
68 void usb_clock_config(void)
69 {
70  /* Magic clock initialization numbers, nobody knows how they work... */
73  write32(USB30_MASTER_CLK_MD, 0x500DF);
74  write32(USB30_MASTER_CLK_NS, 0xE40942);
76  write32(USB30_MOC_UTMI_CLK_NS, 0xD80942);
79 
81  1 << 5 | /* assert port2 HS PHY async reset */
82  1 << 4 | /* assert master async reset */
83  1 << 3 | /* assert sleep async reset */
84  1 << 2 | /* assert MOC UTMI async reset */
85  1 << 1 | /* assert power-on async reset */
86  1 << 0); /* assert PHY async reset */
87  udelay(5);
88  write32(USB30_RESET, 0); /* deassert all USB resets again */
89 }
90 
92 {
93  int i;
94  const int max_tries = 200;
95  struct { void *cbcr, *cmd, *cfg; } clk[] = {
96  {
100  },
101  {
105  },
106  {
110  },
111  {
115  },
116  };
117 
118  /*
119  * uart_clock_config() does this. Ideally, setting these bits once
120  * should suffice. However, if for some reason the order of invocation
121  * of uart_clock_config and blsp_i2c_clock_config gets changed or
122  * something, then one of the functions might not work. Hence, to steer
123  * clear of such dependencies, just replicating the setting of this
124  * bits.
125  *
126  * Moreover, they are read-modify-write and HW wise repeated setting of
127  * the same bits is harmless. Hence repeating them here should be ok.
128  * This will ensure root and branch clocks remain on.
129  */
131 
132  /* Src Sel 1 (fepll 200), Src Div 10.5 */
133  write32(clk[id].cfg, (1u << 8) | (20u << 0));
134 
135  write32(clk[id].cmd, BIT(0)); /* Update En */
136 
137  for (i = 0; i < max_tries; i++) {
138  if (read32(clk[id].cmd) & BIT(0)) {
139  udelay(5);
140  continue;
141  }
142  break;
143  }
144 
145  if (i == max_tries) {
146  printk(BIOS_ERR, "%s failed\n", __func__);
147  return -ETIMEDOUT;
148  }
149 
150  write32(clk[id].cbcr, BIT(0)); /* Enable */
151 
152  return 0;
153 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define printk(level,...)
Definition: stdlib.h:16
#define BIT(nr)
Definition: ec_commands.h:45
#define setbits32(addr, set)
Definition: mmio.h:21
blsp_qup_id_t
Definition: blsp.h:6
#define ETIMEDOUT
Definition: kempld_i2c.c:48
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define GCC_BLSP1_QUP1_I2C_APPS_CBCR
Definition: iomap.h:42
#define BLSP1_AHB
Definition: iomap.h:30
#define GCC_BLSP1_UART_APPS_CFG_RCGR(x)
Definition: iomap.h:89
#define GCC_BLSP1_QUP1_I2C_APPS_CMD_RCGR
Definition: iomap.h:43
#define GCC_BLSP1_QUP1_I2C_APPS_CFG_RCGR
Definition: iomap.h:44
#define GCC_BLSP1_UART_APPS_CMD_RCGR(x)
Definition: iomap.h:88
#define BLSP1_SLEEP
Definition: iomap.h:31
#define GCC_BLSP1_UART_APPS_N(x)
Definition: iomap.h:91
#define GCC_CLK_BRANCH_ENA
Definition: iomap.h:22
#define GCC_BLSP1_UART_APPS_D(x)
Definition: iomap.h:92
#define GCC_BLSP1_UART_APPS_M(x)
Definition: iomap.h:90
#define GCC_BLSP1_UART_MISC(x)
Definition: iomap.h:93
int blsp_i2c_clock_config(blsp_qup_id_t id)
Definition: clock.c:91
void nand_clock_config(void)
nand_clock_config - configure NAND controller clocks
Definition: clock.c:56
#define CLOCK_UPDATE_DELAY
Definition: clock.c:10
void uart_clock_config(unsigned int blsp_uart, unsigned int m, unsigned int n, unsigned int d)
uart_clock_config - configures UART clocks
Definition: clock.c:17
void usb_clock_config(void)
usb_clock_config - configure USB controller clocks and reset the controller
Definition: clock.c:68
#define USB30_MASTER_CLK_NS
Definition: clock.h:43
#define ALWAYS_ON_CLK_BRANCH_ENA(i)
Definition: clock.h:51
#define USB30_MOC_UTMI_CLK_CTL
Definition: clock.h:47
#define USB30_1_MOC_UTMI_CLK_CTL
Definition: clock.h:48
#define USB30_MASTER_CLK_CTL_REG
Definition: clock.h:41
#define USB30_MOC_UTMI_CLK_MD
Definition: clock.h:45
#define USB30_MASTER_CLK_MD
Definition: clock.h:42
#define USB30_MOC_UTMI_CLK_NS
Definition: clock.h:46
#define EBI2_CLK_CTL_REG
Definition: clock.h:39
#define USB30_RESET
Definition: clock.h:49
#define USB30_1_MASTER_CLK_CTL_REG
Definition: clock.h:44
#define CLK_BRANCH_ENA(i)
Definition: clock.h:56
#define m(clkreg, src_bits, pmcreg, dst_bits)
void udelay(uint32_t us)
Definition: udelay.c:15