xref: /openbmc/linux/drivers/mtd/devices/ms02-nv.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *	Copyright (c) 2001, 2003  Maciej W. Rozycki
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *	DEC MS02-NV (54-20948-01) battery backed-up NVRAM module for
61da177e4SLinus Torvalds  *	DECstation/DECsystem 5000/2x0 and DECsystem 5900 and 5900/260
71da177e4SLinus Torvalds  *	systems.
81da177e4SLinus Torvalds  */
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #include <linux/ioport.h>
111da177e4SLinus Torvalds #include <linux/mtd/mtd.h>
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds /*
141da177e4SLinus Torvalds  * Addresses are decoded as follows:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  * 0x000000 - 0x3fffff	SRAM
171da177e4SLinus Torvalds  * 0x400000 - 0x7fffff	CSR
181da177e4SLinus Torvalds  *
191da177e4SLinus Torvalds  * Within the SRAM area the following ranges are forced by the system
201da177e4SLinus Torvalds  * firmware:
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  * 0x000000 - 0x0003ff	diagnostic area, destroyed upon a reboot
231da177e4SLinus Torvalds  * 0x000400 - ENDofRAM	storage area, available to operating systems
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  * but we can't really use the available area right from 0x000400 as
261da177e4SLinus Torvalds  * the first word is used by the firmware as a status flag passed
271da177e4SLinus Torvalds  * from an operating system.  If anything but the valid data magic
281da177e4SLinus Torvalds  * ID value is found, the firmware considers the SRAM clean, i.e.
291da177e4SLinus Torvalds  * containing no valid data, and disables the battery resulting in
301da177e4SLinus Torvalds  * data being erased as soon as power is switched off.  So the choice
311da177e4SLinus Torvalds  * for the start address of the user-available is 0x001000 which is
321da177e4SLinus Torvalds  * nicely page aligned.  The area between 0x000404 and 0x000fff may
331da177e4SLinus Torvalds  * be used by the driver for own needs.
341da177e4SLinus Torvalds  *
351da177e4SLinus Torvalds  * The diagnostic area defines two status words to be read by an
361da177e4SLinus Torvalds  * operating system, a magic ID to distinguish a MS02-NV board from
371da177e4SLinus Torvalds  * anything else and a status information providing results of tests
381da177e4SLinus Torvalds  * as well as the size of SRAM available, which can be 1MiB or 2MiB
391da177e4SLinus Torvalds  * (that's what the firmware handles; no idea if 2MiB modules ever
401da177e4SLinus Torvalds  * existed).
411da177e4SLinus Torvalds  *
421da177e4SLinus Torvalds  * The firmware only handles the MS02-NV board if installed in the
431da177e4SLinus Torvalds  * last (15th) slot, so for any other location the status information
441da177e4SLinus Torvalds  * stored in the SRAM cannot be relied upon.  But from the hardware
451da177e4SLinus Torvalds  * point of view there is no problem using up to 14 such boards in a
461da177e4SLinus Torvalds  * system -- only the 1st slot needs to be filled with a DRAM module.
471da177e4SLinus Torvalds  * The MS02-NV board is ECC-protected, like other MS02 memory boards.
481da177e4SLinus Torvalds  *
491da177e4SLinus Torvalds  * The state of the battery as provided by the CSR is reflected on
501da177e4SLinus Torvalds  * the two onboard LEDs.  When facing the battery side of the board,
511da177e4SLinus Torvalds  * with the LEDs at the top left and the battery at the bottom right
521da177e4SLinus Torvalds  * (i.e. looking from the back side of the system box), their meaning
531da177e4SLinus Torvalds  * is as follows (the system has to be powered on):
541da177e4SLinus Torvalds  *
551da177e4SLinus Torvalds  * left LED		battery disable status: lit = enabled
561da177e4SLinus Torvalds  * right LED		battery condition status: lit = OK
571da177e4SLinus Torvalds  */
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds /* MS02-NV iomem register offsets. */
601da177e4SLinus Torvalds #define MS02NV_CSR		0x400000	/* control & status register */
611da177e4SLinus Torvalds 
621da177e4SLinus Torvalds /* MS02-NV CSR status bits. */
631da177e4SLinus Torvalds #define MS02NV_CSR_BATT_OK	0x01		/* battery OK */
641da177e4SLinus Torvalds #define MS02NV_CSR_BATT_OFF	0x02		/* battery disabled */
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds 
671da177e4SLinus Torvalds /* MS02-NV memory offsets. */
681da177e4SLinus Torvalds #define MS02NV_DIAG		0x0003f8	/* diagnostic status */
691da177e4SLinus Torvalds #define MS02NV_MAGIC		0x0003fc	/* MS02-NV magic ID */
701da177e4SLinus Torvalds #define MS02NV_VALID		0x000400	/* valid data magic ID */
711da177e4SLinus Torvalds #define MS02NV_RAM		0x001000	/* user-exposed RAM start */
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds /* MS02-NV diagnostic status bits. */
741da177e4SLinus Torvalds #define MS02NV_DIAG_TEST	0x01		/* SRAM test done (?) */
751da177e4SLinus Torvalds #define MS02NV_DIAG_RO		0x02		/* SRAM r/o test done */
761da177e4SLinus Torvalds #define MS02NV_DIAG_RW		0x04		/* SRAM r/w test done */
771da177e4SLinus Torvalds #define MS02NV_DIAG_FAIL	0x08		/* SRAM test failed */
781da177e4SLinus Torvalds #define MS02NV_DIAG_SIZE_MASK	0xf0		/* SRAM size mask */
791da177e4SLinus Torvalds #define MS02NV_DIAG_SIZE_SHIFT	0x10		/* SRAM size shift (left) */
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds /* MS02-NV general constants. */
821da177e4SLinus Torvalds #define MS02NV_ID		0x03021966	/* MS02-NV magic ID value */
831da177e4SLinus Torvalds #define MS02NV_VALID_ID		0xbd100248	/* valid data magic ID value */
841da177e4SLinus Torvalds #define MS02NV_SLOT_SIZE	0x800000	/* size of the address space
851da177e4SLinus Torvalds 						   decoded by the module */
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds typedef volatile u32 ms02nv_uint;
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds struct ms02nv_private {
911da177e4SLinus Torvalds 	struct mtd_info *next;
921da177e4SLinus Torvalds 	struct {
931da177e4SLinus Torvalds 		struct resource *module;
941da177e4SLinus Torvalds 		struct resource *diag_ram;
951da177e4SLinus Torvalds 		struct resource *user_ram;
961da177e4SLinus Torvalds 		struct resource *csr;
971da177e4SLinus Torvalds 	} resource;
981da177e4SLinus Torvalds 	u_char *addr;
991da177e4SLinus Torvalds 	size_t size;
1001da177e4SLinus Torvalds 	u_char *uaddr;
1011da177e4SLinus Torvalds };
102