Commit a9dd0c93 authored by Arunmani Alagarsamy's avatar Arunmani Alagarsamy Committed by Chris Friedt
Browse files

drivers: wifi: siwx91x: Support max TX power configuration via Device Tree

Add support for configuring the maximum TX power for STA and AP modes using
a Device Tree property (`max-tx-power`). If unspecified, the default value
is set to 31 dBm.

Signed-off-by: default avatarArunmani Alagarsamy <arunmani.a@silabs.com>
parent 814a9e68
Loading
Loading
Loading
Loading
+32 −2
Changes for drivers/wifi/siwx91x/siwx91x_wifi.c: 32 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -185,9 +185,21 @@ bool siwx91x_param_changed(struct wifi_iface_status *prev_params,
	return false;
}

static int siwx91x_set_max_tx_power(const struct siwx91x_config *siwx91x_cfg)
{
	sl_wifi_interface_t interface = sl_wifi_get_default_interface();
	sl_wifi_max_tx_power_t max_tx_power = {
		.scan_tx_power = siwx91x_cfg->scan_tx_power,
		.join_tx_power = siwx91x_cfg->join_tx_power,
	};

	return sl_wifi_set_max_tx_power(interface, max_tx_power);
}

static int siwx91x_mode(const struct device *dev, struct wifi_mode_info *mode)
{
	sl_wifi_interface_t interface = sl_wifi_get_default_interface();
	const struct siwx91x_config *siwx91x_cfg = dev->config;
	struct siwx91x_dev *sidev = dev->data;
	int cur_mode;
	int ret = 0;
@@ -207,6 +219,12 @@ static int siwx91x_mode(const struct device *dev, struct wifi_mode_info *mode)
			if (ret < 0) {
				return ret;
			}

			ret = siwx91x_set_max_tx_power(siwx91x_cfg);
			if (ret != SL_STATUS_OK) {
				LOG_ERR("Failed to set max tx power:%x", ret);
				return -EINVAL;
			}
		}
		sidev->state = WIFI_STATE_INACTIVE;
	}
@@ -353,6 +371,7 @@ static int siwx91x_get_version(const struct device *dev, struct wifi_version *pa

static void siwx91x_iface_init(struct net_if *iface)
{
	const struct siwx91x_config *siwx91x_cfg = iface->if_dev->dev->config;
	struct siwx91x_dev *sidev = iface->if_dev->dev->data;
	int ret;

@@ -369,6 +388,12 @@ static void siwx91x_iface_init(struct net_if *iface)
	sl_wifi_set_callback(SL_WIFI_STATS_RESPONSE_EVENTS, siwx91x_wifi_module_stats_event_handler,
			     sidev);

	ret = siwx91x_set_max_tx_power(siwx91x_cfg);
	if (ret != SL_STATUS_OK) {
		LOG_ERR("Failed to set max tx power:%x", ret);
		return;
	}

	ret = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, &sidev->macaddr);
	if (ret) {
		LOG_ERR("sl_wifi_get_mac_address(): %#04x", ret);
@@ -419,6 +444,11 @@ static const struct net_wifi_mgmt_offload siwx91x_api = {
	.wifi_mgmt_api = &siwx91x_mgmt,
};

static const struct siwx91x_config siwx91x_cfg = {
	.scan_tx_power = DT_INST_PROP(0, wifi_max_tx_pwr_scan),
	.join_tx_power = DT_INST_PROP(0, wifi_max_tx_pwr_join),
};

static struct siwx91x_dev sidev = {
	.ps_params.enabled = WIFI_PS_DISABLED,
	.ps_params.exit_strategy = WIFI_PS_EXIT_EVERY_TIM,
@@ -427,9 +457,9 @@ static struct siwx91x_dev sidev = {
};

#ifdef CONFIG_WIFI_SILABS_SIWX91X_NET_STACK_NATIVE
ETH_NET_DEVICE_DT_INST_DEFINE(0, siwx91x_dev_init, NULL, &sidev, NULL,
ETH_NET_DEVICE_DT_INST_DEFINE(0, siwx91x_dev_init, NULL, &sidev, &siwx91x_cfg,
			      CONFIG_WIFI_INIT_PRIORITY, &siwx91x_api, NET_ETH_MTU);
#else
NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, siwx91x_dev_init, NULL, &sidev, NULL,
NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, siwx91x_dev_init, NULL, &sidev, &siwx91x_cfg,
				  CONFIG_WIFI_INIT_PRIORITY, &siwx91x_api, NET_ETH_MTU);
#endif
+5 −0
Changes for drivers/wifi/siwx91x/siwx91x_wifi.h: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,11 @@

#include "sl_si91x_types.h"

struct siwx91x_config {
	uint8_t scan_tx_power;
	uint8_t join_tx_power;
};

struct siwx91x_dev {
	struct net_if *iface;
	sl_mac_address_t macaddr;
+16 −0
Changes for dts/bindings/wifi/silabs,siwx91x-wifi.yaml: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,3 +5,19 @@
description: Silabs SiWx91x SoC WiFi

compatible: "silabs,siwx91x-wifi"

properties:
  wifi-max-tx-pwr-scan:
    type: int
    default: 31
    description: |
      Maximum TX power (in dBm) used during Wi‑Fi scanning. Actual
      output may be capped by regulatory or hardware constraints.
      Note: SiWx91x firmware does **not** support per‑rate power.
  wifi-max-tx-pwr-join:
    type: int
    default: 31
    description: |
      Maximum TX power (in dBm) used when joining a Wi‑Fi network.
      Actual output may be capped by regulatory or hardware constraints.
      Note: SiWx91x firmware does **not** support per‑rate power.