]>
Commit | Line | Data |
---|---|---|
09329d37 | 1 | /* |
5b68138e | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
09329d37 GJ |
3 | * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org> |
4 | * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org> | |
5 | * | |
6 | * Permission to use, copy, modify, and/or distribute this software for any | |
7 | * purpose with or without fee is hereby granted, provided that the above | |
8 | * copyright notice and this permission notice appear in all copies. | |
9 | * | |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 | */ | |
18 | ||
19 | #include <linux/nl80211.h> | |
20 | #include <linux/platform_device.h> | |
9dbeb91a | 21 | #include <linux/ath9k_platform.h> |
9d9779e7 | 22 | #include <linux/module.h> |
394cf0a1 | 23 | #include "ath9k.h" |
09329d37 | 24 | |
0a6c9b1b | 25 | static const struct platform_device_id ath9k_platform_id_table[] = { |
6f11c819 VT |
26 | { |
27 | .name = "ath9k", | |
28 | .driver_data = AR5416_AR9100_DEVID, | |
29 | }, | |
e9b7c591 GJ |
30 | { |
31 | .name = "ar933x_wmac", | |
32 | .driver_data = AR9300_DEVID_AR9330, | |
33 | }, | |
247eee0e VT |
34 | { |
35 | .name = "ar934x_wmac", | |
36 | .driver_data = AR9300_DEVID_AR9340, | |
37 | }, | |
9476f4d6 GJ |
38 | { |
39 | .name = "qca955x_wmac", | |
40 | .driver_data = AR9300_DEVID_QCA955X, | |
41 | }, | |
c08148bb SM |
42 | { |
43 | .name = "qca953x_wmac", | |
44 | .driver_data = AR9300_DEVID_AR953X, | |
45 | }, | |
2131fabb MP |
46 | { |
47 | .name = "qca956x_wmac", | |
48 | .driver_data = AR9300_DEVID_QCA956X, | |
49 | }, | |
6f11c819 VT |
50 | {}, |
51 | }; | |
52 | ||
09329d37 | 53 | /* return bus cachesize in 4B word units */ |
5bb12791 | 54 | static void ath_ahb_read_cachesize(struct ath_common *common, int *csz) |
09329d37 GJ |
55 | { |
56 | *csz = L1_CACHE_BYTES >> 2; | |
57 | } | |
58 | ||
5bb12791 | 59 | static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data) |
9dbeb91a | 60 | { |
e307fcf0 | 61 | struct ath_softc *sc = (struct ath_softc *)common->priv; |
9dbeb91a GJ |
62 | struct platform_device *pdev = to_platform_device(sc->dev); |
63 | struct ath9k_platform_data *pdata; | |
64 | ||
8f616c6d | 65 | pdata = dev_get_platdata(&pdev->dev); |
9dbeb91a | 66 | if (off >= (ARRAY_SIZE(pdata->eeprom_data))) { |
3800276a JP |
67 | ath_err(common, |
68 | "%s: flash read failed, offset %08x is out of range\n", | |
69 | __func__, off); | |
9dbeb91a GJ |
70 | return false; |
71 | } | |
72 | ||
73 | *data = pdata->eeprom_data[off]; | |
74 | return true; | |
75 | } | |
76 | ||
09329d37 | 77 | static struct ath_bus_ops ath_ahb_bus_ops = { |
497ad9ad | 78 | .ath_bus_type = ATH_AHB, |
09329d37 | 79 | .read_cachesize = ath_ahb_read_cachesize, |
9dbeb91a | 80 | .eeprom_read = ath_ahb_eeprom_read, |
09329d37 GJ |
81 | }; |
82 | ||
83 | static int ath_ahb_probe(struct platform_device *pdev) | |
84 | { | |
85 | void __iomem *mem; | |
86 | struct ath_softc *sc; | |
87 | struct ieee80211_hw *hw; | |
88 | struct resource *res; | |
6f11c819 | 89 | const struct platform_device_id *id = platform_get_device_id(pdev); |
09329d37 GJ |
90 | int irq; |
91 | int ret = 0; | |
cbe61d8a | 92 | struct ath_hw *ah; |
f934c4d9 | 93 | char hw_name[64]; |
09329d37 | 94 | |
8f616c6d | 95 | if (!dev_get_platdata(&pdev->dev)) { |
9dbeb91a | 96 | dev_err(&pdev->dev, "no platform data specified\n"); |
b81950b1 | 97 | return -EINVAL; |
9dbeb91a GJ |
98 | } |
99 | ||
09329d37 GJ |
100 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
101 | if (res == NULL) { | |
102 | dev_err(&pdev->dev, "no memory resource found\n"); | |
b81950b1 | 103 | return -ENXIO; |
09329d37 GJ |
104 | } |
105 | ||
b81950b1 | 106 | mem = devm_ioremap_nocache(&pdev->dev, res->start, resource_size(res)); |
09329d37 GJ |
107 | if (mem == NULL) { |
108 | dev_err(&pdev->dev, "ioremap failed\n"); | |
b81950b1 | 109 | return -ENOMEM; |
09329d37 GJ |
110 | } |
111 | ||
112 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | |
113 | if (res == NULL) { | |
114 | dev_err(&pdev->dev, "no IRQ resource found\n"); | |
b81950b1 | 115 | return -ENXIO; |
09329d37 GJ |
116 | } |
117 | ||
118 | irq = res->start; | |
119 | ||
cf9ae8fa | 120 | ath9k_fill_chanctx_ops(); |
9ac58615 | 121 | hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops); |
09329d37 GJ |
122 | if (hw == NULL) { |
123 | dev_err(&pdev->dev, "no memory for ieee80211_hw\n"); | |
b81950b1 | 124 | return -ENOMEM; |
09329d37 GJ |
125 | } |
126 | ||
127 | SET_IEEE80211_DEV(hw, &pdev->dev); | |
128 | platform_set_drvdata(pdev, hw); | |
129 | ||
9ac58615 | 130 | sc = hw->priv; |
09329d37 GJ |
131 | sc->hw = hw; |
132 | sc->dev = &pdev->dev; | |
133 | sc->mem = mem; | |
09329d37 GJ |
134 | sc->irq = irq; |
135 | ||
285f2dda | 136 | ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc); |
580171f7 | 137 | if (ret) { |
285f2dda | 138 | dev_err(&pdev->dev, "request_irq failed\n"); |
09329d37 GJ |
139 | goto err_free_hw; |
140 | } | |
141 | ||
eb93e891 | 142 | ret = ath9k_init_device(id->driver_data, sc, &ath_ahb_bus_ops); |
09329d37 | 143 | if (ret) { |
285f2dda S |
144 | dev_err(&pdev->dev, "failed to initialize device\n"); |
145 | goto err_irq; | |
09329d37 GJ |
146 | } |
147 | ||
148 | ah = sc->sc_ah; | |
f934c4d9 | 149 | ath9k_hw_name(ah, hw_name, sizeof(hw_name)); |
c96c31e4 JP |
150 | wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n", |
151 | hw_name, (unsigned long)mem, irq); | |
09329d37 GJ |
152 | |
153 | return 0; | |
154 | ||
285f2dda S |
155 | err_irq: |
156 | free_irq(irq, sc); | |
09329d37 GJ |
157 | err_free_hw: |
158 | ieee80211_free_hw(hw); | |
09329d37 GJ |
159 | return ret; |
160 | } | |
161 | ||
162 | static int ath_ahb_remove(struct platform_device *pdev) | |
163 | { | |
164 | struct ieee80211_hw *hw = platform_get_drvdata(pdev); | |
165 | ||
166 | if (hw) { | |
9ac58615 | 167 | struct ath_softc *sc = hw->priv; |
09329d37 | 168 | |
285f2dda S |
169 | ath9k_deinit_device(sc); |
170 | free_irq(sc->irq, sc); | |
171 | ieee80211_free_hw(sc->hw); | |
09329d37 GJ |
172 | } |
173 | ||
174 | return 0; | |
175 | } | |
176 | ||
177 | static struct platform_driver ath_ahb_driver = { | |
178 | .probe = ath_ahb_probe, | |
179 | .remove = ath_ahb_remove, | |
180 | .driver = { | |
181 | .name = "ath9k", | |
09329d37 | 182 | }, |
6f11c819 | 183 | .id_table = ath9k_platform_id_table, |
09329d37 GJ |
184 | }; |
185 | ||
6f11c819 VT |
186 | MODULE_DEVICE_TABLE(platform, ath9k_platform_id_table); |
187 | ||
09329d37 GJ |
188 | int ath_ahb_init(void) |
189 | { | |
190 | return platform_driver_register(&ath_ahb_driver); | |
191 | } | |
192 | ||
193 | void ath_ahb_exit(void) | |
194 | { | |
195 | platform_driver_unregister(&ath_ahb_driver); | |
196 | } |