1 From 84ead7964e423c37a73da30a1a2c4c486f74242d Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Mon, 20 Jun 2011 21:26:03 +0200
4 Subject: [PATCH 06/27] MIPS: ath79: Add early printk support for the AR933X SoCs
6 The AR933X SoCs are using a different UART, thus require
7 different code for early printk support.
9 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
10 Cc: linux-mips@linux-mips.org
11 Cc: Kathy Giori <kgiori@qca.qualcomm.com>
12 Cc: "Luis R. Rodriguez" <rodrigue@qca.qualcomm.com>
13 Patchwork: https://patchwork.linux-mips.org/patch/2521/
14 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
16 arch/mips/ath79/early_printk.c | 76 +++++++++++++++++++++---
17 arch/mips/include/asm/mach-ath79/ar71xx_regs.h | 3 +
18 arch/mips/include/asm/mach-ath79/ar933x_uart.h | 67 +++++++++++++++++++++
19 3 files changed, 137 insertions(+), 9 deletions(-)
20 create mode 100644 arch/mips/include/asm/mach-ath79/ar933x_uart.h
22 --- a/arch/mips/ath79/early_printk.c
23 +++ b/arch/mips/ath79/early_printk.c
26 - * Atheros AR71XX/AR724X/AR913X SoC early printk support
27 + * Atheros AR7XXX/AR9XXX SoC early printk support
29 - * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
30 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
31 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
33 * This program is free software; you can redistribute it and/or modify it
38 +#include <linux/errno.h>
39 #include <linux/serial_reg.h>
40 #include <asm/addrspace.h>
42 +#include <asm/mach-ath79/ath79.h>
43 #include <asm/mach-ath79/ar71xx_regs.h>
44 +#include <asm/mach-ath79/ar933x_uart.h>
46 -static inline void prom_wait_thre(void __iomem *base)
47 +static void (*_prom_putchar) (unsigned char);
49 +static inline void prom_putchar_wait(void __iomem *reg, u32 mask, u32 val)
55 - lsr = __raw_readl(base + UART_LSR * 4);
56 - if (lsr & UART_LSR_THRE)
57 + t = __raw_readl(reg);
58 + if ((t & mask) == val)
63 -void prom_putchar(unsigned char ch)
64 +static void prom_putchar_ar71xx(unsigned char ch)
66 void __iomem *base = (void __iomem *)(KSEG1ADDR(AR71XX_UART_BASE));
68 - prom_wait_thre(base);
69 + prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
70 __raw_writel(ch, base + UART_TX * 4);
71 - prom_wait_thre(base);
72 + prom_putchar_wait(base + UART_LSR * 4, UART_LSR_THRE, UART_LSR_THRE);
75 +static void prom_putchar_ar933x(unsigned char ch)
77 + void __iomem *base = (void __iomem *)(KSEG1ADDR(AR933X_UART_BASE));
79 + prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
80 + AR933X_UART_DATA_TX_CSR);
81 + __raw_writel(AR933X_UART_DATA_TX_CSR | ch, base + AR933X_UART_DATA_REG);
82 + prom_putchar_wait(base + AR933X_UART_DATA_REG, AR933X_UART_DATA_TX_CSR,
83 + AR933X_UART_DATA_TX_CSR);
86 +static void prom_putchar_dummy(unsigned char ch)
91 +static void prom_putchar_init(void)
96 + base = (void __iomem *)(KSEG1ADDR(AR71XX_RESET_BASE));
97 + id = __raw_readl(base + AR71XX_RESET_REG_REV_ID);
98 + id &= REV_ID_MAJOR_MASK;
101 + case REV_ID_MAJOR_AR71XX:
102 + case REV_ID_MAJOR_AR7240:
103 + case REV_ID_MAJOR_AR7241:
104 + case REV_ID_MAJOR_AR7242:
105 + case REV_ID_MAJOR_AR913X:
106 + _prom_putchar = prom_putchar_ar71xx;
109 + case REV_ID_MAJOR_AR9330:
110 + case REV_ID_MAJOR_AR9331:
111 + _prom_putchar = prom_putchar_ar933x;
115 + _prom_putchar = prom_putchar_dummy;
120 +void prom_putchar(unsigned char ch)
122 + if (!_prom_putchar)
123 + prom_putchar_init();
127 --- a/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
128 +++ b/arch/mips/include/asm/mach-ath79/ar71xx_regs.h
130 #define AR913X_WMAC_BASE (AR71XX_APB_BASE + 0x000C0000)
131 #define AR913X_WMAC_SIZE 0x30000
133 +#define AR933X_UART_BASE (AR71XX_APB_BASE + 0x00020000)
134 +#define AR933X_UART_SIZE 0x14
140 +++ b/arch/mips/include/asm/mach-ath79/ar933x_uart.h
143 + * Atheros AR933X UART defines
145 + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
147 + * This program is free software; you can redistribute it and/or modify it
148 + * under the terms of the GNU General Public License version 2 as published
149 + * by the Free Software Foundation.
152 +#ifndef __AR933X_UART_H
153 +#define __AR933X_UART_H
155 +#define AR933X_UART_REGS_SIZE 20
156 +#define AR933X_UART_FIFO_SIZE 16
158 +#define AR933X_UART_DATA_REG 0x00
159 +#define AR933X_UART_CS_REG 0x04
160 +#define AR933X_UART_CLOCK_REG 0x08
161 +#define AR933X_UART_INT_REG 0x0c
162 +#define AR933X_UART_INT_EN_REG 0x10
164 +#define AR933X_UART_DATA_TX_RX_MASK 0xff
165 +#define AR933X_UART_DATA_RX_CSR BIT(8)
166 +#define AR933X_UART_DATA_TX_CSR BIT(9)
168 +#define AR933X_UART_CS_PARITY_S 0
169 +#define AR933X_UART_CS_PARITY_M 0x3
170 +#define AR933X_UART_CS_PARITY_NONE 0
171 +#define AR933X_UART_CS_PARITY_ODD 1
172 +#define AR933X_UART_CS_PARITY_EVEN 2
173 +#define AR933X_UART_CS_IF_MODE_S 2
174 +#define AR933X_UART_CS_IF_MODE_M 0x3
175 +#define AR933X_UART_CS_IF_MODE_NONE 0
176 +#define AR933X_UART_CS_IF_MODE_DTE 1
177 +#define AR933X_UART_CS_IF_MODE_DCE 2
178 +#define AR933X_UART_CS_FLOW_CTRL_S 4
179 +#define AR933X_UART_CS_FLOW_CTRL_M 0x3
180 +#define AR933X_UART_CS_DMA_EN BIT(6)
181 +#define AR933X_UART_CS_TX_READY_ORIDE BIT(7)
182 +#define AR933X_UART_CS_RX_READY_ORIDE BIT(8)
183 +#define AR933X_UART_CS_TX_READY BIT(9)
184 +#define AR933X_UART_CS_RX_BREAK BIT(10)
185 +#define AR933X_UART_CS_TX_BREAK BIT(11)
186 +#define AR933X_UART_CS_HOST_INT BIT(12)
187 +#define AR933X_UART_CS_HOST_INT_EN BIT(13)
188 +#define AR933X_UART_CS_TX_BUSY BIT(14)
189 +#define AR933X_UART_CS_RX_BUSY BIT(15)
191 +#define AR933X_UART_CLOCK_STEP_M 0xffff
192 +#define AR933X_UART_CLOCK_SCALE_M 0xfff
193 +#define AR933X_UART_CLOCK_SCALE_S 16
194 +#define AR933X_UART_CLOCK_STEP_M 0xffff
196 +#define AR933X_UART_INT_RX_VALID BIT(0)
197 +#define AR933X_UART_INT_TX_READY BIT(1)
198 +#define AR933X_UART_INT_RX_FRAMING_ERR BIT(2)
199 +#define AR933X_UART_INT_RX_OFLOW_ERR BIT(3)
200 +#define AR933X_UART_INT_TX_OFLOW_ERR BIT(4)
201 +#define AR933X_UART_INT_RX_PARITY_ERR BIT(5)
202 +#define AR933X_UART_INT_RX_BREAK_ON BIT(6)
203 +#define AR933X_UART_INT_RX_BREAK_OFF BIT(7)
204 +#define AR933X_UART_INT_RX_FULL BIT(8)
205 +#define AR933X_UART_INT_TX_EMPTY BIT(9)
206 +#define AR933X_UART_INT_ALLINTS 0x3ff
208 +#endif /* __AR933X_UART_H */