Lines Matching +full:chip +full:- +full:temperature +full:- +full:threshold +full:- +full:celsius

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2015-2017 Broadcom
55 /* HW related temperature constants */
57 #define AVS_TMON_TEMP_MIN -88161
72 /* HW field to read the trip temperature */
79 /* Trips when temperature is below threshold */
87 /* Trips when temperature is above threshold */
95 /* Automatically resets chip when above threshold */
119 /* Convert a HW code to a temperature reading (millidegree celsius) */
123 int offset = priv->temp_params->offset; in avs_tmon_code_to_temp()
124 int mult = priv->temp_params->mult; in avs_tmon_code_to_temp()
126 return (offset - (int)((code & AVS_TMON_TEMP_MASK) * mult)); in avs_tmon_code_to_temp()
130 * Convert a temperature value (millidegree celsius) to a HW code
132 * @temp: temperature to convert
138 int offset = priv->temp_params->offset; in avs_tmon_temp_to_code()
139 int mult = priv->temp_params->mult; in avs_tmon_temp_to_code()
148 return (u32)(DIV_ROUND_UP(offset - temp, mult)); in avs_tmon_temp_to_code()
150 return (u32)((offset - temp) / mult); in avs_tmon_temp_to_code()
159 val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS); in brcmstb_get_temp()
162 return -EIO; in brcmstb_get_temp()
179 u32 val = __raw_readl(priv->tmon_base + trip->enable_offs); in avs_tmon_trip_enable()
181 dev_dbg(priv->dev, "%sable trip, type %d\n", en ? "en" : "dis", type); in avs_tmon_trip_enable()
184 val |= trip->enable_mask; in avs_tmon_trip_enable()
186 val &= ~trip->enable_mask; in avs_tmon_trip_enable()
188 __raw_writel(val, priv->tmon_base + trip->enable_offs); in avs_tmon_trip_enable()
195 u32 val = __raw_readl(priv->tmon_base + trip->reg_offs); in avs_tmon_get_trip_temp()
197 val &= trip->reg_msk; in avs_tmon_get_trip_temp()
198 val >>= trip->reg_shift; in avs_tmon_get_trip_temp()
210 dev_dbg(priv->dev, "set temp %d to %d\n", type, temp); in avs_tmon_set_trip_temp()
216 val <<= trip->reg_shift; in avs_tmon_set_trip_temp()
217 val &= trip->reg_msk; in avs_tmon_set_trip_temp()
219 orig = __raw_readl(priv->tmon_base + trip->reg_offs); in avs_tmon_set_trip_temp()
220 orig &= ~trip->reg_msk; in avs_tmon_set_trip_temp()
222 __raw_writel(orig, priv->tmon_base + trip->reg_offs); in avs_tmon_set_trip_temp()
229 val = __raw_readl(priv->tmon_base + AVS_TMON_TEMP_INT_CODE); in avs_tmon_get_intr_temp()
242 dev_dbg(priv->dev, "low/intr/high: %d/%d/%d\n", in brcmstb_tmon_irq_thread()
245 /* Disable high-temp until next threshold shift */ in brcmstb_tmon_irq_thread()
248 /* Disable low-temp until next threshold shift */ in brcmstb_tmon_irq_thread()
253 * Notify using the interrupt temperature, in case the temperature in brcmstb_tmon_irq_thread()
256 thermal_zone_device_update(priv->thermal, intr); in brcmstb_tmon_irq_thread()
265 dev_dbg(priv->dev, "set trips %d <--> %d\n", low, high); in brcmstb_set_trips()
268 * Disable low-temp if "low" is too small. As per thermal framework in brcmstb_set_trips()
269 * API, we use -INT_MAX rather than INT_MIN. in brcmstb_set_trips()
271 if (low <= -INT_MAX) { in brcmstb_set_trips()
278 /* Disable high-temp if "high" is too big. */ in brcmstb_set_trips()
311 { .compatible = "brcm,avs-tmon-bcm7216", .data = &brcmstb_16nm_params },
312 { .compatible = "brcm,avs-tmon", .data = &brcmstb_28nm_params },
324 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in brcmstb_thermal_probe()
326 return -ENOMEM; in brcmstb_thermal_probe()
328 priv->temp_params = of_device_get_match_data(&pdev->dev); in brcmstb_thermal_probe()
329 if (!priv->temp_params) in brcmstb_thermal_probe()
330 return -EINVAL; in brcmstb_thermal_probe()
332 priv->tmon_base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in brcmstb_thermal_probe()
333 if (IS_ERR(priv->tmon_base)) in brcmstb_thermal_probe()
334 return PTR_ERR(priv->tmon_base); in brcmstb_thermal_probe()
336 priv->dev = &pdev->dev; in brcmstb_thermal_probe()
337 of_ops = priv->temp_params->of_ops; in brcmstb_thermal_probe()
339 thermal = devm_thermal_of_zone_register(&pdev->dev, 0, priv, in brcmstb_thermal_probe()
342 return dev_err_probe(&pdev->dev, PTR_ERR(thermal), in brcmstb_thermal_probe()
345 priv->thermal = thermal; in brcmstb_thermal_probe()
349 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in brcmstb_thermal_probe()
354 return dev_err_probe(&pdev->dev, ret, in brcmstb_thermal_probe()
358 dev_info(&pdev->dev, "registered AVS TMON of-sensor driver\n"); in brcmstb_thermal_probe()