5 #include <linux/module.h>
9 #include <linux/capability.h>
13 #include <mach/hardware.h>
15 #include <asm/uaccess.h>
20 #define THERM_USE_PROC
24 #define THERM_START_CONVERT 0xee
25 #define THERM_RESET 0xaf
26 #define THERM_READ_CONFIG 0xac
27 #define THERM_READ_TEMP 0xaa
28 #define THERM_READ_TL 0xa2
29 #define THERM_READ_TH 0xa1
30 #define THERM_WRITE_CONFIG 0x0c
31 #define THERM_WRITE_TL 0x02
32 #define THERM_WRITE_TH 0x01
38 static const char *fan_state[] = {
"off",
"on",
"on (hardwired)" };
49 static inline void netwinder_ds1620_set_clk(
int clk)
54 static inline void netwinder_ds1620_set_data(
int dat)
59 static inline int netwinder_ds1620_get_data(
void)
64 static inline void netwinder_ds1620_set_data_dir(
int dir)
69 static inline void netwinder_ds1620_reset(
void)
75 static inline void netwinder_lock(
unsigned long *
flags)
80 static inline void netwinder_unlock(
unsigned long *
flags)
85 static inline void netwinder_set_fan(
int i)
94 static inline int netwinder_get_fan(
void)
106 static void ds1620_send_bits(
int nr,
int value)
110 for (i = 0; i <
nr; i++) {
111 netwinder_ds1620_set_data(value & 1);
112 netwinder_ds1620_set_clk(0);
114 netwinder_ds1620_set_clk(1);
121 static unsigned int ds1620_recv_bits(
int nr)
123 unsigned int value = 0,
mask = 1;
126 netwinder_ds1620_set_data(0);
128 for (i = 0; i <
nr; i++) {
129 netwinder_ds1620_set_clk(0);
132 if (netwinder_ds1620_get_data())
137 netwinder_ds1620_set_clk(1);
144 static void ds1620_out(
int cmd,
int bits,
int value)
148 netwinder_lock(&flags);
149 netwinder_ds1620_set_clk(1);
150 netwinder_ds1620_set_data_dir(0);
151 netwinder_ds1620_reset();
155 ds1620_send_bits(8, cmd);
157 ds1620_send_bits(bits, value);
161 netwinder_ds1620_reset();
162 netwinder_unlock(&flags);
167 static unsigned int ds1620_in(
int cmd,
int bits)
172 netwinder_lock(&flags);
173 netwinder_ds1620_set_clk(1);
174 netwinder_ds1620_set_data_dir(0);
175 netwinder_ds1620_reset();
179 ds1620_send_bits(8, cmd);
181 netwinder_ds1620_set_data_dir(1);
182 value = ds1620_recv_bits(bits);
184 netwinder_ds1620_reset();
185 netwinder_unlock(&flags);
190 static int cvt_9_to_int(
unsigned int val)
198 static void ds1620_write_state(
struct therm *
therm)
206 static void ds1620_read_state(
struct therm *
therm)
221 signed char cur_temp_degF;
226 cur_temp_degF = (cur_temp * 9) / 5 + 32;
235 ds1620_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
239 struct therm
__user *therm;
244 uarg.i = (
int __user *)arg;
255 therm.
lo = therm.
hi - 3;
264 ds1620_write_state(&therm);
269 ds1620_read_state(&therm);
298 i = netwinder_get_fan();
309 netwinder_set_fan(i);
320 ds1620_unlocked_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
325 ret = ds1620_ioctl(file, cmd, arg);
331 #ifdef THERM_USE_PROC
334 int len,
int *eof,
void *
unused)
339 ds1620_read_state(&
th);
342 len =
sprintf(buf,
"Thermostat: HI %i.%i, LOW %i.%i; "
343 "temperature: %i.%i C, fan %s\n",
344 th.hi >> 1,
th.hi & 1 ? 5 : 0,
345 th.lo >> 1,
th.lo & 1 ? 5 : 0,
346 temp >> 1, temp & 1 ? 5 : 0,
347 fan_state[netwinder_get_fan()]);
359 .unlocked_ioctl = ds1620_unlocked_ioctl,
369 static int __init ds1620_init(
void)
372 struct therm
th, th_start;
386 ds1620_read_state(&
th);
389 ds1620_write_state(&th_start);
393 ds1620_write_state(&
th);
399 #ifdef THERM_USE_PROC
401 if (proc_therm_ds1620)
402 proc_therm_ds1620->
read_proc = proc_therm_ds1620_read;
407 ds1620_read_state(&
th);
411 "current %i.%i C, fan %s.\n",
412 th.hi >> 1,
th.hi & 1 ? 5 : 0,
413 th.lo >> 1,
th.lo & 1 ? 5 : 0,
414 ret >> 1, ret & 1 ? 5 : 0,
415 fan_state[netwinder_get_fan()]);
420 static void __exit ds1620_exit(
void)
422 #ifdef THERM_USE_PROC