Lines Matching +full:lower +full:- +full:cal
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
34 * kitchen-sinked this device, not us. :)
46 * source describing i.MX6 SoCs, and in the linux and u-boot code which comes
51 * units (higher counts are lower temperatures). Items with '_val' in the name
52 * are deci-Celsius, which are converted to/from deci-Kelvins in the sysctl
81 { -1, 0 }
136 * value (0-3) from the ocotp CFG3 register into a mhz value that can be looked
141 #define TZ_ZEROC 2731 /* deci-Kelvin <-> deci-Celsius offset. */
149 return (bus_read_4(imx6_anatop_sc->res[MEMRES], offset)); in imx6_anatop_read_4()
158 bus_write_4(imx6_anatop_sc->res[MEMRES], offset, value); in imx6_anatop_write_4()
184 newtarg = (mv - 700) / 25; in vdd_set()
190 * (1150-700/25=18). in vdd_set()
199 * going from 400->1200, but works for smaller changes). in vdd_set()
205 delay = (newtarg - oldtarg) * 6; in vdd_set()
226 sc->cpu_curmv = newtarg * 25 + 700; in vdd_set()
234 return ((sc->refosc_mhz * (plldiv / 2)) / (corediv + 1)); in cpufreq_mhz_from_div()
243 *plldiv = ((*corediv + 1) * cpu_mhz) / (sc->refosc_mhz / 2); in cpufreq_mhz_to_div()
260 if (cpu_newmhz > sc->cpu_maxmhz_hw && !sc->cpu_overclock_enable) in cpufreq_nearest_oppt()
261 cpu_newmhz = sc->cpu_maxmhz_hw; in cpufreq_nearest_oppt()
266 d = abs((int)cpu_newmhz - (int)imx6_oppt_table[i].mhz); in cpufreq_nearest_oppt()
281 if (op->mhz > sc->cpu_curmhz) { in cpufreq_set_clock()
282 vdd_set(sc, op->mv); in cpufreq_set_clock()
288 * - Set the bypass clock source to REF_CLK_24M (source #0). in cpufreq_set_clock()
289 * - Set the PLL into bypass mode; cpu should now be running at 24mhz. in cpufreq_set_clock()
290 * - Change the divisor. in cpufreq_set_clock()
291 * - Wait for the LOCK bit to come on; it takes ~50 loop iterations. in cpufreq_set_clock()
292 * - Turn off bypass mode; cpu should now be running at the new speed. in cpufreq_set_clock()
294 cpufreq_mhz_to_div(sc, op->mhz, &corediv, &plldiv); in cpufreq_set_clock()
308 if (--timeout == 0) in cpufreq_set_clock()
315 /* If lowering the frequency, it is now safe to lower the voltage. */ in cpufreq_set_clock()
316 if (op->mhz < sc->cpu_curmhz) in cpufreq_set_clock()
317 vdd_set(sc, op->mv); in cpufreq_set_clock()
318 sc->cpu_curmhz = op->mhz; in cpufreq_set_clock()
322 cpufreq_actual_mhz(sc, sc->cpu_curmhz) * 1000000 / 2); in cpufreq_set_clock()
335 temp = sc->cpu_minmhz; in cpufreq_sysctl_minmhz()
337 if (err != 0 || req->newptr == NULL) in cpufreq_sysctl_minmhz()
341 if (op->mhz > sc->cpu_maxmhz) in cpufreq_sysctl_minmhz()
343 else if (op->mhz == sc->cpu_minmhz) in cpufreq_sysctl_minmhz()
350 sc->cpu_minmhz = op->mhz; in cpufreq_sysctl_minmhz()
351 if (sc->cpu_minmhz > sc->cpu_curmhz) { in cpufreq_sysctl_minmhz()
367 temp = sc->cpu_maxmhz; in cpufreq_sysctl_maxmhz()
369 if (err != 0 || req->newptr == NULL) in cpufreq_sysctl_maxmhz()
373 if (op->mhz < sc->cpu_minmhz) in cpufreq_sysctl_maxmhz()
375 else if (op->mhz == sc->cpu_maxmhz) in cpufreq_sysctl_maxmhz()
382 * whether it is higher or lower than the old max. in cpufreq_sysctl_maxmhz()
384 sc->cpu_maxmhz = op->mhz; in cpufreq_sysctl_maxmhz()
397 OID_AUTO, "cpu_mhz", CTLFLAG_RD, &sc->cpu_curmhz, 0, in cpufreq_initialize()
411 OID_AUTO, "cpu_maxmhz_hw", CTLFLAG_RD, &sc->cpu_maxmhz_hw, 0, in cpufreq_initialize()
416 &sc->cpu_overclock_enable, 0, in cpufreq_initialize()
420 * XXX 24mhz shouldn't be hard-coded, should get this from imx6_ccm in cpufreq_initialize()
424 sc->refosc_mhz = 24; in cpufreq_initialize()
430 * - 2b'11: 1200000000Hz; in cpufreq_initialize()
431 * - 2b'10: 996000000Hz; in cpufreq_initialize()
432 * - 2b'01: 852000000Hz; -- i.MX6Q Only, exclusive with 996MHz. in cpufreq_initialize()
433 * - 2b'00: 792000000Hz; in cpufreq_initialize()
438 sc->cpu_maxmhz_hw = imx6_ocotp_mhz_tab[cfg3speed]; in cpufreq_initialize()
439 sc->cpu_maxmhz = sc->cpu_maxmhz_hw; in cpufreq_initialize()
441 TUNABLE_INT_FETCH("hw.imx6.cpu_minmhz", &sc->cpu_minmhz); in cpufreq_initialize()
442 op = cpufreq_nearest_oppt(sc, sc->cpu_minmhz); in cpufreq_initialize()
443 sc->cpu_minmhz = op->mhz; in cpufreq_initialize()
444 sc->cpu_minmv = op->mv; in cpufreq_initialize()
446 TUNABLE_INT_FETCH("hw.imx6.cpu_maxmhz", &sc->cpu_maxmhz); in cpufreq_initialize()
447 op = cpufreq_nearest_oppt(sc, sc->cpu_maxmhz); in cpufreq_initialize()
448 sc->cpu_maxmhz = op->mhz; in cpufreq_initialize()
449 sc->cpu_maxmv = op->mv; in cpufreq_initialize()
466 return (((sc->temp_high_val - (count - sc->temp_high_cnt) * in temp_from_count()
467 (sc->temp_high_val - 250) / in temp_from_count()
468 (sc->temp_room_cnt - sc->temp_high_cnt)))); in temp_from_count()
475 return ((sc->temp_room_cnt - sc->temp_high_cnt) * in temp_to_count()
476 (sc->temp_high_val - temp) / (sc->temp_high_val - 250) + in temp_to_count()
477 sc->temp_high_cnt); in temp_to_count()
488 sc->temp_last_cnt = in temp_update_count()
501 t = temp_from_count(sc, sc->temp_last_cnt) + TZ_ZEROC; in temp_sysctl_handler()
513 temp = sc->temp_throttle_val + TZ_ZEROC; in temp_throttle_sysctl_handler()
517 temp -= TZ_ZEROC; in temp_throttle_sysctl_handler()
518 if (err != 0 || req->newptr == NULL || temp == sc->temp_throttle_val) in temp_throttle_sysctl_handler()
522 sc->temp_throttle_val = temp; in temp_throttle_sysctl_handler()
523 sc->temp_throttle_trigger_cnt = temp_to_count(sc, sc->temp_throttle_val); in temp_throttle_sysctl_handler()
524 sc->temp_throttle_reset_cnt = temp_to_count(sc, sc->temp_throttle_val - 100); in temp_throttle_sysctl_handler()
528 (sc->temp_throttle_trigger_cnt << in temp_throttle_sysctl_handler()
537 if (sc->cpu_curmhz < sc->cpu_maxmhz) { in tempmon_gofast()
538 cpufreq_set_clock(sc, cpufreq_nearest_oppt(sc, sc->cpu_maxmhz)); in tempmon_gofast()
546 if (sc->cpu_curmhz > sc->cpu_minmhz) { in tempmon_goslow()
547 cpufreq_set_clock(sc, cpufreq_nearest_oppt(sc, sc->cpu_minmhz)); in tempmon_goslow()
571 /* Lower counts are higher temperatures. */ in tempmon_throttle_check()
572 if (sc->temp_last_cnt < sc->temp_throttle_trigger_cnt) in tempmon_throttle_check()
574 else if (sc->temp_last_cnt > (sc->temp_throttle_reset_cnt)) in tempmon_throttle_check()
577 callout_reset_sbt(&sc->temp_throttle_callout, sc->temp_throttle_delay, in tempmon_throttle_check()
585 uint32_t cal; in initialize_tempmon() local
591 cal = fsl_ocotp_read_4(FSL_OCOTP_ANA1); in initialize_tempmon()
592 sc->temp_room_cnt = (cal & 0xFFF00000) >> 20; in initialize_tempmon()
593 sc->temp_high_cnt = (cal & 0x000FFF00) >> 8; in initialize_tempmon()
594 sc->temp_high_val = (cal & 0x000000FF) * 10; in initialize_tempmon()
597 * Throttle to a lower cpu freq at 10C below the "hot" temperature, and in initialize_tempmon()
600 sc->temp_throttle_val = sc->temp_high_val - 100; in initialize_tempmon()
601 sc->temp_throttle_trigger_cnt = in initialize_tempmon()
602 temp_to_count(sc, sc->temp_throttle_val); in initialize_tempmon()
603 sc->temp_throttle_reset_cnt = in initialize_tempmon()
604 temp_to_count(sc, sc->temp_throttle_val - 50); in initialize_tempmon()
612 (sc->temp_throttle_trigger_cnt << in initialize_tempmon()
617 * XXX Note that the alarm-interrupt feature isn't working yet, so in initialize_tempmon()
622 while (sc->temp_last_cnt == 0) in initialize_tempmon()
624 sc->temp_throttle_delay = 100 * SBT_1MS; in initialize_tempmon()
625 callout_init(&sc->temp_throttle_callout, 0); in initialize_tempmon()
626 callout_reset_sbt(&sc->temp_throttle_callout, sc->temp_throttle_delay, in initialize_tempmon()
648 sc->res[IRQRES] = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &rid, in intr_setup()
650 if (sc->res[IRQRES] != NULL) { in intr_setup()
651 bus_setup_intr(sc->dev, sc->res[IRQRES], in intr_setup()
653 &sc->temp_intrhand); in intr_setup()
655 device_printf(sc->dev, "Cannot allocate IRQ resource\n"); in intr_setup()
657 config_intrhook_disestablish(&sc->intr_setup_hook); in intr_setup()
673 if (!sc->cpu_init_done && bus_get_pass() >= cpu_init_pass) { in imx6_anatop_new_pass()
674 sc->cpu_init_done = true; in imx6_anatop_new_pass()
678 device_printf(sc->dev, "CPU %uMHz @ %umV\n", in imx6_anatop_new_pass()
679 sc->cpu_curmhz, sc->cpu_curmv); in imx6_anatop_new_pass()
700 sc->dev = dev; in imx6_anatop_attach()
703 if (bus_alloc_resources(dev, imx6_anatop_spec, sc->res)) { in imx6_anatop_attach()
709 sc->intr_setup_hook.ich_func = intr_setup; in imx6_anatop_attach()
710 sc->intr_setup_hook.ich_arg = sc; in imx6_anatop_attach()
711 config_intrhook_establish(&sc->intr_setup_hook); in imx6_anatop_attach()
713 SYSCTL_ADD_UINT(device_get_sysctl_ctx(sc->dev), in imx6_anatop_attach()
714 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), in imx6_anatop_attach()
716 &sc->cpu_curmv, 0, "Current CPU voltage in millivolts"); in imx6_anatop_attach()
740 bus_release_resources(dev, imx6_anatop_spec, sc->res); in imx6_anatop_attach()
774 if (ofw_bus_is_compatible(dev, "fsl,imx6q-anatop") == 0) in imx6_anatop_probe()