^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Amlogic Thermal Sensor Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017 Huan Biao <huan.biao@amlogic.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2019 Guillaume La Roque <glaroque@baylibre.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Register value to celsius temperature formulas:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Read_Val m * U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * U = ---------, Uptat = ---------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * 2^16 1 + n * U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Temperature = A * ( Uptat + u_efuse / 2^16 )- B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * A B m n : calibration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * u_efuse : fused calibration value, it's a signed 16 bits value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/bitfield.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/thermal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "thermal_core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define TSENSOR_CFG_REG1 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define TSENSOR_CFG_REG1_RSET_VBG BIT(12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define TSENSOR_CFG_REG1_RSET_ADC BIT(11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define TSENSOR_CFG_REG1_VCM_EN BIT(10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define TSENSOR_CFG_REG1_VBG_EN BIT(9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define TSENSOR_CFG_REG1_OUT_CTL BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define TSENSOR_CFG_REG1_FILTER_EN BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define TSENSOR_CFG_REG1_DEM_EN BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define TSENSOR_CFG_REG1_CH_SEL GENMASK(1, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define TSENSOR_CFG_REG1_ENABLE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) (TSENSOR_CFG_REG1_FILTER_EN | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) TSENSOR_CFG_REG1_VCM_EN | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) TSENSOR_CFG_REG1_VBG_EN | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) TSENSOR_CFG_REG1_DEM_EN | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) TSENSOR_CFG_REG1_CH_SEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define TSENSOR_STAT0 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define TSENSOR_STAT9 0x64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define TSENSOR_READ_TEMP_MASK GENMASK(15, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define TSENSOR_TEMP_MASK GENMASK(11, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define TSENSOR_TRIM_SIGN_MASK BIT(15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define TSENSOR_TRIM_TEMP_MASK GENMASK(14, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define TSENSOR_TRIM_VERSION_MASK GENMASK(31, 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define TSENSOR_TRIM_VERSION(_version) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) FIELD_GET(TSENSOR_TRIM_VERSION_MASK, _version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define TSENSOR_TRIM_CALIB_VALID_MASK (GENMASK(3, 2) | BIT(7))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define TSENSOR_CALIB_OFFSET 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define TSENSOR_CALIB_SHIFT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * struct amlogic_thermal_soc_calib_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * @A: calibration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @B: calibration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * @m: calibration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @n: calibration parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * This structure is required for configuration of amlogic thermal driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct amlogic_thermal_soc_calib_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) int A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int B;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * struct amlogic_thermal_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @u_efuse_off: register offset to read fused calibration value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @calibration_parameters: calibration parameters structure pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @regmap_config: regmap config for the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * This structure is required for configuration of amlogic thermal driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct amlogic_thermal_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int u_efuse_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) const struct amlogic_thermal_soc_calib_data *calibration_parameters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) const struct regmap_config *regmap_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct amlogic_thermal {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) const struct amlogic_thermal_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct regmap *sec_ao_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct thermal_zone_device *tzd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) u32 trim_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Calculate a temperature value from a temperature code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * The unit of the temperature is degree milliCelsius.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int amlogic_thermal_code_to_millicelsius(struct amlogic_thermal *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int temp_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) const struct amlogic_thermal_soc_calib_data *param =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) pdata->data->calibration_parameters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) s64 factor, Uptat, uefuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) uefuse = pdata->trim_info & TSENSOR_TRIM_SIGN_MASK ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ~(pdata->trim_info & TSENSOR_TRIM_TEMP_MASK) + 1 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) (pdata->trim_info & TSENSOR_TRIM_TEMP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) factor = param->n * temp_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) factor = div_s64(factor, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) Uptat = temp_code * param->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) Uptat = div_s64(Uptat, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) Uptat = Uptat * BIT(16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) Uptat = div_s64(Uptat, BIT(16) + factor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) temp = (Uptat + uefuse) * param->A;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) temp = div_s64(temp, BIT(16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) temp = (temp - param->B) * 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int amlogic_thermal_initialize(struct amlogic_thermal *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) regmap_read(pdata->sec_ao_map, pdata->data->u_efuse_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) &pdata->trim_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ver = TSENSOR_TRIM_VERSION(pdata->trim_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if ((ver & TSENSOR_TRIM_CALIB_VALID_MASK) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) dev_err(&pdata->pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) "tsensor thermal calibration not supported: 0x%x!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int amlogic_thermal_enable(struct amlogic_thermal *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ret = clk_prepare_enable(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) regmap_update_bits(data->regmap, TSENSOR_CFG_REG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) TSENSOR_CFG_REG1_ENABLE, TSENSOR_CFG_REG1_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int amlogic_thermal_disable(struct amlogic_thermal *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) regmap_update_bits(data->regmap, TSENSOR_CFG_REG1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) TSENSOR_CFG_REG1_ENABLE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) clk_disable_unprepare(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int amlogic_thermal_get_temp(void *data, int *temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) unsigned int tval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct amlogic_thermal *pdata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) regmap_read(pdata->regmap, TSENSOR_STAT0, &tval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) *temp =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) amlogic_thermal_code_to_millicelsius(pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) tval & TSENSOR_READ_TEMP_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static const struct thermal_zone_of_device_ops amlogic_thermal_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .get_temp = amlogic_thermal_get_temp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static const struct regmap_config amlogic_thermal_regmap_config_g12a = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .val_bits = 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .reg_stride = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .max_register = TSENSOR_STAT9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static const struct amlogic_thermal_soc_calib_data amlogic_thermal_g12a = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .A = 9411,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .B = 3159,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) .m = 424,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .n = 324,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static const struct amlogic_thermal_data amlogic_thermal_g12a_cpu_param = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .u_efuse_off = 0x128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .calibration_parameters = &amlogic_thermal_g12a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .regmap_config = &amlogic_thermal_regmap_config_g12a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static const struct amlogic_thermal_data amlogic_thermal_g12a_ddr_param = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .u_efuse_off = 0xf0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .calibration_parameters = &amlogic_thermal_g12a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .regmap_config = &amlogic_thermal_regmap_config_g12a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static const struct of_device_id of_amlogic_thermal_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .compatible = "amlogic,g12a-ddr-thermal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .data = &amlogic_thermal_g12a_ddr_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .compatible = "amlogic,g12a-cpu-thermal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .data = &amlogic_thermal_g12a_cpu_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) { /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) MODULE_DEVICE_TABLE(of, of_amlogic_thermal_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int amlogic_thermal_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct amlogic_thermal *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) pdata->data = of_device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pdata->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) platform_set_drvdata(pdev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) base = devm_platform_ioremap_resource(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (IS_ERR(base)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) dev_err(dev, "failed to get io address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return PTR_ERR(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pdata->regmap = devm_regmap_init_mmio(dev, base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) pdata->data->regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (IS_ERR(pdata->regmap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return PTR_ERR(pdata->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) pdata->clk = devm_clk_get(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (IS_ERR(pdata->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (PTR_ERR(pdata->clk) != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) dev_err(dev, "failed to get clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return PTR_ERR(pdata->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) pdata->sec_ao_map = syscon_regmap_lookup_by_phandle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) (pdev->dev.of_node, "amlogic,ao-secure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (IS_ERR(pdata->sec_ao_map)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) dev_err(dev, "syscon regmap lookup failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return PTR_ERR(pdata->sec_ao_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) pdata->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) &amlogic_thermal_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (IS_ERR(pdata->tzd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ret = PTR_ERR(pdata->tzd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_err(dev, "Failed to register tsensor: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ret = amlogic_thermal_initialize(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ret = amlogic_thermal_enable(pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int amlogic_thermal_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct amlogic_thermal *data = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return amlogic_thermal_disable(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int __maybe_unused amlogic_thermal_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct amlogic_thermal *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return amlogic_thermal_disable(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static int __maybe_unused amlogic_thermal_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct amlogic_thermal *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return amlogic_thermal_enable(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static SIMPLE_DEV_PM_OPS(amlogic_thermal_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) amlogic_thermal_suspend, amlogic_thermal_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static struct platform_driver amlogic_thermal_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .name = "amlogic_thermal",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .pm = &amlogic_thermal_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .of_match_table = of_amlogic_thermal_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .probe = amlogic_thermal_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .remove = amlogic_thermal_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) module_platform_driver(amlogic_thermal_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) MODULE_AUTHOR("Guillaume La Roque <glaroque@baylibre.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) MODULE_DESCRIPTION("Amlogic thermal driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) MODULE_LICENSE("GPL v2");