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/ipq_uart.h>
12 #include <stdint.h>
13 
14 #define FIFO_DATA_SIZE 4
15 
16 typedef struct {
17  void *uart_dm_base;
19  unsigned int blsp_uart;
22 
25  .mnd_value = { 24, 625, 313 },
26  .blsp_uart = BLSP1_UART1,
27  .dbg_uart_gpio = {
28  {
29 #if CONFIG(IPQ_QFN_PART)
30  .gpio = 60,
31  .func = 2,
32 #else /* bga */
33  .gpio = 16,
34  .func = 1,
35 #endif
36  .dir = GPIO_INPUT,
37  .pull = GPIO_NO_PULL,
38  .enable = GPIO_ENABLE
39  },
40  {
41 #if CONFIG(IPQ_QFN_PART)
42  .gpio = 61,
43  .func = 2,
44 #else /* bga */
45  .gpio = 17,
46  .func = 1,
47 #endif
48  .dir = GPIO_OUTPUT,
49  .pull = GPIO_NO_PULL,
50  .enable = GPIO_ENABLE
51  },
52  },
53 };
54 
55 /**
56  * @brief msm_boot_uart_dm_init_rx_transfer - Init Rx transfer
57  * @param uart_dm_base: UART controller base address
58  */
59 static unsigned int msm_boot_uart_dm_init_rx_transfer(void *uart_dm_base)
60 {
61  /* Reset receiver */
62  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
64 
65  /* Enable receiver */
66  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
68  write32(MSM_BOOT_UART_DM_DMRX(uart_dm_base),
70 
71  /* Clear stale event */
72  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
74 
75  /* Enable stale event */
76  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
78 
80 }
81 
82 static unsigned int msm_boot_uart_dm_init(void *uart_dm_base);
83 
84 /* Received data is valid or not */
85 static int valid_data = 0;
86 
87 /* Received data */
88 static unsigned int word = 0;
89 
90 void uart_tx_byte(unsigned int idx, unsigned char data)
91 {
92  int num_of_chars = 1;
94 
95  /* Wait until transmit FIFO is empty. */
96  while (!(read32(MSM_BOOT_UART_DM_SR(base)) &
98  udelay(1);
99  /*
100  * TX FIFO is ready to accept new character(s). First write number of
101  * characters to be transmitted.
102  */
104 
105  /* And now write the character(s) */
106  write32(MSM_BOOT_UART_DM_TF(base, 0), data);
107 }
108 
109 /**
110  * @brief msm_boot_uart_dm_reset - resets UART controller
111  * @param base: UART controller base address
112  */
113 static unsigned int msm_boot_uart_dm_reset(void *base)
114 {
121 
123 }
124 
125 /**
126  * @brief msm_boot_uart_dm_init - initilaizes UART controller
127  * @param uart_dm_base: UART controller base address
128  */
129 unsigned int msm_boot_uart_dm_init(void *uart_dm_base)
130 {
131  /* Configure UART mode registers MR1 and MR2 */
132  /* Hardware flow control isn't supported */
133  write32(MSM_BOOT_UART_DM_MR1(uart_dm_base), 0x0);
134 
135  /* 8-N-1 configuration: 8 data bits - No parity - 1 stop bit */
136  write32(MSM_BOOT_UART_DM_MR2(uart_dm_base),
138 
139  /* Configure Interrupt Mask register IMR */
140  write32(MSM_BOOT_UART_DM_IMR(uart_dm_base),
142 
143  /*
144  * Configure Tx and Rx watermarks configuration registers
145  * TX watermark value is set to 0 - interrupt is generated when
146  * FIFO level is less than or equal to 0
147  */
148  write32(MSM_BOOT_UART_DM_TFWR(uart_dm_base),
150 
151  /* RX watermark value */
152  write32(MSM_BOOT_UART_DM_RFWR(uart_dm_base),
154 
155  /* Configure Interrupt Programming Register */
156  /* Set initial Stale timeout value */
157  write32(MSM_BOOT_UART_DM_IPR(uart_dm_base),
159 
160  /* Configure IRDA if required */
161  /* Disabling IRDA mode */
162  write32(MSM_BOOT_UART_DM_IRDA(uart_dm_base), 0x0);
163 
164  /* Configure hunt character value in HCR register */
165  /* Keep it in reset state */
166  write32(MSM_BOOT_UART_DM_HCR(uart_dm_base), 0x0);
167 
168  /*
169  * Configure Rx FIFO base address
170  * Both TX/RX shares same SRAM and default is half-n-half.
171  * Sticking with default value now.
172  * As such RAM size is (2^RAM_ADDR_WIDTH, 32-bit entries).
173  * We have found RAM_ADDR_WIDTH = 0x7f
174  */
175 
176  /* Issue soft reset command */
177  msm_boot_uart_dm_reset(uart_dm_base);
178 
179  /* Enable/Disable Rx/Tx DM interfaces */
180  /* Data Mover not currently utilized. */
181  write32(MSM_BOOT_UART_DM_DMEN(uart_dm_base), 0x0);
182 
183  /* Enable transmitter */
184  write32(MSM_BOOT_UART_DM_CR(uart_dm_base),
186 
187  /* Initialize Receive Path */
188  msm_boot_uart_dm_init_rx_transfer(uart_dm_base);
189 
190  return 0;
191 }
192 
193 /**
194  * @brief ipq40xx_uart_init - initializes UART
195  *
196  * Initializes clocks, GPIO and UART controller.
197  */
198 void uart_init(unsigned int idx)
199 {
200  /* Note int idx isn't used in this driver. */
201  void *dm_base;
202 
203  dm_base = uart_board_param.uart_dm_base;
204 
206  return; /* UART must have been already initialized. */
207 
210 
211  /* Configure the uart clock */
216 
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 /**
243  * ipq40xx_serial_getc - reads a character
244  *
245  * Returns the character read from serial port.
246  */
247 uint8_t uart_rx_byte(unsigned int idx)
248 {
249  uint8_t byte;
250 
251  byte = (uint8_t)(word & 0xff);
252  word = word >> 8;
253  valid_data--;
254 
255  return byte;
256 }
257 
258 /* TODO: Implement function */
259 void uart_fill_lb(void *data)
260 {
261  struct lb_serial serial;
262 
264  serial.baseaddr = (uint32_t)UART1_DM_BASE;
265  serial.baud = get_uart_baudrate();
266  serial.regwidth = 1;
267  serial.input_hertz = uart_platform_refclk();
268  serial.uart_pci_addr = CONFIG_UART_PCI_ADDR;
269  lb_add_serial(&serial, data);
270 
272 }
#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
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_UART1
Definition: iomap.h:81
#define UART1_DM_BASE
Definition: iomap.h:77
uintptr_t base
Definition: uart.c:17
unsigned int uart_platform_refclk(void)
Definition: uart.c:85
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
#define UART_DM_CLK_RX_TX_BIT_RATE
Definition: clock.h:11
#define GPIO_ENABLE
Definition: gpio.h:38
static unsigned int msm_boot_uart_dm_init(void *uart_dm_base)
msm_boot_uart_dm_init - initilaizes UART controller
Definition: uart.c:129
static unsigned int msm_boot_uart_dm_reset(void *base)
msm_boot_uart_dm_reset - resets UART controller
Definition: uart.c:113
void ipq40xx_uart_init(void)
Definition: uart.c:224
static const uart_params_t uart_board_param
Definition: uart.c:23
static int valid_data
Definition: uart.c:85
static unsigned int word
Definition: uart.c:88
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:59
void ipq_configure_gpio(const gpio_func_data_t *gpio, unsigned int count)
Definition: uart.c:24
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
unsigned int d_value
Definition: cdp.h:38
unsigned int m_value
Definition: cdp.h:36
unsigned int n_value
Definition: cdp.h:37
void * uart_dm_base
Definition: uart.c:17
unsigned int blsp_uart
Definition: uart.c:19
gpio_func_data_t dbg_uart_gpio[NO_OF_DBG_UART_GPIOS]
Definition: uart.c:20
uart_clk_mnd_t mnd_value
Definition: uart.c:18
void udelay(uint32_t us)
Definition: udelay.c:15