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