mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-29 22:15:17 -04:00
powctl: implement client api (needs board-specific impl)
This commit is contained in:
parent
3d31837ca1
commit
485304bd17
37 changed files with 1984 additions and 11 deletions
329
libraries/libstratosphere/source/powctl/powctl_charger_api.cpp
Normal file
329
libraries/libstratosphere/source/powctl/powctl_charger_api.cpp
Normal file
|
@ -0,0 +1,329 @@
|
|||
/*
|
||||
* 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 <stratosphere.hpp>
|
||||
#include "impl/powctl_i_power_control_driver.hpp"
|
||||
#include "impl/powctl_device_management.hpp"
|
||||
|
||||
namespace ams::powctl {
|
||||
|
||||
namespace {
|
||||
|
||||
impl::SessionImpl &GetOpenSessionImpl(Session &session) {
|
||||
AMS_ASSERT(session.has_session);
|
||||
auto &impl = GetReference(session.impl_storage);
|
||||
AMS_ASSERT(impl.IsOpen());
|
||||
return impl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result GetChargerChargeCurrentState(ChargeCurrentState *out, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerChargeCurrentState(out, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerChargeCurrentState(Session &session, ChargeCurrentState state) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerChargeCurrentState(std::addressof(device), state);
|
||||
}
|
||||
|
||||
Result GetChargerFastChargeCurrentLimit(u32 *out_ma, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerFastChargeCurrentLimit(out_ma, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerFastChargeCurrentLimit(Session &session, u32 ma) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerFastChargeCurrentLimit(std::addressof(device), ma);
|
||||
}
|
||||
|
||||
Result GetChargerChargeVoltageLimit(u32 *out_mv, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerChargeVoltageLimit(out_mv, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerChargeVoltageLimit(Session &session, u32 mv) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerChargeVoltageLimit(std::addressof(device), mv);
|
||||
}
|
||||
|
||||
Result SetChargerChargerConfiguration(Session &session, ChargerConfiguration cfg) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerChargerConfiguration(std::addressof(device), cfg);
|
||||
}
|
||||
|
||||
Result IsChargerHiZEnabled(bool *out, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().IsChargerHiZEnabled(out, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerHiZEnabled(Session &session, bool en) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerHiZEnabled(std::addressof(device), en);
|
||||
}
|
||||
|
||||
Result GetChargerInputCurrentLimit(u32 *out_ma, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerInputCurrentLimit(out_ma, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerInputCurrentLimit(Session &session, u32 ma) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerInputCurrentLimit(std::addressof(device), ma);
|
||||
}
|
||||
|
||||
Result GetChargerInputVoltageLimit(u32 *out_mv, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerInputVoltageLimit(out_mv, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerInputVoltageLimit(Session &session, u32 mv) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerInputVoltageLimit(std::addressof(device), mv);
|
||||
}
|
||||
|
||||
Result GetChargerChargerStatus(ChargerStatus *out, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerChargerStatus(out, std::addressof(device));
|
||||
}
|
||||
|
||||
Result IsChargerWatchdogTimerEnabled(bool *out, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().IsChargerWatchdogTimerEnabled(out, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerWatchdogTimerEnabled(Session &session, bool en) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerWatchdogTimerEnabled(std::addressof(device), en);
|
||||
}
|
||||
|
||||
Result SetChargerWatchdogTimerTimeout(Session &session, TimeSpan timeout) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerWatchdogTimerTimeout(std::addressof(device), timeout);
|
||||
}
|
||||
|
||||
Result ResetChargerWatchdogTimer(Session &session);
|
||||
|
||||
Result GetChargerBatteryCompensation(u32 *out_mo, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerBatteryCompensation(out_mo, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerBatteryCompensation(Session &session, u32 mo) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerBatteryCompensation(std::addressof(device), mo);
|
||||
}
|
||||
|
||||
Result GetChargerVoltageClamp(u32 *out_mv, Session &session) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Read));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().GetChargerVoltageClamp(out_mv, std::addressof(device));
|
||||
}
|
||||
|
||||
Result SetChargerVoltageClamp(Session &session, u32 mv) {
|
||||
/* Get the session impl. */
|
||||
auto &impl = GetOpenSessionImpl(session);
|
||||
|
||||
/* Check the access mode. */
|
||||
R_TRY(impl.CheckAccess(ddsf::AccessMode_Write));
|
||||
|
||||
/* Get the device. */
|
||||
auto &device = impl.GetDevice().SafeCastTo<impl::IDevice>();
|
||||
|
||||
/* Call into the driver. */
|
||||
return device.GetDriver().SafeCastTo<impl::IPowerControlDriver>().SetChargerVoltageClamp(std::addressof(device), mv);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue