Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 1 | /* |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 2 | * Atheros AR913X/AR933X SoC built-in WMAC device support |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 3 | * |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 4 | * Copyright (C) 2010-2011 Jaiganesh Narayanan <jnarayanan@atheros.com> |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org> |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 6 | * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org> |
| 7 | * |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 8 | * Parts of this file are based on Atheros 2.6.15/2.6.31 BSP |
| 9 | * |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License version 2 as published |
| 12 | * by the Free Software Foundation. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/irq.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/ath9k_platform.h> |
| 20 | |
| 21 | #include <asm/mach-ath79/ath79.h> |
| 22 | #include <asm/mach-ath79/ar71xx_regs.h> |
Gabor Juhos | 009b9d5 | 2011-11-18 00:17:54 +0000 | [diff] [blame] | 23 | #include "dev-wmac.h" |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 24 | |
Gabor Juhos | 67b0f0f | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 25 | static struct ath9k_platform_data ath79_wmac_data; |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 26 | |
Gabor Juhos | 67b0f0f | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 27 | static struct resource ath79_wmac_resources[] = { |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 28 | { |
Gabor Juhos | 6903bb4 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 29 | /* .start and .end fields are filled dynamically */ |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 30 | .flags = IORESOURCE_MEM, |
| 31 | }, { |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 32 | /* .start and .end fields are filled dynamically */ |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 33 | .flags = IORESOURCE_IRQ, |
| 34 | }, |
| 35 | }; |
| 36 | |
Gabor Juhos | 67b0f0f | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 37 | static struct platform_device ath79_wmac_device = { |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 38 | .name = "ath9k", |
| 39 | .id = -1, |
Gabor Juhos | 67b0f0f | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 40 | .resource = ath79_wmac_resources, |
| 41 | .num_resources = ARRAY_SIZE(ath79_wmac_resources), |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 42 | .dev = { |
Gabor Juhos | 67b0f0f | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 43 | .platform_data = &ath79_wmac_data, |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 44 | }, |
| 45 | }; |
| 46 | |
Gabor Juhos | 6903bb4 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 47 | static void __init ar913x_wmac_setup(void) |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 48 | { |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 49 | /* reset the WMAC */ |
| 50 | ath79_device_reset_set(AR913X_RESET_AMBA2WMAC); |
| 51 | mdelay(10); |
| 52 | |
| 53 | ath79_device_reset_clear(AR913X_RESET_AMBA2WMAC); |
| 54 | mdelay(10); |
| 55 | |
Gabor Juhos | 6903bb4 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 56 | ath79_wmac_resources[0].start = AR913X_WMAC_BASE; |
| 57 | ath79_wmac_resources[0].end = AR913X_WMAC_BASE + AR913X_WMAC_SIZE - 1; |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 58 | ath79_wmac_resources[1].start = ATH79_CPU_IRQ_IP2; |
| 59 | ath79_wmac_resources[1].end = ATH79_CPU_IRQ_IP2; |
Gabor Juhos | 6903bb4 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 62 | |
| 63 | static int ar933x_wmac_reset(void) |
| 64 | { |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 65 | ath79_device_reset_set(AR933X_RESET_WMAC); |
Gabor Juhos | de14ca6 | 2012-03-14 10:28:35 +0100 | [diff] [blame] | 66 | ath79_device_reset_clear(AR933X_RESET_WMAC); |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static int ar933x_r1_get_wmac_revision(void) |
| 72 | { |
| 73 | return ath79_soc_rev; |
| 74 | } |
| 75 | |
| 76 | static void __init ar933x_wmac_setup(void) |
| 77 | { |
| 78 | u32 t; |
| 79 | |
| 80 | ar933x_wmac_reset(); |
| 81 | |
| 82 | ath79_wmac_device.name = "ar933x_wmac"; |
| 83 | |
| 84 | ath79_wmac_resources[0].start = AR933X_WMAC_BASE; |
| 85 | ath79_wmac_resources[0].end = AR933X_WMAC_BASE + AR933X_WMAC_SIZE - 1; |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 86 | ath79_wmac_resources[1].start = ATH79_CPU_IRQ_IP2; |
| 87 | ath79_wmac_resources[1].end = ATH79_CPU_IRQ_IP2; |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 88 | |
| 89 | t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP); |
| 90 | if (t & AR933X_BOOTSTRAP_REF_CLK_40) |
| 91 | ath79_wmac_data.is_clk_25mhz = false; |
| 92 | else |
| 93 | ath79_wmac_data.is_clk_25mhz = true; |
| 94 | |
| 95 | if (ath79_soc_rev == 1) |
| 96 | ath79_wmac_data.get_mac_revision = ar933x_r1_get_wmac_revision; |
| 97 | |
| 98 | ath79_wmac_data.external_reset = ar933x_wmac_reset; |
| 99 | } |
| 100 | |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 101 | static void ar934x_wmac_setup(void) |
| 102 | { |
| 103 | u32 t; |
| 104 | |
| 105 | ath79_wmac_device.name = "ar934x_wmac"; |
| 106 | |
| 107 | ath79_wmac_resources[0].start = AR934X_WMAC_BASE; |
| 108 | ath79_wmac_resources[0].end = AR934X_WMAC_BASE + AR934X_WMAC_SIZE - 1; |
| 109 | ath79_wmac_resources[1].start = ATH79_IP2_IRQ(1); |
| 110 | ath79_wmac_resources[1].start = ATH79_IP2_IRQ(1); |
| 111 | |
| 112 | t = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP); |
| 113 | if (t & AR934X_BOOTSTRAP_REF_CLK_40) |
| 114 | ath79_wmac_data.is_clk_25mhz = false; |
| 115 | else |
| 116 | ath79_wmac_data.is_clk_25mhz = true; |
| 117 | } |
| 118 | |
Gabor Juhos | 6903bb4 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 119 | void __init ath79_register_wmac(u8 *cal_data) |
| 120 | { |
| 121 | if (soc_is_ar913x()) |
| 122 | ar913x_wmac_setup(); |
Gabor Juhos | 87b4345 | 2011-12-11 16:11:41 +0100 | [diff] [blame] | 123 | else if (soc_is_ar933x()) |
Gabor Juhos | 34cfcd2 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 124 | ar933x_wmac_setup(); |
Gabor Juhos | 574d6e7 | 2012-03-14 10:45:28 +0100 | [diff] [blame^] | 125 | else if (soc_is_ar934x()) |
| 126 | ar934x_wmac_setup(); |
Gabor Juhos | 6903bb4 | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 127 | else |
| 128 | BUG(); |
| 129 | |
| 130 | if (cal_data) |
| 131 | memcpy(ath79_wmac_data.eeprom_data, cal_data, |
| 132 | sizeof(ath79_wmac_data.eeprom_data)); |
| 133 | |
Gabor Juhos | 67b0f0f | 2011-11-18 00:17:53 +0000 | [diff] [blame] | 134 | platform_device_register(&ath79_wmac_device); |
Gabor Juhos | f5b35d0 | 2011-01-04 21:28:29 +0100 | [diff] [blame] | 135 | } |