~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/mips/pic32/pic32mzda/early_console.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * Joshua Henderson <joshua.henderson@microchip.com>
  4  * Copyright (C) 2015 Microchip Technology Inc.  All rights reserved.
  5  */
  6 #include <asm/mach-pic32/pic32.h>
  7 #include <asm/fw/fw.h>
  8 #include <asm/setup.h>
  9 
 10 #include "pic32mzda.h"
 11 #include "early_pin.h"
 12 
 13 /* Default early console parameters */
 14 #define EARLY_CONSOLE_PORT      1
 15 #define EARLY_CONSOLE_BAUDRATE  115200
 16 
 17 #define UART_ENABLE             BIT(15)
 18 #define UART_ENABLE_RX          BIT(12)
 19 #define UART_ENABLE_TX          BIT(10)
 20 #define UART_TX_FULL            BIT(9)
 21 
 22 /* UART1(x == 0) - UART6(x == 5) */
 23 #define UART_BASE(x)    ((x) * 0x0200)
 24 #define U_MODE(x)       UART_BASE(x)
 25 #define U_STA(x)        (UART_BASE(x) + 0x10)
 26 #define U_TXR(x)        (UART_BASE(x) + 0x20)
 27 #define U_BRG(x)        (UART_BASE(x) + 0x40)
 28 
 29 static void __iomem *uart_base;
 30 static int console_port = -1;
 31 
 32 static int __init configure_uart_pins(int port)
 33 {
 34         switch (port) {
 35         case 1:
 36                 pic32_pps_input(IN_FUNC_U2RX, IN_RPB0);
 37                 pic32_pps_output(OUT_FUNC_U2TX, OUT_RPG9);
 38                 break;
 39         case 5:
 40                 pic32_pps_input(IN_FUNC_U6RX, IN_RPD0);
 41                 pic32_pps_output(OUT_FUNC_U6TX, OUT_RPB8);
 42                 break;
 43         default:
 44                 return -1;
 45         }
 46 
 47         return 0;
 48 }
 49 
 50 static void __init configure_uart(int port, int baud)
 51 {
 52         u32 pbclk;
 53 
 54         pbclk = pic32_get_pbclk(2);
 55 
 56         __raw_writel(0, uart_base + U_MODE(port));
 57         __raw_writel(((pbclk / baud) / 16) - 1, uart_base + U_BRG(port));
 58         __raw_writel(UART_ENABLE, uart_base + U_MODE(port));
 59         __raw_writel(UART_ENABLE_TX | UART_ENABLE_RX,
 60                      uart_base + PIC32_SET(U_STA(port)));
 61 }
 62 
 63 static void __init setup_early_console(int port, int baud)
 64 {
 65         if (configure_uart_pins(port))
 66                 return;
 67 
 68         console_port = port;
 69         configure_uart(console_port, baud);
 70 }
 71 
 72 static char * __init pic32_getcmdline(void)
 73 {
 74         /*
 75          * arch_mem_init() has not been called yet, so we don't have a real
 76          * command line setup if using CONFIG_CMDLINE_BOOL.
 77          */
 78 #ifdef CONFIG_CMDLINE_OVERRIDE
 79         return CONFIG_CMDLINE;
 80 #else
 81         return fw_getcmdline();
 82 #endif
 83 }
 84 
 85 static int __init get_port_from_cmdline(char *arch_cmdline)
 86 {
 87         char *s;
 88         int port = -1;
 89 
 90         if (!arch_cmdline || *arch_cmdline == '\0')
 91                 goto _out;
 92 
 93         s = strstr(arch_cmdline, "earlyprintk=");
 94         if (s) {
 95                 s = strstr(s, "ttyS");
 96                 if (s)
 97                         s += 4;
 98                 else
 99                         goto _out;
100 
101                 port = (*s) - '';
102         }
103 
104 _out:
105         return port;
106 }
107 
108 static int __init get_baud_from_cmdline(char *arch_cmdline)
109 {
110         char *s;
111         int baud = -1;
112 
113         if (!arch_cmdline || *arch_cmdline == '\0')
114                 goto _out;
115 
116         s = strstr(arch_cmdline, "earlyprintk=");
117         if (s) {
118                 s = strstr(s, "ttyS");
119                 if (s)
120                         s += 6;
121                 else
122                         goto _out;
123 
124                 baud = 0;
125                 while (*s >= '' && *s <= '9')
126                         baud = baud * 10 + *s++ - '';
127         }
128 
129 _out:
130         return baud;
131 }
132 
133 void __init fw_init_early_console(void)
134 {
135         char *arch_cmdline = pic32_getcmdline();
136         int baud, port;
137 
138         uart_base = ioremap(PIC32_BASE_UART, 0xc00);
139 
140         baud = get_baud_from_cmdline(arch_cmdline);
141         port = get_port_from_cmdline(arch_cmdline);
142 
143         if (port == -1)
144                 port = EARLY_CONSOLE_PORT;
145 
146         if (baud == -1)
147                 baud = EARLY_CONSOLE_BAUDRATE;
148 
149         setup_early_console(port, baud);
150 }
151 
152 void prom_putchar(char c)
153 {
154         if (console_port >= 0) {
155                 while (__raw_readl(
156                                 uart_base + U_STA(console_port)) & UART_TX_FULL)
157                         ;
158 
159                 __raw_writel(c, uart_base + U_TXR(console_port));
160         }
161 }
162 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php