hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/m68k/mac/misc.c
....@@ -36,37 +36,9 @@
3636
3737 static void (*rom_reset)(void);
3838
39
+#if IS_ENABLED(CONFIG_NVRAM)
3940 #ifdef CONFIG_ADB_CUDA
40
-static time64_t cuda_read_time(void)
41
-{
42
- struct adb_request req;
43
- time64_t time;
44
-
45
- if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0)
46
- return 0;
47
- while (!req.complete)
48
- cuda_poll();
49
-
50
- time = (u32)((req.reply[3] << 24) | (req.reply[4] << 16) |
51
- (req.reply[5] << 8) | req.reply[6]);
52
-
53
- return time - RTC_OFFSET;
54
-}
55
-
56
-static void cuda_write_time(time64_t time)
57
-{
58
- struct adb_request req;
59
- u32 data = lower_32_bits(time + RTC_OFFSET);
60
-
61
- if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME,
62
- (data >> 24) & 0xFF, (data >> 16) & 0xFF,
63
- (data >> 8) & 0xFF, data & 0xFF) < 0)
64
- return;
65
- while (!req.complete)
66
- cuda_poll();
67
-}
68
-
69
-static __u8 cuda_read_pram(int offset)
41
+static unsigned char cuda_pram_read_byte(int offset)
7042 {
7143 struct adb_request req;
7244
....@@ -78,7 +50,7 @@
7850 return req.reply[3];
7951 }
8052
81
-static void cuda_write_pram(int offset, __u8 data)
53
+static void cuda_pram_write_byte(unsigned char data, int offset)
8254 {
8355 struct adb_request req;
8456
....@@ -91,56 +63,29 @@
9163 #endif /* CONFIG_ADB_CUDA */
9264
9365 #ifdef CONFIG_ADB_PMU
94
-static time64_t pmu_read_time(void)
66
+static unsigned char pmu_pram_read_byte(int offset)
9567 {
9668 struct adb_request req;
97
- time64_t time;
9869
99
- if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
70
+ if (pmu_request(&req, NULL, 3, PMU_READ_XPRAM,
71
+ offset & 0xFF, 1) < 0)
10072 return 0;
10173 pmu_wait_complete(&req);
10274
103
- time = (u32)((req.reply[0] << 24) | (req.reply[1] << 16) |
104
- (req.reply[2] << 8) | req.reply[3]);
105
-
106
- return time - RTC_OFFSET;
75
+ return req.reply[0];
10776 }
10877
109
-static void pmu_write_time(time64_t time)
78
+static void pmu_pram_write_byte(unsigned char data, int offset)
11079 {
11180 struct adb_request req;
112
- u32 data = lower_32_bits(time + RTC_OFFSET);
11381
114
- if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
115
- (data >> 24) & 0xFF, (data >> 16) & 0xFF,
116
- (data >> 8) & 0xFF, data & 0xFF) < 0)
82
+ if (pmu_request(&req, NULL, 4, PMU_WRITE_XPRAM,
83
+ offset & 0xFF, 1, data) < 0)
11784 return;
11885 pmu_wait_complete(&req);
119
-}
120
-
121
-static __u8 pmu_read_pram(int offset)
122
-{
123
- struct adb_request req;
124
-
125
- if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM,
126
- (offset >> 8) & 0xFF, offset & 0xFF) < 0)
127
- return 0;
128
- while (!req.complete)
129
- pmu_poll();
130
- return req.reply[3];
131
-}
132
-
133
-static void pmu_write_pram(int offset, __u8 data)
134
-{
135
- struct adb_request req;
136
-
137
- if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM,
138
- (offset >> 8) & 0xFF, offset & 0xFF, data) < 0)
139
- return;
140
- while (!req.complete)
141
- pmu_poll();
14286 }
14387 #endif /* CONFIG_ADB_PMU */
88
+#endif /* CONFIG_NVRAM */
14489
14590 /*
14691 * VIA PRAM/RTC access routines
....@@ -149,7 +94,7 @@
14994 * the RTC should be enabled.
15095 */
15196
152
-static __u8 via_pram_readbyte(void)
97
+static __u8 via_rtc_recv(void)
15398 {
15499 int i, reg;
155100 __u8 data;
....@@ -176,7 +121,7 @@
176121 return data;
177122 }
178123
179
-static void via_pram_writebyte(__u8 data)
124
+static void via_rtc_send(__u8 data)
180125 {
181126 int i, reg, bit;
182127
....@@ -193,6 +138,31 @@
193138 }
194139
195140 /*
141
+ * These values can be found in Inside Macintosh vol. III ch. 2
142
+ * which has a description of the RTC chip in the original Mac.
143
+ */
144
+
145
+#define RTC_FLG_READ BIT(7)
146
+#define RTC_FLG_WRITE_PROTECT BIT(7)
147
+#define RTC_CMD_READ(r) (RTC_FLG_READ | (r << 2))
148
+#define RTC_CMD_WRITE(r) (r << 2)
149
+#define RTC_REG_SECONDS_0 0
150
+#define RTC_REG_SECONDS_1 1
151
+#define RTC_REG_SECONDS_2 2
152
+#define RTC_REG_SECONDS_3 3
153
+#define RTC_REG_WRITE_PROTECT 13
154
+
155
+/*
156
+ * Inside Mac has no information about two-byte RTC commands but
157
+ * the MAME/MESS source code has the essentials.
158
+ */
159
+
160
+#define RTC_REG_XPRAM 14
161
+#define RTC_CMD_XPRAM_READ (RTC_CMD_READ(RTC_REG_XPRAM) << 8)
162
+#define RTC_CMD_XPRAM_WRITE (RTC_CMD_WRITE(RTC_REG_XPRAM) << 8)
163
+#define RTC_CMD_XPRAM_ARG(a) (((a & 0xE0) << 3) | ((a & 0x1F) << 2))
164
+
165
+/*
196166 * Execute a VIA PRAM/RTC command. For read commands
197167 * data should point to a one-byte buffer for the
198168 * resulting data. For write commands it should point
....@@ -201,29 +171,33 @@
201171 * This function disables all interrupts while running.
202172 */
203173
204
-static void via_pram_command(int command, __u8 *data)
174
+static void via_rtc_command(int command, __u8 *data)
205175 {
206176 unsigned long flags;
207177 int is_read;
208178
209179 local_irq_save(flags);
210180
181
+ /* The least significant bits must be 0b01 according to Inside Mac */
182
+
183
+ command = (command & ~3) | 1;
184
+
211185 /* Enable the RTC and make sure the strobe line is high */
212186
213187 via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb;
214188
215189 if (command & 0xFF00) { /* extended (two-byte) command */
216
- via_pram_writebyte((command & 0xFF00) >> 8);
217
- via_pram_writebyte(command & 0xFF);
218
- is_read = command & 0x8000;
190
+ via_rtc_send((command & 0xFF00) >> 8);
191
+ via_rtc_send(command & 0xFF);
192
+ is_read = command & (RTC_FLG_READ << 8);
219193 } else { /* one-byte command */
220
- via_pram_writebyte(command);
221
- is_read = command & 0x80;
194
+ via_rtc_send(command);
195
+ is_read = command & RTC_FLG_READ;
222196 }
223197 if (is_read) {
224
- *data = via_pram_readbyte();
198
+ *data = via_rtc_recv();
225199 } else {
226
- via_pram_writebyte(*data);
200
+ via_rtc_send(*data);
227201 }
228202
229203 /* All done, disable the RTC */
....@@ -233,14 +207,30 @@
233207 local_irq_restore(flags);
234208 }
235209
236
-static __u8 via_read_pram(int offset)
210
+#if IS_ENABLED(CONFIG_NVRAM)
211
+static unsigned char via_pram_read_byte(int offset)
237212 {
238
- return 0;
213
+ unsigned char temp;
214
+
215
+ via_rtc_command(RTC_CMD_XPRAM_READ | RTC_CMD_XPRAM_ARG(offset), &temp);
216
+
217
+ return temp;
239218 }
240219
241
-static void via_write_pram(int offset, __u8 data)
220
+static void via_pram_write_byte(unsigned char data, int offset)
242221 {
222
+ unsigned char temp;
223
+
224
+ temp = 0x55;
225
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
226
+
227
+ temp = data;
228
+ via_rtc_command(RTC_CMD_XPRAM_WRITE | RTC_CMD_XPRAM_ARG(offset), &temp);
229
+
230
+ temp = 0x55 | RTC_FLG_WRITE_PROTECT;
231
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
243232 }
233
+#endif /* CONFIG_NVRAM */
244234
245235 /*
246236 * Return the current time in seconds since January 1, 1904.
....@@ -257,10 +247,10 @@
257247 } result, last_result;
258248 int count = 1;
259249
260
- via_pram_command(0x81, &last_result.cdata[3]);
261
- via_pram_command(0x85, &last_result.cdata[2]);
262
- via_pram_command(0x89, &last_result.cdata[1]);
263
- via_pram_command(0x8D, &last_result.cdata[0]);
250
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0), &last_result.cdata[3]);
251
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1), &last_result.cdata[2]);
252
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2), &last_result.cdata[1]);
253
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3), &last_result.cdata[0]);
264254
265255 /*
266256 * The NetBSD guys say to loop until you get the same reading
....@@ -268,10 +258,14 @@
268258 */
269259
270260 while (1) {
271
- via_pram_command(0x81, &result.cdata[3]);
272
- via_pram_command(0x85, &result.cdata[2]);
273
- via_pram_command(0x89, &result.cdata[1]);
274
- via_pram_command(0x8D, &result.cdata[0]);
261
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_0),
262
+ &result.cdata[3]);
263
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_1),
264
+ &result.cdata[2]);
265
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_2),
266
+ &result.cdata[1]);
267
+ via_rtc_command(RTC_CMD_READ(RTC_REG_SECONDS_3),
268
+ &result.cdata[0]);
275269
276270 if (result.idata == last_result.idata)
277271 return (time64_t)result.idata - RTC_OFFSET;
....@@ -295,29 +289,33 @@
295289 * is basically any machine with Mac II-style ADB.
296290 */
297291
298
-static void via_write_time(time64_t time)
292
+static void via_set_rtc_time(struct rtc_time *tm)
299293 {
300294 union {
301295 __u8 cdata[4];
302296 __u32 idata;
303297 } data;
304298 __u8 temp;
299
+ time64_t time;
300
+
301
+ time = mktime64(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
302
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
305303
306304 /* Clear the write protect bit */
307305
308306 temp = 0x55;
309
- via_pram_command(0x35, &temp);
307
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
310308
311309 data.idata = lower_32_bits(time + RTC_OFFSET);
312
- via_pram_command(0x01, &data.cdata[3]);
313
- via_pram_command(0x05, &data.cdata[2]);
314
- via_pram_command(0x09, &data.cdata[1]);
315
- via_pram_command(0x0D, &data.cdata[0]);
310
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_0), &data.cdata[3]);
311
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_1), &data.cdata[2]);
312
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_2), &data.cdata[1]);
313
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_SECONDS_3), &data.cdata[0]);
316314
317315 /* Set the write protect bit */
318316
319
- temp = 0xD5;
320
- via_pram_command(0x35, &temp);
317
+ temp = 0x55 | RTC_FLG_WRITE_PROTECT;
318
+ via_rtc_command(RTC_CMD_WRITE(RTC_REG_WRITE_PROTECT), &temp);
321319 }
322320
323321 static void via_shutdown(void)
....@@ -378,65 +376,57 @@
378376 *-------------------------------------------------------------------
379377 */
380378
381
-void mac_pram_read(int offset, __u8 *buffer, int len)
379
+#if IS_ENABLED(CONFIG_NVRAM)
380
+unsigned char mac_pram_read_byte(int addr)
382381 {
383
- __u8 (*func)(int);
384
- int i;
385
-
386382 switch (macintosh_config->adb_type) {
387383 case MAC_ADB_IOP:
388384 case MAC_ADB_II:
389385 case MAC_ADB_PB1:
390
- func = via_read_pram;
391
- break;
386
+ return via_pram_read_byte(addr);
392387 #ifdef CONFIG_ADB_CUDA
393388 case MAC_ADB_EGRET:
394389 case MAC_ADB_CUDA:
395
- func = cuda_read_pram;
396
- break;
390
+ return cuda_pram_read_byte(addr);
397391 #endif
398392 #ifdef CONFIG_ADB_PMU
399393 case MAC_ADB_PB2:
400
- func = pmu_read_pram;
401
- break;
394
+ return pmu_pram_read_byte(addr);
402395 #endif
403396 default:
404
- return;
405
- }
406
- for (i = 0 ; i < len ; i++) {
407
- buffer[i] = (*func)(offset++);
397
+ return 0xFF;
408398 }
409399 }
410400
411
-void mac_pram_write(int offset, __u8 *buffer, int len)
401
+void mac_pram_write_byte(unsigned char val, int addr)
412402 {
413
- void (*func)(int, __u8);
414
- int i;
415
-
416403 switch (macintosh_config->adb_type) {
417404 case MAC_ADB_IOP:
418405 case MAC_ADB_II:
419406 case MAC_ADB_PB1:
420
- func = via_write_pram;
407
+ via_pram_write_byte(val, addr);
421408 break;
422409 #ifdef CONFIG_ADB_CUDA
423410 case MAC_ADB_EGRET:
424411 case MAC_ADB_CUDA:
425
- func = cuda_write_pram;
412
+ cuda_pram_write_byte(val, addr);
426413 break;
427414 #endif
428415 #ifdef CONFIG_ADB_PMU
429416 case MAC_ADB_PB2:
430
- func = pmu_write_pram;
417
+ pmu_pram_write_byte(val, addr);
431418 break;
432419 #endif
433420 default:
434
- return;
435
- }
436
- for (i = 0 ; i < len ; i++) {
437
- (*func)(offset++, buffer[i]);
421
+ break;
438422 }
439423 }
424
+
425
+ssize_t mac_pram_get_size(void)
426
+{
427
+ return 256;
428
+}
429
+#endif /* CONFIG_NVRAM */
440430
441431 void mac_poweroff(void)
442432 {
....@@ -462,9 +452,8 @@
462452
463453 void mac_reset(void)
464454 {
465
- if (macintosh_config->adb_type == MAC_ADB_II) {
466
- unsigned long flags;
467
-
455
+ if (macintosh_config->adb_type == MAC_ADB_II &&
456
+ macintosh_config->ident != MAC_MODEL_SE30) {
468457 /* need ROMBASE in booter */
469458 /* indeed, plus need to MAP THE ROM !! */
470459
....@@ -474,17 +463,8 @@
474463 /* works on some */
475464 rom_reset = (void *) (mac_bi_data.rombase + 0xa);
476465
477
- if (macintosh_config->ident == MAC_MODEL_SE30) {
478
- /*
479
- * MSch: Machines known to crash on ROM reset ...
480
- */
481
- } else {
482
- local_irq_save(flags);
483
-
484
- rom_reset();
485
-
486
- local_irq_restore(flags);
487
- }
466
+ local_irq_disable();
467
+ rom_reset();
488468 #ifdef CONFIG_ADB_CUDA
489469 } else if (macintosh_config->adb_type == MAC_ADB_EGRET ||
490470 macintosh_config->adb_type == MAC_ADB_CUDA) {
....@@ -641,12 +621,12 @@
641621 #ifdef CONFIG_ADB_CUDA
642622 case MAC_ADB_EGRET:
643623 case MAC_ADB_CUDA:
644
- now = cuda_read_time();
624
+ now = cuda_get_time();
645625 break;
646626 #endif
647627 #ifdef CONFIG_ADB_PMU
648628 case MAC_ADB_PB2:
649
- now = pmu_read_time();
629
+ now = pmu_get_time();
650630 break;
651631 #endif
652632 default:
....@@ -657,32 +637,25 @@
657637 unmktime(now, 0,
658638 &t->tm_year, &t->tm_mon, &t->tm_mday,
659639 &t->tm_hour, &t->tm_min, &t->tm_sec);
660
- pr_debug("%s: read %04d-%02d-%-2d %02d:%02d:%02d\n",
661
- __func__, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
662
- t->tm_hour, t->tm_min, t->tm_sec);
640
+ pr_debug("%s: read %ptR\n", __func__, t);
663641 } else { /* write */
664
- pr_debug("%s: tried to write %04d-%02d-%-2d %02d:%02d:%02d\n",
665
- __func__, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
666
- t->tm_hour, t->tm_min, t->tm_sec);
667
-
668
- now = mktime64(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday,
669
- t->tm_hour, t->tm_min, t->tm_sec);
642
+ pr_debug("%s: tried to write %ptR\n", __func__, t);
670643
671644 switch (macintosh_config->adb_type) {
672645 case MAC_ADB_IOP:
673646 case MAC_ADB_II:
674647 case MAC_ADB_PB1:
675
- via_write_time(now);
648
+ via_set_rtc_time(t);
676649 break;
677650 #ifdef CONFIG_ADB_CUDA
678651 case MAC_ADB_EGRET:
679652 case MAC_ADB_CUDA:
680
- cuda_write_time(now);
653
+ cuda_set_rtc_time(t);
681654 break;
682655 #endif
683656 #ifdef CONFIG_ADB_PMU
684657 case MAC_ADB_PB2:
685
- pmu_write_time(now);
658
+ pmu_set_rtc_time(t);
686659 break;
687660 #endif
688661 default: