Squashed backup commit (no shallow-clone history issues) of xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2 branch, upstream commit 9eece662e) plus all fixes applied to get everpal_defconfig building clean against a modern (GCC 15.2.0) toolchain -- see the previous commit message on the lineage-23.2 branch (also in this repo history is not available here since this is a squashed snapshot; full incremental history lives in the local DL380 checkout and the upstream GitHub remote). Upstream: https://github.com/xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2)
119 lines
2.4 KiB
C
119 lines
2.4 KiB
C
/*
|
|
* Copyright (C) 2019 MediaTek Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See http://www.gnu.org/licenses/gpl-2.0.html for more details.
|
|
*/
|
|
|
|
#include <linux/errno.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/time.h>
|
|
#include <linux/slab.h>
|
|
#include <mt-plat/prop_chgalgo_class.h>
|
|
#include "mtk_intf.h"
|
|
|
|
static struct pe50 *pe5;
|
|
|
|
static int __pe50_notifier_call(struct notifier_block *nb, unsigned long event,
|
|
void *data)
|
|
{
|
|
chr_info("%s %s\n", __func__, prop_chgalgo_notify_evt_tostring(event));
|
|
switch (event) {
|
|
case PCA_NOTIEVT_ALGO_STOP:
|
|
wake_up_charger();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int pe50_stop(void)
|
|
{
|
|
if (pe5 == NULL)
|
|
return -ENODEV;
|
|
|
|
if (pe5->online == true) {
|
|
chr_err("%s\n", __func__);
|
|
enable_vbus_ovp(true);
|
|
pe5->online = false;
|
|
pe5->state = PE50_INIT;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
bool pe50_is_ready(void)
|
|
{
|
|
if (pe5 == NULL)
|
|
return false;
|
|
|
|
return prop_chgalgo_is_algo_ready(pe5->pca_algo);
|
|
}
|
|
|
|
int pe50_init(void)
|
|
{
|
|
int ret = -EBUSY;
|
|
struct pe50 *pe50 = NULL;
|
|
|
|
if (pe5 == NULL) {
|
|
pe50 = kzalloc(sizeof(struct pe50), GFP_KERNEL);
|
|
if (pe50 == NULL)
|
|
return -ENOMEM;
|
|
|
|
pe5 = pe50;
|
|
pe50->pca_algo = prop_chgalgo_dev_get_by_name("pca_algo_dv2");
|
|
if (!pe50->pca_algo) {
|
|
chr_err("[PE50] Get pca_algo fail\n");
|
|
ret = -EINVAL;
|
|
} else {
|
|
ret = prop_chgalgo_init_algo(pe50->pca_algo);
|
|
if (ret < 0) {
|
|
chr_err("[PE50] Init algo fail\n");
|
|
pe50->pca_algo = NULL;
|
|
goto out;
|
|
}
|
|
pe50->nb.notifier_call = __pe50_notifier_call;
|
|
ret = prop_chgalgo_notifier_register(pe50->pca_algo,
|
|
&pe50->nb);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
int pe50_run(void)
|
|
{
|
|
int ret = 0;
|
|
bool running;
|
|
|
|
switch (pe5->state) {
|
|
case PE50_INIT:
|
|
enable_vbus_ovp(false);
|
|
pe5->online = true;
|
|
ret = prop_chgalgo_start_algo(pe5->pca_algo);
|
|
if (ret < 0)
|
|
enable_vbus_ovp(true);
|
|
|
|
pe5->state = PE50_RUNNING;
|
|
break;
|
|
|
|
case PE50_RUNNING:
|
|
running = prop_chgalgo_is_algo_running(pe5->pca_algo);
|
|
if (!running)
|
|
enable_vbus_ovp(true);
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|