ACPI: thinkpad-acpi: preserve radio state across shutdown
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / mips / lasat / sysctl.c
blob8f88886feb12e147167fa7bcf61a5961bd6430cf
1 /*
2 * Thomas Horsten <thh@lasat.com>
3 * Copyright (C) 2000 LASAT Networks A/S.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * Routines specific to the LASAT boards
20 #include <linux/types.h>
21 #include <asm/lasat/lasat.h>
23 #include <linux/module.h>
24 #include <linux/sysctl.h>
25 #include <linux/stddef.h>
26 #include <linux/init.h>
27 #include <linux/fs.h>
28 #include <linux/ctype.h>
29 #include <linux/string.h>
30 #include <linux/net.h>
31 #include <linux/inet.h>
32 #include <linux/uaccess.h>
34 #include <asm/time.h>
36 #ifdef CONFIG_DS1603
37 #include "ds1603.h"
38 #endif
40 /* Strategy function to write EEPROM after changing string entry */
41 int sysctl_lasatstring(ctl_table *table,
42 void *oldval, size_t *oldlenp,
43 void *newval, size_t newlen)
45 int r;
47 r = sysctl_string(table, oldval, oldlenp, newval, newlen);
48 if (r < 0)
49 return r;
51 if (newval && newlen)
52 lasat_write_eeprom_info();
54 return 0;
58 /* And the same for proc */
59 int proc_dolasatstring(ctl_table *table, int write, struct file *filp,
60 void *buffer, size_t *lenp, loff_t *ppos)
62 int r;
64 r = proc_dostring(table, write, filp, buffer, lenp, ppos);
65 if ((!write) || r)
66 return r;
68 lasat_write_eeprom_info();
70 return 0;
73 /* proc function to write EEPROM after changing int entry */
74 int proc_dolasatint(ctl_table *table, int write, struct file *filp,
75 void *buffer, size_t *lenp, loff_t *ppos)
77 int r;
79 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
80 if ((!write) || r)
81 return r;
83 lasat_write_eeprom_info();
85 return 0;
88 #ifdef CONFIG_DS1603
89 static int rtctmp;
91 /* proc function to read/write RealTime Clock */
92 int proc_dolasatrtc(ctl_table *table, int write, struct file *filp,
93 void *buffer, size_t *lenp, loff_t *ppos)
95 int r;
97 if (!write) {
98 rtctmp = read_persistent_clock();
99 /* check for time < 0 and set to 0 */
100 if (rtctmp < 0)
101 rtctmp = 0;
103 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
104 if (r)
105 return r;
107 if (write)
108 rtc_mips_set_mmss(rtctmp);
110 return 0;
112 #endif
114 /* Sysctl for setting the IP addresses */
115 int sysctl_lasat_intvec(ctl_table *table,
116 void *oldval, size_t *oldlenp,
117 void *newval, size_t newlen)
119 int r;
121 r = sysctl_intvec(table, oldval, oldlenp, newval, newlen);
122 if (r < 0)
123 return r;
125 if (newval && newlen)
126 lasat_write_eeprom_info();
128 return 0;
131 #ifdef CONFIG_DS1603
132 /* Same for RTC */
133 int sysctl_lasat_rtc(ctl_table *table,
134 void *oldval, size_t *oldlenp,
135 void *newval, size_t newlen)
137 int r;
139 rtctmp = read_persistent_clock();
140 if (rtctmp < 0)
141 rtctmp = 0;
142 r = sysctl_intvec(table, oldval, oldlenp, newval, newlen);
143 if (r < 0)
144 return r;
145 if (newval && newlen)
146 rtc_mips_set_mmss(rtctmp);
148 return r;
150 #endif
152 #ifdef CONFIG_INET
153 int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
154 void *buffer, size_t *lenp, loff_t *ppos)
156 unsigned int ip;
157 char *p, c;
158 int len;
159 char ipbuf[32];
161 if (!table->data || !table->maxlen || !*lenp ||
162 (*ppos && !write)) {
163 *lenp = 0;
164 return 0;
167 if (write) {
168 len = 0;
169 p = buffer;
170 while (len < *lenp) {
171 if (get_user(c, p++))
172 return -EFAULT;
173 if (c == 0 || c == '\n')
174 break;
175 len++;
177 if (len >= sizeof(ipbuf)-1)
178 len = sizeof(ipbuf) - 1;
179 if (copy_from_user(ipbuf, buffer, len))
180 return -EFAULT;
181 ipbuf[len] = 0;
182 *ppos += *lenp;
183 /* Now see if we can convert it to a valid IP */
184 ip = in_aton(ipbuf);
185 *(unsigned int *)(table->data) = ip;
186 lasat_write_eeprom_info();
187 } else {
188 ip = *(unsigned int *)(table->data);
189 sprintf(ipbuf, "%d.%d.%d.%d",
190 (ip) & 0xff,
191 (ip >> 8) & 0xff,
192 (ip >> 16) & 0xff,
193 (ip >> 24) & 0xff);
194 len = strlen(ipbuf);
195 if (len > *lenp)
196 len = *lenp;
197 if (len)
198 if (copy_to_user(buffer, ipbuf, len))
199 return -EFAULT;
200 if (len < *lenp) {
201 if (put_user('\n', ((char *) buffer) + len))
202 return -EFAULT;
203 len++;
205 *lenp = len;
206 *ppos += len;
209 return 0;
211 #endif
213 static int sysctl_lasat_prid(ctl_table *table,
214 void *oldval, size_t *oldlenp,
215 void *newval, size_t newlen)
217 int r;
219 r = sysctl_intvec(table, oldval, oldlenp, newval, newlen);
220 if (r < 0)
221 return r;
222 if (newval && newlen) {
223 lasat_board_info.li_eeprom_info.prid = *(int *)newval;
224 lasat_write_eeprom_info();
225 lasat_init_board_info();
227 return 0;
230 int proc_lasat_prid(ctl_table *table, int write, struct file *filp,
231 void *buffer, size_t *lenp, loff_t *ppos)
233 int r;
235 r = proc_dointvec(table, write, filp, buffer, lenp, ppos);
236 if (r < 0)
237 return r;
238 if (write) {
239 lasat_board_info.li_eeprom_info.prid =
240 lasat_board_info.li_prid;
241 lasat_write_eeprom_info();
242 lasat_init_board_info();
244 return 0;
247 extern int lasat_boot_to_service;
249 static ctl_table lasat_table[] = {
251 .ctl_name = CTL_UNNUMBERED,
252 .procname = "cpu-hz",
253 .data = &lasat_board_info.li_cpu_hz,
254 .maxlen = sizeof(int),
255 .mode = 0444,
256 .proc_handler = &proc_dointvec,
257 .strategy = &sysctl_intvec
260 .ctl_name = CTL_UNNUMBERED,
261 .procname = "bus-hz",
262 .data = &lasat_board_info.li_bus_hz,
263 .maxlen = sizeof(int),
264 .mode = 0444,
265 .proc_handler = &proc_dointvec,
266 .strategy = &sysctl_intvec
269 .ctl_name = CTL_UNNUMBERED,
270 .procname = "bmid",
271 .data = &lasat_board_info.li_bmid,
272 .maxlen = sizeof(int),
273 .mode = 0444,
274 .proc_handler = &proc_dointvec,
275 .strategy = &sysctl_intvec
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "prid",
280 .data = &lasat_board_info.li_prid,
281 .maxlen = sizeof(int),
282 .mode = 0644,
283 .proc_handler = &proc_lasat_prid,
284 .strategy = &sysctl_lasat_prid
286 #ifdef CONFIG_INET
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "ipaddr",
290 .data = &lasat_board_info.li_eeprom_info.ipaddr,
291 .maxlen = sizeof(int),
292 .mode = 0644,
293 .proc_handler = &proc_lasat_ip,
294 .strategy = &sysctl_lasat_intvec
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "netmask",
299 .data = &lasat_board_info.li_eeprom_info.netmask,
300 .maxlen = sizeof(int),
301 .mode = 0644,
302 .proc_handler = &proc_lasat_ip,
303 .strategy = &sysctl_lasat_intvec
305 #endif
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "passwd_hash",
309 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
310 .maxlen =
311 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
312 .mode = 0600,
313 .proc_handler = &proc_dolasatstring,
314 .strategy = &sysctl_lasatstring
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "boot-service",
319 .data = &lasat_boot_to_service,
320 .maxlen = sizeof(int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
323 .strategy = &sysctl_intvec
325 #ifdef CONFIG_DS1603
327 .ctl_name = CTL_UNNUMBERED,
328 .procname = "rtc",
329 .data = &rtctmp,
330 .maxlen = sizeof(int),
331 .mode = 0644,
332 .proc_handler = &proc_dolasatrtc,
333 .strategy = &sysctl_lasat_rtc
335 #endif
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "namestr",
339 .data = &lasat_board_info.li_namestr,
340 .maxlen = sizeof(lasat_board_info.li_namestr),
341 .mode = 0444,
342 .proc_handler = &proc_dostring,
343 .strategy = &sysctl_string
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "typestr",
348 .data = &lasat_board_info.li_typestr,
349 .maxlen = sizeof(lasat_board_info.li_typestr),
350 .mode = 0444,
351 .proc_handler = &proc_dostring,
352 .strategy = &sysctl_string
357 static ctl_table lasat_root_table[] = {
359 .ctl_name = CTL_UNNUMBERED,
360 .procname = "lasat",
361 .mode = 0555,
362 .child = lasat_table
367 static int __init lasat_register_sysctl(void)
369 struct ctl_table_header *lasat_table_header;
371 lasat_table_header =
372 register_sysctl_table(lasat_root_table);
373 if (!lasat_table_header) {
374 printk(KERN_ERR "Unable to register LASAT sysctl\n");
375 return -ENOMEM;
378 return 0;
381 __initcall(lasat_register_sysctl);