pwm: implement driver for boot sysmodule

This commit is contained in:
Michael Scire 2020-11-01 23:04:19 -08:00 committed by SciresM
parent 35552bac2c
commit 3d31837ca1
41 changed files with 2107 additions and 59 deletions

View file

@ -61,6 +61,7 @@
#include <stratosphere/nim.hpp>
#include <stratosphere/ns.hpp>
#include <stratosphere/patcher.hpp>
#include <stratosphere/pcv.hpp>
#include <stratosphere/pgl.hpp>
#include <stratosphere/psc.hpp>
#include <stratosphere/pm.hpp>

View file

@ -0,0 +1,20 @@
/*
* 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 <stratosphere/pcv/pcv_types.hpp>
#include <stratosphere/pcv/pcv_api.hpp>

View file

@ -0,0 +1,30 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pcv/pcv_types.hpp>
namespace ams::pcv {
void Initialize();
void Finalize();
Result SetClockEnabled(Module module, bool en);
Result SetClockRate(Module module, ClockHz hz);
Result SetReset(Module module, bool en);
}

View file

@ -0,0 +1,116 @@
/*
* 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 <vapours.hpp>
namespace ams::pcv {
using ClockHz = u32;
using MicroVolt = s32;
using MilliC = s32;
/* TODO: Device codes? */
enum Module {
Module_Cpu = 0,
Module_Gpu = 1,
Module_I2s1 = 2,
Module_I2s2 = 3,
Module_I2s3 = 4,
Module_Pwm = 5,
Module_I2c1 = 6,
Module_I2c2 = 7,
Module_I2c3 = 8,
Module_I2c4 = 9,
Module_I2c5 = 10,
Module_I2c6 = 11,
Module_Spi1 = 12,
Module_Spi2 = 13,
Module_Spi3 = 14,
Module_Spi4 = 15,
Module_Disp1 = 16,
Module_Disp2 = 17,
Module_Isp = 18,
Module_Vi = 19,
Module_Sdmmc1 = 20,
Module_Sdmmc2 = 21,
Module_Sdmmc3 = 22,
Module_Sdmmc4 = 23,
Module_Owr = 24,
Module_Csite = 25,
Module_Tsec = 26,
Module_Mselect = 27,
Module_Hda2codec2x = 28,
Module_Actmon = 29,
Module_I2cSlow = 30,
Module_Sor1 = 31,
Module_Sata = 32,
Module_Hda = 33,
Module_XusbCoreHostSrc = 34,
Module_XusbFalconSrc = 35,
Module_XusbFsSrc = 36,
Module_XusbCoreDevSrc = 37,
Module_XusbSsSrc = 38,
Module_UartA = 39,
Module_UartB = 40,
Module_UartC = 41,
Module_UartD = 42,
Module_Host1x = 43,
Module_Entropy = 44,
Module_SocTherm = 45,
Module_Vic = 46,
Module_Nvenc = 47,
Module_Nvjpg = 48,
Module_Nvdec = 49,
Module_Qspi = 50,
Module_ViI2c = 51,
Module_Tsecb = 52,
Module_Ape = 53,
Module_AudioDsp = 54,
Module_AudioUart = 55,
Module_Emc = 56,
Module_Plle = 57,
Module_PlleHwSeq = 58,
Module_Dsi = 59,
Module_Maud = 60,
Module_Dpaux1 = 61,
Module_MipiCal = 62,
Module_UartFstMipiCal = 63,
Module_Osc = 64,
Module_SysBus = 65,
Module_SorSafe = 66,
Module_XusbSs = 67,
Module_XusbHost = 68,
Module_XusbDevice = 69,
Module_Extperiph1 = 70,
Module_Ahub = 71,
Module_Hda2hdmicodec = 72,
Module_Gpuaux = 73,
Module_UsbD = 74,
Module_Usb2 = 75,
Module_Pcie = 76,
Module_Afi = 77,
Module_PciExClk = 78,
Module_PExUsbPhy = 79,
Module_XUsbPadCtl = 80,
Module_Apbdma = 81,
Module_Usb2TrkClk = 82,
Module_XUsbIoPll = 83,
Module_XUsbIoPllHwSeq = 84,
Module_Cec = 85,
Module_Extperiph2 = 86,
};
}

View file

@ -15,6 +15,14 @@
*/
#pragma once
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/pwm/pwm_select_channel_name.hpp>
#include <stratosphere/pwm/sf/pwm_sf_i_channel_session.hpp>
#include <stratosphere/pwm/sf/pwm_sf_i_manager.hpp>
#include <stratosphere/pwm/server/pwm_server_api.hpp>
#include <stratosphere/pwm/driver/pwm_select_driver_api.hpp>
#include <stratosphere/pwm/driver/pwm_driver_service_api.hpp>
#include <stratosphere/pwm/driver/pwm_driver_client_api.hpp>
#include <stratosphere/pwm/driver/pwm_channel_api.hpp>
#include <stratosphere/pwm/pwm_api.hpp>
#include <stratosphere/pwm/pwm_channel_api.hpp>

View file

@ -0,0 +1,24 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
namespace ams::pwm::driver::board::nintendo_nx {
void Initialize();
}

View file

@ -0,0 +1,50 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
namespace ams::pwm::driver {
namespace impl {
constexpr inline size_t ChannelSessionSize = 0x60;
constexpr inline size_t ChannelSessionAlign = 8;
struct alignas(ChannelSessionAlign) ChannelSessionImplPadded;
}
struct ChannelSession {
util::TypedStorage<impl::ChannelSessionImplPadded, impl::ChannelSessionSize, impl::ChannelSessionAlign> _impl;
};
Result OpenSession(ChannelSession *out, DeviceCode device_code);
void CloseSession(ChannelSession &session);
void SetPeriod(ChannelSession &session, TimeSpan period);
TimeSpan GetPeriod(ChannelSession &session);
void SetDuty(ChannelSession &session, int duty);
int GetDuty(ChannelSession &session);
void SetEnabled(ChannelSession &session, bool en);
bool GetEnabled(ChannelSession &session);
void SetScale(ChannelSession &session, double scale);
double GetScale(ChannelSession &session);
}

View file

@ -0,0 +1,25 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
namespace ams::pwm::driver {
void Initialize();
void Finalize();
}

View file

@ -0,0 +1,30 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/pwm/driver/pwm_i_pwm_device.hpp>
#include <stratosphere/pwm/driver/pwm_i_pwm_driver.hpp>
namespace ams::pwm::driver {
void RegisterDriver(IPwmDriver *driver);
void UnregisterDriver(IPwmDriver *driver);
Result RegisterDeviceCode(DeviceCode device_code, IPwmDevice *device);
bool UnregisterDeviceCode(DeviceCode device_code);
}

View file

@ -0,0 +1,36 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/ddsf.hpp>
namespace ams::pwm::driver {
class IPwmDevice : public ::ams::ddsf::IDevice {
NON_COPYABLE(IPwmDevice);
NON_MOVEABLE(IPwmDevice);
AMS_DDSF_CASTABLE_TRAITS(ams::pwm::IPwmDevice, ::ams::ddsf::IDriver);
private:
int channel_index;
public:
IPwmDevice(int id) : IDevice(false), channel_index(id) { /* ... */ }
virtual ~IPwmDevice() { /* ... */ }
constexpr int GetChannelIndex() const { return this->channel_index; }
};
}

View file

@ -0,0 +1,54 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/pwm/driver/pwm_i_pwm_device.hpp>
#include <stratosphere/ddsf.hpp>
namespace ams::pwm::driver {
class IPwmDriver : public ::ams::ddsf::IDriver {
NON_COPYABLE(IPwmDriver);
NON_MOVEABLE(IPwmDriver);
AMS_DDSF_CASTABLE_TRAITS(ams::pwm::IPwmDriver, ::ams::ddsf::IDriver);
public:
IPwmDriver() : IDriver() { /* ... */ }
virtual ~IPwmDriver() { /* ... */ }
virtual void InitializeDriver() = 0;
virtual void FinalizeDriver() = 0;
virtual Result InitializeDevice(IPwmDevice *device) = 0;
virtual void FinalizeDevice(IPwmDevice *device) = 0;
virtual Result SetPeriod(IPwmDevice *device, TimeSpan period) = 0;
virtual Result GetPeriod(TimeSpan *out, IPwmDevice *device) = 0;
virtual Result SetDuty(IPwmDevice *device, int duty) = 0;
virtual Result GetDuty(int *out, IPwmDevice *device) = 0;
virtual Result SetScale(IPwmDevice *device, double scale) = 0;
virtual Result GetScale(double *out, IPwmDevice *device) = 0;
virtual Result SetEnabled(IPwmDevice *device, bool en) = 0;
virtual Result GetEnabled(bool *out, IPwmDevice *device) = 0;
virtual Result Suspend() = 0;
virtual void Resume() = 0;
};
}

View file

@ -0,0 +1,36 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/pwm/driver/pwm_i_pwm_driver.hpp>
#if defined(ATMOSPHERE_BOARD_NINTENDO_NX)
#include <stratosphere/pwm/driver/board/nintendo_nx/pwm_driver_api.hpp>
namespace ams::pwm::driver::board {
using namespace ams::pwm::driver::board::nintendo_nx;
}
#else
#error "Unknown board for ams::pwm::driver::"
#endif

View file

@ -0,0 +1,26 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/pwm/sf/pwm_sf_i_manager.hpp>
namespace ams::pwm {
void InitializeWith(std::shared_ptr<pwm::sf::IManager> &&sp);
void Finalize();
}

View file

@ -0,0 +1,41 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
namespace ams::pwm {
struct ChannelSession {
void *_session;
};
Result OpenSession(ChannelSession *out, DeviceCode device_code);
void CloseSession(ChannelSession &session);
void SetPeriod(ChannelSession &session, TimeSpan period);
TimeSpan GetPeriod(ChannelSession &session);
void SetDuty(ChannelSession &session, int duty);
int GetDuty(ChannelSession &session);
void SetEnabled(ChannelSession &session, bool en);
bool GetEnabled(ChannelSession &session);
void SetScale(ChannelSession &session, double scale);
double GetScale(ChannelSession &session);
}

View file

@ -0,0 +1,25 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
#include <stratosphere/pwm/sf/pwm_sf_i_manager.hpp>
namespace ams::pwm::server {
std::shared_ptr<pwm::sf::IManager> GetServiceObject();
}

View file

@ -0,0 +1,35 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/pwm/pwm_types.hpp>
namespace ams::pwm::sf {
#define AMS_PWM_I_CHANNEL_SESSION_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, SetPeriod, (TimeSpanType period) ) \
AMS_SF_METHOD_INFO(C, H, 1, Result, GetPeriod, (ams::sf::Out<TimeSpanType> out) ) \
AMS_SF_METHOD_INFO(C, H, 2, Result, SetDuty, (int duty) ) \
AMS_SF_METHOD_INFO(C, H, 3, Result, GetDuty, (ams::sf::Out<int> out) ) \
AMS_SF_METHOD_INFO(C, H, 4, Result, SetEnabled, (bool enabled) ) \
AMS_SF_METHOD_INFO(C, H, 5, Result, GetEnabled, (ams::sf::Out<bool> out) ) \
AMS_SF_METHOD_INFO(C, H, 6, Result, SetScale, (double scale), hos::Version_6_0_0) \
AMS_SF_METHOD_INFO(C, H, 7, Result, GetScale, (ams::sf::Out<double> out), hos::Version_6_0_0)
AMS_SF_DEFINE_INTERFACE(IChannelSession, AMS_PWM_I_CHANNEL_SESSION_INTERFACE_INFO)
}

View file

@ -0,0 +1,32 @@
/*
* 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 <vapours.hpp>
#include <stratosphere/ddsf/ddsf_types.hpp>
#include <stratosphere/pwm/pwm_select_channel_name.hpp>
#include <stratosphere/pwm/sf/pwm_sf_i_channel_session.hpp>
namespace ams::pwm::sf {
#define AMS_PWM_I_MANAGER_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 0, Result, OpenSessionForDev, (ams::sf::Out<std::shared_ptr<pwm::sf::IChannelSession>> out, int channel) ) \
AMS_SF_METHOD_INFO(C, H, 1, Result, OpenSession, (ams::sf::Out<std::shared_ptr<pwm::sf::IChannelSession>> out, pwm::ChannelName channel_name) ) \
AMS_SF_METHOD_INFO(C, H, 2, Result, OpenSession2, (ams::sf::Out<std::shared_ptr<pwm::sf::IChannelSession>> out, DeviceCode device_code), hos::Version_6_0_0)
AMS_SF_DEFINE_INTERFACE(IManager, AMS_PWM_I_MANAGER_INTERFACE_INFO)
}