blob: 6f7422400f32aeaca60fc887fcb7d8132b7d9a69 [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
Brian Murphy1f21d2b2007-08-21 22:34:16 +020023#include <linux/sysctl.h>
24#include <linux/stddef.h>
25#include <linux/init.h>
26#include <linux/fs.h>
27#include <linux/ctype.h>
28#include <linux/string.h>
29#include <linux/net.h>
30#include <linux/inet.h>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020031#include <linux/uaccess.h>
32
Ralf Baechle4b550482007-10-11 23:46:08 +010033#include <asm/time.h>
34
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010035#ifdef CONFIG_DS1603
Brian Murphy1f21d2b2007-08-21 22:34:16 +020036#include "ds1603.h"
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010037#endif
Brian Murphy1f21d2b2007-08-21 22:34:16 +020038
Brian Murphy1f21d2b2007-08-21 22:34:16 +020039
40/* And the same for proc */
Joe Perchesd3478d52013-06-14 01:37:29 +000041int proc_dolasatstring(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020042 void *buffer, size_t *lenp, loff_t *ppos)
43{
44 int r;
45
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070046 r = proc_dostring(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010047 if ((!write) || r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020048 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010049
Brian Murphy1f21d2b2007-08-21 22:34:16 +020050 lasat_write_eeprom_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +020051
52 return 0;
53}
54
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010055#ifdef CONFIG_DS1603
Brian Murphy1f21d2b2007-08-21 22:34:16 +020056static int rtctmp;
57
Brian Murphy1f21d2b2007-08-21 22:34:16 +020058/* proc function to read/write RealTime Clock */
Joe Perchesd3478d52013-06-14 01:37:29 +000059int proc_dolasatrtc(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020060 void *buffer, size_t *lenp, loff_t *ppos)
61{
Xunlei Pang2ee96632015-04-01 20:34:22 -070062 struct timespec64 ts;
Brian Murphy1f21d2b2007-08-21 22:34:16 +020063 int r;
64
Brian Murphy1f21d2b2007-08-21 22:34:16 +020065 if (!write) {
Xunlei Pang2ee96632015-04-01 20:34:22 -070066 read_persistent_clock64(&ts);
Martin Schwidefskyd4f587c2009-08-14 15:47:31 +020067 rtctmp = ts.tv_sec;
Brian Murphy1f21d2b2007-08-21 22:34:16 +020068 /* check for time < 0 and set to 0 */
69 if (rtctmp < 0)
70 rtctmp = 0;
71 }
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070072 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010073 if (r)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020074 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010075
76 if (write)
77 rtc_mips_set_mmss(rtctmp);
Brian Murphy1f21d2b2007-08-21 22:34:16 +020078
79 return 0;
80}
81#endif
82
Brian Murphy1f21d2b2007-08-21 22:34:16 +020083#ifdef CONFIG_INET
Joe Perchesd3478d52013-06-14 01:37:29 +000084int proc_lasat_ip(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020085 void *buffer, size_t *lenp, loff_t *ppos)
86{
87 unsigned int ip;
88 char *p, c;
89 int len;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +010090 char ipbuf[32];
Brian Murphy1f21d2b2007-08-21 22:34:16 +020091
92 if (!table->data || !table->maxlen || !*lenp ||
93 (*ppos && !write)) {
94 *lenp = 0;
95 return 0;
96 }
97
Brian Murphy1f21d2b2007-08-21 22:34:16 +020098 if (write) {
99 len = 0;
100 p = buffer;
101 while (len < *lenp) {
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100102 if (get_user(c, p++))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200103 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200104 if (c == 0 || c == '\n')
105 break;
106 len++;
107 }
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100108 if (len >= sizeof(ipbuf)-1)
109 len = sizeof(ipbuf) - 1;
110 if (copy_from_user(ipbuf, buffer, len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200111 return -EFAULT;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100112 ipbuf[len] = 0;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200113 *ppos += *lenp;
114 /* Now see if we can convert it to a valid IP */
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100115 ip = in_aton(ipbuf);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200116 *(unsigned int *)(table->data) = ip;
117 lasat_write_eeprom_info();
118 } else {
119 ip = *(unsigned int *)(table->data);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100120 sprintf(ipbuf, "%d.%d.%d.%d",
Ralf Baechle70342282013-01-22 12:59:30 +0100121 (ip) & 0xff,
122 (ip >> 8) & 0xff,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200123 (ip >> 16) & 0xff,
124 (ip >> 24) & 0xff);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100125 len = strlen(ipbuf);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200126 if (len > *lenp)
127 len = *lenp;
128 if (len)
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100129 if (copy_to_user(buffer, ipbuf, len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200130 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200131 if (len < *lenp) {
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100132 if (put_user('\n', ((char *) buffer) + len))
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200133 return -EFAULT;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200134 len++;
135 }
136 *lenp = len;
137 *ppos += len;
138 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200139
140 return 0;
141}
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100142#endif
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200143
Joe Perchesd3478d52013-06-14 01:37:29 +0000144int proc_lasat_prid(struct ctl_table *table, int write,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200145 void *buffer, size_t *lenp, loff_t *ppos)
146{
147 int r;
148
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700149 r = proc_dointvec(table, write, buffer, lenp, ppos);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100150 if (r < 0)
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200151 return r;
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100152 if (write) {
153 lasat_board_info.li_eeprom_info.prid =
154 lasat_board_info.li_prid;
155 lasat_write_eeprom_info();
156 lasat_init_board_info();
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200157 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200158 return 0;
159}
160
161extern int lasat_boot_to_service;
162
Joe Perchesd3478d52013-06-14 01:37:29 +0000163static struct ctl_table lasat_table[] = {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200164 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200165 .procname = "cpu-hz",
166 .data = &lasat_board_info.li_cpu_hz,
167 .maxlen = sizeof(int),
168 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800169 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200170 },
171 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200172 .procname = "bus-hz",
173 .data = &lasat_board_info.li_bus_hz,
174 .maxlen = sizeof(int),
175 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800176 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200177 },
178 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200179 .procname = "bmid",
180 .data = &lasat_board_info.li_bmid,
181 .maxlen = sizeof(int),
182 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800183 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200184 },
185 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200186 .procname = "prid",
187 .data = &lasat_board_info.li_prid,
188 .maxlen = sizeof(int),
189 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800190 .proc_handler = proc_lasat_prid,
Ralf Baechle606d62f2009-12-17 01:57:37 +0000191 },
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200192#ifdef CONFIG_INET
193 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200194 .procname = "ipaddr",
195 .data = &lasat_board_info.li_eeprom_info.ipaddr,
196 .maxlen = sizeof(int),
197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800198 .proc_handler = proc_lasat_ip,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200199 },
200 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200201 .procname = "netmask",
202 .data = &lasat_board_info.li_eeprom_info.netmask,
203 .maxlen = sizeof(int),
204 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800205 .proc_handler = proc_lasat_ip,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200206 },
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200207#endif
208 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200209 .procname = "passwd_hash",
210 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
211 .maxlen =
212 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
213 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800214 .proc_handler = proc_dolasatstring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200215 },
216 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200217 .procname = "boot-service",
218 .data = &lasat_boot_to_service,
219 .maxlen = sizeof(int),
220 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800221 .proc_handler = proc_dointvec,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200222 },
223#ifdef CONFIG_DS1603
224 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200225 .procname = "rtc",
226 .data = &rtctmp,
227 .maxlen = sizeof(int),
228 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800229 .proc_handler = proc_dolasatrtc,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200230 },
231#endif
232 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200233 .procname = "namestr",
234 .data = &lasat_board_info.li_namestr,
235 .maxlen = sizeof(lasat_board_info.li_namestr),
236 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800237 .proc_handler = proc_dostring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200238 },
239 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200240 .procname = "typestr",
241 .data = &lasat_board_info.li_typestr,
242 .maxlen = sizeof(lasat_board_info.li_typestr),
243 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800244 .proc_handler = proc_dostring,
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200245 },
246 {}
247};
248
Joe Perchesd3478d52013-06-14 01:37:29 +0000249static struct ctl_table lasat_root_table[] = {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200250 {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200251 .procname = "lasat",
252 .mode = 0555,
253 .child = lasat_table
254 },
255 {}
256};
257
258static int __init lasat_register_sysctl(void)
259{
260 struct ctl_table_header *lasat_table_header;
261
262 lasat_table_header =
263 register_sysctl_table(lasat_root_table);
Thomas Horsten1f34f2e2008-06-15 02:17:11 +0100264 if (!lasat_table_header) {
265 printk(KERN_ERR "Unable to register LASAT sysctl\n");
266 return -ENOMEM;
267 }
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200268
269 return 0;
270}
271
Ralf Baechle1bab0b62015-07-20 09:09:40 +0200272arch_initcall(lasat_register_sysctl);