Signed-off-by: Andreas Färber andreas.faerber@web.de --- arch/ppc/qemu/qemu.c | 18 ++++++++++-- config/examples/ppc64_config.xml | 1 + config/examples/ppc_config.xml | 1 + drivers/build.xml | 1 + drivers/m48t59.c | 60 ++++++++++++++++++++++++++++++++++++++++ include/drivers/drivers.h | 3 ++ 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 drivers/m48t59.c
diff --git a/arch/ppc/qemu/qemu.c b/arch/ppc/qemu/qemu.c index 381affb..1e3994c 100644 --- a/arch/ppc/qemu/qemu.c +++ b/arch/ppc/qemu/qemu.c @@ -80,9 +80,13 @@ printk( const char *fmt, ... ) int arch_nvram_size(void) { if (is_apple()) { +#ifdef CONFIG_DRIVER_MACIO return macio_get_nvram_size(); +#endif } else { - // not implemented +#ifdef CONFIG_DRIVER_M48T59 + return m48t59_nvram_size(); +#endif } return 0; } @@ -90,17 +94,25 @@ int arch_nvram_size(void) void arch_nvram_put(char *buf) { if (is_apple()) { +#ifdef CONFIG_DRIVER_MACIO macio_nvram_put(buf); +#endif } else { - // not implemented +#ifdef CONFIG_DRIVER_M48T59 + m48t59_nvram_put(buf); +#endif } }
void arch_nvram_get(char *buf) { if (is_apple()) { +#ifdef CONFIG_DRIVER_MACIO macio_nvram_get(buf); +#endif } else { - // not implemented +#ifdef CONFIG_DRIVER_M48T59 + m48t59_nvram_get(buf); +#endif } } diff --git a/config/examples/ppc64_config.xml b/config/examples/ppc64_config.xml index 5f79c21..04343b4 100644 --- a/config/examples/ppc64_config.xml +++ b/config/examples/ppc64_config.xml @@ -75,3 +75,4 @@ <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/> <option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xf0000510"/> + <option name="CONFIG_DRIVER_M48T59" type="boolean" value="false"/> diff --git a/config/examples/ppc_config.xml b/config/examples/ppc_config.xml index 5bb789f..2229f00 100644 --- a/config/examples/ppc_config.xml +++ b/config/examples/ppc_config.xml @@ -78,3 +78,4 @@ <option name="CONFIG_DRIVER_ESCC" type="boolean" value="true"/> <option name="CONFIG_DRIVER_FW_CFG" type="boolean" value="true"/> <option name="CONFIG_FW_CFG_ADDR" type="integer" value="0xf0000510"/> + <option name="CONFIG_DRIVER_M48T59" type="boolean" value="true"/> diff --git a/drivers/build.xml b/drivers/build.xml index edec6b5..bcb21ae 100644 --- a/drivers/build.xml +++ b/drivers/build.xml @@ -22,6 +22,7 @@ <object source="pc_serial.c" condition="DRIVER_PC_SERIAL"/> <object source="escc.c" condition="DRIVER_ESCC"/> <object source="fw_cfg.c" condition="DRIVER_FW_CFG"/> + <object source="m48t59.c" condition="DRIVER_M48T59"/> </library>
<dictionary name="openbios" target="forth"> diff --git a/drivers/m48t59.c b/drivers/m48t59.c new file mode 100644 index 0000000..cd9e9f6 --- /dev/null +++ b/drivers/m48t59.c @@ -0,0 +1,60 @@ +/* + * OpenBIOS PReP m48t59 driver + * + * Copyright (c) 2013 Andreas Färber + */ + +#include "config.h" + +#include "drivers/drivers.h" +#include "asm/io.h" + +#define PREP_NVRAM_SIZE 0x2000 +#define PREP_NVRAM_ADDR_LO 0x74 +#define PREP_NVRAM_ADDR_HI 0x75 +#define PREP_NVRAM_DATA 0x77 + +static uint8_t m48t59_nvram_read_byte(uint16_t offset) +{ + outb(offset & 0xff, PREP_NVRAM_ADDR_LO); + outb(offset >> 8, PREP_NVRAM_ADDR_HI); + return inb(PREP_NVRAM_DATA); +} + +static void m48t59_nvram_read(uint16_t offset, char *buf, unsigned int len) +{ + unsigned int i; + for (i = 0; i < len; i++) { + buf[i] = m48t59_nvram_read_byte(offset); + } +} + +static void m48t59_nvram_write_byte(uint16_t offset, uint8_t value) +{ + outb(offset & 0xff, PREP_NVRAM_ADDR_LO); + outb(offset >> 8, PREP_NVRAM_ADDR_HI); + outb(value, PREP_NVRAM_DATA); +} + +static void m48t59_nvram_write(uint16_t offset, const char *buf, unsigned int len) +{ + unsigned int i; + for (i = 0; i < len; i++) { + m48t59_nvram_write_byte(offset, buf[i]); + } +} + +int m48t59_nvram_size(void) +{ + return PREP_NVRAM_SIZE; +} + +void m48t59_nvram_put(char *buf) +{ + m48t59_nvram_write(0, buf, PREP_NVRAM_SIZE); +} + +void m48t59_nvram_get(char *buf) +{ + m48t59_nvram_read(0, buf, PREP_NVRAM_SIZE); +} diff --git a/include/drivers/drivers.h b/include/drivers/drivers.h index 47d730f..73da6a2 100644 --- a/include/drivers/drivers.h +++ b/include/drivers/drivers.h @@ -125,6 +125,9 @@ unsigned char keyboard_readdata(void); int macio_get_nvram_size(void); void macio_nvram_put(char *buf); void macio_nvram_get(char *buf); +int m48t59_nvram_size(void); +void m48t59_nvram_put(char *buf); +void m48t59_nvram_get(char *buf);
/* drivers/timer.c */ void setup_timers(void);