1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2019 Intel Corporation
4 * Copyright (C) 2017 Intel Deutschland GmbH
6 #include <linux/leds.h>
11 static void iwl_mvm_send_led_fw_cmd(struct iwl_mvm *mvm, bool on)
13 struct iwl_led_cmd led_cmd = {
14 .status = cpu_to_le32(on),
16 struct iwl_host_cmd cmd = {
17 .id = WIDE_ID(LONG_GROUP, LEDS_CMD),
18 .len = { sizeof(led_cmd), },
19 .data = { &led_cmd, },
24 if (!iwl_mvm_firmware_running(mvm))
27 err = iwl_mvm_send_cmd(mvm, &cmd);
30 IWL_WARN(mvm, "LED command failed: %d\n", err);
33 static void iwl_mvm_led_set(struct iwl_mvm *mvm, bool on)
35 if (fw_has_capa(&mvm->fw->ucode_capa,
36 IWL_UCODE_TLV_CAPA_LED_CMD_SUPPORT)) {
37 iwl_mvm_send_led_fw_cmd(mvm, on);
41 iwl_write32(mvm->trans, CSR_LED_REG,
42 on ? CSR_LED_REG_TURN_ON : CSR_LED_REG_TURN_OFF);
45 static void iwl_led_brightness_set(struct led_classdev *led_cdev,
46 enum led_brightness brightness)
48 struct iwl_mvm *mvm = container_of(led_cdev, struct iwl_mvm, led);
50 iwl_mvm_led_set(mvm, brightness > 0);
53 int iwl_mvm_leds_init(struct iwl_mvm *mvm)
55 int mode = iwlwifi_mod_params.led_mode;
60 IWL_ERR(mvm, "Blink led mode not supported, used default\n");
63 case IWL_LED_RF_STATE:
64 mode = IWL_LED_RF_STATE;
67 IWL_INFO(mvm, "Led disabled\n");
73 mvm->led.name = kasprintf(GFP_KERNEL, "%s-led",
74 wiphy_name(mvm->hw->wiphy));
78 mvm->led.brightness_set = iwl_led_brightness_set;
79 mvm->led.max_brightness = 1;
81 if (mode == IWL_LED_RF_STATE)
82 mvm->led.default_trigger =
83 ieee80211_get_radio_led_name(mvm->hw);
85 ret = led_classdev_register(mvm->trans->dev, &mvm->led);
88 IWL_INFO(mvm, "Failed to enable led\n");
92 mvm->init_status |= IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE;
96 void iwl_mvm_leds_sync(struct iwl_mvm *mvm)
98 if (!(mvm->init_status & IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE))
102 * if we control through the register, we're doing it
103 * even when the firmware isn't up, so no need to sync
105 if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000)
108 iwl_mvm_led_set(mvm, mvm->led.brightness > 0);
111 void iwl_mvm_leds_exit(struct iwl_mvm *mvm)
113 if (!(mvm->init_status & IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE))
116 led_classdev_unregister(&mvm->led);
117 kfree(mvm->led.name);
118 mvm->init_status &= ~IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE;