mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-15 19:08:54 +00:00
V1.0.5
This commit is contained in:
63
bsp/artinchip/drv/tsen/Kconfig.dev
Normal file
63
bsp/artinchip/drv/tsen/Kconfig.dev
Normal file
@@ -0,0 +1,63 @@
|
||||
#-----------------------------
|
||||
# Tsensor devices local parameter
|
||||
#-----------------------------
|
||||
|
||||
menu "TSEN_CPU Parameter"
|
||||
depends on AIC_USING_TSEN_CPU
|
||||
|
||||
choice
|
||||
prompt "obtaning data mode"
|
||||
default AIC_TSEN0_SOFT_MODE_SINGLE_INTER
|
||||
help
|
||||
Select the obtaning data mode
|
||||
|
||||
config AIC_TSEN0_SOFT_MODE_SINGLE_INTER
|
||||
bool "single interrupt mode"
|
||||
config AIC_TSEN0_SOFT_MODE_SINGLE_POLL
|
||||
bool "polling mode"
|
||||
|
||||
endchoice
|
||||
|
||||
config AIC_TSEN0_SOFT_MODE
|
||||
int
|
||||
default 0 if AIC_TSEN0_SOFT_MODE_SINGLE_INTER
|
||||
default 1 if AIC_TSEN0_SOFT_MODE_PERIOD_INTER
|
||||
default 2 if AIC_TSEN0_SOFT_MODE_SINGLE_POLL
|
||||
|
||||
config AIC_TSEN0_MODE
|
||||
int
|
||||
default 0 if AIC_TSEN0_SOFT_MODE_SINGLE_INTER
|
||||
default 1 if AIC_TSEN0_SOFT_MODE_PERIOD_INTER
|
||||
default 0 if AIC_TSEN0_SOFT_MODE_SINGLE_POLL
|
||||
|
||||
endmenu
|
||||
|
||||
menu "TSEN_GPAI Parameter"
|
||||
depends on AIC_USING_TSEN_GPAI
|
||||
|
||||
choice
|
||||
prompt "obtaning data mode"
|
||||
default AIC_TSEN1_SOFT_MODE_SINGLE_INTER
|
||||
help
|
||||
Select the obtaning data mode
|
||||
|
||||
config AIC_TSEN1_SOFT_MODE_SINGLE_INTER
|
||||
bool "single interrupt mode"
|
||||
config AIC_TSEN1_SOFT_MODE_SINGLE_POLL
|
||||
bool "polling mode"
|
||||
|
||||
endchoice
|
||||
|
||||
config AIC_TSEN1_SOFT_MODE
|
||||
int
|
||||
default 0 if AIC_TSEN1_SOFT_MODE_SINGLE_INTER
|
||||
default 1 if AIC_TSEN1_SOFT_MODE_PERIOD_INTER
|
||||
default 2 if AIC_TSEN1_SOFT_MODE_SINGLE_POLL
|
||||
|
||||
config AIC_TSEN1_MODE
|
||||
int
|
||||
default 0 if AIC_TSEN1_SOFT_MODE_SINGLE_INTER
|
||||
default 1 if AIC_TSEN1_SOFT_MODE_PERIOD_INTER
|
||||
default 0 if AIC_TSEN1_SOFT_MODE_SINGLE_POLL
|
||||
|
||||
endmenu
|
||||
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "drivers/sensor.h"
|
||||
|
||||
#define LOG_TAG "TSEN"
|
||||
#include "aic_core.h"
|
||||
|
||||
#include "hal_tsen.h"
|
||||
|
||||
struct aic_tsen_dev {
|
||||
@@ -22,31 +22,58 @@ struct aic_tsen_dev {
|
||||
};
|
||||
|
||||
// TODO: slope & shift should be read from eFuse, which was writen by CP tester
|
||||
struct aic_tsen_ch aic_tsen_chs = {
|
||||
struct aic_tsen_ch aic_tsen_chs[] = {
|
||||
#ifdef AIC_USING_TSEN_CPU
|
||||
{
|
||||
.id = 0,
|
||||
.available = 1,
|
||||
.name = "tsen-cpu",
|
||||
.mode = AIC_TSEN_MODE_SINGLE,
|
||||
.name = "tsen_cpu",
|
||||
.mode = AIC_TSEN0_MODE,
|
||||
.soft_mode = AIC_TSEN0_SOFT_MODE,
|
||||
.hta_enable = 0,
|
||||
.lta_enable = 0,
|
||||
.otp_enable = 0,
|
||||
#ifndef CONFIG_FPGA_BOARD_ARTINCHIP
|
||||
.slope = -1134,
|
||||
.offset = 2439001,
|
||||
#endif
|
||||
},
|
||||
#endif
|
||||
#ifdef AIC_USING_TSEN_GPAI
|
||||
{
|
||||
.id = 1,
|
||||
.available = 1,
|
||||
.name = "tsen_gpai",
|
||||
.mode = AIC_TSEN1_MODE,
|
||||
.soft_mode = AIC_TSEN1_SOFT_MODE,
|
||||
.hta_enable = 0,
|
||||
.lta_enable = 0,
|
||||
.otp_enable = 0,
|
||||
#ifndef CONFIG_FPGA_BOARD_ARTINCHIP
|
||||
.slope = -1139,
|
||||
.offset = 2450566,
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct aic_tsen_dev g_aic_tsen = {0};
|
||||
static struct aic_tsen_dev g_aic_tsen[ARRAY_SIZE(aic_tsen_chs)];
|
||||
|
||||
static rt_size_t aic_tsen_fetch(struct rt_sensor_device *sensor, void *buf, rt_size_t len)
|
||||
static rt_size_t aic_tsen_fetch(struct rt_sensor_device *sensor,
|
||||
void *buf, rt_size_t len)
|
||||
{
|
||||
struct aic_tsen_ch *chan = &aic_tsen_chs;
|
||||
struct aic_tsen_ch *chan = &aic_tsen_chs[sensor->parent.device_id];
|
||||
struct rt_sensor_data *data = (struct rt_sensor_data *)buf;
|
||||
|
||||
if (!chan)
|
||||
return -RT_EINVAL;
|
||||
|
||||
if (!chan->available) {
|
||||
pr_warn("%s is unavailable!\n", chan->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
pr_debug("The ch%d is obtaining data\n", chan->id);
|
||||
#ifdef AIC_SID_DRV
|
||||
hal_tsen_curve_fitting(chan);
|
||||
#endif
|
||||
@@ -63,8 +90,17 @@ static rt_size_t aic_tsen_fetch(struct rt_sensor_device *sensor, void *buf, rt_s
|
||||
static rt_err_t aic_tsen_control(struct rt_sensor_device *sensor,
|
||||
int cmd, void *args)
|
||||
{
|
||||
LOG_D("Unsupported cmd: 0x%x", cmd);
|
||||
return -RT_ERROR;
|
||||
struct aic_tsen_ch *data = (struct aic_tsen_ch *)args;
|
||||
switch (cmd) {
|
||||
case RT_SENSOR_CTRL_GET_CH_INFO:
|
||||
*data = aic_tsen_chs[sensor->parent.device_id];
|
||||
break;
|
||||
default:
|
||||
LOG_D("Unsupported cmd: 0x%x", cmd);
|
||||
return -RT_ERROR;
|
||||
break;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static struct rt_sensor_ops aic_sensor_ops = {
|
||||
@@ -75,30 +111,35 @@ static struct rt_sensor_ops aic_sensor_ops = {
|
||||
static int drv_tsen_init(void)
|
||||
{
|
||||
s32 ret = 0;
|
||||
struct rt_sensor_info *info = &g_aic_tsen.dev.info;
|
||||
struct rt_sensor_info *info;
|
||||
|
||||
hal_tsen_clk_init();
|
||||
hal_tsen_pclk_get(&aic_tsen_chs);
|
||||
aicos_request_irq(TSEN_IRQn, hal_tsen_irq_handle, 0, NULL, NULL);
|
||||
hal_tsen_enable(1);
|
||||
hal_tsen_ch_init(&aic_tsen_chs, g_aic_tsen.pclk_rate);
|
||||
if (aic_tsen_chs.mode == AIC_TSEN_MODE_SINGLE)
|
||||
aic_tsen_chs.complete = aicos_sem_create(0);
|
||||
hal_tsen_set_ch_num(ARRAY_SIZE(aic_tsen_chs));
|
||||
|
||||
g_aic_tsen.ch = &aic_tsen_chs;
|
||||
for (int i = 0; i < ARRAY_SIZE(aic_tsen_chs); i++) {
|
||||
hal_tsen_pclk_get(&aic_tsen_chs[i]);
|
||||
hal_tsen_ch_init(&aic_tsen_chs[i], g_aic_tsen[i].pclk_rate);
|
||||
if (aic_tsen_chs[i].mode == AIC_TSEN_MODE_SINGLE)
|
||||
aic_tsen_chs[i].complete = aicos_sem_create(0);
|
||||
|
||||
info->type = RT_SENSOR_CLASS_TEMP;
|
||||
info->model = "aic-tsen";
|
||||
info->unit = RT_SENSOR_UNIT_DCELSIUS;
|
||||
info->range_max = 125;
|
||||
info->range_min = 0;
|
||||
info->period_min = 1000; // 1000ms
|
||||
g_aic_tsen.dev.ops = &aic_sensor_ops;
|
||||
ret = rt_hw_sensor_register(&g_aic_tsen.dev, "aic",
|
||||
RT_DEVICE_FLAG_RDWR, RT_NULL);
|
||||
if (ret != RT_EOK) {
|
||||
LOG_E("Failed to register %s. ret %d", aic_tsen_chs.name, ret);
|
||||
return -RT_ERROR;
|
||||
g_aic_tsen[i].ch = &aic_tsen_chs[i];
|
||||
info = &g_aic_tsen[i].dev.info;
|
||||
info->type = RT_SENSOR_CLASS_TEMP;
|
||||
info->model = "aic-tsen";
|
||||
info->unit = RT_SENSOR_UNIT_DCELSIUS;
|
||||
info->range_max = 125;
|
||||
info->range_min = 0;
|
||||
info->period_min = 1000; // 1000ms
|
||||
g_aic_tsen[i].dev.parent.device_id = i;
|
||||
g_aic_tsen[i].dev.ops = &aic_sensor_ops;
|
||||
ret = rt_hw_sensor_register(&g_aic_tsen[i].dev, aic_tsen_chs[i].name,
|
||||
RT_DEVICE_FLAG_RDWR, RT_NULL);
|
||||
if (ret != RT_EOK) {
|
||||
LOG_E("Failed to register %s. ret %d", aic_tsen_chs[i].name, ret);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -110,7 +151,9 @@ INIT_DEVICE_EXPORT(drv_tsen_init);
|
||||
|
||||
static void cmd_tsen_status(int argc, char **argv)
|
||||
{
|
||||
hal_tsen_status_show(&aic_tsen_chs);
|
||||
for (int i = 0; i < ARRAY_SIZE(aic_tsen_chs); i++) {
|
||||
hal_tsen_status_show(&aic_tsen_chs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT_ALIAS(cmd_tsen_status, tsen_status, Show the status of TSensor);
|
||||
|
||||
Reference in New Issue
Block a user