/*
* 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 .
*/
#include
#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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().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();
/* Call into the driver. */
return device.GetDriver().SafeCastTo().SetChargerVoltageClamp(std::addressof(device), mv);
}
}