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()
155 struct brcmstb_thermal_priv *priv = tz->devdata; in brcmstb_get_temp()
159 val = __raw_readl(priv->tmon_base + AVS_TMON_STATUS); in brcmstb_get_temp()
162 dev_err(priv->dev, "reading not valid\n"); in brcmstb_get_temp()
163 return -EIO; in brcmstb_get_temp()
181 u32 val = __raw_readl(priv->tmon_base + trip->enable_offs); in avs_tmon_trip_enable()
183 dev_dbg(priv->dev, "%sable trip, type %d\n", en ? "en" : "dis", type); in avs_tmon_trip_enable()
186 val |= trip->enable_mask; in avs_tmon_trip_enable()
188 val &= ~trip->enable_mask; in avs_tmon_trip_enable()
190 __raw_writel(val, priv->tmon_base + trip->enable_offs); in avs_tmon_trip_enable()
197 u32 val = __raw_readl(priv->tmon_base + trip->reg_offs); in avs_tmon_get_trip_temp()
199 val &= trip->reg_msk; in avs_tmon_get_trip_temp()
200 val >>= trip->reg_shift; in avs_tmon_get_trip_temp()
212 dev_dbg(priv->dev, "set temp %d to %d\n", type, temp); in avs_tmon_set_trip_temp()
218 val <<= trip->reg_shift; in avs_tmon_set_trip_temp()
219 val &= trip->reg_msk; in avs_tmon_set_trip_temp()
221 orig = __raw_readl(priv->tmon_base + trip->reg_offs); in avs_tmon_set_trip_temp()
222 orig &= ~trip->reg_msk; in avs_tmon_set_trip_temp()
224 __raw_writel(orig, priv->tmon_base + trip->reg_offs); in avs_tmon_set_trip_temp()
231 val = __raw_readl(priv->tmon_base + AVS_TMON_TEMP_INT_CODE); in avs_tmon_get_intr_temp()
244 dev_dbg(priv->dev, "low/intr/high: %d/%d/%d\n", in brcmstb_tmon_irq_thread()
247 /* Disable high-temp until next threshold shift */ in brcmstb_tmon_irq_thread()
250 /* Disable low-temp until next threshold shift */ in brcmstb_tmon_irq_thread()
255 * Notify using the interrupt temperature, in case the temperature in brcmstb_tmon_irq_thread()
258 thermal_zone_device_update(priv->thermal, intr); in brcmstb_tmon_irq_thread()
265 struct brcmstb_thermal_priv *priv = tz->devdata; in brcmstb_set_trips()
267 dev_dbg(priv->dev, "set trips %d <--> %d\n", low, high); in brcmstb_set_trips()
270 * Disable low-temp if "low" is too small. As per thermal framework in brcmstb_set_trips()
271 * API, we use -INT_MAX rather than INT_MIN. in brcmstb_set_trips()
273 if (low <= -INT_MAX) { in brcmstb_set_trips()
280 /* Disable high-temp if "high" is too big. */ in brcmstb_set_trips()
313 { .compatible = "brcm,avs-tmon-bcm7216", .data = &brcmstb_16nm_params },
314 { .compatible = "brcm,avs-tmon", .data = &brcmstb_28nm_params },
327 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in brcmstb_thermal_probe()
329 return -ENOMEM; in brcmstb_thermal_probe()
331 priv->temp_params = of_device_get_match_data(&pdev->dev); in brcmstb_thermal_probe()
332 if (!priv->temp_params) in brcmstb_thermal_probe()
333 return -EINVAL; in brcmstb_thermal_probe()
336 priv->tmon_base = devm_ioremap_resource(&pdev->dev, res); in brcmstb_thermal_probe()
337 if (IS_ERR(priv->tmon_base)) in brcmstb_thermal_probe()
338 return PTR_ERR(priv->tmon_base); in brcmstb_thermal_probe()
340 priv->dev = &pdev->dev; in brcmstb_thermal_probe()
342 of_ops = priv->temp_params->of_ops; in brcmstb_thermal_probe()
344 thermal = devm_thermal_of_zone_register(&pdev->dev, 0, priv, in brcmstb_thermal_probe()
348 dev_err(&pdev->dev, "could not register sensor: %d\n", ret); in brcmstb_thermal_probe()
352 priv->thermal = thermal; in brcmstb_thermal_probe()
356 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, in brcmstb_thermal_probe()
361 dev_err(&pdev->dev, "could not request IRQ: %d\n", ret); in brcmstb_thermal_probe()
366 dev_info(&pdev->dev, "registered AVS TMON of-sensor driver\n"); in brcmstb_thermal_probe()