]> Git Repo - J-linux.git/blob - drivers/net/wireless/ath/ath5k/ahb.c
Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux...
[J-linux.git] / drivers / net / wireless / ath / ath5k / ahb.c
1 /*
2  * Copyright (c) 2008-2009 Atheros Communications Inc.
3  * Copyright (c) 2009 Gabor Juhos <[email protected]>
4  * Copyright (c) 2009 Imre Kaloz <[email protected]>
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/module.h>
20 #include <linux/nl80211.h>
21 #include <linux/platform_device.h>
22 #include <linux/etherdevice.h>
23 #include <ath25_platform.h>
24 #include "ath5k.h"
25 #include "debug.h"
26 #include "base.h"
27 #include "reg.h"
28
29 /* return bus cachesize in 4B word units */
30 static void ath5k_ahb_read_cachesize(struct ath_common *common, int *csz)
31 {
32         *csz = L1_CACHE_BYTES >> 2;
33 }
34
35 static bool
36 ath5k_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
37 {
38         struct ath5k_hw *ah = common->priv;
39         struct platform_device *pdev = to_platform_device(ah->dev);
40         struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
41         u16 *eeprom, *eeprom_end;
42
43         eeprom = (u16 *) bcfg->radio;
44         eeprom_end = ((void *) bcfg->config) + BOARD_CONFIG_BUFSZ;
45
46         eeprom += off;
47         if (eeprom > eeprom_end)
48                 return false;
49
50         *data = *eeprom;
51         return true;
52 }
53
54 int ath5k_hw_read_srev(struct ath5k_hw *ah)
55 {
56         struct platform_device *pdev = to_platform_device(ah->dev);
57         struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
58         ah->ah_mac_srev = bcfg->devid;
59         return 0;
60 }
61
62 static int ath5k_ahb_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
63 {
64         struct platform_device *pdev = to_platform_device(ah->dev);
65         struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
66         u8 *cfg_mac;
67
68         if (to_platform_device(ah->dev)->id == 0)
69                 cfg_mac = bcfg->config->wlan0_mac;
70         else
71                 cfg_mac = bcfg->config->wlan1_mac;
72
73         memcpy(mac, cfg_mac, ETH_ALEN);
74         return 0;
75 }
76
77 static const struct ath_bus_ops ath_ahb_bus_ops = {
78         .ath_bus_type = ATH_AHB,
79         .read_cachesize = ath5k_ahb_read_cachesize,
80         .eeprom_read = ath5k_ahb_eeprom_read,
81         .eeprom_read_mac = ath5k_ahb_eeprom_read_mac,
82 };
83
84 /*Initialization*/
85 static int ath_ahb_probe(struct platform_device *pdev)
86 {
87         struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
88         struct ath5k_hw *ah;
89         struct ieee80211_hw *hw;
90         struct resource *res;
91         void __iomem *mem;
92         int irq;
93         int ret = 0;
94         u32 reg;
95
96         if (!dev_get_platdata(&pdev->dev)) {
97                 dev_err(&pdev->dev, "no platform data specified\n");
98                 ret = -EINVAL;
99                 goto err_out;
100         }
101
102         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
103         if (res == NULL) {
104                 dev_err(&pdev->dev, "no memory resource found\n");
105                 ret = -ENXIO;
106                 goto err_out;
107         }
108
109         mem = ioremap(res->start, resource_size(res));
110         if (mem == NULL) {
111                 dev_err(&pdev->dev, "ioremap failed\n");
112                 ret = -ENOMEM;
113                 goto err_out;
114         }
115
116         irq = platform_get_irq(pdev, 0);
117         if (irq < 0) {
118                 dev_err(&pdev->dev, "no IRQ resource found: %d\n", irq);
119                 ret = irq;
120                 goto err_iounmap;
121         }
122
123         hw = ieee80211_alloc_hw(sizeof(struct ath5k_hw), &ath5k_hw_ops);
124         if (hw == NULL) {
125                 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
126                 ret = -ENOMEM;
127                 goto err_iounmap;
128         }
129
130         ah = hw->priv;
131         ah->hw = hw;
132         ah->dev = &pdev->dev;
133         ah->iobase = mem;
134         ah->irq = irq;
135         ah->devid = bcfg->devid;
136
137         if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
138                 /* Enable WMAC AHB arbitration */
139                 reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
140                 reg |= AR5K_AR2315_AHB_ARB_CTL_WLAN;
141                 iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
142
143                 /* Enable global WMAC swapping */
144                 reg = ioread32((void __iomem *) AR5K_AR2315_BYTESWAP);
145                 reg |= AR5K_AR2315_BYTESWAP_WMAC;
146                 iowrite32(reg, (void __iomem *) AR5K_AR2315_BYTESWAP);
147         } else {
148                 /* Enable WMAC DMA access (assuming 5312 or 231x*/
149                 /* TODO: check other platforms */
150                 reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
151                 if (to_platform_device(ah->dev)->id == 0)
152                         reg |= AR5K_AR5312_ENABLE_WLAN0;
153                 else
154                         reg |= AR5K_AR5312_ENABLE_WLAN1;
155                 iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
156
157                 /*
158                  * On a dual-band AR5312, the multiband radio is only
159                  * used as pass-through. Disable 2 GHz support in the
160                  * driver for it
161                  */
162                 if (to_platform_device(ah->dev)->id == 0 &&
163                     (bcfg->config->flags & (BD_WLAN0 | BD_WLAN1)) ==
164                      (BD_WLAN1 | BD_WLAN0))
165                         ah->ah_capabilities.cap_needs_2GHz_ovr = true;
166                 else
167                         ah->ah_capabilities.cap_needs_2GHz_ovr = false;
168         }
169
170         ret = ath5k_init_ah(ah, &ath_ahb_bus_ops);
171         if (ret != 0) {
172                 dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
173                 ret = -ENODEV;
174                 goto err_free_hw;
175         }
176
177         platform_set_drvdata(pdev, hw);
178
179         return 0;
180
181  err_free_hw:
182         ieee80211_free_hw(hw);
183  err_iounmap:
184         iounmap(mem);
185  err_out:
186         return ret;
187 }
188
189 static int ath_ahb_remove(struct platform_device *pdev)
190 {
191         struct ar231x_board_config *bcfg = dev_get_platdata(&pdev->dev);
192         struct ieee80211_hw *hw = platform_get_drvdata(pdev);
193         struct ath5k_hw *ah;
194         u32 reg;
195
196         if (!hw)
197                 return 0;
198
199         ah = hw->priv;
200
201         if (bcfg->devid >= AR5K_SREV_AR2315_R6) {
202                 /* Disable WMAC AHB arbitration */
203                 reg = ioread32((void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
204                 reg &= ~AR5K_AR2315_AHB_ARB_CTL_WLAN;
205                 iowrite32(reg, (void __iomem *) AR5K_AR2315_AHB_ARB_CTL);
206         } else {
207                 /*Stop DMA access */
208                 reg = ioread32((void __iomem *) AR5K_AR5312_ENABLE);
209                 if (to_platform_device(ah->dev)->id == 0)
210                         reg &= ~AR5K_AR5312_ENABLE_WLAN0;
211                 else
212                         reg &= ~AR5K_AR5312_ENABLE_WLAN1;
213                 iowrite32(reg, (void __iomem *) AR5K_AR5312_ENABLE);
214         }
215
216         ath5k_deinit_ah(ah);
217         iounmap(ah->iobase);
218         ieee80211_free_hw(hw);
219
220         return 0;
221 }
222
223 static struct platform_driver ath_ahb_driver = {
224         .probe      = ath_ahb_probe,
225         .remove     = ath_ahb_remove,
226         .driver         = {
227                 .name   = "ar231x-wmac",
228         },
229 };
230
231 module_platform_driver(ath_ahb_driver);
This page took 0.060648 seconds and 4 git commands to generate.