xref: /linux/drivers/net/wireless/ath/ath9k/ahb.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1203c4805SLuis R. Rodriguez /*
25b68138eSSujith Manoharan  * Copyright (c) 2008-2011 Atheros Communications Inc.
3203c4805SLuis R. Rodriguez  * Copyright (c) 2009 Gabor Juhos <juhosg@openwrt.org>
4203c4805SLuis R. Rodriguez  * Copyright (c) 2009 Imre Kaloz <kaloz@openwrt.org>
5203c4805SLuis R. Rodriguez  *
6203c4805SLuis R. Rodriguez  * Permission to use, copy, modify, and/or distribute this software for any
7203c4805SLuis R. Rodriguez  * purpose with or without fee is hereby granted, provided that the above
8203c4805SLuis R. Rodriguez  * copyright notice and this permission notice appear in all copies.
9203c4805SLuis R. Rodriguez  *
10203c4805SLuis R. Rodriguez  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11203c4805SLuis R. Rodriguez  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12203c4805SLuis R. Rodriguez  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13203c4805SLuis R. Rodriguez  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14203c4805SLuis R. Rodriguez  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15203c4805SLuis R. Rodriguez  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16203c4805SLuis R. Rodriguez  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17203c4805SLuis R. Rodriguez  */
18203c4805SLuis R. Rodriguez 
19203c4805SLuis R. Rodriguez #include <linux/nl80211.h>
20203c4805SLuis R. Rodriguez #include <linux/platform_device.h>
219d9779e7SPaul Gortmaker #include <linux/module.h>
22ac316725SRandy Dunlap #include <linux/mod_devicetable.h>
23203c4805SLuis R. Rodriguez #include "ath9k.h"
24203c4805SLuis R. Rodriguez 
250a6c9b1bSVasanthakumar Thiagarajan static const struct platform_device_id ath9k_platform_id_table[] = {
266f11c819SVasanthakumar Thiagarajan 	{
276f11c819SVasanthakumar Thiagarajan 		.name = "ath9k",
286f11c819SVasanthakumar Thiagarajan 		.driver_data = AR5416_AR9100_DEVID,
296f11c819SVasanthakumar Thiagarajan 	},
30247eee0eSVasanthakumar Thiagarajan 	{
31e9b7c591SGabor Juhos 		.name = "ar933x_wmac",
32e9b7c591SGabor Juhos 		.driver_data = AR9300_DEVID_AR9330,
33e9b7c591SGabor Juhos 	},
34e9b7c591SGabor Juhos 	{
35247eee0eSVasanthakumar Thiagarajan 		.name = "ar934x_wmac",
36247eee0eSVasanthakumar Thiagarajan 		.driver_data = AR9300_DEVID_AR9340,
37247eee0eSVasanthakumar Thiagarajan 	},
389476f4d6SGabor Juhos 	{
399476f4d6SGabor Juhos 		.name = "qca955x_wmac",
409476f4d6SGabor Juhos 		.driver_data = AR9300_DEVID_QCA955X,
419476f4d6SGabor Juhos 	},
42c08148bbSSujith Manoharan 	{
43c08148bbSSujith Manoharan 		.name = "qca953x_wmac",
44c08148bbSSujith Manoharan 		.driver_data = AR9300_DEVID_AR953X,
45c08148bbSSujith Manoharan 	},
462131fabbSMiaoqing Pan 	{
472131fabbSMiaoqing Pan 		.name = "qca956x_wmac",
482131fabbSMiaoqing Pan 		.driver_data = AR9300_DEVID_QCA956X,
492131fabbSMiaoqing Pan 	},
506f11c819SVasanthakumar Thiagarajan 	{},
516f11c819SVasanthakumar Thiagarajan };
526f11c819SVasanthakumar Thiagarajan 
53203c4805SLuis R. Rodriguez /* return bus cachesize in 4B word units */
ath_ahb_read_cachesize(struct ath_common * common,int * csz)545bb12791SLuis R. Rodriguez static void ath_ahb_read_cachesize(struct ath_common *common, int *csz)
55203c4805SLuis R. Rodriguez {
56203c4805SLuis R. Rodriguez 	*csz = L1_CACHE_BYTES >> 2;
57203c4805SLuis R. Rodriguez }
58203c4805SLuis R. Rodriguez 
ath_ahb_eeprom_read(struct ath_common * common,u32 off,u16 * data)595bb12791SLuis R. Rodriguez static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data)
60203c4805SLuis R. Rodriguez {
6156398519SMartin Blumenstingl 	ath_err(common, "%s: eeprom data has to be provided externally\n",
6256398519SMartin Blumenstingl 		__func__);
63203c4805SLuis R. Rodriguez 	return false;
64203c4805SLuis R. Rodriguez }
65203c4805SLuis R. Rodriguez 
668ca5a607SBhumika Goyal static const struct ath_bus_ops ath_ahb_bus_ops  = {
67497ad9adSSujith 	.ath_bus_type = ATH_AHB,
68203c4805SLuis R. Rodriguez 	.read_cachesize = ath_ahb_read_cachesize,
69203c4805SLuis R. Rodriguez 	.eeprom_read = ath_ahb_eeprom_read,
70203c4805SLuis R. Rodriguez };
71203c4805SLuis R. Rodriguez 
ath_ahb_probe(struct platform_device * pdev)72203c4805SLuis R. Rodriguez static int ath_ahb_probe(struct platform_device *pdev)
73203c4805SLuis R. Rodriguez {
74203c4805SLuis R. Rodriguez 	void __iomem *mem;
75203c4805SLuis R. Rodriguez 	struct ath_softc *sc;
76203c4805SLuis R. Rodriguez 	struct ieee80211_hw *hw;
77203c4805SLuis R. Rodriguez 	struct resource *res;
786f11c819SVasanthakumar Thiagarajan 	const struct platform_device_id *id = platform_get_device_id(pdev);
79203c4805SLuis R. Rodriguez 	int irq;
80203c4805SLuis R. Rodriguez 	int ret = 0;
81203c4805SLuis R. Rodriguez 	struct ath_hw *ah;
82f934c4d9SLuis R. Rodriguez 	char hw_name[64];
83203c4805SLuis R. Rodriguez 
848f616c6dSJingoo Han 	if (!dev_get_platdata(&pdev->dev)) {
85203c4805SLuis R. Rodriguez 		dev_err(&pdev->dev, "no platform data specified\n");
86b81950b1SFelix Fietkau 		return -EINVAL;
87203c4805SLuis R. Rodriguez 	}
88203c4805SLuis R. Rodriguez 
89203c4805SLuis R. Rodriguez 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90203c4805SLuis R. Rodriguez 	if (res == NULL) {
91203c4805SLuis R. Rodriguez 		dev_err(&pdev->dev, "no memory resource found\n");
92b81950b1SFelix Fietkau 		return -ENXIO;
93203c4805SLuis R. Rodriguez 	}
94203c4805SLuis R. Rodriguez 
954bdc0d67SChristoph Hellwig 	mem = devm_ioremap(&pdev->dev, res->start, resource_size(res));
96203c4805SLuis R. Rodriguez 	if (mem == NULL) {
97203c4805SLuis R. Rodriguez 		dev_err(&pdev->dev, "ioremap failed\n");
98b81950b1SFelix Fietkau 		return -ENOMEM;
99203c4805SLuis R. Rodriguez 	}
100203c4805SLuis R. Rodriguez 
1019503a1fcSMinghao Chi 	irq = platform_get_irq(pdev, 0);
102d7ceee80SYang Li 	if (irq < 0)
1039503a1fcSMinghao Chi 		return irq;
104203c4805SLuis R. Rodriguez 
105cf9ae8faSRajkumar Manoharan 	ath9k_fill_chanctx_ops();
1069ac58615SFelix Fietkau 	hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
107203c4805SLuis R. Rodriguez 	if (hw == NULL) {
108203c4805SLuis R. Rodriguez 		dev_err(&pdev->dev, "no memory for ieee80211_hw\n");
109b81950b1SFelix Fietkau 		return -ENOMEM;
110203c4805SLuis R. Rodriguez 	}
111203c4805SLuis R. Rodriguez 
112203c4805SLuis R. Rodriguez 	SET_IEEE80211_DEV(hw, &pdev->dev);
113203c4805SLuis R. Rodriguez 	platform_set_drvdata(pdev, hw);
114203c4805SLuis R. Rodriguez 
1159ac58615SFelix Fietkau 	sc = hw->priv;
116203c4805SLuis R. Rodriguez 	sc->hw = hw;
117203c4805SLuis R. Rodriguez 	sc->dev = &pdev->dev;
118203c4805SLuis R. Rodriguez 	sc->mem = mem;
119203c4805SLuis R. Rodriguez 	sc->irq = irq;
120203c4805SLuis R. Rodriguez 
121203c4805SLuis R. Rodriguez 	ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
122203c4805SLuis R. Rodriguez 	if (ret) {
123580171f7SLuis R. Rodriguez 		dev_err(&pdev->dev, "request_irq failed\n");
124285f2ddaSSujith 		goto err_free_hw;
125285f2ddaSSujith 	}
126285f2ddaSSujith 
127eb93e891SPavel Roskin 	ret = ath9k_init_device(id->driver_data, sc, &ath_ahb_bus_ops);
128285f2ddaSSujith 	if (ret) {
129285f2ddaSSujith 		dev_err(&pdev->dev, "failed to initialize device\n");
130285f2ddaSSujith 		goto err_irq;
131203c4805SLuis R. Rodriguez 	}
132203c4805SLuis R. Rodriguez 
133203c4805SLuis R. Rodriguez 	ah = sc->sc_ah;
134f934c4d9SLuis R. Rodriguez 	ath9k_hw_name(ah, hw_name, sizeof(hw_name));
135061115fbSDongliang Mu 	wiphy_info(hw->wiphy, "%s mem=0x%p, irq=%d\n",
136061115fbSDongliang Mu 		   hw_name, mem, irq);
137203c4805SLuis R. Rodriguez 
138203c4805SLuis R. Rodriguez 	return 0;
139203c4805SLuis R. Rodriguez 
140285f2ddaSSujith  err_irq:
141285f2ddaSSujith 	free_irq(irq, sc);
142203c4805SLuis R. Rodriguez  err_free_hw:
143203c4805SLuis R. Rodriguez 	ieee80211_free_hw(hw);
144203c4805SLuis R. Rodriguez 	return ret;
145203c4805SLuis R. Rodriguez }
146203c4805SLuis R. Rodriguez 
ath_ahb_remove(struct platform_device * pdev)147*27ce06d0SUwe Kleine-König static void ath_ahb_remove(struct platform_device *pdev)
148203c4805SLuis R. Rodriguez {
149203c4805SLuis R. Rodriguez 	struct ieee80211_hw *hw = platform_get_drvdata(pdev);
150203c4805SLuis R. Rodriguez 
151203c4805SLuis R. Rodriguez 	if (hw) {
1529ac58615SFelix Fietkau 		struct ath_softc *sc = hw->priv;
153203c4805SLuis R. Rodriguez 
154285f2ddaSSujith 		ath9k_deinit_device(sc);
155285f2ddaSSujith 		free_irq(sc->irq, sc);
156285f2ddaSSujith 		ieee80211_free_hw(sc->hw);
157203c4805SLuis R. Rodriguez 	}
158203c4805SLuis R. Rodriguez }
159203c4805SLuis R. Rodriguez 
160203c4805SLuis R. Rodriguez static struct platform_driver ath_ahb_driver = {
161203c4805SLuis R. Rodriguez 	.probe      = ath_ahb_probe,
162*27ce06d0SUwe Kleine-König 	.remove_new = ath_ahb_remove,
163203c4805SLuis R. Rodriguez 	.driver		= {
164203c4805SLuis R. Rodriguez 		.name	= "ath9k",
165203c4805SLuis R. Rodriguez 	},
1666f11c819SVasanthakumar Thiagarajan 	.id_table    = ath9k_platform_id_table,
167203c4805SLuis R. Rodriguez };
168203c4805SLuis R. Rodriguez 
1696f11c819SVasanthakumar Thiagarajan MODULE_DEVICE_TABLE(platform, ath9k_platform_id_table);
1706f11c819SVasanthakumar Thiagarajan 
ath_ahb_init(void)171203c4805SLuis R. Rodriguez int ath_ahb_init(void)
172203c4805SLuis R. Rodriguez {
173203c4805SLuis R. Rodriguez 	return platform_driver_register(&ath_ahb_driver);
174203c4805SLuis R. Rodriguez }
175203c4805SLuis R. Rodriguez 
ath_ahb_exit(void)176203c4805SLuis R. Rodriguez void ath_ahb_exit(void)
177203c4805SLuis R. Rodriguez {
178203c4805SLuis R. Rodriguez 	platform_driver_unregister(&ath_ahb_driver);
179203c4805SLuis R. Rodriguez }
180