Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic
ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include
ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic_wrap/$(CONFIG_MTK_PLATFORM)
#ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/
#ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/mach/
ifeq ($(CONFIG_MTK_TINYSYS_SSPM_SUPPORT), y)
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/sspm/$(MTK_PLATFORM)/
endif
obj-$(CONFIG_MTK_PMIC_COMMON) += upmu.o upmu_regulator.o upmu_debugfs.o upmu_initial_setting.o
ifeq ($(CONFIG_MTK_PMIC_CHIP_MT6359), y)
obj-y += upmu_lbat_service_v2.o
else ifeq ($(CONFIG_MTK_PMIC_CHIP_MT6359P), y)
obj-y += upmu_lbat_service_v2.o
else
obj-y += upmu_lbat_service.o
endif
+740
View File
@@ -0,0 +1,740 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <generated/autoconf.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/preempt.h>
#include <linux/uaccess.h>
#include <linux/of_platform.h>
#include <linux/soc/mediatek/pmic_wrap.h>
#include <linux/regmap.h>
#include <linux/mfd/mt6358/core.h>
#include <mt-plat/upmu_common.h>
#include <mach/mtk_pmic.h>
#include "include/pmic.h"
#include "include/pmic_irq.h"
#include "include/pmic_throttling_dlpt.h"
#include "include/pmic_debugfs.h"
#include "include/pmic_api_buck.h"
#include "include/pmic_bif.h"
#include "include/pmic_auxadc.h"
/**********************************************************
* PMIC related define
***********************************************************/
#if !defined(CONFIG_FPGA_EARLY_PORTING)
#define CONFIG_PMIC_HW_ACCESS_EN
#endif
/*---IPI Mailbox define---*/
#if defined(IPIMB)
#include <mach/mtk_pmic_ipi.h>
#endif
/**********************************************************
* PMIC read/write APIs
***********************************************************/
static struct mt6358_chip *chip;
struct regmap *pmic_nolock_regmap;
static int pmic_read_device(struct regmap *map,
unsigned int RegNum,
unsigned int *val,
unsigned int MASK,
unsigned int SHIFT)
{
int ret = 0;
#if defined(CONFIG_PMIC_HW_ACCESS_EN)
if (!map) {
pr_notice("[%s] regmap not ready\n", __func__);
return -ENODEV;
}
ret = regmap_read(map, RegNum, val);
if (ret) {
dev_notice(chip->dev,
"[%s]ret=%d Reg=0x%x MASK=0x%x SHIFT=%d\n",
__func__, ret, RegNum, MASK, SHIFT);
return ret;
}
*val &= (MASK << SHIFT);
*val >>= SHIFT;
PMICLOG("[%s] (0x%x,0x%x,0x%x,0x%x)\n",
__func__, RegNum, *val, MASK, SHIFT);
#else
pr_info("[%s] Can not access HW PMIC(FPGA?/PWRAP?)\n", __func__);
#endif /*defined(CONFIG_PMIC_HW_ACCESS_EN)*/
return ret;
}
static int pmic_write_device(struct regmap *map,
unsigned int RegNum,
unsigned int val,
unsigned int MASK,
unsigned int SHIFT)
{
int ret = 0;
#if defined(CONFIG_PMIC_HW_ACCESS_EN)
if (!map) {
pr_notice("[%s] regmap not ready\n", __func__);
return -ENODEV;
}
ret = regmap_update_bits(map, RegNum, (MASK << SHIFT), (val << SHIFT));
if (ret) {
dev_notice(chip->dev,
"[%s]ret=%d Reg=0x%x val=0x%x MASK=0x%x SHIFT=%d\n",
__func__, ret, RegNum, val, MASK, SHIFT);
return ret;
}
PMICLOG("[%s] (0x%x,0x%x,0x%x,%d)\n",
__func__, RegNum, val, MASK, SHIFT);
#else
PMICLOG("[%s] Can not access HW PMIC(FPGA?/PWRAP?)\n", __func__);
#endif /*defined(CONFIG_PMIC_HW_ACCESS_EN)*/
return ret;
}
unsigned int pmic_read_interface(unsigned int RegNum,
unsigned int *val,
unsigned int MASK,
unsigned int SHIFT)
{
int ret;
if (!chip) {
pr_notice("[%s] PMIC not ready\n", __func__);
return -ENODEV;
}
ret = pmic_read_device(chip->regmap, RegNum, val, MASK, SHIFT);
return abs(ret);
}
unsigned int pmic_config_interface(unsigned int RegNum,
unsigned int val,
unsigned int MASK,
unsigned int SHIFT)
{
int ret;
if (preempt_count() > 0 ||
irqs_disabled() ||
system_state != SYSTEM_RUNNING ||
oops_in_progress)
return pmic_config_interface_nolock(RegNum, val, MASK, SHIFT);
if (!chip) {
pr_notice("[%s] PMIC not ready\n", __func__);
return -ENODEV;
}
ret = pmic_write_device(chip->regmap, RegNum, val, MASK, SHIFT);
return ret;
}
unsigned int pmic_read_interface_nolock(unsigned int RegNum,
unsigned int *val,
unsigned int MASK,
unsigned int SHIFT)
{
int ret;
ret = pmic_read_device(pmic_nolock_regmap, RegNum, val, MASK, SHIFT);
return abs(ret);
}
unsigned int pmic_config_interface_nolock(unsigned int RegNum,
unsigned int val,
unsigned int MASK,
unsigned int SHIFT)
{
int ret = 0;
ret = pmic_write_device(pmic_nolock_regmap, RegNum, val, MASK, SHIFT);
return abs(ret);
}
unsigned short pmic_set_register_value(PMU_FLAGS_LIST_ENUM flagname,
unsigned int val)
{
const PMU_FLAG_TABLE_ENTRY *pFlag = &pmu_flags_table[flagname];
unsigned int ret = 0;
if (pFlag->flagname != flagname) {
pr_info("[%s]pmic flag idx error\n", __func__);
return 1;
}
ret = pmic_config_interface((unsigned int)(pFlag->offset), val,
(unsigned int)(pFlag->mask), (unsigned int)(pFlag->shift));
if (ret != 0) {
pr_info("[%s] error ret: %d when set Reg[0x%x]=0x%x\n",
__func__, ret, (pFlag->offset), val);
return ret;
}
return 0;
}
unsigned short pmic_get_register_value(PMU_FLAGS_LIST_ENUM flagname)
{
const PMU_FLAG_TABLE_ENTRY *pFlag = &pmu_flags_table[flagname];
unsigned int val = 0;
unsigned int ret = 0;
ret = pmic_read_interface((unsigned int)pFlag->offset, &val,
(unsigned int)(pFlag->mask), (unsigned int)(pFlag->shift));
if (ret != 0) {
pr_info("[%s] error ret: %d when get Reg[0x%x]\n", __func__,
ret, (pFlag->offset));
return ret;
}
return val;
}
unsigned short pmic_set_register_value_nolock(PMU_FLAGS_LIST_ENUM flagname,
unsigned int val)
{
const PMU_FLAG_TABLE_ENTRY *pFlag = &pmu_flags_table[flagname];
unsigned int ret = 0;
if (pFlag->flagname != flagname) {
pr_info("[%s]pmic flag idx error\n", __func__);
return 1;
}
ret = pmic_config_interface_nolock((unsigned int)(pFlag->offset), val,
(unsigned int)(pFlag->mask), (unsigned int)(pFlag->shift));
if (ret != 0) {
pr_info("[%s] error ret: %d when set Reg[0x%x]=0x%x\n",
__func__, ret, (pFlag->offset), val);
return ret;
}
return 0;
}
unsigned short pmic_get_register_value_nolock(PMU_FLAGS_LIST_ENUM flagname)
{
const PMU_FLAG_TABLE_ENTRY *pFlag = &pmu_flags_table[flagname];
unsigned int val = 0;
unsigned int ret = 0;
ret = pmic_read_interface_nolock((unsigned int)pFlag->offset, &val,
(unsigned int)(pFlag->mask), (unsigned int)(pFlag->shift));
if (ret != 0) {
pr_info("[%s] error ret: %d when get Reg[0x%x]\n", __func__,
ret, (pFlag->offset));
return ret;
}
return val;
}
unsigned short bc11_set_register_value(PMU_FLAGS_LIST_ENUM flagname,
unsigned int val)
{
return pmic_set_register_value(flagname, val);
}
unsigned short bc11_get_register_value(PMU_FLAGS_LIST_ENUM flagname)
{
return pmic_get_register_value(flagname);
}
unsigned short pmic_set_hk_reg_value(PMU_FLAGS_LIST_ENUM flagname,
unsigned int val)
{
return pmic_set_register_value(flagname, val);
}
unsigned int upmu_get_reg_value(unsigned int reg)
{
unsigned int reg_val = 0;
unsigned int ret = 0;
ret = pmic_read_interface(reg, &reg_val, 0xFFFF, 0x0);
return reg_val;
}
EXPORT_SYMBOL(upmu_get_reg_value);
void upmu_set_reg_value(unsigned int reg, unsigned int reg_val)
{
unsigned int ret = 0;
ret = pmic_config_interface(reg, reg_val, 0xFFFF, 0x0);
}
/*****************************************************************************
* FTM
******************************************************************************/
#define PMIC_DEVNAME "pmic_ftm"
#define Get_IS_EXT_BUCK_EXIST _IOW('k', 20, int)
#define Get_IS_EXT_VBAT_BOOST_EXIST _IOW('k', 21, int)
#define Get_IS_EXT_SWCHR_EXIST _IOW('k', 22, int)
#define Get_IS_EXT_BUCK2_EXIST _IOW('k', 23, int)
#define Get_IS_EXT_BUCK3_EXIST _IOW('k', 24, int)
static struct class *pmic_class;
static struct cdev *pmic_cdev;
static int pmic_major;
static dev_t pmic_devno;
static long pmic_ftm_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg)
{
void __user *user_data = (void __user *)arg;
int adc_in_data[2] = { 1, 1 };
int adc_out_data[2] = { 1, 1 };
/* adc_in_data is used to check userspace data size */
if (copy_from_user(adc_in_data, user_data, sizeof(adc_in_data)))
return -EFAULT;
switch (cmd) {
case Get_IS_EXT_BUCK_EXIST:
#ifdef CONFIG_MTK_EXTBUCK
adc_out_data[0] = is_ext_buck_exist();
#else
adc_out_data[0] = 0;
#endif
PMICLOG("[%s] Get_IS_EXT_BUCK_EXIST:%d\n"
, __func__, adc_out_data[0]);
break;
case Get_IS_EXT_VBAT_BOOST_EXIST:
adc_out_data[0] = is_ext_vbat_boost_exist();
PMICLOG("[%s] Get_IS_EXT_VBAT_BOOST_EXIST:%d\n"
, __func__, adc_out_data[0]);
break;
case Get_IS_EXT_SWCHR_EXIST:
adc_out_data[0] = is_ext_swchr_exist();
PMICLOG("[%s] Get_IS_EXT_SWCHR_EXIST:%d\n"
, __func__, adc_out_data[0]);
break;
case Get_IS_EXT_BUCK2_EXIST:
#ifdef CONFIG_MTK_EXTBUCK
adc_out_data[0] = is_ext_buck2_exist();
#else
adc_out_data[0] = 0;
#endif
PMICLOG("[%s] Get_IS_EXT_BUCK2_EXIST:%d\n"
, __func__, adc_out_data[0]);
break;
case Get_IS_EXT_BUCK3_EXIST:
#ifdef CONFIG_MTK_EXTBUCK
/* just for UI showing CONNECTED */
adc_out_data[0] = is_ext_buck2_exist();
#else
adc_out_data[0] = 0;
#endif
PMICLOG("[%s] Get_IS_EXT_BUCK3_EXIST:%d\n"
, __func__, adc_out_data[0]);
break;
default:
PMICLOG("[%s] Error ID\n", __func__);
return -EINVAL;
}
if (copy_to_user(user_data, adc_out_data, sizeof(adc_out_data)))
return -EFAULT;
return 0;
}
#ifdef CONFIG_COMPAT
static long pmic_ftm_compat_ioctl(struct file *file,
unsigned int cmd,
unsigned long arg)
{
int ret = 0;
switch (cmd) {
/*#if defined(FTM_EXT_BUCK_CHECK) */
case Get_IS_EXT_BUCK_EXIST:
case Get_IS_EXT_VBAT_BOOST_EXIST:
case Get_IS_EXT_SWCHR_EXIST:
case Get_IS_EXT_BUCK2_EXIST:
ret = file->f_op->unlocked_ioctl(file, cmd, arg);
break;
default:
PMICLOG("[%s] Error ID\n", __func__);
break;
}
return 0;
}
#endif
static int pmic_ftm_open(struct inode *inode, struct file *file)
{
return 0;
}
static int pmic_ftm_release(struct inode *inode, struct file *file)
{
return 0;
}
static const struct file_operations pmic_ftm_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = pmic_ftm_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = pmic_ftm_compat_ioctl,
#endif
.open = pmic_ftm_open,
.release = pmic_ftm_release,
};
void pmic_ftm_init(void)
{
struct class_device *class_dev = NULL;
int ret = 0;
ret = alloc_chrdev_region(&pmic_devno, 0, 1, PMIC_DEVNAME);
if (ret)
PMICLOG("[%s] Error: Can't Get Major number for pmic_ftm\n"
, __func__);
pmic_cdev = cdev_alloc();
pmic_cdev->owner = THIS_MODULE;
pmic_cdev->ops = &pmic_ftm_fops;
ret = cdev_add(pmic_cdev, pmic_devno, 1);
if (ret)
PMICLOG("[%s] Error: cdev_add\n", __func__);
pmic_major = MAJOR(pmic_devno);
pmic_class = class_create(THIS_MODULE, PMIC_DEVNAME);
class_dev = (struct class_device *)device_create(pmic_class,
NULL, pmic_devno, NULL, PMIC_DEVNAME);
PMICLOG("[%s] Done\n", __func__);
}
/*****************************************************************************
* HW Setting
******************************************************************************/
unsigned short is_battery_remove;
unsigned short is_wdt_reboot_pmic;
unsigned short is_wdt_reboot_pmic_chk;
unsigned short g_vmodem_vosel;
unsigned short is_battery_remove_pmic(void)
{
return is_battery_remove;
}
void PMIC_CUSTOM_SETTING_V1(void)
{
}
/*****************************************************************************
* system function
******************************************************************************/
void __attribute__ ((weak)) pmic_auxadc_suspend(void)
{
}
void __attribute__ ((weak)) pmic_auxadc_resume(void)
{
}
void __attribute__ ((weak)) record_md_vosel(void)
{
}
void __attribute__ ((weak)) pmic_enable_smart_reset(unsigned char smart_en,
unsigned char smart_sdn_en)
{
pr_notice("[%s] smart reset not support!\n", __func__);
}
void __attribute__ ((weak)) enable_bat_temp_det(bool en)
{
}
#ifdef IPIMB
static struct regmap *pmic_read_regmap;
static int pmic_ipi_reg_write(void *context, const void *data,
size_t count)
{
unsigned int ret;
unsigned short *dout = (unsigned short *)data;
unsigned short reg = dout[0], val = dout[1];
if (count != 4) {
pr_notice("%s: reg=0x%x, val=0x%x, count=%zu\n",
__func__, reg, val, count);
return -EINVAL;
}
ret = pmic_ipi_config_interface(reg, val, 0xFFFF, 0, 1);
if (ret) {
pr_info("[%s]fail with ret=%d, reg=0x%x val=0x%x\n",
__func__, ret, reg, val);
return -EINVAL;
}
return 0;
}
static int pmic_ipi_reg_read(void *context,
const void *reg_buf, size_t reg_size,
void *val_buf, size_t val_size)
{
unsigned short reg = *(unsigned short *)reg_buf;
unsigned int val = 0;
int ret = 0;
if (reg_size != 2 || val_size != 2) {
pr_notice("%s: reg=0x%x, reg_size=%zu, val_size=%zu\n",
__func__, reg, reg_size, val_size);
return -EINVAL;
}
ret = regmap_read(pmic_read_regmap, reg, &val);
*(u16 *)val_buf = val;
return ret;
}
static int pmic_ipi_reg_update_bits(void *context, unsigned int reg,
unsigned int mask, unsigned int val)
{
unsigned int ret;
ret = pmic_ipi_config_interface(reg, val, mask, 0, 1);
if (ret) {
pr_info("[%s]fail with ret=%d, reg=0x%x mask=0x%x val=0x%x\n",
__func__, ret, reg, mask, val);
return -EINVAL;
}
return 0;
}
static void pmic_ipi_regmap_unlock_empty(void *__map)
{
}
static const struct regmap_config pmic_ipi_regmap_config = {
.name = "pmic_ipi",
.reg_bits = 16,
.val_bits = 16,
.reg_stride = 2,
.max_register = 0xffff,
.reg_format_endian = REGMAP_ENDIAN_NATIVE,
.val_format_endian = REGMAP_ENDIAN_NATIVE,
};
static const struct regmap_config pmic_ipi_nolock_regmap_config = {
.name = "pmic_ipi_nolock",
.reg_bits = 16,
.val_bits = 16,
.lock = pmic_ipi_regmap_unlock_empty,
.unlock = pmic_ipi_regmap_unlock_empty,
.reg_stride = 2,
.max_register = 0xffff,
.reg_format_endian = REGMAP_ENDIAN_NATIVE,
.val_format_endian = REGMAP_ENDIAN_NATIVE,
};
static struct regmap_bus regmap_pmic_ipi_bus = {
.write = pmic_ipi_reg_write,
.read = pmic_ipi_reg_read,
.reg_update_bits = pmic_ipi_reg_update_bits,
.fast_io = true,
};
#endif
#if IS_ENABLED(CONFIG_CHRDET_VBUS_DETECTION)
static irqreturn_t mtk_mt_irq_handler_thread(int irq, void *data)
{
if (pmic_get_register_value(PMIC_RGS_CHRDET)) {
pr_info("usb cable in\n");
mt_usb_connect_v1();
} else {
pr_info("usb cable out\n");
mt_usb_disconnect_v1();
}
return IRQ_HANDLED;
}
bool mtk_mt_pmic_get_vcdt(void)
{
if (pmic_get_register_value(PMIC_RGS_CHRDET))
return true;
return false;
}
EXPORT_SYMBOL(mtk_mt_pmic_get_vcdt);
#endif
static int pmic_mt_probe(struct platform_device *pdev)
{
int ret = 0;
#if IS_ENABLED(CONFIG_CHRDET_VBUS_DETECTION)
int mt_irq = 0;
#endif
chip = dev_get_drvdata(pdev->dev.parent);
#ifdef IPIMB
pmic_read_regmap = dev_get_regmap(chip->dev->parent, NULL);
chip->regmap = devm_regmap_init(&pdev->dev, &regmap_pmic_ipi_bus,
NULL, &pmic_ipi_regmap_config);
if (IS_ERR(chip->regmap)) {
ret = PTR_ERR(chip->regmap);
dev_notice(&pdev->dev, "failed to init IPI regmap\n");
chip->regmap = dev_get_regmap(chip->dev->parent, NULL);
}
pmic_nolock_regmap = devm_regmap_init(&pdev->dev,
&regmap_pmic_ipi_bus,
NULL,
&pmic_ipi_nolock_regmap_config);
if (IS_ERR(pmic_nolock_regmap)) {
ret = PTR_ERR(pmic_nolock_regmap);
dev_notice(&pdev->dev, "failed to init nolock regmap\n");
pmic_nolock_regmap = chip->regmap;
}
#else
pmic_nolock_regmap = chip->regmap;
#endif
pr_info("******** MT pmic driver probe!! ********\n");
/*get PMIC CID */
PMICLOG("PMIC CID = 0x%x\n", pmic_get_register_value(PMIC_SWCID));
#if defined(CONFIG_MACH_MT6781)
record_is_pmic_new_power_grid(pdev);
#endif
record_md_vosel();
PMIC_INIT_SETTING_V1();
PMICLOG("[PMIC_INIT_SETTING_V1] Done\n");
/*PMIC Interrupt Service*/
PMIC_EINT_SETTING(pdev);
PMICLOG("[PMIC_EINT_SETTING] Done\n");
mtk_regulator_init(to_platform_device(pdev->dev.parent));
PMICLOG("[PMIC] mtk_regulator_init : done.\n");
pmic_throttling_dlpt_init(pdev);
PMICLOG("[PMIC] pmic_throttling_dlpt_init : done.\n");
pmic_debug_init(pdev);
PMICLOG("[PMIC] pmic_debug_init : done.\n");
pmic_ftm_init();
if (IS_ENABLED(CONFIG_MTK_BIF_SUPPORT))
pmic_bif_init();
#if IS_ENABLED(CONFIG_CHRDET_VBUS_DETECTION)
/*add pmic mt6358 chrdet irq for vbus detection*/
mt_irq = platform_get_irq_byname(pdev, "chrdet_edge");
if (mt_irq < 0) {
pr_info("[PMIC] Get mt irq fail, %d.\n", mt_irq);
return mt_irq;
}
ret = devm_request_threaded_irq(&pdev->dev, mt_irq, NULL,
mtk_mt_irq_handler_thread,
IRQF_ONESHOT | IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW,
"chrdet_edge", chip);
if (ret) {
pr_info("Failed to request mt IRQ: %d: %d\n", mt_irq, ret);
return ret;
}
#endif
return ret;
}
static int pmic_mt_remove(struct platform_device *pdev)
{
PMICLOG("******** MT pmic driver remove!! ********\n");
return 0;
}
static void pmic_mt_shutdown(struct platform_device *pdev)
{
PMICLOG("******** MT pmic driver shutdown!! ********\n");
vmd1_pmic_setting_on();
}
static int pmic_mt_suspend(struct platform_device *pdev, pm_message_t state)
{
PMICLOG("******** MT pmic driver suspend!! ********\n");
pmic_throttling_dlpt_suspend();
pmic_auxadc_suspend();
return 0;
}
static int pmic_mt_resume(struct platform_device *pdev)
{
PMICLOG("******** MT pmic driver resume!! ********\n");
pmic_throttling_dlpt_resume();
pmic_auxadc_resume();
return 0;
}
static const struct of_device_id pmic_of_match[] = {
{.compatible = "mediatek,mt-pmic"},
{},
};
static struct platform_driver pmic_mt_driver = {
.probe = pmic_mt_probe,
.remove = pmic_mt_remove,
.shutdown = pmic_mt_shutdown,
.suspend = pmic_mt_suspend,
.resume = pmic_mt_resume,
.driver = {
.name = "mt-pmic",
.of_match_table = pmic_of_match,
},
};
/**************************************************************************
* PMIC mudule init/exit
***************************************************************************/
static int __init pmic_mt_init(void)
{
int ret;
ret = platform_driver_register(&pmic_mt_driver);
if (ret) {
pr_info("****[%s] Unable to register driver (%d)\n",
__func__, ret);
return ret;
}
pr_info("****[%s] Initialization : DONE !!\n", __func__);
return 0;
}
fs_initcall(pmic_mt_init);
static void __exit pmic_mt_exit(void)
{
platform_driver_unregister(&pmic_mt_driver);
}
module_exit(pmic_mt_exit);
MODULE_AUTHOR("Jimmy-YJ Huang");
MODULE_DESCRIPTION("MTK PMIC COMMON Interface Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0_M");
@@ -0,0 +1,225 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <mach/mtk_pmic.h>
#include <mt-plat/mtk_auxadc_intf.h>
static struct mtk_auxadc_intf *auxadc_intf;
const char *pmic_get_auxadc_name(u8 list)
{
return pmic_auxadc_channel_name[list];
}
EXPORT_SYMBOL(pmic_get_auxadc_name);
int pmic_get_auxadc_value(u8 list)
{
int value = 0;
if (list >= AUXADC_LIST_START && list <= AUXADC_LIST_END) {
value = mt_get_auxadc_value(list);
return value;
}
pr_info("%s Invalid AUXADC LIST\n", __func__);
return -EINVAL;
}
static struct mtk_auxadc_ops pmic_auxadc_ops = {
.get_channel_value = pmic_get_auxadc_value,
.dump_regs = pmic_auxadc_dump_regs,
};
static struct mtk_auxadc_intf pmic_auxadc_intf = {
.ops = &pmic_auxadc_ops,
.name = "mtk_auxadc_intf",
.channel_name = pmic_auxadc_channel_name,
};
int register_mtk_auxadc_intf(struct mtk_auxadc_intf *intf)
{
auxadc_intf = intf;
platform_device_register_simple(auxadc_intf->name, -1, NULL, 0);
return 0;
}
EXPORT_SYMBOL(register_mtk_auxadc_intf);
void mtk_auxadc_init(void)
{
#if 0
pmic_auxadc_init();
#endif
pmic_auxadc_intf.channel_num = pmic_get_auxadc_channel_max();
if (register_mtk_auxadc_intf(&pmic_auxadc_intf) < 0)
pr_notice("[%s] register MTK Auxadc Intf Fail\n", __func__);
}
static ssize_t mtk_auxadc_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count);
static ssize_t mtk_auxadc_show(struct device *dev,
struct device_attribute *attr, char *buf);
static struct device_attribute mtk_auxadc_attrs[] = {
__ATTR(dump_channel, 0444, mtk_auxadc_show, NULL),
__ATTR(channel, 0644, mtk_auxadc_show, mtk_auxadc_store),
__ATTR(value, 0444, mtk_auxadc_show, NULL),
__ATTR(regs, 0444, mtk_auxadc_show, NULL),
__ATTR(md_channel, 0644, mtk_auxadc_show, mtk_auxadc_store),
__ATTR(md_value, 0444, mtk_auxadc_show, NULL),
__ATTR(md_dump_channel, 0444, mtk_auxadc_show, NULL),
};
static int get_parameters(char *buf, long int *param, int num_of_par)
{
char *token;
int base, cnt;
token = strsep(&buf, " ");
for (cnt = 0; cnt < num_of_par; cnt++) {
if (token != NULL) {
if ((token[1] == 'x') || (token[1] == 'X'))
base = 16;
else
base = 10;
if (kstrtoul(token, base, &param[cnt]) != 0)
return -EINVAL;
token = strsep(&buf, " ");
} else
return -EINVAL;
}
return 0;
}
static ssize_t mtk_auxadc_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
ptrdiff_t cmd;
int ret;
long int val;
cmd = attr - mtk_auxadc_attrs;
switch (cmd) {
case AUXADC_CHANNEL:
ret = get_parameters((char *)buf, &val, 1);
if (ret < 0) {
pr_notice("get parameter fail\n");
return -EINVAL;
}
auxadc_intf->dbg_chl = val;
break;
default:
break;
}
return count;
}
static ssize_t mtk_auxadc_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
ptrdiff_t cmd;
int i;
int value;
cmd = attr - mtk_auxadc_attrs;
buf[0] = '\0';
switch (cmd) {
case AUXADC_DUMP:
snprintf(buf+strlen(buf),
256, "=== Channel Dump Start ===\n");
for (i = 0; i < auxadc_intf->channel_num; i++) {
value = auxadc_intf->ops->get_channel_value(i);
if (value >= 0)
snprintf(buf+strlen(buf), 256,
"Channel%d (%s) = 0x%x(%d)\n",
i, auxadc_intf->channel_name[i],
value, value);
}
snprintf(buf+strlen(buf),
256, "==== Channel Dump End ====\n");
break;
case AUXADC_CHANNEL:
snprintf(buf + strlen(buf), 256, "%d (%s)\n"
, auxadc_intf->dbg_chl
, auxadc_intf->channel_name[auxadc_intf->dbg_chl]);
break;
case AUXADC_VALUE:
value = auxadc_intf->ops->get_channel_value(
auxadc_intf->dbg_chl);
snprintf(buf + strlen(buf), 256, "Channel%d (%s) = 0x%x(%d)\n"
, auxadc_intf->dbg_chl
, auxadc_intf->channel_name[auxadc_intf->dbg_chl]
, value, value);
break;
case AUXADC_REGS:
auxadc_intf->ops->dump_regs(buf);
break;
default:
break;
}
return strlen(buf);
}
static int create_sysfs_interface(struct device *dev)
{
int i;
for (i = 0; i < ARRAY_SIZE(mtk_auxadc_attrs); i++)
if (device_create_file(dev, mtk_auxadc_attrs + i))
return -EINVAL;
return 0;
}
static int remove_sysfs_interface(struct device *dev)
{
int i;
for (i = 0; i < ARRAY_SIZE(mtk_auxadc_attrs); i++)
device_remove_file(dev, mtk_auxadc_attrs + i);
return 0;
}
static int mtk_auxadc_intf_probe(struct platform_device *pdev)
{
int ret;
pr_info("%s\n", __func__);
platform_set_drvdata(pdev, auxadc_intf);
ret = create_sysfs_interface(&pdev->dev);
if (ret < 0) {
pr_notice("%s create sysfs fail\n", __func__);
return -EINVAL;
}
return 0;
}
static int mtk_auxadc_intf_remove(struct platform_device *pdev)
{
int ret;
ret = remove_sysfs_interface(&pdev->dev);
return 0;
}
static struct platform_driver mtk_auxadc_intf_driver = {
.driver = {
.name = "mtk_auxadc_intf",
},
.probe = mtk_auxadc_intf_probe,
.remove = mtk_auxadc_intf_remove,
};
module_platform_driver(mtk_auxadc_intf_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("MTK PMIC AUXADC Interface Driver");
MODULE_AUTHOR("Jeff Chang <jeff_chang@richtek.com>");
MODULE_VERSION("1.0.0_M");
@@ -0,0 +1,310 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <generated/autoconf.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <linux/debugfs.h>
#include <mt-plat/upmu_common.h>
#include "include/pmic.h"
#include "include/pmic_debugfs.h"
#include "include/pmic_irq.h"
#include "include/pmic_throttling_dlpt.h"
#include "include/pmic_lbat_service.h"
/*-------pmic_dbg_level global variable-------*/
unsigned int gPMICDbgLvl;
unsigned int gPMICHKDbgLvl;
unsigned int gPMICIRQDbgLvl;
unsigned int gPMICREGDbgLvl;
unsigned int gPMICCOMDbgLvl; /* so far no used */
#define DUMP_ALL_REG 0
int pmic_pre_wdt_reset(void)
{
int ret = 0;
/* remove dump exception status before wdt, since we will recore
* it at next boot preloader
*/
#if 0
preempt_disable();
local_irq_disable();
pr_info(PMICTAG "[%s][pmic_boot_status]\n", __func__);
pmic_dump_exception_reg();
#if DUMP_ALL_REG
pmic_dump_register();
#endif
#endif
return ret;
}
int pmic_pre_condition1(void)
{
return 0;
}
int pmic_pre_condition2(void)
{
return 0;
}
int pmic_pre_condition3(void)
{
return 0;
}
int pmic_post_condition1(void)
{
return 0;
}
int pmic_post_condition2(void)
{
return 0;
}
int pmic_post_condition3(void)
{
return 0;
}
/*****************************************************************************
* mt-pmic dev_attr APIs
******************************************************************************/
unsigned int g_reg_value;
static ssize_t show_pmic_access(struct device *dev,
struct device_attribute *attr,
char *buf)
{
pr_info("[%s] 0x%x\n", __func__, g_reg_value);
return sprintf(buf, "0x%x\n", g_reg_value);
}
static ssize_t store_pmic_access(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t size)
{
int ret = 0;
char *pvalue = NULL, *addr = NULL, *val = NULL;
unsigned int reg_value = 0;
unsigned int reg_address = 0;
pr_info("[%s]\n", __func__);
if (buf != NULL && size != 0) {
pr_info("[%s] size is %d, buf is %s\n"
, __func__, (int)size, buf);
pvalue = (char *)buf;
addr = strsep(&pvalue, " ");
val = strsep(&pvalue, " ");
if (addr)
ret = kstrtou32(addr, 16, (unsigned int *)&reg_address);
if (val) {
ret = kstrtou32(val, 16, (unsigned int *)&reg_value);
pr_info("[%s] write PMU reg 0x%x with value 0x%x !\n"
, __func__, reg_address, reg_value);
ret = pmic_config_interface(
reg_address, reg_value, 0xFFFF, 0x0);
} else {
ret = pmic_read_interface(
reg_address, &g_reg_value, 0xFFFF, 0x0);
pr_info("[%s] read PMU reg 0x%x with value 0x%x !\n"
, __func__, reg_address, g_reg_value);
pr_info("[%s] use \"cat pmic_access\" to get value\n"
, __func__);
}
}
return size;
}
/*664*/
static DEVICE_ATTR(pmic_access, 0664, show_pmic_access, store_pmic_access);
/*
* PMIC dump exception
*/
static int pmic_dump_exception_show(struct seq_file *s, void *unused)
{
both_dump_exception_reg(s);
return 0;
}
static int pmic_dump_exception_open(struct inode *inode, struct file *file)
{
return single_open(file, pmic_dump_exception_show, NULL);
}
const struct file_operations pmic_dump_exception_operations = {
.open = pmic_dump_exception_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
/*
* PMIC debug level
*/
/*-------pmic_dbg_level-------*/
static ssize_t pmic_dbg_level_write(struct file *file,
const char __user *buf,
size_t size,
loff_t *ppos)
{
char info[10];
unsigned int value = 0;
int ret = 0;
memset(info, 0, 10);
ret = simple_write_to_buffer(info, sizeof(info) - 1, ppos, buf, size);
if (ret < 0)
return ret;
ret = kstrtou32(info, 16, (unsigned int *)&value);
if (ret)
return ret;
pr_info("[%s] value=0x%x\n", __func__, value);
if (value != 0xFFFF) {
pmic_dbg_level_set(value);
pr_info("D %d, HK %d, IRQ %d, REG %d, COM %d\n",
gPMICDbgLvl, gPMICHKDbgLvl, gPMICIRQDbgLvl,
gPMICREGDbgLvl, gPMICCOMDbgLvl);
}
return size;
}
static int pmic_dbg_level_show(struct seq_file *s, void *unused)
{
seq_puts(s, "4:PMIC_LOG_DBG\n");
seq_puts(s, "3:PMIC_LOG_INFO\n");
seq_puts(s, "2:PMIC_LOG_NOT\n");
seq_puts(s, "1:PMIC_LOG_WARN\n");
seq_puts(s, "0:PMIC_LOG_ERR\n");
seq_printf(s, "PMIC_Dbg_Lvl = %d\n", gPMICDbgLvl);
seq_printf(s, "PMIC_HK_Dbg_Lvl = %d\n", gPMICHKDbgLvl);
seq_printf(s, "PMIC_IRQ_Dbg_Lvl = %d\n", gPMICIRQDbgLvl);
seq_printf(s, "PMIC_REG_Dbg_Lvl = %d\n", gPMICREGDbgLvl);
seq_printf(s, "PMIC_COM_Dbg_Lvl = %d\n", gPMICCOMDbgLvl);
return 0;
}
static int pmic_dbg_level_open(struct inode *inode, struct file *file)
{
return single_open(file, pmic_dbg_level_show, NULL);
}
static const struct file_operations pmic_dbg_level_operations = {
.open = pmic_dbg_level_open,
.read = seq_read,
.write = pmic_dbg_level_write,
.llseek = seq_lseek,
.release = single_release,
};
/*
* PMIC reg cmp log
*/
/*----------------pmic reg cmp machanism-----------------------*/
void __attribute__ ((weak)) pmic_cmp_register(struct seq_file *m)
{
}
static int proc_cmp_register_show(struct seq_file *m, void *v)
{
seq_puts(m, "*****Compare PMIC registers with initial setting*****\n");
pmic_cmp_register(m);
return 0;
}
static int proc_cmp_register_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_cmp_register_show, NULL);
}
static const struct file_operations pmic_cmp_register_proc_fops = {
.open = proc_cmp_register_open,
.read = seq_read,
};
/*
* PMIC reg dump log
*/
/*----------------pmic reg dump machanism-----------------------*/
static int proc_dump_register_show(struct seq_file *m, void *v)
{
seq_puts(m, "********** dump PMIC registers**********\n");
pmic_dump_register(m);
return 0;
}
static int proc_dump_register_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_dump_register_show, NULL);
}
static const struct file_operations pmic_dump_register_proc_fops = {
.open = proc_dump_register_open,
.read = seq_read,
};
int __attribute__ ((weak)) pmic_irq_debug_init(struct dentry *debug_dir)
{
return 0;
}
int pmic_debug_init(struct platform_device *dev)
{
struct dentry *mtk_pmic_dir;
int ret_device_file = 0;
mtk_pmic_dir = debugfs_create_dir("mtk_pmic", NULL);
if (!mtk_pmic_dir) {
pr_notice(PMICTAG "fail to mkdir /sys/kernel/debug/mtk_pmic\n");
return -ENOMEM;
}
/*--/sys/kernel/debug/mtk_pmic--*/
debugfs_create_file("dump_pmic_reg", 0644,
mtk_pmic_dir, NULL,
&pmic_dump_register_proc_fops);
debugfs_create_file("cmp_pmic_reg", 0644,
mtk_pmic_dir, NULL,
&pmic_cmp_register_proc_fops);
debugfs_create_file("pmic_dump_exception", (S_IFREG | 0444),
mtk_pmic_dir, NULL,
&pmic_dump_exception_operations);
debugfs_create_file("pmic_dbg_level", (S_IFREG | 0444),
mtk_pmic_dir, NULL,
&pmic_dbg_level_operations);
pmic_regulator_debug_init(dev, mtk_pmic_dir);
pmic_throttling_dlpt_debug_init(dev, mtk_pmic_dir);
pmic_irq_debug_init(mtk_pmic_dir);
lbat_debug_init(mtk_pmic_dir);
PMICLOG("%s debugfs done\n", __func__);
/*--/sys/devices/platform/mt-pmic/ --*/
ret_device_file = device_create_file(&(dev->dev),
&dev_attr_pmic_access);
PMICLOG("%s dev attr done\n", __func__);
return 0;
}
MODULE_AUTHOR("Jimmy-YJ Huang");
MODULE_DESCRIPTION("MT PMIC DEBUGFS Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0_M");
@@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <mt-plat/upmu_common.h>
#include <linux/io.h>
#include <linux/io.h>
#include <linux/of_address.h>
#include "include/pmic.h"
void PMIC_INIT_SETTING_V1(void)
{
unsigned int chip_version = 0;
chip_version = pmic_get_register_value(PMIC_SWCID);
PMIC_check_battery(); /*--update is_battery_remove--*/
PMIC_check_wdt_status(); /*--update is_wdt_reboot_pmic/chk--*/
/*--------------------------------------------------------*/
if (!PMIC_check_pwrhold_status())
PMIC_POWER_HOLD(1);
PMICLOG("[PMIC] Chip = 0x%x,is_battery_remove =%d, is_wdt_reboot=%d\n"
, chip_version, is_battery_remove, is_wdt_reboot_pmic);
PMIC_LP_INIT_SETTING();
/*****************************************************
* below programming is used for MD setting
*****************************************************/
#ifdef CONFIG_MTK_PMIC_CHIP_MT6355
PMIC_MD_INIT_SETTING_V1();
#endif
/*PMIC_PWROFF_SEQ_SETTING();*/
}
@@ -0,0 +1,669 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/list_sort.h>
#include <linux/dcache.h>
#include <linux/debugfs.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/pm_wakeup.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <mt-plat/upmu_common.h>
#include <include/pmic_lbat_service.h>
#define VOLT_TO_RAW(volt) (((volt) << 12) / 5400)
#define RAW_TO_VOLT(thd) (((thd) * 5400) >> 12)
#define USER_SIZE 16
#define DEF_H_DEB 150 /* 150ms */
#define DEF_L_DEB 0 /* no de-bounce */
#define LBAT_PRD 15 /* 15ms */
#define LBAT_SERVICE_DBG 0
static DEFINE_MUTEX(lbat_mutex);
static struct list_head lbat_hv_list = LIST_HEAD_INIT(lbat_hv_list);
static struct list_head lbat_lv_list = LIST_HEAD_INIT(lbat_lv_list);
/* workqueue for SW de-bounce */
static struct workqueue_struct *lbat_wq;
static unsigned int user_count;
enum lbat_thd_type {
LBAT_HV,
LBAT_LV,
};
struct lbat_thd_t {
unsigned int thd_volt;
struct lbat_user *user;
struct list_head list;
};
static struct lbat_thd_t *cur_hv_ptr;
static struct lbat_thd_t *cur_lv_ptr;
static struct lbat_user *lbat_user_table[USER_SIZE];
static void lbat_max_en_setting(int en_val)
{
pmic_set_register_value(PMIC_AUXADC_LBAT_EN_MAX, en_val);
pmic_set_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MAX, en_val);
}
static void lbat_min_en_setting(int en_val)
{
pmic_set_register_value(PMIC_AUXADC_LBAT_EN_MIN, en_val);
pmic_set_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MIN, en_val);
}
static void lbat_irq_enable(void)
{
if (cur_hv_ptr != NULL)
lbat_max_en_setting(1);
if (cur_lv_ptr != NULL)
lbat_min_en_setting(1);
}
static void lbat_irq_disable(void)
{
lbat_max_en_setting(0);
lbat_min_en_setting(0);
}
static int hv_list_cmp(void *priv, struct list_head *a, struct list_head *b)
{
struct lbat_thd_t *thd_a, *thd_b;
thd_a = list_entry(a, struct lbat_thd_t, list);
thd_b = list_entry(b, struct lbat_thd_t, list);
return thd_a->thd_volt - thd_b->thd_volt;
}
static int lv_list_cmp(void *priv, struct list_head *a, struct list_head *b)
{
struct lbat_thd_t *thd_a, *thd_b;
thd_a = list_entry(a, struct lbat_thd_t, list);
thd_b = list_entry(b, struct lbat_thd_t, list);
return thd_b->thd_volt - thd_a->thd_volt;
}
static int modify_lbat_list(enum lbat_thd_type type,
struct lbat_thd_t *thd)
{
if (!thd)
return -EINVAL;
switch (type) {
case LBAT_HV:
list_add(&thd->list, &lbat_hv_list);
list_sort(NULL, &lbat_hv_list, hv_list_cmp);
thd = list_first_entry(&lbat_hv_list,
struct lbat_thd_t, list);
if (cur_hv_ptr != thd) {
cur_hv_ptr = thd;
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MAX,
VOLT_TO_RAW(cur_hv_ptr->thd_volt));
}
break;
case LBAT_LV:
list_add(&thd->list, &lbat_lv_list);
list_sort(NULL, &lbat_lv_list, lv_list_cmp);
thd = list_first_entry(&lbat_lv_list,
struct lbat_thd_t, list);
if (cur_lv_ptr != thd) {
cur_lv_ptr = thd;
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MIN,
VOLT_TO_RAW(cur_lv_ptr->thd_volt));
}
break;
}
return 0;
}
/*
* After execute lbat_user's callback, set next thd node to wait event
*/
static void lbat_set_next_thd(struct lbat_user *user, struct lbat_thd_t *thd)
{
if (thd == user->hv_thd) {
modify_lbat_list(LBAT_LV, user->lv1_thd);
if (!list_empty(&user->lv2_thd->list))
list_del_init(&user->lv2_thd->list);
} else if (thd == user->lv1_thd) {
modify_lbat_list(LBAT_HV, user->hv_thd);
if (list_empty(&user->lv2_thd->list))
modify_lbat_list(LBAT_LV, user->lv2_thd);
}
}
/*
* Execute user's callback and set its next threshold if reach deb_times,
* otherwise ignore this event and reset lbat_list
*/
static void lbat_deb_handler(struct work_struct *work)
{
enum lbat_thd_type type;
unsigned int deb_times;
struct lbat_user *user =
container_of(work, struct lbat_user, deb_work);
mutex_lock(&lbat_mutex);
if (user->deb_thd_ptr == user->hv_thd) {
type = LBAT_HV;
deb_times = user->hv_deb_times;
} else {
type = LBAT_LV;
deb_times = user->lv_deb_times;
}
if (user->deb_cnt >= deb_times) {
/* execute user's callback after de-bounce */
user->callback(user->deb_thd_ptr->thd_volt);
lbat_set_next_thd(user, user->deb_thd_ptr);
} else {
/* ignore this event and reset lbat_list */
modify_lbat_list(type, user->deb_thd_ptr);
}
/* de-bounce done, reset deb_cnt and deb_thd_ptr */
user->deb_cnt = 0;
user->deb_thd_ptr = NULL;
lbat_irq_disable();
udelay(200);
lbat_irq_enable();
mutex_unlock(&lbat_mutex);
}
//static void lbat_timer_func(unsigned long data)
static void lbat_timer_func(struct timer_list *t)
{
unsigned int deb_prd = 0;
unsigned int deb_times = 0;
struct lbat_user *user = from_timer(user, t, deb_timer);
if (user->deb_thd_ptr == user->hv_thd) {
/* LBAT user HV de-bounce */
if (lbat_read_volt() < user->deb_thd_ptr->thd_volt) {
/* queue deb_work to reset lbat_list */
goto wq_handler;
}
deb_prd = user->hv_deb_prd;
deb_times = user->hv_deb_times;
} else if (user->deb_thd_ptr == user->lv1_thd ||
user->deb_thd_ptr == user->lv2_thd) {
/* LBAT user LV de-bounce */
if (lbat_read_volt() > user->deb_thd_ptr->thd_volt) {
/* queue deb_work to reset lbat_list */
goto wq_handler;
}
deb_prd = user->lv_deb_prd;
deb_times = user->lv_deb_times;
} else {
pr_notice("[%s] LBAT de-bounce threshold not match\n",
__func__);
return;
}
user->deb_cnt++;
#if LBAT_SERVICE_DBG
pr_info("[%s] name:%s, thd_volt:%d, de-bounce times:%d\n",
__func__, user->name,
user->deb_thd_ptr->thd_volt, user->deb_cnt);
#endif
if (user->deb_cnt < deb_times) {
mod_timer(&user->deb_timer,
jiffies + msecs_to_jiffies(deb_prd));
return;
}
wq_handler:
/* queue deb_work to execute user's callback or reset lbat_list */
queue_work(lbat_wq, &user->deb_work);
}
static void lbat_user_init_timer(struct lbat_user *user)
{
user->deb_cnt = 0;
user->hv_deb_prd = 0;
user->hv_deb_times = 0;
user->lv_deb_prd = 0;
user->lv_deb_times = 0;
/*workaround for mt6768*/
//init_timer(&user->deb_timer);
//user->deb_timer.data = (unsigned long)user;
//user->deb_timer.expires = 0;
//user->deb_timer.function = lbat_timer_func;
timer_setup(&user->deb_timer, lbat_timer_func, 0);
}
static int lbat_user_update(struct lbat_user *user)
{
/*
* add lv_thd to lbat_lv_list
* and assign first entry of lv_list to cur_lv_ptr
*/
modify_lbat_list(LBAT_LV, user->lv1_thd);
if (user_count == 0)
lbat_min_en_setting(1);
lbat_user_table[user_count++] = user;
return 0;
}
static struct lbat_thd_t *lbat_thd_init(unsigned int thd_volt,
struct lbat_user *user)
{
struct lbat_thd_t *thd;
if (thd_volt == 0)
return NULL;
thd = kzalloc(sizeof(*thd), GFP_KERNEL);
if (thd == NULL)
return NULL;
thd->thd_volt = thd_volt;
thd->user = user;
INIT_LIST_HEAD(&thd->list);
return thd;
}
struct lbat_user *lbat_user_register(const char *name,
unsigned int hv_thd_volt,
unsigned int lv1_thd_volt, unsigned int lv2_thd_volt,
void (*callback)(unsigned int thd_volt))
{
int ret = 0;
struct lbat_user *user = NULL;
mutex_lock(&lbat_mutex);
user = kzalloc(sizeof(*user), GFP_KERNEL);
if (user == NULL) {
ret = -10;
goto out;
}
strncpy(user->name, name, strlen(user->name));
if (hv_thd_volt >= 5400 || lv1_thd_volt <= 2650) {
ret = -11;
goto out;
} else if (hv_thd_volt < lv1_thd_volt ||
lv1_thd_volt < lv2_thd_volt) {
ret = -12;
goto out;
} else if (callback == NULL) {
ret = -13;
goto out;
}
user->hv_thd = lbat_thd_init(hv_thd_volt, user);
user->lv1_thd = lbat_thd_init(lv1_thd_volt, user);
user->lv2_thd = lbat_thd_init(lv2_thd_volt, user);
user->callback = callback;
lbat_user_init_timer(user);
INIT_WORK(&user->deb_work, lbat_deb_handler);
pr_info("[%s] hv=%d, lv1=%d, lv2=%d\n",
__func__, hv_thd_volt, lv1_thd_volt, lv2_thd_volt);
ret = lbat_user_update(user);
out:
if (ret)
pr_notice("[%s] error ret=%d\n", __func__, ret);
mutex_unlock(&lbat_mutex);
return user;
}
EXPORT_SYMBOL(lbat_user_register);
int lbat_user_set_debounce(struct lbat_user *user,
unsigned int hv_deb_prd, unsigned int hv_deb_times,
unsigned int lv_deb_prd, unsigned int lv_deb_times)
{
if (IS_ERR(user))
return PTR_ERR(user);
user->hv_deb_prd = hv_deb_prd;
user->hv_deb_times = hv_deb_times;
user->lv_deb_prd = lv_deb_prd;
user->lv_deb_times = lv_deb_times;
return 0;
}
EXPORT_SYMBOL(lbat_user_set_debounce);
static irqreturn_t bat_h_int_handler(int irq, void *data)
{
struct lbat_user *user;
if (cur_hv_ptr == NULL) {
lbat_max_en_setting(0);
return IRQ_NONE;
}
mutex_lock(&lbat_mutex);
pr_info("[%s] cur_thd_volt=%d\n", __func__, cur_hv_ptr->thd_volt);
user = cur_hv_ptr->user;
list_del_init(&cur_hv_ptr->list);
if (user->hv_deb_times) {
user->deb_cnt = 0;
user->deb_thd_ptr = cur_hv_ptr;
mod_timer(&user->deb_timer,
jiffies + msecs_to_jiffies(user->hv_deb_prd));
} else {
user->callback(cur_hv_ptr->thd_volt);
lbat_set_next_thd(user, cur_hv_ptr);
}
/* Since cur_hv_ptr is removed, assign new thd for cur_hv_ptr */
if (list_empty(&lbat_hv_list)) {
cur_hv_ptr = NULL;
goto out;
}
cur_hv_ptr = list_first_entry(
&lbat_hv_list, struct lbat_thd_t, list);
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MAX,
VOLT_TO_RAW(cur_hv_ptr->thd_volt));
out:
lbat_irq_disable();
udelay(200);
lbat_irq_enable();
mutex_unlock(&lbat_mutex);
return IRQ_HANDLED;
}
static irqreturn_t bat_l_int_handler(int irq, void *data)
{
struct lbat_user *user;
if (cur_lv_ptr == NULL) {
lbat_min_en_setting(0);
return IRQ_NONE;
}
mutex_lock(&lbat_mutex);
pr_info("[%s] cur_thd_volt=%d\n", __func__, cur_lv_ptr->thd_volt);
user = cur_lv_ptr->user;
list_del_init(&cur_lv_ptr->list);
if (user->lv_deb_times) {
user->deb_cnt = 0;
user->deb_thd_ptr = cur_lv_ptr;
mod_timer(&user->deb_timer,
jiffies + msecs_to_jiffies(user->lv_deb_prd));
} else {
user->callback(cur_lv_ptr->thd_volt);
lbat_set_next_thd(user, cur_lv_ptr);
}
/* Since cur_lv_ptr is removed, assign new thd for cur_lv_ptr */
if (list_empty(&lbat_lv_list)) {
cur_lv_ptr = NULL;
goto out;
}
cur_lv_ptr = list_first_entry(
&lbat_lv_list, struct lbat_thd_t, list);
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MIN,
VOLT_TO_RAW(cur_lv_ptr->thd_volt));
out:
lbat_irq_disable();
udelay(200);
lbat_irq_enable();
mutex_unlock(&lbat_mutex);
return IRQ_HANDLED;
}
void lbat_suspend(void)
{
lbat_irq_disable();
}
void lbat_resume(void)
{
lbat_irq_enable();
}
int lbat_service_init(struct platform_device *pdev)
{
int ret = 0;
pr_info("[%s]\n", __func__);
pmic_set_register_value(PMIC_AUXADC_LBAT_DEBT_MAX,
DEF_H_DEB / LBAT_PRD);
pmic_set_register_value(PMIC_AUXADC_LBAT_DEBT_MIN,
DEF_L_DEB / LBAT_PRD);
pmic_set_register_value(
PMIC_AUXADC_LBAT_DET_PRD_15_0,
LBAT_PRD);
pmic_set_register_value(
PMIC_AUXADC_LBAT_DET_PRD_19_16,
(LBAT_PRD & 0xF0000) >> 16);
ret = devm_request_threaded_irq(&pdev->dev,
platform_get_irq_byname(pdev, "bat_h"),
NULL, bat_h_int_handler, IRQF_TRIGGER_NONE,
"bat_h", NULL);
if (ret < 0)
dev_notice(&pdev->dev, "request bat_h irq fail\n");
ret = devm_request_threaded_irq(&pdev->dev,
platform_get_irq_byname(pdev, "bat_l"),
NULL, bat_l_int_handler, IRQF_TRIGGER_NONE,
"bat_l", NULL);
if (ret < 0)
dev_notice(&pdev->dev, "request bat_l irq fail\n");
lbat_wq = create_singlethread_workqueue("lbat_service");
return ret;
}
unsigned int lbat_read_raw(void)
{
return pmic_get_register_value(PMIC_AUXADC_ADC_OUT_LBAT);
}
unsigned int lbat_read_volt(void)
{
unsigned int raw_data = lbat_read_raw();
return RAW_TO_VOLT(raw_data);
}
/*
* Lbat service debug
*/
void lbat_dump_reg(void)
{
pr_notice("AUXADC_LBAT_VOLT_MAX = 0x%x, AUXADC_LBAT_VOLT_MIN = 0x%x, RG_INT_EN_BAT_H = %d, RG_INT_EN_BAT_L = %d\n"
, pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MIN)
, pmic_get_register_value(PMIC_RG_INT_EN_BAT_H)
, pmic_get_register_value(PMIC_RG_INT_EN_BAT_L));
pr_notice("AUXADC_LBAT_EN_MAX = %d, AUXADC_LBAT_IRQ_EN_MAX = %d, AUXADC_LBAT_EN_MIN = %d, AUXADC_LBAT_IRQ_EN_MIN = %d\n"
, pmic_get_register_value(PMIC_AUXADC_LBAT_EN_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_EN_MIN)
, pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MIN));
pr_notice("AUXADC_LBAT_DEBT_MAX=%d, AUXADC_LBAT_DEBT_MIN=%d\n"
, pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MIN));
}
static void lbat_dump_thd_list(struct seq_file *s)
{
unsigned int len = 0;
char str[128] = "";
struct lbat_thd_t *thd = NULL;
if (list_empty(&lbat_hv_list) && list_empty(&lbat_lv_list)) {
pr_notice("[%s] no entry in lbat list\n", __func__);
seq_puts(s, "no entry in lbat list\n");
return;
}
mutex_lock(&lbat_mutex);
list_for_each_entry(thd, &lbat_hv_list, list) {
len += snprintf(str + len, sizeof(str) - len,
"%shv_list, thd_volt:%d, user:%s\n",
(thd == cur_hv_ptr ||
thd == cur_lv_ptr) ? "->" : " ",
thd->thd_volt, thd->user->name);
pr_notice("%s", str);
seq_printf(s, "%s", str);
strncpy(str, "", strlen(str));
len = 0;
}
pr_notice("\n");
seq_puts(s, "\n");
list_for_each_entry(thd, &lbat_lv_list, list) {
len += snprintf(str + len, sizeof(str) - len,
"%slv_list, thd_volt:%d, user:%s\n",
(thd == cur_hv_ptr ||
thd == cur_lv_ptr) ? "->" : " ",
thd->thd_volt, thd->user->name);
pr_notice("%s", str);
seq_printf(s, "%s", str);
strncpy(str, "", strlen(str));
len = 0;
}
pr_notice("\n");
mutex_unlock(&lbat_mutex);
}
static void lbat_dbg_dump_reg(struct seq_file *s)
{
lbat_dump_reg();
seq_printf(s, "AUXADC_LBAT_VOLT_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MAX));
seq_printf(s, "AUXADC_LBAT_VOLT_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MIN));
seq_printf(s, "RG_INT_EN_BAT_H = 0x%x\n",
pmic_get_register_value(PMIC_RG_INT_EN_BAT_H));
seq_printf(s, "RG_INT_EN_BAT_L = 0x%x\n",
pmic_get_register_value(PMIC_RG_INT_EN_BAT_L));
seq_printf(s, "AUXADC_LBAT_EN_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_EN_MAX));
seq_printf(s, "AUXADC_LBAT_IRQ_EN_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MAX));
seq_printf(s, "AUXADC_LBAT_EN_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_EN_MIN));
seq_printf(s, "AUXADC_LBAT_IRQ_EN_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MIN));
seq_printf(s, "AUXADC_LBAT_DEBT_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MAX));
seq_printf(s, "AUXADC_LBAT_DEBT_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MIN));
seq_printf(s, "AUXADC_ADC_RDY_LBAT = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_ADC_RDY_LBAT));
seq_printf(s, "AUXADC_ADC_OUT_LBAT = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_ADC_OUT_LBAT));
}
static void lbat_dump_user_table(struct seq_file *s)
{
unsigned int i;
struct lbat_user *user;
mutex_lock(&lbat_mutex);
for (i = 0; i < user_count; i++) {
user = lbat_user_table[i];
seq_printf(s, "%2d:%20s, %d, %d, %d, (%d,%d,%d,%d), %pf\n",
i, user->name,
user->hv_thd->thd_volt,
user->lv1_thd->thd_volt, user->lv2_thd->thd_volt,
user->hv_deb_prd, user->hv_deb_times,
user->lv_deb_prd, user->lv_deb_times,
user->callback);
}
mutex_unlock(&lbat_mutex);
}
struct lbat_dbg_st {
unsigned int dbg_id;
};
enum {
LBAT_DBG_DUMP_LIST,
LBAT_DBG_DUMP_REG,
LBAT_DBG_DUMP_TABLE,
LBAT_DBG_MAX,
};
static struct lbat_dbg_st dbg_data[LBAT_DBG_MAX];
static int lbat_dbg_show(struct seq_file *s, void *unused)
{
struct lbat_dbg_st *dbg_st = s->private;
switch (dbg_st->dbg_id) {
case LBAT_DBG_DUMP_LIST:
lbat_dump_thd_list(s);
break;
case LBAT_DBG_DUMP_REG:
lbat_dbg_dump_reg(s);
break;
case LBAT_DBG_DUMP_TABLE:
lbat_dump_user_table(s);
break;
default:
break;
}
return 0;
}
static int lbat_dbg_open(struct inode *inode, struct file *file)
{
if (file->f_mode & FMODE_READ)
return single_open(file, lbat_dbg_show, inode->i_private);
file->private_data = inode->i_private;
return 0;
}
static ssize_t lbat_dbg_write(struct file *file,
const char __user *user_buffer, size_t count, loff_t *position)
{
return count;
}
static int lbat_dbg_release(struct inode *inode, struct file *file)
{
if (file->f_mode & FMODE_READ)
return single_release(inode, file);
return 0;
}
static const struct file_operations lbat_dbg_fops = {
.open = lbat_dbg_open,
.read = seq_read,
.write = lbat_dbg_write,
.llseek = seq_lseek,
.release = lbat_dbg_release,
};
int lbat_debug_init(struct dentry *debug_dir)
{
struct dentry *lbat_dbg_dir;
if (IS_ERR(debug_dir) || !debug_dir) {
pr_notice("dir mtk_pmic does not exist\n");
return -1;
}
lbat_dbg_dir = debugfs_create_dir("lbat_dbg", debug_dir);
if (IS_ERR(lbat_dbg_dir) || !lbat_dbg_dir) {
pr_notice("fail mkdir /sys/kernel/debug/mtk_pmic/lbat_dbg\n");
return -1;
}
/* lbat service debug init */
dbg_data[0].dbg_id = LBAT_DBG_DUMP_LIST;
/* file type is regular file(S_IFREG), permission is read(444) */
debugfs_create_file("lbat_dump_list", (S_IFREG | 0444),
lbat_dbg_dir, (void *)&dbg_data[0], &lbat_dbg_fops);
dbg_data[1].dbg_id = LBAT_DBG_DUMP_REG;
debugfs_create_file("lbat_dump_reg", (S_IFREG | 0444),
lbat_dbg_dir, (void *)&dbg_data[1], &lbat_dbg_fops);
dbg_data[2].dbg_id = LBAT_DBG_DUMP_TABLE;
debugfs_create_file("lbat_dump_table", (S_IFREG | 0444),
lbat_dbg_dir, (void *)&dbg_data[2], &lbat_dbg_fops);
return 0;
}
@@ -0,0 +1,784 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/list_sort.h>
#include <linux/dcache.h>
#include <linux/debugfs.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/pm_wakeup.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/of.h>
#include <mt-plat/upmu_common.h>
#include <include/pmic_lbat_service.h>
#define USER_SIZE 16
#define LBAT_SERVICE_DBG 0
static DEFINE_MUTEX(lbat_mutex);
static struct list_head lbat_hv_list = LIST_HEAD_INIT(lbat_hv_list);
static struct list_head lbat_lv_list = LIST_HEAD_INIT(lbat_lv_list);
/* workqueue for SW de-bounce */
static struct workqueue_struct *lbat_wq;
static unsigned int user_count;
enum lbat_thd_type {
LBAT_HV,
LBAT_LV,
};
struct lbat_thd_t {
unsigned int thd_volt;
struct lbat_user *user;
struct list_head list;
};
static struct lbat_thd_t *cur_hv_ptr;
static struct lbat_thd_t *cur_lv_ptr;
static struct lbat_user *lbat_user_table[USER_SIZE];
static unsigned int r_ratio[2];
static unsigned int VOLT_TO_RAW(unsigned int volt)
{
return (volt << 12) / (1800 * r_ratio[0] / r_ratio[1]);
}
static void lbat_max_en_setting(int en_val)
{
pmic_set_register_value(PMIC_AUXADC_LBAT_DET_MAX, en_val);
pmic_set_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MAX, en_val);
}
static void lbat_min_en_setting(int en_val)
{
pmic_set_register_value(PMIC_AUXADC_LBAT_DET_MIN, en_val);
pmic_set_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MIN, en_val);
}
static void lbat_irq_enable(void)
{
if (cur_hv_ptr != NULL)
lbat_max_en_setting(1);
if (cur_lv_ptr != NULL)
lbat_min_en_setting(1);
pmic_set_register_value(PMIC_AUXADC_LBAT_EN, 1);
}
static void lbat_irq_disable(void)
{
pmic_set_register_value(PMIC_AUXADC_LBAT_EN, 0);
lbat_max_en_setting(0);
lbat_min_en_setting(0);
}
static int hv_list_cmp(void *priv, struct list_head *a, struct list_head *b)
{
struct lbat_thd_t *thd_a, *thd_b;
thd_a = list_entry(a, struct lbat_thd_t, list);
thd_b = list_entry(b, struct lbat_thd_t, list);
return thd_a->thd_volt - thd_b->thd_volt;
}
static int lv_list_cmp(void *priv, struct list_head *a, struct list_head *b)
{
struct lbat_thd_t *thd_a, *thd_b;
thd_a = list_entry(a, struct lbat_thd_t, list);
thd_b = list_entry(b, struct lbat_thd_t, list);
return thd_b->thd_volt - thd_a->thd_volt;
}
static int modify_lbat_list(enum lbat_thd_type type,
struct lbat_thd_t *thd)
{
if (!thd)
return -EINVAL;
switch (type) {
case LBAT_HV:
list_move(&thd->list, &lbat_hv_list);
list_sort(NULL, &lbat_hv_list, hv_list_cmp);
thd = list_first_entry(&lbat_hv_list,
struct lbat_thd_t, list);
if (cur_hv_ptr != thd) {
cur_hv_ptr = thd;
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MAX,
VOLT_TO_RAW(cur_hv_ptr->thd_volt));
}
break;
case LBAT_LV:
list_move(&thd->list, &lbat_lv_list);
list_sort(NULL, &lbat_lv_list, lv_list_cmp);
thd = list_first_entry(&lbat_lv_list,
struct lbat_thd_t, list);
if (cur_lv_ptr != thd) {
cur_lv_ptr = thd;
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MIN,
VOLT_TO_RAW(cur_lv_ptr->thd_volt));
}
break;
}
return 0;
}
static inline int list_is_first(const struct list_head *list,
const struct list_head *head)
{
return list->prev == head;
}
/*
* After execute lbat_user's callback, set next thd node to wait event
*/
static void lbat_hv_set_next_thd(struct lbat_user *user, struct lbat_thd_t *thd)
{
/* restore user->thd_list */
list_move(&thd->list, &user->thd_list);
list_sort(NULL, &user->thd_list, lv_list_cmp);
/* HV is triggered */
if (!list_is_first(&thd->list, &user->thd_list)) /* Not first */
modify_lbat_list(LBAT_HV, list_prev_entry(thd, list));
if (!list_is_last(&thd->list, &user->thd_list)) /* Not last */
modify_lbat_list(LBAT_LV, list_next_entry(thd, list));
}
static void lbat_lv_set_next_thd(struct lbat_user *user, struct lbat_thd_t *thd)
{
/* restore user->thd_list */
list_move(&thd->list, &user->thd_list);
list_sort(NULL, &user->thd_list, lv_list_cmp);
/* LV is triggered */
if (!list_is_first(&thd->list, &user->thd_list)) /* Not first */
modify_lbat_list(LBAT_HV, list_prev_entry(thd, list));
if (!list_is_last(&thd->list, &user->thd_list)) /* Not last */
modify_lbat_list(LBAT_LV, list_next_entry(thd, list));
}
static void lbat_set_next_thd(struct lbat_user *user, struct lbat_thd_t *thd)
{
if (thd == user->hv_thd) {
modify_lbat_list(LBAT_LV, user->lv1_thd);
if (!list_empty(&user->lv2_thd->list))
list_del_init(&user->lv2_thd->list);
} else if (thd == user->lv1_thd) {
modify_lbat_list(LBAT_HV, user->hv_thd);
if (list_empty(&user->lv2_thd->list))
modify_lbat_list(LBAT_LV, user->lv2_thd);
}
}
/*
* Execute user's callback and set its next threshold if reach deb_times,
* otherwise ignore this event and reset lbat_list
*/
// workaround for mt6877
static void lbat_deb_handler(struct work_struct *work)
{
enum lbat_thd_type type;
unsigned int deb_times;
struct lbat_user *user =
container_of(work, struct lbat_user, deb_work);
mutex_lock(&lbat_mutex);
if (user->deb_thd_ptr == user->hv_thd) {
type = LBAT_HV;
deb_times = user->hv_deb_times;
} else {
type = LBAT_LV;
deb_times = user->lv_deb_times;
}
if (user->deb_cnt >= deb_times) {
/* execute user's callback after de-bounce */
user->callback(user->deb_thd_ptr->thd_volt);
lbat_set_next_thd(user, user->deb_thd_ptr);
} else {
/* ignore this event and reset lbat_list */
modify_lbat_list(type, user->deb_thd_ptr);
}
/* de-bounce done, reset deb_cnt and deb_thd_ptr */
user->deb_cnt = 0;
user->deb_thd_ptr = NULL;
lbat_irq_disable();
udelay(200);
lbat_irq_enable();
mutex_unlock(&lbat_mutex);
}
//static void lbat_timer_func(unsigned long data)
static void lbat_timer_func(struct timer_list *t)
{
unsigned int deb_prd = 0;
unsigned int deb_times = 0;
// struct lbat_user *user = (struct lbat_user *)data;
struct lbat_user *user = from_timer(user, t, deb_timer);
if (user->deb_thd_ptr == user->hv_thd) {
/* LBAT user HV de-bounce */
if (lbat_read_volt() < user->deb_thd_ptr->thd_volt) {
/* queue deb_work to reset lbat_list */
goto wq_handler;
}
deb_prd = user->hv_deb_prd;
deb_times = user->hv_deb_times;
} else if (user->deb_thd_ptr == user->lv1_thd ||
user->deb_thd_ptr == user->lv2_thd) {
/* LBAT user LV de-bounce */
if (lbat_read_volt() > user->deb_thd_ptr->thd_volt) {
/* queue deb_work to reset lbat_list */
goto wq_handler;
}
deb_prd = user->lv_deb_prd;
deb_times = user->lv_deb_times;
} else {
pr_notice("[%s] LBAT de-bounce threshold not match\n",
__func__);
return;
}
user->deb_cnt++;
#if LBAT_SERVICE_DBG
pr_info("[%s] name:%s, thd_volt:%d, de-bounce times:%d\n",
__func__, user->name,
user->deb_thd_ptr->thd_volt, user->deb_cnt);
#endif
if (user->deb_cnt < deb_times) {
mod_timer(&user->deb_timer,
jiffies + msecs_to_jiffies(deb_prd));
return;
}
wq_handler:
/* queue deb_work to execute user's callback or reset lbat_list */
queue_work(lbat_wq, &user->deb_work);
}
static void lbat_user_init_timer(struct lbat_user *user)
{
user->deb_cnt = 0;
user->hv_deb_prd = 0;
user->hv_deb_times = 0;
user->lv_deb_prd = 0;
user->lv_deb_times = 0;
//init_timer(&user->deb_timer);
//user->deb_timer.data = (unsigned long)user;
//user->deb_timer.expires = 0;
//user->deb_timer.function = lbat_timer_func;
timer_setup(&user->deb_timer, lbat_timer_func, 0);
}
static int lbat_user_update(struct lbat_user *user)
{
struct lbat_thd_t *thd;
/*
* add lv_thd to lbat_lv_list
* and assign first entry of lv_list to cur_lv_ptr
*/
if (list_empty(&user->thd_list))
thd = user->lv1_thd;
else {
thd = list_first_entry(&user->thd_list,
struct lbat_thd_t, list);
thd = list_next_entry(thd, list);
}
modify_lbat_list(LBAT_LV, thd);
if (user_count == 0)
lbat_irq_enable();
lbat_user_table[user_count++] = user;
return 0;
}
static struct lbat_thd_t *lbat_thd_init(unsigned int thd_volt,
struct lbat_user *user)
{
struct lbat_thd_t *thd = NULL;
if (thd_volt == 0)
return NULL;
thd = kzalloc(sizeof(*thd), GFP_KERNEL);
if (thd == NULL)
return NULL;
thd->thd_volt = thd_volt;
thd->user = user;
INIT_LIST_HEAD(&thd->list);
return thd;
}
struct lbat_user *lbat_user_register_ext(const char *name,
unsigned int *thd_volt_arr, unsigned int thd_volt_size,
void (*callback)(unsigned int thd_volt))
{
int i, ret;
struct lbat_thd_t *thd;
struct lbat_user *user;
mutex_lock(&lbat_mutex);
user = kzalloc(sizeof(*user), GFP_KERNEL);
if (user == NULL) {
ret = -10;
goto out;
}
strncpy(user->name, name, ARRAY_SIZE(user->name) - 1);
if (thd_volt_arr[0] >= 5400 || thd_volt_arr[thd_volt_size - 1] <= 2000) {
ret = -EINVAL;
goto out;
} else if (callback == NULL) {
ret = -EINVAL;
goto out;
}
INIT_LIST_HEAD(&user->thd_list);
thd = lbat_thd_init(thd_volt_arr[0], user);
for (i = 0; i < thd_volt_size; i++) {
thd = lbat_thd_init(thd_volt_arr[i], user);
list_add_tail(&thd->list, &user->thd_list);
}
user->callback = callback;
lbat_user_init_timer(user);
INIT_WORK(&user->deb_work, lbat_deb_handler);
pr_info("[%s] name=%s, thd_volt_max=%d, thd_volt_min=%d\n", __func__,
user->name, thd_volt_arr[0], thd_volt_arr[thd_volt_size - 1]);
ret = lbat_user_update(user);
out:
if (ret)
pr_notice("[%s] error ret=%d\n", __func__, ret);
mutex_unlock(&lbat_mutex);
return user;
}
EXPORT_SYMBOL(lbat_user_register_ext);
struct lbat_user *lbat_user_register(const char *name,
unsigned int hv_thd_volt,
unsigned int lv1_thd_volt, unsigned int lv2_thd_volt,
void (*callback)(unsigned int thd_volt))
{
int ret = 0;
struct lbat_user *user;
mutex_lock(&lbat_mutex);
user = kzalloc(sizeof(*user), GFP_KERNEL);
if (user == NULL) {
ret = -10;
goto out;
}
strncpy(user->name, name, ARRAY_SIZE(user->name) - 1);
if (hv_thd_volt >= 5400 || lv1_thd_volt <= 2650) {
ret = -11;
goto out;
} else if (hv_thd_volt < lv1_thd_volt ||
lv1_thd_volt < lv2_thd_volt) {
ret = -12;
goto out;
} else if (callback == NULL) {
ret = -13;
goto out;
}
INIT_LIST_HEAD(&user->thd_list);
user->hv_thd = lbat_thd_init(hv_thd_volt, user);
user->lv1_thd = lbat_thd_init(lv1_thd_volt, user);
user->lv2_thd = lbat_thd_init(lv2_thd_volt, user);
user->callback = callback;
lbat_user_init_timer(user);
INIT_WORK(&user->deb_work, lbat_deb_handler);
pr_info("[%s] name=%s, hv=%d, lv1=%d, lv2=%d\n",
__func__, name, hv_thd_volt, lv1_thd_volt, lv2_thd_volt);
ret = lbat_user_update(user);
out:
if (ret)
pr_notice("[%s] error ret=%d\n", __func__, ret);
mutex_unlock(&lbat_mutex);
return user;
}
EXPORT_SYMBOL(lbat_user_register);
int lbat_user_set_debounce(struct lbat_user *user,
unsigned int hv_deb_prd, unsigned int hv_deb_times,
unsigned int lv_deb_prd, unsigned int lv_deb_times)
{
if (IS_ERR(user))
return PTR_ERR(user);
user->hv_deb_prd = hv_deb_prd;
user->hv_deb_times = hv_deb_times;
user->lv_deb_prd = lv_deb_prd;
user->lv_deb_times = lv_deb_times;
return 0;
}
EXPORT_SYMBOL(lbat_user_set_debounce);
static irqreturn_t bat_h_int_handler(int irq, void *data)
{
struct lbat_user *user = NULL;
if (cur_hv_ptr == NULL) {
lbat_max_en_setting(0);
return IRQ_NONE;
}
mutex_lock(&lbat_mutex);
pr_info("[%s] cur_thd_volt=%d\n", __func__, cur_hv_ptr->thd_volt);
user = cur_hv_ptr->user;
list_del_init(&cur_hv_ptr->list);
if (user->hv_deb_times) {
user->deb_cnt = 0;
user->deb_thd_ptr = cur_hv_ptr;
mod_timer(&user->deb_timer,
jiffies + msecs_to_jiffies(user->hv_deb_prd));
} else {
user->callback(cur_hv_ptr->thd_volt);
if (list_empty(&user->thd_list))
lbat_set_next_thd(user, cur_hv_ptr);
else
lbat_hv_set_next_thd(user, cur_hv_ptr);
}
/* Since cur_hv_ptr is removed, assign new thd for cur_hv_ptr */
if (list_empty(&lbat_hv_list)) {
cur_hv_ptr = NULL;
goto out;
}
cur_hv_ptr = list_first_entry(
&lbat_hv_list, struct lbat_thd_t, list);
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MAX,
VOLT_TO_RAW(cur_hv_ptr->thd_volt));
out:
lbat_irq_disable();
udelay(200);
lbat_irq_enable();
mutex_unlock(&lbat_mutex);
return IRQ_HANDLED;
}
static irqreturn_t bat_l_int_handler(int irq, void *data)
{
struct lbat_user *user = NULL;
if (cur_lv_ptr == NULL) {
lbat_min_en_setting(0);
return IRQ_NONE;
}
mutex_lock(&lbat_mutex);
pr_info("[%s] cur_thd_volt=%d\n", __func__, cur_lv_ptr->thd_volt);
user = cur_lv_ptr->user;
list_del_init(&cur_lv_ptr->list);
if (user->lv_deb_times) {
user->deb_cnt = 0;
user->deb_thd_ptr = cur_lv_ptr;
mod_timer(&user->deb_timer,
jiffies + msecs_to_jiffies(user->lv_deb_prd));
} else {
user->callback(cur_lv_ptr->thd_volt);
if (list_empty(&user->thd_list))
lbat_set_next_thd(user, cur_lv_ptr);
else
lbat_lv_set_next_thd(user, cur_lv_ptr);
}
/* Since cur_lv_ptr is removed, assign new thd for cur_lv_ptr */
if (list_empty(&lbat_lv_list)) {
cur_lv_ptr = NULL;
goto out;
}
cur_lv_ptr = list_first_entry(
&lbat_lv_list, struct lbat_thd_t, list);
pmic_set_register_value(PMIC_AUXADC_LBAT_VOLT_MIN,
VOLT_TO_RAW(cur_lv_ptr->thd_volt));
out:
lbat_irq_disable();
udelay(200);
lbat_irq_enable();
mutex_unlock(&lbat_mutex);
return IRQ_HANDLED;
}
void lbat_suspend(void)
{
lbat_irq_disable();
}
void lbat_resume(void)
{
lbat_irq_enable();
}
int lbat_service_init(struct platform_device *pdev)
{
int ret = 0;
struct device_node *np = NULL;
pr_info("[%s]\n", __func__);
/* Selects debounce as 8 */
pmic_set_register_value(PMIC_AUXADC_LBAT_DEBT_MAX_SEL, 3);
/* Selects debounce as 1 */
pmic_set_register_value(PMIC_AUXADC_LBAT_DEBT_MIN_SEL, 0);
/* Set LBAT_PRD as 15ms */
pmic_set_register_value(PMIC_AUXADC_LBAT_DET_PRD_SEL, 0);
ret = devm_request_threaded_irq(&pdev->dev,
platform_get_irq_byname(pdev, "bat_h"),
NULL, bat_h_int_handler, IRQF_TRIGGER_NONE,
"bat_h", NULL);
if (ret < 0)
dev_notice(&pdev->dev, "request bat_h irq fail\n");
ret = devm_request_threaded_irq(&pdev->dev,
platform_get_irq_byname(pdev, "bat_l"),
NULL, bat_l_int_handler, IRQF_TRIGGER_NONE,
"bat_l", NULL);
if (ret < 0)
dev_notice(&pdev->dev, "request bat_l irq fail\n");
lbat_wq = create_singlethread_workqueue("lbat_service");
/* get LBAT r_ratio */
np = of_find_node_by_name(NULL, "batadc");
if (!np) {
pr_notice("[%s] get batadc node fail\n", __func__);
r_ratio[0] = 7;
r_ratio[1] = 2;
return 0;
}
ret = of_property_read_u32_array(np, "resistance-ratio", r_ratio, 2);
pr_info("[%s] r_ratio = %d/%d\n", __func__, r_ratio[0], r_ratio[1]);
return ret;
}
unsigned int lbat_read_raw(void)
{
return pmic_get_register_value(PMIC_AUXADC_ADC_OUT_LBAT);
}
unsigned int lbat_read_volt(void)
{
unsigned int raw_data = lbat_read_raw();
return (raw_data * 1800 * r_ratio[0] / r_ratio[1]) >> 12;
}
/*
* Lbat service debug
*/
void lbat_dump_reg(void)
{
pr_notice("AUXADC_LBAT_VOLT_MAX = 0x%x, AUXADC_LBAT_VOLT_MIN = 0x%x, RG_INT_EN_BAT_H = %d, RG_INT_EN_BAT_L = %d\n"
, pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MIN)
, pmic_get_register_value(PMIC_RG_INT_EN_BAT_H)
, pmic_get_register_value(PMIC_RG_INT_EN_BAT_L));
pr_notice("AUXADC_LBAT_EN = %d, AUXADC_LBAT_DET_MAX = %d, AUXADC_LBAT_IRQ_EN_MAX = %d, AUXADC_LBAT_DET_MIN = %d, AUXADC_LBAT_IRQ_EN_MIN = %d\n"
, pmic_get_register_value(PMIC_AUXADC_LBAT_EN)
, pmic_get_register_value(PMIC_AUXADC_LBAT_DET_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MAX)
, pmic_get_register_value(PMIC_AUXADC_LBAT_DET_MIN)
, pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MIN));
pr_notice("AUXADC_LBAT_DEBT_MAX_SEL=%d, AUXADC_LBAT_DEBT_MIN_SEL=%d\n"
, pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MAX_SEL)
, pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MIN_SEL));
}
static void lbat_dump_thd_list(struct seq_file *s)
{
unsigned int len = 0;
char str[128] = "";
struct lbat_thd_t *thd = NULL;
if (list_empty(&lbat_hv_list) && list_empty(&lbat_lv_list)) {
pr_notice("[%s] no entry in lbat list\n", __func__);
seq_puts(s, "no entry in lbat list\n");
return;
}
mutex_lock(&lbat_mutex);
list_for_each_entry(thd, &lbat_hv_list, list) {
len += snprintf(str + len, sizeof(str) - len,
"%shv_list, thd_volt:%d, user:%s\n",
(thd == cur_hv_ptr ||
thd == cur_lv_ptr) ? "->" : " ",
thd->thd_volt, thd->user->name);
pr_notice("%s", str);
seq_printf(s, "%s", str);
strncpy(str, "", strlen(str));
len = 0;
}
pr_notice("\n");
seq_puts(s, "\n");
list_for_each_entry(thd, &lbat_lv_list, list) {
len += snprintf(str + len, sizeof(str) - len,
"%slv_list, thd_volt:%d, user:%s\n",
(thd == cur_hv_ptr ||
thd == cur_lv_ptr) ? "->" : " ",
thd->thd_volt, thd->user->name);
pr_notice("%s", str);
seq_printf(s, "%s", str);
strncpy(str, "", strlen(str));
len = 0;
}
pr_notice("\n");
mutex_unlock(&lbat_mutex);
}
static void lbat_dbg_dump_reg(struct seq_file *s)
{
lbat_dump_reg();
seq_printf(s, "AUXADC_LBAT_VOLT_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MAX));
seq_printf(s, "AUXADC_LBAT_VOLT_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_VOLT_MIN));
seq_printf(s, "RG_INT_EN_BAT_H = 0x%x\n",
pmic_get_register_value(PMIC_RG_INT_EN_BAT_H));
seq_printf(s, "RG_INT_EN_BAT_L = 0x%x\n",
pmic_get_register_value(PMIC_RG_INT_EN_BAT_L));
seq_printf(s, "AUXADC_LBAT_EN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_EN));
seq_printf(s, "AUXADC_LBAT_DET_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_DET_MAX));
seq_printf(s, "AUXADC_LBAT_IRQ_EN_MAX = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MAX));
seq_printf(s, "AUXADC_LBAT_DET_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_DET_MIN));
seq_printf(s, "AUXADC_LBAT_IRQ_EN_MIN = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_IRQ_EN_MIN));
seq_printf(s, "AUXADC_LBAT_DEBT_MAX_SEL = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MAX_SEL));
seq_printf(s, "AUXADC_LBAT_DEBT_MIN_SEL = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_LBAT_DEBT_MIN_SEL));
seq_printf(s, "AUXADC_ADC_RDY_LBAT = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_ADC_RDY_LBAT));
seq_printf(s, "AUXADC_ADC_OUT_LBAT = 0x%x\n",
pmic_get_register_value(PMIC_AUXADC_ADC_OUT_LBAT));
}
static void lbat_dump_user_table(struct seq_file *s)
{
unsigned int i = 0;
struct lbat_user *user = NULL;
struct lbat_thd_t *thd = NULL;
mutex_lock(&lbat_mutex);
for (i = 0; i < user_count; i++) {
user = lbat_user_table[i];
if (list_empty(&user->thd_list)) {
seq_printf(s,
"%2d:%20s, %d, %d, %d, (%d,%d,%d,%d), %pf\n",
i, user->name,
user->hv_thd->thd_volt,
user->lv1_thd->thd_volt,
user->lv2_thd->thd_volt,
user->hv_deb_prd, user->hv_deb_times,
user->lv_deb_prd, user->lv_deb_times,
user->callback);
} else {
seq_printf(s, "%2d:%20s,", i, user->name);
list_for_each_entry(thd, &user->thd_list, list) {
seq_printf(s, " %d,", thd->thd_volt);
}
seq_printf(s, " %pf\n", user->callback);
}
}
mutex_unlock(&lbat_mutex);
}
struct lbat_dbg_st {
unsigned int dbg_id;
};
enum {
LBAT_DBG_DUMP_LIST,
LBAT_DBG_DUMP_REG,
LBAT_DBG_DUMP_TABLE,
LBAT_DBG_MAX,
};
static struct lbat_dbg_st dbg_data[LBAT_DBG_MAX];
static int lbat_dbg_show(struct seq_file *s, void *unused)
{
struct lbat_dbg_st *dbg_st = s->private;
switch (dbg_st->dbg_id) {
case LBAT_DBG_DUMP_LIST:
lbat_dump_thd_list(s);
break;
case LBAT_DBG_DUMP_REG:
lbat_dbg_dump_reg(s);
break;
case LBAT_DBG_DUMP_TABLE:
lbat_dump_user_table(s);
break;
default:
break;
}
return 0;
}
static int lbat_dbg_open(struct inode *inode, struct file *file)
{
if (file->f_mode & FMODE_READ)
return single_open(file, lbat_dbg_show, inode->i_private);
file->private_data = inode->i_private;
return 0;
}
static ssize_t lbat_dbg_write(struct file *file,
const char __user *user_buffer, size_t count, loff_t *position)
{
return count;
}
static int lbat_dbg_release(struct inode *inode, struct file *file)
{
if (file->f_mode & FMODE_READ)
return single_release(inode, file);
return 0;
}
static const struct file_operations lbat_dbg_fops = {
.open = lbat_dbg_open,
.read = seq_read,
.write = lbat_dbg_write,
.llseek = seq_lseek,
.release = lbat_dbg_release,
};
int lbat_debug_init(struct dentry *debug_dir)
{
struct dentry *lbat_dbg_dir = NULL;
if (IS_ERR(debug_dir) || !debug_dir) {
pr_notice("dir mtk_pmic does not exist\n");
return -1;
}
lbat_dbg_dir = debugfs_create_dir("lbat_dbg", debug_dir);
if (IS_ERR(lbat_dbg_dir) || !lbat_dbg_dir) {
pr_notice("fail mkdir /sys/kernel/debug/mtk_pmic/lbat_dbg\n");
return -1;
}
/* lbat service debug init */
dbg_data[0].dbg_id = LBAT_DBG_DUMP_LIST;
/* file type is regular file(S_IFREG), permission is read(444) */
debugfs_create_file("lbat_dump_list", (S_IFREG | 0444),
lbat_dbg_dir, (void *)&dbg_data[0], &lbat_dbg_fops);
dbg_data[1].dbg_id = LBAT_DBG_DUMP_REG;
debugfs_create_file("lbat_dump_reg", (S_IFREG | 0444),
lbat_dbg_dir, (void *)&dbg_data[1], &lbat_dbg_fops);
dbg_data[2].dbg_id = LBAT_DBG_DUMP_TABLE;
debugfs_create_file("lbat_dump_table", (S_IFREG | 0444),
lbat_dbg_dir, (void *)&dbg_data[2], &lbat_dbg_fops);
return 0;
}
@@ -0,0 +1,813 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <generated/autoconf.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/debugfs.h>
#include <linux/syscalls.h>
#include <linux/writeback.h>
#include <linux/seq_file.h>
#include <linux/suspend.h>
#include <linux/uaccess.h>
#include <mt-plat/upmu_common.h>
#include "include/pmic_regulator.h"
#include "include/regulator_codegen.h"
/*****************************************************************************
* Global variable
******************************************************************************/
/*****************************************************************************
* PMIC BUCK/LDO info for EM
******************************************************************************/
static ssize_t show_buck_ldo_info(struct device *dev,
struct device_attribute *attr,
char *buf)
{
unsigned short i;
unsigned int len = 0;
pr_info("[%s]\n", __func__);
for (i = 0; i < mt_bucks_size; i++)
len += snprintf(buf + len, PAGE_SIZE, "%s,0/1=off/on\n"
, mt_bucks[i].en_att.attr.name);
len += snprintf(buf + len, PAGE_SIZE, "SEP\n");
for (i = 0; i < mt_ldos_size; i++)
len += snprintf(buf + len, PAGE_SIZE, "%s,0/1=off/on\n"
, mt_ldos[i].en_att.attr.name);
len += snprintf(buf + len, PAGE_SIZE, "SEP\n");
for (i = 0; i < mt_bucks_size; i++)
len += snprintf(buf + len, PAGE_SIZE, "%s,mv\n"
, mt_bucks[i].voltage_att.attr.name);
len += snprintf(buf + len, PAGE_SIZE, "SEP\n");
for (i = 0; i < mt_ldos_size; i++)
len += snprintf(buf + len, PAGE_SIZE, "%s,mv\n"
, mt_ldos[i].voltage_att.attr.name);
return len;
}
/* 444 no write permission */
static DEVICE_ATTR(buck_ldo_info, 0444, show_buck_ldo_info, NULL);
/*****************************************************************************
* PMIC6355 linux reguplator driver
******************************************************************************/
#ifdef REGULATOR_TEST
unsigned int g_buck_uV;
static ssize_t show_buck_api(struct device *dev,
struct device_attribute *attr,
char *buf)
{
pr_info("[%s] 0x%x\n", __func__, g_buck_uV);
return sprintf(buf, "%u\n", g_buck_uV);
}
static ssize_t store_buck_api(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t size)
{
/*PMICLOG("[EM] Not Support Write Function\n");*/
int ret = 0;
char *pvalue = NULL, *addr = NULL, *val = NULL;
unsigned int buck_uV = 0;
unsigned int buck_type = 0;
pr_info("[%s]\n", __func__);
if (buf != NULL && size != 0) {
pr_info("[%s] buf is %s\n", __func__, buf);
/*buck_type = simple_strtoul(buf, &pvalue, 16);*/
pvalue = (char *)buf;
if (size > 5) {
addr = strsep(&pvalue, " ");
if (addr)
ret = kstrtou32(addr, 10,
(unsigned int *)&buck_type);
} else
ret = kstrtou32(pvalue, 10, (unsigned int *)&buck_type);
if (buck_type == 9999) {
pr_info("[%s] regulator_test!\n", __func__);
pmic_regulator_en_test();
#if 0
pmic_regulator_vol_test();
#endif
} else {
if (size > 5) {
val = strsep(&pvalue, " ");
if (val)
ret = kstrtou32(val, 10,
(unsigned int *)&buck_uV);
pr_info("[%s] write buck_type[%d] with voltgae %d !\n"
, __func__, buck_type, buck_uV);
/* only for regulator test*/
/* ret=buck_set_voltage(buck_type, buck_uV); */
} else {
pr_info("[%s] use \"cat pmic_access\" to get value(decimal)\r\n"
, __func__);
}
}
}
return size;
}
/*664*/
static DEVICE_ATTR(buck_api, 0664, show_buck_api, store_buck_api);
#endif /*--REGULATOR_TEST--*/
/*****************************************************************************
* PMIC extern variable
******************************************************************************/
struct platform_device mt_pmic_device = {
.name = "pmic_regulator",
.id = -1,
};
static const struct platform_device_id pmic_regulator_id[] = {
{"pmic_regulator", 0},
{},
};
static int pmic_regulator_cust_dts_parser(struct platform_device *pdev,
struct device_node *regulators)
{
struct device_node *child = NULL;
int ret = 0;
unsigned int i = 0, default_on = 0;
if (!regulators) {
PMICLOG("[PMIC]%s regulators node not found\n", __func__);
return -ENODEV;
}
for_each_child_of_node(regulators, child) {
for (i = 0; i < pmic_regulator_ldo_matches_size; i++) {
/* compare dt name & ldos name */
if (!of_node_cmp(child->name,
pmic_regulator_ldo_matches[i].name)) {
PMICLOG("[PMIC]%s regulator_matches %s\n"
, child->name
, (char *)of_get_property(child,
"regulator-name", NULL));
break;
}
}
if (i == pmic_regulator_ldo_matches_size)
continue;
/* check regualtors and set it */
if (!of_property_read_u32(child, "regulator-default-on"
, &default_on)) {
switch (default_on) {
case 0:
/* skip */
PMICLOG("[PMIC]%s regulator_skip %s\n"
, child->name
, pmic_regulator_ldo_matches[i].name);
break;
case 1:
/* turn ldo off */
(mt_ldos[i].en_cb)(0);
PMICLOG("[PMIC]%s default is off\n"
, (char *)of_get_property(child,
"regulator-name", NULL));
break;
case 2:
/* turn ldo on */
(mt_ldos[i].en_cb)(1);
PMICLOG("[PMIC]%s default is on\n"
, (char *)of_get_property(child,
"regulator-name", NULL));
break;
default:
break;
}
}
}
PMICLOG("[PMIC]%s done\n", __func__);
return ret;
}
static int pmic_regulator_buck_dts_parser(struct platform_device *pdev,
struct device_node *np)
{
struct device_node *buck_regulators = NULL;
struct regulator_config config = {};
struct regulator_dev *rdev = NULL;
struct regulation_constraints *c = NULL;
int matched, i = 0, ret = 0;
#ifdef REGULATOR_TEST
int isEn;
#endif /*--REGULATOR_TEST--*/
buck_regulators = of_get_child_by_name(np, "buck_regulators");
if (!buck_regulators) {
pr_info("[PMIC]regulators node not found\n");
return -EINVAL;
}
matched = of_regulator_match(&pdev->dev, buck_regulators,
pmic_regulator_buck_matches,
pmic_regulator_buck_matches_size);
if ((matched < 0) || (matched != mt_bucks_size)) {
pr_info("[PMIC]Error parsing regulator init data: %d %d\n",
matched, mt_bucks_size);
ret = -matched;
goto out;
}
for (i = 0; i < pmic_regulator_buck_matches_size; i++) {
if (mt_bucks[i].isUsedable != 1)
continue;
#if 1
config.dev = &(pdev->dev);
config.init_data = pmic_regulator_buck_matches[i].init_data;
config.of_node = pmic_regulator_buck_matches[i].of_node;
config.driver_data = &(mt_bucks[i]);
mt_bucks[i].desc.owner = THIS_MODULE;
rdev = regulator_register(&mt_bucks[i].desc, &config);
if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
pr_notice("[regulator_register] failed to register %s (%d)\n"
, mt_bucks[i].desc.name, ret);
continue;
} else
PMICLOG("[regulator_register] pass %s\n"
, mt_bucks[i].desc.name);
c = rdev->constraints;
c->valid_ops_mask |= mt_bucks[i].constraints.valid_ops_mask;
c->valid_modes_mask |= mt_bucks[i].constraints.valid_modes_mask;
#else
mt_bucks[i].config.dev = &(pdev->dev);
mt_bucks[i].config.init_data =
pmic_regulator_buck_matches[i].init_data;
mt_bucks[i].config.of_node =
pmic_regulator_buck_matches[i].of_node;
mt_bucks[i].config.driver_data =
pmic_regulator_buck_matches[i].driver_data;
mt_bucks[i].desc.owner = THIS_MODULE;
mt_bucks[i].rdev =
regulator_register(&mt_bucks[i].desc,
&mt_bucks[i].config);
if (IS_ERR(mt_bucks[i].rdev)) {
ret = PTR_ERR(mt_bucks[i].rdev);
pr_notice("[regulator_register] failed to register %s (%d)\n"
, mt_bucks[i].desc.name, ret);
continue;
} else
PMICLOG("[regulator_register] pass %s\n"
, mt_bucks[i].desc.name);
#endif
#ifdef REGULATOR_TEST
mt_bucks[i].reg = regulator_get(&(pdev->dev)
, mt_bucks[i].desc.name);
isEn = regulator_is_enabled(mt_bucks[i].reg);
if (isEn != 0)
PMICLOG("[regulator] %s is default on\n"
, mt_bucks[i].desc.name);
#endif /*--REGULATOR_TEST--*/
}
out:
of_node_put(buck_regulators);
return ret;
}
static int pmic_regulator_ldo_dts_parser(struct platform_device *pdev,
struct device_node *np)
{
struct device_node *ldo_regulators = NULL;
struct regulator_config config = {};
struct regulator_dev *rdev = NULL;
int matched, i = 0, ret = 0;
#ifdef REGULATOR_TEST
int isEn;
#endif /*--REGULATOR_TEST--*/
ldo_regulators = of_get_child_by_name(np, "ldo_regulators");
if (!ldo_regulators) {
pr_info("[PMIC]regulators node not found\n");
return -EINVAL;
}
matched = of_regulator_match(&pdev->dev, ldo_regulators,
pmic_regulator_ldo_matches,
pmic_regulator_ldo_matches_size);
if ((matched < 0) || (matched != mt_ldos_size)) {
pr_info("[PMIC]Error parsing regulator init data: %d %d\n",
matched, mt_ldos_size);
ret = -matched;
goto out;
}
for (i = 0; i < pmic_regulator_ldo_matches_size; i++) {
if (mt_ldos[i].isUsedable != 1)
continue;
#if 1
config.dev = &(pdev->dev);
config.init_data = pmic_regulator_ldo_matches[i].init_data;
config.of_node = pmic_regulator_ldo_matches[i].of_node;
config.driver_data = pmic_regulator_ldo_matches[i].driver_data;
mt_ldos[i].desc.owner = THIS_MODULE;
rdev = regulator_register(&mt_ldos[i].desc, &config);
if (IS_ERR(rdev)) {
ret = PTR_ERR(rdev);
pr_notice("[regulator_register] failed to register %s (%d)\n"
, mt_ldos[i].desc.name, ret);
continue;
} else {
PMICLOG("[regulator_register] pass %s\n"
, mt_ldos[i].desc.name);
}
#else
mt_ldos[i].config.dev = &(pdev->dev);
mt_ldos[i].config.init_data =
pmic_regulator_ldo_matches[i].init_data;
mt_ldos[i].config.of_node =
pmic_regulator_ldo_matches[i].of_node;
mt_ldos[i].config.driver_data =
pmic_regulator_ldo_matches[i].driver_data;
mt_ldos[i].desc.owner = THIS_MODULE;
mt_ldos[i].rdev =
regulator_register(&mt_ldos[i].desc,
&mt_ldos[i].config);
if (IS_ERR(mt_ldos[i].rdev)) {
ret = PTR_ERR(mt_ldos[i].rdev);
pr_notice("[regulator_register] failed to register %s (%d)\n"
, mt_ldos[i].desc.name, ret);
continue;
} else {
PMICLOG("[regulator_register] pass %s\n"
, mt_ldos[i].desc.name);
}
#endif
#ifdef REGULATOR_TEST
mt_ldos[i].reg = regulator_get(&(pdev->dev),
mt_ldos[i].desc.name);
isEn = regulator_is_enabled(mt_ldos[i].reg);
if (isEn != 0)
PMICLOG("[regulator] %s is default on\n"
, mt_ldos[i].desc.name);
#endif /*--REGULATOR_TEST--*/
/* To initialize varriables which were used to record status, */
/* if ldo regulator have been modified by user. */
/* mt_ldos[i].vosel.ldo_user = mt_ldos[i].rdev->use_count; */
if (mt_ldos[i].da_vol_cb != NULL)
mt_ldos[i].vosel.def_sel = (mt_ldos[i].da_vol_cb)();
mt_ldos[i].vosel.cur_sel = mt_ldos[i].vosel.def_sel;
}
/*--for ldo customization--*/
ret = pmic_regulator_cust_dts_parser(pdev, ldo_regulators);
if (ret) {
pr_info("pmic_regulator_cust_dts_parser fail\n");
ret = -EINVAL;
goto out;
}
out:
of_node_put(ldo_regulators);
return ret;
}
static int pmic_regulator_init(struct platform_device *pdev)
{
struct device_node *np;
int ret = 0;
np = pdev->dev.of_node;
if (!np) {
pr_info("%s np = NULL\n", __func__);
return -EINVAL;
}
ret = pmic_regulator_buck_dts_parser(pdev, np);
if (ret) {
pr_info("pmic_regulator_buck_dts_parser fail\n");
ret = -EINVAL;
goto out;
}
ret = pmic_regulator_ldo_dts_parser(pdev, np);
if (ret) {
pr_info("pmic_regulator_ldo_dts_parser fail\n");
ret = -EINVAL;
goto out;
}
out:
of_node_put(np);
return ret;
}
void pmic_regulator_suspend(void)
{
int i;
for (i = 0; i < mt_ldos_size; i++) {
if (mt_ldos[i].isUsedable == 1) {
if (mt_ldos[i].da_vol_cb != NULL) {
mt_ldos[i].vosel.cur_sel =
(mt_ldos[i].da_vol_cb)();
if (mt_ldos[i].vosel.cur_sel !=
mt_ldos[i].vosel.def_sel) {
mt_ldos[i].vosel.restore = true;
pr_info("%s(name=%s id=%d default_sel=%d current_sel=%d)\n"
, __func__
, mt_ldos[i].rdev->desc->name
, mt_ldos[i].rdev->desc->id
, mt_ldos[i].vosel.def_sel
, mt_ldos[i].vosel.cur_sel);
} else
mt_ldos[i].vosel.restore = false;
}
}
}
}
void pmic_regulator_resume(void)
{
int i, selector;
for (i = 0; i < mt_ldos_size; i++) {
if (mt_ldos[i].isUsedable == 1) {
if (mt_ldos[i].vol_cb != NULL) {
if (mt_ldos[i].vosel.restore == true) {
/*-- regulator voltage changed? --*/
selector = mt_ldos[i].vosel.cur_sel;
(mt_ldos[i].vol_cb)(selector);
pr_info("%s(name=%s id=%d default_sel=%d current_sel=%d)\n"
, __func__
, mt_ldos[i].rdev->desc->name
, mt_ldos[i].rdev->desc->id
, mt_ldos[i].vosel.def_sel
, mt_ldos[i].vosel.cur_sel);
}
}
}
}
}
static int pmic_regulator_pm_event(struct notifier_block *notifier,
unsigned long pm_event,
void *unused)
{
switch (pm_event) {
case PM_HIBERNATION_PREPARE: /* Going to hibernate */
pr_info("[%s] pm_event %lu (IPOH)\n", __func__, pm_event);
return NOTIFY_DONE;
case PM_POST_HIBERNATION: /* Hibernation finished */
pr_info("[%s] pm_event %lu\n", __func__, pm_event);
pmic_regulator_resume();
return NOTIFY_DONE;
}
return NOTIFY_OK;
}
static struct notifier_block pmic_regulator_pm_notifier_block = {
.notifier_call = pmic_regulator_pm_event,
.priority = 0,
};
int mtk_regulator_init(struct platform_device *dev)
{
int ret = 0;
#ifdef CONFIG_OF
pmic_regulator_init(dev);
#endif
ret = register_pm_notifier(&pmic_regulator_pm_notifier_block);
if (ret) {
PMICLOG("****failed to register PM notifier %d\n", ret);
return ret;
}
return ret;
}
#ifdef REGULATOR_TEST
void pmic_regulator_en_test(void)
{
int i = 0;
int ret1 = 0, ret2 = 0;
struct regulator *reg = NULL;
/*for (i = 0; i < ARRAY_SIZE(mt_ldos); i++) {*/
for (i = 0; i < mt_ldos_size; i++) {
if (mt_ldos[i].isUsedable != 1)
continue;
/*---VIO18 should not be off---*/
if (strcmp("va09", mt_ldos[i].desc.name) != 0)
continue;
reg = mt_ldos[i].reg;
pr_info("[regulator enable test] %s\n", mt_ldos[i].desc.name);
ret1 = regulator_enable(reg);
ret2 = regulator_is_enabled(reg);
if (ret2 == (mt_ldos[i].da_en_cb()))
pr_info("[enable test pass]\n");
else
pr_info("[enable test fail]\n");
ret1 = regulator_disable(reg);
ret2 = regulator_is_enabled(reg);
if (ret2 == (mt_ldos[i].da_en_cb()))
pr_info("[disable test pass]\n");
else
pr_info("[disable test fail]\n");
}
}
void pmic_regulator_vol_test(void)
{
int i = 0, j = 0;
struct regulator *reg = NULL;
const int *pVoltage = NULL;
const int *idxs = NULL;
int rvoltage = 0;
for (i = 0; i < mt_ldos_size; i++) {
reg = mt_ldos[i].reg;
if (mt_ldos[i].isUsedable != 1)
continue;
pr_info("[regulator voltage test] %s n_voltages:%d\n",
mt_ldos[i].desc.name, mt_ldos[i].desc.n_voltages);
if (mt_ldos[i].pvoltages == NULL)
continue;
pVoltage = mt_ldos[i].pvoltages;
idxs = mt_ldos[i].idxs;
for (j = 0; j < mt_ldos[i].desc.n_voltages; j++) {
regulator_set_voltage(reg, pVoltage[j], pVoltage[j]);
rvoltage = regulator_get_voltage(reg);
if (idxs[j] == mt_ldos[i].da_vol_cb() &&
(pVoltage[j] == rvoltage)) {
pr_info("[%d]:pass set_voltage:%d rvoltage:%d\n"
, idxs[j]
, pVoltage[j]
, rvoltage);
} else {
pr_info("[%d:%d]:fail set_voltage:%d rvoltage:%d\n"
, idxs[j]
, mt_ldos[i].da_vol_cb()
, pVoltage[j]
, rvoltage);
}
}
}
}
#endif /*--REGULATOR_TEST--*/
/*****************************************************************************
* Dump all LDO status
******************************************************************************/
void dump_ldo_status_read_debug(void)
{
int i = 0, j = 0;
int en = 0, ret = 0;
int voltage_reg = 0;
int voltage = 0;
const int *pVoltage = NULL, *pVoltidx = NULL;
pr_debug("********** BUCK/LDO status dump [1:ON,0:OFF]**********\n");
/*for (i = 0; i < ARRAY_SIZE(mtk_bucks); i++) {*/
for (i = 0; i < mt_bucks_size; i++) {
if (mt_bucks[i].da_en_cb != NULL)
en = (mt_bucks[i].da_en_cb)();
else
en = -1;
if (mt_bucks[i].da_vol_cb != NULL) {
voltage_reg = (mt_bucks[i].da_vol_cb)();
voltage = mt_bucks[i].desc.min_uV +
mt_bucks[i].desc.uV_step * voltage_reg;
} else {
voltage_reg = -1;
voltage = -1;
}
pr_info("%s status:%d voltage:%duv voltage_reg:%d\n",
mt_bucks[i].desc.name, en, voltage, voltage_reg);
}
/*for (i = 0; i < ARRAY_SIZE(mt_ldos); i++) {*/
for (i = 0; i < mt_ldos_size; i++) {
if (mt_ldos[i].da_en_cb != NULL)
en = (mt_ldos[i].da_en_cb)();
else
en = -1;
if (mt_ldos[i].desc.n_voltages != 1) {
if (mt_ldos[i].da_vol_cb != NULL) {
voltage_reg = (mt_ldos[i].da_vol_cb)();
if (mt_ldos[i].pvoltages != NULL) {
pVoltage = (const int *)
mt_ldos[i].pvoltages;
pVoltidx = (const int *)
mt_ldos[i].idxs;
/*HW LDO sequence issue, we need to change it */
for (j = 0;
j < mt_ldos[i].desc.n_voltages;
j++) {
if (pVoltidx[j] == voltage_reg) {
ret = j;
break;
}
}
voltage = pVoltage[ret];
} else {
voltage =
mt_ldos[i].desc.min_uV +
mt_ldos[i].desc.uV_step *
voltage_reg;
}
} else {
voltage_reg = -1;
voltage = -1;
}
} else
voltage = mt_ldos[i].desc.fixed_uV;
pr_info("%s status:%d voltage:%duv voltage_reg:%d\n",
mt_ldos[i].desc.name, en, voltage, voltage_reg);
}
}
static int proc_utilization_show(struct seq_file *m, void *v)
{
int i = 0, j = 0;
int en = 0, ret = 0;
int voltage_reg = 0;
int voltage = 0;
const int *pVoltage = NULL, *pVoltidx = NULL;
seq_puts(m, "********** BUCK/LDO status dump [1:ON,0:OFF]**********\n");
/*for (i = 0; i < ARRAY_SIZE(mtk_bucks); i++) {*/
for (i = 0; i < mt_bucks_size; i++) {
if (mt_bucks[i].da_en_cb != NULL)
en = (mt_bucks[i].da_en_cb)();
else
en = -1;
if (mt_bucks[i].da_vol_cb != NULL) {
voltage_reg = (mt_bucks[i].da_vol_cb)();
voltage = mt_bucks[i].desc.min_uV +
mt_bucks[i].desc.uV_step *
voltage_reg;
} else {
voltage_reg = -1;
voltage = -1;
}
seq_printf(m, "%s status:%d voltage:%duv voltage_reg:%d\n"
, mt_bucks[i].desc.name
, en, voltage, voltage_reg);
}
/*for (i = 0; i < ARRAY_SIZE(mt_ldos); i++) {*/
for (i = 0; i < mt_ldos_size; i++) {
if (mt_ldos[i].da_en_cb != NULL)
en = (mt_ldos[i].da_en_cb)();
else
en = -1;
if (mt_ldos[i].desc.n_voltages != 1) {
if (mt_ldos[i].da_vol_cb != NULL) {
voltage_reg = (mt_ldos[i].da_vol_cb)();
if (mt_ldos[i].pvoltages != NULL) {
pVoltage = (const int *)
mt_ldos[i].pvoltages;
pVoltidx = (const int *)
mt_ldos[i].idxs;
/*HW LDO sequence issue, we need to change it */
for (j = 0;
j < mt_ldos[i].desc.n_voltages; j++) {
if (pVoltidx[j] == voltage_reg) {
ret = j;
break;
}
}
voltage = pVoltage[ret];
} else {
voltage =
mt_ldos[i].desc.min_uV +
mt_ldos[i].desc.uV_step *
voltage_reg;
}
} else {
voltage_reg = -1;
voltage = -1;
}
} else {
voltage = mt_ldos[i].desc.fixed_uV;
voltage_reg = -1;
}
seq_printf(m, "%s status:%d voltage:%duv voltage_reg:%d\n"
, mt_ldos[i].desc.name, en, voltage, voltage_reg);
}
return 0;
}
static int proc_utilization_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_utilization_show, NULL);
}
static const struct file_operations pmic_debug_proc_fops = {
.open = proc_utilization_open,
.read = seq_read,
};
void pmic_regulator_debug_init(struct platform_device *dev,
struct dentry *debug_dir)
{
/* /sys/class/regulator/.../ */
int ret_device_file = 0, i;
struct dentry *mt_pmic_dir = debug_dir;
#ifdef REGULATOR_TEST
ret_device_file = device_create_file(&(dev->dev), &dev_attr_buck_api);
#endif /*--REGULATOR_TEST--*/
/* /sys/class/regulator/.../ */
/*EM BUCK voltage & Status*/
for (i = 0; i < mt_bucks_size; i++) {
/*PMICLOG("[PMIC] register buck id=%d\n",i);*/
if (*(int *)(&mt_bucks[i].en_att)) {
PMICLOG("[PMIC] register ldo en_att\n");
ret_device_file = device_create_file(&(dev->dev),
&(mt_bucks[i].en_att));
}
if (*(int *)(&mt_bucks[i].voltage_att)) {
PMICLOG("[PMIC] register ldo voltage_att\n");
ret_device_file = device_create_file(&(dev->dev),
&(mt_bucks[i].voltage_att));
}
}
/*ret_device_file = device_create_file(&(dev->dev),
*&mtk_bucks_class[i].voltage_att);
*/
/*EM ldo voltage & Status*/
for (i = 0; i < mt_ldos_size; i++) {
/*PMICLOG("[PMIC] register ldo id=%d\n",i);*/
if (*(int *)(&mt_ldos[i].en_att)) {
PMICLOG("[PMIC] register ldo en_att\n");
ret_device_file = device_create_file(&(dev->dev),
&mt_ldos[i].en_att);
}
if (*(int *)(&mt_ldos[i].voltage_att)) {
PMICLOG("[PMIC] register ldo voltage_att\n");
ret_device_file = device_create_file(&(dev->dev),
&mt_ldos[i].voltage_att);
}
}
ret_device_file = device_create_file(&(dev->dev),
&dev_attr_buck_ldo_info);
debugfs_create_file("dump_ldo_status", 0644,
mt_pmic_dir, NULL, &pmic_debug_proc_fops);
PMICLOG("proc_create pmic_debug_proc_fops\n");
}
MODULE_AUTHOR("Jimmy-YJ Huang");
MODULE_DESCRIPTION("MT PMIC REGULATOR Driver");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0.0_M");
@@ -0,0 +1,207 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2021 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/pm.h>
#include <linux/of_gpio.h>
#include <linux/pm_runtime.h>
#include <linux/smp.h>
#include <linux/device.h>
#include <linux/debugfs.h>
#include <linux/printk.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/consumer.h>
#include <linux/dcache.h>
#include <mach/upmu_hw.h>
#include <mach/upmu_sw.h>
#include <mt-plat/upmu_common.h>
#include <mach/mtk_pmic.h>
#include "include/pmic.h"
#include "include/pmic_irq.h"
#include "include/pmic_throttling_dlpt.h"
#include "include/pmic_debugfs.h"
#include "include/pmic_api_buck.h"
#include "include/pmic_bif.h"
#include "include/pmic_auxadc.h"
#if 0
/* /proj/mtk22477/casws_mtk22477/lc1/kernel-4.19/drivers/misc/mediatek/include/mt-plat */
/*
-I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include \
-I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(CONFIG_MTK_PLATFORM)/include/mach \
*/
/*
* PMIC EXTERN FUNCTIONS
*/
/*----- BATTERY_OC_PROTECT -----*/
void __attribute__ ((weak)) exec_battery_oc_callback(BATTERY_OC_LEVEL battery_oc_level){ }
void __attribute__ ((weak)) bat_oc_h_en_setting(int en_val){ }
void __attribute__ ((weak)) bat_oc_l_en_setting(int en_val){ }
/*----- CHRDET_PROTECT -----*/
#ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
unsigned int __attribute__ ((weak)) upmu_get_rgs_chrdet(void){ return 0; }
#endif
/*----- PMIC thread -----*/
void __attribute__ ((weak)) pmic_enable_charger_detection_int(int x){ }
/*----- LDO OC -----*/
void __attribute__ ((weak)) msdc_sd_power_off(void){ }
/*----- REGULATOR -----*/
int __attribute__ ((weak)) mtk_regulator_init(struct platform_device *dev){ return 0; }
unsigned int __attribute__ ((weak)) pmic_config_interface_buck_vsleep_check(unsigned int RegNum,
unsigned int val, unsigned int MASK, unsigned int SHIFT){ return 0; }
void __attribute__ ((weak)) pmic_regulator_debug_init(
struct platform_device *dev, struct dentry *debug_dir){ }
void __attribute__ ((weak)) pmic_regulator_suspend(void){ }
void __attribute__ ((weak)) pmic_regulator_resume(void){ }
/*----- EFUSE -----*/
int __attribute__ ((weak)) pmic_read_VMC_efuse(void){ return 0; }
/*----- Others -----*/
int __attribute__ ((weak)) PMIC_POWER_HOLD(unsigned int hold){ return 0; }
void __attribute__ ((weak)) mt_power_off(void){ }
unsigned int __attribute__ ((weak)) bat_get_ui_percentage(void){ return 0; }
signed int __attribute__ ((weak)) fgauge_read_IM_current(void *data){ return 0; }
void __attribute__ ((weak)) pmic_auxadc_lock(void){ }
void __attribute__ ((weak)) pmic_auxadc_unlock(void){ }
signed int __attribute__ ((weak)) fgauge_read_v_by_d(int d_val){ return 0; }
signed int __attribute__ ((weak)) fgauge_read_r_bat_by_v(signed int voltage){ return 0; }
void __attribute__ ((weak)) kpd_pwrkey_pmic_handler(unsigned long pressed){ }
void __attribute__ ((weak)) kpd_pmic_rstkey_handler(unsigned long pressed){ }
int __attribute__ ((weak)) is_mt6311_sw_ready(void){ return 0; }
int __attribute__ ((weak)) is_mt6311_exist(void){ return 0; }
int __attribute__ ((weak)) get_mt6311_i2c_ch_num(void){ return 0; }
#if !defined CONFIG_MTK_LEGACY
void __attribute__ ((weak)) pmu_drv_tool_customization_init(void){ }
#endif
int __attribute__ ((weak)) batt_init_cust_data(void){ return 0; }
unsigned int __attribute__ ((weak)) mt_gpio_to_irq(unsigned int gpio){return 0; }
int __attribute__ ((weak)) mt_gpio_set_debounce(unsigned int gpio, unsigned int debounce){ return 0; }
#ifdef CONFIG_MTK_PMIC_COMMON
int __attribute__ ((weak)) PMIC_check_battery(void){ return 0; }
int __attribute__ ((weak)) PMIC_check_wdt_status(void){ return 0; }
int __attribute__ ((weak)) PMIC_check_pwrhold_status(void){ return 0; }
void __attribute__ ((weak)) PMIC_LP_INIT_SETTING(void){ }
int __attribute__ ((weak)) PMIC_MD_INIT_SETTING_V1(void){ return 0; }
void __attribute__ ((weak)) PMIC_PWROFF_SEQ_SETTING(void){ }
int __attribute__ ((weak)) pmic_tracking_init(void){ return 0; }
#endif
unsigned int __attribute__ ((weak)) PMIC_CHIP_VER(void){ return 0; }
void __attribute__ ((weak)) record_md_vosel(void){ }
void __attribute__ ((weak)) register_low_battery_notify(
void (*low_battery_callback)(enum LOW_BATTERY_LEVEL_TAG),
enum LOW_BATTERY_PRIO_TAG prio_val)
{
}
void __attribute__ ((weak)) register_low_battery_notify_ext(
void (*low_battery_callback)(enum LOW_BATTERY_LEVEL_TAG),
enum LOW_BATTERY_PRIO_TAG prio_val)
{
}
int __attribute__ ((weak)) dlpt_check_power_off(void)
{
return 0;
}
unsigned int __attribute__ ((weak)) PMIC_LP_CHIP_VER(void) { return 0; }
unsigned int __attribute__ ((weak)) is_pmic_mrv(void) { return 0; }
void __attribute__ ((weak)) PMIC_INIT_SETTING_V1(void) { }
int __attribute__ ((weak)) do_ptim_ex(bool isSuspend, unsigned int *bat, signed int *cur) { return 0; }
#if defined(CONFIG_MACH_MT6768) || defined(CONFIG_MACH_MT6739) || defined(CONFIG_MACH_MT6781)
int __attribute__ ((weak)) pmic_buck_vproc_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_buck_vcore_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_buck_vmodem_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_buck_vs1_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_buck_vpa_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vsram_proc_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vsram_others_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vfe28_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vxo22_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vrf18_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vrf12_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vefuse_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vcn33_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vcn28_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vcn18_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vcama_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vcamd_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vcamio_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vldo28_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vaux18_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vaud28_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vio28_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vdram_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vmc_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vmch_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vemc_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vsim1_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vsim2_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vibr_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vusb33_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_tref_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
int __attribute__ ((weak)) pmic_ldo_vio18_lp(enum BUCK_LDO_EN_USER user,
unsigned char op_en, unsigned char op_cfg){ return 0; }
#endif
/*kernel-4.14/drivers/misc/mediatek/pmic/mt6359p/v1/pmic_lp_api.c*/
#if defined(CONFIG_MACH_MT6877)
int __attribute__ ((weak)) pmic_ldo_vio18_lp(
enum BUCK_LDO_EN_USER user,
int op_mode,
unsigned char op_en,
unsigned char op_cfg) { return 0; }
#endif
void __attribute__ ((weak)) register_battery_oc_notify(
void (*battery_oc_callback)(BATTERY_OC_LEVEL tag),
BATTERY_OC_PRIO prio_val) {}
#endif
#include <mt-plat/mtk_boot_common.h>
void __attribute__ ((weak)) mt_usb_connect_v1(void){}
void __attribute__ ((weak)) mt_usb_disconnect_v1(void){}
enum boot_mode_t __attribute__ ((weak)) get_boot_mode(void){ return 0;}