📄 cpufreq_32.c
字号:
_set_L3CR(0); } } set_speed_proc(speed_mode == CPUFREQ_LOW); if (speed_mode == CPUFREQ_HIGH && cpu_has_feature(CPU_FTR_L3CR)) { l3cr = _get_L3CR(); if ((prev_l3cr & L3CR_L3E) && l3cr != prev_l3cr) _set_L3CR(prev_l3cr); } if (notify) cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); cur_freq = (speed_mode == CPUFREQ_HIGH) ? hi_freq : low_freq; return 0;}static unsigned int pmac_cpufreq_get_speed(unsigned int cpu){ return cur_freq;}static int pmac_cpufreq_verify(struct cpufreq_policy *policy){ return cpufreq_frequency_table_verify(policy, pmac_cpu_freqs);}static int pmac_cpufreq_target( struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation){ unsigned int newstate = 0; int rc; if (cpufreq_frequency_table_target(policy, pmac_cpu_freqs, target_freq, relation, &newstate)) return -EINVAL; rc = do_set_cpu_speed(newstate, 1); ppc_proc_freq = cur_freq * 1000ul; return rc;}static int pmac_cpufreq_cpu_init(struct cpufreq_policy *policy){ if (policy->cpu != 0) return -ENODEV; policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; policy->cur = cur_freq; cpufreq_frequency_table_get_attr(pmac_cpu_freqs, policy->cpu); return cpufreq_frequency_table_cpuinfo(policy, pmac_cpu_freqs);}static u32 read_gpio(struct device_node *np){ const u32 *reg = of_get_property(np, "reg", NULL); u32 offset; if (reg == NULL) return 0; /* That works for all keylargos but shall be fixed properly * some day... The problem is that it seems we can't rely * on the "reg" property of the GPIO nodes, they are either * relative to the base of KeyLargo or to the base of the * GPIO space, and the device-tree doesn't help. */ offset = *reg; if (offset < KEYLARGO_GPIO_LEVELS0) offset += KEYLARGO_GPIO_LEVELS0; return offset;}static int pmac_cpufreq_suspend(struct cpufreq_policy *policy, pm_message_t pmsg){ /* Ok, this could be made a bit smarter, but let's be robust for now. We * always force a speed change to high speed before sleep, to make sure * we have appropriate voltage and/or bus speed for the wakeup process, * and to make sure our loops_per_jiffies are "good enough", that is will * not cause too short delays if we sleep in low speed and wake in high * speed.. */ no_schedule = 1; sleep_freq = cur_freq; if (cur_freq == low_freq && !is_pmu_based) do_set_cpu_speed(CPUFREQ_HIGH, 0); return 0;}static int pmac_cpufreq_resume(struct cpufreq_policy *policy){ /* If we resume, first check if we have a get() function */ if (get_speed_proc) cur_freq = get_speed_proc(); else cur_freq = 0; /* We don't, hrm... we don't really know our speed here, best * is that we force a switch to whatever it was, which is * probably high speed due to our suspend() routine */ do_set_cpu_speed(sleep_freq == low_freq ? CPUFREQ_LOW : CPUFREQ_HIGH, 0); ppc_proc_freq = cur_freq * 1000ul; no_schedule = 0; return 0;}static struct cpufreq_driver pmac_cpufreq_driver = { .verify = pmac_cpufreq_verify, .target = pmac_cpufreq_target, .get = pmac_cpufreq_get_speed, .init = pmac_cpufreq_cpu_init, .suspend = pmac_cpufreq_suspend, .resume = pmac_cpufreq_resume, .flags = CPUFREQ_PM_NO_WARN, .attr = pmac_cpu_freqs_attr, .name = "powermac", .owner = THIS_MODULE,};static int pmac_cpufreq_init_MacRISC3(struct device_node *cpunode){ struct device_node *volt_gpio_np = of_find_node_by_name(NULL, "voltage-gpio"); struct device_node *freq_gpio_np = of_find_node_by_name(NULL, "frequency-gpio"); struct device_node *slew_done_gpio_np = of_find_node_by_name(NULL, "slewing-done"); const u32 *value; /* * Check to see if it's GPIO driven or PMU only * * The way we extract the GPIO address is slightly hackish, but it * works well enough for now. We need to abstract the whole GPIO * stuff sooner or later anyway */ if (volt_gpio_np) voltage_gpio = read_gpio(volt_gpio_np); if (freq_gpio_np) frequency_gpio = read_gpio(freq_gpio_np); if (slew_done_gpio_np) slew_done_gpio = read_gpio(slew_done_gpio_np); /* If we use the frequency GPIOs, calculate the min/max speeds based * on the bus frequencies */ if (frequency_gpio && slew_done_gpio) { int lenp, rc; const u32 *freqs, *ratio; freqs = of_get_property(cpunode, "bus-frequencies", &lenp); lenp /= sizeof(u32); if (freqs == NULL || lenp != 2) { printk(KERN_ERR "cpufreq: bus-frequencies incorrect or missing\n"); return 1; } ratio = of_get_property(cpunode, "processor-to-bus-ratio*2", NULL); if (ratio == NULL) { printk(KERN_ERR "cpufreq: processor-to-bus-ratio*2 missing\n"); return 1; } /* Get the min/max bus frequencies */ low_freq = min(freqs[0], freqs[1]); hi_freq = max(freqs[0], freqs[1]); /* Grrrr.. It _seems_ that the device-tree is lying on the low bus * frequency, it claims it to be around 84Mhz on some models while * it appears to be approx. 101Mhz on all. Let's hack around here... * fortunately, we don't need to be too precise */ if (low_freq < 98000000) low_freq = 101000000; /* Convert those to CPU core clocks */ low_freq = (low_freq * (*ratio)) / 2000; hi_freq = (hi_freq * (*ratio)) / 2000; /* Now we get the frequencies, we read the GPIO to see what is out current * speed */ rc = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0); cur_freq = (rc & 0x01) ? hi_freq : low_freq; set_speed_proc = gpios_set_cpu_speed; return 1; } /* If we use the PMU, look for the min & max frequencies in the * device-tree */ value = of_get_property(cpunode, "min-clock-frequency", NULL); if (!value) return 1; low_freq = (*value) / 1000; /* The PowerBook G4 12" (PowerBook6,1) has an error in the device-tree * here */ if (low_freq < 100000) low_freq *= 10; value = of_get_property(cpunode, "max-clock-frequency", NULL); if (!value) return 1; hi_freq = (*value) / 1000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; return 0;}static int pmac_cpufreq_init_7447A(struct device_node *cpunode){ struct device_node *volt_gpio_np; if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL) return 1; volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select"); if (volt_gpio_np) voltage_gpio = read_gpio(volt_gpio_np); if (!voltage_gpio){ printk(KERN_ERR "cpufreq: missing cpu-vcore-select gpio\n"); return 1; } /* OF only reports the high frequency */ hi_freq = cur_freq; low_freq = cur_freq/2; /* Read actual frequency from CPU */ cur_freq = dfs_get_cpu_speed(); set_speed_proc = dfs_set_cpu_speed; get_speed_proc = dfs_get_cpu_speed; return 0;}static int pmac_cpufreq_init_750FX(struct device_node *cpunode){ struct device_node *volt_gpio_np; u32 pvr; const u32 *value; if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL) return 1; hi_freq = cur_freq; value = of_get_property(cpunode, "reduced-clock-frequency", NULL); if (!value) return 1; low_freq = (*value) / 1000; volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select"); if (volt_gpio_np) voltage_gpio = read_gpio(volt_gpio_np); pvr = mfspr(SPRN_PVR); has_cpu_l2lve = !((pvr & 0xf00) == 0x100); set_speed_proc = cpu_750fx_cpu_speed; get_speed_proc = cpu_750fx_get_cpu_speed; cur_freq = cpu_750fx_get_cpu_speed(); return 0;}/* Currently, we support the following machines: * * - Titanium PowerBook 1Ghz (PMU based, 667Mhz & 1Ghz) * - Titanium PowerBook 800 (PMU based, 667Mhz & 800Mhz) * - Titanium PowerBook 400 (PMU based, 300Mhz & 400Mhz) * - Titanium PowerBook 500 (PMU based, 300Mhz & 500Mhz) * - iBook2 500/600 (PMU based, 400Mhz & 500/600Mhz) * - iBook2 700 (CPU based, 400Mhz & 700Mhz, support low voltage) * - Recent MacRISC3 laptops * - All new machines with 7447A CPUs */static int __init pmac_cpufreq_setup(void){ struct device_node *cpunode; const u32 *value; if (strstr(cmd_line, "nocpufreq")) return 0; /* Assume only one CPU */ cpunode = of_find_node_by_type(NULL, "cpu"); if (!cpunode) goto out; /* Get current cpu clock freq */ value = of_get_property(cpunode, "clock-frequency", NULL); if (!value) goto out; cur_freq = (*value) / 1000; /* Check for 7447A based MacRISC3 */ if (machine_is_compatible("MacRISC3") && of_get_property(cpunode, "dynamic-power-step", NULL) && PVR_VER(mfspr(SPRN_PVR)) == 0x8003) { pmac_cpufreq_init_7447A(cpunode); /* Check for other MacRISC3 machines */ } else if (machine_is_compatible("PowerBook3,4") || machine_is_compatible("PowerBook3,5") || machine_is_compatible("MacRISC3")) { pmac_cpufreq_init_MacRISC3(cpunode); /* Else check for iBook2 500/600 */ } else if (machine_is_compatible("PowerBook4,1")) { hi_freq = cur_freq; low_freq = 400000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; } /* Else check for TiPb 550 */ else if (machine_is_compatible("PowerBook3,3") && cur_freq == 550000) { hi_freq = cur_freq; low_freq = 500000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; } /* Else check for TiPb 400 & 500 */ else if (machine_is_compatible("PowerBook3,2")) { /* We only know about the 400 MHz and the 500Mhz model * they both have 300 MHz as low frequency */ if (cur_freq < 350000 || cur_freq > 550000) goto out; hi_freq = cur_freq; low_freq = 300000; set_speed_proc = pmu_set_cpu_speed; is_pmu_based = 1; } /* Else check for 750FX */ else if (PVR_VER(mfspr(SPRN_PVR)) == 0x7000) pmac_cpufreq_init_750FX(cpunode);out: of_node_put(cpunode); if (set_speed_proc == NULL) return -ENODEV; pmac_cpu_freqs[CPUFREQ_LOW].frequency = low_freq; pmac_cpu_freqs[CPUFREQ_HIGH].frequency = hi_freq; ppc_proc_freq = cur_freq * 1000ul; printk(KERN_INFO "Registering PowerMac CPU frequency driver\n"); printk(KERN_INFO "Low: %d Mhz, High: %d Mhz, Boot: %d Mhz\n", low_freq/1000, hi_freq/1000, cur_freq/1000); return cpufreq_register_driver(&pmac_cpufreq_driver);}module_init(pmac_cpufreq_setup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -