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