blob: c3b04c929f29b552014013f253d18e8500faae5b [file] [log] [blame]
Gabor Juhosd4a67d92011-01-04 21:28:14 +01001/*
2 * Atheros AR71XX/AR724X/AR913X common devices
3 *
4 * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Parts of this file are based on Atheros' 2.6.15 BSP
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17#include <linux/serial_8250.h>
18#include <linux/clk.h>
19#include <linux/err.h>
20
21#include <asm/mach-ath79/ath79.h>
22#include <asm/mach-ath79/ar71xx_regs.h>
Gabor Juhos13051c52011-06-20 19:26:12 +020023#include <asm/mach-ath79/ar933x_uart_platform.h>
Gabor Juhosd4a67d92011-01-04 21:28:14 +010024#include "common.h"
25#include "dev-common.h"
26
27static struct resource ath79_uart_resources[] = {
28 {
29 .start = AR71XX_UART_BASE,
30 .end = AR71XX_UART_BASE + AR71XX_UART_SIZE - 1,
31 .flags = IORESOURCE_MEM,
32 },
33};
34
35#define AR71XX_UART_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP)
36static struct plat_serial8250_port ath79_uart_data[] = {
37 {
38 .mapbase = AR71XX_UART_BASE,
Gabor Juhosfd633cf2013-02-07 19:32:24 +000039 .irq = ATH79_MISC_IRQ(3),
Gabor Juhosd4a67d92011-01-04 21:28:14 +010040 .flags = AR71XX_UART_FLAGS,
41 .iotype = UPIO_MEM32,
42 .regshift = 2,
43 }, {
44 /* terminating entry */
45 }
46};
47
48static struct platform_device ath79_uart_device = {
49 .name = "serial8250",
50 .id = PLAT8250_DEV_PLATFORM,
51 .resource = ath79_uart_resources,
52 .num_resources = ARRAY_SIZE(ath79_uart_resources),
53 .dev = {
54 .platform_data = ath79_uart_data
55 },
56};
57
Gabor Juhos13051c52011-06-20 19:26:12 +020058static struct resource ar933x_uart_resources[] = {
59 {
60 .start = AR933X_UART_BASE,
61 .end = AR933X_UART_BASE + AR71XX_UART_SIZE - 1,
62 .flags = IORESOURCE_MEM,
63 },
64 {
Gabor Juhosfd633cf2013-02-07 19:32:24 +000065 .start = ATH79_MISC_IRQ(3),
66 .end = ATH79_MISC_IRQ(3),
Gabor Juhos13051c52011-06-20 19:26:12 +020067 .flags = IORESOURCE_IRQ,
68 },
69};
70
71static struct ar933x_uart_platform_data ar933x_uart_data;
72static struct platform_device ar933x_uart_device = {
73 .name = "ar933x-uart",
74 .id = -1,
75 .resource = ar933x_uart_resources,
76 .num_resources = ARRAY_SIZE(ar933x_uart_resources),
77 .dev = {
78 .platform_data = &ar933x_uart_data,
79 },
80};
81
Gabor Juhosd4a67d92011-01-04 21:28:14 +010082void __init ath79_register_uart(void)
83{
Gabor Juhos23107802013-08-28 10:41:44 +020084 unsigned long uart_clk_rate;
Gabor Juhosd4a67d92011-01-04 21:28:14 +010085
Gabor Juhos23107802013-08-28 10:41:44 +020086 uart_clk_rate = ath79_get_sys_clk_rate("uart");
Gabor Juhosd4a67d92011-01-04 21:28:14 +010087
Gabor Juhos13051c52011-06-20 19:26:12 +020088 if (soc_is_ar71xx() ||
89 soc_is_ar724x() ||
Gabor Juhos9800bdc2012-03-14 10:45:27 +010090 soc_is_ar913x() ||
Gabor Juhos13992302013-02-15 13:38:21 +000091 soc_is_ar934x() ||
92 soc_is_qca955x()) {
Gabor Juhos23107802013-08-28 10:41:44 +020093 ath79_uart_data[0].uartclk = uart_clk_rate;
Gabor Juhos13051c52011-06-20 19:26:12 +020094 platform_device_register(&ath79_uart_device);
95 } else if (soc_is_ar933x()) {
Gabor Juhos23107802013-08-28 10:41:44 +020096 ar933x_uart_data.uartclk = uart_clk_rate;
Gabor Juhos13051c52011-06-20 19:26:12 +020097 platform_device_register(&ar933x_uart_device);
98 } else {
99 BUG();
100 }
Gabor Juhosd4a67d92011-01-04 21:28:14 +0100101}
Gabor Juhos858f7632011-01-04 21:28:20 +0100102
Gabor Juhos858f7632011-01-04 21:28:20 +0100103void __init ath79_register_wdt(void)
104{
Gabor Juhos09f51002012-12-27 15:38:26 +0100105 struct resource res;
106
107 memset(&res, 0, sizeof(res));
108
109 res.flags = IORESOURCE_MEM;
110 res.start = AR71XX_RESET_BASE + AR71XX_RESET_REG_WDOG_CTRL;
111 res.end = res.start + 0x8 - 1;
112
113 platform_device_register_simple("ath79-wdt", -1, &res, 1);
Gabor Juhos858f7632011-01-04 21:28:20 +0100114}