aboutsummaryrefslogtreecommitdiffstats
path: root/ubuntu/omnibook/cooling.c
blob: a9a935e7e6f3edded7602cb0e6ef5c6e6399ab11 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * colling.c -- cooling methods feature
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Written by Mathieu Bérard <mathieu.berard@crans.org>, 2007
 */

#include "omnibook.h"
#include "hardware.h"

static int omnibook_cooling_read(char *buffer, struct omnibook_operation *io_op)
{
	int len = 0;

	if(mutex_lock_interruptible(&io_op->backend->mutex))
		return -ERESTARTSYS;

	len += sprintf(buffer + len, "Cooling method : %s\n", 
			io_op->backend->cooling_state ? "Performance"  : "Powersave" );

	mutex_unlock(&io_op->backend->mutex);
	return len;
}

static int omnibook_cooling_write(char *buffer, struct omnibook_operation *io_op)
{
	int retval = 0;

	if(mutex_lock_interruptible(&io_op->backend->mutex))
		return -ERESTARTSYS;


	if (*buffer == '0') {
		retval = __backend_byte_write(io_op, 
				TSM70_COOLING_OFFSET + TSM70_COOLING_POWERSAVE);
	} else if (*buffer == '1') {
		retval = __backend_byte_write(io_op,
				TSM70_COOLING_OFFSET + TSM70_COOLING_PERF);
	} else {
		retval = -EINVAL;
		goto out;
	}

	/* *buffer is either '0' or '1' here */
	if (!retval)
		io_op->backend->cooling_state = *buffer - '0' ;

	mutex_unlock(&io_op->backend->mutex);

	out:
	return retval;
}

static int __init omnibook_cooling_init(struct omnibook_operation *io_op)
{
	mutex_lock(&io_op->backend->mutex);
	/* XXX: Assumed default cooling method: performance */
	io_op->backend->cooling_state = TSM70_COOLING_PERF;
	mutex_unlock(&io_op->backend->mutex);
	return 0;
}

static void __exit omnibook_cooling_exit(struct omnibook_operation *io_op)
{
	/* Set back cooling method to performance */	
	backend_byte_write(io_op, TSM70_COOLING_OFFSET + TSM70_COOLING_PERF);
}

static struct omnibook_tbl cooling_table[] __initdata = {
	{TSM70 | TSX205, {CDI, 0, TSM70_FN_INDEX, 0, 0, 0 }},
	{0,}
};

struct omnibook_feature __declared_feature cooling_driver = {
	.name = "cooling",
	.enabled = 1,
	.read = omnibook_cooling_read,
	.write = omnibook_cooling_write,
	.init = omnibook_cooling_init,
	.exit = omnibook_cooling_exit,
	.ectypes = TSM70 | TSX205,
	.tbl = cooling_table,
};

module_param_named(cooling, cooling_driver.enabled, int, S_IRUGO);
MODULE_PARM_DESC(cooling, "Use 0 to disable, 1 to enable CPU cooling method control");

/* End of file */