AWAC-PDM control and status registers.

This commit is contained in:
Maxim Poliakovski 2021-10-01 01:02:43 +02:00
parent 0f55877137
commit 3ca7a78a37
4 changed files with 78 additions and 7 deletions

View File

@ -44,6 +44,7 @@ AMIC::AMIC()
}
this->viacuda = std::unique_ptr<ViaCuda> (new ViaCuda());
this->awacs = std::unique_ptr<AwacDevicePdm> (new AwacDevicePdm());
}
bool AMIC::supports_type(HWCompType type) {
@ -60,7 +61,12 @@ uint32_t AMIC::read(uint32_t reg_start, uint32_t offset, int size)
return this->viacuda->read(offset >> 9);
}
LOG_F(INFO, "AMIC read!");
switch(offset) {
case AMICReg::Snd_Stat_0:
case AMICReg::Snd_Stat_1:
case AMICReg::Snd_Stat_2:
return (this->awacs->read_stat() >> (offset & 3 * 8)) & 0xFF;
}
return 0;
}
@ -72,6 +78,19 @@ void AMIC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size)
}
switch(offset) {
case AMICReg::Snd_Cntl_0:
case AMICReg::Snd_Cntl_1:
case AMICReg::Snd_Cntl_2:
// remember values of sound control registers
this->imm_snd_regs[offset & 3] = value;
// transfer control information to the sound codec when ready
if ((this->imm_snd_regs[0] & 0xC0) == PDM_SND_CNTL_VALID) {
this->awacs->write_ctrl(
(this->imm_snd_regs[1] >> 4) | (this->imm_snd_regs[0] & 0x3F),
((this->imm_snd_regs[1] & 0xF) << 8) | this->imm_snd_regs[2]
);
}
break;
case AMICReg::Snd_Out_Cntl:
LOG_F(INFO, "AMIC Sound Out Ctrl updated, val=%x", value);
break;

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef AMIC_H
#define AMIC_H
#include "awacs.h"
#include "mmiodevice.h"
#include "viacuda.h"
#include <cinttypes>
@ -31,9 +32,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
/* AMIC DMA registers offsets from AMIC base (0x50F00000). */
enum AMICReg : uint32_t {
// Sound control registers
Snd_Out_Cntl = 0x14010,
Snd_In_Cntl = 0x14011,
// Audio codec control registers
Snd_Cntl_0 = 0x14000, // audio codec control register 0
Snd_Cntl_1 = 0x14001, // audio codec control register 1
Snd_Cntl_2 = 0x14002, // audio codec control register 2
Snd_Stat_0 = 0x14004, // audio codec status register 0
Snd_Stat_1 = 0x14005, // audio codec status register 1
Snd_Stat_2 = 0x14006, // audio codec status register 2
Snd_Out_Cntl = 0x14010, // audio codec output DMA control register
Snd_In_Cntl = 0x14011, // audio codec input DMA control register
// VIA2 registers
VIA2_Slot_IER = 0x26012,
@ -70,7 +77,10 @@ protected:
void dma_reg_write(uint32_t offset, uint32_t value, int size);
private:
std::unique_ptr<ViaCuda> viacuda;
uint8_t imm_snd_regs[4]; // temporary storage for sound control registers
std::unique_ptr<ViaCuda> viacuda;
std::unique_ptr<AwacDevicePdm> awacs;
};
#endif // AMIC_H

View File

@ -287,3 +287,25 @@ void AWACDevice::dma_start()
void AWACDevice::dma_end()
{
}
//=========================== PDM-style AWAC =================================
AwacDevicePdm::AwacDevicePdm()
{
}
uint32_t AwacDevicePdm::read_stat()
{
LOG_F(INFO, "AWAC-PDM status requested!");
return 0;
}
void AwacDevicePdm::write_ctrl(uint32_t addr, uint16_t value)
{
LOG_F(INFO, "AWAC-PDM control updated, address=0x%X, val=0x%X", addr, value);
if (addr <= 4) {
this->ctrl_regs[addr] = value;
} else {
LOG_F(ERROR, "AWAC-PDM: invalid control register address %d!", addr);
}
}

View File

@ -41,8 +41,8 @@ enum {
};
/** AWAC manufacturer and revision. */
#define AWAC_MAKER_CRYSTAL 1
#define AWAC_REV_SCREAMER 3
#define AWAC_MAKER_CRYSTAL 1
#define AWAC_REV_SCREAMER 3
/** Apple source calls this kValidData but doesn't explain
what it actually means. It seems like it's used to check
@ -136,5 +136,25 @@ private:
DMAChannel *dma_out_ch;
};
/** AWAC PDM-style definitions. */
// PDM HWInit source defines two constants: kExpBit = 0x80 and kCmdBit = 0x40
// I don't know what they means but it seems that their combination will
// cause sound control parameters to be transferred to the sound chip.
#define PDM_SND_CNTL_VALID 0xC0
/** AWAC PDM-style sound codec. */
class AwacDevicePdm {
public:
AwacDevicePdm();
~AwacDevicePdm() = default;
uint32_t read_stat(void);
void write_ctrl(uint32_t addr, uint16_t value);
private:
uint16_t ctrl_regs[5]; // 12-bit wide control registers
};
#endif /* AWAC_H */