From 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Mon, 13 May 2024 10:30:14 +0000 Subject: [PATCH] modify sin led gpio --- kernel/drivers/thermal/rcar_thermal.c | 85 +++++++++++++++++++++--------------------- 1 files changed, 43 insertions(+), 42 deletions(-) diff --git a/kernel/drivers/thermal/rcar_thermal.c b/kernel/drivers/thermal/rcar_thermal.c index 140386d..5c2a13b 100644 --- a/kernel/drivers/thermal/rcar_thermal.c +++ b/kernel/drivers/thermal/rcar_thermal.c @@ -52,6 +52,7 @@ unsigned int irq_per_ch : 1; unsigned int needs_suspend_resume : 1; unsigned int nirqs; + unsigned int ctemp_bands; }; static const struct rcar_thermal_chip rcar_thermal = { @@ -60,6 +61,7 @@ .irq_per_ch = 0, .needs_suspend_resume = 0, .nirqs = 1, + .ctemp_bands = 1, }; static const struct rcar_thermal_chip rcar_gen2_thermal = { @@ -68,6 +70,7 @@ .irq_per_ch = 0, .needs_suspend_resume = 0, .nirqs = 1, + .ctemp_bands = 1, }; static const struct rcar_thermal_chip rcar_gen3_thermal = { @@ -80,6 +83,7 @@ * interrupts to detect a temperature change, rise or fall. */ .nirqs = 2, + .ctemp_bands = 2, }; struct rcar_thermal_priv { @@ -91,7 +95,6 @@ struct mutex lock; struct list_head list; int id; - u32 ctemp; }; #define rcar_thermal_for_each_priv(pos, common) \ @@ -111,6 +114,18 @@ { .compatible = "renesas,rcar-gen2-thermal", .data = &rcar_gen2_thermal, + }, + { + .compatible = "renesas,thermal-r8a774c0", + .data = &rcar_gen3_thermal, + }, + { + .compatible = "renesas,thermal-r8a77970", + .data = &rcar_gen3_thermal, + }, + { + .compatible = "renesas,thermal-r8a77990", + .data = &rcar_gen3_thermal, }, { .compatible = "renesas,thermal-r8a77995", @@ -183,9 +198,8 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv) { struct device *dev = rcar_priv_to_dev(priv); - int i; - u32 ctemp, old, new; - int ret = -EINVAL; + int old, new, ctemp = -EINVAL; + unsigned int i; mutex_lock(&priv->lock); @@ -195,7 +209,6 @@ */ rcar_thermal_bset(priv, THSCR, CPCTL, CPCTL); - ctemp = 0; old = ~0; for (i = 0; i < 128; i++) { /* @@ -203,7 +216,7 @@ * to get stable temperature. * see "Usage Notes" on datasheet */ - udelay(300); + usleep_range(300, 400); new = rcar_thermal_read(priv, THSSR) & CTEMP; if (new == old) { @@ -213,7 +226,7 @@ old = new; } - if (!ctemp) { + if (ctemp < 0) { dev_err(dev, "thermal sensor was broken\n"); goto err_out_unlock; } @@ -231,37 +244,29 @@ ((ctemp - 1) << 0))); } - dev_dbg(dev, "thermal%d %d -> %d\n", priv->id, priv->ctemp, ctemp); - - priv->ctemp = ctemp; - ret = 0; err_out_unlock: mutex_unlock(&priv->lock); - return ret; + + return ctemp; } static int rcar_thermal_get_current_temp(struct rcar_thermal_priv *priv, int *temp) { - int tmp; - int ret; + int ctemp; - ret = rcar_thermal_update_temp(priv); - if (ret < 0) - return ret; + ctemp = rcar_thermal_update_temp(priv); + if (ctemp < 0) + return ctemp; - mutex_lock(&priv->lock); - tmp = MCELSIUS((priv->ctemp * 5) - 65); - mutex_unlock(&priv->lock); + /* Guaranteed operating range is -45C to 125C. */ - if ((tmp < MCELSIUS(-45)) || (tmp > MCELSIUS(125))) { - struct device *dev = rcar_priv_to_dev(priv); - - dev_err(dev, "it couldn't measure temperature correctly\n"); - return -EIO; - } - - *temp = tmp; + if (priv->chip->ctemp_bands == 1) + *temp = MCELSIUS((ctemp * 5) - 65); + else if (ctemp < 24) + *temp = MCELSIUS(((ctemp * 55) - 720) / 10); + else + *temp = MCELSIUS((ctemp * 5) - 60); return 0; } @@ -371,14 +376,9 @@ static void rcar_thermal_work(struct work_struct *work) { struct rcar_thermal_priv *priv; - int cctemp, nctemp; int ret; priv = container_of(work, struct rcar_thermal_priv, work.work); - - ret = rcar_thermal_get_current_temp(priv, &cctemp); - if (ret < 0) - return; ret = rcar_thermal_update_temp(priv); if (ret < 0) @@ -386,13 +386,7 @@ rcar_thermal_irq_enable(priv); - ret = rcar_thermal_get_current_temp(priv, &nctemp); - if (ret < 0) - return; - - if (nctemp != cctemp) - thermal_zone_device_update(priv->zone, - THERMAL_EVENT_UNSPECIFIED); + thermal_zone_device_update(priv->zone, THERMAL_EVENT_UNSPECIFIED); } static u32 rcar_thermal_had_changed(struct rcar_thermal_priv *priv, u32 status) @@ -552,16 +546,23 @@ if (ret < 0) goto error_unregister; - if (chip->use_of_thermal) + if (chip->use_of_thermal) { priv->zone = devm_thermal_zone_of_sensor_register( dev, i, priv, &rcar_thermal_zone_of_ops); - else + } else { priv->zone = thermal_zone_device_register( "rcar_thermal", 1, 0, priv, &rcar_thermal_zone_ops, NULL, 0, idle); + + ret = thermal_zone_device_enable(priv->zone); + if (ret) { + thermal_zone_device_unregister(priv->zone); + priv->zone = ERR_PTR(ret); + } + } if (IS_ERR(priv->zone)) { dev_err(dev, "can't register thermal zone\n"); ret = PTR_ERR(priv->zone); -- Gitblit v1.6.2