mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-22 10:55:14 -04:00
exo2: implement SmcIramCopy/reboot to payload/rcm
This commit is contained in:
parent
bb6671a94a
commit
6c145d76c7
31 changed files with 868 additions and 47 deletions
|
@ -145,12 +145,17 @@ namespace ams::pmic {
|
|||
u8 cnfg = i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffCnfg1);
|
||||
|
||||
/* Set SlpEn. */
|
||||
cnfg |= (1 << 2);
|
||||
cnfg |= MAX77620_ONOFFCNFG1_SLPEN;
|
||||
|
||||
/* Write the new cfg. */
|
||||
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffCnfg1, cnfg);
|
||||
}
|
||||
|
||||
void PowerOff() {
|
||||
/* Write power-off to onoff cfg. */
|
||||
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Pmic, Max77620RegisterOnOffCnfg1, MAX77620_ONOFFCNFG1_PWR_OFF);
|
||||
}
|
||||
|
||||
bool IsAcOk() {
|
||||
return (GetPmicOnOffStat() & (1 << 1)) != 0;
|
||||
}
|
||||
|
|
60
libraries/libexosphere/source/rtc/max77620-rtc.h
Normal file
60
libraries/libexosphere/source/rtc/max77620-rtc.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* PMIC Real Time Clock driver for Nintendo Switch's MAX77620-RTC
|
||||
*
|
||||
* Copyright (c) 2018 CTCaer
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _MFD_MAX77620_RTC_H_
|
||||
#define _MFD_MAX77620_RTC_H_
|
||||
|
||||
#define MAX77620_RTC_I2C_ADDR 0x68
|
||||
|
||||
#define MAX77620_RTC_NR_TIME_REGS 7
|
||||
|
||||
#define MAX77620_RTC_CONTROLM_REG 0x02
|
||||
#define MAX77620_RTC_CONTROL_REG 0x03
|
||||
#define MAX77620_RTC_BIN_FORMAT (1 << 0)
|
||||
#define MAX77620_RTC_24H (1 << 1)
|
||||
|
||||
#define MAX77620_RTC_UPDATE0_REG 0x04
|
||||
#define MAX77620_RTC_WRITE_UPDATE (1 << 0)
|
||||
#define MAX77620_RTC_READ_UPDATE (1 << 4)
|
||||
|
||||
#define MAX77620_RTC_SEC_REG 0x07
|
||||
#define MAX77620_RTC_MIN_REG 0x08
|
||||
#define MAX77620_RTC_HOUR_REG 0x09
|
||||
#define MAX77620_RTC_HOUR_PM_MASK (1 << 6)
|
||||
#define MAX77620_RTC_WEEKDAY_REG 0x0A
|
||||
#define MAX77620_RTC_MONTH_REG 0x0B
|
||||
#define MAX77620_RTC_YEAR_REG 0x0C
|
||||
#define MAX77620_RTC_DATE_REG 0x0D
|
||||
|
||||
#define MAX77620_ALARM1_SEC_REG 0x0E
|
||||
#define MAX77620_ALARM1_MIN_REG 0x0F
|
||||
#define MAX77620_ALARM1_HOUR_REG 0x10
|
||||
#define MAX77620_ALARM1_WEEKDAY_REG 0x11
|
||||
#define MAX77620_ALARM1_MONTH_REG 0x12
|
||||
#define MAX77620_ALARM1_YEAR_REG 0x13
|
||||
#define MAX77620_ALARM1_DATE_REG 0x14
|
||||
#define MAX77620_ALARM2_SEC_REG 0x15
|
||||
#define MAX77620_ALARM2_MIN_REG 0x16
|
||||
#define MAX77620_ALARM2_HOUR_REG 0x17
|
||||
#define MAX77620_ALARM2_WEEKDAY_REG 0x18
|
||||
#define MAX77620_ALARM2_MONTH_REG 0x19
|
||||
#define MAX77620_ALARM2_YEAR_REG 0x1A
|
||||
#define MAX77620_ALARM2_DATE_REG 0x1B
|
||||
#define MAX77620_RTC_ALARM_EN_MASK (1 << 7)
|
||||
|
||||
#endif /* _MFD_MAX77620_RTC_H_ */
|
65
libraries/libexosphere/source/rtc/rtc_api.cpp
Normal file
65
libraries/libexosphere/source/rtc/rtc_api.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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 "max77620-rtc.h"
|
||||
|
||||
namespace ams::rtc {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr inline int I2cAddressMax77620Rtc = 0x68;
|
||||
|
||||
/* TODO: Find datasheet, link to it instead. */
|
||||
/* NOTE: Tentatively, Max77620 "mostly" matches https://datasheets.maximintegrated.com/en/ds/MAX77863.pdf. */
|
||||
constexpr inline int Max77620RtcRegisterUpdate0 = 0x04;
|
||||
|
||||
constexpr inline int Max77620RtcRegisterAlarmStart = 0x0E;
|
||||
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Sec = 0x0E;
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Min = 0x0F;
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Hour = 0x10;
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Weekday = 0x11;
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Month = 0x12;
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Year = 0x13;
|
||||
constexpr inline int Max77620RtcRegisterAlarm1Date = 0x14;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Sec = 0x15;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Min = 0x16;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Hour = 0x17;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Weekday = 0x18;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Month = 0x19;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Year = 0x1A;
|
||||
constexpr inline int Max77620RtcRegisterAlarm2Date = 0x1B;
|
||||
|
||||
constexpr inline int Max77620RtcRegisterAlarmLast = 0x1B;
|
||||
|
||||
}
|
||||
|
||||
void StopAlarm() {
|
||||
/* Begin update. */
|
||||
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Rtc, Max77620RtcRegisterUpdate0, MAX77620_RTC_READ_UPDATE);
|
||||
|
||||
/* Clear ALARM_EN for all alarm registers. */
|
||||
for (auto reg = Max77620RtcRegisterAlarmStart; reg <= Max77620RtcRegisterAlarmLast; ++reg) {
|
||||
u8 val = i2c::QueryByte(i2c::Port_5, I2cAddressMax77620Rtc, reg);
|
||||
val &= ~MAX77620_RTC_ALARM_EN_MASK;
|
||||
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Rtc, reg, val);
|
||||
}
|
||||
|
||||
/* End update. */
|
||||
i2c::SendByte(i2c::Port_5, I2cAddressMax77620Rtc, Max77620RtcRegisterUpdate0, MAX77620_RTC_WRITE_UPDATE);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue