18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci  Broadcom B43 wireless driver
58c2ecf20Sopenharmony_ci  RFKILL support
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci  Copyright (c) 2007 Michael Buesch <m@bues.ch>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci*/
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "b43.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/* Returns TRUE, if the radio is enabled in hardware. */
168c2ecf20Sopenharmony_cibool b43_is_hw_radio_enabled(struct b43_wldev *dev)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	return !(b43_read32(dev, B43_MMIO_RADIO_HWENABLED_HI)
198c2ecf20Sopenharmony_ci		& B43_MMIO_RADIO_HWENABLED_HI_MASK);
208c2ecf20Sopenharmony_ci}
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/* The poll callback for the hardware button. */
238c2ecf20Sopenharmony_civoid b43_rfkill_poll(struct ieee80211_hw *hw)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	struct b43_wl *wl = hw_to_b43_wl(hw);
268c2ecf20Sopenharmony_ci	struct b43_wldev *dev = wl->current_dev;
278c2ecf20Sopenharmony_ci	bool enabled;
288c2ecf20Sopenharmony_ci	bool brought_up = false;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	mutex_lock(&wl->mutex);
318c2ecf20Sopenharmony_ci	if (unlikely(b43_status(dev) < B43_STAT_INITIALIZED)) {
328c2ecf20Sopenharmony_ci		if (b43_bus_powerup(dev, 0)) {
338c2ecf20Sopenharmony_ci			mutex_unlock(&wl->mutex);
348c2ecf20Sopenharmony_ci			return;
358c2ecf20Sopenharmony_ci		}
368c2ecf20Sopenharmony_ci		b43_device_enable(dev, 0);
378c2ecf20Sopenharmony_ci		brought_up = true;
388c2ecf20Sopenharmony_ci	}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	enabled = b43_is_hw_radio_enabled(dev);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	if (unlikely(enabled != dev->radio_hw_enable)) {
438c2ecf20Sopenharmony_ci		dev->radio_hw_enable = enabled;
448c2ecf20Sopenharmony_ci		b43info(wl, "Radio hardware status changed to %s\n",
458c2ecf20Sopenharmony_ci			enabled ? "ENABLED" : "DISABLED");
468c2ecf20Sopenharmony_ci		wiphy_rfkill_set_hw_state(hw->wiphy, !enabled);
478c2ecf20Sopenharmony_ci		if (enabled != dev->phy.radio_on)
488c2ecf20Sopenharmony_ci			b43_software_rfkill(dev, !enabled);
498c2ecf20Sopenharmony_ci	}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	if (brought_up) {
528c2ecf20Sopenharmony_ci		b43_device_disable(dev, 0);
538c2ecf20Sopenharmony_ci		b43_bus_may_powerdown(dev);
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	mutex_unlock(&wl->mutex);
578c2ecf20Sopenharmony_ci}
58