Lines Matching full:tsc

91 	void (*thermal_init)(struct rcar_gen3_thermal_tsc *tsc);
94 static inline u32 rcar_gen3_thermal_read(struct rcar_gen3_thermal_tsc *tsc, in rcar_gen3_thermal_read() argument
97 return ioread32(tsc->base + reg); in rcar_gen3_thermal_read()
100 static inline void rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, in rcar_gen3_thermal_write() argument
103 iowrite32(data, tsc->base + reg); in rcar_gen3_thermal_write()
134 static void rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, in rcar_gen3_thermal_calc_coefs() argument
144 tsc->tj_t = (FIXPT_INT((ptat[1] - ptat[2]) * 157) in rcar_gen3_thermal_calc_coefs()
147 tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), in rcar_gen3_thermal_calc_coefs()
148 tsc->tj_t - FIXPT_INT(TJ_3)); in rcar_gen3_thermal_calc_coefs()
149 tsc->coef.b1 = FIXPT_INT(thcode[2]) - tsc->coef.a1 * TJ_3; in rcar_gen3_thermal_calc_coefs()
151 tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), in rcar_gen3_thermal_calc_coefs()
152 tsc->tj_t - FIXPT_INT(ths_tj_1)); in rcar_gen3_thermal_calc_coefs()
153 tsc->coef.b2 = FIXPT_INT(thcode[0]) - tsc->coef.a2 * ths_tj_1; in rcar_gen3_thermal_calc_coefs()
168 struct rcar_gen3_thermal_tsc *tsc = devdata; in rcar_gen3_thermal_get_temp() local
173 reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK; in rcar_gen3_thermal_get_temp()
175 if (reg <= thcodes[tsc->id][1]) in rcar_gen3_thermal_get_temp()
176 val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b1, in rcar_gen3_thermal_get_temp()
177 tsc->coef.a1); in rcar_gen3_thermal_get_temp()
179 val = FIXPT_DIV(FIXPT_INT(reg) - tsc->coef.b2, in rcar_gen3_thermal_get_temp()
180 tsc->coef.a2); in rcar_gen3_thermal_get_temp()
191 static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc, in rcar_gen3_thermal_mcelsius_to_temp() argument
197 if (celsius <= INT_FIXPT(tsc->tj_t)) in rcar_gen3_thermal_mcelsius_to_temp()
198 val = celsius * tsc->coef.a1 + tsc->coef.b1; in rcar_gen3_thermal_mcelsius_to_temp()
200 val = celsius * tsc->coef.a2 + tsc->coef.b2; in rcar_gen3_thermal_mcelsius_to_temp()
205 static int rcar_gen3_thermal_update_range(struct rcar_gen3_thermal_tsc *tsc) in rcar_gen3_thermal_update_range() argument
209 rcar_gen3_thermal_get_temp(tsc, &temperature); in rcar_gen3_thermal_update_range()
214 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQTEMP1, in rcar_gen3_thermal_update_range()
215 rcar_gen3_thermal_mcelsius_to_temp(tsc, low)); in rcar_gen3_thermal_update_range()
217 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQTEMP2, in rcar_gen3_thermal_update_range()
218 rcar_gen3_thermal_mcelsius_to_temp(tsc, high)); in rcar_gen3_thermal_update_range()
260 static void rcar_gen3_thermal_init_r8a7795es1(struct rcar_gen3_thermal_tsc *tsc) in rcar_gen3_thermal_init_r8a7795es1() argument
262 rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, CTSR_THBGR); in rcar_gen3_thermal_init_r8a7795es1()
263 rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, 0x0); in rcar_gen3_thermal_init_r8a7795es1()
267 rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, CTSR_PONM); in rcar_gen3_thermal_init_r8a7795es1()
269 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQCTL, 0x3F); in rcar_gen3_thermal_init_r8a7795es1()
270 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQMSK, 0); in rcar_gen3_thermal_init_r8a7795es1()
271 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN, IRQ_TEMPD1 | IRQ_TEMP2); in rcar_gen3_thermal_init_r8a7795es1()
273 rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, in rcar_gen3_thermal_init_r8a7795es1()
278 rcar_gen3_thermal_write(tsc, REG_GEN3_CTSR, in rcar_gen3_thermal_init_r8a7795es1()
285 static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_tsc *tsc) in rcar_gen3_thermal_init() argument
289 reg_val = rcar_gen3_thermal_read(tsc, REG_GEN3_THCTR); in rcar_gen3_thermal_init()
291 rcar_gen3_thermal_write(tsc, REG_GEN3_THCTR, reg_val); in rcar_gen3_thermal_init()
295 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQCTL, 0); in rcar_gen3_thermal_init()
296 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQMSK, 0); in rcar_gen3_thermal_init()
297 rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN, IRQ_TEMPD1 | IRQ_TEMP2); in rcar_gen3_thermal_init()
299 reg_val = rcar_gen3_thermal_read(tsc, REG_GEN3_THCTR); in rcar_gen3_thermal_init()
301 rcar_gen3_thermal_write(tsc, REG_GEN3_THCTR, reg_val); in rcar_gen3_thermal_init()
415 struct rcar_gen3_thermal_tsc *tsc; in rcar_gen3_thermal_probe() local
421 tsc = devm_kzalloc(dev, sizeof(*tsc), GFP_KERNEL); in rcar_gen3_thermal_probe()
422 if (!tsc) { in rcar_gen3_thermal_probe()
427 tsc->base = devm_ioremap_resource(dev, res); in rcar_gen3_thermal_probe()
428 if (IS_ERR(tsc->base)) { in rcar_gen3_thermal_probe()
429 ret = PTR_ERR(tsc->base); in rcar_gen3_thermal_probe()
432 tsc->id = i; in rcar_gen3_thermal_probe()
434 priv->tscs[i] = tsc; in rcar_gen3_thermal_probe()
436 priv->thermal_init(tsc); in rcar_gen3_thermal_probe()
437 rcar_gen3_thermal_calc_coefs(tsc, ptat, thcodes[i], in rcar_gen3_thermal_probe()
440 zone = devm_thermal_zone_of_sensor_register(dev, i, tsc, in rcar_gen3_thermal_probe()
447 tsc->zone = zone; in rcar_gen3_thermal_probe()
449 tsc->zone->tzp->no_hwmon = false; in rcar_gen3_thermal_probe()
450 ret = thermal_add_hwmon_sysfs(tsc->zone); in rcar_gen3_thermal_probe()
458 ret = of_thermal_get_ntrips(tsc->zone); in rcar_gen3_thermal_probe()
462 rcar_gen3_thermal_update_range(tsc); in rcar_gen3_thermal_probe()
464 dev_info(dev, "TSC%d: Loaded %d trip points\n", i, ret); in rcar_gen3_thermal_probe()
499 struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i]; in rcar_gen3_thermal_resume() local
501 priv->thermal_init(tsc); in rcar_gen3_thermal_resume()
502 rcar_gen3_thermal_update_range(tsc); in rcar_gen3_thermal_resume()