Add RockChip RK356X support to existing RockChip thermal driver.
This commit is contained in:
parent
64f923959a
commit
0b6d133c08
@ -55,6 +55,11 @@ __FBSDID("$FreeBSD$");
|
||||
#include "syscon_if.h"
|
||||
#include "rk_tsadc_if.h"
|
||||
|
||||
/* Version of HW */
|
||||
#define TSADC_V2 1
|
||||
#define TSADC_V3 2
|
||||
#define TSADC_V7 3
|
||||
|
||||
/* Global registers */
|
||||
#define TSADC_USER_CON 0x000
|
||||
#define TSADC_AUTO_CON 0x004
|
||||
@ -78,7 +83,7 @@ __FBSDID("$FreeBSD$");
|
||||
#define TSADC_COMP0_LOW_INT 0x080 /* V3 only */
|
||||
#define TSADC_COMP1_LOW_INT 0x084 /* V3 only */
|
||||
|
||||
/* GFR Bits */
|
||||
/* V3 GFR registers */
|
||||
#define GRF_SARADC_TESTBIT 0x0e644
|
||||
#define GRF_SARADC_TESTBIT_ON (0x10001 << 2)
|
||||
#define GRF_TSADC_TESTBIT_L 0x0e648
|
||||
@ -87,6 +92,13 @@ __FBSDID("$FreeBSD$");
|
||||
#define GRF_TSADC_VCM_EN_H (0x10001 << 7)
|
||||
#define GRF_TSADC_TESTBIT_H_ON (0x10001 << 2)
|
||||
|
||||
/* V7 GRF register */
|
||||
#define GRF_TSADC_CON 0x0600
|
||||
#define GRF_TSADC_ANA_REG0 (0x10001 << 0)
|
||||
#define GRF_TSADC_ANA_REG1 (0x10001 << 1)
|
||||
#define GRF_TSADC_ANA_REG2 (0x10001 << 2)
|
||||
#define GRF_TSADC_TSEN (0x10001 << 8)
|
||||
|
||||
#define WR4(_sc, _r, _v) bus_write_4((_sc)->mem_res, (_r), (_v))
|
||||
#define RD4(_sc, _r) bus_read_4((_sc)->mem_res, (_r))
|
||||
|
||||
@ -109,7 +121,7 @@ struct tsadc_calib_info {
|
||||
};
|
||||
|
||||
struct tsadc_conf {
|
||||
int use_syscon;
|
||||
int version;
|
||||
int q_sel_ntc;
|
||||
int shutdown_temp;
|
||||
int shutdown_mode;
|
||||
@ -183,7 +195,7 @@ struct tsensor rk3288_tsensors[] = {
|
||||
};
|
||||
|
||||
struct tsadc_conf rk3288_tsadc_conf = {
|
||||
.use_syscon = 0,
|
||||
.version = TSADC_V2,
|
||||
.q_sel_ntc = 0,
|
||||
.shutdown_temp = 95000,
|
||||
.shutdown_mode = 1, /* GPIO */
|
||||
@ -237,7 +249,7 @@ static struct tsensor rk3328_tsensors[] = {
|
||||
};
|
||||
|
||||
static struct tsadc_conf rk3328_tsadc_conf = {
|
||||
.use_syscon = 0,
|
||||
.version = TSADC_V2,
|
||||
.q_sel_ntc = 1,
|
||||
.shutdown_temp = 95000,
|
||||
.shutdown_mode = 0, /* CRU */
|
||||
@ -293,7 +305,7 @@ static struct tsensor rk3399_tsensors[] = {
|
||||
};
|
||||
|
||||
static struct tsadc_conf rk3399_tsadc_conf = {
|
||||
.use_syscon = 1,
|
||||
.version = TSADC_V3,
|
||||
.q_sel_ntc = 1,
|
||||
.shutdown_temp = 95000,
|
||||
.shutdown_mode = 1, /* GPIO */
|
||||
@ -306,10 +318,68 @@ static struct tsadc_conf rk3399_tsadc_conf = {
|
||||
}
|
||||
};
|
||||
|
||||
static struct rk_calib_entry rk3568_calib_data[] = {
|
||||
{0, -40000},
|
||||
{1584, -40000},
|
||||
{1620, -35000},
|
||||
{1652, -30000},
|
||||
{1688, -25000},
|
||||
{1720, -20000},
|
||||
{1756, -15000},
|
||||
{1788, -10000},
|
||||
{1824, -5000},
|
||||
{1856, 0},
|
||||
{1892, 5000},
|
||||
{1924, 10000},
|
||||
{1956, 15000},
|
||||
{1992, 20000},
|
||||
{2024, 25000},
|
||||
{2060, 30000},
|
||||
{2092, 35000},
|
||||
{2128, 40000},
|
||||
{2160, 45000},
|
||||
{2196, 50000},
|
||||
{2228, 55000},
|
||||
{2264, 60000},
|
||||
{2300, 65000},
|
||||
{2332, 70000},
|
||||
{2368, 75000},
|
||||
{2400, 80000},
|
||||
{2436, 85000},
|
||||
{2468, 90000},
|
||||
{2500, 95000},
|
||||
{2536, 100000},
|
||||
{2572, 105000},
|
||||
{2604, 110000},
|
||||
{2636, 115000},
|
||||
{2672, 120000},
|
||||
{2704, 125000},
|
||||
};
|
||||
|
||||
static struct tsensor rk3568_tsensors[] = {
|
||||
{ .channel = 0, .id = 0, .name = "CPU"},
|
||||
{ .channel = 1, .id = 1, .name = "GPU"},
|
||||
};
|
||||
|
||||
static struct tsadc_conf rk3568_tsadc_conf = {
|
||||
.version = TSADC_V7,
|
||||
.q_sel_ntc = 1,
|
||||
.shutdown_temp = 95000,
|
||||
.shutdown_mode = 1, /* GPIO */
|
||||
.shutdown_pol = 0, /* Low */
|
||||
.tsensors = rk3568_tsensors,
|
||||
.ntsensors = nitems(rk3568_tsensors),
|
||||
.calib_info = {
|
||||
.table = rk3568_calib_data,
|
||||
.nentries = nitems(rk3568_calib_data),
|
||||
}
|
||||
};
|
||||
|
||||
static struct ofw_compat_data compat_data[] = {
|
||||
{"rockchip,rk3288-tsadc", (uintptr_t)&rk3288_tsadc_conf},
|
||||
{"rockchip,rk3328-tsadc", (uintptr_t)&rk3328_tsadc_conf},
|
||||
{"rockchip,rk3399-tsadc", (uintptr_t)&rk3399_tsadc_conf},
|
||||
{"rockchip,rk3568-tsadc", (uintptr_t)&rk3568_tsadc_conf},
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
@ -445,13 +515,15 @@ tsadc_init(struct tsadc_softc *sc)
|
||||
val |= TSADC_AUTO_Q_SEL;
|
||||
WR4(sc, TSADC_AUTO_CON, val);
|
||||
|
||||
if (!sc->conf->use_syscon) {
|
||||
switch (sc->conf->version) {
|
||||
case TSADC_V2:
|
||||
/* V2 init */
|
||||
WR4(sc, TSADC_AUTO_PERIOD, 250); /* 250 ms */
|
||||
WR4(sc, TSADC_AUTO_PERIOD_HT, 50); /* 50 ms */
|
||||
WR4(sc, TSADC_HIGHT_INT_DEBOUNCE, 4);
|
||||
WR4(sc, TSADC_HIGHT_TSHUT_DEBOUNCE, 4);
|
||||
} else {
|
||||
break;
|
||||
case TSADC_V3:
|
||||
/* V3 init */
|
||||
if (sc->grf == NULL) {
|
||||
/* Errata: adjust interleave to working value */
|
||||
@ -473,6 +545,26 @@ tsadc_init(struct tsadc_softc *sc)
|
||||
WR4(sc, TSADC_AUTO_PERIOD_HT, 1875); /* 2.5 ms */
|
||||
WR4(sc, TSADC_HIGHT_INT_DEBOUNCE, 4);
|
||||
WR4(sc, TSADC_HIGHT_TSHUT_DEBOUNCE, 4);
|
||||
break;
|
||||
case TSADC_V7:
|
||||
/* V7 init */
|
||||
WR4(sc, TSADC_USER_CON, 0xfc0); /* 97us, at least 90us */
|
||||
WR4(sc, TSADC_AUTO_PERIOD, 1622); /* 2.5ms */
|
||||
WR4(sc, TSADC_HIGHT_INT_DEBOUNCE, 4);
|
||||
WR4(sc, TSADC_AUTO_PERIOD_HT, 1622); /* 2.5ms */
|
||||
WR4(sc, TSADC_HIGHT_TSHUT_DEBOUNCE, 4);
|
||||
if (sc->grf) {
|
||||
SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON, GRF_TSADC_TSEN);
|
||||
DELAY(15); /* 10 usec min */
|
||||
SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON,
|
||||
GRF_TSADC_ANA_REG0);
|
||||
SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON,
|
||||
GRF_TSADC_ANA_REG1);
|
||||
SYSCON_WRITE_4(sc->grf, GRF_TSADC_CON,
|
||||
GRF_TSADC_ANA_REG2);
|
||||
DELAY(100); /* 90 usec min */
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,13 +577,11 @@ tsadc_read_temp(struct tsadc_softc *sc, struct tsensor *sensor, int *temp)
|
||||
*temp = tsadc_raw_to_temp(sc, val);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("%s: Sensor(id: %d, ch: %d), temp: %d\n", __func__,
|
||||
sensor->id, sensor->channel, *temp);
|
||||
printf(" status: 0x%08X, 0x%08X\n",
|
||||
RD4(sc, TSADC_USER_CON),
|
||||
RD4(sc, TSADC_AUTO_CON));
|
||||
printf(" Data: 0x%08X, 0x%08X, 0x%08X\n",
|
||||
RD4(sc, TSADC_DATA(sensor->channel)),
|
||||
device_printf(sc->dev, "%s: Sensor(id: %d, ch: %d), val: %d temp: %d\n",
|
||||
__func__, sensor->id, sensor->channel, val, *temp);
|
||||
device_printf(sc->dev, "%s: user_con=0x%08x auto_con=0x%08x "
|
||||
"comp_int=0x%08x comp_shut=0x%08x\n",
|
||||
__func__, RD4(sc, TSADC_USER_CON), RD4(sc, TSADC_AUTO_CON),
|
||||
RD4(sc, TSADC_COMP_INT(sensor->channel)),
|
||||
RD4(sc, TSADC_COMP_SHUT(sensor->channel)));
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user