Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * CMOS/NV-RAM driver for Atari. Adapted from drivers/char/nvram.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 1997 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * idea by and with help from Richard Jelinek <rj@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Portions copyright (c) 2001,2002 Sun Microsystems (thockin@sun.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Further contributions from Cesar Barros, Erik Gilling, Tim Hockin and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Wim Van Sebroeck.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mc146818rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/nvram.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/atarihw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/atariints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define NVRAM_BYTES		50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* It is worth noting that these functions all access bytes of general
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * purpose memory in the NVRAM - that is to say, they all add the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * NVRAM_FIRST_BYTE offset. Pass them offsets into NVRAM as if you did not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * know about the RTC cruft.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* Note that *all* calls to CMOS_READ and CMOS_WRITE must be done with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * rtc_lock held. Due to the index-port/data-port design of the RTC, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * don't want two different things trying to get to it at once. (e.g. the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * periodic 11 min sync from kernel/time/ntp.c vs. this driver.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static unsigned char __nvram_read_byte(int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	return CMOS_READ(NVRAM_FIRST_BYTE + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* This races nicely with trying to read with checksum checking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static void __nvram_write_byte(unsigned char c, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	CMOS_WRITE(c, NVRAM_FIRST_BYTE + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* On Ataris, the checksum is over all bytes except the checksum bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * themselves; these are at the very end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define ATARI_CKS_RANGE_START	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define ATARI_CKS_RANGE_END	47
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define ATARI_CKS_LOC		48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int __nvram_check_checksum(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned char sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		sum += __nvram_read_byte(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return (__nvram_read_byte(ATARI_CKS_LOC) == (~sum & 0xff)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	       (__nvram_read_byte(ATARI_CKS_LOC + 1) == (sum & 0xff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static void __nvram_set_checksum(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned char sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	for (i = ATARI_CKS_RANGE_START; i <= ATARI_CKS_RANGE_END; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		sum += __nvram_read_byte(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	__nvram_write_byte(~sum, ATARI_CKS_LOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	__nvram_write_byte(sum, ATARI_CKS_LOC + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) long atari_nvram_set_checksum(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	spin_lock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	__nvram_set_checksum();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) long atari_nvram_initialize(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	loff_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	spin_lock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	for (i = 0; i < NVRAM_BYTES; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		__nvram_write_byte(0, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	__nvram_set_checksum();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) ssize_t atari_nvram_read(char *buf, size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	loff_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	spin_lock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (!__nvram_check_checksum()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	for (i = *ppos; count > 0 && i < NVRAM_BYTES; --count, ++i, ++p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		*p = __nvram_read_byte(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	*ppos = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ssize_t atari_nvram_write(char *buf, size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	char *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	loff_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	spin_lock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (!__nvram_check_checksum()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	for (i = *ppos; count > 0 && i < NVRAM_BYTES; --count, ++i, ++p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		__nvram_write_byte(*p, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	__nvram_set_checksum();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	*ppos = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ssize_t atari_nvram_get_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return NVRAM_BYTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	unsigned char val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) } boot_prefs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	{ 0x80, "TOS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	{ 0x40, "ASV" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	{ 0x20, "NetBSD (?)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	{ 0x10, "Linux" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	{ 0x00, "unspecified" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static const char * const languages[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	"English (US)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	"German",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	"French",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	"English (UK)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	"Spanish",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	"Italian",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	"6 (undefined)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	"Swiss (French)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	"Swiss (German)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static const char * const dateformat[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	"MM%cDD%cYY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	"DD%cMM%cYY",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	"YY%cMM%cDD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	"YY%cDD%cMM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	"4 (undefined)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	"5 (undefined)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	"6 (undefined)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	"7 (undefined)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static const char * const colors[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	"2", "4", "16", "256", "65536", "??", "??", "??"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void atari_nvram_proc_read(unsigned char *nvram, struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				  void *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	unsigned int vmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	spin_lock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	checksum = __nvram_check_checksum();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	seq_printf(seq, "Checksum status  : %svalid\n", checksum ? "" : "not ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	seq_puts(seq, "Boot preference  : ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	for (i = ARRAY_SIZE(boot_prefs) - 1; i >= 0; --i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (nvram[1] == boot_prefs[i].val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			seq_printf(seq, "%s\n", boot_prefs[i].name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		seq_printf(seq, "0x%02x (undefined)\n", nvram[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	seq_printf(seq, "SCSI arbitration : %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		   (nvram[16] & 0x80) ? "on" : "off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	seq_puts(seq, "SCSI host ID     : ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (nvram[16] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		seq_printf(seq, "%d\n", nvram[16] & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		seq_puts(seq, "n/a\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (!MACH_IS_FALCON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	seq_puts(seq, "OS language      : ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (nvram[6] < ARRAY_SIZE(languages))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		seq_printf(seq, "%s\n", languages[nvram[6]]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		seq_printf(seq, "%u (undefined)\n", nvram[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	seq_puts(seq, "Keyboard language: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (nvram[7] < ARRAY_SIZE(languages))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		seq_printf(seq, "%s\n", languages[nvram[7]]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		seq_printf(seq, "%u (undefined)\n", nvram[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	seq_puts(seq, "Date format      : ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	seq_printf(seq, dateformat[nvram[8] & 7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		   nvram[9] ? nvram[9] : '/', nvram[9] ? nvram[9] : '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	seq_printf(seq, ", %dh clock\n", nvram[8] & 16 ? 24 : 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	seq_puts(seq, "Boot delay       : ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (nvram[10] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		seq_puts(seq, "default\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		seq_printf(seq, "%ds%s\n", nvram[10],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			   nvram[10] < 8 ? ", no memory test" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	vmode = (nvram[14] << 8) | nvram[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		   "Video mode       : %s colors, %d columns, %s %s monitor\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		   colors[vmode & 7], vmode & 8 ? 80 : 40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		   vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		   "                   %soverscan, compat. mode %s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		   vmode & 64 ? "" : "no ", vmode & 128 ? "on" : "off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		   vmode & 256 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		   (vmode & 16 ? ", line doubling" : ", half screen") : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int nvram_proc_read(struct seq_file *seq, void *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	unsigned char contents[NVRAM_BYTES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	spin_lock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	for (i = 0; i < NVRAM_BYTES; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		contents[i] = __nvram_read_byte(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	spin_unlock_irq(&rtc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	atari_nvram_proc_read(contents, seq, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int __init atari_nvram_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (!(MACH_IS_ATARI && ATARIHW_PRESENT(TT_CLK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (!proc_create_single("driver/nvram", 0, NULL, nvram_proc_read)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		pr_err("nvram: can't create /proc/driver/nvram\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) device_initcall(atari_nvram_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif /* CONFIG_PROC_FS */