Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Mackerras | c55377e | 2005-11-14 17:22:01 +1100 | [diff] [blame] | 2 | * NVRAM definitions and access functions. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | */ |
| 9 | |
Paul Mackerras | c55377e | 2005-11-14 17:22:01 +1100 | [diff] [blame] | 10 | #ifndef _ASM_POWERPC_NVRAM_H |
| 11 | #define _ASM_POWERPC_NVRAM_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Ishizaki Kou | 4751505 | 2007-12-13 21:11:36 +1100 | [diff] [blame] | 13 | #include <linux/errno.h> |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #define NVRW_CNT 0x20 |
| 16 | #define NVRAM_HEADER_LEN 16 /* sizeof(struct nvram_header) */ |
| 17 | #define NVRAM_BLOCK_LEN 16 |
| 18 | #define NVRAM_MAX_REQ (2080/NVRAM_BLOCK_LEN) |
| 19 | #define NVRAM_MIN_REQ (1056/NVRAM_BLOCK_LEN) |
| 20 | |
| 21 | #define NVRAM_AS0 0x74 |
| 22 | #define NVRAM_AS1 0x75 |
| 23 | #define NVRAM_DATA 0x77 |
| 24 | |
| 25 | |
| 26 | /* RTC Offsets */ |
| 27 | |
| 28 | #define MOTO_RTC_SECONDS 0x1FF9 |
| 29 | #define MOTO_RTC_MINUTES 0x1FFA |
| 30 | #define MOTO_RTC_HOURS 0x1FFB |
| 31 | #define MOTO_RTC_DAY_OF_WEEK 0x1FFC |
| 32 | #define MOTO_RTC_DAY_OF_MONTH 0x1FFD |
| 33 | #define MOTO_RTC_MONTH 0x1FFE |
| 34 | #define MOTO_RTC_YEAR 0x1FFF |
| 35 | #define MOTO_RTC_CONTROLA 0x1FF8 |
| 36 | #define MOTO_RTC_CONTROLB 0x1FF9 |
| 37 | |
| 38 | #define NVRAM_SIG_SP 0x02 /* support processor */ |
| 39 | #define NVRAM_SIG_OF 0x50 /* open firmware config */ |
| 40 | #define NVRAM_SIG_FW 0x51 /* general firmware */ |
| 41 | #define NVRAM_SIG_HW 0x52 /* hardware (VPD) */ |
| 42 | #define NVRAM_SIG_FLIP 0x5a /* Apple flip/flop header */ |
| 43 | #define NVRAM_SIG_APPL 0x5f /* Apple "system" (???) */ |
| 44 | #define NVRAM_SIG_SYS 0x70 /* system env vars */ |
| 45 | #define NVRAM_SIG_CFG 0x71 /* config data */ |
| 46 | #define NVRAM_SIG_ELOG 0x72 /* error log */ |
| 47 | #define NVRAM_SIG_VEND 0x7e /* vendor defined */ |
| 48 | #define NVRAM_SIG_FREE 0x7f /* Free space */ |
| 49 | #define NVRAM_SIG_OS 0xa0 /* OS defined */ |
| 50 | #define NVRAM_SIG_PANIC 0xa1 /* Apple OSX "panic" */ |
| 51 | |
| 52 | /* If change this size, then change the size of NVNAME_LEN */ |
| 53 | struct nvram_header { |
| 54 | unsigned char signature; |
| 55 | unsigned char checksum; |
| 56 | unsigned short length; |
| 57 | char name[12]; |
| 58 | }; |
| 59 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 60 | #ifdef __KERNEL__ |
Andrew Morton | 134d495 | 2008-02-04 22:27:31 -0800 | [diff] [blame] | 61 | |
| 62 | #include <linux/list.h> |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | struct nvram_partition { |
| 65 | struct list_head partition; |
| 66 | struct nvram_header header; |
| 67 | unsigned int index; |
| 68 | }; |
| 69 | |
| 70 | |
Linas Vepstas | 0f2342c | 2007-08-10 06:56:41 +1000 | [diff] [blame] | 71 | extern int nvram_write_error_log(char * buff, int length, |
| 72 | unsigned int err_type, unsigned int err_seq); |
| 73 | extern int nvram_read_error_log(char * buff, int length, |
| 74 | unsigned int * err_type, unsigned int *err_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | extern int nvram_clear_error_log(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | extern int pSeries_nvram_init(void); |
Ishizaki Kou | 4751505 | 2007-12-13 21:11:36 +1100 | [diff] [blame] | 78 | |
| 79 | #ifdef CONFIG_MMIO_NVRAM |
Arnd Bergmann | f3f66f5 | 2005-10-31 20:08:37 -0500 | [diff] [blame] | 80 | extern int mmio_nvram_init(void); |
Ishizaki Kou | 4751505 | 2007-12-13 21:11:36 +1100 | [diff] [blame] | 81 | #else |
| 82 | static inline int mmio_nvram_init(void) |
| 83 | { |
| 84 | return -ENODEV; |
| 85 | } |
| 86 | #endif |
| 87 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 88 | #endif /* __KERNEL__ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* PowerMac specific nvram stuffs */ |
| 91 | |
| 92 | enum { |
| 93 | pmac_nvram_OF, /* Open Firmware partition */ |
| 94 | pmac_nvram_XPRAM, /* MacOS XPRAM partition */ |
| 95 | pmac_nvram_NR /* MacOS Name Registry partition */ |
| 96 | }; |
| 97 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 98 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* Return partition offset in nvram */ |
| 100 | extern int pmac_get_partition(int partition); |
| 101 | |
| 102 | /* Direct access to XPRAM on PowerMacs */ |
| 103 | extern u8 pmac_xpram_read(int xpaddr); |
| 104 | extern void pmac_xpram_write(int xpaddr, u8 data); |
| 105 | |
| 106 | /* Synchronize NVRAM */ |
Paul Mackerras | c55377e | 2005-11-14 17:22:01 +1100 | [diff] [blame] | 107 | extern void nvram_sync(void); |
| 108 | |
Martyn Welch | d331d83 | 2009-08-13 09:03:02 +0100 | [diff] [blame] | 109 | /* Determine NVRAM size */ |
| 110 | extern ssize_t nvram_get_size(void); |
| 111 | |
Paul Mackerras | c55377e | 2005-11-14 17:22:01 +1100 | [diff] [blame] | 112 | /* Normal access to NVRAM */ |
| 113 | extern unsigned char nvram_read_byte(int i); |
| 114 | extern void nvram_write_byte(unsigned char c, int i); |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 115 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | /* Some offsets in XPRAM */ |
| 118 | #define PMAC_XPRAM_MACHINE_LOC 0xe4 |
| 119 | #define PMAC_XPRAM_SOUND_VOLUME 0x08 |
| 120 | |
| 121 | /* Machine location structure in PowerMac XPRAM */ |
| 122 | struct pmac_machine_location { |
| 123 | unsigned int latitude; /* 2+30 bit Fractional number */ |
| 124 | unsigned int longitude; /* 2+30 bit Fractional number */ |
| 125 | unsigned int delta; /* mix of GMT delta and DLS */ |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * /dev/nvram ioctls |
| 130 | * |
| 131 | * Note that PMAC_NVRAM_GET_OFFSET is still supported, but is |
| 132 | * definitely obsolete. Do not use it if you can avoid it |
| 133 | */ |
| 134 | |
| 135 | #define OBSOLETE_PMAC_NVRAM_GET_OFFSET \ |
| 136 | _IOWR('p', 0x40, int) |
| 137 | |
| 138 | #define IOC_NVRAM_GET_OFFSET _IOWR('p', 0x42, int) /* Get NVRAM partition offset */ |
Paul Mackerras | c55377e | 2005-11-14 17:22:01 +1100 | [diff] [blame] | 139 | #define IOC_NVRAM_SYNC _IO('p', 0x43) /* Sync NVRAM image */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Paul Mackerras | c55377e | 2005-11-14 17:22:01 +1100 | [diff] [blame] | 141 | #endif /* _ASM_POWERPC_NVRAM_H */ |