coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
uart.c
Go to the documentation of this file.
1 /* Source : APQ8064 LK boot */
2 /* SPDX-License-Identifier: BSD-3-Clause */
3 
4 #include <device/mmio.h>
5 #include <boot/coreboot_tables.h>
6 #include <console/uart.h>
7 #include <delay.h>
8 #include <gpio.h>
9 #include <soc/clock.h>
10 #include <soc/blsp.h>
11 #include <soc/uart.h>
12 #include <soc/cdp.h>
13 #include <stdint.h>
14 #include <soc/iomap.h>
15 
16 #define FIFO_DATA_SIZE 4
17 
18 typedef struct {
19  void *uart_dm_base;
20  unsigned int blsp_uart;
23 
24 void ipq_configure_gpio(const gpio_func_data_t *gpio, unsigned int count)
25 {
26  int i;
27 
28  for (i = 0; i < count; i++) {
29  gpio_configure(gpio->gpio, gpio->func,
30  gpio->pull, gpio->drvstr, gpio->enable);
31  gpio++;
32  }
33 }
34 
37  .blsp_uart = BLSP1_UART2,
38  .dbg_uart_gpio = {
39  {
40  .gpio = GPIO(17),
41  .func = 1,
42  .dir = GPIO_OUTPUT,
43  .pull = GPIO_PULL_UP,
44  .enable = GPIO_OUTPUT
45  },
46  {
47  .gpio = GPIO(18),
48  .func = 1,
49  .dir = GPIO_INPUT,
50  .pull = GPIO_NO_PULL,
51  .enable = GPIO_INPUT
52  },
53  },
54 };
55 
56 /**
57  * @brief msm_boot_uart_dm_init_rx_transfer - Init Rx transfer
58  * @param uart_dm_base: UART controller base address
59  */
60 static unsigned int msm_boot_uart_dm_init_rx_transfer(void *uart_dm_base)
61 {
62  /* Reset receiver */
63  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
65 
66  /* Enable receiver */
67  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
69  write32(MSM_BOOT_UART_DM_DMRX(uart_dm_base),
71 
72  /* Clear stale event */
73  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
75 
76  /* Enable stale event */
77  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
79 
81 }
82 
83 #if CONFIG(DRIVERS_UART)
84 static unsigned int msm_boot_uart_dm_init(void *uart_dm_base);
85 
86 /* Received data is valid or not */
87 static int valid_data = 0;
88 
89 /* Received data */
90 static unsigned int word = 0;
91 
92 void uart_tx_byte(unsigned int idx, unsigned char data)
93 {
94  int num_of_chars = 1;
96 
97  /* Wait until transmit FIFO is empty. */
98  while (!(read32(MSM_BOOT_UART_DM_SR(base)) &
100  udelay(1);
101  /*
102  * TX FIFO is ready to accept new character(s). First write number of
103  * characters to be transmitted.
104  */
106 
107  /* And now write the character(s) */
108  write32(MSM_BOOT_UART_DM_TF(base, 0), data);
109 }
110 #endif /* CONFIG_SERIAL_UART */
111 
112 /**
113  * @brief msm_boot_uart_dm_reset - resets UART controller
114  * @param base: UART controller base address
115  */
116 static unsigned int msm_boot_uart_dm_reset(void *base)
117 {
124 
126 }
127 
128 /**
129  * @brief msm_boot_uart_dm_init - initilaizes UART controller
130  * @param uart_dm_base: UART controller base address
131  */
132 unsigned int msm_boot_uart_dm_init(void *uart_dm_base)
133 {
134  /* Configure UART mode registers MR1 and MR2 */
135  /* Hardware flow control isn't supported */
136  write32(MSM_BOOT_UART_DM_MR1(uart_dm_base), 0x0);
137 
138  /* 8-N-1 configuration: 8 data bits - No parity - 1 stop bit */
139  write32(MSM_BOOT_UART_DM_MR2(uart_dm_base),
141 
142  /* Configure Interrupt Mask register IMR */
143  write32(MSM_BOOT_UART_DM_IMR(uart_dm_base),
145 
146  /*
147  * Configure Tx and Rx watermarks configuration registers
148  * TX watermark value is set to 0 - interrupt is generated when
149  * FIFO level is less than or equal to 0
150  */
151  write32(MSM_BOOT_UART_DM_TFWR(uart_dm_base),
153 
154  /* RX watermark value */
155  write32(MSM_BOOT_UART_DM_RFWR(uart_dm_base),
157 
158  /* Configure Interrupt Programming Register */
159  /* Set initial Stale timeout value */
160  write32(MSM_BOOT_UART_DM_IPR(uart_dm_base),
162 
163  /* Configure IRDA if required */
164  /* Disabling IRDA mode */
165  write32(MSM_BOOT_UART_DM_IRDA(uart_dm_base), 0x0);
166 
167  /* Configure hunt character value in HCR register */
168  /* Keep it in reset state */
169  write32(MSM_BOOT_UART_DM_HCR(uart_dm_base), 0x0);
170 
171  /*
172  * Configure Rx FIFO base address
173  * Both TX/RX shares same SRAM and default is half-n-half.
174  * Sticking with default value now.
175  * As such RAM size is (2^RAM_ADDR_WIDTH, 32-bit entries).
176  * We have found RAM_ADDR_WIDTH = 0x7f
177  */
178 
179  /* Issue soft reset command */
180  msm_boot_uart_dm_reset(uart_dm_base);
181 
182  /* Enable/Disable Rx/Tx DM interfaces */
183  /* Data Mover not currently utilized. */
184  write32(MSM_BOOT_UART_DM_DMEN(uart_dm_base), 0x0);
185 
186  /* Enable transmitter */
187  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
189 
190  /* Initialize Receive Path */
191  msm_boot_uart_dm_init_rx_transfer(uart_dm_base);
192 
193  return 0;
194 }
195 
196 /**
197  * @brief qcs405_uart_init - initializes UART
198  *
199  * Initializes clocks, GPIO and UART controller.
200  */
201 void uart_init(unsigned int idx)
202 {
203  /* Note int idx isn't used in this driver. */
204  void *dm_base;
205 
206  dm_base = uart_board_param.uart_dm_base;
207 
208  if (read32(MSM_BOOT_UART_DM_CSR(dm_base)) == 0xFF)
209  return; /* UART must have been already initialized. */
210 
211  clock_configure_uart(1843200);
213 
216 
217  write32(MSM_BOOT_UART_DM_CSR(dm_base), 0xFF);
218 
219  /* Initialize UART_DM */
220  msm_boot_uart_dm_init(dm_base);
221 }
222 
223 /* for the benefit of non-console uart init */
225 {
226  uart_init(0);
227 }
228 
229 /**
230  * @brief uart_tx_flush - transmits a string of data
231  * @param idx: string to transmit
232  */
233 void uart_tx_flush(unsigned int idx)
234 {
236 
237  while (!(read32(MSM_BOOT_UART_DM_SR(base)) &
239  ;
240 }
241 
242 #if CONFIG(DRIVERS_UART)
243 /**
244  * qcs405_serial_getc - reads a character
245  *
246  * Returns the character read from serial port.
247  */
248 uint8_t uart_rx_byte(unsigned int idx)
249 {
250  uint8_t byte;
251 
252  byte = (uint8_t)(word & 0xff);
253  word = word >> 8;
254  valid_data--;
255 
256  return byte;
257 }
258 #endif
259 
260 void uart_fill_lb(void *data)
261 {
262  struct lb_serial serial;
263 
265  serial.baseaddr = (uint64_t)UART2_DM_BASE;
266  serial.baud = get_uart_baudrate();
267  serial.regwidth = 1;
268  serial.input_hertz = uart_platform_refclk();
269  serial.uart_pci_addr = CONFIG_UART_PCI_ADDR;
270  lb_add_serial(&serial, data);
271 
273 }
#define GPIO_OUTPUT
Definition: gpio_ftns.h:23
#define GPIO_INPUT
Definition: gpio_ftns.h:24
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
unsigned int get_uart_baudrate(void)
Definition: bmcinfo.c:167
#define LB_TAG_CONSOLE_SERIAL8250MEM
#define LB_SERIAL_TYPE_MEMORY_MAPPED
@ GPIO
Definition: chip.h:84
void lb_add_console(uint16_t consoletype, void *data)
void lb_add_serial(struct lb_serial *serial, void *data)
#define NO_OF_DBG_UART_GPIOS
Definition: cdp.h:76
#define MSM_BOOT_UART_DM_TF(base, x)
Definition: ipq_uart.h:58
#define MSM_BOOT_UART_DM_DMRX(base)
Definition: ipq_uart.h:152
#define MSM_BOOT_UART_DM_IMR(base)
Definition: ipq_uart.h:111
#define MSM_BOOT_UART_DM_MR1(base)
Definition: ipq_uart.h:44
#define MSM_BOOT_UART_DM_CSR(base)
Definition: ipq_uart.h:51
#define MSM_BOOT_UART_DM_GCMD_ENA_STALE_EVT
Definition: ipq_uart.h:106
#define MSM_BOOT_UART_DM_HCR(base)
Definition: ipq_uart.h:149
#define MSM_BOOT_UART_DM_SR_TXEMT
Definition: ipq_uart.h:182
#define MSM_BOOT_UART_DM_CMD_RES_TX_ERR
Definition: ipq_uart.h:92
#define MSM_BOOT_UART_DM_TFWR(base)
Definition: ipq_uart.h:140
#define MSM_BOOT_UART_DM_MR2(base)
Definition: ipq_uart.h:45
#define MSM_BOOT_UART_DM_SR(base)
Definition: ipq_uart.h:175
#define MSM_BOOT_UART_DM_IMR_ENABLED
Definition: ipq_uart.h:130
#define MSM_BOOT_UART_DM_TFW_VALUE
Definition: ipq_uart.h:142
#define MSM_BOOT_UART_DM_IPR(base)
Definition: ipq_uart.h:135
#define MSM_BOOT_UART_DM_DMEN(base)
Definition: ipq_uart.h:165
#define MSM_BOOT_UART_DM_STALE_TIMEOUT_LSB
Definition: ipq_uart.h:136
#define MSM_BOOT_UART_DM_CR_TX_ENABLE
Definition: ipq_uart.h:71
#define MSM_BOOT_UART_DM_RFWR(base)
Definition: ipq_uart.h:144
#define MSM_BOOT_UART_DM_DMRX_DEF_VALUE
Definition: ipq_uart.h:155
#define MSM_BOOT_UART_DM_NO_CHARS_FOR_TX(base)
Definition: ipq_uart.h:168
#define MSM_BOOT_UART_DM_CMD_RESET_TX
Definition: ipq_uart.h:81
#define MSM_BOOT_UART_DM_IRDA(base)
Definition: ipq_uart.h:159
#define MSM_BOOT_UART_DM_CR(base)
Definition: ipq_uart.h:65
#define MSM_BOOT_UART_DM_8_N_1_MODE
Definition: ipq_uart.h:37
#define MSM_BOOT_UART_DM_CMD_RES_STALE_INT
Definition: ipq_uart.h:87
#define MSM_BOOT_UART_DM_E_SUCCESS
Definition: ipq_uart.h:236
#define MSM_BOOT_UART_DM_CMD_RESET_RX
Definition: ipq_uart.h:80
#define MSM_BOOT_UART_DM_RFW_VALUE
Definition: ipq_uart.h:146
#define MSM_BOOT_UART_DM_CMD_RESET_ERR_STAT
Definition: ipq_uart.h:82
#define MSM_BOOT_UART_DM_CR_RX_ENABLE
Definition: ipq_uart.h:69
unsigned int serial
Definition: edid.c:52
void uart_init(unsigned int idx)
Definition: uart.c:13
void uart_tx_flush(unsigned int idx)
Definition: uart.c:27
unsigned char uart_rx_byte(unsigned int idx)
Definition: uart.c:17
void uart_fill_lb(void *data)
Definition: uart.c:31
void uart_tx_byte(unsigned int idx, unsigned char data)
Definition: uart.c:22
@ GPIO_NO_PULL
Definition: gpio_common.h:62
@ BLSP1_UART2
Definition: iomap.h:82
#define UART2_DM_BASE
Definition: iomap.h:78
uintptr_t base
Definition: uart.c:17
unsigned int uart_platform_refclk(void)
Definition: uart.c:85
void gpio_configure(gpio_t gpio, uint32_t func, uint32_t pull, uint32_t drive_str, uint32_t enable)
Definition: gpio.c:7
#define GPIO_PULL_UP
Definition: gpio.h:24
static int valid_data
Definition: uart.c:85
static unsigned int word
Definition: uart.c:88
void clock_enable_uart(void)
Definition: clock.c:246
void clock_configure_uart(uint32_t hz)
Definition: clock.c:190
unsigned int msm_boot_uart_dm_init(void *uart_dm_base)
msm_boot_uart_dm_init - initilaizes UART controller
Definition: uart.c:132
static unsigned int msm_boot_uart_dm_reset(void *base)
msm_boot_uart_dm_reset - resets UART controller
Definition: uart.c:116
void ipq_configure_gpio(const gpio_func_data_t *gpio, unsigned int count)
Definition: uart.c:24
void qcs405_uart_init(void)
Definition: uart.c:224
static const uart_params_t uart_board_param
Definition: uart.c:35
static unsigned int msm_boot_uart_dm_init_rx_transfer(void *uart_dm_base)
msm_boot_uart_dm_init_rx_transfer - Init Rx transfer
Definition: uart.c:60
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
Definition: pinmux.c:36
unsigned int func
Definition: pinmux.c:38
unsigned int pull
Definition: pinmux.c:39
void * uart_dm_base
Definition: uart.c:17
gpio_func_data_t dbg_uart_gpio[NO_OF_DBG_UART_GPIOS]
Definition: uart.c:20
void udelay(uint32_t us)
Definition: udelay.c:15
#define count