18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 38c2ecf20Sopenharmony_ci * Copyright (c) 2004-2005 Atheros Communications, Inc. 48c2ecf20Sopenharmony_ci * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com> 58c2ecf20Sopenharmony_ci * Copyright (c) 2009 Bob Copeland <me@bobcopeland.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * All rights reserved. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 108c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 118c2ecf20Sopenharmony_ci * are met: 128c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 138c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer, 148c2ecf20Sopenharmony_ci * without modification. 158c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer 168c2ecf20Sopenharmony_ci * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 178c2ecf20Sopenharmony_ci * redistribution must be conditioned upon including a substantially 188c2ecf20Sopenharmony_ci * similar Disclaimer requirement for further binary redistribution. 198c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names 208c2ecf20Sopenharmony_ci * of any contributors may be used to endorse or promote products derived 218c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 248c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 258c2ecf20Sopenharmony_ci * Software Foundation. 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * NO WARRANTY 288c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 298c2ecf20Sopenharmony_ci * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 308c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 318c2ecf20Sopenharmony_ci * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 328c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 338c2ecf20Sopenharmony_ci * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 348c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 358c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 368c2ecf20Sopenharmony_ci * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 378c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 388c2ecf20Sopenharmony_ci * THE POSSIBILITY OF SUCH DAMAGES. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#include <linux/pci.h> 458c2ecf20Sopenharmony_ci#include "ath5k.h" 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define ATH_SDEVICE(subv, subd) \ 488c2ecf20Sopenharmony_ci .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \ 498c2ecf20Sopenharmony_ci .subvendor = (subv), .subdevice = (subd) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define ATH_LED(pin, polarity) .driver_data = (((pin) << 8) | (polarity)) 528c2ecf20Sopenharmony_ci#define ATH_PIN(data) ((data) >> 8) 538c2ecf20Sopenharmony_ci#define ATH_POLARITY(data) ((data) & 0xff) 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* Devices we match on for LED config info (typically laptops) */ 568c2ecf20Sopenharmony_cistatic const struct pci_device_id ath5k_led_devices[] = { 578c2ecf20Sopenharmony_ci /* AR5211 */ 588c2ecf20Sopenharmony_ci { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5211), ATH_LED(0, 0) }, 598c2ecf20Sopenharmony_ci /* HP Compaq nc6xx, nc4000, nx6000 */ 608c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_COMPAQ, PCI_ANY_ID), ATH_LED(1, 1) }, 618c2ecf20Sopenharmony_ci /* Acer Aspire One A150 (maximlevitsky@gmail.com) */ 628c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe008), ATH_LED(3, 0) }, 638c2ecf20Sopenharmony_ci /* Acer Aspire One AO531h AO751h (keng-yu.lin@canonical.com) */ 648c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_FOXCONN, 0xe00d), ATH_LED(3, 0) }, 658c2ecf20Sopenharmony_ci /* Acer Ferrari 5000 (russ.dill@gmail.com) */ 668c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0422), ATH_LED(1, 1) }, 678c2ecf20Sopenharmony_ci /* E-machines E510 (tuliom@gmail.com) */ 688c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_AMBIT, 0x0428), ATH_LED(3, 0) }, 698c2ecf20Sopenharmony_ci /* BenQ Joybook R55v (nowymarluk@wp.pl) */ 708c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0100), ATH_LED(1, 0) }, 718c2ecf20Sopenharmony_ci /* Acer Extensa 5620z (nekoreeve@gmail.com) */ 728c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0105), ATH_LED(3, 0) }, 738c2ecf20Sopenharmony_ci /* Fukato Datacask Jupiter 1014a (mrb74@gmx.at) */ 748c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_AZWAVE, 0x1026), ATH_LED(3, 0) }, 758c2ecf20Sopenharmony_ci /* IBM ThinkPad AR5BXB6 (legovini@spiro.fisica.unipd.it) */ 768c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_IBM, 0x058a), ATH_LED(1, 0) }, 778c2ecf20Sopenharmony_ci /* HP Compaq CQ60-206US (ddreggors@jumptv.com) */ 788c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137a), ATH_LED(3, 1) }, 798c2ecf20Sopenharmony_ci /* HP Compaq C700 (nitrousnrg@gmail.com) */ 808c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_HP, 0x0137b), ATH_LED(3, 0) }, 818c2ecf20Sopenharmony_ci /* LiteOn AR5BXB63 (magooz@salug.it) */ 828c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_ATHEROS, 0x3067), ATH_LED(3, 0) }, 838c2ecf20Sopenharmony_ci /* IBM-specific AR5212 (all others) */ 848c2ecf20Sopenharmony_ci { PCI_VDEVICE(ATHEROS, PCI_DEVICE_ID_ATHEROS_AR5212_IBM), ATH_LED(0, 0) }, 858c2ecf20Sopenharmony_ci /* Dell Vostro A860 (shahar@shahar-or.co.il) */ 868c2ecf20Sopenharmony_ci { ATH_SDEVICE(PCI_VENDOR_ID_QMI, 0x0112), ATH_LED(3, 0) }, 878c2ecf20Sopenharmony_ci { } 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_civoid ath5k_led_enable(struct ath5k_hw *ah) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci if (IS_ENABLED(CONFIG_MAC80211_LEDS) && 938c2ecf20Sopenharmony_ci test_bit(ATH_STAT_LEDSOFT, ah->status)) { 948c2ecf20Sopenharmony_ci ath5k_hw_set_gpio_output(ah, ah->led_pin); 958c2ecf20Sopenharmony_ci ath5k_led_off(ah); 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci} 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistatic void ath5k_led_on(struct ath5k_hw *ah) 1008c2ecf20Sopenharmony_ci{ 1018c2ecf20Sopenharmony_ci if (!test_bit(ATH_STAT_LEDSOFT, ah->status)) 1028c2ecf20Sopenharmony_ci return; 1038c2ecf20Sopenharmony_ci ath5k_hw_set_gpio(ah, ah->led_pin, ah->led_on); 1048c2ecf20Sopenharmony_ci} 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_civoid ath5k_led_off(struct ath5k_hw *ah) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci if (!IS_ENABLED(CONFIG_MAC80211_LEDS) || 1098c2ecf20Sopenharmony_ci !test_bit(ATH_STAT_LEDSOFT, ah->status)) 1108c2ecf20Sopenharmony_ci return; 1118c2ecf20Sopenharmony_ci ath5k_hw_set_gpio(ah, ah->led_pin, !ah->led_on); 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic void 1158c2ecf20Sopenharmony_ciath5k_led_brightness_set(struct led_classdev *led_dev, 1168c2ecf20Sopenharmony_ci enum led_brightness brightness) 1178c2ecf20Sopenharmony_ci{ 1188c2ecf20Sopenharmony_ci struct ath5k_led *led = container_of(led_dev, struct ath5k_led, 1198c2ecf20Sopenharmony_ci led_dev); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci if (brightness == LED_OFF) 1228c2ecf20Sopenharmony_ci ath5k_led_off(led->ah); 1238c2ecf20Sopenharmony_ci else 1248c2ecf20Sopenharmony_ci ath5k_led_on(led->ah); 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_cistatic int 1288c2ecf20Sopenharmony_ciath5k_register_led(struct ath5k_hw *ah, struct ath5k_led *led, 1298c2ecf20Sopenharmony_ci const char *name, const char *trigger) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci int err; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci led->ah = ah; 1348c2ecf20Sopenharmony_ci strncpy(led->name, name, sizeof(led->name)); 1358c2ecf20Sopenharmony_ci led->name[sizeof(led->name)-1] = 0; 1368c2ecf20Sopenharmony_ci led->led_dev.name = led->name; 1378c2ecf20Sopenharmony_ci led->led_dev.default_trigger = trigger; 1388c2ecf20Sopenharmony_ci led->led_dev.brightness_set = ath5k_led_brightness_set; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci err = led_classdev_register(ah->dev, &led->led_dev); 1418c2ecf20Sopenharmony_ci if (err) { 1428c2ecf20Sopenharmony_ci ATH5K_WARN(ah, "could not register LED %s\n", name); 1438c2ecf20Sopenharmony_ci led->ah = NULL; 1448c2ecf20Sopenharmony_ci } 1458c2ecf20Sopenharmony_ci return err; 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_cistatic void 1498c2ecf20Sopenharmony_ciath5k_unregister_led(struct ath5k_led *led) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci if (!IS_ENABLED(CONFIG_MAC80211_LEDS) || !led->ah) 1528c2ecf20Sopenharmony_ci return; 1538c2ecf20Sopenharmony_ci led_classdev_unregister(&led->led_dev); 1548c2ecf20Sopenharmony_ci ath5k_led_off(led->ah); 1558c2ecf20Sopenharmony_ci led->ah = NULL; 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_civoid ath5k_unregister_leds(struct ath5k_hw *ah) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci ath5k_unregister_led(&ah->rx_led); 1618c2ecf20Sopenharmony_ci ath5k_unregister_led(&ah->tx_led); 1628c2ecf20Sopenharmony_ci} 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ciint ath5k_init_leds(struct ath5k_hw *ah) 1658c2ecf20Sopenharmony_ci{ 1668c2ecf20Sopenharmony_ci int ret = 0; 1678c2ecf20Sopenharmony_ci struct ieee80211_hw *hw = ah->hw; 1688c2ecf20Sopenharmony_ci#ifndef CONFIG_ATH5K_AHB 1698c2ecf20Sopenharmony_ci struct pci_dev *pdev = ah->pdev; 1708c2ecf20Sopenharmony_ci#endif 1718c2ecf20Sopenharmony_ci char name[ATH5K_LED_MAX_NAME_LEN + 1]; 1728c2ecf20Sopenharmony_ci const struct pci_device_id *match; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci if (!IS_ENABLED(CONFIG_MAC80211_LEDS) || !ah->pdev) 1758c2ecf20Sopenharmony_ci return 0; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci#ifdef CONFIG_ATH5K_AHB 1788c2ecf20Sopenharmony_ci match = NULL; 1798c2ecf20Sopenharmony_ci#else 1808c2ecf20Sopenharmony_ci match = pci_match_id(&ath5k_led_devices[0], pdev); 1818c2ecf20Sopenharmony_ci#endif 1828c2ecf20Sopenharmony_ci if (match) { 1838c2ecf20Sopenharmony_ci __set_bit(ATH_STAT_LEDSOFT, ah->status); 1848c2ecf20Sopenharmony_ci ah->led_pin = ATH_PIN(match->driver_data); 1858c2ecf20Sopenharmony_ci ah->led_on = ATH_POLARITY(match->driver_data); 1868c2ecf20Sopenharmony_ci } 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci if (!test_bit(ATH_STAT_LEDSOFT, ah->status)) 1898c2ecf20Sopenharmony_ci goto out; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci ath5k_led_enable(ah); 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), "ath5k-%s::rx", wiphy_name(hw->wiphy)); 1948c2ecf20Sopenharmony_ci ret = ath5k_register_led(ah, &ah->rx_led, name, 1958c2ecf20Sopenharmony_ci ieee80211_get_rx_led_name(hw)); 1968c2ecf20Sopenharmony_ci if (ret) 1978c2ecf20Sopenharmony_ci goto out; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci snprintf(name, sizeof(name), "ath5k-%s::tx", wiphy_name(hw->wiphy)); 2008c2ecf20Sopenharmony_ci ret = ath5k_register_led(ah, &ah->tx_led, name, 2018c2ecf20Sopenharmony_ci ieee80211_get_tx_led_name(hw)); 2028c2ecf20Sopenharmony_ciout: 2038c2ecf20Sopenharmony_ci return ret; 2048c2ecf20Sopenharmony_ci} 2058c2ecf20Sopenharmony_ci 206