arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / mips / lasat / sysctl.c
blobe666fe26c50d34f68addb5f553de5bfe98aa21b2
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Thomas Horsten <thh@lasat.com>
4 * Copyright (C) 2000 LASAT Networks A/S.
6 * Routines specific to the LASAT boards
7 */
8 #include <linux/types.h>
9 #include <asm/lasat/lasat.h>
11 #include <linux/sysctl.h>
12 #include <linux/stddef.h>
13 #include <linux/init.h>
14 #include <linux/fs.h>
15 #include <linux/ctype.h>
16 #include <linux/string.h>
17 #include <linux/net.h>
18 #include <linux/inet.h>
19 #include <linux/uaccess.h>
21 #include <asm/time.h>
23 #ifdef CONFIG_DS1603
24 #include "ds1603.h"
25 #endif
28 /* And the same for proc */
29 int proc_dolasatstring(struct ctl_table *table, int write,
30 void *buffer, size_t *lenp, loff_t *ppos)
32 int r;
34 r = proc_dostring(table, write, buffer, lenp, ppos);
35 if ((!write) || r)
36 return r;
38 lasat_write_eeprom_info();
40 return 0;
43 #ifdef CONFIG_DS1603
44 static int rtctmp;
46 /* proc function to read/write RealTime Clock */
47 int proc_dolasatrtc(struct ctl_table *table, int write,
48 void *buffer, size_t *lenp, loff_t *ppos)
50 struct timespec64 ts;
51 int r;
53 if (!write) {
54 read_persistent_clock64(&ts);
55 rtctmp = ts.tv_sec;
56 /* check for time < 0 and set to 0 */
57 if (rtctmp < 0)
58 rtctmp = 0;
60 r = proc_dointvec(table, write, buffer, lenp, ppos);
61 if (r)
62 return r;
64 if (write) {
66 * Due to the RTC hardware limitation, we can not actually
67 * use the full 64-bit range here.
69 ts.tv_sec = rtctmp;
70 ts.tv_nsec = 0;
72 update_persistent_clock64(ts);
75 return 0;
77 #endif
79 #ifdef CONFIG_INET
80 int proc_lasat_ip(struct ctl_table *table, int write,
81 void *buffer, size_t *lenp, loff_t *ppos)
83 unsigned int ip;
84 char *p, c;
85 int len;
86 char ipbuf[32];
88 if (!table->data || !table->maxlen || !*lenp ||
89 (*ppos && !write)) {
90 *lenp = 0;
91 return 0;
94 if (write) {
95 len = 0;
96 p = buffer;
97 while (len < *lenp) {
98 if (get_user(c, p++))
99 return -EFAULT;
100 if (c == 0 || c == '\n')
101 break;
102 len++;
104 if (len >= sizeof(ipbuf)-1)
105 len = sizeof(ipbuf) - 1;
106 if (copy_from_user(ipbuf, buffer, len))
107 return -EFAULT;
108 ipbuf[len] = 0;
109 *ppos += *lenp;
110 /* Now see if we can convert it to a valid IP */
111 ip = in_aton(ipbuf);
112 *(unsigned int *)(table->data) = ip;
113 lasat_write_eeprom_info();
114 } else {
115 ip = *(unsigned int *)(table->data);
116 sprintf(ipbuf, "%d.%d.%d.%d",
117 (ip) & 0xff,
118 (ip >> 8) & 0xff,
119 (ip >> 16) & 0xff,
120 (ip >> 24) & 0xff);
121 len = strlen(ipbuf);
122 if (len > *lenp)
123 len = *lenp;
124 if (len)
125 if (copy_to_user(buffer, ipbuf, len))
126 return -EFAULT;
127 if (len < *lenp) {
128 if (put_user('\n', ((char *) buffer) + len))
129 return -EFAULT;
130 len++;
132 *lenp = len;
133 *ppos += len;
136 return 0;
138 #endif
140 int proc_lasat_prid(struct ctl_table *table, int write,
141 void *buffer, size_t *lenp, loff_t *ppos)
143 int r;
145 r = proc_dointvec(table, write, buffer, lenp, ppos);
146 if (r < 0)
147 return r;
148 if (write) {
149 lasat_board_info.li_eeprom_info.prid =
150 lasat_board_info.li_prid;
151 lasat_write_eeprom_info();
152 lasat_init_board_info();
154 return 0;
157 extern int lasat_boot_to_service;
159 static struct ctl_table lasat_table[] = {
161 .procname = "cpu-hz",
162 .data = &lasat_board_info.li_cpu_hz,
163 .maxlen = sizeof(int),
164 .mode = 0444,
165 .proc_handler = proc_dointvec,
168 .procname = "bus-hz",
169 .data = &lasat_board_info.li_bus_hz,
170 .maxlen = sizeof(int),
171 .mode = 0444,
172 .proc_handler = proc_dointvec,
175 .procname = "bmid",
176 .data = &lasat_board_info.li_bmid,
177 .maxlen = sizeof(int),
178 .mode = 0444,
179 .proc_handler = proc_dointvec,
182 .procname = "prid",
183 .data = &lasat_board_info.li_prid,
184 .maxlen = sizeof(int),
185 .mode = 0644,
186 .proc_handler = proc_lasat_prid,
188 #ifdef CONFIG_INET
190 .procname = "ipaddr",
191 .data = &lasat_board_info.li_eeprom_info.ipaddr,
192 .maxlen = sizeof(int),
193 .mode = 0644,
194 .proc_handler = proc_lasat_ip,
197 .procname = "netmask",
198 .data = &lasat_board_info.li_eeprom_info.netmask,
199 .maxlen = sizeof(int),
200 .mode = 0644,
201 .proc_handler = proc_lasat_ip,
203 #endif
205 .procname = "passwd_hash",
206 .data = &lasat_board_info.li_eeprom_info.passwd_hash,
207 .maxlen =
208 sizeof(lasat_board_info.li_eeprom_info.passwd_hash),
209 .mode = 0600,
210 .proc_handler = proc_dolasatstring,
213 .procname = "boot-service",
214 .data = &lasat_boot_to_service,
215 .maxlen = sizeof(int),
216 .mode = 0644,
217 .proc_handler = proc_dointvec,
219 #ifdef CONFIG_DS1603
221 .procname = "rtc",
222 .data = &rtctmp,
223 .maxlen = sizeof(int),
224 .mode = 0644,
225 .proc_handler = proc_dolasatrtc,
227 #endif
229 .procname = "namestr",
230 .data = &lasat_board_info.li_namestr,
231 .maxlen = sizeof(lasat_board_info.li_namestr),
232 .mode = 0444,
233 .proc_handler = proc_dostring,
236 .procname = "typestr",
237 .data = &lasat_board_info.li_typestr,
238 .maxlen = sizeof(lasat_board_info.li_typestr),
239 .mode = 0444,
240 .proc_handler = proc_dostring,
245 static struct ctl_table lasat_root_table[] = {
247 .procname = "lasat",
248 .mode = 0555,
249 .child = lasat_table
254 static int __init lasat_register_sysctl(void)
256 struct ctl_table_header *lasat_table_header;
258 lasat_table_header =
259 register_sysctl_table(lasat_root_table);
260 if (!lasat_table_header) {
261 printk(KERN_ERR "Unable to register LASAT sysctl\n");
262 return -ENOMEM;
265 return 0;
268 arch_initcall(lasat_register_sysctl);