diff mbox series

[v3,09/12] wifi: rtlwifi: Add rtl8192du/fw.{c,h} and rtl8192du/led.{c,h}

Message ID 254c1ce0-3d28-4f7f-97c2-e94515e3dc66@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Ping-Ke Shih
Headers show
Series wifi: rtlwifi: Add new rtl8192du driver | expand

Commit Message

Bitterblue Smith March 20, 2024, 7:41 p.m. UTC
fw.c contains a function for loading the firmware.
led.c contains a function for controlling the LED.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v3:
 - No change.

v2:
 - Patch is new in v2, split from patch 3/3 in v1.
---
 .../wireless/realtek/rtlwifi/rtl8192du/fw.c   | 109 ++++++++++++++++++
 .../wireless/realtek/rtlwifi/rtl8192du/fw.h   |   9 ++
 .../wireless/realtek/rtlwifi/rtl8192du/led.c  |  10 ++
 .../wireless/realtek/rtlwifi/rtl8192du/led.h  |   9 ++
 4 files changed, 137 insertions(+)
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
 create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h

Comments

Ping-Ke Shih March 22, 2024, 5:42 a.m. UTC | #1
On Wed, 2024-03-20 at 21:41 +0200, Bitterblue Smith wrote:
> 
> fw.c contains a function for loading the firmware.
> led.c contains a function for controlling the LED.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> ---
> v3:
>  - No change.
> 
> v2:
>  - Patch is new in v2, split from patch 3/3 in v1.
> ---
>  .../wireless/realtek/rtlwifi/rtl8192du/fw.c   | 109 ++++++++++++++++++
>  .../wireless/realtek/rtlwifi/rtl8192du/fw.h   |   9 ++
>  .../wireless/realtek/rtlwifi/rtl8192du/led.c  |  10 ++
>  .../wireless/realtek/rtlwifi/rtl8192du/led.h  |   9 ++
>  4 files changed, 137 insertions(+)
>  create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
>  create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
>  create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
>  create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h
> 
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
> b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
> new file mode 100644
> index 000000000000..1521460f4f37
> --- /dev/null
> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
> @@ -0,0 +1,109 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright(c) 2009-2012  Realtek Corporation.*/
> +
> +#include "../wifi.h"
> +#include "../pci.h"
> +#include "../base.h"
> +#include "../efuse.h"
> +#include "../rtl8192d/reg.h"
> +#include "../rtl8192d/def.h"
> +#include "../rtl8192d/fw_common.h"
> +#include "fw.h"
> +#include "sw.h"
> +
> +int rtl92d_download_fw(struct ieee80211_hw *hw)
> +{
> +       struct rtl_priv *rtlpriv = rtl_priv(hw);
> +       struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
> +       enum version_8192d version = rtlhal->version;
> +       bool fwdl_in_process = false;
> +       bool fw_downloaded = false;
> +       u32 fwsize, count;
> +       u8 *pfwheader;
> +       u8 *pfwdata;
> +       u8 value;
> +       int err;
> +
> +       if (rtlpriv->max_fw_size == 0 || !rtlhal->pfirmware)
> +               return 1;
> +
> +       fwsize = rtlhal->fwsize;
> +       pfwheader = rtlhal->pfirmware;
> +       pfwdata = rtlhal->pfirmware;
> +       rtlhal->fw_version = (u16)GET_FIRMWARE_HDR_VERSION(pfwheader);
> +       rtlhal->fw_subversion = (u16)GET_FIRMWARE_HDR_SUB_VER(pfwheader);

blank lines (I also insert them below as examples)

> +       rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
> +               "FirmwareVersion(%d), FirmwareSubVersion(%d), Signature(%#x)\n",
> +               rtlhal->fw_version, rtlhal->fw_subversion,
> +               GET_FIRMWARE_HDR_SIGNATURE(pfwheader));
> +       if (IS_FW_HEADER_EXIST(pfwheader)) {
> +               rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
> +                       "Shift 32 bytes for FW header!!\n");
> +               pfwdata = pfwdata + 32;
> +               fwsize = fwsize - 32;
> +       }
> +
> +       mutex_lock(&globalmutex_for_fwdownload);
> +       fw_downloaded = rtl92d_is_fw_downloaded(rtlpriv);
> +       if ((rtl_read_byte(rtlpriv, 0x1f) & BIT(5)) == BIT(5))
> +               fwdl_in_process = true;
> +       else
> +               fwdl_in_process = false;

> +       if (fw_downloaded) {
> +               mutex_unlock(&globalmutex_for_fwdownload);
> +               goto exit;
> +       } else if (fwdl_in_process) {
> +               mutex_unlock(&globalmutex_for_fwdownload);
> +               for (count = 0; count < 5000; count++) {
> +                       udelay(500);

> +                       mutex_lock(&globalmutex_for_fwdownload);
> +                       fw_downloaded = rtl92d_is_fw_downloaded(rtlpriv);
> +                       if ((rtl_read_byte(rtlpriv, 0x1f) & BIT(5)) == BIT(5))
> +                               fwdl_in_process = true;
> +                       else
> +                               fwdl_in_process = false;
> +                       mutex_unlock(&globalmutex_for_fwdownload);

> +                       if (fw_downloaded)
> +                               goto exit;
> +                       else if (!fwdl_in_process)
> +                               break;
> +
> +                       rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG,
> +                               "Wait for another mac download fw\n");
> +               }
> +               mutex_lock(&globalmutex_for_fwdownload);

> +               value = rtl_read_byte(rtlpriv, 0x1f);
> +               value |= BIT(5);
> +               rtl_write_byte(rtlpriv, 0x1f, value);
> +               mutex_unlock(&globalmutex_for_fwdownload);
> +       } else {
> +               value = rtl_read_byte(rtlpriv, 0x1f);
> +               value |= BIT(5);
> +               rtl_write_byte(rtlpriv, 0x1f, value);
> +               mutex_unlock(&globalmutex_for_fwdownload);
> +       }
> +
> +       /* If 8051 is running in RAM code, driver should
> +        * inform Fw to reset by itself, or it will cause
> +        * download Fw fail.
> +        */
> +       if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) {
> +               rtl92d_firmware_selfreset(hw);
> +               rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
> +       }

> +       rtl92d_enable_fw_download(hw, true);
> +       rtl92d_write_fw(hw, version, pfwdata, fwsize);
> +       rtl92d_enable_fw_download(hw, false);

> +       mutex_lock(&globalmutex_for_fwdownload);
> +       err = rtl92d_fw_free_to_go(hw);
> +       /* download fw over,clear 0x1f[5] */
> +       value = rtl_read_byte(rtlpriv, 0x1f);
> +       value &= (~BIT(5));
> +       rtl_write_byte(rtlpriv, 0x1f, value);
> +       mutex_unlock(&globalmutex_for_fwdownload);

> +       if (err)
> +               pr_err("fw is not ready to run!\n");
> +exit:
> +       err = rtl92d_fw_init(hw);
> +       return err;
> +}
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
> b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
> new file mode 100644
> index 000000000000..857431fe8952
> --- /dev/null
> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright(c) 2009-2012  Realtek Corporation.*/
> +
> +#ifndef __RTL92D__FW__H__
> +#define __RTL92D__FW__H__

__RTL8192DU_FW_H__ ?

Here you use double underscore that is inconsistent with others.

> +
> +int rtl92d_download_fw(struct ieee80211_hw *hw);
> +
> +#endif
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
> b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
> new file mode 100644
> index 000000000000..a2761f25e94e
> --- /dev/null
> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
> @@ -0,0 +1,10 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright(c) 2009-2012  Realtek Corporation.*/
> +
> +#include "../wifi.h"
> +#include "led.h"
> +
> +void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
> +{
> +       /* The hardware has control. */
> +}
> diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h
> b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h
> new file mode 100644
> index 000000000000..b7f7a74d5261
> --- /dev/null
> +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright(c) 2009-2012  Realtek Corporation.*/
> +
> +#ifndef __RTL92CE_LED_H__
> +#define __RTL92CE_LED_H__

__RTL8192DU_LED_H__ ?

Some headers files use short forms like RTL92CE, but others use full form
like RTL8821AE. Both are fine, just ensure all consistent in your patchset.

> +
> +void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction);
> +
> +#endif
> --
> 2.43.2
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
new file mode 100644
index 000000000000..1521460f4f37
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.c
@@ -0,0 +1,109 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2009-2012  Realtek Corporation.*/
+
+#include "../wifi.h"
+#include "../pci.h"
+#include "../base.h"
+#include "../efuse.h"
+#include "../rtl8192d/reg.h"
+#include "../rtl8192d/def.h"
+#include "../rtl8192d/fw_common.h"
+#include "fw.h"
+#include "sw.h"
+
+int rtl92d_download_fw(struct ieee80211_hw *hw)
+{
+	struct rtl_priv *rtlpriv = rtl_priv(hw);
+	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
+	enum version_8192d version = rtlhal->version;
+	bool fwdl_in_process = false;
+	bool fw_downloaded = false;
+	u32 fwsize, count;
+	u8 *pfwheader;
+	u8 *pfwdata;
+	u8 value;
+	int err;
+
+	if (rtlpriv->max_fw_size == 0 || !rtlhal->pfirmware)
+		return 1;
+
+	fwsize = rtlhal->fwsize;
+	pfwheader = rtlhal->pfirmware;
+	pfwdata = rtlhal->pfirmware;
+	rtlhal->fw_version = (u16)GET_FIRMWARE_HDR_VERSION(pfwheader);
+	rtlhal->fw_subversion = (u16)GET_FIRMWARE_HDR_SUB_VER(pfwheader);
+	rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
+		"FirmwareVersion(%d), FirmwareSubVersion(%d), Signature(%#x)\n",
+		rtlhal->fw_version, rtlhal->fw_subversion,
+		GET_FIRMWARE_HDR_SIGNATURE(pfwheader));
+	if (IS_FW_HEADER_EXIST(pfwheader)) {
+		rtl_dbg(rtlpriv, COMP_INIT, DBG_LOUD,
+			"Shift 32 bytes for FW header!!\n");
+		pfwdata = pfwdata + 32;
+		fwsize = fwsize - 32;
+	}
+
+	mutex_lock(&globalmutex_for_fwdownload);
+	fw_downloaded = rtl92d_is_fw_downloaded(rtlpriv);
+	if ((rtl_read_byte(rtlpriv, 0x1f) & BIT(5)) == BIT(5))
+		fwdl_in_process = true;
+	else
+		fwdl_in_process = false;
+	if (fw_downloaded) {
+		mutex_unlock(&globalmutex_for_fwdownload);
+		goto exit;
+	} else if (fwdl_in_process) {
+		mutex_unlock(&globalmutex_for_fwdownload);
+		for (count = 0; count < 5000; count++) {
+			udelay(500);
+			mutex_lock(&globalmutex_for_fwdownload);
+			fw_downloaded = rtl92d_is_fw_downloaded(rtlpriv);
+			if ((rtl_read_byte(rtlpriv, 0x1f) & BIT(5)) == BIT(5))
+				fwdl_in_process = true;
+			else
+				fwdl_in_process = false;
+			mutex_unlock(&globalmutex_for_fwdownload);
+			if (fw_downloaded)
+				goto exit;
+			else if (!fwdl_in_process)
+				break;
+
+			rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG,
+				"Wait for another mac download fw\n");
+		}
+		mutex_lock(&globalmutex_for_fwdownload);
+		value = rtl_read_byte(rtlpriv, 0x1f);
+		value |= BIT(5);
+		rtl_write_byte(rtlpriv, 0x1f, value);
+		mutex_unlock(&globalmutex_for_fwdownload);
+	} else {
+		value = rtl_read_byte(rtlpriv, 0x1f);
+		value |= BIT(5);
+		rtl_write_byte(rtlpriv, 0x1f, value);
+		mutex_unlock(&globalmutex_for_fwdownload);
+	}
+
+	/* If 8051 is running in RAM code, driver should
+	 * inform Fw to reset by itself, or it will cause
+	 * download Fw fail.
+	 */
+	if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) {
+		rtl92d_firmware_selfreset(hw);
+		rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
+	}
+	rtl92d_enable_fw_download(hw, true);
+	rtl92d_write_fw(hw, version, pfwdata, fwsize);
+	rtl92d_enable_fw_download(hw, false);
+	mutex_lock(&globalmutex_for_fwdownload);
+	err = rtl92d_fw_free_to_go(hw);
+	/* download fw over,clear 0x1f[5] */
+	value = rtl_read_byte(rtlpriv, 0x1f);
+	value &= (~BIT(5));
+	rtl_write_byte(rtlpriv, 0x1f, value);
+	mutex_unlock(&globalmutex_for_fwdownload);
+	if (err)
+		pr_err("fw is not ready to run!\n");
+exit:
+	err = rtl92d_fw_init(hw);
+	return err;
+}
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
new file mode 100644
index 000000000000..857431fe8952
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/fw.h
@@ -0,0 +1,9 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2009-2012  Realtek Corporation.*/
+
+#ifndef __RTL92D__FW__H__
+#define __RTL92D__FW__H__
+
+int rtl92d_download_fw(struct ieee80211_hw *hw);
+
+#endif
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
new file mode 100644
index 000000000000..a2761f25e94e
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.c
@@ -0,0 +1,10 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright(c) 2009-2012  Realtek Corporation.*/
+
+#include "../wifi.h"
+#include "led.h"
+
+void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction)
+{
+	/* The hardware has control. */
+}
diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h
new file mode 100644
index 000000000000..b7f7a74d5261
--- /dev/null
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/led.h
@@ -0,0 +1,9 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2009-2012  Realtek Corporation.*/
+
+#ifndef __RTL92CE_LED_H__
+#define __RTL92CE_LED_H__
+
+void rtl92de_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction);
+
+#endif