1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-22 20:06:40 +00:00

exo/mariko fatal: stop sound output on fatal error

This commit is contained in:
Michael Scire 2020-11-20 22:29:24 -08:00 committed by SciresM
parent 5382011b0d
commit 2bc6dec126
4 changed files with 102 additions and 13 deletions

View file

@ -16,6 +16,7 @@
#include <exosphere.hpp>
#include "fatal_sdmmc.hpp"
#include "fatal_save_context.hpp"
#include "fatal_sound.hpp"
#include "fatal_display.hpp"
namespace ams::secmon::fatal {
@ -60,10 +61,17 @@ namespace ams::secmon::fatal {
AMS_SECMON_LOG("Failed to save fatal error context: %08x\n", result.GetValue());
}
/* Ensure that i2c-5 is usable for communicating with the pmic. */
/* Ensure that i2c-1/i2c-5 are usable for communicating with the audio device/pmic. */
clkrst::EnableI2c1Clock();
clkrst::EnableI2c5Clock();
i2c::Initialize(i2c::Port_1);
i2c::Initialize(i2c::Port_5);
/* Shut down audio. */
{
StopSound();
}
/* Display the fatal error. */
{
AMS_SECMON_LOG("Showing Display, LCD Vendor = %04x\n", GetLcdVendor());

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <exosphere.hpp>
#include "fatal_sound.hpp"
namespace ams::secmon::fatal {
namespace {
constexpr inline int I2cAddressMaxAlc5639 = 0x1C;
constexpr inline uintptr_t GPIO = secmon::MemoryRegionVirtualDeviceGpio.GetAddress();
constexpr size_t GPIO_PORT7_CNF_1 = 0x604;
constexpr size_t GPIO_PORT7_OE_1 = 0x614;
constexpr size_t GPIO_PORT7_OUT_1 = 0x624;
void WriteAlc5639Register(int r, u16 val) {
i2c::Send(i2c::Port_1, I2cAddressMaxAlc5639, r, std::addressof(val), sizeof(val));
}
}
void StopSound() {
/* Mute output to the speaker, setting left/right volume to 0 DB. */
WriteAlc5639Register(0x01, 0xC8C8);
/* Mute output to headphones, setting left/right volume to 0 DB. */
WriteAlc5639Register(0x02, 0xC8C8);
/* Clear all Power Management Control registers by writing 0x0000 to them. */
for (int r = 0x61; r <= 0x66; ++r) {
WriteAlc5639Register(r, 0x0000);
}
/* Configure CodecLdoEn as GPIO. */
reg::SetBits(GPIO + GPIO_PORT7_CNF_1, (1u << 4));
/* Configure CodecLdoEn as Output. */
reg::SetBits(GPIO + GPIO_PORT7_OE_1, (1u << 4));
/* Wait 200 milliseconds for config to take effect. */
util::WaitMicroSeconds(200'000ul);
/* Pull CodecLdoEn low. */
reg::ClearBits(GPIO + GPIO_PORT7_OUT_1, (1u << 4));
}
}

View file

@ -0,0 +1,23 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <exosphere.hpp>
namespace ams::secmon::fatal {
void StopSound();
}

View file

@ -43,25 +43,21 @@ namespace ams::fatal::srv {
ON_SCOPE_EXIT { i2csessionClose(&audio); };
struct {
u16 dev;
u8 val;
u8 reg;
u16 val;
} __attribute__((packed)) cmd;
static_assert(sizeof(cmd) == 3, "I2C command definition!");
cmd.dev = 0xC801;
cmd.val = 200;
cmd.reg = 0x01;
cmd.val = 0xC8C8;
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
cmd.dev = 0xC802;
cmd.val = 200;
cmd.reg = 0x02;
cmd.val = 0xC8C8;
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
cmd.dev = 0xC802;
cmd.val = 200;
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
for (u16 dev = 97; dev <= 102; dev++) {
cmd.dev = dev;
for (u8 reg = 97; reg <= 102; reg++) {
cmd.reg = reg;
cmd.val = 0;
i2csessionSendAuto(&audio, &cmd, sizeof(cmd), I2cTransactionOption_All);
}