blob: 3b7f65cc42187e95627bdd14b461be0e60e7342b [file] [log] [blame]
Brian Murphy1f21d2b2007-08-21 22:34:16 +02001/*
2 * Thomas Horsten <thh@lasat.com>
3 * Copyright (C) 2000 LASAT Networks A/S.
4 *
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.
8 *
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.
13 *
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.
17 *
18 * Routines specific to the LASAT boards
19 */
20#include <linux/types.h>
21#include <asm/lasat/lasat.h>
22
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>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020032#include <linux/uaccess.h>
33
Ralf Baechle4b550482007-10-11 23:46:08 +010034#include <asm/time.h>
35
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010036#ifdef CONFIG_DS1603
Brian Murphy1f21d2b2007-08-21 22:34:16 +020037#include "ds1603.h"
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010038#endif
Brian Murphy1f21d2b2007-08-21 22:34:16 +020039
Brian Murphy1f21d2b2007-08-21 22:34:16 +020040
41/* And the same for proc */
Joe Perchesd3478d52013-06-14 01:37:29 +000042int proc_dolasatstring(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020043 void *buffer, size_t *lenp, loff_t *ppos)
44{
45 int r;
46
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070047 r = proc_dostring(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010048 if ((!write) || r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020049 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010050
Brian Murphy1f21d2b2007-08-21 22:34:16 +020051 lasat_write_eeprom_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +020052
53 return 0;
54}
55
56/* proc function to write EEPROM after changing int entry */
Joe Perchesd3478d52013-06-14 01:37:29 +000057int proc_dolasatint(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020058 void *buffer, size_t *lenp, loff_t *ppos)
59{
60 int r;
61
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070062 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010063 if ((!write) || r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020064 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010065
Brian Murphy1f21d2b2007-08-21 22:34:16 +020066 lasat_write_eeprom_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +020067
68 return 0;
69}
70
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010071#ifdef CONFIG_DS1603
Brian Murphy1f21d2b2007-08-21 22:34:16 +020072static int rtctmp;
73
Brian Murphy1f21d2b2007-08-21 22:34:16 +020074/* proc function to read/write RealTime Clock */
Joe Perchesd3478d52013-06-14 01:37:29 +000075int proc_dolasatrtc(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020076 void *buffer, size_t *lenp, loff_t *ppos)
77{
Martin Schwidefskyd4f587c2009-08-14 15:47:31 +020078 struct timespec ts;
Brian Murphy1f21d2b2007-08-21 22:34:16 +020079 int r;
80
Brian Murphy1f21d2b2007-08-21 22:34:16 +020081 if (!write) {
Martin Schwidefskyd4f587c2009-08-14 15:47:31 +020082 read_persistent_clock(&ts);
83 rtctmp = ts.tv_sec;
Brian Murphy1f21d2b2007-08-21 22:34:16 +020084 /* check for time < 0 and set to 0 */
85 if (rtctmp < 0)
86 rtctmp = 0;
87 }
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070088 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010089 if (r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020090 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010091
92 if (write)
93 rtc_mips_set_mmss(rtctmp);
Brian Murphy1f21d2b2007-08-21 22:34:16 +020094
95 return 0;
96}
97#endif
98
Brian Murphy1f21d2b2007-08-21 22:34:16 +020099#ifdef CONFIG_INET
Joe Perchesd3478d52013-06-14 01:37:29 +0000100int proc_lasat_ip(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200101 void *buffer, size_t *lenp, loff_t *ppos)
102{
103 unsigned int ip;
104 char *p, c;
105 int len;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100106 char ipbuf[32];
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200107
108 if (!table->data || !table->maxlen || !*lenp ||
109 (*ppos && !write)) {
110 *lenp = 0;
111 return 0;
112 }
113
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200114 if (write) {
115 len = 0;
116 p = buffer;
117 while (len < *lenp) {
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100118 if (get_user(c, p++))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200119 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200120 if (c == 0 || c == '\n')
121 break;
122 len++;
123 }
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100124 if (len >= sizeof(ipbuf)-1)
125 len = sizeof(ipbuf) - 1;
126 if (copy_from_user(ipbuf, buffer, len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200127 return -EFAULT;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100128 ipbuf[len] = 0;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200129 *ppos += *lenp;
130 /* Now see if we can convert it to a valid IP */
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100131 ip = in_aton(ipbuf);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200132 *(unsigned int *)(table->data) = ip;
133 lasat_write_eeprom_info();
134 } else {
135 ip = *(unsigned int *)(table->data);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100136 sprintf(ipbuf, "%d.%d.%d.%d",
Ralf Baechle70342282013-01-22 12:59:30 +0100137 (ip) & 0xff,
138 (ip >> 8) & 0xff,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200139 (ip >> 16) & 0xff,
140 (ip >> 24) & 0xff);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100141 len = strlen(ipbuf);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200142 if (len > *lenp)
143 len = *lenp;
144 if (len)
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100145 if (copy_to_user(buffer, ipbuf, len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200146 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200147 if (len < *lenp) {
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100148 if (put_user('\n', ((char *) buffer) + len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200149 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200150 len++;
151 }
152 *lenp = len;
153 *ppos += len;
154 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200155
156 return 0;
157}
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100158#endif
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200159
Joe Perchesd3478d52013-06-14 01:37:29 +0000160int proc_lasat_prid(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200161 void *buffer, size_t *lenp, loff_t *ppos)
162{
163 int r;
164
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700165 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100166 if (r < 0)
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200167 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100168 if (write) {
169 lasat_board_info.li_eeprom_info.prid =
170 lasat_board_info.li_prid;
171 lasat_write_eeprom_info();
172 lasat_init_board_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200173 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200174 return 0;
175}
176
177extern int lasat_boot_to_service;
178
Joe Perchesd3478d52013-06-14 01:37:29 +0000179static struct ctl_table lasat_table[] = {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200180 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200181 .procname = "cpu-hz",
182 .data = &lasat_board_info.li_cpu_hz,
183 .maxlen = sizeof(int),
184 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800185 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200186 },
187 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200188 .procname = "bus-hz",
189 .data = &lasat_board_info.li_bus_hz,
190 .maxlen = sizeof(int),
191 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800192 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200193 },
194 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200195 .procname = "bmid",
196 .data = &lasat_board_info.li_bmid,
197 .maxlen = sizeof(int),
198 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800199 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200200 },
201 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200202 .procname = "prid",
203 .data = &lasat_board_info.li_prid,
204 .maxlen = sizeof(int),
205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800206 .proc_handler = proc_lasat_prid,
Ralf Baechle606d62f2009-12-17 01:57:37 +0000207 },
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200208#ifdef CONFIG_INET
209 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200210 .procname = "ipaddr",
211 .data = &lasat_board_info.li_eeprom_info.ipaddr,
212 .maxlen = sizeof(int),
213 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800214 .proc_handler = proc_lasat_ip,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200215 },
216 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200217 .procname = "netmask",
218 .data = &lasat_board_info.li_eeprom_info.netmask,
219 .maxlen = sizeof(int),
220 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800221 .proc_handler = proc_lasat_ip,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200222 },
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200223#endif
224 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200225 .procname = "passwd_hash",
226 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
227 .maxlen =
228 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
229 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800230 .proc_handler = proc_dolasatstring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200231 },
232 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200233 .procname = "boot-service",
234 .data = &lasat_boot_to_service,
235 .maxlen = sizeof(int),
236 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800237 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200238 },
239#ifdef CONFIG_DS1603
240 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200241 .procname = "rtc",
242 .data = &rtctmp,
243 .maxlen = sizeof(int),
244 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800245 .proc_handler = proc_dolasatrtc,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200246 },
247#endif
248 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200249 .procname = "namestr",
250 .data = &lasat_board_info.li_namestr,
251 .maxlen = sizeof(lasat_board_info.li_namestr),
252 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800253 .proc_handler = proc_dostring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200254 },
255 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200256 .procname = "typestr",
257 .data = &lasat_board_info.li_typestr,
258 .maxlen = sizeof(lasat_board_info.li_typestr),
259 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800260 .proc_handler = proc_dostring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200261 },
262 {}
263};
264
Joe Perchesd3478d52013-06-14 01:37:29 +0000265static struct ctl_table lasat_root_table[] = {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200266 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200267 .procname = "lasat",
268 .mode = 0555,
269 .child = lasat_table
270 },
271 {}
272};
273
274static int __init lasat_register_sysctl(void)
275{
276 struct ctl_table_header *lasat_table_header;
277
278 lasat_table_header =
279 register_sysctl_table(lasat_root_table);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100280 if (!lasat_table_header) {
281 printk(KERN_ERR "Unable to register LASAT sysctl\n");
282 return -ENOMEM;
283 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200284
285 return 0;
286}
287
288__initcall(lasat_register_sysctl);