Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 1 | /* |
| 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> |
Alban Bedel | 2ddf3a7 | 2015-05-31 02:18:24 +0200 | [diff] [blame] | 17 | #include <linux/platform_data/gpio-ath79.h> |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 18 | #include <linux/serial_8250.h> |
| 19 | #include <linux/clk.h> |
| 20 | #include <linux/err.h> |
| 21 | |
| 22 | #include <asm/mach-ath79/ath79.h> |
| 23 | #include <asm/mach-ath79/ar71xx_regs.h> |
| 24 | #include "common.h" |
| 25 | #include "dev-common.h" |
| 26 | |
| 27 | static 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) |
| 36 | static struct plat_serial8250_port ath79_uart_data[] = { |
| 37 | { |
| 38 | .mapbase = AR71XX_UART_BASE, |
Gabor Juhos | fd633cf | 2013-02-07 19:32:24 +0000 | [diff] [blame] | 39 | .irq = ATH79_MISC_IRQ(3), |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 40 | .flags = AR71XX_UART_FLAGS, |
| 41 | .iotype = UPIO_MEM32, |
| 42 | .regshift = 2, |
| 43 | }, { |
| 44 | /* terminating entry */ |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | static 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 Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 58 | static 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 Juhos | fd633cf | 2013-02-07 19:32:24 +0000 | [diff] [blame] | 65 | .start = ATH79_MISC_IRQ(3), |
| 66 | .end = ATH79_MISC_IRQ(3), |
Gabor Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 67 | .flags = IORESOURCE_IRQ, |
| 68 | }, |
| 69 | }; |
| 70 | |
Gabor Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 71 | static struct platform_device ar933x_uart_device = { |
| 72 | .name = "ar933x-uart", |
| 73 | .id = -1, |
| 74 | .resource = ar933x_uart_resources, |
| 75 | .num_resources = ARRAY_SIZE(ar933x_uart_resources), |
Gabor Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 78 | void __init ath79_register_uart(void) |
| 79 | { |
Gabor Juhos | 2310780 | 2013-08-28 10:41:44 +0200 | [diff] [blame] | 80 | unsigned long uart_clk_rate; |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 81 | |
Gabor Juhos | 2310780 | 2013-08-28 10:41:44 +0200 | [diff] [blame] | 82 | uart_clk_rate = ath79_get_sys_clk_rate("uart"); |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 83 | |
Gabor Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 84 | if (soc_is_ar71xx() || |
| 85 | soc_is_ar724x() || |
Gabor Juhos | 9800bdc | 2012-03-14 10:45:27 +0100 | [diff] [blame] | 86 | soc_is_ar913x() || |
Gabor Juhos | 1399230 | 2013-02-15 13:38:21 +0000 | [diff] [blame] | 87 | soc_is_ar934x() || |
| 88 | soc_is_qca955x()) { |
Gabor Juhos | 2310780 | 2013-08-28 10:41:44 +0200 | [diff] [blame] | 89 | ath79_uart_data[0].uartclk = uart_clk_rate; |
Gabor Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 90 | platform_device_register(&ath79_uart_device); |
| 91 | } else if (soc_is_ar933x()) { |
Gabor Juhos | 13051c5 | 2011-06-20 19:26:12 +0200 | [diff] [blame] | 92 | platform_device_register(&ar933x_uart_device); |
| 93 | } else { |
| 94 | BUG(); |
| 95 | } |
Gabor Juhos | d4a67d9 | 2011-01-04 21:28:14 +0100 | [diff] [blame] | 96 | } |
Gabor Juhos | 858f763 | 2011-01-04 21:28:20 +0100 | [diff] [blame] | 97 | |
Gabor Juhos | 858f763 | 2011-01-04 21:28:20 +0100 | [diff] [blame] | 98 | void __init ath79_register_wdt(void) |
| 99 | { |
Gabor Juhos | 09f5100 | 2012-12-27 15:38:26 +0100 | [diff] [blame] | 100 | struct resource res; |
| 101 | |
| 102 | memset(&res, 0, sizeof(res)); |
| 103 | |
| 104 | res.flags = IORESOURCE_MEM; |
| 105 | res.start = AR71XX_RESET_BASE + AR71XX_RESET_REG_WDOG_CTRL; |
| 106 | res.end = res.start + 0x8 - 1; |
| 107 | |
| 108 | platform_device_register_simple("ath79-wdt", -1, &res, 1); |
Gabor Juhos | 858f763 | 2011-01-04 21:28:20 +0100 | [diff] [blame] | 109 | } |
Alban Bedel | 2ddf3a7 | 2015-05-31 02:18:24 +0200 | [diff] [blame] | 110 | |
| 111 | static struct ath79_gpio_platform_data ath79_gpio_pdata; |
| 112 | |
| 113 | static struct resource ath79_gpio_resources[] = { |
| 114 | { |
| 115 | .flags = IORESOURCE_MEM, |
| 116 | .start = AR71XX_GPIO_BASE, |
| 117 | .end = AR71XX_GPIO_BASE + AR71XX_GPIO_SIZE - 1, |
| 118 | }, |
| 119 | { |
| 120 | .start = ATH79_MISC_IRQ(2), |
| 121 | .end = ATH79_MISC_IRQ(2), |
| 122 | .flags = IORESOURCE_IRQ, |
| 123 | }, |
| 124 | }; |
| 125 | |
| 126 | static struct platform_device ath79_gpio_device = { |
| 127 | .name = "ath79-gpio", |
| 128 | .id = -1, |
| 129 | .resource = ath79_gpio_resources, |
| 130 | .num_resources = ARRAY_SIZE(ath79_gpio_resources), |
| 131 | .dev = { |
| 132 | .platform_data = &ath79_gpio_pdata |
| 133 | }, |
| 134 | }; |
| 135 | |
| 136 | void __init ath79_gpio_init(void) |
| 137 | { |
| 138 | if (soc_is_ar71xx()) { |
| 139 | ath79_gpio_pdata.ngpios = AR71XX_GPIO_COUNT; |
| 140 | } else if (soc_is_ar7240()) { |
| 141 | ath79_gpio_pdata.ngpios = AR7240_GPIO_COUNT; |
| 142 | } else if (soc_is_ar7241() || soc_is_ar7242()) { |
| 143 | ath79_gpio_pdata.ngpios = AR7241_GPIO_COUNT; |
| 144 | } else if (soc_is_ar913x()) { |
| 145 | ath79_gpio_pdata.ngpios = AR913X_GPIO_COUNT; |
| 146 | } else if (soc_is_ar933x()) { |
| 147 | ath79_gpio_pdata.ngpios = AR933X_GPIO_COUNT; |
| 148 | } else if (soc_is_ar934x()) { |
| 149 | ath79_gpio_pdata.ngpios = AR934X_GPIO_COUNT; |
| 150 | ath79_gpio_pdata.oe_inverted = 1; |
| 151 | } else if (soc_is_qca955x()) { |
| 152 | ath79_gpio_pdata.ngpios = QCA955X_GPIO_COUNT; |
| 153 | ath79_gpio_pdata.oe_inverted = 1; |
| 154 | } else { |
| 155 | BUG(); |
| 156 | } |
| 157 | |
| 158 | platform_device_register(&ath79_gpio_device); |
| 159 | } |