- sys-clk-OC: Charging current limit
This commit is contained in:
@@ -19,6 +19,7 @@ extern "C" {
|
||||
#include "sysclk/apm.h"
|
||||
#include "sysclk/config.h"
|
||||
#include "sysclk/errors.h"
|
||||
#include "sysclk/i2c.h"
|
||||
#include "sysclk/psm_ext.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef enum {
|
||||
SysClkConfigValue_AutoCPUBoost,
|
||||
SysClkConfigValue_SyncReverseNXMode,
|
||||
SysClkConfigValue_AllowUnsafeFrequencies,
|
||||
SysClkConfigValue_DisableFastCharging,
|
||||
SysClkConfigValue_ChargingCurrentLimit,
|
||||
SysClkConfigValue_ChargingLimitPercentage,
|
||||
SysClkConfigValue_GovernorExperimental,
|
||||
SysClkConfigValue_EnumMax,
|
||||
@@ -46,8 +46,8 @@ static inline const char* sysclkFormatConfigValue(SysClkConfigValue val, bool pr
|
||||
return pretty ? "Sync ReverseNX Mode Sync" : "sync_reversenx_mode";
|
||||
case SysClkConfigValue_AllowUnsafeFrequencies:
|
||||
return pretty ? "Allow Unsafe Frequencies" : "allow_unsafe_freq";
|
||||
case SysClkConfigValue_DisableFastCharging:
|
||||
return pretty ? "Disable Fast Charging" : "disable_fast_charging";
|
||||
case SysClkConfigValue_ChargingCurrentLimit:
|
||||
return pretty ? "Charging Current Limit (mA)" : "charging_current";
|
||||
case SysClkConfigValue_ChargingLimitPercentage:
|
||||
return pretty ? "Charging Limit (%%)" : "charging_limit_perc";
|
||||
case SysClkConfigValue_GovernorExperimental:
|
||||
@@ -66,12 +66,13 @@ static inline uint64_t sysclkDefaultConfigValue(SysClkConfigValue val)
|
||||
case SysClkConfigValue_TempLogIntervalMs:
|
||||
case SysClkConfigValue_CsvWriteIntervalMs:
|
||||
case SysClkConfigValue_AllowUnsafeFrequencies:
|
||||
case SysClkConfigValue_DisableFastCharging:
|
||||
case SysClkConfigValue_GovernorExperimental:
|
||||
return 0ULL;
|
||||
case SysClkConfigValue_AutoCPUBoost:
|
||||
case SysClkConfigValue_SyncReverseNXMode:
|
||||
return 1ULL;
|
||||
case SysClkConfigValue_ChargingCurrentLimit:
|
||||
return 2000ULL;
|
||||
case SysClkConfigValue_ChargingLimitPercentage:
|
||||
return 100ULL;
|
||||
default:
|
||||
@@ -91,9 +92,10 @@ static inline uint64_t sysclkValidConfigValue(SysClkConfigValue val, uint64_t in
|
||||
case SysClkConfigValue_AutoCPUBoost:
|
||||
case SysClkConfigValue_SyncReverseNXMode:
|
||||
case SysClkConfigValue_AllowUnsafeFrequencies:
|
||||
case SysClkConfigValue_DisableFastCharging:
|
||||
case SysClkConfigValue_GovernorExperimental:
|
||||
return (input & 0x1) == input;
|
||||
case SysClkConfigValue_ChargingCurrentLimit:
|
||||
return (input >= 100 && input <= 2000 && input % 100 == 0);
|
||||
case SysClkConfigValue_ChargingLimitPercentage:
|
||||
return (input <= 100 && input >= 20);
|
||||
default:
|
||||
|
||||
36
Source/sys-clk-OC/common/include/sysclk/i2c.h
Normal file
36
Source/sys-clk-OC/common/include/sysclk/i2c.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
// To use i2c service, sm and i2c should be intialized via smInitialize() and i2cInitialize().
|
||||
|
||||
Result I2cSet_U8(I2cDevice dev, u8 reg, u8 val);
|
||||
|
||||
Result I2cRead_OutU8(I2cDevice dev, u8 reg, u8 *out);
|
||||
Result I2cRead_OutU16(I2cDevice dev, u8 reg, u16 *out);
|
||||
|
||||
// Max17050 fuel gauge
|
||||
float I2c_Max17050_GetBatteryCurrent();
|
||||
|
||||
const u8 MAX17050_CURRENT_REG = 0x0A;
|
||||
|
||||
// Max77812 Mariko-specific buck converter
|
||||
typedef enum I2c_Max77812_Volt_Type {
|
||||
I2c_Max77812_CPUVOLT_REG = 0x26,
|
||||
I2c_Max77812_GPUVOLT_REG = 0x23,
|
||||
I2c_Max77812_MEMVOLT_REG = 0x25,
|
||||
} I2c_Max77812_Volt_Type;
|
||||
|
||||
u32 I2c_Max77812_GetMVOUT(I2c_Max77812_Volt_Type type);
|
||||
|
||||
// Bq24193 Battery management
|
||||
u32 I2c_Bq24193_Convert_Raw_mA(u8 raw);
|
||||
u8 I2c_Bq24193_Convert_mA_Raw(u32 ma);
|
||||
|
||||
Result I2c_Bq24193_GetFastChargeCurrentLimit(u32 *ma);
|
||||
Result I2c_Bq24193_SetFastChargeCurrentLimit(u32 ma);
|
||||
|
||||
const u32 MA_RANGE_MIN = 512;
|
||||
const u32 MA_RANGE_MAX = 4544;
|
||||
|
||||
const u8 BQ24193_CHARGE_CURRENT_CONTROL_REG = 0x2;
|
||||
@@ -66,12 +66,10 @@ typedef enum {
|
||||
|
||||
bool PsmIsChargerConnected(const PsmChargeInfo* info);
|
||||
bool PsmIsCharging(const PsmChargeInfo* info);
|
||||
bool PsmIsFastChargingEnabled(const PsmChargeInfo* info);
|
||||
|
||||
typedef enum {
|
||||
PsmBatteryState_Discharging,
|
||||
PsmBatteryState_ChargingPaused,
|
||||
PsmBatteryState_SlowCharging,
|
||||
PsmBatteryState_FastCharging
|
||||
} PsmBatteryState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user