1e705c121SKalle Valo /****************************************************************************** 2e705c121SKalle Valo * 3e705c121SKalle Valo * This file is provided under a dual BSD/GPLv2 license. When using or 4e705c121SKalle Valo * redistributing this file, you may do so under either license. 5e705c121SKalle Valo * 6e705c121SKalle Valo * GPL LICENSE SUMMARY 7e705c121SKalle Valo * 8e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 9e705c121SKalle Valo * 10e705c121SKalle Valo * This program is free software; you can redistribute it and/or modify 11e705c121SKalle Valo * it under the terms of version 2 of the GNU General Public License as 12e705c121SKalle Valo * published by the Free Software Foundation. 13e705c121SKalle Valo * 14e705c121SKalle Valo * This program is distributed in the hope that it will be useful, but 15e705c121SKalle Valo * WITHOUT ANY WARRANTY; without even the implied warranty of 16e705c121SKalle Valo * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17e705c121SKalle Valo * General Public License for more details. 18e705c121SKalle Valo * 19e705c121SKalle Valo * You should have received a copy of the GNU General Public License 20e705c121SKalle Valo * along with this program; if not, write to the Free Software 21e705c121SKalle Valo * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 22e705c121SKalle Valo * USA 23e705c121SKalle Valo * 24e705c121SKalle Valo * The full GNU General Public License is included in this distribution 25e705c121SKalle Valo * in the file called COPYING. 26e705c121SKalle Valo * 27e705c121SKalle Valo * Contact Information: 28*d01c5366SEmmanuel Grumbach * Intel Linux Wireless <linuxwifi@intel.com> 29e705c121SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 30e705c121SKalle Valo * 31e705c121SKalle Valo * BSD LICENSE 32e705c121SKalle Valo * 33e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 34e705c121SKalle Valo * All rights reserved. 35e705c121SKalle Valo * 36e705c121SKalle Valo * Redistribution and use in source and binary forms, with or without 37e705c121SKalle Valo * modification, are permitted provided that the following conditions 38e705c121SKalle Valo * are met: 39e705c121SKalle Valo * 40e705c121SKalle Valo * * Redistributions of source code must retain the above copyright 41e705c121SKalle Valo * notice, this list of conditions and the following disclaimer. 42e705c121SKalle Valo * * Redistributions in binary form must reproduce the above copyright 43e705c121SKalle Valo * notice, this list of conditions and the following disclaimer in 44e705c121SKalle Valo * the documentation and/or other materials provided with the 45e705c121SKalle Valo * distribution. 46e705c121SKalle Valo * * Neither the name Intel Corporation nor the names of its 47e705c121SKalle Valo * contributors may be used to endorse or promote products derived 48e705c121SKalle Valo * from this software without specific prior written permission. 49e705c121SKalle Valo * 50e705c121SKalle Valo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 51e705c121SKalle Valo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 52e705c121SKalle Valo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 53e705c121SKalle Valo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 54e705c121SKalle Valo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 55e705c121SKalle Valo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 56e705c121SKalle Valo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 57e705c121SKalle Valo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 58e705c121SKalle Valo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 59e705c121SKalle Valo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 60e705c121SKalle Valo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61e705c121SKalle Valo * 62e705c121SKalle Valo *****************************************************************************/ 63e705c121SKalle Valo 64e705c121SKalle Valo #include <linux/leds.h> 65e705c121SKalle Valo #include "iwl-io.h" 66e705c121SKalle Valo #include "iwl-csr.h" 67e705c121SKalle Valo #include "mvm.h" 68e705c121SKalle Valo 69e705c121SKalle Valo /* Set led register on */ 70e705c121SKalle Valo static void iwl_mvm_led_enable(struct iwl_mvm *mvm) 71e705c121SKalle Valo { 72e705c121SKalle Valo iwl_write32(mvm->trans, CSR_LED_REG, CSR_LED_REG_TURN_ON); 73e705c121SKalle Valo } 74e705c121SKalle Valo 75e705c121SKalle Valo /* Set led register off */ 76e705c121SKalle Valo static void iwl_mvm_led_disable(struct iwl_mvm *mvm) 77e705c121SKalle Valo { 78e705c121SKalle Valo iwl_write32(mvm->trans, CSR_LED_REG, CSR_LED_REG_TURN_OFF); 79e705c121SKalle Valo } 80e705c121SKalle Valo 81e705c121SKalle Valo static void iwl_led_brightness_set(struct led_classdev *led_cdev, 82e705c121SKalle Valo enum led_brightness brightness) 83e705c121SKalle Valo { 84e705c121SKalle Valo struct iwl_mvm *mvm = container_of(led_cdev, struct iwl_mvm, led); 85e705c121SKalle Valo if (brightness > 0) 86e705c121SKalle Valo iwl_mvm_led_enable(mvm); 87e705c121SKalle Valo else 88e705c121SKalle Valo iwl_mvm_led_disable(mvm); 89e705c121SKalle Valo } 90e705c121SKalle Valo 91e705c121SKalle Valo int iwl_mvm_leds_init(struct iwl_mvm *mvm) 92e705c121SKalle Valo { 93e705c121SKalle Valo int mode = iwlwifi_mod_params.led_mode; 94e705c121SKalle Valo int ret; 95e705c121SKalle Valo 96e705c121SKalle Valo switch (mode) { 97e705c121SKalle Valo case IWL_LED_BLINK: 98e705c121SKalle Valo IWL_ERR(mvm, "Blink led mode not supported, used default\n"); 99e705c121SKalle Valo case IWL_LED_DEFAULT: 100e705c121SKalle Valo case IWL_LED_RF_STATE: 101e705c121SKalle Valo mode = IWL_LED_RF_STATE; 102e705c121SKalle Valo break; 103e705c121SKalle Valo case IWL_LED_DISABLE: 104e705c121SKalle Valo IWL_INFO(mvm, "Led disabled\n"); 105e705c121SKalle Valo return 0; 106e705c121SKalle Valo default: 107e705c121SKalle Valo return -EINVAL; 108e705c121SKalle Valo } 109e705c121SKalle Valo 110e705c121SKalle Valo mvm->led.name = kasprintf(GFP_KERNEL, "%s-led", 111e705c121SKalle Valo wiphy_name(mvm->hw->wiphy)); 112e705c121SKalle Valo mvm->led.brightness_set = iwl_led_brightness_set; 113e705c121SKalle Valo mvm->led.max_brightness = 1; 114e705c121SKalle Valo 115e705c121SKalle Valo if (mode == IWL_LED_RF_STATE) 116e705c121SKalle Valo mvm->led.default_trigger = 117e705c121SKalle Valo ieee80211_get_radio_led_name(mvm->hw); 118e705c121SKalle Valo 119e705c121SKalle Valo ret = led_classdev_register(mvm->trans->dev, &mvm->led); 120e705c121SKalle Valo if (ret) { 121e705c121SKalle Valo kfree(mvm->led.name); 122e705c121SKalle Valo IWL_INFO(mvm, "Failed to enable led\n"); 123e705c121SKalle Valo return ret; 124e705c121SKalle Valo } 125e705c121SKalle Valo 126e705c121SKalle Valo return 0; 127e705c121SKalle Valo } 128e705c121SKalle Valo 129e705c121SKalle Valo void iwl_mvm_leds_exit(struct iwl_mvm *mvm) 130e705c121SKalle Valo { 131e705c121SKalle Valo if (iwlwifi_mod_params.led_mode == IWL_LED_DISABLE) 132e705c121SKalle Valo return; 133e705c121SKalle Valo 134e705c121SKalle Valo led_classdev_unregister(&mvm->led); 135e705c121SKalle Valo kfree(mvm->led.name); 136e705c121SKalle Valo } 137