windfarm_pm91.c

来自「linux 内核源代码」· C语言 代码 · 共 745 行 · 第 1/2 页

C
745
字号
static void wf_smu_create_slots_fans(void){	struct wf_pid_param param = {		.interval	= 1,		.history_len	= 8,		.gd		= 0x00000000,		.gp		= 0x00000000,		.gr		= 0x00020000,		.itarget	= 0x00000000	};	/* Alloc & initialize state */	wf_smu_slots_fans = kmalloc(sizeof(struct wf_smu_slots_fans_state),					GFP_KERNEL);	if (wf_smu_slots_fans == NULL) {		printk(KERN_WARNING "windfarm: Memory allocation error"		       " max fan speed\n");		goto fail;	}       	wf_smu_slots_fans->ticks = 1;	/* Fill PID params */	param.additive = (fan_slots->type == WF_CONTROL_RPM_FAN);	param.min = fan_slots->ops->get_min(fan_slots);	param.max = fan_slots->ops->get_max(fan_slots);	wf_pid_init(&wf_smu_slots_fans->pid, &param);	DBG("wf: Slots Fan control initialized.\n");	DBG("    itarged=%d.%03d, min=%d RPM, max=%d RPM\n",	    FIX32TOPRINT(param.itarget), param.min, param.max);	return; fail:	if (fan_slots)		wf_control_set_max(fan_slots);}static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st){	s32 new_setpoint, power;	int rc;	if (--st->ticks != 0) {		if (wf_smu_readjust)			goto readjust;		return;	}	st->ticks = st->pid.param.interval;	rc = sensor_slots_power->ops->get_value(sensor_slots_power, &power);	if (rc) {		printk(KERN_WARNING "windfarm: Slots power sensor error %d\n",		       rc);		wf_smu_failure_state |= FAILURE_SENSOR;		return;	}	DBG("wf_smu: Slots Fans tick ! Slots power: %d.%03d\n",	    FIX32TOPRINT(power));#if 0 /* Check what makes a good overtemp condition */	if (power > (st->pid.param.itarget + 0x50000))		wf_smu_failure_state |= FAILURE_OVERTEMP;#endif	new_setpoint = wf_pid_run(&st->pid, power);	DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint);	if (st->setpoint == new_setpoint)		return;	st->setpoint = new_setpoint; readjust:	if (fan_slots && wf_smu_failure_state == 0) {		rc = fan_slots->ops->set_value(fan_slots, st->setpoint);		if (rc) {			printk(KERN_WARNING "windfarm: Slots fan error %d\n",			       rc);			wf_smu_failure_state |= FAILURE_FAN;		}	}}/* * ****** Setup / Init / Misc ... ****** * */static void wf_smu_tick(void){	unsigned int last_failure = wf_smu_failure_state;	unsigned int new_failure;	if (!wf_smu_started) {		DBG("wf: creating control loops !\n");		wf_smu_create_drive_fans();		wf_smu_create_slots_fans();		wf_smu_create_cpu_fans();		wf_smu_started = 1;	}	/* Skipping ticks */	if (wf_smu_skipping && --wf_smu_skipping)		return;	wf_smu_failure_state = 0;	if (wf_smu_drive_fans)		wf_smu_drive_fans_tick(wf_smu_drive_fans);	if (wf_smu_slots_fans)		wf_smu_slots_fans_tick(wf_smu_slots_fans);	if (wf_smu_cpu_fans)		wf_smu_cpu_fans_tick(wf_smu_cpu_fans);	wf_smu_readjust = 0;	new_failure = wf_smu_failure_state & ~last_failure;	/* If entering failure mode, clamp cpufreq and ramp all	 * fans to full speed.	 */	if (wf_smu_failure_state && !last_failure) {		if (cpufreq_clamp)			wf_control_set_max(cpufreq_clamp);		if (fan_cpu_main)			wf_control_set_max(fan_cpu_main);		if (fan_cpu_second)			wf_control_set_max(fan_cpu_second);		if (fan_cpu_third)			wf_control_set_max(fan_cpu_third);		if (fan_hd)			wf_control_set_max(fan_hd);		if (fan_slots)			wf_control_set_max(fan_slots);	}	/* If leaving failure mode, unclamp cpufreq and readjust	 * all fans on next iteration	 */	if (!wf_smu_failure_state && last_failure) {		if (cpufreq_clamp)			wf_control_set_min(cpufreq_clamp);		wf_smu_readjust = 1;	}	/* Overtemp condition detected, notify and start skipping a couple	 * ticks to let the temperature go down	 */	if (new_failure & FAILURE_OVERTEMP) {		wf_set_overtemp();		wf_smu_skipping = 2;	}	/* We only clear the overtemp condition if overtemp is cleared	 * _and_ no other failure is present. Since a sensor error will	 * clear the overtemp condition (can't measure temperature) at	 * the control loop levels, but we don't want to keep it clear	 * here in this case	 */	if (new_failure == 0 && last_failure & FAILURE_OVERTEMP)		wf_clear_overtemp();}static void wf_smu_new_control(struct wf_control *ct){	if (wf_smu_all_controls_ok)		return;	if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) {		if (wf_get_control(ct) == 0)			fan_cpu_main = ct;	}	if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) {		if (wf_get_control(ct) == 0)			fan_cpu_second = ct;	}	if (fan_cpu_third == NULL && !strcmp(ct->name, "cpu-front-fan-0")) {		if (wf_get_control(ct) == 0)			fan_cpu_third = ct;	}	if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) {		if (wf_get_control(ct) == 0)			cpufreq_clamp = ct;	}	if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) {		if (wf_get_control(ct) == 0)			fan_hd = ct;	}	if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) {		if (wf_get_control(ct) == 0)			fan_slots = ct;	}	if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd &&	    fan_slots && cpufreq_clamp)		wf_smu_all_controls_ok = 1;}static void wf_smu_new_sensor(struct wf_sensor *sr){	if (wf_smu_all_sensors_ok)		return;	if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) {		if (wf_get_sensor(sr) == 0)			sensor_cpu_power = sr;	}	if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) {		if (wf_get_sensor(sr) == 0)			sensor_cpu_temp = sr;	}	if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) {		if (wf_get_sensor(sr) == 0)			sensor_hd_temp = sr;	}	if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) {		if (wf_get_sensor(sr) == 0)			sensor_slots_power = sr;	}	if (sensor_cpu_power && sensor_cpu_temp &&	    sensor_hd_temp && sensor_slots_power)		wf_smu_all_sensors_ok = 1;}static int wf_smu_notify(struct notifier_block *self,			       unsigned long event, void *data){	switch(event) {	case WF_EVENT_NEW_CONTROL:		DBG("wf: new control %s detected\n",		    ((struct wf_control *)data)->name);		wf_smu_new_control(data);		wf_smu_readjust = 1;		break;	case WF_EVENT_NEW_SENSOR:		DBG("wf: new sensor %s detected\n",		    ((struct wf_sensor *)data)->name);		wf_smu_new_sensor(data);		break;	case WF_EVENT_TICK:		if (wf_smu_all_controls_ok && wf_smu_all_sensors_ok)			wf_smu_tick();	}	return 0;}static struct notifier_block wf_smu_events = {	.notifier_call	= wf_smu_notify,};static int wf_init_pm(void){	printk(KERN_INFO "windfarm: Initializing for Desktop G5 model\n");	return 0;}static int wf_smu_probe(struct platform_device *ddev){	wf_register_client(&wf_smu_events);	return 0;}static int __devexit wf_smu_remove(struct platform_device *ddev){	wf_unregister_client(&wf_smu_events);	/* XXX We don't have yet a guarantee that our callback isn't	 * in progress when returning from wf_unregister_client, so	 * we add an arbitrary delay. I'll have to fix that in the core	 */	msleep(1000);	/* Release all sensors */	/* One more crappy race: I don't think we have any guarantee here	 * that the attribute callback won't race with the sensor beeing	 * disposed of, and I'm not 100% certain what best way to deal	 * with that except by adding locks all over... I'll do that	 * eventually but heh, who ever rmmod this module anyway ?	 */	if (sensor_cpu_power)		wf_put_sensor(sensor_cpu_power);	if (sensor_cpu_temp)		wf_put_sensor(sensor_cpu_temp);	if (sensor_hd_temp)		wf_put_sensor(sensor_hd_temp);	if (sensor_slots_power)		wf_put_sensor(sensor_slots_power);	/* Release all controls */	if (fan_cpu_main)		wf_put_control(fan_cpu_main);	if (fan_cpu_second)		wf_put_control(fan_cpu_second);	if (fan_cpu_third)		wf_put_control(fan_cpu_third);	if (fan_hd)		wf_put_control(fan_hd);	if (fan_slots)		wf_put_control(fan_slots);	if (cpufreq_clamp)		wf_put_control(cpufreq_clamp);	/* Destroy control loops state structures */	if (wf_smu_slots_fans)		kfree(wf_smu_cpu_fans);	if (wf_smu_drive_fans)		kfree(wf_smu_cpu_fans);	if (wf_smu_cpu_fans)		kfree(wf_smu_cpu_fans);	return 0;}static struct platform_driver wf_smu_driver = {        .probe = wf_smu_probe,        .remove = __devexit_p(wf_smu_remove),	.driver = {		.name = "windfarm",		.bus = &platform_bus_type,	},};static int __init wf_smu_init(void){	int rc = -ENODEV;	if (machine_is_compatible("PowerMac9,1"))		rc = wf_init_pm();	if (rc == 0) {#ifdef MODULE		request_module("windfarm_smu_controls");		request_module("windfarm_smu_sensors");		request_module("windfarm_lm75_sensor");		request_module("windfarm_cpufreq_clamp");#endif /* MODULE */		platform_driver_register(&wf_smu_driver);	}	return rc;}static void __exit wf_smu_exit(void){	platform_driver_unregister(&wf_smu_driver);}module_init(wf_smu_init);module_exit(wf_smu_exit);MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1");MODULE_LICENSE("GPL");

⌨️ 快捷键说明

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