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

+469
View File
@@ -0,0 +1,469 @@
config MTK_COMBO
tristate "MediaTek Connectivity Combo Chip Support"
help
MTK connectivity combo chip driver for MT66xx
This config
is used to
turn on/off connsys
#
# MTK Combo Chip Selection
#
choice
prompt "Select Chip"
depends on MTK_COMBO
help
This is used to select chip.
When MTK_COMBO is y,
we need to choose
a chip.
config MTK_COMBO_CHIP_MT6620
bool "MT6620"
help
this config is used to decided combo chip version
in current platform
is
MT6620
config MTK_COMBO_CHIP_MT6628
bool "MT6628"
help
this config is used to decided combo chip version
in current platform
is
MT6628
config MTK_COMBO_CHIP_MT7668
bool "MT7668"
help
this config is used to decided combo chip version
in current platform
is
MT7668
config MTK_COMBO_CHIP_MT6630
bool "MT6630"
help
this config is used to decided combo chip version
in current platform
is
MT6630
config MTK_COMBO_CHIP_MT6632
bool "Mediatek MT6632 device driver support"
help
This driver supports the built-in smart phone found
in the Mediatek MT6632 chipset.
If you want to use MT6632 driver supprt, say Y.
If unsure, say N.
Mediatek MT6632 module includes BT, FM, GPS, WIFI.
config MTK_COMBO_CHIP_CONSYS_6757
bool "MTK MT6757 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6757(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6763
bool "MTK MT6763 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6763(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6758
bool "MTK MT6758 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6758(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6759
bool "MTK MT6759 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6759(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6765
bool "MTK MT6765 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6765(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6761
bool "MTK MT6761 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6761(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_8167
bool "MTK MT8167 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT8167(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_8168
bool "MTK MT8168 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT8168(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_3967
bool "MTK MT3967 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT3967(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6771
bool "MTK MT6771 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6771(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6739
bool "MTK MT6739 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6739(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6768
bool "MTK MT6768 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6768(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6779
bool "MTK MT6779 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6779(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6781
bool "MTK MT6781 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6781(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6785
bool "MTK MT6785 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6785(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6833
bool "MTK MT6833 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6833(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6853
bool "MTK MT6853 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6853(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6873
bool "MTK MT6873 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6873(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6877
bool "MTK MT6877 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6877(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6885
bool "MTK MT6885 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6885(BT/WIFI/GPS/FM combo chip)
config MTK_COMBO_CHIP_CONSYS_6893
bool "MTK MT6893 combo chip support"
help
this config is used to decided SOC consys version
in current platform
is
MT6893(BT/WIFI/GPS/FM combo chip)
endchoice
config MTK_COMBO_CHIP
string
default "MT6620" if MTK_COMBO_CHIP_MT6620
default "MT6628" if MTK_COMBO_CHIP_MT6628
default "MT6630" if MTK_COMBO_CHIP_MT6630
default "MT6632" if MTK_COMBO_CHIP_MT6632
default "MT7668" if MTK_COMBO_CHIP_MT7668
default "MT7663" if MTK_COMBO_CHIP_MT7663
default "CONSYS_6757" if MTK_COMBO_CHIP_CONSYS_6757
default "CONSYS_6763" if MTK_COMBO_CHIP_CONSYS_6763
default "CONSYS_6758" if MTK_COMBO_CHIP_CONSYS_6758
default "CONSYS_6759" if MTK_COMBO_CHIP_CONSYS_6759
default "CONSYS_6765" if MTK_COMBO_CHIP_CONSYS_6765
default "CONSYS_6761" if MTK_COMBO_CHIP_CONSYS_6761
default "CONSYS_8167" if MTK_COMBO_CHIP_CONSYS_8167
default "CONSYS_3967" if MTK_COMBO_CHIP_CONSYS_3967
default "CONSYS_6771" if MTK_COMBO_CHIP_CONSYS_6771
default "CONSYS_6739" if MTK_COMBO_CHIP_CONSYS_6739
default "CONSYS_6768" if MTK_COMBO_CHIP_CONSYS_6768
default "CONSYS_6779" if MTK_COMBO_CHIP_CONSYS_6779
default "CONSYS_6781" if MTK_COMBO_CHIP_CONSYS_6781
default "CONSYS_6785" if MTK_COMBO_CHIP_CONSYS_6785
default "CONSYS_6833" if MTK_COMBO_CHIP_CONSYS_6833
default "CONSYS_6853" if MTK_COMBO_CHIP_CONSYS_6853
default "CONSYS_6873" if MTK_COMBO_CHIP_CONSYS_6873
default "CONSYS_6885" if MTK_COMBO_CHIP_CONSYS_6885
default "CONSYS_6893" if MTK_COMBO_CHIP_CONSYS_6893
default "CONSYS_6877" if MTK_COMBO_CHIP_CONSYS_6877
help
this feature is used to identify combo chip version or SOC chip
consys version.
#
# Target Platform Selection
#
config MTK_COMBO_PLAT_PATH
string "Platform folder name"
depends on MTK_COMBO
default "sample" if MTK_COMBO_PLAT_SAMPLE
help
Specify platform folder under common driver platform folder:
mtk_wcn_combo/common/platform/*
#
# MTK COMBO Chip Configuration
#
config MTK_COMBO_COMM
depends on MTK_COMBO
tristate "MediaTek Combo Chip Common part driver"
help
MediaTek combo chip common part driver
config MTK_COMBO_COMM_UART
depends on MTK_COMBO_COMM
tristate "Common interface UART"
help
Use UART for common part interface type
config MTK_COMBO_COMM_SDIO
depends on MTK_COMBO_COMM
tristate "Common interface SDIO"
help
Use SDIO for common part interface type
config MTK_COMBO_COMM_NPWR
depends on MTK_COMBO_COMM
bool "Enable NPWR support"
default n
help
Enable NPWR support of new power on swquence
config MTK_COMBO_COMM_APO
depends on MTK_COMBO_COMM
bool "Enable always power on support"
default n
help
Enable chip will always power on
config MTK_COMBO_BT
tristate "MediaTek Combo Chip BT driver"
depends on MTK_COMBO
help
MTK BT /dev/stpbt driver for Bluedroid
config MTK_COMBO_ANT
tristate "MediaTek Combo Chip ANT driver"
depends on MTK_COMBO
help
MTK ANT /dev/stpant driver for ANT
config MTK_COMBO_BT_HCI
tristate "MediaTek Combo Chip BlueZ driver"
depends on BT && MTK_COMBO
help
MTK BT driver for BlueZ
config MTK_COMBO_GPS
tristate "MediaTek Combo Chip GPS driver"
depends on MTK_COMBO
help
MTK GPS /dev/stpgps driver
config MTK_COMBO_WIFI
tristate "MediaTek combo chip Wi-Fi support"
depends on MTK_COMBO
select WIRELESS_EXT
select WEXT_PRIV
config MTK_PASSPOINT_R1_SUPPORT
bool "MTK_PASSPOINT_R1_SUPPORT"
depends on MTK_COMBO_WIFI
help
Support Passpoint R1 (Hotspot 2.0 R1)
config MTK_PASSPOINT_R2_SUPPORT
bool "MTK_PASSPOINT_R2_SUPPORT"
depends on MTK_COMBO_WIFI
help
Support Passpoint R2
config MTK_WIFI_MCC_SUPPORT
bool "MTK_WIFI_MCC_SUPPORT"
depends on MTK_COMBO_WIFI
default y
help
if it is set to TRUE, wlan will support Multi-Channel Concurrency,
otherwise, only support Single Channel Concurrency
config MTK_DHCPV6C_WIFI
bool "MTK_DHCPV6C_WIFI"
help
no: disable this feature
config MTK_CONN_LTE_IDC_SUPPORT
bool "MediaTek CONN LTE IDC support"
default y if MTK_ECCCI_DRIVER
help
This option enables CONN LTE IDC support
menuconfig GPS
tristate "GPS drivers"
default n
---help---
Say Y here for supporting GPS.
config MTK_GPS_SUPPORT
tristate "support MediaTek GPS driver"
help
to switch GPS feature on the platform.
Set "yes" to turn on and set "no"
(with MTK_AGPS_APP=no at the same time)
to turn off.
config MTK_GPS_REGISTER_SETTING
tristate "MediaTek GPS Register Setting"
depends on MTK_COMBO_GPS
help
GPS register settings.
config MTK_GPS_EMI
tristate "MediaTek GPS EMI Driver"
depends on MTK_COMBO_GPS
help
GPS EMI driver is for MNL OFFLOAD feature.
config MTK_FMRADIO
tristate "MediaTek FMRadio driver"
depends on MTK_COMBO
help
This config is used to choose
if need to compile fmradio folder.
Will compile fmradio folder if set to 'y',
otherwise will not compile fmradio folder.
config MTK_FM_CHIP
string "MTK FM CHIP"
depends on MTK_FMRADIO
help
This config is used to choose
which FM radio chip to use:
e.g. MT6627_FM, MT6580_FM, MT6630_FM,
for control to use which platform code.
config MTK_FM_50KHZ_SUPPORT
bool "support MTK FM 50KHZ"
depends on MTK_FMRADIO
help
This config is used to choose
if need to support FM 50KHz step or not
for tune/seek/scan functions.
Will support 50KHz step if set to 'y',
otherwise will not support 50KHz step.
config MTK_MERGE_INTERFACE_SUPPORT
bool "support MTK MERGE INTERFACE"
help
This config is used to control FM Audio
path. FM audio path will use PCM/I2S merge
interface is set to 'y',
otherwise merge interface is not used.
config MTK_COMBO_CHIP_DEEP_SLEEP_SUPPORT
depends on MTK_COMBO_CHIP_MT6632
default y
tristate "Mediatek combo chip deep sleep feature setting"
help
this config is used to enable or disable chip deep sleep feature,
if the project is no deep sleep design,
host can`t wake up chip form deep sleep,
we must close this config.
config MTK_CONN_MT3337_CHIP_SUPPORT
bool "Mediatek MT3337 device driver support"
help
This config is used to enable or disable chip 3337's gps driver.
MT3337 is gps only chip without BT and wifi,
it is powered on by new gps driver.
Otherwise we must close this config.
config MTK_COMBO_CHIP_MT7663
bool "MT7663"
default n
help
this config is used to decided combo chip version
in current platform
is
MT7663
config MTK_CONNSYS_DEDICATED_LOG_PATH
bool "Enable connsys log using dedicated path"
default n
help
This will enable connsys log using dedicated path
1. There would be a common debug utility for collecting log
from connsys (by EMI or other specific path)
2. The scope may include (but not limited) Wi-Fi firmware log,
BT firmware log, GPS firmware log etc.
+108
View File
@@ -0,0 +1,108 @@
#
# Copyright (C) 2015 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 the
# GNU General Public License for more details.
#
# Connectivity combo driver
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
subdir-ccflags-y += -I$(srctree)/
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/clkbuf/src
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/base/power/include/clkbuf_v1/$(MTK_PLATFORM)
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat
ifeq ($(CONFIG_MTK_PMIC_CHIP_MT6359),y)
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include/mt6359
endif
ifeq ($(CONFIG_MTK_PMIC_NEW_ARCH),y)
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/pmic/include
endif
subdir-ccflags-y += -I$(srctree)/drivers/mmc/core
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/eccci/$(MTK_PLATFORM)
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/eccci/
subdir-ccflags-y += -I$(srctree)/drivers/clk/mediatek/
subdir-ccflags-y += -I$(srctree)/drivers/pinctrl/mediatek/
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/power_throttling/
# Do Nothing, move to standalone repo
MODULE_NAME := connadp
obj-$(CONFIG_MTK_COMBO) += $(MODULE_NAME).o
$(MODULE_NAME)-objs += common/connectivity_build_in_adapter.o
$(MODULE_NAME)-objs += common/wmt_build_in_adapter.o
$(MODULE_NAME)-objs += power_throttling/adapter.o
$(MODULE_NAME)-objs += power_throttling/core.o
ifeq ($(CONFIG_CONN_PWR_DEBUG),y)
$(MODULE_NAME)-objs += power_throttling/test.o
endif
ifeq ($(CONFIG_MTK_COMBO), y)
ccflags-y += -D CFG_CONNADP_BUILD_IN
endif
# Do build-in for Makefile checking
# export CONFIG_WLAN_DRV_BUILD_IN=y
ifeq ($(CONFIG_WLAN_DRV_BUILD_IN),y)
PATH_TO_WMT_DRV = vendor/mediatek/kernel_modules/connectivity/common
PATH_TO_WLAN_CHR_DRV = vendor/mediatek/kernel_modules/connectivity/wlan/adaptor
PATH_TO_WLAN_DRV = vendor/mediatek/kernel_modules/connectivity/wlan/core/gen4m
ABS_PATH_TO_WMT_DRV = $(srctree)/../$(PATH_TO_WMT_DRV)
ABS_PATH_TO_WLAN_CHR_DRV = $(srctree)/../$(PATH_TO_WLAN_CHR_DRV)
ABS_PATH_TO_WLAN_DRV = $(srctree)/../$(PATH_TO_WLAN_DRV)
# check wlan driver folder
ifeq (,$(wildcard $(ABS_PATH_TO_WMT_DRV)))
$(error $(ABS_PATH_TO_WMT_DRV) is not existed)
endif
ifeq (,$(wildcard $(ABS_PATH_TO_WLAN_CHR_DRV)))
$(error $(ABS_PATH_TO_WLAN_CHR_DRV) is not existed)
endif
ifeq (,$(wildcard $(ABS_PATH_TO_WLAN_DRV)))
$(error $(ABS_PATH_TO_WLAN_DRV) is not existed)
endif
$(warning symbolic link to $(PATH_TO_WMT_DRV))
$(warning symbolic link to $(PATH_TO_WLAN_CHR_DRV))
$(warning symbolic link to $(PATH_TO_WLAN_DRV))
$(shell unlink $(srctree)/$(src)/wmt_drv)
$(shell unlink $(srctree)/$(src)/wmt_chrdev_wifi)
$(shell unlink $(srctree)/$(src)/wlan_drv_gen4m)
$(shell ln -s $(ABS_PATH_TO_WMT_DRV) $(srctree)/$(src)/wmt_drv)
$(shell ln -s $(ABS_PATH_TO_WLAN_CHR_DRV) $(srctree)/$(src)/wmt_chrdev_wifi)
$(shell ln -s $(ABS_PATH_TO_WLAN_DRV) $(srctree)/$(src)/wlan_drv_gen4m)
# for gen4m options
export CONFIG_MTK_COMBO_WIFI_HIF=axi
export MTK_COMBO_CHIP=CONNAC
export WLAN_CHIP_ID=6765
export MTK_ANDROID_WMT=y
# Do build-in for xxx.c checking
subdir-ccflags-y += -D MTK_WCN_REMOVE_KERNEL_MODULE
subdir-ccflags-y += -D MTK_WCN_BUILT_IN_DRIVER
obj-y += wmt_drv/
obj-y += wmt_chrdev_wifi/
obj-y += wlan_drv_gen4m/
endif
# Otherwise we were called directly from the command line;
# invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
@@ -0,0 +1,399 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifdef DFT_TAG
#undef DFT_TAG
#endif
#define DFT_TAG "[CONNADP]"
#include "connectivity_build_in_adapter.h"
#include <kernel/sched/sched.h>
/*device tree mode*/
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/irqreturn.h>
#include <linux/of_address.h>
#endif
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/of_reserved_mem.h>
#include <linux/trace_events.h>
#include <linux/interrupt.h>
#ifdef CONFIG_MTK_MT6306_GPIO_SUPPORT
#include <mtk_6306_gpio.h>
#endif
#ifdef CONNADP_HAS_CLOCK_BUF_CTRL
#include <mtk_clkbuf_ctl.h>
#endif
/* PMIC */
#if defined(CONFIG_MTK_PMIC_CHIP_MT6359)
#include <mtk_pmic_api_buck.h>
#endif
#if defined(CONFIG_MTK_PMIC_CHIP_MT6359P)
#include <pmic_api_buck.h>
#endif
#include <upmu_common.h>
/* MMC */
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include <sdio_ops.h>
#ifdef CONFIG_ARCH_MT6570
#define CPU_BOOST y
#endif
#ifdef CONFIG_ARCH_MT6755
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6757
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6763
#define CPU_BOOST y
#endif
#ifdef CPU_BOOST
#include "mtk_ppm_api.h"
#endif
#ifndef TASK_STATE_TO_CHAR_STR
#define TASK_STATE_TO_CHAR_STR "RSDTtXZxKWPNn"
#endif
void connectivity_export_show_stack(struct task_struct *tsk, unsigned long *sp)
{
#ifdef CFG_CONNADP_BUILD_IN
show_stack(tsk, sp);
#else
pr_info("%s not support in connadp.ko\n", __func__);
#endif
}
EXPORT_SYMBOL(connectivity_export_show_stack);
void connectivity_export_tracing_record_cmdline(struct task_struct *tsk)
{
#ifdef CONFIG_TRACING
#ifdef CFG_CONNADP_BUILD_IN
tracing_record_cmdline(tsk);
#else
pr_info("%s not support in connadp.ko\n", __func__);
#endif
#endif
}
EXPORT_SYMBOL(connectivity_export_tracing_record_cmdline);
void connectivity_export_conap_scp_init(unsigned int chip_info, phys_addr_t emi_phy_addr)
{
}
EXPORT_SYMBOL(connectivity_export_conap_scp_init);
void connectivity_export_conap_scp_deinit(void)
{
}
EXPORT_SYMBOL(connectivity_export_conap_scp_deinit);
#ifdef CPU_BOOST
bool connectivity_export_spm_resource_req(unsigned int user,
unsigned int req_mask)
{
return spm_resource_req(user, req_mask);
}
EXPORT_SYMBOL(connectivity_export_spm_resource_req);
void connectivity_export_mt_ppm_sysboost_freq(enum ppm_sysboost_user user,
unsigned int freq)
{
mt_ppm_sysboost_freq(user, freq);
}
EXPORT_SYMBOL(connectivity_export_mt_ppm_sysboost_freq);
void connectivity_export_mt_ppm_sysboost_core(enum ppm_sysboost_user user,
unsigned int core_num)
{
mt_ppm_sysboost_core(user, core_num);
}
EXPORT_SYMBOL(connectivity_export_mt_ppm_sysboost_core);
void connectivity_export_mt_ppm_sysboost_set_core_limit(
enum ppm_sysboost_user user,
unsigned int cluster,
int min_core, int max_core)
{
mt_ppm_sysboost_set_core_limit(user, cluster, min_core, max_core);
}
EXPORT_SYMBOL(connectivity_export_mt_ppm_sysboost_set_core_limit);
void connectivity_export_mt_ppm_sysboost_set_freq_limit(
enum ppm_sysboost_user user,
unsigned int cluster,
int min_freq, int max_freq)
{
mt_ppm_sysboost_set_freq_limit(user, cluster, min_freq, max_freq);
}
EXPORT_SYMBOL(connectivity_export_mt_ppm_sysboost_set_freq_limit);
#endif
/*******************************************************************************
* Clock Buffer Control
******************************************************************************/
#ifdef CONNADP_HAS_CLOCK_BUF_CTRL
void connectivity_export_clk_buf_ctrl(enum clk_buf_id id, bool onoff)
{
clk_buf_ctrl(id, onoff);
}
EXPORT_SYMBOL(connectivity_export_clk_buf_ctrl);
void connectivity_export_clk_buf_show_status_info(void)
{
#if defined(CONFIG_MACH_MT6768) || \
defined(CONFIG_MACH_MT6771) || \
defined(CONFIG_MACH_MT6739) || \
defined(CONFIG_MACH_MT6781) || \
defined(CONFIG_MACH_MT6785) || \
defined(CONFIG_MACH_MT6873) || \
defined(CONFIG_MACH_MT6885) || \
defined(CONFIG_MACH_MT6893) || \
defined(CONFIG_MACH_MT6877)
#if defined(CONFIG_MTK_BASE_POWER)
clk_buf_show_status_info();
#else
pr_info("[%s] not support now", __func__);
#endif
#endif
}
EXPORT_SYMBOL(connectivity_export_clk_buf_show_status_info);
int connectivity_export_clk_buf_get_xo_en_sta(/*enum xo_id id*/ int id)
{
#if defined(CONFIG_MACH_MT6768) || \
defined(CONFIG_MACH_MT6781) || \
defined(CONFIG_MACH_MT6785) || \
defined(CONFIG_MACH_MT6771) || \
defined(CONFIG_MACH_MT6739)
return clk_buf_get_xo_en_sta(id);
#else
return KERNEL_CLK_BUF_CHIP_NOT_SUPPORT;
#endif
}
EXPORT_SYMBOL(connectivity_export_clk_buf_get_xo_en_sta);
#endif
/*******************************************************************************
* MT6306 I2C-based GPIO Expander
******************************************************************************/
#ifdef CONFIG_MTK_MT6306_GPIO_SUPPORT
void connectivity_export_mt6306_set_gpio_out(unsigned long pin,
unsigned long output)
{
mt6306_set_gpio_out(MT6306_GPIO_01, MT6306_GPIO_OUT_LOW);
}
EXPORT_SYMBOL(connectivity_export_mt6306_set_gpio_out);
void connectivity_export_mt6306_set_gpio_dir(unsigned long pin,
unsigned long dir)
{
mt6306_set_gpio_dir(MT6306_GPIO_01, MT6306_GPIO_DIR_OUT);
}
EXPORT_SYMBOL(connectivity_export_mt6306_set_gpio_dir);
#endif
/*******************************************************************************
* PMIC
******************************************************************************/
void connectivity_export_pmic_config_interface(unsigned int RegNum,
unsigned int val, unsigned int MASK, unsigned int SHIFT)
{
#if !defined(CONFIG_MACH_MT6761) && !defined(CONFIG_MACH_MT6765) && !defined(CONFIG_MACH_MT6779)
pmic_config_interface(RegNum, val, MASK, SHIFT);
#else
return;
#endif
}
EXPORT_SYMBOL(connectivity_export_pmic_config_interface);
void connectivity_export_pmic_read_interface(unsigned int RegNum,
unsigned int *val, unsigned int MASK, unsigned int SHIFT)
{
#if !defined(CONFIG_MACH_MT6761) && !defined(CONFIG_MACH_MT6765) && !defined(CONFIG_MACH_MT6779)
pmic_read_interface(RegNum, val, MASK, SHIFT);
#else
return;
#endif
}
EXPORT_SYMBOL(connectivity_export_pmic_read_interface);
void connectivity_export_pmic_set_register_value(int flagname, unsigned int val)
{
#ifdef CONNADP_HAS_UPMU_VCN_CTRL
upmu_set_reg_value(flagname, val);
#else
#if !defined(CONFIG_MACH_MT6761) && !defined(CONFIG_MACH_MT6765) && !defined(CONFIG_MACH_MT6779)
pmic_set_register_value(flagname, val);
#else
return;
#endif
#endif
}
EXPORT_SYMBOL(connectivity_export_pmic_set_register_value);
unsigned short connectivity_export_pmic_get_register_value(int flagname)
{
#ifdef CONNADP_HAS_UPMU_VCN_CTRL
return upmu_get_reg_value(flagname);
#else
#if !defined(CONFIG_MACH_MT6761) && !defined(CONFIG_MACH_MT6765) && !defined(CONFIG_MACH_MT6779)
return pmic_get_register_value(flagname);
#else
return 0;
#endif
#endif
}
EXPORT_SYMBOL(connectivity_export_pmic_get_register_value);
void connectivity_export_upmu_set_reg_value(unsigned int reg,
unsigned int reg_val)
{
#if !defined(CONFIG_MACH_MT6761) && !defined(CONFIG_MACH_MT6765) && !defined(CONFIG_MACH_MT6779)
upmu_set_reg_value(reg, reg_val);
#else
return;
#endif
}
EXPORT_SYMBOL(connectivity_export_upmu_set_reg_value);
#if defined(CONFIG_MTK_PMIC_CHIP_MT6359) || \
defined(CONFIG_MTK_PMIC_CHIP_MT6359P)
int connectivity_export_pmic_ldo_vcn13_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg)
{
return pmic_ldo_vcn13_lp(user, op_mode, op_en, op_cfg);
}
EXPORT_SYMBOL(connectivity_export_pmic_ldo_vcn13_lp);
int connectivity_export_pmic_ldo_vcn18_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg)
{
return pmic_ldo_vcn18_lp(user, op_mode, op_en, op_cfg);
}
EXPORT_SYMBOL(connectivity_export_pmic_ldo_vcn18_lp);
void connectivity_export_pmic_ldo_vfe28_lp(unsigned int user,
int op_mode, unsigned char op_en, unsigned char op_cfg)
{
pmic_ldo_vfe28_lp(user, op_mode, op_en, op_cfg);
}
EXPORT_SYMBOL(connectivity_export_pmic_ldo_vfe28_lp);
int connectivity_export_pmic_ldo_vcn33_1_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg)
{
return pmic_ldo_vcn33_1_lp(user, op_mode, op_en, op_cfg);
}
EXPORT_SYMBOL(connectivity_export_pmic_ldo_vcn33_1_lp);
int connectivity_export_pmic_ldo_vcn33_2_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg)
{
return pmic_ldo_vcn33_2_lp(user, op_mode, op_en, op_cfg);
}
EXPORT_SYMBOL(connectivity_export_pmic_ldo_vcn33_2_lp);
#endif
/*******************************************************************************
* MMC
******************************************************************************/
int connectivity_export_mmc_io_rw_direct(struct mmc_card *card,
int write, unsigned int fn,
unsigned int addr, u8 in, u8 *out)
{
/* TODO: porting this function if sdio is used */
/* return mmc_io_rw_direct(card, write, fn, addr, in, out); */
return 0;
}
EXPORT_SYMBOL(connectivity_export_mmc_io_rw_direct);
/******************************************************************************
* GPIO dump information
******************************************************************************/
#ifndef CONFIG_MTK_GPIO
void __weak gpio_dump_regs_range(int start, int end)
{
pr_info(DFT_TAG "[W]%s: is not define!\n", __func__);
}
#endif
#ifndef CONFIG_MTK_GPIO
void connectivity_export_dump_gpio_info(int start, int end)
{
gpio_dump_regs_range(start, end);
}
EXPORT_SYMBOL(connectivity_export_dump_gpio_info);
#endif
void connectivity_export_dump_thread_state(const char *name)
{
#ifdef CFG_CONNADP_BUILD_IN
static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
struct task_struct *p;
int cpu;
struct rq *rq;
struct task_struct *curr;
struct thread_info *ti;
if (name == NULL || strlen(name) > 255) {
pr_info("invalid name:%p or thread name too long\n", name);
return;
}
pr_info("start to show debug info of %s\n", name);
rcu_read_lock();
for_each_process(p) {
unsigned long state;
if (strncmp(p->comm, name, strlen(name)) != 0)
continue;
state = p->state;
cpu = task_cpu(p);
rq = cpu_rq(cpu);
curr = rq->curr;
ti = task_thread_info(curr);
if (state)
state = __ffs(state) + 1;
pr_info("%d:%-15.15s %c", p->pid, p->comm,
state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
pr_info("cpu=%d on_cpu=%d ", cpu, p->on_cpu);
show_stack(p, NULL);
pr_info("CPU%d curr=%d:%-15.15s preempt_count=0x%x", cpu,
curr->pid, curr->comm, ti->preempt_count);
if (state == TASK_RUNNING && curr != p)
show_stack(curr, NULL);
break;
}
rcu_read_unlock();
#else
pr_info("%s not support in connadp.ko\n", __func__);
#endif
}
EXPORT_SYMBOL(connectivity_export_dump_thread_state);
int connectivity_export_gpio_get_tristate_input(unsigned int pin)
{
return 0;
}
EXPORT_SYMBOL(connectivity_export_gpio_get_tristate_input);
MODULE_LICENSE("GPL");
@@ -0,0 +1,290 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef CONNECTIVITY_BUILD_IN_ADAPTER_H
#define CONNECTIVITY_BUILD_IN_ADAPTER_H
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/dma-mapping.h>
#include <linux/sched/clock.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <mtk-clkbuf-bridge.h>
/*******************************************************************************
* Clock Buffer Control
*
* The Connsys adaptation layer must provide Clock Buffer Control support
* should it be available from the platform.
* Therefore CONNADP_HAS_CLOCK_BUF_CTRL is defined based on platform chip, and
* is used to decide if adaptation has support on Clock Buffer Control.
*
* Each WMT platform file must still define its own CONSYS_CLOCK_BUF_CTRL to
* decide if it is a co-clock'd platform.
* It is possible that the Clock Buffer Control is available on the platform,
* but is not used by Connsys.
*
* For Kernel-4,4, definition of CONNADP_HAS_CLOCK_BUF_CTRL must align with:
* drivers/misc/mediatek/base/power/include/mtk_clkbuf_ctl.h
*
* Platform that wishes to use Clock Buffer Control, please be sure to #include
* the header file above.
******************************************************************************/
#if defined(CONFIG_MACH_MT6735) || \
defined(CONFIG_MACH_MT6735M) || \
defined(CONFIG_MACH_MT6753) || \
defined(CONFIG_MACH_MT6739) || \
defined(CONFIG_MACH_MT6755) || \
defined(CONFIG_MACH_MT6757) || \
defined(CONFIG_MACH_MT6758) || \
defined(CONFIG_MACH_MT6759) || \
defined(CONFIG_MACH_MT6763) || \
defined(CONFIG_MACH_MT6775) || \
defined(CONFIG_MACH_MT6797) || \
defined(CONFIG_MACH_MT6799) || \
defined(CONFIG_MACH_MT6580) || \
defined(CONFIG_MACH_MT6761) || \
defined(CONFIG_MACH_MT6765) || \
defined(CONFIG_MACH_MT6781) || \
defined(CONFIG_MACH_MT3967) || \
defined(CONFIG_MACH_MT6771) || \
defined(CONFIG_MACH_MT6768) || \
defined(CONFIG_MACH_MT6785) || \
defined(CONFIG_MACH_KIBOPLUS) || \
defined(CONFIG_MACH_MT6885) || \
defined(CONFIG_MACH_MT6853) || \
defined(CONFIG_MACH_MT6873) || \
defined(CONFIG_MACH_ELBRUS) || \
defined(CONFIG_MACH_MT6893) || \
defined(CONFIG_MACH_MT6877)
#define CONNADP_HAS_CLOCK_BUF_CTRL
#define KERNEL_CLK_BUF_CHIP_NOT_SUPPORT -7788
#define KERNEL_clk_buf_ctrl connectivity_export_clk_buf_ctrl
#define KERNEL_clk_buf_show_status_info \
connectivity_export_clk_buf_show_status_info
#define KERNEL_clk_buf_get_xo_en_sta \
connectivity_export_clk_buf_get_xo_en_sta
enum clk_buf_id;
void connectivity_export_clk_buf_ctrl(enum clk_buf_id id, bool onoff);
void connectivity_export_clk_buf_show_status_info(void);
int connectivity_export_clk_buf_get_xo_en_sta(/*enum xo_id id*/ int id);
#endif
/*******************************************************************************
* PMIC
* Caller please be sure to #include:
* drivers/misc/mediatek/pmic/include/mt6359/mtk_pmic_api_buck.h
* drivers/misc/mediatek/include/mt-plat/upmu_common.h
******************************************************************************/
#define KERNEL_pmic_config_interface \
connectivity_export_pmic_config_interface
#define KERNEL_pmic_read_interface \
connectivity_export_pmic_read_interface
#define KERNEL_pmic_set_register_value \
connectivity_export_pmic_set_register_value
#define KERNEL_pmic_get_register_value \
connectivity_export_pmic_get_register_value
#define KERNEL_upmu_set_reg_value \
connectivity_export_upmu_set_reg_value
#if defined(CONFIG_MTK_PMIC_CHIP_MT6359) || \
defined(CONFIG_MTK_PMIC_CHIP_MT6359P)
#define KERNEL_pmic_ldo_vcn13_lp \
connectivity_export_pmic_ldo_vcn13_lp
#define KERNEL_pmic_ldo_vcn18_lp \
connectivity_export_pmic_ldo_vcn18_lp
#define KERNEL_pmic_ldo_vfe28_lp \
connectivity_export_pmic_ldo_vfe28_lp
#define KERNEL_pmic_ldo_vcn33_1_lp \
connectivity_export_pmic_ldo_vcn33_1_lp
#define KERNEL_pmic_ldo_vcn33_2_lp \
connectivity_export_pmic_ldo_vcn33_2_lp
#endif
void connectivity_export_pmic_config_interface(unsigned int RegNum,
unsigned int val,
unsigned int MASK,
unsigned int SHIFT);
void connectivity_export_pmic_read_interface(unsigned int RegNum,
unsigned int *val,
unsigned int MASK,
unsigned int SHIFT);
void connectivity_export_pmic_set_register_value(int flagname,
unsigned int val);
unsigned short connectivity_export_pmic_get_register_value(int flagname);
void connectivity_export_upmu_set_reg_value(unsigned int reg,
unsigned int reg_val);
#if defined(CONFIG_MTK_PMIC_CHIP_MT6359) || \
defined(CONFIG_MTK_PMIC_CHIP_MT6359P)
int connectivity_export_pmic_ldo_vcn13_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg);
int connectivity_export_pmic_ldo_vcn18_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg);
void connectivity_export_pmic_ldo_vfe28_lp(unsigned int user,
int op_mode, unsigned char op_en, unsigned char op_cfg);
int connectivity_export_pmic_ldo_vcn33_1_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg);
int connectivity_export_pmic_ldo_vcn33_2_lp(int user,
int op_mode, unsigned char op_en, unsigned char op_cfg);
#endif
/*******************************************************************************
* MMC
* Caller please be sure to #include:
* <linux/mmc/host.h>
* <linux/mmc/card.h>
* drivers/mmc/core/sdio_ops.h
******************************************************************************/
#define KERNEL_mmc_io_rw_direct connectivity_export_mmc_io_rw_direct
struct mmc_card;
int connectivity_export_mmc_io_rw_direct(struct mmc_card *card, int write,
unsigned int fn,
unsigned int addr,
u8 in, u8 *out);
/*******************************************************************************
* MT6306 I2C-based GPIO Expander
******************************************************************************/
#ifdef CONFIG_MTK_MT6306_GPIO_SUPPORT
#define KERNEL_mt6306_set_gpio_out connectivity_export_mt6306_set_gpio_out
#define KERNEL_mt6306_set_gpio_dir connectivity_export_mt6306_set_gpio_dir
void connectivity_export_mt6306_set_gpio_out(unsigned long pin,
unsigned long output);
void connectivity_export_mt6306_set_gpio_dir(unsigned long pin,
unsigned long dir);
#endif
#ifdef CONFIG_ARCH_MT6570
#define CPU_BOOST y
#endif
#ifdef CONFIG_ARCH_MT6755
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6757
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6758
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6763
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6799
#define CPU_BOOST y
#endif
#ifdef CONFIG_MACH_MT6739
#define CPU_BOOST y
#endif
#ifdef CPU_BOOST
#include "mtk_ppm_api.h"
#include "mtk_spm_resource_req.h"
#endif
#define KERNEL_show_stack connectivity_export_show_stack
#define KERNEL_tracing_record_cmdline connectivity_export_tracing_record_cmdline
#define KERNEL_dump_thread_state connectivity_export_dump_thread_state
#ifdef CPU_BOOST
#define KERNEL_mt_ppm_sysboost_freq connectivity_export_mt_ppm_sysboost_freq
#define KERNEL_mt_ppm_sysboost_core connectivity_export_mt_ppm_sysboost_core
#define KERNEL_mt_ppm_sysboost_set_core_limit \
connectivity_export_mt_ppm_sysboost_set_core_limit
#define KERNEL_mt_ppm_sysboost_set_freq_limit \
connectivity_export_mt_ppm_sysboost_set_freq_limit
#define KERNEL_spm_resource_req connectivity_export_spm_resource_req
#else
#define KERNEL_mt_ppm_sysboost_freq
#define KERNEL_mt_ppm_sysboost_core
#define KERNEL_mt_ppm_sysboost_set_core_limit
#define KERNEL_mt_ppm_sysboost_set_freq_limit
#define KERNEL_spm_resource_req
#endif
extern void tracing_record_cmdline(struct task_struct *tsk);
extern void show_stack(struct task_struct *tsk, unsigned long *sp);
#ifdef CPU_BOOST
extern void mt_ppm_sysboost_freq(enum ppm_sysboost_user user,
unsigned int freq);
extern void mt_ppm_sysboost_core(enum ppm_sysboost_user user,
unsigned int core_num);
extern void mt_ppm_sysboost_set_core_limit(enum ppm_sysboost_user user,
unsigned int cluster,
int min_core, int max_core);
extern void mt_ppm_sysboost_set_freq_limit(enum ppm_sysboost_user user,
unsigned int cluster,
int min_freq, int max_freq);
extern bool spm_resource_req(unsigned int user, unsigned int req_mask);
#endif
#ifdef CONFIG_ARM64
extern void __flush_dcache_area(void *addr, size_t len);
#else
extern void v7_flush_kern_dcache_area(void *addr, size_t len);
#endif
void connectivity_export_show_stack(struct task_struct *tsk, unsigned long *sp);
void connectivity_export_dump_thread_state(const char *name);
void connectivity_export_tracing_record_cmdline(struct task_struct *tsk);
struct connsys_state_info {
unsigned int chip_info;
phys_addr_t emi_phy_addr;
};
void connectivity_export_conap_scp_init(unsigned int chip_info, phys_addr_t emi_phy_addr);
void connectivity_export_conap_scp_deinit(void);
void connectivity_register_state_notifier(struct notifier_block *nb);
void connectivity_unregister_state_notifier(struct notifier_block *nb);
#ifdef CPU_BOOST
void connectivity_export_mt_ppm_sysboost_freq(enum ppm_sysboost_user user,
unsigned int freq);
void connectivity_export_mt_ppm_sysboost_core(enum ppm_sysboost_user user,
unsigned int core_num);
void connectivity_export_mt_ppm_sysboost_set_core_limit(
enum ppm_sysboost_user user,
unsigned int cluster,
int min_core, int max_core);
void connectivity_export_mt_ppm_sysboost_set_freq_limit(
enum ppm_sysboost_user user,
unsigned int cluster,
int min_freq, int max_freq);
bool connectivity_export_spm_resource_req(unsigned int user,
unsigned int req_mask);
#endif
/*********************************************
* copy from
* kernel-3.18/include/linux/ftrace_event.h
* kernel-4.4/include/linux/trace_events.h
*
* event_trace_printk()
*********************************************/
#ifndef CONFIG_MACH_MT6739
#define KERNEL_event_trace_printk(ip, fmt, args...) \
do { \
__trace_printk_check_format(fmt, ##args); \
KERNEL_tracing_record_cmdline(current); \
if (__builtin_constant_p(fmt)) { \
static const char *trace_printk_fmt \
__attribute__((section("__trace_printk_fmt"))) = \
__builtin_constant_p(fmt) ? fmt : NULL; \
__trace_bprintk(ip, trace_printk_fmt, ##args); \
} else \
__trace_printk(ip, fmt, ##args); \
} while (0)
#endif
/******************************************************************************
* GPIO dump information
******************************************************************************/
#ifndef CONFIG_MTK_GPIO
#define KERNEL_gpio_dump_regs_range connectivity_export_dump_gpio_info
extern void gpio_dump_regs_range(int start, int end);
void connectivity_export_dump_gpio_info(int start, int end);
#endif
int connectivity_export_gpio_get_tristate_input(unsigned int pin);
#endif /* CONNECTIVITY_BUILD_IN_ADAPTER_H */
@@ -0,0 +1,392 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/kernel.h>
#include "wmt_build_in_adapter.h"
#include <linux/string.h>
#include <linux/printk.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/ctype.h>
#include <linux/cdev.h>
/*device tree mode*/
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/irqreturn.h>
#include <linux/of_address.h>
#endif
#include <linux/interrupt.h>
#include <linux/ratelimit.h>
#define CONNADP_LOG_LOUD 4
#define CONNADP_LOG_DBG 3
#define CONNADP_LOG_INFO 2
#define CONNADP_LOG_WARN 1
#define CONNADP_LOG_ERR 0
/*******************************************************************************
* Connsys adaptation layer logging utility
******************************************************************************/
static unsigned int gConnAdpDbgLvl = CONNADP_LOG_INFO;
#define CONNADP_LOUD_FUNC(fmt, arg...) \
do { \
if (gConnAdpDbgLvl >= CONNADP_LOG_LOUD) \
pr_info("[L]%s:" fmt, __func__, ##arg); \
} while (0)
#define CONNADP_DBG_FUNC(fmt, arg...) \
do { \
if (gConnAdpDbgLvl >= CONNADP_LOG_DBG) \
pr_info("[D]%s:" fmt, __func__, ##arg); \
} while (0)
#define CONNADP_INFO_FUNC(fmt, arg...) \
do { \
if (gConnAdpDbgLvl >= CONNADP_LOG_INFO) \
pr_info("[I]%s:" fmt, __func__, ##arg); \
} while (0)
#define CONNADP_WARN_FUNC(fmt, arg...) \
do { \
if (gConnAdpDbgLvl >= CONNADP_LOG_WARN) \
pr_info("[W]%s:" fmt, __func__, ##arg); \
} while (0)
#define CONNADP_ERR_FUNC(fmt, arg...) \
do { \
if (gConnAdpDbgLvl >= CONNADP_LOG_ERR) \
pr_info("[E]%s(%d):" fmt, __func__, __LINE__, ##arg); \
} while (0)
/* device node related macro */
#define CONN_DBG_DEV_NUM 1
#define CONN_DBG_DRVIER_NAME "conn_dbg_drv"
#define CONN_DBG_DEVICE_NAME "conn_dbg_dev"
#define CONN_DBG_DEV_MAJOR 156
/* device node related */
static int gConnDbgMajor = CONN_DBG_DEV_MAJOR;
static struct class *pConnDbgClass;
static struct device *pConnDbgDev;
static struct cdev gConnDbgdev;
/*******************************************************************************
* Bridging from platform -> wmt_drv.ko
******************************************************************************/
static struct wmt_platform_bridge bridge;
ssize_t conn_dbg_dev_write(struct file *filp, const char __user *buffer,
size_t count, loff_t *f_pos)
{
if (bridge.debug_write_cb)
return bridge.debug_write_cb(filp, buffer, count, f_pos);
return 0;
}
ssize_t conn_dbg_dev_read(struct file *filp, char __user *buffer,
size_t count, loff_t *f_pos)
{
if (bridge.debug_read_cb)
return bridge.debug_read_cb(filp, buffer, count, f_pos);
return 0;
}
const struct file_operations gConnDbgDevFops = {
.write = conn_dbg_dev_write,
.read = conn_dbg_dev_read,
};
static int conn_dbg_dev_init(void)
{
dev_t dev_id = MKDEV(gConnDbgMajor, 0);
int ret = 0;
ret = register_chrdev_region(dev_id, CONN_DBG_DEV_NUM, CONN_DBG_DRVIER_NAME);
if (ret) {
pr_info("%s fail to register chrdev.(%d)\n", __func__, ret);
return -1;
}
cdev_init(&gConnDbgdev, &gConnDbgDevFops);
gConnDbgdev.owner = THIS_MODULE;
ret = cdev_add(&gConnDbgdev, dev_id, CONN_DBG_DEV_NUM);
if (ret) {
pr_info("cdev_add() fails (%d)\n", ret);
goto err1;
}
pConnDbgClass = class_create(THIS_MODULE, CONN_DBG_DEVICE_NAME);
if (IS_ERR(pConnDbgClass)) {
pr_info("class create fail, error code(%ld)\n", PTR_ERR(pConnDbgClass));
goto err2;
}
pConnDbgDev = device_create(pConnDbgClass, NULL, dev_id, NULL, CONN_DBG_DEVICE_NAME);
if (IS_ERR(pConnDbgDev)) {
pr_info("device create fail, error code(%ld)\n", PTR_ERR(pConnDbgDev));
goto err3;
}
return 0;
err3:
pr_info("[%s] err3", __func__);
if (pConnDbgClass) {
class_destroy(pConnDbgClass);
pConnDbgClass = NULL;
}
err2:
pr_info("[%s] err2", __func__);
cdev_del(&gConnDbgdev);
err1:
pr_info("[%s] err1", __func__);
unregister_chrdev_region(dev_id, CONN_DBG_DEV_NUM);
return -1;
}
static int conn_dbg_dev_deinit(void)
{
dev_t dev_id = MKDEV(gConnDbgMajor, 0);
if (pConnDbgDev) {
device_destroy(pConnDbgClass, dev_id);
pConnDbgDev = NULL;
}
if (pConnDbgClass) {
class_destroy(pConnDbgClass);
pConnDbgClass = NULL;
}
cdev_del(&gConnDbgdev);
unregister_chrdev_region(dev_id, CONN_DBG_DEV_NUM);
return 0;
}
void wmt_export_platform_bridge_register(struct wmt_platform_bridge *cb)
{
if (unlikely(!cb))
return;
bridge.thermal_query_cb = cb->thermal_query_cb;
bridge.trigger_assert_cb = cb->trigger_assert_cb;
bridge.clock_fail_dump_cb = cb->clock_fail_dump_cb;
bridge.conninfra_reg_readable_cb = cb->conninfra_reg_readable_cb;
bridge.conninfra_reg_is_bus_hang_cb = cb->conninfra_reg_is_bus_hang_cb;
if (cb->debug_write_cb != NULL && cb->debug_read_cb != NULL) {
bridge.debug_write_cb = cb->debug_write_cb;
bridge.debug_read_cb = cb->debug_read_cb;
conn_dbg_dev_init();
}
CONNADP_INFO_FUNC("\n");
}
EXPORT_SYMBOL(wmt_export_platform_bridge_register);
void wmt_export_platform_bridge_unregister(void)
{
if (bridge.debug_write_cb && bridge.debug_read_cb)
conn_dbg_dev_deinit();
memset(&bridge, 0, sizeof(struct wmt_platform_bridge));
CONNADP_INFO_FUNC("\n");
}
EXPORT_SYMBOL(wmt_export_platform_bridge_unregister);
int mtk_wcn_cmb_stub_query_ctrl(void)
{
CONNADP_DBG_FUNC("\n");
if (unlikely(!bridge.thermal_query_cb)) {
CONNADP_WARN_FUNC("Thermal query not registered\n");
return -1;
} else
return bridge.thermal_query_cb();
}
int mtk_wcn_cmb_stub_trigger_assert(void)
{
CONNADP_DBG_FUNC("\n");
/* dump backtrace for checking assert reason */
dump_stack();
if (unlikely(!bridge.trigger_assert_cb)) {
CONNADP_WARN_FUNC("Trigger assert not registered\n");
return -1;
} else
return bridge.trigger_assert_cb();
}
void mtk_wcn_cmb_stub_clock_fail_dump(void)
{
CONNADP_DBG_FUNC("\n");
if (unlikely(!bridge.clock_fail_dump_cb))
CONNADP_WARN_FUNC("Clock fail dump not registered\n");
else
bridge.clock_fail_dump_cb();
}
int mtk_wcn_conninfra_reg_readable(void)
{
static DEFINE_RATELIMIT_STATE(_rs, 5*HZ, 1);
if (unlikely(!bridge.conninfra_reg_readable_cb)) {
if (__ratelimit(&_rs))
CONNADP_WARN_FUNC("reg_readable not registered\n");
return -1;
} else
return bridge.conninfra_reg_readable_cb();
}
int mtk_wcn_conninfra_is_bus_hang(void)
{
static DEFINE_RATELIMIT_STATE(_rs, 5*HZ, 1);
if (unlikely(!bridge.conninfra_reg_is_bus_hang_cb)) {
if (__ratelimit(&_rs))
CONNADP_WARN_FUNC("is_bus_hang not registered\n");
return -1;
} else
return bridge.conninfra_reg_is_bus_hang_cb();
}
/*******************************************************************************
* SDIO integration with platform MMC driver
******************************************************************************/
static void mtk_wcn_cmb_sdio_request_eirq(msdc_sdio_irq_handler_t irq_handler,
void *data);
static void mtk_wcn_cmb_sdio_enable_eirq(void);
static void mtk_wcn_cmb_sdio_disable_eirq(void);
static void mtk_wcn_cmb_sdio_register_pm(pm_callback_t pm_cb, void *data);
struct sdio_ops mt_sdio_ops[4] = {
{NULL, NULL, NULL, NULL},
{NULL, NULL, NULL, NULL},
{mtk_wcn_cmb_sdio_request_eirq, mtk_wcn_cmb_sdio_enable_eirq,
mtk_wcn_cmb_sdio_disable_eirq, mtk_wcn_cmb_sdio_register_pm},
{mtk_wcn_cmb_sdio_request_eirq, mtk_wcn_cmb_sdio_enable_eirq,
mtk_wcn_cmb_sdio_disable_eirq, mtk_wcn_cmb_sdio_register_pm}
};
static atomic_t sdio_claim_irq_enable_flag;
static atomic_t irq_enable_flag;
static msdc_sdio_irq_handler_t mtk_wcn_cmb_sdio_eirq_handler;
static void *mtk_wcn_cmb_sdio_eirq_data;
unsigned int wifi_irq = 0xffffffff;
EXPORT_SYMBOL(wifi_irq);
pm_callback_t mtk_wcn_cmb_sdio_pm_cb;
EXPORT_SYMBOL(mtk_wcn_cmb_sdio_pm_cb);
void *mtk_wcn_cmb_sdio_pm_data;
EXPORT_SYMBOL(mtk_wcn_cmb_sdio_pm_data);
static int _mtk_wcn_sdio_irq_flag_set(int flag)
{
if (flag != 0)
atomic_set(&sdio_claim_irq_enable_flag, 1);
else
atomic_set(&sdio_claim_irq_enable_flag, 0);
CONNADP_DBG_FUNC("sdio_claim_irq_enable_flag:%d\n",
atomic_read(&sdio_claim_irq_enable_flag));
return atomic_read(&sdio_claim_irq_enable_flag);
}
int wmt_export_mtk_wcn_sdio_irq_flag_set(int flag)
{
return _mtk_wcn_sdio_irq_flag_set(flag);
}
EXPORT_SYMBOL(wmt_export_mtk_wcn_sdio_irq_flag_set);
static irqreturn_t mtk_wcn_cmb_sdio_eirq_handler_stub(int irq, void *data)
{
if ((mtk_wcn_cmb_sdio_eirq_handler != NULL) &&
(atomic_read(&sdio_claim_irq_enable_flag) != 0))
mtk_wcn_cmb_sdio_eirq_handler(mtk_wcn_cmb_sdio_eirq_data);
return IRQ_HANDLED;
}
static void mtk_wcn_cmb_sdio_request_eirq(msdc_sdio_irq_handler_t irq_handler,
void *data)
{
#ifdef CONFIG_OF
struct device_node *node;
int ret = -EINVAL;
CONNADP_INFO_FUNC("enter\n");
_mtk_wcn_sdio_irq_flag_set(0);
atomic_set(&irq_enable_flag, 1);
mtk_wcn_cmb_sdio_eirq_data = data;
mtk_wcn_cmb_sdio_eirq_handler = irq_handler;
node = (struct device_node *)of_find_compatible_node(NULL, NULL,
"mediatek,connectivity-combo");
if (node) {
wifi_irq = irq_of_parse_and_map(node, 0);/* get wifi eint num */
ret = request_irq(wifi_irq, mtk_wcn_cmb_sdio_eirq_handler_stub,
IRQF_TRIGGER_LOW, "WIFI-eint", NULL);
CONNADP_DBG_FUNC("WIFI EINT irq %d !!\n", wifi_irq);
if (ret)
CONNADP_WARN_FUNC("WIFI EINT LINE NOT AVAILABLE!!\n");
else
mtk_wcn_cmb_sdio_disable_eirq();/*state:power off*/
} else
CONNADP_WARN_FUNC("can't find connectivity compatible node\n");
CONNADP_INFO_FUNC("exit\n");
#else
CONNADP_ERR_FUNC("not implemented\n");
#endif
}
static void mtk_wcn_cmb_sdio_register_pm(pm_callback_t pm_cb, void *data)
{
CONNADP_DBG_FUNC("cmb_sdio_register_pm (0x%p, 0x%p)\n", pm_cb, data);
/* register pm change callback */
mtk_wcn_cmb_sdio_pm_cb = pm_cb;
mtk_wcn_cmb_sdio_pm_data = data;
}
static void mtk_wcn_cmb_sdio_enable_eirq(void)
{
if (atomic_read(&irq_enable_flag))
CONNADP_DBG_FUNC("wifi eint has been enabled\n");
else {
atomic_set(&irq_enable_flag, 1);
if (wifi_irq != 0xfffffff) {
enable_irq(wifi_irq);
CONNADP_DBG_FUNC(" enable WIFI EINT %d!\n", wifi_irq);
}
}
}
static void mtk_wcn_cmb_sdio_disable_eirq(void)
{
if (!atomic_read(&irq_enable_flag))
CONNADP_DBG_FUNC("wifi eint has been disabled!\n");
else {
if (wifi_irq != 0xfffffff) {
disable_irq_nosync(wifi_irq);
CONNADP_DBG_FUNC("disable WIFI EINT %d!\n", wifi_irq);
}
atomic_set(&irq_enable_flag, 0);
}
}
void wmt_export_mtk_wcn_cmb_sdio_disable_eirq(void)
{
mtk_wcn_cmb_sdio_disable_eirq();
}
EXPORT_SYMBOL(wmt_export_mtk_wcn_cmb_sdio_disable_eirq);
@@ -0,0 +1,52 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef WMT_BUILD_IN_ADAPTER_H
#define WMT_BUILD_IN_ADAPTER_H
#include <mtk_wcn_cmb_stub.h>
#include <linux/types.h>
#include <linux/fs.h>
/*******************************************************************************
* Bridging from platform -> wmt_drv.ko
******************************************************************************/
typedef int (*wmt_bridge_thermal_query_cb)(void);
typedef int (*wmt_bridge_trigger_assert_cb)(void);
typedef void (*wmt_bridge_connsys_clock_fail_dump_cb)(void);
typedef int (*wmt_bridge_conninfra_reg_readable)(void);
typedef int (*wmt_bridge_conninfra_reg_is_bus_hang)(void);
typedef ssize_t (*wmt_bridge_debug_write_cb)(struct file *, const char __user *, size_t, loff_t *);
typedef ssize_t (*wmt_bridge_debug_read_cb)(struct file *, char __user *, size_t, loff_t *);
struct wmt_platform_bridge {
wmt_bridge_thermal_query_cb thermal_query_cb;
wmt_bridge_trigger_assert_cb trigger_assert_cb;
wmt_bridge_connsys_clock_fail_dump_cb clock_fail_dump_cb;
wmt_bridge_debug_write_cb debug_write_cb;
wmt_bridge_debug_read_cb debug_read_cb;
/* for CONNAC 2 */
wmt_bridge_conninfra_reg_readable conninfra_reg_readable_cb;
wmt_bridge_conninfra_reg_is_bus_hang conninfra_reg_is_bus_hang_cb;
};
void wmt_export_platform_bridge_register(struct wmt_platform_bridge *cb);
void wmt_export_platform_bridge_unregister(void);
/*******************************************************************************
* SDIO integration with platform MMC driver
******************************************************************************/
extern unsigned int wifi_irq;
extern pm_callback_t mtk_wcn_cmb_sdio_pm_cb;
extern void *mtk_wcn_cmb_sdio_pm_data;
void wmt_export_mtk_wcn_cmb_sdio_disable_eirq(void);
int wmt_export_mtk_wcn_sdio_irq_flag_set(int flag);
#endif /* WMT_BUILD_IN_ADAPTER_H */
@@ -0,0 +1,584 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/string.h>
#include <linux/printk.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/ctype.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/sched/clock.h>
#if IS_ENABLED(CONFIG_COMPAT)
#include <linux/compat.h>
#endif
#include "conn_power_throttling.h"
#if IS_ENABLED(CONFIG_MTK_LOW_BATTERY_POWER_THROTTLING)
#include <mtk_low_battery_throttling.h>
#endif
/* termal related macro */
#if IS_ENABLED(CONFIG_MTK_LOW_BATTERY_POWER_THROTTLING)
//#define CONN_PWR_LOW_BATTERY_ENABLE
#endif
#define CONN_PWR_INVALID_TEMP (-888)
#define CONN_PWR_MAX_TEMP_HIGH 110
#if IS_ENABLED(CONFIG_CONN_PWR_DEBUG)
#define CONN_PWR_MAX_TEMP_LOW 0
#else
#define CONN_PWR_MAX_TEMP_LOW 60
#endif
/* device node related macro */
#define CONN_PWR_DEV_NUM 1
#define CONN_PWR_DRVIER_NAME "conn_pwr_drv"
#define CONN_PWR_DEVICE_NAME "conn_pwr_dev"
#define CONN_PWR_DEV_MAJOR 155
#define CONN_PWR_DEV_IOC_MAGIC 0xc2
#define CONN_PWR_IOCTL_SET_MAX_TEMP _IOW(CONN_PWR_DEV_IOC_MAGIC, 0, int)
#define CONN_PWR_IOCTL_GET_DRV_LEVEL _IOR(CONN_PWR_DEV_IOC_MAGIC, 1, int)
#define CONN_PWR_IOCTL_GET_PLAT_LEVEL _IOR(CONN_PWR_DEV_IOC_MAGIC, 2, int)
#define CONN_PWR_SWITCH_LEVEL_MIN_SEC 30
#define CONN_PWR_SWITCH_LEVEL_GPS_MIN_SEC 5
#define CONN_CUSTOMER_SET_LEVEL_SUCCESS 0
#define CONN_CUSTOMER_SET_LEVEL_FAILED -1
static struct conn_pwr_plat_info g_plat_info;
static CONN_PWR_EVENT_CB g_event_cb_tbl[CONN_PWR_DRV_MAX];
static int g_drv_status_tbl[CONN_PWR_DRV_MAX];
#ifdef CONN_PWR_LOW_BATTERY_ENABLE
static int g_low_battery_level = LOW_BATTERY_LEVEL_0;
#else
static int g_low_battery_level;
#endif
static int g_max_temp = CONN_PWR_MAX_TEMP_HIGH;
static int g_connsys_temp = CONN_PWR_INVALID_TEMP;
static unsigned int g_customer_level;
static unsigned long long g_radio_last_updated_time[CONN_PWR_DRV_MAX];
/* device node related */
static int gConnPwrMajor = CONN_PWR_DEV_MAJOR;
static struct class *pConnPwrClass;
static struct device *pConnPwrDev;
static struct cdev gConnPwrdev;
#if IS_ENABLED(CONFIG_CONN_PWR_DEBUG)
extern ssize_t conn_pwr_dev_write(struct file *filp, const char __user *buffer, size_t count,
loff_t *f_pos);
#endif
static long conn_pwr_dev_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
#if IS_ENABLED(CONFIG_COMPAT)
static long conn_pwr_dev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
#endif
const struct file_operations gConnPwrDevFops = {
#if IS_ENABLED(CONFIG_CONN_PWR_DEBUG)
.write = conn_pwr_dev_write,
#endif
.unlocked_ioctl = conn_pwr_dev_unlocked_ioctl,
#if IS_ENABLED(CONFIG_COMPAT)
.compat_ioctl = conn_pwr_dev_compat_ioctl,
#endif
};
void conn_pwr_get_local_time(unsigned long long *sec, unsigned long *usec)
{
if (sec != NULL && usec != NULL) {
*sec = local_clock();
*usec = do_div(*sec, 1000000000)/1000;
} else
pr_info("The input parameters error when get local time\n");
}
int conn_pwr_enable(int enable)
{
conn_pwr_core_enable(enable);
return 0;
}
EXPORT_SYMBOL(conn_pwr_enable);
int conn_pwr_send_msg(enum conn_pwr_drv_type drv, enum conn_pwr_msg_type msg, void *data)
{
struct conn_pwr_update_info info = {0};
if (drv < 0 || drv >= CONN_PWR_DRV_MAX || msg < 0 || msg > CONN_PWR_MSG_MAX) {
pr_info("%s, invalid parameter. drv (%d), msg(%d)", __func__, drv, msg);
return -1;
}
if (msg == CONN_PWR_MSG_TEMP_TOO_HIGH) {
if (data != NULL) {
g_connsys_temp = *((int *)data);
pr_info("%s drv:%d, msg: %d, temp: %d\n", __func__, drv, msg,
*((int *)data));
}
info.reason = CONN_PWR_ARB_TEMP_CHECK;
info.drv = drv;
conn_pwr_arbitrate(&info);
} else if (msg == CONN_PWR_MSG_TEMP_RECOVERY) {
if (data != NULL) {
g_connsys_temp = *((int *)data);
pr_info("%s drv:%d, msg: %d, temp: %d\n", __func__, drv, msg,
*((int *)data));
}
info.reason = CONN_PWR_ARB_TEMP_CHECK;
info.drv = drv;
conn_pwr_arbitrate(&info);
} else if (msg == CONN_PWR_MSG_GET_TEMP && data != NULL) {
struct conn_pwr_event_max_temp *d = (struct conn_pwr_event_max_temp *)data;
conn_pwr_get_thermal(d);
pr_info("%s drv:%d, msg: %d, max: %d, recovery: %d\n", __func__, drv, msg,
d->max_temp, d->recovery_temp);
}
if (data == NULL)
pr_info("%s drv:%d, msg: %d\n", __func__, drv, msg);
return 0;
}
EXPORT_SYMBOL(conn_pwr_send_msg);
int conn_pwr_set_max_temp(unsigned long arg)
{
struct conn_pwr_update_info info;
if (g_max_temp == arg || arg > CONN_PWR_MAX_TEMP_HIGH || arg < CONN_PWR_MAX_TEMP_LOW) {
pr_info("%s, max temp is not updated. old(%d), new(%lu)", __func__,
g_max_temp, arg);
return 0;
}
pr_info("%s, max temp is adjusted to %lu from %d\n", __func__, arg, g_max_temp);
g_max_temp = arg;
info.reason = CONN_PWR_ARB_THERMAL;
conn_pwr_arbitrate(&info);
return 0;
}
int conn_pwr_set_battery_level(int level)
{
struct conn_pwr_update_info info;
pr_info("%s level = %d\n", __func__, level);
#if IS_ENABLED(CONFIG_MTK_LOW_BATTERY_POWER_THROTTLING)
if (level < LOW_BATTERY_LEVEL_0 || level > LOW_BATTERY_LEVEL_2) {
pr_info("invalid level %d\n", level);
return -1;
}
#endif
g_low_battery_level = level;
info.reason = CONN_PWR_ARB_LOW_BATTERY;
conn_pwr_arbitrate(&info);
return 0;
}
static long conn_pwr_dev_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int ret = 0;
pr_info("[%s] cmd (%d),arg (%ld)\n", __func__, cmd, arg);
switch (cmd) {
case CONN_PWR_IOCTL_SET_MAX_TEMP:
ret = conn_pwr_set_max_temp(arg);
break;
case CONN_PWR_IOCTL_GET_DRV_LEVEL:
conn_pwr_get_drv_level(arg, (enum conn_pwr_low_battery_level *)&ret);
break;
case CONN_PWR_IOCTL_GET_PLAT_LEVEL:
conn_pwr_get_platform_level(arg, (int *)&ret);
break;
default:
break;
}
return ret;
}
#if IS_ENABLED(CONFIG_COMPAT)
static long conn_pwr_dev_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
pr_info("[%s] cmd (%d)\n", __func__, cmd);
return conn_pwr_dev_unlocked_ioctl(filp, cmd, arg);
}
#endif
#ifdef CONN_PWR_LOW_BATTERY_ENABLE
static void conn_pwr_low_battery_cb(enum LOW_BATTERY_LEVEL_TAG level)
{
conn_pwr_set_battery_level(level);
}
#endif
int conn_pwr_get_plat_level(enum conn_pwr_plat_type type, int *data)
{
if (data == NULL) {
pr_info("%s: data is NULL.\n", __func__);
return -1;
}
if (type == CONN_PWR_PLAT_LOW_BATTERY)
*data = g_low_battery_level;
else if (type == CONN_PWR_PLAT_THERMAL)
*data = g_max_temp;
else if (type == CONN_PWR_PLAT_CUSTOMER)
*data = g_customer_level;
else {
pr_info("type %d is out of range.\n", type);
return -2;
}
pr_info("%s ,type = %d, ret = %d\n", __func__, type, *data);
return 0;
}
int conn_pwr_set_customer_level(enum conn_pwr_drv_type type, enum conn_pwr_low_battery_level level)
{
struct conn_pwr_update_info info = {0};
int i;
int updated = 0;
unsigned long long sec;
unsigned long usec;
int ret = CONN_CUSTOMER_SET_LEVEL_SUCCESS;
unsigned int inactive_time = 0;
if (type < CONN_PRW_DRV_ALL || type >= CONN_PWR_DRV_MAX || level < CONN_PWR_THR_LV_0 ||
level >= CONN_PWR_LOW_BATTERY_MAX) {
pr_info("%s, invalid parameter, type = %d, level = %d\n", __func__, type, level);
return CONN_CUSTOMER_SET_LEVEL_FAILED;
}
conn_pwr_get_local_time(&sec, &usec);
if (type == CONN_PRW_DRV_ALL) {
for (i = 0; i < CONN_PWR_DRV_MAX; i++) {
if (i == CONN_PWR_DRV_GPS)
inactive_time = CONN_PWR_SWITCH_LEVEL_GPS_MIN_SEC;
else
inactive_time = CONN_PWR_SWITCH_LEVEL_MIN_SEC;
if (sec > (g_radio_last_updated_time[i] + inactive_time) ||
g_radio_last_updated_time[i] > sec) {
updated = 1;
} else {
updated = 0;
break;
}
}
if (updated) {
CONN_PWR_SET_CUSTOMER_POWER_LEVEL(g_customer_level, CONN_PWR_DRV_BT, level);
CONN_PWR_SET_CUSTOMER_POWER_LEVEL(g_customer_level, CONN_PWR_DRV_FM, level);
CONN_PWR_SET_CUSTOMER_POWER_LEVEL(g_customer_level, CONN_PWR_DRV_GPS,
level);
CONN_PWR_SET_CUSTOMER_POWER_LEVEL(g_customer_level, CONN_PWR_DRV_WIFI,
level);
g_radio_last_updated_time[CONN_PWR_DRV_BT] = sec;
g_radio_last_updated_time[CONN_PWR_DRV_FM] = sec;
g_radio_last_updated_time[CONN_PWR_DRV_GPS] = sec;
g_radio_last_updated_time[CONN_PWR_DRV_WIFI] = sec;
}
} else {
if (type == CONN_PWR_DRV_GPS)
inactive_time = CONN_PWR_SWITCH_LEVEL_GPS_MIN_SEC;
else
inactive_time = CONN_PWR_SWITCH_LEVEL_MIN_SEC;
if (sec > (g_radio_last_updated_time[type] + inactive_time) ||
g_radio_last_updated_time[type] > sec) {
g_radio_last_updated_time[type] = sec;
updated = 1;
}
if (updated)
CONN_PWR_SET_CUSTOMER_POWER_LEVEL(g_customer_level, type, level);
}
if (updated) {
info.reason = CONN_PWR_ARB_CUSTOMER;
info.drv = type;
conn_pwr_arbitrate(&info);
}
pr_info("%s, type = %d, level = %d, customer_level = %d, updated = %d\n", __func__,
type, level, g_customer_level, updated);
if (updated == 0) {
pr_info("%s, Set Level failed within %d, %llu (%llu, %llu, %llu, %llu)\n", __func__,
CONN_PWR_SWITCH_LEVEL_MIN_SEC, sec,
g_radio_last_updated_time[CONN_PWR_DRV_BT],
g_radio_last_updated_time[CONN_PWR_DRV_FM],
g_radio_last_updated_time[CONN_PWR_DRV_GPS],
g_radio_last_updated_time[CONN_PWR_DRV_WIFI]);
ret = CONN_CUSTOMER_SET_LEVEL_FAILED;
}
return ret;
}
EXPORT_SYMBOL(conn_pwr_set_customer_level);
int conn_pwr_get_chip_id(void)
{
return g_plat_info.chip_id;
}
int conn_pwr_get_adie_id(void)
{
return g_plat_info.adie_id;
}
int conn_pwr_get_temp(int *temp, int cached)
{
int ret = 0;
if ((g_connsys_temp == CONN_PWR_INVALID_TEMP || cached == 0) && g_plat_info.get_temp) {
ret = (*g_plat_info.get_temp)(temp);
if (ret == 0)
g_connsys_temp = *temp;
} else if (cached > 0 && g_connsys_temp != CONN_PWR_INVALID_TEMP) {
*temp = g_connsys_temp;
} else {
ret = -1;
pr_info("%s, get_temp is NULL/n", __func__);
}
pr_info("%s, ret = %d, temp = %d, cached = %d\n", __func__, ret, *temp, cached);
return ret;
}
int conn_pwr_notify_event(enum conn_pwr_drv_type drv, enum conn_pwr_event_type event, void *data)
{
int ret;
struct conn_pwr_event_max_temp *d;
if (drv < 0 || drv >= CONN_PWR_DRV_MAX || event < 0 || event >= CONN_PWR_EVENT_MAX) {
pr_info("drv %d or event %d is out of range.\n", drv, event);
return -1;
}
if (g_event_cb_tbl[drv] == NULL) {
pr_info("event cb is not registered.\n", drv);
return -2;
}
ret = (*g_event_cb_tbl[drv])(event, data);
if (event == CONN_PWR_EVENT_LEVEL)
pr_info("%s, drv = %d, level = %d, ret = %d\n", __func__, drv, *((int *)data), ret);
else if (event == CONN_PWR_EVENT_MAX_TEMP && data != NULL) {
d = (struct conn_pwr_event_max_temp *)data;
pr_info("%s, drv = %d, max_t = %d, rcv_t = %d, ret = %d\n", __func__,
drv, d->max_temp, d->recovery_temp, ret);
} else {
pr_info("invalid. event = %d, data = %d\n", event, drv);
return -3;
}
return ret;
}
int conn_pwr_get_drv_status(enum conn_pwr_drv_type type)
{
if (type < 0 || type >= CONN_PWR_DRV_MAX) {
pr_info("type %d is out of range.\n", type);
return -1;
}
return g_drv_status_tbl[type];
}
static int conn_pwr_set_drv_status(enum conn_pwr_drv_type type, enum conn_pwr_drv_status status)
{
struct conn_pwr_update_info info;
pr_info("%s, type = %d, status = %x\n", __func__, type, status);
if (type < 0 || type >= CONN_PWR_DRV_MAX) {
pr_info("type %d is out of range.\n", type);
return -1;
}
if (status != CONN_PWR_DRV_STATUS_OFF && status != CONN_PWR_DRV_STATUS_ON) {
pr_info("status %d is invalid.\n", status);
return -2;
}
if (g_drv_status_tbl[type] == status) {
pr_info("status is not changed.\n");
return 0;
}
g_drv_status_tbl[type] = status;
info.reason = CONN_PWR_ARB_SUBSYS_ON_OFF;
info.drv = type;
info.status = status;
conn_pwr_arbitrate(&info);
return 0;
}
int conn_pwr_drv_pre_on(enum conn_pwr_drv_type type, enum conn_pwr_low_battery_level *level)
{
int ret;
ret = conn_pwr_set_drv_status(type, CONN_PWR_DRV_STATUS_ON);
if (ret == 0)
ret = conn_pwr_get_drv_level(type, level);
pr_info("%s, ret = %d, type = %d, level = %d\n", __func__, ret, type, *level);
return ret;
}
EXPORT_SYMBOL(conn_pwr_drv_pre_on);
int conn_pwr_drv_post_off(enum conn_pwr_drv_type type)
{
pr_info("%s type = %d", __func__, type);
return conn_pwr_set_drv_status(type, CONN_PWR_DRV_STATUS_OFF);
}
EXPORT_SYMBOL(conn_pwr_drv_post_off);
int conn_pwr_register_event_cb(enum conn_pwr_drv_type type,
CONN_PWR_EVENT_CB cb)
{
pr_info("%s, type = %d, cb = %p\n", __func__, type, cb);
if (type < 0 || type >= CONN_PWR_DRV_MAX) {
pr_info("type %d is out of range.\n", type);
return -1;
}
g_event_cb_tbl[type] = cb;
return 0;
}
EXPORT_SYMBOL(conn_pwr_register_event_cb);
static int conn_pwr_dev_init(void)
{
dev_t dev_id = MKDEV(gConnPwrMajor, 0);
int ret = 0;
ret = register_chrdev_region(dev_id, CONN_PWR_DEV_NUM,
CONN_PWR_DRVIER_NAME);
if (ret) {
pr_info("fail to register chrdev.(%d)\n", ret);
return -1;
}
cdev_init(&gConnPwrdev, &gConnPwrDevFops);
gConnPwrdev.owner = THIS_MODULE;
ret = cdev_add(&gConnPwrdev, dev_id, CONN_PWR_DEV_NUM);
if (ret) {
pr_info("cdev_add() fails (%d)\n", ret);
goto err1;
}
pConnPwrClass = class_create(THIS_MODULE, CONN_PWR_DEVICE_NAME);
if (IS_ERR(pConnPwrClass)) {
pr_info("class create fail, error code(%ld)\n",
PTR_ERR(pConnPwrClass));
goto err2;
}
pConnPwrDev = device_create(pConnPwrClass, NULL, dev_id,
NULL, CONN_PWR_DEVICE_NAME);
if (IS_ERR(pConnPwrDev)) {
pr_info("device create fail, error code(%ld)\n",
PTR_ERR(pConnPwrDev));
goto err3;
}
return 0;
err3:
pr_info("[%s] err3", __func__);
if (pConnPwrClass) {
class_destroy(pConnPwrClass);
pConnPwrClass = NULL;
}
err2:
pr_info("[%s] err2", __func__);
cdev_del(&gConnPwrdev);
err1:
pr_info("[%s] err1", __func__);
unregister_chrdev_region(dev_id, CONN_PWR_DEV_NUM);
return -1;
}
static int conn_pwr_dev_deinit(void)
{
dev_t dev_id = MKDEV(gConnPwrMajor, 0);
if (pConnPwrDev) {
device_destroy(pConnPwrClass, dev_id);
pConnPwrDev = NULL;
}
if (pConnPwrClass) {
class_destroy(pConnPwrClass);
pConnPwrClass = NULL;
}
cdev_del(&gConnPwrdev);
unregister_chrdev_region(dev_id, CONN_PWR_DEV_NUM);
return 0;
}
int conn_pwr_init(struct conn_pwr_plat_info *data)
{
pr_info("%s\n", __func__);
if (data == NULL) {
pr_info("data is NULL\n");
return -1;
}
if (data->chip_id == 0 || data->get_temp == NULL) {
pr_info("%s, init data is invalid: chip_id = %d, get_temp = %p\n",
__func__, data->chip_id, data->get_temp);
return -2;
}
memcpy(&g_plat_info, data, sizeof(struct conn_pwr_plat_info));
memset(g_event_cb_tbl, 0, sizeof(g_event_cb_tbl));
memset(g_drv_status_tbl, 0, sizeof(g_drv_status_tbl));
conn_pwr_core_init();
#ifdef CONN_PWR_LOW_BATTERY_ENABLE
register_low_battery_notify(&conn_pwr_low_battery_cb, LOW_BATTERY_PRIO_WIFI);
#endif
conn_pwr_dev_init();
return 0;
}
EXPORT_SYMBOL(conn_pwr_init);
int conn_pwr_deinit(void)
{
pr_info("%s", __func__);
conn_pwr_dev_deinit();
return 0;
}
EXPORT_SYMBOL(conn_pwr_deinit);
int conn_pwr_resume(void)
{
conn_pwr_core_resume();
return 0;
}
EXPORT_SYMBOL(conn_pwr_resume);
int conn_pwr_suspend(void)
{
conn_pwr_core_suspend();
return 0;
}
EXPORT_SYMBOL(conn_pwr_suspend);
@@ -0,0 +1,143 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#define CONN_PWR_SET_CUSTOMER_POWER_LEVEL(value, index, lv) \
((value) = (((lv) << ((index) * 8)) | ((value) & ~(0xFF << ((index) * 8)))))
#define CONN_PWR_GET_CUSTOMER_POWER_LEVEL(value, index) ((value >> (index * 8)) & 0xFF)
struct conn_pwr_plat_info {
int chip_id; /* platform chip id */
int adie_id; /* a die chip id */
int (*get_temp)(int *temp); /* callback for getting connsys temperature */
};
enum conn_pwr_drv_type {
CONN_PRW_DRV_ALL = -1,
CONN_PWR_DRV_BT = 0,
CONN_PWR_DRV_FM = 1,
CONN_PWR_DRV_GPS = 2,
CONN_PWR_DRV_WIFI = 3,
CONN_PWR_DRV_MAX
};
enum conn_pwr_drv_status {
CONN_PWR_DRV_STATUS_OFF = 0,
CONN_PWR_DRV_STATUS_ON = 1,
CONN_PWR_DRV_STATUS_MAX
};
enum conn_pwr_plat_type {
CONN_PWR_PLAT_LOW_BATTERY = 0,
CONN_PWR_PLAT_THERMAL = 1,
CONN_PWR_PLAT_CUSTOMER = 2,
CONN_PWR_PLAT_MAX
};
enum conn_pwr_msg_type {
CONN_PWR_MSG_TEMP_TOO_HIGH = 0,
CONN_PWR_MSG_TEMP_RECOVERY = 1,
CONN_PWR_MSG_GET_TEMP = 2,
CONN_PWR_MSG_MAX
};
enum conn_pwr_low_battery_level {
CONN_PWR_THR_LV_0 = 0,
CONN_PWR_THR_LV_1 = 1,
CONN_PWR_THR_LV_2 = 2,
CONN_PWR_THR_LV_3 = 3,
CONN_PWR_THR_LV_4 = 4,
CONN_PWR_THR_LV_5 = 5,
CONN_PWR_LOW_BATTERY_MAX
};
enum conn_pwr_arb_reason {
CONN_PWR_ARB_SUBSYS_ON_OFF = 0,
CONN_PWR_ARB_LOW_BATTERY = 1,
CONN_PWR_ARB_THERMAL = 2,
CONN_PWR_ARB_CUSTOMER = 3,
CONN_PWR_ARB_TEMP_CHECK = 4,
CONN_PWR_ARB_MAX
};
struct conn_pwr_update_info {
enum conn_pwr_arb_reason reason;
enum conn_pwr_drv_type drv;
enum conn_pwr_drv_status status;
};
enum conn_pwr_event_type {
CONN_PWR_EVENT_LEVEL = 0,
CONN_PWR_EVENT_MAX_TEMP = 1,
CONN_PWR_EVENT_MAX
};
struct conn_pwr_event_max_temp {
int max_temp;
int recovery_temp;
};
typedef int (*CONN_PWR_EVENT_CB)(enum conn_pwr_event_type type, void *data);
/* called by conn_pwr_core */
int conn_pwr_get_chip_id(void);
int conn_pwr_get_adie_id(void);
int conn_pwr_get_temp(int *temp, int cached);
int conn_pwr_get_plat_level(enum conn_pwr_plat_type type, int *data);
int conn_pwr_get_drv_status(enum conn_pwr_drv_type type);
int conn_pwr_notify_event(enum conn_pwr_drv_type drv, enum conn_pwr_event_type event, void *data);
/* called by customer */
int conn_pwr_set_customer_level(enum conn_pwr_drv_type type, enum conn_pwr_low_battery_level level);
/* called by conn_pwr_adapter */
int conn_pwr_get_drv_level(enum conn_pwr_drv_type type, enum conn_pwr_low_battery_level *level);
/* called by conn_pwr_adapter */
int conn_pwr_get_platform_level(enum conn_pwr_plat_type type, int *level);
/* called by conn_pwr_adapter */
int conn_pwr_get_thermal(struct conn_pwr_event_max_temp *temp);
/* called by conn_pwr_adapter */
int conn_pwr_arbitrate(struct conn_pwr_update_info *info);
/* called by subsys driver */
int conn_pwr_register_event_cb(enum conn_pwr_drv_type type,
CONN_PWR_EVENT_CB cb);
/* called by subsys driver */
int conn_pwr_send_msg(enum conn_pwr_drv_type drv, enum conn_pwr_msg_type msg, void *data);
/* called by adapter */
int conn_pwr_core_init(void);
int conn_pwr_core_resume(void);
int conn_pwr_core_suspend(void);
/* called by adapter */
int conn_pwr_core_enable(int enable);
/* called by WMT/conninfra */
int conn_pwr_init(struct conn_pwr_plat_info *data);
int conn_pwr_deinit(void);
int conn_pwr_resume(void);
int conn_pwr_suspend(void);
/* called by subsys before function on */
int conn_pwr_drv_pre_on(enum conn_pwr_drv_type type, enum conn_pwr_low_battery_level *level);
/* called by subsys after function off */
int conn_pwr_drv_post_off(enum conn_pwr_drv_type type);
/* called by subsys to report min. level required */
int conn_pwr_report_level_required(enum conn_pwr_drv_type type,
enum conn_pwr_low_battery_level level);
/* called by enable/disable */
int conn_pwr_enable(int enable);
/* called by UT */
int conn_pwr_set_max_temp(unsigned long arg);
int conn_pwr_set_battery_level(int level);
@@ -0,0 +1,329 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/string.h>
#include <linux/printk.h>
#include <linux/spinlock.h>
#include "conn_power_throttling.h"
#if IS_ENABLED(CONFIG_MTK_LOW_BATTERY_POWER_THROTTLING)
#include <mtk_low_battery_throttling.h>
#endif
static unsigned int g_enable = 1;
static unsigned int g_radio_pwr_level[CONN_PWR_DRV_MAX];
static unsigned int g_platform_pwr_level[CONN_PWR_PLAT_MAX];
static struct conn_pwr_event_max_temp g_thermal_info;
static unsigned int g_last_temp;
spinlock_t pwr_core_lock;
#define CONN_PWR_THERMAL_RECOVERY_INTERVAL 10
#define CONN_PWR_THERMAL_HIGHER_INTERVAL 10
#define CONN_PWR_THERMAL_HIGHEST_INTERVAL 20
#define CONN_PWR_CONNSYS_MAX_THERMAL 100
int conn_pwr_core_init(void)
{
pr_info("%s\n", __func__);
memset(g_radio_pwr_level, CONN_PWR_THR_LV_0, sizeof(g_radio_pwr_level));
memset(g_platform_pwr_level, CONN_PWR_THR_LV_0, sizeof(g_platform_pwr_level));
g_thermal_info.max_temp = CONN_PWR_CONNSYS_MAX_THERMAL;
g_thermal_info.recovery_temp =
CONN_PWR_CONNSYS_MAX_THERMAL - CONN_PWR_THERMAL_RECOVERY_INTERVAL;
spin_lock_init(&pwr_core_lock);
return 0;
}
int conn_pwr_core_enable(int enable)
{
int i, default_lv = 0;
if (enable) {
g_enable = 1;
} else {
for (i = 0; i < CONN_PWR_DRV_MAX; i++) {
if (conn_pwr_get_drv_status(i) == CONN_PWR_DRV_STATUS_ON &&
g_radio_pwr_level[i] != default_lv) {
conn_pwr_notify_event(i, CONN_PWR_EVENT_LEVEL, &default_lv);
}
g_radio_pwr_level[i] = default_lv;
}
g_enable = 0;
}
pr_info("%s\n enable = %d", __func__, enable);
return 0;
}
int conn_pwr_core_resume(void)
{
pr_info("%s low_battery=%d, thermal=%d, customer=0x%08x\n", __func__,
g_platform_pwr_level[CONN_PWR_PLAT_LOW_BATTERY],
g_platform_pwr_level[CONN_PWR_PLAT_THERMAL],
g_platform_pwr_level[CONN_PWR_PLAT_CUSTOMER]);
pr_info("%s bt=%d, FM=%d, GPS=%d, Wi-Fi=%d\n", __func__, g_radio_pwr_level[0],
g_radio_pwr_level[1], g_radio_pwr_level[2], g_radio_pwr_level[3]);
return 0;
}
int conn_pwr_core_suspend(void)
{
return 0;
}
int conn_pwr_get_low_battery_level(struct conn_pwr_update_info *info)
{
int ret = CONN_PWR_THR_LV_0;
int low_battery_power_level = 0;
if (conn_pwr_get_plat_level(CONN_PWR_PLAT_LOW_BATTERY, &low_battery_power_level) != 0) {
pr_info("%s conn_pwr cant get battery level\n", __func__);
return ret;
}
#if IS_ENABLED(CONFIG_MTK_LOW_BATTERY_POWER_THROTTLING)
if (conn_pwr_get_drv_status(CONN_PWR_DRV_WIFI) == CONN_PWR_DRV_STATUS_ON ||
(info->reason == CONN_PWR_ARB_SUBSYS_ON_OFF &&
info->drv == CONN_PWR_DRV_WIFI && info->status == CONN_PWR_DRV_STATUS_ON)) {
switch (low_battery_power_level) {
case LOW_BATTERY_LEVEL_0:
break;
case LOW_BATTERY_LEVEL_1:
case LOW_BATTERY_LEVEL_2:
ret = CONN_PWR_THR_LV_4;
break;
default:
break;
}
}
#endif
return ret;
}
int conn_pwr_get_thermal_level(struct conn_pwr_update_info *info, int current_temp)
{
int ret = CONN_PWR_THR_LV_0;
int thermal_max_level = 0;
if (conn_pwr_get_plat_level(CONN_PWR_PLAT_THERMAL, &thermal_max_level) != 0) {
pr_info("%s conn_pwr cant get thermal level\n", __func__);
return ret;
}
g_thermal_info.max_temp = thermal_max_level;
g_thermal_info.recovery_temp = thermal_max_level - CONN_PWR_THERMAL_RECOVERY_INTERVAL;
if (current_temp > thermal_max_level) {
pr_info("%s update param = %d, %d, %d\n", __func__,
current_temp, thermal_max_level, g_last_temp);
if (current_temp < (thermal_max_level + CONN_PWR_THERMAL_HIGHER_INTERVAL) ||
g_radio_pwr_level[CONN_PWR_DRV_WIFI] < CONN_PWR_THR_LV_2 ||
(g_radio_pwr_level[CONN_PWR_DRV_WIFI] < CONN_PWR_THR_LV_4 &&
current_temp <= g_last_temp)) {
ret = CONN_PWR_THR_LV_2;
} else if (current_temp < (thermal_max_level + CONN_PWR_THERMAL_HIGHEST_INTERVAL) ||
g_radio_pwr_level[CONN_PWR_DRV_WIFI] < CONN_PWR_THR_LV_4 ||
(g_radio_pwr_level[CONN_PWR_DRV_WIFI] < CONN_PWR_THR_LV_5 &&
current_temp <= g_last_temp)) {
ret = CONN_PWR_THR_LV_4;
} else {
ret = CONN_PWR_THR_LV_5;
}
g_last_temp = current_temp;
} else if (current_temp < (thermal_max_level - CONN_PWR_THERMAL_RECOVERY_INTERVAL)) {
pr_info("%s recovery param = %d, %d, %d\n", __func__,
current_temp, thermal_max_level, g_last_temp);
ret = CONN_PWR_THR_LV_0;
g_last_temp = current_temp;
} else {
ret = g_radio_pwr_level[CONN_PWR_DRV_WIFI];
}
return ret;
}
int conn_pwr_set_level(struct conn_pwr_update_info *info, int radio_power_level[], int current_temp)
{
int customer_level = 0;
int radio_value = 0;
int i;
switch (info->reason) {
case CONN_PWR_ARB_SUBSYS_ON_OFF:
if (info->drv == CONN_PWR_DRV_WIFI) {
g_platform_pwr_level[CONN_PWR_PLAT_LOW_BATTERY] =
conn_pwr_get_low_battery_level(info);
}
break;
case CONN_PWR_ARB_LOW_BATTERY:
g_platform_pwr_level[CONN_PWR_PLAT_LOW_BATTERY] =
conn_pwr_get_low_battery_level(info);
break;
case CONN_PWR_ARB_THERMAL:
case CONN_PWR_ARB_TEMP_CHECK:
g_platform_pwr_level[CONN_PWR_PLAT_THERMAL] =
conn_pwr_get_thermal_level(info, current_temp);
break;
default:
break;
}
if (conn_pwr_get_plat_level(CONN_PWR_PLAT_CUSTOMER, &customer_level) != 0)
customer_level = 0;
g_platform_pwr_level[CONN_PWR_PLAT_CUSTOMER] = customer_level;
for (i = 0; i < CONN_PWR_DRV_MAX; i++) {
radio_power_level[i] = g_platform_pwr_level[CONN_PWR_PLAT_LOW_BATTERY];
if (i == CONN_PWR_DRV_WIFI &&
(radio_power_level[i] < g_platform_pwr_level[CONN_PWR_PLAT_THERMAL]))
radio_power_level[i] = g_platform_pwr_level[CONN_PWR_PLAT_THERMAL];
radio_value =
CONN_PWR_GET_CUSTOMER_POWER_LEVEL(
g_platform_pwr_level[CONN_PWR_PLAT_CUSTOMER], i);
if (radio_power_level[i] < radio_value && radio_value < CONN_PWR_LOW_BATTERY_MAX)
radio_power_level[i] = radio_value;
}
pr_info("%s low_battery=%d, thermal=%d, customer=0x%08x\n", __func__,
g_platform_pwr_level[CONN_PWR_PLAT_LOW_BATTERY],
g_platform_pwr_level[CONN_PWR_PLAT_THERMAL],
g_platform_pwr_level[CONN_PWR_PLAT_CUSTOMER]);
return 0;
}
int conn_pwr_get_drv_level(enum conn_pwr_drv_type type, enum conn_pwr_low_battery_level *level)
{
if (level != NULL && type < CONN_PWR_DRV_MAX && type >= 0) {
*level = g_radio_pwr_level[type];
return 0;
} else {
return -1;
}
}
EXPORT_SYMBOL(conn_pwr_get_drv_level);
int conn_pwr_get_platform_level(enum conn_pwr_plat_type type, int *level)
{
if (level != NULL && type < CONN_PWR_PLAT_MAX && type >= 0) {
*level = g_platform_pwr_level[type];
return 0;
} else {
return -1;
}
}
EXPORT_SYMBOL(conn_pwr_get_platform_level);
int conn_pwr_get_thermal(struct conn_pwr_event_max_temp *temp)
{
if (temp == NULL)
return -1;
temp->max_temp = g_thermal_info.max_temp;
temp->recovery_temp = g_thermal_info.recovery_temp;
return 0;
}
EXPORT_SYMBOL(conn_pwr_get_thermal);
int conn_pwr_arbitrate(struct conn_pwr_update_info *info)
{
int radio_power_level[CONN_PWR_DRV_MAX] = {CONN_PWR_THR_LV_0};
int i;
int current_temp = 0;
int adie;
unsigned long flag;
if (!g_enable) {
pr_info("%s disable\n", __func__);
return 0;
}
if (info == NULL)
return -1;
adie = conn_pwr_get_adie_id();
if (adie != 0x6637) {
pr_info("%s no support 0x%x", __func__, adie);
return 0;
}
if (info->reason == CONN_PWR_ARB_SUBSYS_ON_OFF) {
if (info->drv == CONN_PWR_DRV_WIFI) {
int battery_lv = 0;
if (conn_pwr_get_plat_level(CONN_PWR_PLAT_LOW_BATTERY, &battery_lv) != 0) {
pr_info("%s conn_pwr cant get battery level\n", __func__);
battery_lv = 0;
}
if (battery_lv == 0) {
pr_info("%s reason=%d, low battery level is 0\n", __func__,
info->reason);
return 0;
}
} else {
pr_info("%s reason=%d, no need updated\n", __func__, info->reason);
return 0;
}
}
if (info->reason == CONN_PWR_ARB_THERMAL)
conn_pwr_get_temp(&current_temp, 0);
else if (info->reason == CONN_PWR_ARB_TEMP_CHECK)
conn_pwr_get_temp(&current_temp, 1);
spin_lock_irqsave(&pwr_core_lock, flag);
conn_pwr_set_level(info, radio_power_level, current_temp);
if (info->reason == CONN_PWR_ARB_SUBSYS_ON_OFF) {
for (i = 0; i < CONN_PWR_DRV_MAX; i++) {
if (info->drv != i &&
conn_pwr_get_drv_status(i) == CONN_PWR_DRV_STATUS_ON &&
g_radio_pwr_level[i] != radio_power_level[i])
conn_pwr_notify_event(i, CONN_PWR_EVENT_LEVEL,
&radio_power_level[i]);
g_radio_pwr_level[i] = radio_power_level[i];
}
} else {
for (i = 0; i < CONN_PWR_DRV_MAX; i++) {
if (conn_pwr_get_drv_status(i) == CONN_PWR_DRV_STATUS_ON &&
g_radio_pwr_level[i] != radio_power_level[i])
conn_pwr_notify_event(i, CONN_PWR_EVENT_LEVEL,
&radio_power_level[i]);
g_radio_pwr_level[i] = radio_power_level[i];
}
if ((info->reason == CONN_PWR_ARB_THERMAL ||
info->reason == CONN_PWR_ARB_TEMP_CHECK) &&
conn_pwr_get_drv_status(CONN_PWR_DRV_WIFI) == CONN_PWR_DRV_STATUS_ON)
conn_pwr_notify_event(CONN_PWR_DRV_WIFI,
CONN_PWR_EVENT_MAX_TEMP, &g_thermal_info);
}
pr_info("%s reason=%d, bt=%d, FM=%d, GPS=%d, Wi-Fi=%d\n", __func__,
info->reason, g_radio_pwr_level[0],
g_radio_pwr_level[1], g_radio_pwr_level[2], g_radio_pwr_level[3]);
spin_unlock_irqrestore(&pwr_core_lock, flag);
return 0;
}
int conn_pwr_report_level_required(enum conn_pwr_drv_type type,
enum conn_pwr_low_battery_level level)
{
return 0;
}
EXPORT_SYMBOL(conn_pwr_report_level_required);
@@ -0,0 +1,286 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/string.h>
#include <linux/printk.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/ctype.h>
#include <linux/cdev.h>
#include <linux/uaccess.h>
#include <linux/kernel.h>
#include "conn_power_throttling.h"
/* unit-test related */
#if IS_ENABLED(CONFIG_CONN_PWR_DEBUG)
static int conn_pwr_ut_send_msg(int par1, int par2, int par3);
static int conn_pwr_ut_thermal(int par1, int par2, int par3);
static int conn_pwr_ut_start(int par1, int par2, int par3);
static int conn_pwr_ut_stop(int par1, int par2, int par3);
static int conn_pwr_ut_notify(int par1, int par2, int par3);
static int conn_pwr_ut_get_temp(int par1, int par2, int par3);
static int conn_pwr_ut_get_plat_level(int par1, int par2, int par3);
static int conn_pwr_ut_set_customer_level(int par1, int par2, int par3);
static int conn_pwr_ut_set_battery_level(int par1, int par2, int par3);
static int conn_pwr_ut_set_max_temp(int par1, int par2, int par3);
static int conn_pwr_ut_update_thermal_status(int par1, int par2, int par3);
static int conn_pwr_ut_enable_throttling(int par1, int par2, int par3);
static int conn_pwr_ut_event_cb_bt(enum conn_pwr_event_type event, void *data);
static int conn_pwr_ut_event_cb_fm(enum conn_pwr_event_type event, void *data);
static int conn_pwr_ut_event_cb_gps(enum conn_pwr_event_type event, void *data);
static int conn_pwr_ut_event_cb_wifi(enum conn_pwr_event_type event, void *data);
typedef int(*CONN_PWR_TEST_FUNC) (int par1, int par2, int par3);
static const CONN_PWR_TEST_FUNC conn_pwr_test_func[] = {
[0x0] = conn_pwr_ut_send_msg,
[0x1] = conn_pwr_ut_thermal,
[0x2] = conn_pwr_ut_start,
[0x3] = conn_pwr_ut_stop,
[0x4] = conn_pwr_ut_notify,
[0x5] = conn_pwr_ut_get_temp,
[0x6] = conn_pwr_ut_get_plat_level,
[0x7] = conn_pwr_ut_set_customer_level,
[0x8] = conn_pwr_ut_set_max_temp,
[0x9] = conn_pwr_ut_set_battery_level,
[0xA] = conn_pwr_ut_update_thermal_status,
[0x10] = conn_pwr_ut_enable_throttling,
};
static const CONN_PWR_EVENT_CB ut_cb_tbl[] = {
conn_pwr_ut_event_cb_bt,
conn_pwr_ut_event_cb_fm,
conn_pwr_ut_event_cb_gps,
conn_pwr_ut_event_cb_wifi
};
static int ut_battery_level;
static int ut_max_temp = 100;
static int ut_recovery_temp = 60;
ssize_t conn_pwr_dev_write(struct file *filp, const char __user *buffer, size_t count,
loff_t *f_pos)
{
size_t len = count;
char buf[256];
char *pBuf;
char *pDelimiter = " \t";
int x = 0, y = 0, z = 0;
char *pToken = NULL;
long res = 0;
static int test_enabled = -1;
pr_info("write parameter len = %d\n\r", (int) len);
if (len >= sizeof(buf)) {
pr_info("input handling fail!\n");
len = sizeof(buf) - 1;
return -1;
}
if (copy_from_user(buf, buffer, len))
return -EFAULT;
buf[len] = '\0';
pr_info("write parameter data = %s\n\r", buf);
pBuf = buf;
pToken = strsep(&pBuf, pDelimiter);
if (pToken != NULL) {
kstrtol(pToken, 16, &res);
x = (int)res;
} else {
x = 0;
}
pToken = strsep(&pBuf, "\t\n ");
if (pToken != NULL) {
kstrtol(pToken, 16, &res);
y = (int)res;
pr_info("y = 0x%08x\n\r", y);
}
pToken = strsep(&pBuf, "\t\n ");
if (pToken != NULL) {
kstrtol(pToken, 16, &res);
z = (int)res;
}
pr_info("x(0x%08x), y(0x%08x), z(0x%08x)\n\r", x, y, z);
/* For eng and userdebug load, have to enable debug by
* writing 0xDB9DB9 to * "/proc/driver/wmt_dbg" to avoid
* some malicious use
*/
if (x == 0xDB9DB9) {
test_enabled = 1;
return len;
}
if (test_enabled < 0)
return len;
if (ARRAY_SIZE(conn_pwr_test_func) > x &&
conn_pwr_test_func[x] != NULL)
(*conn_pwr_test_func[x]) (x, y, z);
else
pr_info("no handler defined for command id(0x%08x)\n\r", x);
return len;
}
static int conn_pwr_ut_send_msg(int par1, int par2, int par3)
{
conn_pwr_send_msg(par2, par3, NULL);
return 0;
}
static int conn_pwr_ut_thermal(int par1, int par2, int par3)
{
conn_pwr_set_max_temp(par2);
return 0;
}
static void conn_pwr_ut_event_cb(const char *s, enum conn_pwr_event_type event, void *data)
{
if (event == CONN_PWR_EVENT_LEVEL)
pr_info("%s level = %d\n", s, *((int *)data));
else if (event == CONN_PWR_EVENT_MAX_TEMP) {
struct conn_pwr_event_max_temp *d = (struct conn_pwr_event_max_temp *)data;
pr_info("%s m_temp = %d, r_temp = %d\n", s, d->max_temp, d->recovery_temp);
}
}
static int conn_pwr_ut_event_cb_bt(enum conn_pwr_event_type event, void *data)
{
conn_pwr_ut_event_cb(__func__, event, data);
return 0;
}
static int conn_pwr_ut_event_cb_fm(enum conn_pwr_event_type event, void *data)
{
conn_pwr_ut_event_cb(__func__, event, data);
return 0;
}
static int conn_pwr_ut_event_cb_gps(enum conn_pwr_event_type event, void *data)
{
conn_pwr_ut_event_cb(__func__, event, data);
return 0;
}
static int conn_pwr_ut_event_cb_wifi(enum conn_pwr_event_type event, void *data)
{
conn_pwr_ut_event_cb(__func__, event, data);
return 0;
}
static int conn_pwr_ut_start(int par1, int par2, int par3)
{
enum conn_pwr_low_battery_level level = CONN_PWR_THR_LV_0;
int ret;
pr_info("%s", __func__);
if (par2 < 0 || par2 >= CONN_PWR_DRV_MAX) {
pr_info("type %d is invalid", par2);
return 0;
}
ret = conn_pwr_register_event_cb(par2, ut_cb_tbl[par2]);
pr_info("%d register event cb, ret = %d", par2, ret);
ret = conn_pwr_drv_pre_on(par2, &level);
pr_info("type(%d) on, ret = %d, level = %d", par2, ret, level);
return 0;
}
static int conn_pwr_ut_stop(int par1, int par2, int par3)
{
int ret;
ret = conn_pwr_drv_post_off(par2);
pr_info("type(%d) off, ret = %d", par2, ret);
return 0;
}
static int conn_pwr_ut_notify(int par1, int par2, int par3)
{
struct conn_pwr_event_max_temp data;
if (par3 == CONN_PWR_EVENT_LEVEL)
conn_pwr_notify_event(par2, par3, &ut_battery_level);
else if (par3 == CONN_PWR_EVENT_MAX_TEMP) {
data.max_temp = ut_max_temp;
data.recovery_temp = ut_recovery_temp;
conn_pwr_notify_event(par2, par3, &data);
}
return 0;
}
static int conn_pwr_ut_get_temp(int par1, int par2, int par3)
{
int temp = 0, ret;
ret = conn_pwr_get_temp(&temp, par2);
pr_info("%s ret= %d, temp = %d", __func__, ret, temp);
return 0;
}
static int conn_pwr_ut_get_plat_level(int par1, int par2, int par3)
{
int level = 0, ret;
ret = conn_pwr_get_plat_level(par2, &level);
pr_info("%s ret= %d, type = %d, level = %d", __func__, ret, par2, level);
return 0;
}
static int conn_pwr_ut_set_customer_level(int par1, int par2, int par3)
{
conn_pwr_set_customer_level(par2, par3);
pr_info("%s type = %d, level = %d\n", __func__, par2, par3);
return 0;
}
static int conn_pwr_ut_set_battery_level(int par1, int par2, int par3)
{
ut_battery_level = par2;
conn_pwr_set_battery_level(par2);
return 0;
}
/* this is used to set temp to notfiy driver later */
static int conn_pwr_ut_set_max_temp(int par1, int par2, int par3)
{
ut_max_temp = par2;
ut_recovery_temp = par3;
pr_info("%s max = %d, recovery = %d\n", __func__, par2, par3);
return 0;
}
static int conn_pwr_ut_update_thermal_status(int par1, int par2, int par3)
{
void *value;
value = &par3;
conn_pwr_send_msg(CONN_PWR_DRV_WIFI, par2, value);
return 0;
}
static int conn_pwr_ut_enable_throttling(int par1, int par2, int par3)
{
conn_pwr_enable(par2);
return 0;
}
#endif