From 014137bf60fc5804b6759cd0879c6a374dbce26e Mon Sep 17 00:00:00 2001
From: Robert Sprowson <rsprowson@gitlab.riscosopen.org>
Date: Thu, 15 Aug 2013 13:39:58 +0000
Subject: [PATCH] Create placeholder NVMemory HAL device when EEPROM detected

The HAL device created is merely a dummy one, but presents any EEPROM detected for completeness of stuff the HAL knows about.

Version 0.87. Tagged as 'OMAP3-0_87'
---
 VersionASM   | 12 ++++----
 VersionNum   | 20 +++++++-------
 hdr/StaticWS |  1 +
 s/Boot       |  6 +---
 s/NVMemory   | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 93 insertions(+), 24 deletions(-)

diff --git a/VersionASM b/VersionASM
index 88b9812..0f01dd2 100644
--- a/VersionASM
+++ b/VersionASM
@@ -11,13 +11,13 @@
                         GBLS    Module_HelpVersion
                         GBLS    Module_ComponentName
                         GBLS    Module_ComponentPath
-Module_MajorVersion     SETS    "0.86"
-Module_Version          SETA    86
+Module_MajorVersion     SETS    "0.87"
+Module_Version          SETA    87
 Module_MinorVersion     SETS    ""
-Module_Date             SETS    "21 Feb 2013"
-Module_ApplicationDate  SETS    "21-Feb-13"
+Module_Date             SETS    "15 Aug 2013"
+Module_ApplicationDate  SETS    "15-Aug-13"
 Module_ComponentName    SETS    "OMAP3"
 Module_ComponentPath    SETS    "castle/RiscOS/Sources/HAL/OMAP3"
-Module_FullVersion      SETS    "0.86"
-Module_HelpVersion      SETS    "0.86 (21 Feb 2013)"
+Module_FullVersion      SETS    "0.87"
+Module_HelpVersion      SETS    "0.87 (15 Aug 2013)"
                         END
diff --git a/VersionNum b/VersionNum
index f9e54b6..30e3da4 100644
--- a/VersionNum
+++ b/VersionNum
@@ -1,23 +1,23 @@
-/* (0.86)
+/* (0.87)
  *
  * This file is automatically maintained by srccommit, do not edit manually.
  * Last processed by srccommit version: 1.1.
  *
  */
-#define Module_MajorVersion_CMHG        0.86
+#define Module_MajorVersion_CMHG        0.87
 #define Module_MinorVersion_CMHG        
-#define Module_Date_CMHG                21 Feb 2013
+#define Module_Date_CMHG                15 Aug 2013
 
-#define Module_MajorVersion             "0.86"
-#define Module_Version                  86
+#define Module_MajorVersion             "0.87"
+#define Module_Version                  87
 #define Module_MinorVersion             ""
-#define Module_Date                     "21 Feb 2013"
+#define Module_Date                     "15 Aug 2013"
 
-#define Module_ApplicationDate          "21-Feb-13"
+#define Module_ApplicationDate          "15-Aug-13"
 
 #define Module_ComponentName            "OMAP3"
 #define Module_ComponentPath            "castle/RiscOS/Sources/HAL/OMAP3"
 
-#define Module_FullVersion              "0.86"
-#define Module_HelpVersion              "0.86 (21 Feb 2013)"
-#define Module_LibraryVersionInfo       "0:86"
+#define Module_FullVersion              "0.87"
+#define Module_HelpVersion              "0.87 (15 Aug 2013)"
+#define Module_LibraryVersionInfo       "0:87"
diff --git a/hdr/StaticWS b/hdr/StaticWS
index 4c65726..a744c19 100644
--- a/hdr/StaticWS
+++ b/hdr/StaticWS
@@ -110,6 +110,7 @@ AudioWS         #       Audio_WorkspaceSize
 NICWS           #       NIC_DeviceSize
 CPUClkWS        #       CPUClk_WorkspaceSize
 GPIOWS          #       HALDevice_GPIO_Size
+NVRAMWS         #       HALDeviceSize
 
 SDIOWS          #       SDHCISize * MaxSDControllers
 BMUWS1          #       BMUSize
diff --git a/s/Boot b/s/Boot
index db6f2c7..5644b17 100644
--- a/s/Boot
+++ b/s/Boot
@@ -604,11 +604,6 @@ Board_Init_IGEPv2
  ]
         BL      USB_Init ; Uses GPTIMER2
 
- [ MoreDebug
-        DebugTX "NVMemory_Init"
- ]
-        BL      NVMemory_Init ; Uses GPTIMER2
-
  [ MoreDebug
         DebugTX "Timer_Init"
  ]
@@ -907,6 +902,7 @@ HAL_InitDevices
         DebugTime a1, "HAL_InitDevices @ "
         ; Common HAL devices
         BL      CPUClk_Init
+        BL      NVMemory_Init
         BL      RTC_Init
         BL      SDMA_Init
         BL      VideoDevice_Init
diff --git a/s/NVMemory b/s/NVMemory
index a0f036f..5e0e3ac 100644
--- a/s/NVMemory
+++ b/s/NVMemory
@@ -33,6 +33,7 @@
         EXPORT  HAL_NVMemoryRead
         EXPORT  HAL_NVMemoryWrite
 
+        IMPORT  memcpy
         IMPORT  HAL_CounterDelay
 
         ; Autodetect the EEPROM at runtime in the range 2kbit to 16kbit
@@ -212,7 +213,6 @@ NVMemory_Init
         GPIO_SetAsOutput a1, a2, a4
         GPIO_SetAsInput a1, a3, a4
 
-
         MOV     a1, #0
         BL      NVMemory_BGet
 05
@@ -262,7 +262,7 @@ NVMemory_Init
 30
       ]
         STR     v3, NVMemoryFound
-      [ TryLoadedCMOS
+    [ TryLoadedCMOS
         TEQ     v3, #0
         BNE     %FT50
 
@@ -299,7 +299,12 @@ NVMemory_Init
         SUBS    v1, v1, #1
         BNE     %BT45
 50
-      ]
+    ]
+        ; If some was found, create a placeholder HAL device
+        LDR     a1, NVMemoryFound
+        TEQ     a1, #0
+        BLNE    NVMemory_AddDevice
+
         Pull    "v1-v3, pc"
 
 NVMemory_Barrel16
@@ -325,6 +330,73 @@ NVMemory_Barrel16
 
         Pull    "v1-v2, pc"
 
+NVMemory_AddDevice
+        ; void NVMemory_AddDevice(uint32_t bytesize)
+        Push    "a1, lr"
+
+        ; Copy over template
+        ADRL    a1, NVRAMWS
+        ADR     a2, NVMemory_AddDevice_Template
+        MOV     a3, #HALDeviceSize
+        BL      memcpy
+
+        ; Map 256/512/1024/2048 to table index 0/1/2/3
+        MOV     a2, a1
+        Pull    "a3, lr"
+        CLZ     a1, a3
+        RSB     a1, a1, #31 - 8
+
+        ADR     a4, NVMemory_AddDevice_IDs
+        MOV     a3, a1, LSL #1
+        LDRH    a3, [a4, a3]
+        STRH    a3, [a2, #HALDevice_ID]
+
+        ADR     a4, NVMemory_AddDevice_Descs
+        MOV     a3, #1 + :LEN:"24Cxx EEPROM"
+        MLA     a3, a3, a1, a4
+        STR     a3, [a2, #HALDevice_Description]
+
+        ; Tail call the OS to add it
+        MOV     a1, #0
+        LDR     pc, OSentries + 4*OS_AddDevice
+
+NVMemory_AddDevice_Template
+        DCW     HALDeviceType_SysPeri + HALDeviceSysPeri_NVRAM
+        DCW     &1234           ; ID filled at runtime
+        DCD     HALDeviceBus_Ser + HALDeviceSerBus_IIC
+        DCD     0               ; API version 0
+        DCD     &12345678       ; Description filled at runtime
+        DCD     0               ; Address - N/A
+        %       12              ; Reserved
+        DCD     NVMemory_AddDevice_Activate
+        DCD     NVMemory_AddDevice_Deactivate
+        DCD     NVMemory_AddDevice_Reset
+        DCD     NVMemory_AddDevice_Sleep
+        DCD     -1
+        DCD     0
+        %       8
+        ASSERT  (. - NVMemory_AddDevice_Template) = HALDeviceSize
+
+NVMemory_AddDevice_Activate
+        MOV     a1, #1
+        MOV     pc, lr
+NVMemory_AddDevice_Sleep
+        MOV     a1, #0
+NVMemory_AddDevice_Deactivate
+NVMemory_AddDevice_Reset
+        MOV     pc, lr
+NVMemory_AddDevice_IDs
+        DCW    HALDeviceID_NVRAM_24C02
+        DCW    HALDeviceID_NVRAM_24C04
+        DCW    HALDeviceID_NVRAM_24C08
+        DCW    HALDeviceID_NVRAM_24C16
+NVMemory_AddDevice_Descs
+        DCB    "24C02 EEPROM", 0
+        DCB    "24C04 EEPROM", 0
+        DCB    "24C08 EEPROM", 0
+        DCB    "24C16 EEPROM", 0
+        ALIGN
+
 NVMemory_BGet
         ; int32_t NVMemory_BGet(uint32_t loc)
         ; Returns -1 if no ACK otherwise the byte read
-- 
GitLab