1 /*
2 * Copyright (c) 2008-2011 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/mod_devicetable.h>
20 #include <linux/module.h>
21 #include <linux/nl80211.h>
22 #include <linux/of.h>
23 #include <linux/platform_device.h>
24
25 #include "ath9k.h"
26
27 static const struct of_device_id ath9k_of_match_table[] = {
28 { .compatible = "qca,ar9130-wifi", .data = (void *)AR5416_AR9100_DEVID },
29 { .compatible = "qca,ar9330-wifi", .data = (void *)AR9300_DEVID_AR9330 },
30 { .compatible = "qca,ar9340-wifi", .data = (void *)AR9300_DEVID_AR9340 },
31 { .compatible = "qca,qca9530-wifi", .data = (void *)AR9300_DEVID_AR953X },
32 { .compatible = "qca,qca9550-wifi", .data = (void *)AR9300_DEVID_QCA955X },
33 { .compatible = "qca,qca9560-wifi", .data = (void *)AR9300_DEVID_QCA956X },
34 {},
35 };
36
37 /* return bus cachesize in 4B word units */
ath_ahb_read_cachesize(struct ath_common * common,int * csz)38 static void ath_ahb_read_cachesize(struct ath_common *common, int *csz)
39 {
40 *csz = L1_CACHE_BYTES >> 2;
41 }
42
ath_ahb_eeprom_read(struct ath_common * common,u32 off,u16 * data)43 static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
44 {
45 ath_err(common, "%s: eeprom data has to be provided externally\n",
46 __func__);
47 return false;
48 }
49
50 static const struct ath_bus_ops ath_ahb_bus_ops = {
51 .ath_bus_type = ATH_AHB,
52 .read_cachesize = ath_ahb_read_cachesize,
53 .eeprom_read = ath_ahb_eeprom_read,
54 };
55
ath_ahb_probe(struct platform_device * pdev)56 static int ath_ahb_probe(struct platform_device *pdev)
57 {
58 struct ieee80211_hw *hw;
59 struct ath_softc *sc;
60 struct ath_hw *ah;
61 void __iomem *mem;
62 char hw_name[64];
63 u16 dev_id;
64 int irq;
65 int ret;
66
67 mem = devm_platform_ioremap_resource(pdev, 0);
68 if (IS_ERR(mem)) {
69 dev_err(&pdev->dev, "ioremap failed\n");
70 return PTR_ERR(mem);
71 }
72
73 irq = platform_get_irq(pdev, 0);
74 if (irq < 0)
75 return irq;
76
77 ath9k_fill_chanctx_ops();
78 hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
79 if (hw == NULL) {
80 dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
81 return -ENOMEM;
82 }
83
84 SET_IEEE80211_DEV(hw, &pdev->dev);
85 platform_set_drvdata(pdev, hw);
86
87 sc = hw->priv;
88 sc->hw = hw;
89 sc->dev = &pdev->dev;
90 sc->mem = mem;
91 sc->irq = irq;
92
93 ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
94 if (ret) {
95 dev_err(&pdev->dev, "request_irq failed\n");
96 goto err_free_hw;
97 }
98
99 dev_id = (u16)(kernel_ulong_t)of_device_get_match_data(&pdev->dev);
100 ret = ath9k_init_device(dev_id, sc, &ath_ahb_bus_ops);
101 if (ret) {
102 dev_err(&pdev->dev, "failed to initialize device\n");
103 goto err_irq;
104 }
105
106 ah = sc->sc_ah;
107 ath9k_hw_name(ah, hw_name, sizeof(hw_name));
108 wiphy_info(hw->wiphy, "%s mem=0x%p, irq=%d\n",
109 hw_name, mem, irq);
110
111 return 0;
112
113 err_irq:
114 free_irq(irq, sc);
115 err_free_hw:
116 ieee80211_free_hw(hw);
117 return ret;
118 }
119
ath_ahb_remove(struct platform_device * pdev)120 static void ath_ahb_remove(struct platform_device *pdev)
121 {
122 struct ieee80211_hw *hw = platform_get_drvdata(pdev);
123
124 if (hw) {
125 struct ath_softc *sc = hw->priv;
126
127 ath9k_deinit_device(sc);
128 free_irq(sc->irq, sc);
129 ieee80211_free_hw(sc->hw);
130 }
131 }
132
133 static struct platform_driver ath_ahb_driver = {
134 .probe = ath_ahb_probe,
135 .remove = ath_ahb_remove,
136 .driver = {
137 .name = "ath9k",
138 .of_match_table = ath9k_of_match_table,
139 },
140 };
141
142 MODULE_DEVICE_TABLE(of, ath9k_of_match_table);
143
ath_ahb_init(void)144 int ath_ahb_init(void)
145 {
146 return platform_driver_register(&ath_ahb_driver);
147 }
148
ath_ahb_exit(void)149 void ath_ahb_exit(void)
150 {
151 platform_driver_unregister(&ath_ahb_driver);
152 }
153