]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/ath9k/ahb.c
ath9k: introduce platform driver for AHB bus support
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / ath9k / ahb.c
CommitLineData
09329d37
GJ
1/*
2 * Copyright (c) 2008 Atheros Communications Inc.
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>
21#include "core.h"
22#include "reg.h"
23#include "hw.h"
24
25/* return bus cachesize in 4B word units */
26static void ath_ahb_read_cachesize(struct ath_softc *sc, int *csz)
27{
28 *csz = L1_CACHE_BYTES >> 2;
29}
30
31static void ath_ahb_cleanup(struct ath_softc *sc)
32{
33 iounmap(sc->mem);
34}
35
36static struct ath_bus_ops ath_ahb_bus_ops = {
37 .read_cachesize = ath_ahb_read_cachesize,
38 .cleanup = ath_ahb_cleanup,
39};
40
41static int ath_ahb_probe(struct platform_device *pdev)
42{
43 void __iomem *mem;
44 struct ath_softc *sc;
45 struct ieee80211_hw *hw;
46 struct resource *res;
47 int irq;
48 int ret = 0;
49 struct ath_hal *ah;
50
51 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
52 if (res == NULL) {
53 dev_err(&pdev->dev, "no memory resource found\n");
54 ret = -ENXIO;
55 goto err_out;
56 }
57
58 mem = ioremap_nocache(res->start, res->end - res->start + 1);
59 if (mem == NULL) {
60 dev_err(&pdev->dev, "ioremap failed\n");
61 ret = -ENOMEM;
62 goto err_out;
63 }
64
65 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
66 if (res == NULL) {
67 dev_err(&pdev->dev, "no IRQ resource found\n");
68 ret = -ENXIO;
69 goto err_iounmap;
70 }
71
72 irq = res->start;
73
74 hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
75 if (hw == NULL) {
76 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
77 ret = -ENOMEM;
78 goto err_iounmap;
79 }
80
81 SET_IEEE80211_DEV(hw, &pdev->dev);
82 platform_set_drvdata(pdev, hw);
83
84 sc = hw->priv;
85 sc->hw = hw;
86 sc->dev = &pdev->dev;
87 sc->mem = mem;
88 sc->bus_ops = &ath_ahb_bus_ops;
89 sc->irq = irq;
90
91 ret = ath_attach(AR5416_AR9100_DEVID, sc);
92 if (ret != 0) {
93 dev_err(&pdev->dev, "failed to attach device, err=%d\n", ret);
94 ret = -ENODEV;
95 goto err_free_hw;
96 }
97
98 ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
99 if (ret) {
100 dev_err(&pdev->dev, "request_irq failed, err=%d\n", ret);
101 ret = -EIO;
102 goto err_detach;
103 }
104
105 ah = sc->sc_ah;
106 printk(KERN_INFO
107 "%s: Atheros AR%s MAC/BB Rev:%x, "
108 "AR%s RF Rev:%x, mem=0x%lx, irq=%d\n",
109 wiphy_name(hw->wiphy),
110 ath_mac_bb_name(ah->ah_macVersion),
111 ah->ah_macRev,
112 ath_rf_name((ah->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR)),
113 ah->ah_phyRev,
114 (unsigned long)mem, irq);
115
116 return 0;
117
118 err_detach:
119 ath_detach(sc);
120 err_free_hw:
121 ieee80211_free_hw(hw);
122 platform_set_drvdata(pdev, NULL);
123 err_iounmap:
124 iounmap(mem);
125 err_out:
126 return ret;
127}
128
129static int ath_ahb_remove(struct platform_device *pdev)
130{
131 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
132
133 if (hw) {
134 struct ath_softc *sc = hw->priv;
135
136 ath_cleanup(sc);
137 platform_set_drvdata(pdev, NULL);
138 }
139
140 return 0;
141}
142
143static struct platform_driver ath_ahb_driver = {
144 .probe = ath_ahb_probe,
145 .remove = ath_ahb_remove,
146 .driver = {
147 .name = "ath9k",
148 .owner = THIS_MODULE,
149 },
150};
151
152int ath_ahb_init(void)
153{
154 return platform_driver_register(&ath_ahb_driver);
155}
156
157void ath_ahb_exit(void)
158{
159 platform_driver_unregister(&ath_ahb_driver);
160}