⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gx-suspmod.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
static void gx_set_cpuspeed(unsigned int khz){        u8 suscfg, pmer1;	unsigned int new_khz;	unsigned long flags;	struct cpufreq_freqs freqs;	freqs.cpu = 0;	freqs.old = gx_get_cpuspeed(0);	new_khz = gx_validate_speed(khz, &gx_params->on_duration, &gx_params->off_duration);	freqs.new = new_khz;	cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);	local_irq_save(flags);	if (new_khz != stock_freq) {  /* if new khz == 100% of CPU speed, it is special case */		switch (gx_params->cs55x0->device) {		case PCI_DEVICE_ID_CYRIX_5530_LEGACY:			pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP;			/* FIXME: need to test other values -- Zwane,Miura */			pci_write_config_byte(gx_params->cs55x0, PCI_IRQTC, 4); /* typical 2 to 4ms */			pci_write_config_byte(gx_params->cs55x0, PCI_VIDTC, 100);/* typical 50 to 100ms */			pci_write_config_byte(gx_params->cs55x0, PCI_PMER1, pmer1);			if (gx_params->pci_rev < 0x10) {   /* CS5530(rev 1.2, 1.3) */				suscfg = gx_params->pci_suscfg | SUSMOD;			} else {                           /* CS5530A,B.. */				suscfg = gx_params->pci_suscfg | SUSMOD | PWRSVE;			}			break;		case PCI_DEVICE_ID_CYRIX_5520:		case PCI_DEVICE_ID_CYRIX_5510:			suscfg = gx_params->pci_suscfg | SUSMOD;			break;		default:			local_irq_restore(flags);			dprintk("fatal: try to set unknown chipset.\n");			return;		}	} else {		suscfg = gx_params->pci_suscfg & ~(SUSMOD);		gx_params->off_duration = 0;		gx_params->on_duration = 0;		dprintk("suspend modulation disabled: cpu runs 100 percent speed.\n");	}	pci_write_config_byte(gx_params->cs55x0, PCI_MODOFF, gx_params->off_duration);	pci_write_config_byte(gx_params->cs55x0, PCI_MODON, gx_params->on_duration);        pci_write_config_byte(gx_params->cs55x0, PCI_SUSCFG, suscfg);        pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg);        local_irq_restore(flags);	gx_params->pci_suscfg = suscfg;	cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);        dprintk("suspend modulation w/ duration of ON:%d us, OFF:%d us\n",                gx_params->on_duration * 32, gx_params->off_duration * 32);	dprintk("suspend modulation w/ clock speed: %d kHz.\n", freqs.new); }/**************************************************************** *             High level functions                             * ****************************************************************//* *	cpufreq_gx_verify: test if frequency range is valid  * *	This function checks if a given frequency range in kHz is valid  *      for the hardware supported by the driver.  */static int cpufreq_gx_verify(struct cpufreq_policy *policy){	unsigned int tmp_freq = 0;	u8 tmp1, tmp2;        if (!stock_freq || !policy)                return -EINVAL;	policy->cpu = 0;	cpufreq_verify_within_limits(policy, (stock_freq / max_duration), stock_freq);	/* it needs to be assured that at least one supported frequency is	 * within policy->min and policy->max. If it is not, policy->max	 * needs to be increased until one freuqency is supported.	 * policy->min may not be decreased, though. This way we guarantee a 	 * specific processing capacity.	 */	tmp_freq = gx_validate_speed(policy->min, &tmp1, &tmp2);	if (tmp_freq < policy->min) 		tmp_freq += stock_freq / max_duration;	policy->min = tmp_freq;	if (policy->min > policy->max) 		policy->max = tmp_freq;	tmp_freq = gx_validate_speed(policy->max, &tmp1, &tmp2);	if (tmp_freq > policy->max)		tmp_freq -= stock_freq / max_duration;	policy->max = tmp_freq;	if (policy->max < policy->min)		policy->max = policy->min;	cpufreq_verify_within_limits(policy, (stock_freq / max_duration), stock_freq);		return 0;}/* *      cpufreq_gx_target:   * */static int cpufreq_gx_target(struct cpufreq_policy *policy,			     unsigned int target_freq,			     unsigned int relation){	u8 tmp1, tmp2;	unsigned int tmp_freq;        if (!stock_freq || !policy)                return -EINVAL;	policy->cpu = 0;	tmp_freq = gx_validate_speed(target_freq, &tmp1, &tmp2);	while (tmp_freq < policy->min) {		tmp_freq += stock_freq / max_duration;		tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2);	}	while (tmp_freq > policy->max) {		tmp_freq -= stock_freq / max_duration;		tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2);	}	gx_set_cpuspeed(tmp_freq);	return 0;}static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy){	unsigned int maxfreq, curfreq;	if (!policy || policy->cpu != 0)		return -ENODEV;	/* determine maximum frequency */	if (pci_busclk) {		maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f];	} else if (cpu_khz) {		maxfreq = cpu_khz;	} else {		maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f];	}	stock_freq = maxfreq;	curfreq = gx_get_cpuspeed(0);	dprintk("cpu max frequency is %d.\n", maxfreq);	dprintk("cpu current frequency is %dkHz.\n",curfreq);	/* setup basic struct for cpufreq API */	policy->cpu = 0;	if (max_duration < POLICY_MIN_DIV)		policy->min = maxfreq / max_duration;	else		policy->min = maxfreq / POLICY_MIN_DIV;	policy->max = maxfreq;	policy->cur = curfreq;	policy->governor = CPUFREQ_DEFAULT_GOVERNOR;	policy->cpuinfo.min_freq = maxfreq / max_duration;	policy->cpuinfo.max_freq = maxfreq;	policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;	return 0;}/*  * cpufreq_gx_init: *   MediaGX/Geode GX initialize cpufreq driver */static struct cpufreq_driver gx_suspmod_driver = {	.get		= gx_get_cpuspeed,	.verify		= cpufreq_gx_verify,	.target		= cpufreq_gx_target,	.init		= cpufreq_gx_cpu_init,	.name		= "gx-suspmod",	.owner		= THIS_MODULE,};static int __init cpufreq_gx_init(void){	int ret;	struct gxfreq_params *params;	struct pci_dev *gx_pci;	u32 class_rev;	/* Test if we have the right hardware */	if ((gx_pci = gx_detect_chipset()) == NULL) 		return -ENODEV;	/* check whether module parameters are sane */	if (max_duration > 0xff)		max_duration = 0xff;	dprintk("geode suspend modulation available.\n");	params = kmalloc(sizeof(struct gxfreq_params), GFP_KERNEL);	if (params == NULL)		return -ENOMEM;	memset(params, 0, sizeof(struct gxfreq_params));	params->cs55x0 = gx_pci;	gx_params = params;	/* keep cs55x0 configurations */	pci_read_config_byte(params->cs55x0, PCI_SUSCFG, &(params->pci_suscfg));	pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1));	pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2));	pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration));	pci_read_config_byte(params->cs55x0, PCI_MODOFF, &(params->off_duration));        pci_read_config_dword(params->cs55x0, PCI_CLASS_REVISION, &class_rev);	params->pci_rev = class_rev && 0xff;	if ((ret = cpufreq_register_driver(&gx_suspmod_driver))) { 		kfree(params);		return ret;                   /* register error! */	}	return 0;}static void __exit cpufreq_gx_exit(void){	cpufreq_unregister_driver(&gx_suspmod_driver);	pci_dev_put(gx_params->cs55x0);	kfree(gx_params);}MODULE_AUTHOR ("Hiroshi Miura <miura@da-cha.org>");MODULE_DESCRIPTION ("Cpufreq driver for Cyrix MediaGX and NatSemi Geode");MODULE_LICENSE ("GPL");module_init(cpufreq_gx_init);module_exit(cpufreq_gx_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -