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> 21203c4805SLuis R. Rodriguez #include <linux/ath9k_platform.h> 22203c4805SLuis R. Rodriguez #include "ath9k.h" 23203c4805SLuis R. Rodriguez 240a6c9b1bSVasanthakumar Thiagarajan static const struct platform_device_id ath9k_platform_id_table[] = { 256f11c819SVasanthakumar Thiagarajan { 266f11c819SVasanthakumar Thiagarajan .name = "ath9k", 276f11c819SVasanthakumar Thiagarajan .driver_data = AR5416_AR9100_DEVID, 286f11c819SVasanthakumar Thiagarajan }, 29247eee0eSVasanthakumar Thiagarajan { 30e9b7c591SGabor Juhos .name = "ar933x_wmac", 31e9b7c591SGabor Juhos .driver_data = AR9300_DEVID_AR9330, 32e9b7c591SGabor Juhos }, 33e9b7c591SGabor Juhos { 34247eee0eSVasanthakumar Thiagarajan .name = "ar934x_wmac", 35247eee0eSVasanthakumar Thiagarajan .driver_data = AR9300_DEVID_AR9340, 36247eee0eSVasanthakumar Thiagarajan }, 376f11c819SVasanthakumar Thiagarajan {}, 386f11c819SVasanthakumar Thiagarajan }; 396f11c819SVasanthakumar Thiagarajan 40203c4805SLuis R. Rodriguez /* return bus cachesize in 4B word units */ 415bb12791SLuis R. Rodriguez static void ath_ahb_read_cachesize(struct ath_common *common, int *csz) 42203c4805SLuis R. Rodriguez { 43203c4805SLuis R. Rodriguez *csz = L1_CACHE_BYTES >> 2; 44203c4805SLuis R. Rodriguez } 45203c4805SLuis R. Rodriguez 465bb12791SLuis R. Rodriguez static bool ath_ahb_eeprom_read(struct ath_common *common, u32 off, u16 *data) 47203c4805SLuis R. Rodriguez { 48e307fcf0SMarek Lindner struct ath_softc *sc = (struct ath_softc *)common->priv; 49203c4805SLuis R. Rodriguez struct platform_device *pdev = to_platform_device(sc->dev); 50203c4805SLuis R. Rodriguez struct ath9k_platform_data *pdata; 51203c4805SLuis R. Rodriguez 52203c4805SLuis R. Rodriguez pdata = (struct ath9k_platform_data *) pdev->dev.platform_data; 53203c4805SLuis R. Rodriguez if (off >= (ARRAY_SIZE(pdata->eeprom_data))) { 543800276aSJoe Perches ath_err(common, 553800276aSJoe Perches "%s: flash read failed, offset %08x is out of range\n", 56203c4805SLuis R. Rodriguez __func__, off); 57203c4805SLuis R. Rodriguez return false; 58203c4805SLuis R. Rodriguez } 59203c4805SLuis R. Rodriguez 60203c4805SLuis R. Rodriguez *data = pdata->eeprom_data[off]; 61203c4805SLuis R. Rodriguez return true; 62203c4805SLuis R. Rodriguez } 63203c4805SLuis R. Rodriguez 64203c4805SLuis R. Rodriguez static struct ath_bus_ops ath_ahb_bus_ops = { 65497ad9adSSujith .ath_bus_type = ATH_AHB, 66203c4805SLuis R. Rodriguez .read_cachesize = ath_ahb_read_cachesize, 67203c4805SLuis R. Rodriguez .eeprom_read = ath_ahb_eeprom_read, 68203c4805SLuis R. Rodriguez }; 69203c4805SLuis R. Rodriguez 70203c4805SLuis R. Rodriguez static int ath_ahb_probe(struct platform_device *pdev) 71203c4805SLuis R. Rodriguez { 72203c4805SLuis R. Rodriguez void __iomem *mem; 73203c4805SLuis R. Rodriguez struct ath_softc *sc; 74203c4805SLuis R. Rodriguez struct ieee80211_hw *hw; 75203c4805SLuis R. Rodriguez struct resource *res; 766f11c819SVasanthakumar Thiagarajan const struct platform_device_id *id = platform_get_device_id(pdev); 77203c4805SLuis R. Rodriguez int irq; 78203c4805SLuis R. Rodriguez int ret = 0; 79203c4805SLuis R. Rodriguez struct ath_hw *ah; 80f934c4d9SLuis R. Rodriguez char hw_name[64]; 81203c4805SLuis R. Rodriguez 82203c4805SLuis R. Rodriguez if (!pdev->dev.platform_data) { 83203c4805SLuis R. Rodriguez dev_err(&pdev->dev, "no platform data specified\n"); 84203c4805SLuis R. Rodriguez ret = -EINVAL; 85203c4805SLuis R. Rodriguez goto err_out; 86203c4805SLuis R. Rodriguez } 87203c4805SLuis R. Rodriguez 88203c4805SLuis R. Rodriguez res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 89203c4805SLuis R. Rodriguez if (res == NULL) { 90203c4805SLuis R. Rodriguez dev_err(&pdev->dev, "no memory resource found\n"); 91203c4805SLuis R. Rodriguez ret = -ENXIO; 92203c4805SLuis R. Rodriguez goto err_out; 93203c4805SLuis R. Rodriguez } 94203c4805SLuis R. Rodriguez 959ac47933SShan Wei mem = ioremap_nocache(res->start, resource_size(res)); 96203c4805SLuis R. Rodriguez if (mem == NULL) { 97203c4805SLuis R. Rodriguez dev_err(&pdev->dev, "ioremap failed\n"); 98203c4805SLuis R. Rodriguez ret = -ENOMEM; 99203c4805SLuis R. Rodriguez goto err_out; 100203c4805SLuis R. Rodriguez } 101203c4805SLuis R. Rodriguez 102203c4805SLuis R. Rodriguez res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 103203c4805SLuis R. Rodriguez if (res == NULL) { 104203c4805SLuis R. Rodriguez dev_err(&pdev->dev, "no IRQ resource found\n"); 105203c4805SLuis R. Rodriguez ret = -ENXIO; 106203c4805SLuis R. Rodriguez goto err_iounmap; 107203c4805SLuis R. Rodriguez } 108203c4805SLuis R. Rodriguez 109203c4805SLuis R. Rodriguez irq = res->start; 110203c4805SLuis R. Rodriguez 1119ac58615SFelix Fietkau hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops); 112203c4805SLuis R. Rodriguez if (hw == NULL) { 113203c4805SLuis R. Rodriguez dev_err(&pdev->dev, "no memory for ieee80211_hw\n"); 114203c4805SLuis R. Rodriguez ret = -ENOMEM; 115203c4805SLuis R. Rodriguez goto err_iounmap; 116203c4805SLuis R. Rodriguez } 117203c4805SLuis R. Rodriguez 118203c4805SLuis R. Rodriguez SET_IEEE80211_DEV(hw, &pdev->dev); 119203c4805SLuis R. Rodriguez platform_set_drvdata(pdev, hw); 120203c4805SLuis R. Rodriguez 1219ac58615SFelix Fietkau sc = hw->priv; 122203c4805SLuis R. Rodriguez sc->hw = hw; 123203c4805SLuis R. Rodriguez sc->dev = &pdev->dev; 124203c4805SLuis R. Rodriguez sc->mem = mem; 125203c4805SLuis R. Rodriguez sc->irq = irq; 126203c4805SLuis R. Rodriguez 1275e4ea1f0SSujith /* Will be cleared in ath9k_start() */ 1285e4ea1f0SSujith sc->sc_flags |= SC_OP_INVALID; 1295e4ea1f0SSujith 130203c4805SLuis R. Rodriguez ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc); 131203c4805SLuis R. Rodriguez if (ret) { 132580171f7SLuis R. Rodriguez dev_err(&pdev->dev, "request_irq failed\n"); 133285f2ddaSSujith goto err_free_hw; 134285f2ddaSSujith } 135285f2ddaSSujith 136*eb93e891SPavel Roskin ret = ath9k_init_device(id->driver_data, sc, &ath_ahb_bus_ops); 137285f2ddaSSujith if (ret) { 138285f2ddaSSujith dev_err(&pdev->dev, "failed to initialize device\n"); 139285f2ddaSSujith goto err_irq; 140203c4805SLuis R. Rodriguez } 141203c4805SLuis R. Rodriguez 142203c4805SLuis R. Rodriguez ah = sc->sc_ah; 143f934c4d9SLuis R. Rodriguez ath9k_hw_name(ah, hw_name, sizeof(hw_name)); 144c96c31e4SJoe Perches wiphy_info(hw->wiphy, "%s mem=0x%lx, irq=%d\n", 145c96c31e4SJoe Perches hw_name, (unsigned long)mem, irq); 146203c4805SLuis R. Rodriguez 147203c4805SLuis R. Rodriguez return 0; 148203c4805SLuis R. Rodriguez 149285f2ddaSSujith err_irq: 150285f2ddaSSujith free_irq(irq, sc); 151203c4805SLuis R. Rodriguez err_free_hw: 152203c4805SLuis R. Rodriguez ieee80211_free_hw(hw); 153203c4805SLuis R. Rodriguez platform_set_drvdata(pdev, NULL); 154203c4805SLuis R. Rodriguez err_iounmap: 155203c4805SLuis R. Rodriguez iounmap(mem); 156203c4805SLuis R. Rodriguez err_out: 157203c4805SLuis R. Rodriguez return ret; 158203c4805SLuis R. Rodriguez } 159203c4805SLuis R. Rodriguez 160203c4805SLuis R. Rodriguez static int ath_ahb_remove(struct platform_device *pdev) 161203c4805SLuis R. Rodriguez { 162203c4805SLuis R. Rodriguez struct ieee80211_hw *hw = platform_get_drvdata(pdev); 163203c4805SLuis R. Rodriguez 164203c4805SLuis R. Rodriguez if (hw) { 1659ac58615SFelix Fietkau struct ath_softc *sc = hw->priv; 166ab5132a2SPavel Roskin void __iomem *mem = sc->mem; 167203c4805SLuis R. Rodriguez 168285f2ddaSSujith ath9k_deinit_device(sc); 169285f2ddaSSujith free_irq(sc->irq, sc); 170285f2ddaSSujith ieee80211_free_hw(sc->hw); 171ab5132a2SPavel Roskin iounmap(mem); 172203c4805SLuis R. Rodriguez platform_set_drvdata(pdev, NULL); 173203c4805SLuis R. Rodriguez } 174203c4805SLuis R. Rodriguez 175203c4805SLuis R. Rodriguez return 0; 176203c4805SLuis R. Rodriguez } 177203c4805SLuis R. Rodriguez 178203c4805SLuis R. Rodriguez static struct platform_driver ath_ahb_driver = { 179203c4805SLuis R. Rodriguez .probe = ath_ahb_probe, 180203c4805SLuis R. Rodriguez .remove = ath_ahb_remove, 181203c4805SLuis R. Rodriguez .driver = { 182203c4805SLuis R. Rodriguez .name = "ath9k", 183203c4805SLuis R. Rodriguez .owner = THIS_MODULE, 184203c4805SLuis R. Rodriguez }, 1856f11c819SVasanthakumar Thiagarajan .id_table = ath9k_platform_id_table, 186203c4805SLuis R. Rodriguez }; 187203c4805SLuis R. Rodriguez 1886f11c819SVasanthakumar Thiagarajan MODULE_DEVICE_TABLE(platform, ath9k_platform_id_table); 1896f11c819SVasanthakumar Thiagarajan 190203c4805SLuis R. Rodriguez int ath_ahb_init(void) 191203c4805SLuis R. Rodriguez { 192203c4805SLuis R. Rodriguez return platform_driver_register(&ath_ahb_driver); 193203c4805SLuis R. Rodriguez } 194203c4805SLuis R. Rodriguez 195203c4805SLuis R. Rodriguez void ath_ahb_exit(void) 196203c4805SLuis R. Rodriguez { 197203c4805SLuis R. Rodriguez platform_driver_unregister(&ath_ahb_driver); 198203c4805SLuis R. Rodriguez } 199