AR-1 - Adding support category for distributions AR-4 - Remove Allwinner legacy AR-5 - Drop Udoo family and move Udoo board into newly created imx6 family AR-9 - Rename sunxi-next to sunxi-legacy AR-10 - Rename sunxi-dev to sunxi-current AR-11 - Adding Radxa Rockpi S support AR-13 - Rename rockchip64-default to rockchip64-legacy AR-14 - Add rockchip64-current as mainline source AR-15 - Drop Rockchip 4.19.y NEXT, current become 5.3.y AR-16 - Rename RK3399 default to legacy AR-17 - Rename Odroid XU4 next and default to legacy 4.14.y, add DEV 5.4.y AR-18 - Add Odroid N2 current mainline AR-19 - Move Odroid C1 to meson family AR-20 - Rename mvebu64-default to mvebu64-legacy AR-21 - Rename mvebu-default to mvebu-legacy AR-22 - Rename mvebu-next to mvebu-current AR-23 - Drop meson64 default and next, current becomes former DEV 5.3.y AR-24 - Drop cubox family and move Cubox/Hummingboard boards under imx6 AR-26 - Adjust motd AR-27 - Enabling distribution release status AR-28 - Added new GCC compilers AR-29 - Implementing Ubuntu Eoan AR-30 - Add desktop packages per board or family AR-31 - Remove (Ubuntu/Debian) distribution name from image filename AR-32 - Move arch configs from configuration.sh to separate arm64 and armhf config files AR-33 - Revision numbers for beta builds changed to day_in_the_year AR-34 - Patches support linked patches AR-35 - Break meson64 family into gxbb and gxl AR-36 - Add Nanopineo2 Black AR-38 - Upgrade option from old branches to new one via armbian-config AR-41 - Show full timezone info AR-43 - Merge Odroid N2 to meson64 AR-44 - Enable FORCE_BOOTSCRIPT_UPDATE for all builds
306 lines
8.8 KiB
Diff
306 lines
8.8 KiB
Diff
diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c
|
|
index ae7532894..a23a5c7f0 100644
|
|
--- a/drivers/thermal/armada_thermal.c
|
|
+++ b/drivers/thermal/armada_thermal.c
|
|
@@ -23,8 +23,7 @@
|
|
#include <linux/platform_device.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/thermal.h>
|
|
-
|
|
-#define THERMAL_VALID_MASK 0x1
|
|
+#include <linux/iopoll.h>
|
|
|
|
/* Thermal Manager Control and Status Register */
|
|
#define PMU_TDC0_SW_RST_MASK (0x1 << 1)
|
|
@@ -39,14 +38,33 @@
|
|
#define A375_UNIT_CONTROL_MASK 0x7
|
|
#define A375_READOUT_INVERT BIT(15)
|
|
#define A375_HW_RESETn BIT(8)
|
|
-#define A380_HW_RESET BIT(8)
|
|
+
|
|
+/* Legacy bindings */
|
|
+#define LEGACY_CONTROL_MEM_LEN 0x4
|
|
+
|
|
+/* Current bindings with the 2 control registers under the same memory area */
|
|
+#define LEGACY_CONTROL1_OFFSET 0x0
|
|
+#define CONTROL0_OFFSET 0x0
|
|
+#define CONTROL1_OFFSET 0x4
|
|
+
|
|
+/* Errata fields */
|
|
+#define CONTROL0_TSEN_TC_TRIM_MASK 0x7
|
|
+#define CONTROL0_TSEN_TC_TRIM_VAL 0x3
|
|
+
|
|
+/* EXT_TSEN refers to the external temperature sensors, out of the AP */
|
|
+#define CONTROL1_EXT_TSEN_SW_RESET BIT(7)
|
|
+#define CONTROL1_EXT_TSEN_HW_RESETn BIT(8)
|
|
+
|
|
+#define STATUS_POLL_PERIOD_US 1000
|
|
+#define STATUS_POLL_TIMEOUT_US 100000
|
|
|
|
struct armada_thermal_data;
|
|
|
|
/* Marvell EBU Thermal Sensor Dev Structure */
|
|
struct armada_thermal_priv {
|
|
- void __iomem *sensor;
|
|
- void __iomem *control;
|
|
+ void __iomem *status;
|
|
+ void __iomem *control0;
|
|
+ void __iomem *control1;
|
|
struct armada_thermal_data *data;
|
|
};
|
|
|
|
@@ -58,7 +76,7 @@ struct armada_thermal_data {
|
|
/* Test for a valid sensor value (optional) */
|
|
bool (*is_valid)(struct armada_thermal_priv *);
|
|
|
|
- /* Formula coeficients: temp = (b + m * reg) / div */
|
|
+ /* Formula coeficients: temp = (b - m * reg) / div */
|
|
unsigned long coef_b;
|
|
unsigned long coef_m;
|
|
unsigned long coef_div;
|
|
@@ -67,91 +85,111 @@ struct armada_thermal_data {
|
|
/* Register shift and mask to access the sensor temperature */
|
|
unsigned int temp_shift;
|
|
unsigned int temp_mask;
|
|
- unsigned int is_valid_shift;
|
|
+ u32 is_valid_bit;
|
|
+ bool needs_control0;
|
|
};
|
|
|
|
static void armadaxp_init_sensor(struct platform_device *pdev,
|
|
struct armada_thermal_priv *priv)
|
|
{
|
|
- unsigned long reg;
|
|
+ u32 reg;
|
|
|
|
- reg = readl_relaxed(priv->control);
|
|
+ reg = readl_relaxed(priv->control1);
|
|
reg |= PMU_TDC0_OTF_CAL_MASK;
|
|
- writel(reg, priv->control);
|
|
+ writel(reg, priv->control1);
|
|
|
|
/* Reference calibration value */
|
|
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
|
|
reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
|
|
- writel(reg, priv->control);
|
|
+ writel(reg, priv->control1);
|
|
|
|
/* Reset the sensor */
|
|
- reg = readl_relaxed(priv->control);
|
|
- writel((reg | PMU_TDC0_SW_RST_MASK), priv->control);
|
|
+ reg = readl_relaxed(priv->control1);
|
|
+ writel((reg | PMU_TDC0_SW_RST_MASK), priv->control1);
|
|
|
|
- writel(reg, priv->control);
|
|
+ writel(reg, priv->control1);
|
|
|
|
/* Enable the sensor */
|
|
- reg = readl_relaxed(priv->sensor);
|
|
+ reg = readl_relaxed(priv->status);
|
|
reg &= ~PMU_TM_DISABLE_MASK;
|
|
- writel(reg, priv->sensor);
|
|
+ writel(reg, priv->status);
|
|
}
|
|
|
|
static void armada370_init_sensor(struct platform_device *pdev,
|
|
struct armada_thermal_priv *priv)
|
|
{
|
|
- unsigned long reg;
|
|
+ u32 reg;
|
|
|
|
- reg = readl_relaxed(priv->control);
|
|
+ reg = readl_relaxed(priv->control1);
|
|
reg |= PMU_TDC0_OTF_CAL_MASK;
|
|
- writel(reg, priv->control);
|
|
+ writel(reg, priv->control1);
|
|
|
|
/* Reference calibration value */
|
|
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
|
|
reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
|
|
- writel(reg, priv->control);
|
|
+ writel(reg, priv->control1);
|
|
|
|
reg &= ~PMU_TDC0_START_CAL_MASK;
|
|
- writel(reg, priv->control);
|
|
+ writel(reg, priv->control1);
|
|
|
|
- mdelay(10);
|
|
+ msleep(10);
|
|
}
|
|
|
|
static void armada375_init_sensor(struct platform_device *pdev,
|
|
struct armada_thermal_priv *priv)
|
|
{
|
|
- unsigned long reg;
|
|
+ u32 reg;
|
|
|
|
- reg = readl(priv->control + 4);
|
|
+ reg = readl(priv->control1);
|
|
reg &= ~(A375_UNIT_CONTROL_MASK << A375_UNIT_CONTROL_SHIFT);
|
|
reg &= ~A375_READOUT_INVERT;
|
|
reg &= ~A375_HW_RESETn;
|
|
|
|
- writel(reg, priv->control + 4);
|
|
- mdelay(20);
|
|
+ writel(reg, priv->control1);
|
|
+ msleep(20);
|
|
|
|
reg |= A375_HW_RESETn;
|
|
- writel(reg, priv->control + 4);
|
|
- mdelay(50);
|
|
+ writel(reg, priv->control1);
|
|
+ msleep(50);
|
|
+}
|
|
+
|
|
+static void armada_wait_sensor_validity(struct armada_thermal_priv *priv)
|
|
+{
|
|
+ u32 reg;
|
|
+
|
|
+ readl_relaxed_poll_timeout(priv->status, reg,
|
|
+ reg & priv->data->is_valid_bit,
|
|
+ STATUS_POLL_PERIOD_US,
|
|
+ STATUS_POLL_TIMEOUT_US);
|
|
}
|
|
|
|
static void armada380_init_sensor(struct platform_device *pdev,
|
|
struct armada_thermal_priv *priv)
|
|
{
|
|
- unsigned long reg = readl_relaxed(priv->control);
|
|
-
|
|
- /* Reset hardware once */
|
|
- if (!(reg & A380_HW_RESET)) {
|
|
- reg |= A380_HW_RESET;
|
|
- writel(reg, priv->control);
|
|
- mdelay(10);
|
|
+ u32 reg = readl_relaxed(priv->control1);
|
|
+
|
|
+ /* Disable the HW/SW reset */
|
|
+ reg |= CONTROL1_EXT_TSEN_HW_RESETn;
|
|
+ reg &= ~CONTROL1_EXT_TSEN_SW_RESET;
|
|
+ writel(reg, priv->control1);
|
|
+
|
|
+ /* Set Tsen Tc Trim to correct default value (errata #132698) */
|
|
+ if (priv->control0) {
|
|
+ reg = readl_relaxed(priv->control0);
|
|
+ reg &= ~CONTROL0_TSEN_TC_TRIM_MASK;
|
|
+ reg |= CONTROL0_TSEN_TC_TRIM_VAL;
|
|
+ writel(reg, priv->control0);
|
|
}
|
|
+
|
|
+ /* Wait the sensors to be valid or the core will warn the user */
|
|
+ armada_wait_sensor_validity(priv);
|
|
}
|
|
|
|
static bool armada_is_valid(struct armada_thermal_priv *priv)
|
|
{
|
|
- unsigned long reg = readl_relaxed(priv->sensor);
|
|
+ u32 reg = readl_relaxed(priv->status);
|
|
|
|
- return (reg >> priv->data->is_valid_shift) & THERMAL_VALID_MASK;
|
|
+ return reg & priv->data->is_valid_bit;
|
|
}
|
|
|
|
static int armada_get_temp(struct thermal_zone_device *thermal,
|
|
@@ -168,7 +206,7 @@ static int armada_get_temp(struct thermal_zone_device *thermal,
|
|
return -EIO;
|
|
}
|
|
|
|
- reg = readl_relaxed(priv->sensor);
|
|
+ reg = readl_relaxed(priv->status);
|
|
reg = (reg >> priv->data->temp_shift) & priv->data->temp_mask;
|
|
|
|
/* Get formula coeficients */
|
|
@@ -199,7 +237,7 @@ static const struct armada_thermal_data armadaxp_data = {
|
|
static const struct armada_thermal_data armada370_data = {
|
|
.is_valid = armada_is_valid,
|
|
.init_sensor = armada370_init_sensor,
|
|
- .is_valid_shift = 9,
|
|
+ .is_valid_bit = BIT(9),
|
|
.temp_shift = 10,
|
|
.temp_mask = 0x1ff,
|
|
.coef_b = 3153000000UL,
|
|
@@ -210,24 +248,26 @@ static const struct armada_thermal_data armada370_data = {
|
|
static const struct armada_thermal_data armada375_data = {
|
|
.is_valid = armada_is_valid,
|
|
.init_sensor = armada375_init_sensor,
|
|
- .is_valid_shift = 10,
|
|
+ .is_valid_bit = BIT(10),
|
|
.temp_shift = 0,
|
|
.temp_mask = 0x1ff,
|
|
.coef_b = 3171900000UL,
|
|
.coef_m = 10000000UL,
|
|
.coef_div = 13616,
|
|
+ .needs_control0 = true,
|
|
};
|
|
|
|
static const struct armada_thermal_data armada380_data = {
|
|
.is_valid = armada_is_valid,
|
|
.init_sensor = armada380_init_sensor,
|
|
- .is_valid_shift = 10,
|
|
+ .is_valid_bit = BIT(10),
|
|
.temp_shift = 0,
|
|
.temp_mask = 0x3ff,
|
|
.coef_b = 1172499100UL,
|
|
.coef_m = 2000096UL,
|
|
.coef_div = 4201,
|
|
.inverted = true,
|
|
+ .needs_control0 = true,
|
|
};
|
|
|
|
static const struct of_device_id armada_thermal_id_table[] = {
|
|
@@ -255,6 +295,7 @@ MODULE_DEVICE_TABLE(of, armada_thermal_id_table);
|
|
|
|
static int armada_thermal_probe(struct platform_device *pdev)
|
|
{
|
|
+ void __iomem *control = NULL;
|
|
struct thermal_zone_device *thermal;
|
|
const struct of_device_id *match;
|
|
struct armada_thermal_priv *priv;
|
|
@@ -268,17 +309,39 @@ static int armada_thermal_probe(struct platform_device *pdev)
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
+ priv->data = (struct armada_thermal_data *)match->data;
|
|
+
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
- priv->sensor = devm_ioremap_resource(&pdev->dev, res);
|
|
- if (IS_ERR(priv->sensor))
|
|
- return PTR_ERR(priv->sensor);
|
|
+ priv->status = devm_ioremap_resource(&pdev->dev, res);
|
|
+ if (IS_ERR(priv->status))
|
|
+ return PTR_ERR(priv->status);
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
- priv->control = devm_ioremap_resource(&pdev->dev, res);
|
|
- if (IS_ERR(priv->control))
|
|
- return PTR_ERR(priv->control);
|
|
|
|
- priv->data = (struct armada_thermal_data *)match->data;
|
|
+ /* Calculate control0 address and edit the resource start address and
|
|
+ * length to map over all the registers */
|
|
+ if (priv->data->needs_control0)
|
|
+ res->start -= CONTROL1_OFFSET;
|
|
+
|
|
+ control = devm_ioremap_resource(&pdev->dev, res);
|
|
+ if (IS_ERR(control))
|
|
+ return PTR_ERR(control);
|
|
+
|
|
+ dev_info(&pdev->dev, "res size = %d\n", resource_size(res));
|
|
+
|
|
+ /*
|
|
+ * Legacy DT bindings only described "control1" register (also referred
|
|
+ * as "control MSB" on old documentation). New bindings cover
|
|
+ * "control0/control LSB" and "control1/control MSB" registers within
|
|
+ * the same resource, which is then of size 8 instead of 4.
|
|
+ */
|
|
+ if (resource_size(res) == LEGACY_CONTROL_MEM_LEN) {
|
|
+ priv->control1 = control + LEGACY_CONTROL1_OFFSET;
|
|
+ } else {
|
|
+ priv->control0 = control + CONTROL0_OFFSET;
|
|
+ priv->control1 = control + CONTROL1_OFFSET;
|
|
+ }
|
|
+
|
|
priv->data->init_sensor(pdev, priv);
|
|
|
|
thermal = thermal_zone_device_register("armada_thermal", 0, 0,
|