ms02-nv.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2001, 2003 Maciej W. Rozycki
  4. *
  5. * DEC MS02-NV (54-20948-01) battery backed-up NVRAM module for
  6. * DECstation/DECsystem 5000/2x0 and DECsystem 5900 and 5900/260
  7. * systems.
  8. */
  9. #include <linux/ioport.h>
  10. #include <linux/mtd/mtd.h>
  11. /*
  12. * Addresses are decoded as follows:
  13. *
  14. * 0x000000 - 0x3fffff SRAM
  15. * 0x400000 - 0x7fffff CSR
  16. *
  17. * Within the SRAM area the following ranges are forced by the system
  18. * firmware:
  19. *
  20. * 0x000000 - 0x0003ff diagnostic area, destroyed upon a reboot
  21. * 0x000400 - ENDofRAM storage area, available to operating systems
  22. *
  23. * but we can't really use the available area right from 0x000400 as
  24. * the first word is used by the firmware as a status flag passed
  25. * from an operating system. If anything but the valid data magic
  26. * ID value is found, the firmware considers the SRAM clean, i.e.
  27. * containing no valid data, and disables the battery resulting in
  28. * data being erased as soon as power is switched off. So the choice
  29. * for the start address of the user-available is 0x001000 which is
  30. * nicely page aligned. The area between 0x000404 and 0x000fff may
  31. * be used by the driver for own needs.
  32. *
  33. * The diagnostic area defines two status words to be read by an
  34. * operating system, a magic ID to distinguish a MS02-NV board from
  35. * anything else and a status information providing results of tests
  36. * as well as the size of SRAM available, which can be 1MiB or 2MiB
  37. * (that's what the firmware handles; no idea if 2MiB modules ever
  38. * existed).
  39. *
  40. * The firmware only handles the MS02-NV board if installed in the
  41. * last (15th) slot, so for any other location the status information
  42. * stored in the SRAM cannot be relied upon. But from the hardware
  43. * point of view there is no problem using up to 14 such boards in a
  44. * system -- only the 1st slot needs to be filled with a DRAM module.
  45. * The MS02-NV board is ECC-protected, like other MS02 memory boards.
  46. *
  47. * The state of the battery as provided by the CSR is reflected on
  48. * the two onboard LEDs. When facing the battery side of the board,
  49. * with the LEDs at the top left and the battery at the bottom right
  50. * (i.e. looking from the back side of the system box), their meaning
  51. * is as follows (the system has to be powered on):
  52. *
  53. * left LED battery disable status: lit = enabled
  54. * right LED battery condition status: lit = OK
  55. */
  56. /* MS02-NV iomem register offsets. */
  57. #define MS02NV_CSR 0x400000 /* control & status register */
  58. /* MS02-NV CSR status bits. */
  59. #define MS02NV_CSR_BATT_OK 0x01 /* battery OK */
  60. #define MS02NV_CSR_BATT_OFF 0x02 /* battery disabled */
  61. /* MS02-NV memory offsets. */
  62. #define MS02NV_DIAG 0x0003f8 /* diagnostic status */
  63. #define MS02NV_MAGIC 0x0003fc /* MS02-NV magic ID */
  64. #define MS02NV_VALID 0x000400 /* valid data magic ID */
  65. #define MS02NV_RAM 0x001000 /* user-exposed RAM start */
  66. /* MS02-NV diagnostic status bits. */
  67. #define MS02NV_DIAG_TEST 0x01 /* SRAM test done (?) */
  68. #define MS02NV_DIAG_RO 0x02 /* SRAM r/o test done */
  69. #define MS02NV_DIAG_RW 0x04 /* SRAM r/w test done */
  70. #define MS02NV_DIAG_FAIL 0x08 /* SRAM test failed */
  71. #define MS02NV_DIAG_SIZE_MASK 0xf0 /* SRAM size mask */
  72. #define MS02NV_DIAG_SIZE_SHIFT 0x10 /* SRAM size shift (left) */
  73. /* MS02-NV general constants. */
  74. #define MS02NV_ID 0x03021966 /* MS02-NV magic ID value */
  75. #define MS02NV_VALID_ID 0xbd100248 /* valid data magic ID value */
  76. #define MS02NV_SLOT_SIZE 0x800000 /* size of the address space
  77. decoded by the module */
  78. typedef volatile u32 ms02nv_uint;
  79. struct ms02nv_private {
  80. struct mtd_info *next;
  81. struct {
  82. struct resource *module;
  83. struct resource *diag_ram;
  84. struct resource *user_ram;
  85. struct resource *csr;
  86. } resource;
  87. u_char *addr;
  88. size_t size;
  89. u_char *uaddr;
  90. };