Lines Matching +full:max +full:- +full:by +full:- +full:define
1 // SPDX-License-Identifier: GPL-2.0-only
5 * (C) 2002 Hiroshi Miura <miura@da-cha.org>
10 * software is provided AS-IS with no warranties.
19 * Suspend Modulation works by asserting and de-asserting the SUSP# pin
28 * 32us intervals which the SUSP# pin is asserted(ON)/de-asserted(OFF)
31 * These counters define a ratio which is the effective frequency
35 * F_eff = Fgx * ----------------------
43 * on_duration = off_duration * (stock_freq - freq) / freq
46 * on_duration = DURATION - off_duration
48 *---------------------------------------------------------------------------
51 * Dec. 12, 2003 Hiroshi Miura <miura@da-cha.org>
52 * - fix on/off register mistake
53 * - fix cpu_khz calc when it stops cpu modulation.
55 * Dec. 11, 2002 Hiroshi Miura <miura@da-cha.org>
56 * - rewrite for Cyrix MediaGX Cx5510/5520 and
60 * - cs5530_mod patch for 2.4.19-rc1.
62 *---------------------------------------------------------------------------
69 * Suspend Modulation - Definitions *
82 #include <asm/processor-cyrix.h>
85 #define PCI_PMER1 0x80 /* power management enable register 1 */
86 #define PCI_PMER2 0x81 /* power management enable register 2 */
87 #define PCI_PMER3 0x82 /* power management enable register 3 */
88 #define PCI_IRQTC 0x8c /* irq speedup timer counter register:typical 2 to 4ms */
89 #define PCI_VIDTC 0x8d /* video speedup timer counter register: typical 50 to 100ms */
90 #define PCI_MODOFF 0x94 /* suspend modulation OFF counter register, 1 = 32us */
91 #define PCI_MODON 0x95 /* suspend modulation ON counter register */
92 #define PCI_SUSCFG 0x96 /* suspend configuration register */
95 #define GPM (1<<0) /* global power management */
96 #define GIT (1<<1) /* globally enable PM device idle timers */
97 #define GTR (1<<2) /* globally enable IO traps */
98 #define IRQ_SPDUP (1<<3) /* disable clock throttle during interrupt handling */
99 #define VID_SPDUP (1<<4) /* disable clock throttle during vga video handling */
102 #define SUSMOD (1<<0) /* enable/disable suspend modulation */
104 #define SMISPDUP (1<<1) /* select how SMI re-enable suspend modulation: */
105 /* IRQTC timer or read SMI speedup disable reg.(F1BAR[08-09h]) */
106 #define SUSCFG (1<<2) /* enable powering down a GXLV processor. "Special 3Volt Suspend" mode */
108 #define PWRSVE_ISA (1<<3) /* stop ISA clock */
109 #define PWRSVE (1<<4) /* active idle */
123 /* PCI bus clock - defaults to 30.000 if cpu_khz is not available */
131 * is suspended -- processing power is just 0.39% of what it used to be,
132 * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */
137 * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV)
139 #define POLICY_MIN_DIV 20
146 * 0000 = SYSCLK multiplied by 4 (test only)
147 * 0001 = SYSCLK multiplied by 10
148 * 0010 = SYSCLK multiplied by 4
149 * 0011 = SYSCLK multiplied by 6
150 * 0100 = SYSCLK multiplied by 9
151 * 0101 = SYSCLK multiplied by 5
152 * 0110 = SYSCLK multiplied by 7
153 * 0111 = SYSCLK multiplied by 8
175 pci_write_config_byte(gx_params->cs55x0, reg, value); in gx_write_byte()
204 if ((gx_params->pci_suscfg & SUSMOD) == 0) in gx_get_cpuspeed()
207 return (stock_freq * gx_params->off_duration) in gx_get_cpuspeed()
208 / (gx_params->on_duration + gx_params->off_duration); in gx_get_cpuspeed()
228 for (i = max_duration; i > 0; i--) { in gx_validate_speed()
230 tmp_on = i - tmp_off; in gx_validate_speed()
233 * prefer it, too - lower latency */ in gx_validate_speed()
234 if (abs(tmp_freq - khz) <= abs(old_tmp_freq - khz)) { in gx_validate_speed()
259 new_khz = gx_validate_speed(khz, &gx_params->on_duration, in gx_set_cpuspeed()
260 &gx_params->off_duration); in gx_set_cpuspeed()
269 switch (gx_params->cs55x0->device) { in gx_set_cpuspeed()
271 pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP; in gx_set_cpuspeed()
272 /* FIXME: need to test other values -- Zwane,Miura */ in gx_set_cpuspeed()
279 if (gx_params->cs55x0->revision < 0x10) { in gx_set_cpuspeed()
281 suscfg = gx_params->pci_suscfg|SUSMOD; in gx_set_cpuspeed()
284 suscfg = gx_params->pci_suscfg|SUSMOD|PWRSVE; in gx_set_cpuspeed()
289 suscfg = gx_params->pci_suscfg | SUSMOD; in gx_set_cpuspeed()
297 suscfg = gx_params->pci_suscfg & ~(SUSMOD); in gx_set_cpuspeed()
298 gx_params->off_duration = 0; in gx_set_cpuspeed()
299 gx_params->on_duration = 0; in gx_set_cpuspeed()
303 gx_write_byte(PCI_MODOFF, gx_params->off_duration); in gx_set_cpuspeed()
304 gx_write_byte(PCI_MODON, gx_params->on_duration); in gx_set_cpuspeed()
307 pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg); in gx_set_cpuspeed()
311 gx_params->pci_suscfg = suscfg; in gx_set_cpuspeed()
316 gx_params->on_duration * 32, gx_params->off_duration * 32); in gx_set_cpuspeed()
328 * for the hardware supported by the driver.
337 return -EINVAL; in cpufreq_gx_verify()
339 policy->cpu = 0; in cpufreq_gx_verify()
344 * within policy->min and policy->max. If it is not, policy->max in cpufreq_gx_verify()
346 * policy->min may not be decreased, though. This way we guarantee a in cpufreq_gx_verify()
349 tmp_freq = gx_validate_speed(policy->min, &tmp1, &tmp2); in cpufreq_gx_verify()
350 if (tmp_freq < policy->min) in cpufreq_gx_verify()
352 policy->min = tmp_freq; in cpufreq_gx_verify()
353 if (policy->min > policy->max) in cpufreq_gx_verify()
354 policy->max = tmp_freq; in cpufreq_gx_verify()
355 tmp_freq = gx_validate_speed(policy->max, &tmp1, &tmp2); in cpufreq_gx_verify()
356 if (tmp_freq > policy->max) in cpufreq_gx_verify()
357 tmp_freq -= stock_freq / max_duration; in cpufreq_gx_verify()
358 policy->max = tmp_freq; in cpufreq_gx_verify()
359 if (policy->max < policy->min) in cpufreq_gx_verify()
360 policy->max = policy->min; in cpufreq_gx_verify()
379 return -EINVAL; in cpufreq_gx_target()
381 policy->cpu = 0; in cpufreq_gx_target()
384 while (tmp_freq < policy->min) { in cpufreq_gx_target()
388 while (tmp_freq > policy->max) { in cpufreq_gx_target()
389 tmp_freq -= stock_freq / max_duration; in cpufreq_gx_target()
402 if (!policy || policy->cpu != 0) in cpufreq_gx_cpu_init()
403 return -ENODEV; in cpufreq_gx_cpu_init()
415 pr_debug("cpu max frequency is %d.\n", maxfreq); in cpufreq_gx_cpu_init()
418 policy->cpu = 0; in cpufreq_gx_cpu_init()
421 policy->min = maxfreq / max_duration; in cpufreq_gx_cpu_init()
423 policy->min = maxfreq / POLICY_MIN_DIV; in cpufreq_gx_cpu_init()
424 policy->max = maxfreq; in cpufreq_gx_cpu_init()
425 policy->cpuinfo.min_freq = maxfreq / max_duration; in cpufreq_gx_cpu_init()
426 policy->cpuinfo.max_freq = maxfreq; in cpufreq_gx_cpu_init()
441 .name = "gx-suspmod",
453 return -ENODEV; in cpufreq_gx_init()
463 return -ENOMEM; in cpufreq_gx_init()
465 params->cs55x0 = gx_pci; in cpufreq_gx_init()
469 pci_read_config_byte(params->cs55x0, PCI_SUSCFG, &(params->pci_suscfg)); in cpufreq_gx_init()
470 pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1)); in cpufreq_gx_init()
471 pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2)); in cpufreq_gx_init()
472 pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration)); in cpufreq_gx_init()
473 pci_read_config_byte(params->cs55x0, PCI_MODOFF, in cpufreq_gx_init()
474 &(params->off_duration)); in cpufreq_gx_init()
488 pci_dev_put(gx_params->cs55x0); in cpufreq_gx_exit()
492 MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>");