1
0
mirror of https://github.com/aircrack-ng/rtl8812au.git synced 2024-11-23 13:49:57 +00:00
rtl8812au/hal/phydm/phydm_adc_sampling.c

790 lines
23 KiB
C
Raw Normal View History

2018-06-22 16:48:32 +00:00
/******************************************************************************
*
2018-08-24 20:52:34 +00:00
* Copyright(c) 2007 - 2017 Realtek Corporation.
2018-06-22 16:48:32 +00:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2018-08-24 20:52:34 +00:00
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2018-06-22 16:48:32 +00:00
* more details.
*
2018-08-24 20:52:34 +00:00
* The full GNU General Public License is included in this distribution in the
* file called LICENSE.
*
* Contact Information:
* wlanfae <wlanfae@realtek.com>
* Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
* Hsinchu 300, Taiwan.
*
* Larry Finger <Larry.Finger@lwfinger.net>
*
2018-06-22 16:48:32 +00:00
*****************************************************************************/
#include "mp_precomp.h"
#include "phydm_precomp.h"
#if (DM_ODM_SUPPORT_TYPE & ODM_AP)
#if ((RTL8197F_SUPPORT == 1) || (RTL8822B_SUPPORT == 1))
#include "rtl8197f/Hal8197FPhyReg.h"
#include "WlanHAL/HalMac88XX/halmac_reg2.h"
#else
#include "WlanHAL/HalHeader/HalComReg.h"
#endif
#endif
#if (PHYDM_LA_MODE_SUPPORT == 1)
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
#if WPP_SOFTWARE_TRACE
#include "phydm_adc_sampling.tmh"
#endif
#endif
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
boolean
phydm_la_buffer_allocate(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
2018-08-24 20:52:34 +00:00
void *adapter = dm->adapter;
2018-06-22 16:48:32 +00:00
#endif
2018-08-24 20:52:34 +00:00
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
boolean ret = false;
2018-08-24 20:52:34 +00:00
pr_debug("[LA mode BufferAllocate]\n");
2018-06-22 16:48:32 +00:00
if (adc_smp_buf->length == 0) {
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
2018-08-24 20:52:34 +00:00
if (PlatformAllocateMemoryWithZero(adapter, (void **)&adc_smp_buf->octet, adc_smp_buf->buffer_size) != RT_STATUS_SUCCESS) {
2018-06-22 16:48:32 +00:00
#else
2018-08-24 20:52:34 +00:00
odm_allocate_memory(dm, (void **)&adc_smp_buf->octet, adc_smp_buf->buffer_size);
if (!adc_smp_buf->octet) {
2018-06-22 16:48:32 +00:00
#endif
ret = false;
} else {
2018-06-22 16:48:32 +00:00
adc_smp_buf->length = adc_smp_buf->buffer_size;
ret = true;
}
2018-06-22 16:48:32 +00:00
}
return ret;
}
#endif
void
phydm_la_get_tx_pkt_buf(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
u32 i = 0, value32, data_l = 0, data_h = 0;
u32 addr, finish_addr;
u32 end_addr = (adc_smp_buf->start_pos + adc_smp_buf->buffer_size) - 1; /*end_addr = 0x3ffff;*/
boolean is_round_up;
static u32 page = 0xFF;
u32 smp_cnt = 0, smp_number = 0, addr_8byte = 0;
u8 backup_dma = 0;
2018-08-24 20:52:34 +00:00
odm_memory_set(dm, adc_smp_buf->octet, 0, adc_smp_buf->length);
odm_write_1byte(dm, 0x0106, 0x69);
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
pr_debug("GetTxPktBuf\n");
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
value32 = odm_read_4byte(dm, 0x7c0);
2018-06-22 16:48:32 +00:00
is_round_up = (boolean)((value32 & BIT(31)) >> 31);
finish_addr = (value32 & 0x7FFF0000) >> 16; /*Reg7C0[30:16]: finish addr (unit: 8byte)*/
#if (DM_ODM_SUPPORT_TYPE & ODM_AP)
#if (RTL8197F_SUPPORT)
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & ODM_RTL8197F) {
odm_set_bb_reg(dm, 0x7c0, BIT(0), 0x0);
2018-06-22 16:48:32 +00:00
/*Stop DMA*/
2018-08-24 20:52:34 +00:00
backup_dma = odm_get_mac_reg(dm, 0x300, MASKLWORD);
odm_set_mac_reg(dm, 0x300, 0x7fff, 0x7fff);
2018-06-22 16:48:32 +00:00
/*move LA mode content from IMEM to TxPktBuffer
Source : OCPBASE_IMEM 0x00000000
Destination : OCPBASE_TXBUF 0x18780000
Length : 64K*/
2018-08-24 20:52:34 +00:00
GET_HAL_INTERFACE(dm->priv)->init_ddma_handler(dm->priv, OCPBASE_IMEM, OCPBASE_TXBUF, 0x10000);
2018-06-22 16:48:32 +00:00
}
#endif
#endif
if (is_round_up) {
addr = (finish_addr + 1) << 3;
2018-08-24 20:52:34 +00:00
pr_debug("is_round_up = ((%d)), finish_addr=((0x%x)), 0x7c0=((0x%x))\n", is_round_up, finish_addr, value32);
2018-06-22 16:48:32 +00:00
smp_number = ((adc_smp_buf->buffer_size) >> 3); /*Byte to 8Byte (64bit)*/
} else {
addr = adc_smp_buf->start_pos;
addr_8byte = addr >> 3;
if (addr_8byte > finish_addr)
smp_number = addr_8byte - finish_addr;
else
smp_number = finish_addr - addr_8byte;
2018-08-24 20:52:34 +00:00
pr_debug("is_round_up = ((%d)), finish_addr=((0x%x * 8Byte)), Start_Addr = ((0x%x * 8Byte)), smp_number = ((%d))\n", is_round_up, finish_addr, addr_8byte, smp_number);
2018-06-22 16:48:32 +00:00
}
/*
dbg_print("is_round_up = %d, finish_addr=0x%x, value32=0x%x\n", is_round_up, finish_addr, value32);
dbg_print("end_addr = %x, adc_smp_buf->start_pos = 0x%x, adc_smp_buf->buffer_size = 0x%x\n", end_addr, adc_smp_buf->start_pos, adc_smp_buf->buffer_size);
*/
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & ODM_RTL8197F) {
2018-06-22 16:48:32 +00:00
for (addr = 0x0, i = 0; addr < end_addr; addr += 8, i += 2) { /*64K byte*/
if ((addr & 0xfff) == 0)
2018-08-24 20:52:34 +00:00
odm_set_bb_reg(dm, 0x0140, MASKLWORD, 0x780 + (addr >> 12));
data_l = odm_get_bb_reg(dm, 0x8000 + (addr & 0xfff), MASKDWORD);
data_h = odm_get_bb_reg(dm, 0x8000 + (addr & 0xfff) + 4, MASKDWORD);
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
pr_debug("%08x%08x\n", data_h, data_l);
2018-06-22 16:48:32 +00:00
}
} else {
i = 0;
while (addr != (finish_addr << 3)) {
if (page != (addr >> 12)) {
/*Reg140=0x780+(addr>>12), addr=0x30~0x3F, total 16 pages*/
page = (addr >> 12);
}
2018-08-24 20:52:34 +00:00
odm_set_bb_reg(dm, 0x0140, MASKLWORD, 0x780 + page);
2018-06-22 16:48:32 +00:00
/*pDataL = 0x8000+(addr&0xfff);*/
2018-08-24 20:52:34 +00:00
data_l = odm_get_bb_reg(dm, 0x8000 + (addr & 0xfff), MASKDWORD);
data_h = odm_get_bb_reg(dm, 0x8000 + (addr & 0xfff) + 4, MASKDWORD);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
adc_smp_buf->octet[i] = data_h;
adc_smp_buf->octet[i + 1] = data_l;
#endif
#if DBG /*WIN driver check build*/
2018-08-24 20:52:34 +00:00
pr_debug("%08x%08x\n", data_h, data_l);
2018-06-22 16:48:32 +00:00
#else /*WIN driver free build*/
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("%08x%08x\n", adc_smp_buf->octet[i], adc_smp_buf->octet[i + 1]));
#endif
#endif
i = i + 2;
if ((addr + 8) >= end_addr)
addr = adc_smp_buf->start_pos;
else
addr = addr + 8;
smp_cnt++;
if (smp_cnt >= (smp_number - 1))
break;
}
2018-08-24 20:52:34 +00:00
pr_debug("smp_cnt = ((%d))\n", smp_cnt);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("smp_cnt = ((%d))\n", smp_cnt));
#endif
}
#if (DM_ODM_SUPPORT_TYPE & ODM_AP)
#if (RTL8197F_SUPPORT)
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & ODM_RTL8197F)
odm_set_mac_reg(dm, 0x300, 0x7fff, backup_dma); /*Resume DMA*/
2018-06-22 16:48:32 +00:00
#endif
#endif
}
void
phydm_la_mode_set_mac_iq_dump(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
u32 reg_value;
2018-08-24 20:52:34 +00:00
odm_write_1byte(dm, 0x7c0, 0); /*clear all 0x7c0*/
odm_set_mac_reg(dm, 0x7c0, BIT(0), 1); /*Enable LA mode HW block*/
2018-06-22 16:48:32 +00:00
if (adc_smp->la_trig_mode == PHYDM_MAC_TRIG) {
adc_smp->is_bb_trigger = 0;
2018-08-24 20:52:34 +00:00
odm_set_mac_reg(dm, 0x7c0, BIT(2), 1); /*polling bit for MAC mode*/
odm_set_mac_reg(dm, 0x7c0, BIT(4) | BIT(3), adc_smp->la_trigger_edge); /*trigger mode for MAC*/
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
pr_debug("[MAC_trig] ref_mask = ((0x%x)), ref_value = ((0x%x)), dbg_port = ((0x%x))\n", adc_smp->la_mac_mask_or_hdr_sel, adc_smp->la_trig_sig_sel, adc_smp->la_dbg_port);
2018-06-22 16:48:32 +00:00
/*[Set MAC Debug Port]*/
2018-08-24 20:52:34 +00:00
odm_set_mac_reg(dm, 0xF4, BIT(16), 1);
odm_set_mac_reg(dm, 0x38, 0xff0000, adc_smp->la_dbg_port);
odm_set_mac_reg(dm, 0x7c4, MASKDWORD, adc_smp->la_mac_mask_or_hdr_sel);
odm_set_mac_reg(dm, 0x7c8, MASKDWORD, adc_smp->la_trig_sig_sel);
2018-06-22 16:48:32 +00:00
} else {
adc_smp->is_bb_trigger = 1;
2018-08-24 20:52:34 +00:00
odm_set_mac_reg(dm, 0x7c0, BIT(1), 1); /*polling bit for BB ADC mode*/
2018-06-22 16:48:32 +00:00
if (adc_smp->la_trig_mode == PHYDM_ADC_MAC_TRIG) {
2018-08-24 20:52:34 +00:00
odm_set_mac_reg(dm, 0x7c0, BIT(3), 1); /*polling bit for MAC trigger event*/
odm_set_mac_reg(dm, 0x7c0, BIT(7) | BIT(6), adc_smp->la_trig_sig_sel);
2018-06-22 16:48:32 +00:00
if (adc_smp->la_trig_sig_sel == ADCSMP_TRIG_REG)
2018-08-24 20:52:34 +00:00
odm_set_mac_reg(dm, 0x7c0, BIT(5), 1); /* manual trigger 0x7C0[5] = 0->1*/
2018-06-22 16:48:32 +00:00
}
}
2018-08-24 20:52:34 +00:00
reg_value = odm_get_bb_reg(dm, 0x7c0, 0xff);
pr_debug("4. [Set MAC IQ dump] 0x7c0[7:0] = ((0x%x))\n", reg_value);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("4. [Set MAC IQ dump] 0x7c0[7:0] = ((0x%x))\n", reg_value));
#endif
}
void
phydm_adc_smp_start(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
u8 tmp_u1b;
u8 while_cnt = 0;
u8 polling_ok = false, target_polling_bit;
2018-08-24 20:52:34 +00:00
phydm_la_mode_bb_setting(dm);
phydm_la_mode_set_trigger_time(dm, adc_smp->la_trigger_time);
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & ODM_RTL8197F)
odm_set_bb_reg(dm, 0xd00, BIT(26), 0x1);
2018-06-22 16:48:32 +00:00
else { /*for 8814A and 8822B?*/
2018-08-24 20:52:34 +00:00
odm_write_1byte(dm, 0x8b4, 0x80);
/* odm_set_bb_reg(dm, 0x8b4, BIT(7), 1); */
2018-06-22 16:48:32 +00:00
}
2018-08-24 20:52:34 +00:00
phydm_la_mode_set_mac_iq_dump(dm);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_AP)
2018-08-24 20:52:34 +00:00
watchdog_stop(dm->priv);
2018-06-22 16:48:32 +00:00
#endif
target_polling_bit = (adc_smp->is_bb_trigger) ? BIT(1) : BIT(2);
do { /*Polling time always use 100ms, when it exceed 2s, break while loop*/
2018-08-24 20:52:34 +00:00
tmp_u1b = odm_read_1byte(dm, 0x7c0);
2018-06-22 16:48:32 +00:00
if (adc_smp->adc_smp_state != ADCSMP_STATE_SET) {
2018-08-24 20:52:34 +00:00
pr_debug("[state Error] adc_smp_state != ADCSMP_STATE_SET\n");
2018-06-22 16:48:32 +00:00
break;
} else if (tmp_u1b & target_polling_bit) {
ODM_delay_ms(100);
while_cnt = while_cnt + 1;
continue;
} else {
2018-08-24 20:52:34 +00:00
pr_debug("[LA Query OK] polling_bit=((0x%x))\n", target_polling_bit);
2018-06-22 16:48:32 +00:00
polling_ok = true;
break;
}
} while (while_cnt < 20);
if (adc_smp->adc_smp_state == ADCSMP_STATE_SET) {
if (polling_ok)
2018-08-24 20:52:34 +00:00
phydm_la_get_tx_pkt_buf(dm);
2018-06-22 16:48:32 +00:00
else
2018-08-24 20:52:34 +00:00
pr_debug("[Polling timeout]\n");
2018-06-22 16:48:32 +00:00
}
#if (DM_ODM_SUPPORT_TYPE & ODM_AP)
2018-08-24 20:52:34 +00:00
watchdog_resume(dm->priv);
2018-06-22 16:48:32 +00:00
#endif
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
if (adc_smp->adc_smp_state == ADCSMP_STATE_SET)
adc_smp->adc_smp_state = ADCSMP_STATE_QUERY;
#endif
2018-08-24 20:52:34 +00:00
pr_debug("[LA mode] LA_pattern_count = ((%d))\n", adc_smp->la_count);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("[LA mode] la_count = ((%d))\n", adc_smp->la_count));
#endif
2018-08-24 20:52:34 +00:00
adc_smp_stop(dm);
2018-06-22 16:48:32 +00:00
if (adc_smp->la_count == 0) {
2018-08-24 20:52:34 +00:00
pr_debug("LA Dump finished ---------->\n\n\n");
phydm_release_bb_dbg_port(dm);
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
if ((dm->support_ic_type & ODM_RTL8821C) && (dm->cut_version >= ODM_CUT_B))
odm_set_bb_reg(dm, 0x95c, BIT(23), 0);
2018-06-22 16:48:32 +00:00
} else {
adc_smp->la_count--;
2018-08-24 20:52:34 +00:00
pr_debug("LA Dump more ---------->\n\n\n");
adc_smp_set(dm, adc_smp->la_trig_mode, adc_smp->la_trig_sig_sel, adc_smp->la_dma_type, adc_smp->la_trigger_time, 0);
2018-06-22 16:48:32 +00:00
}
}
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
void
adc_smp_work_item_callback(
2018-08-24 20:52:34 +00:00
void *context
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
void *adapter = (void *)context;
PHAL_DATA_TYPE hal_data = GET_HAL_DATA(((PADAPTER)adapter));
struct dm_struct *dm = &hal_data->DM_OutSrc;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
pr_debug("[WorkItem Call back] LA_State=((%d))\n", adc_smp->adc_smp_state);
phydm_adc_smp_start(dm);
2018-06-22 16:48:32 +00:00
}
#endif
void
adc_smp_set(
2018-08-24 20:52:34 +00:00
void *dm_void,
2018-06-22 16:48:32 +00:00
u8 trig_mode,
u32 trig_sig_sel,
u8 dma_data_sig_sel,
u32 trigger_time,
u16 polling_time
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
2018-06-22 16:48:32 +00:00
boolean is_set_success = true;
2018-08-24 20:52:34 +00:00
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
adc_smp->la_trig_mode = trig_mode;
adc_smp->la_trig_sig_sel = trig_sig_sel;
adc_smp->la_dma_type = dma_data_sig_sel;
adc_smp->la_trigger_time = trigger_time;
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
if (adc_smp->adc_smp_state != ADCSMP_STATE_IDLE)
is_set_success = false;
else if (adc_smp->adc_smp_buf.length == 0)
2018-08-24 20:52:34 +00:00
is_set_success = phydm_la_buffer_allocate(dm);
2018-06-22 16:48:32 +00:00
#endif
if (is_set_success) {
adc_smp->adc_smp_state = ADCSMP_STATE_SET;
2018-08-24 20:52:34 +00:00
pr_debug("[LA Set Success] LA_State=((%d))\n", adc_smp->adc_smp_state);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
2018-08-24 20:52:34 +00:00
pr_debug("ADCSmp_work_item_index = ((%d))\n", adc_smp->la_work_item_index);
2018-06-22 16:48:32 +00:00
if (adc_smp->la_work_item_index != 0) {
2018-08-24 20:52:34 +00:00
odm_schedule_work_item(&adc_smp->adc_smp_work_item_1);
2018-06-22 16:48:32 +00:00
adc_smp->la_work_item_index = 0;
} else {
2018-08-24 20:52:34 +00:00
odm_schedule_work_item(&adc_smp->adc_smp_work_item);
2018-06-22 16:48:32 +00:00
adc_smp->la_work_item_index = 1;
}
#else
2018-08-24 20:52:34 +00:00
phydm_adc_smp_start(dm);
2018-06-22 16:48:32 +00:00
#endif
} else
2018-08-24 20:52:34 +00:00
pr_debug("[LA Set Fail] LA_State=((%d))\n", adc_smp->adc_smp_state);
2018-06-22 16:48:32 +00:00
}
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
enum rt_status
adc_smp_query(
2018-08-24 20:52:34 +00:00
void *dm_void,
2018-06-22 16:48:32 +00:00
ULONG information_buffer_length,
void *information_buffer,
PULONG bytes_written
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
enum rt_status ret_status = RT_STATUS_SUCCESS;
2018-08-24 20:52:34 +00:00
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
pr_debug("[%s] LA_State=((%d))", __func__, adc_smp->adc_smp_state);
2018-06-22 16:48:32 +00:00
if (information_buffer_length != adc_smp_buf->buffer_size) {
*bytes_written = 0;
ret_status = RT_STATUS_RESOURCE;
} else if (adc_smp_buf->length != adc_smp_buf->buffer_size) {
*bytes_written = 0;
ret_status = RT_STATUS_RESOURCE;
} else if (adc_smp->adc_smp_state != ADCSMP_STATE_QUERY) {
*bytes_written = 0;
ret_status = RT_STATUS_PENDING;
} else {
2018-08-24 20:52:34 +00:00
odm_move_memory(dm, information_buffer, adc_smp_buf->octet, adc_smp_buf->buffer_size);
2018-06-22 16:48:32 +00:00
*bytes_written = adc_smp_buf->buffer_size;
adc_smp->adc_smp_state = ADCSMP_STATE_IDLE;
}
2018-08-24 20:52:34 +00:00
pr_debug("Return status %d\n", ret_status);
2018-06-22 16:48:32 +00:00
return ret_status;
}
#elif (DM_ODM_SUPPORT_TYPE & ODM_CE)
void
adc_smp_query(
2018-08-24 20:52:34 +00:00
void *dm_void,
2018-06-22 16:48:32 +00:00
void *output,
u32 out_len,
u32 *pused
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
u32 used = *pused;
u32 i;
/* struct timespec t; */
/* rtw_get_current_timespec(&t); */
2018-08-24 20:52:34 +00:00
pr_debug("%s adc_smp_state %d", __func__, adc_smp->adc_smp_state);
2018-06-22 16:48:32 +00:00
for (i = 0; i < (adc_smp_buf->length >> 2) - 2; i += 2) {
2018-08-24 20:52:34 +00:00
PDM_SNPF(out_len, used, output + used, out_len - used,
"%08x%08x\n", adc_smp_buf->octet[i],
adc_smp_buf->octet[i + 1]);
2018-06-22 16:48:32 +00:00
}
2018-08-24 20:52:34 +00:00
PDM_SNPF(out_len, used, output + used, out_len - used, "\n");
/* PDM_SNPF((output+used, out_len-used, "\n[%lu.%06lu]\n", t.tv_sec, t.tv_nsec)); */
2018-06-22 16:48:32 +00:00
*pused = used;
}
s32
adc_smp_get_sample_counts(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
return (adc_smp_buf->length >> 2) - 2;
}
s32
adc_smp_query_single_data(
2018-08-24 20:52:34 +00:00
void *dm_void,
2018-06-22 16:48:32 +00:00
void *output,
u32 out_len,
u32 index
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
u32 used = 0;
/* dbg_print("%s adc_smp_state %d\n", __func__, adc_smp->adc_smp_state); */
if (adc_smp->adc_smp_state != ADCSMP_STATE_QUERY) {
2018-08-24 20:52:34 +00:00
PDM_SNPF(out_len, used, output + used, out_len - used,
"Error: la data is not ready yet ...\n");
2018-06-22 16:48:32 +00:00
return -1;
}
if (index < ((adc_smp_buf->length >> 2) - 2)) {
2018-08-24 20:52:34 +00:00
PDM_SNPF(out_len, used, output + used, out_len - used,
"%08x%08x\n",
adc_smp_buf->octet[index],
adc_smp_buf->octet[index + 1]);
2018-06-22 16:48:32 +00:00
}
return 0;
}
#endif
void
adc_smp_stop(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
adc_smp->adc_smp_state = ADCSMP_STATE_IDLE;
2018-08-24 20:52:34 +00:00
pr_debug("[LA_Stop] LA_state = ((%d))\n", adc_smp->adc_smp_state);
2018-06-22 16:48:32 +00:00
}
void
adc_smp_init(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
adc_smp->adc_smp_state = ADCSMP_STATE_IDLE;
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & ODM_RTL8814A) {
2018-06-22 16:48:32 +00:00
adc_smp_buf->start_pos = 0x30000;
adc_smp_buf->buffer_size = 0x10000;
2018-08-24 20:52:34 +00:00
} else if (dm->support_ic_type & ODM_RTL8822B) {
2018-06-22 16:48:32 +00:00
adc_smp_buf->start_pos = 0x20000;
adc_smp_buf->buffer_size = 0x20000;
2018-08-24 20:52:34 +00:00
} else if (dm->support_ic_type & ODM_RTL8197F) {
2018-06-22 16:48:32 +00:00
adc_smp_buf->start_pos = 0x00000;
adc_smp_buf->buffer_size = 0x10000;
2018-08-24 20:52:34 +00:00
} else if (dm->support_ic_type & ODM_RTL8821C) {
2018-06-22 16:48:32 +00:00
adc_smp_buf->start_pos = 0x8000;
adc_smp_buf->buffer_size = 0x8000;
}
}
#if (DM_ODM_SUPPORT_TYPE & (ODM_WIN | ODM_CE))
void
adc_smp_de_init(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
struct rt_adcsmp_string *adc_smp_buf = &adc_smp->adc_smp_buf;
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
adc_smp_stop(dm);
2018-06-22 16:48:32 +00:00
if (adc_smp_buf->length != 0x0) {
2018-08-24 20:52:34 +00:00
odm_free_memory(dm, adc_smp_buf->octet, adc_smp_buf->length);
2018-06-22 16:48:32 +00:00
adc_smp_buf->length = 0x0;
}
}
#endif
void
phydm_la_mode_bb_setting(
2018-08-24 20:52:34 +00:00
void *dm_void
2018-06-22 16:48:32 +00:00
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
u8 trig_mode = adc_smp->la_trig_mode;
u32 trig_sig_sel = adc_smp->la_trig_sig_sel;
u32 dbg_port = adc_smp->la_dbg_port;
u8 is_trigger_edge = adc_smp->la_trigger_edge;
u8 sampling_rate = adc_smp->la_smp_rate;
u8 la_dma_type = adc_smp->la_dma_type;
u32 dbg_port_header_sel = 0;
2018-08-24 20:52:34 +00:00
pr_debug("1. [BB Setting] trig_mode = ((%d)), dbg_port = ((0x%x)), Trig_Edge = ((%d)), smp_rate = ((%d)), Trig_Sel = ((0x%x)), Dma_type = ((%d))\n",
2018-06-22 16:48:32 +00:00
trig_mode, dbg_port, is_trigger_edge, sampling_rate, trig_sig_sel, la_dma_type);
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("1. [LA mode bb_setting]trig_mode = ((%d)), dbg_port = ((0x%x)), Trig_Edge = ((%d)), smp_rate = ((%d)), Trig_Sel = ((0x%x)), Dma_type = ((%d))\n",
trig_mode, dbg_port, is_trigger_edge, sampling_rate, trig_sig_sel, la_dma_type));
#endif
if (trig_mode == PHYDM_MAC_TRIG)
trig_sig_sel = 0; /*ignore this setting*/
/*set BB debug port*/
2018-08-24 20:52:34 +00:00
if (phydm_set_bb_dbg_port(dm, BB_DBGPORT_PRIORITY_3, dbg_port)) {
pr_debug("Set dbg_port((0x%x)) success\n", dbg_port);
2018-06-22 16:48:32 +00:00
}
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
2018-06-22 16:48:32 +00:00
if (trig_mode == PHYDM_ADC_RF0_TRIG)
dbg_port_header_sel = 9; /*DBGOUT_RFC_a[31:0]*/
else if (trig_mode == PHYDM_ADC_RF1_TRIG)
dbg_port_header_sel = 8; /*DBGOUT_RFC_b[31:0]*/
else if ((trig_mode == PHYDM_ADC_BB_TRIG) || (trig_mode == PHYDM_ADC_MAC_TRIG)) {
if (adc_smp->la_mac_mask_or_hdr_sel <= 0xf) {
dbg_port_header_sel = adc_smp->la_mac_mask_or_hdr_sel;
} else {
dbg_port_header_sel = 0;
}
}
2018-08-24 20:52:34 +00:00
phydm_bb_dbg_port_header_sel(dm, dbg_port_header_sel);
2018-06-22 16:48:32 +00:00
2018-08-24 20:52:34 +00:00
odm_set_bb_reg(dm, 0x95c, 0xf00, la_dma_type); /*0x95C[11:8]*/
odm_set_bb_reg(dm, 0x95C, 0x1f, trig_sig_sel); /*0x95C[4:0], BB debug port bit*/
odm_set_bb_reg(dm, 0x95C, BIT(31), is_trigger_edge); /*0: posedge, 1: negedge*/
odm_set_bb_reg(dm, 0x95c, 0xe0, sampling_rate);
2018-06-22 16:48:32 +00:00
/* (0:) '80MHz'
(1:) '40MHz'
(2:) '20MHz'
(3:) '10MHz'
(4:) '5MHz'
(5:) '2.5MHz'
(6:) '1.25MHz'
(7:) '160MHz (for BW160 ic)'
*/
2018-08-24 20:52:34 +00:00
if ((dm->support_ic_type & ODM_RTL8821C) && (dm->cut_version >= ODM_CUT_B)) {
odm_set_bb_reg(dm, 0x95c, BIT(23), 1);
2018-06-22 16:48:32 +00:00
}
} else {
2018-08-24 20:52:34 +00:00
odm_set_bb_reg(dm, 0x9a0, 0xf00, la_dma_type); /*0x9A0[11:8]*/
odm_set_bb_reg(dm, 0x9a0, 0x1f, trig_sig_sel); /*0x9A0[4:0], BB debug port bit*/
odm_set_bb_reg(dm, 0x9A0, BIT(31), is_trigger_edge); /*0: posedge, 1: negedge*/
odm_set_bb_reg(dm, 0x9A0, 0xe0, sampling_rate);
2018-06-22 16:48:32 +00:00
/* (0:) '80MHz'
(1:) '40MHz'
(2:) '20MHz'
(3:) '10MHz'
(4:) '5MHz'
(5:) '2.5MHz'
(6:) '1.25MHz'
(7:) '160MHz (for BW160 ic)'
*/
}
}
void
phydm_la_mode_set_trigger_time(
2018-08-24 20:52:34 +00:00
void *dm_void,
2018-06-22 16:48:32 +00:00
u32 trigger_time_mu_sec
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
2018-06-22 16:48:32 +00:00
u8 trigger_time_unit_num;
u32 time_unit = 0;
if (trigger_time_mu_sec < 128) {
time_unit = 0; /*unit: 1mu sec*/
} else if (trigger_time_mu_sec < 256) {
time_unit = 1; /*unit: 2mu sec*/
} else if (trigger_time_mu_sec < 512) {
time_unit = 2; /*unit: 4mu sec*/
} else if (trigger_time_mu_sec < 1024) {
time_unit = 3; /*unit: 8mu sec*/
} else if (trigger_time_mu_sec < 2048) {
time_unit = 4; /*unit: 16mu sec*/
} else if (trigger_time_mu_sec < 4096) {
time_unit = 5; /*unit: 32mu sec*/
} else if (trigger_time_mu_sec < 8192) {
time_unit = 6; /*unit: 64mu sec*/
}
trigger_time_unit_num = (u8)(trigger_time_mu_sec >> time_unit);
2018-08-24 20:52:34 +00:00
pr_debug("2. [Set Trigger Time] Trig_Time = ((%d)) * unit = ((2^%d us))\n", trigger_time_unit_num, time_unit);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("3. [Set Trigger Time] Trig_Time = ((%d)) * unit = ((2^%d us))\n", trigger_time_unit_num, time_unit));
#endif
2018-08-24 20:52:34 +00:00
odm_set_mac_reg(dm, 0x7cc, BIT(20) | BIT(19) | BIT(18), time_unit);
odm_set_mac_reg(dm, 0x7c0, 0x7f00, (trigger_time_unit_num & 0x7f));
2018-06-22 16:48:32 +00:00
}
void
phydm_lamode_trigger_setting(
2018-08-24 20:52:34 +00:00
void *dm_void,
2018-06-22 16:48:32 +00:00
char input[][16],
u32 *_used,
char *output,
u32 *_out_len,
u32 input_num
)
{
2018-08-24 20:52:34 +00:00
struct dm_struct *dm = (struct dm_struct *)dm_void;
struct rt_adcsmp *adc_smp = &dm->adcsmp;
2018-06-22 16:48:32 +00:00
u8 trig_mode, dma_data_sig_sel;
u32 trig_sig_sel;
boolean is_enable_la_mode;
u32 trigger_time_mu_sec;
char help[] = "-h";
u32 var1[10] = {0};
u32 used = *_used;
u32 out_len = *_out_len;
2018-08-24 20:52:34 +00:00
if (dm->support_ic_type & PHYDM_IC_SUPPORT_LA_MODE) {
2018-06-22 16:48:32 +00:00
PHYDM_SSCANF(input[1], DCMD_DECIMAL, &var1[0]);
is_enable_la_mode = (boolean)var1[0];
/*dbg_print("echo cmd input_num = %d\n", input_num);*/
if ((strcmp(input[1], help) == 0)) {
2018-08-24 20:52:34 +00:00
PDM_SNPF(out_len, used, output + used,
out_len - used,
"{En} {0:BB,1:BB_MAC,2:RF0,3:RF1,4:MAC} \n {BB:dbg_port[bit],BB_MAC:0-ok/1-fail/2-cca,MAC:ref} {DMA type} {TrigTime} \n {DbgPort_head/ref_mask} {dbg_port} {0:P_Edge, 1:N_Edge} {SpRate:0-80M,1-40M,2-20M} {Capture num}\n");
2018-06-22 16:48:32 +00:00
/**/
} else if ((is_enable_la_mode == 1)) {
PHYDM_SSCANF(input[2], DCMD_DECIMAL, &var1[1]);
trig_mode = (u8)var1[1];
if (trig_mode == PHYDM_MAC_TRIG)
PHYDM_SSCANF(input[3], DCMD_HEX, &var1[2]);
else
PHYDM_SSCANF(input[3], DCMD_DECIMAL, &var1[2]);
trig_sig_sel = var1[2];
PHYDM_SSCANF(input[4], DCMD_DECIMAL, &var1[3]);
PHYDM_SSCANF(input[5], DCMD_DECIMAL, &var1[4]);
PHYDM_SSCANF(input[6], DCMD_HEX, &var1[5]);
PHYDM_SSCANF(input[7], DCMD_HEX, &var1[6]);
PHYDM_SSCANF(input[8], DCMD_DECIMAL, &var1[7]);
PHYDM_SSCANF(input[9], DCMD_DECIMAL, &var1[8]);
PHYDM_SSCANF(input[10], DCMD_DECIMAL, &var1[9]);
dma_data_sig_sel = (u8)var1[3];
trigger_time_mu_sec = var1[4]; /*unit: us*/
adc_smp->la_mac_mask_or_hdr_sel = var1[5];
adc_smp->la_dbg_port = var1[6];
adc_smp->la_trigger_edge = (u8) var1[7];
adc_smp->la_smp_rate = (u8)(var1[8] & 0x7);
adc_smp->la_count = var1[9];
2018-08-24 20:52:34 +00:00
pr_debug("echo lamode %d %d %d %d %d %d %x %d %d %d\n", var1[0], var1[1], var1[2], var1[3], var1[4], var1[5], var1[6], var1[7], var1[8], var1[9]);
2018-06-22 16:48:32 +00:00
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
RT_TRACE_EX(COMP_LA_MODE, DBG_LOUD, ("echo lamode %d %d %d %d %d %d %x %d %d %d\n", var1[0], var1[1], var1[2], var1[3], var1[4], var1[5], var1[6], var1[7], var1[8], var1[9]));
#endif
2018-08-24 20:52:34 +00:00
PDM_SNPF(out_len, used, output + used,
out_len - used,
"a.En= ((1)), b.mode = ((%d)), c.Trig_Sel = ((0x%x)), d.Dma_type = ((%d))\n",
trig_mode, trig_sig_sel,
dma_data_sig_sel);
PDM_SNPF(out_len, used, output + used,
out_len - used,
"e.Trig_Time = ((%dus)), f.Dbg_head/mac_ref_mask = ((0x%x)), g.dbg_port = ((0x%x))\n",
trigger_time_mu_sec,
adc_smp->la_mac_mask_or_hdr_sel,
adc_smp->la_dbg_port);
PDM_SNPF(out_len, used, output + used,
out_len - used,
"h.Trig_edge = ((%d)), i.smp rate = ((%d MHz)), j.Cap_num = ((%d))\n",
adc_smp->la_trigger_edge,
(80 >> adc_smp->la_smp_rate),
adc_smp->la_count);
adc_smp_set(dm, trig_mode, trig_sig_sel, dma_data_sig_sel, trigger_time_mu_sec, 0);
2018-06-22 16:48:32 +00:00
} else {
2018-08-24 20:52:34 +00:00
adc_smp_stop(dm);
PDM_SNPF(out_len, used, output + used,
out_len - used, "Disable LA mode\n");
2018-06-22 16:48:32 +00:00
}
}
*_used = used;
*_out_len = out_len;
}
#endif /*endif PHYDM_LA_MODE_SUPPORT == 1*/