Path: blob/main/sys/contrib/dev/iwlwifi/mld/led.c
106924 views
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause1/*2* Copyright (C) 2024 Intel Corporation3*/4#include <linux/leds.h>5#include <net/mac80211.h>67#include "fw/api/led.h"8#include "mld.h"9#include "led.h"10#include "hcmd.h"1112static void iwl_mld_send_led_fw_cmd(struct iwl_mld *mld, bool on)13{14struct iwl_led_cmd led_cmd = {15.status = cpu_to_le32(on),16};17int err;1819if (WARN_ON(!mld->fw_status.running))20return;2122err = iwl_mld_send_cmd_with_flags_pdu(mld, WIDE_ID(LONG_GROUP,23LEDS_CMD),24CMD_ASYNC, &led_cmd);2526if (err)27IWL_WARN(mld, "LED command failed: %d\n", err);28}2930static void iwl_led_brightness_set(struct led_classdev *led_cdev,31enum led_brightness brightness)32{33struct iwl_mld *mld = container_of(led_cdev, struct iwl_mld, led);3435if (!mld->fw_status.running)36return;3738iwl_mld_send_led_fw_cmd(mld, brightness > 0);39}4041int iwl_mld_leds_init(struct iwl_mld *mld)42{43int mode = iwlwifi_mod_params.led_mode;44int ret;4546switch (mode) {47case IWL_LED_BLINK:48IWL_ERR(mld, "Blink led mode not supported, used default\n");49fallthrough;50case IWL_LED_DEFAULT:51case IWL_LED_RF_STATE:52mode = IWL_LED_RF_STATE;53break;54case IWL_LED_DISABLE:55IWL_INFO(mld, "Led disabled\n");56return 0;57default:58return -EINVAL;59}6061mld->led.name = kasprintf(GFP_KERNEL, "%s-led",62wiphy_name(mld->hw->wiphy));63if (!mld->led.name)64return -ENOMEM;6566mld->led.brightness_set = iwl_led_brightness_set;67mld->led.max_brightness = 1;6869if (mode == IWL_LED_RF_STATE)70mld->led.default_trigger =71ieee80211_get_radio_led_name(mld->hw);7273ret = led_classdev_register(mld->trans->dev, &mld->led);74if (ret) {75kfree(mld->led.name);76mld->led.name = NULL;77IWL_INFO(mld, "Failed to enable led\n");78}7980return ret;81}8283void iwl_mld_led_config_fw(struct iwl_mld *mld)84{85if (!mld->led.name)86return;8788iwl_mld_send_led_fw_cmd(mld, mld->led.brightness > 0);89}9091void iwl_mld_leds_exit(struct iwl_mld *mld)92{93if (!mld->led.name)94return;9596led_classdev_unregister(&mld->led);97kfree(mld->led.name);98mld->led.name = NULL;99}100101102