// SPDX-License-Identifier: GPL-2.0-or-later
/*
* msi-ec: MSI laptops' embedded controller driver.
*
* This driver allows various MSI laptops' functionalities to be
* controlled from userspace.
*
* It contains EC memory configurations for different firmware versions
* and exports battery charge thresholds to userspace.
*
* Copyright (C) 2023 Jose Angel Pastrana <japp0005@red.ujaen.es>
* Copyright (C) 2023 Aakash Singh <mail@singhaakash.dev>
* Copyright (C) 2023 Nikita Kravets <teackot@gmail.com>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include "msi-ec.h"
#include <acpi/battery.h>
#include <linux/acpi.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/seq_file.h>
#include <linux/string.h>
#define SM_ECO_NAME "eco"
#define SM_COMFORT_NAME "comfort"
#define SM_SPORT_NAME "sport"
#define SM_TURBO_NAME "turbo"
#define FM_AUTO_NAME "auto"
#define FM_SILENT_NAME "silent"
#define FM_BASIC_NAME "basic"
#define FM_ADVANCED_NAME "advanced"
static const char * const ALLOWED_FW_0[] __initconst = {
"14C1EMS1.012",
"14C1EMS1.101",
"14C1EMS1.102",
NULL
};
static struct msi_ec_conf CONF0 __initdata = {
.allowed_fw = ALLOWED_FW_0,
.charge_control = {
.address = 0xef,
.offset_start = 0x8a,
.offset_end = 0x80,
.range_min = 0x8a,
.range_max = 0xe4,
},
.webcam = {
.address = 0x2e,
.block_address = 0x2f,
.bit = 1,
},
.fn_win_swap = {
.address = 0xbf,
.bit = 4,
},
.cooler_boost = {
.address = 0x98,
.bit = 7,
},
.shift_mode = {
.address = 0xf2,
.modes = {
{ SM_ECO_NAME, 0xc2 },
{ SM_COMFORT_NAME, 0xc1 },
{ SM_SPORT_NAME, 0xc0 },
MSI_EC_MODE_NULL
},
},
.super_battery = {
.address = MSI_EC_ADDR_UNKNOWN, // 0xd5 needs testing
},
.fan_mode = {
.address = 0xf4,
.modes = {
{ FM_AUTO_NAME, 0x0d },
{ FM_SILENT_NAME, 0x1d },
{ FM_BASIC_NAME, 0x4d },
{ FM_ADVANCED_NAME, 0x8d },
MSI_EC_MODE_NULL
},
},
.cpu = {
.rt_temp_address = 0x68,
.rt_fan_speed_address = 0x71,
.rt_fan_speed_base_min = 0x19,
.rt_fan_speed_base_max = 0x37,
.bs_fan_speed_address = 0x89,
.bs_fan_speed_base_min = 0x00,
.bs_fan_speed_base_max = 0x0f,
},
.gpu = {
.rt_temp_address = 0x80,
.rt_fan_speed_address = 0x89,
},
.leds = {
.micmute_led_address = 0x2b,
.mute_led_address = 0x2c,
.bit