[][MAC80211][WiFi7][app][Add Griffin support for atenl/iwpriv]

[Description]
Add Griffin support for atenl & iwpriv wrapper.
Also, add device id macro to prevent any confusion regarding the
inconsistency between device id & chip id used by the driver.
For example, for Eagle, MT76 driver use chip id 7996 (align top side
mark), but its pcie device id is 7990.

[Release-log]
N/A

Change-Id: Ia57342dabd252d42c2b9161a309644d069e70b83
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/9663654
diff --git a/feed/app/atenl/files/ated.sh b/feed/app/atenl/files/ated.sh
index 9037054..9046136 100755
--- a/feed/app/atenl/files/ated.sh
+++ b/feed/app/atenl/files/ated.sh
@@ -108,6 +108,10 @@
             SOC_start_idx="0"
             SOC_end_idx="1"
             is_connac3="1"
+        elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7993")" ]; then
+            SOC_start_idx="0"
+            SOC_end_idx="1"
+            is_connac3="1"
         else
             echo "Interface Conversion Failed!"
             echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
@@ -131,6 +135,10 @@
             echo "      echo STARTIDX=0 >> ${ated_file}"
             echo "      echo ENDIDX=1 >> ${ated_file}"
             echo "      echo IS_CONNAC3=1 >> ${ated_file}"
+            echo "For Griffin:"
+            echo "      echo STARTIDX=0 >> ${interface_file}"
+            echo "      echo ENDIDX=1 >> ${interface_file}"
+            echo "      echo IS_CONNAC3=1 >> ${interface_file}"
             exit 0
         fi
         record_config "STARTIDX" ${SOC_start_idx} ${ated_file}
diff --git a/feed/app/atenl/files/iwpriv.sh b/feed/app/atenl/files/iwpriv.sh
index f6cbd4c..9b73fe8 100755
--- a/feed/app/atenl/files/iwpriv.sh
+++ b/feed/app/atenl/files/iwpriv.sh
@@ -118,6 +118,10 @@
             SOC_start_idx="0"
             SOC_end_idx="1"
             is_connac3="1"
+        elif [ ! -z "$(head -c 2 ${eeprom_file} | hexdump | grep "7993")" ]; then
+            SOC_start_idx="0"
+            SOC_end_idx="1"
+            is_connac3="1"
         else
             echo "Interface Conversion Failed!"
             echo "Please use iwpriv <phy0/phy1/..> set <...> or configure the sku of your board manually by the following commands"
@@ -141,6 +145,10 @@
             echo "      echo STARTIDX=0 >> ${interface_file}"
             echo "      echo ENDIDX=1 >> ${interface_file}"
             echo "      echo IS_CONNAC3=1 >> ${interface_file}"
+            echo "For Griffin:"
+            echo "      echo STARTIDX=0 >> ${interface_file}"
+            echo "      echo ENDIDX=1 >> ${interface_file}"
+            echo "      echo IS_CONNAC3=1 >> ${interface_file}"
             exit 0
         fi
         record_config "STARTIDX" ${SOC_start_idx} ${interface_file}
@@ -198,10 +206,8 @@
 function change_band_idx {
     local new_idx=$1
     local new_phy_idx=$phy_idx
-
     local old_idx=$(get_config "ATECTRLBANDIDX" ${iwpriv_file})
 
-
     if [[ ${interface_ori} == "ra"* ]]; then
         if [ -z "${old_idx}" ] || [ "${old_idx}" != "${new_idx}" ]; then
             if [ "${new_idx}" = "0" ]; then
diff --git a/feed/app/atenl/src/atenl.h b/feed/app/atenl/src/atenl.h
index edd3b78..6f4f0f5 100644
--- a/feed/app/atenl/src/atenl.h
+++ b/feed/app/atenl/src/atenl.h
@@ -285,7 +285,10 @@
 	MT_EE_EAGLE_BAND_SEL_2GHZ,
 	MT_EE_EAGLE_BAND_SEL_5GHZ,
 	MT_EE_EAGLE_BAND_SEL_6GHZ,
-	MT_EE_EAGLE_BAND_SEL_5GHZ_6GHZ,
+	MT_EE_EAGLE_BAND_SEL_5GHZ_LOW,
+	MT_EE_EAGLE_BAND_SEL_5GHZ_HIGH,
+	MT_EE_EAGLE_BAND_SEL_6GHZ_LOW,
+	MT_EE_EAGLE_BAND_SEL_6GHZ_HIGH,
 };
 
 #define MT_EE_WIFI_CONF				0x190
@@ -391,39 +394,67 @@
 	PREK_CLEAN_DPD,
 };
 
+#define MT7916_EEPROM_CHIP_ID		0x7916
+
+/* Wi-Fi6 device id */
+#define MT7915_DEVICE_ID		0x7915
+#define MT7915_DEVICE_ID_2		0x7916
+#define MT7916_DEVICE_ID		0x7906
+#define MT7916_DEVICE_ID_2		0x790a
+#define MT7981_DEVICE_ID		0x7981
+#define MT7986_DEVICE_ID		0x7986
+
+/* Wi-Fi7 device id */
+#define MT7996_DEVICE_ID		0x7990
+#define MT7996_DEVICE_ID_2		0x7991
+#define MT7992_DEVICE_ID		0x7992
+#define MT7992_DEVICE_ID_2		0x799a
+#define MT7990_DEVICE_ID		0x7993
+#define MT7990_DEVICE_ID_2		0x799b
+
 static inline bool is_mt7915(struct atenl *an)
 {
-	return an->chip_id == 0x7915;
+	return an->chip_id == MT7915_DEVICE_ID;
 }
 
 static inline bool is_mt7916(struct atenl *an)
 {
-	return (an->chip_id == 0x7916) || (an->chip_id == 0x7906);
+	/* Merlin is special case:
+	 * pcie id is 0x7906/0x790a but eeprom chip id use 0x7916,
+	 * since 0x7916 is already used by the second pcie of Harrier.
+	 */
+	return (an->chip_id == MT7916_EEPROM_CHIP_ID) ||
+	       (an->chip_id == MT7916_DEVICE_ID);
 }
 
 static inline bool is_mt7981(struct atenl *an)
 {
-	return an->chip_id == 0x7981;
+	return an->chip_id == MT7981_DEVICE_ID;
 }
 
 static inline bool is_mt7986(struct atenl *an)
 {
-	return an->chip_id == 0x7986;
+	return an->chip_id == MT7986_DEVICE_ID;
 }
 
 static inline bool is_mt7996(struct atenl *an)
 {
-	return an->chip_id == 0x7990;
+	return an->chip_id == MT7996_DEVICE_ID;
 }
 
 static inline bool is_mt7992(struct atenl *an)
 {
-	return an->chip_id == 0x7992;
+	return an->chip_id == MT7992_DEVICE_ID;
 }
 
+static inline bool is_mt7990(struct atenl *an)
+{
+	return an->chip_id == MT7990_DEVICE_ID;
+}
+
 static inline bool is_connac3(struct atenl *an)
 {
-	return is_mt7996(an) || is_mt7992(an);
+	return is_mt7996(an) || is_mt7992(an) || is_mt7990(an);
 }
 
 int atenl_eth_init(struct atenl *an);
diff --git a/feed/app/atenl/src/eeprom.c b/feed/app/atenl/src/eeprom.c
index a3c73cf..6dd4113 100644
--- a/feed/app/atenl/src/eeprom.c
+++ b/feed/app/atenl/src/eeprom.c
@@ -151,6 +151,8 @@
 		/* TODO: parse info if required */
 	} else if (is_mt7992(an)) {
 		/* TODO: parse info if required */
+	} else if (is_mt7990(an)) {
+		/* TODO: parse info if required */
 	}
 }
 
@@ -158,19 +160,20 @@
 atenl_eeprom_init_max_size(struct atenl *an)
 {
 	switch (an->chip_id) {
-	case 0x7915:
+	case MT7915_DEVICE_ID:
 		an->eeprom_size = 3584;
 		an->eeprom_prek_offs = 0x62;
 		break;
-	case 0x7906:
-	case 0x7916:
-	case 0x7981:
-	case 0x7986:
+	case MT7916_EEPROM_CHIP_ID:
+	case MT7916_DEVICE_ID:
+	case MT7981_DEVICE_ID:
+	case MT7986_DEVICE_ID:
 		an->eeprom_size = 4096;
 		an->eeprom_prek_offs = 0x19a;
 		break;
-	case 0x7990:
-	case 0x7992:
+	case MT7996_DEVICE_ID:
+	case MT7992_DEVICE_ID:
+	case MT7990_DEVICE_ID:
 		an->eeprom_size = 7680;
 		an->eeprom_prek_offs = 0x1a5;
 	default:
@@ -255,20 +258,21 @@
 			case MT_EE_EAGLE_BAND_SEL_2GHZ:
 				anb->cap = BAND_TYPE_2G;
 				break;
+			case MT_EE_EAGLE_BAND_SEL_5GHZ_LOW:
+			case MT_EE_EAGLE_BAND_SEL_5GHZ_HIGH:
 			case MT_EE_EAGLE_BAND_SEL_5GHZ:
 				anb->cap = BAND_TYPE_5G;
 				break;
+			case MT_EE_EAGLE_BAND_SEL_6GHZ_LOW:
+			case MT_EE_EAGLE_BAND_SEL_6GHZ_HIGH:
 			case MT_EE_EAGLE_BAND_SEL_6GHZ:
 				anb->cap = BAND_TYPE_6G;
 				break;
-			case MT_EE_EAGLE_BAND_SEL_5GHZ_6GHZ:
-				anb->cap = BAND_TYPE_5G_6G;
-				break;
 			default:
 				break;
 			}
 		}
-	} else if (is_mt7992(an)) {
+	} else if (is_mt7992(an) || is_mt7990(an)) {
 		struct atenl_band *anb;
 		u8 val, band_sel;
 		u8 band_sel_mask[2] = {EAGLE_BAND_SEL(0), EAGLE_BAND_SEL(1)};
@@ -284,15 +288,16 @@
 			case MT_EE_EAGLE_BAND_SEL_2GHZ:
 				anb->cap = BAND_TYPE_2G;
 				break;
+			case MT_EE_EAGLE_BAND_SEL_5GHZ_LOW:
+			case MT_EE_EAGLE_BAND_SEL_5GHZ_HIGH:
 			case MT_EE_EAGLE_BAND_SEL_5GHZ:
 				anb->cap = BAND_TYPE_5G;
 				break;
+			case MT_EE_EAGLE_BAND_SEL_6GHZ_LOW:
+			case MT_EE_EAGLE_BAND_SEL_6GHZ_HIGH:
 			case MT_EE_EAGLE_BAND_SEL_6GHZ:
 				anb->cap = BAND_TYPE_6G;
 				break;
-			case MT_EE_EAGLE_BAND_SEL_5GHZ_6GHZ:
-				anb->cap = BAND_TYPE_5G_6G;
-				break;
 			default:
 				break;
 			}
@@ -304,7 +309,7 @@
 atenl_eeprom_init_antenna_cap(struct atenl *an)
 {
 	switch (an->chip_id) {
-	case 0x7915:
+	case MT7915_DEVICE_ID:
 		if (an->anb[0].cap == BAND_TYPE_2G_5G)
 			an->anb[0].chainmask = 0xf;
 		else {
@@ -312,28 +317,34 @@
 			an->anb[1].chainmask = 0xc;
 		}
 		break;
-	case 0x7906:
-	case 0x7916:
+	case MT7916_EEPROM_CHIP_ID:
+	case MT7916_DEVICE_ID:
 		an->anb[0].chainmask = 0x3;
 		an->anb[1].chainmask = 0x3;
 		break;
-	case 0x7981:
+	case MT7981_DEVICE_ID:
 		an->anb[0].chainmask = 0x3;
 		an->anb[1].chainmask = 0x7;
 		break;
-	case 0x7986:
+	case MT7986_DEVICE_ID:
 		an->anb[0].chainmask = 0xf;
 		an->anb[1].chainmask = 0xf;
 		break;
-	case 0x7990:
+	case MT7996_DEVICE_ID:
+		/* TODO: handle 4T5R */
 		an->anb[0].chainmask = 0xf;
 		an->anb[1].chainmask = 0xf;
 		an->anb[2].chainmask = 0xf;
 		break;
-	case 0x7992:
+	case MT7992_DEVICE_ID:
+		/* TODO: handle BE7200 2i5i 5T5R */
 		an->anb[0].chainmask = 0xf;
 		an->anb[1].chainmask = 0xf;
 		break;
+	case MT7990_DEVICE_ID:
+		an->anb[0].chainmask = 0x3;
+		an->anb[1].chainmask = 0x7;
+		break;
 	default:
 		break;
 	}