]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
[PATCH] ppc32: nvram driver for chrp
authorOlaf Hering <olh@suse.de>
Sat, 29 Oct 2005 00:46:19 +0000 (17:46 -0700)
committerPaul Mackerras <paulus@samba.org>
Sat, 29 Oct 2005 04:35:00 +0000 (14:35 +1000)
This implements a nvram acccess method, similar to
arch/ppc64/kernel/pSeries_nvram.c tested on CHRP B50.

Signed-off-by: Olaf Hering <olh@suse.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/platforms/chrp/Makefile
arch/powerpc/platforms/chrp/chrp.h [new file with mode: 0644]
arch/powerpc/platforms/chrp/nvram.c [new file with mode: 0644]
arch/powerpc/platforms/chrp/setup.c
arch/ppc/platforms/Makefile
arch/ppc/platforms/chrp_nvram.c [new file with mode: 0644]
arch/ppc/platforms/chrp_setup.c
include/asm-ppc/system.h

index 1fde4e68414fe357cdd793d84deb4032af79875a..902feb1ac4319de74bfe9cf75643efcd5871b7f9 100644 (file)
@@ -1,3 +1,4 @@
 obj-y                          += setup.o time.o pegasos_eth.o
 obj-$(CONFIG_PCI)              += pci.o
 obj-$(CONFIG_SMP)              += smp.o
+obj-$(CONFIG_NVRAM)            += nvram.o
diff --git a/arch/powerpc/platforms/chrp/chrp.h b/arch/powerpc/platforms/chrp/chrp.h
new file mode 100644 (file)
index 0000000..3a2057f
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Declarations of CHRP platform-specific things.
+ */
+
+extern void chrp_nvram_init(void);
+extern void chrp_get_rtc_time(struct rtc_time *);
+extern int chrp_set_rtc_time(struct rtc_time *);
+extern void chrp_calibrate_decr(void);
+extern long chrp_time_init(void);
+
+extern void chrp_find_bridges(void);
+extern void chrp_event_scan(void);
diff --git a/arch/powerpc/platforms/chrp/nvram.c b/arch/powerpc/platforms/chrp/nvram.c
new file mode 100644 (file)
index 0000000..4ac7125
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ *  c 2001 PPC 64 Team, IBM Corp
+ *
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ *
+ * /dev/nvram driver for PPC
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <asm/uaccess.h>
+#include <asm/prom.h>
+#include <asm/machdep.h>
+#include "chrp.h"
+
+static unsigned int nvram_size;
+static unsigned char nvram_buf[4];
+static DEFINE_SPINLOCK(nvram_lock);
+
+static unsigned char chrp_nvram_read(int addr)
+{
+       unsigned long done, flags;
+       unsigned char ret;
+
+       if (addr >= nvram_size) {
+               printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",
+                      current->comm, addr, nvram_size);
+               return 0xff;
+       }
+       spin_lock_irqsave(&nvram_lock, flags);
+       if ((call_rtas("nvram-fetch", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done)
+               ret = 0xff;
+       else
+               ret = nvram_buf[0];
+       spin_unlock_irqrestore(&nvram_lock, flags);
+
+       return ret;
+}
+
+static void chrp_nvram_write(int addr, unsigned char val)
+{
+       unsigned long done, flags;
+
+       if (addr >= nvram_size) {
+               printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n",
+                      current->comm, addr, nvram_size);
+               return;
+       }
+       spin_lock_irqsave(&nvram_lock, flags);
+       nvram_buf[0] = val;
+       if ((call_rtas("nvram-store", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done)
+               printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);
+       spin_unlock_irqrestore(&nvram_lock, flags);
+}
+
+void __init chrp_nvram_init(void)
+{
+       struct device_node *nvram;
+       unsigned int *nbytes_p, proplen;
+
+       nvram = of_find_node_by_type(NULL, "nvram");
+       if (nvram == NULL)
+               return;
+
+       nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
+       if (nbytes_p == NULL || proplen != sizeof(unsigned int))
+               return;
+
+       nvram_size = *nbytes_p;
+
+       printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
+       of_node_put(nvram);
+
+       ppc_md.nvram_read_val = chrp_nvram_read;
+       ppc_md.nvram_write_val = chrp_nvram_write;
+
+       return;
+}
index 5145990e6a01d3af70a9e83840a46ccc256fe3f6..ecd32d5d85f487e775fc3dcb455d2c409ca793af 100644 (file)
 #include <asm/rtas.h>
 #include <asm/xmon.h>
 
-void chrp_get_rtc_time(struct rtc_time *);
-int chrp_set_rtc_time(struct rtc_time *);
-void chrp_calibrate_decr(void);
-long chrp_time_init(void);
+#include "chrp.h"
 
-void chrp_find_bridges(void);
-void chrp_event_scan(void);
 void rtas_indicator_progress(char *, unsigned short);
 void btext_progress(char *, unsigned short);
 
@@ -469,6 +464,10 @@ void __init chrp_init_IRQ(void)
 void __init
 chrp_init2(void)
 {
+#ifdef CONFIG_NVRAM
+       chrp_nvram_init();
+#endif
+
        request_region(0x20,0x20,"pic1");
        request_region(0xa0,0x20,"pic2");
        request_region(0x00,0x20,"dma1");
index ff7452e5d8e511ef79f6e97a8eb38bc9b301ce6c..7c5cdabf6f3c159a3448d2563628c8581917ee9d 100644 (file)
@@ -14,6 +14,9 @@ obj-$(CONFIG_PPC_PMAC)                += pmac_pic.o pmac_setup.o pmac_time.o \
                                        pmac_low_i2c.o pmac_cache.o
 obj-$(CONFIG_PPC_CHRP)         += chrp_setup.o chrp_time.o chrp_pci.o \
                                        chrp_pegasos_eth.o
+ifeq ($(CONFIG_PPC_CHRP),y)
+obj-$(CONFIG_NVRAM)            += chrp_nvram.o
+endif
 obj-$(CONFIG_PPC_PREP)         += prep_pci.o prep_setup.o
 ifeq ($(CONFIG_PPC_PMAC),y)
 obj-$(CONFIG_NVRAM)            += pmac_nvram.o
diff --git a/arch/ppc/platforms/chrp_nvram.c b/arch/ppc/platforms/chrp_nvram.c
new file mode 100644 (file)
index 0000000..465ba9b
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  c 2001 PPC 64 Team, IBM Corp
+ *
+ *      This program is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU General Public License
+ *      as published by the Free Software Foundation; either version
+ *      2 of the License, or (at your option) any later version.
+ *
+ * /dev/nvram driver for PPC
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <asm/uaccess.h>
+#include <asm/prom.h>
+#include <asm/machdep.h>
+
+static unsigned int nvram_size;
+static unsigned char nvram_buf[4];
+static DEFINE_SPINLOCK(nvram_lock);
+
+static unsigned char chrp_nvram_read(int addr)
+{
+       unsigned long done, flags;
+       unsigned char ret;
+
+       if (addr >= nvram_size) {
+               printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n",
+                      current->comm, addr, nvram_size);
+               return 0xff;
+       }
+       spin_lock_irqsave(&nvram_lock, flags);
+       if ((call_rtas("nvram-fetch", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done)
+               ret = 0xff;
+       else
+               ret = nvram_buf[0];
+       spin_unlock_irqrestore(&nvram_lock, flags);
+
+       return ret;
+}
+
+static void chrp_nvram_write(int addr, unsigned char val)
+{
+       unsigned long done, flags;
+
+       if (addr >= nvram_size) {
+               printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n",
+                      current->comm, addr, nvram_size);
+               return;
+       }
+       spin_lock_irqsave(&nvram_lock, flags);
+       nvram_buf[0] = val;
+       if ((call_rtas("nvram-store", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done)
+               printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr);
+       spin_unlock_irqrestore(&nvram_lock, flags);
+}
+
+void __init chrp_nvram_init(void)
+{
+       struct device_node *nvram;
+       unsigned int *nbytes_p, proplen;
+
+       nvram = of_find_node_by_type(NULL, "nvram");
+       if (nvram == NULL)
+               return;
+
+       nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
+       if (nbytes_p == NULL || proplen != sizeof(unsigned int))
+               return;
+
+       nvram_size = *nbytes_p;
+
+       printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size);
+       of_node_put(nvram);
+
+       ppc_md.nvram_read_val = chrp_nvram_read;
+       ppc_md.nvram_write_val = chrp_nvram_write;
+
+       return;
+}
index dad81ffd401318bd2edf81725336a9a18a706b99..f1b70ab3c6fd892a34ef182427e32e63e0c52c2b 100644 (file)
@@ -454,8 +454,7 @@ void __init
 chrp_init2(void)
 {
 #ifdef CONFIG_NVRAM
-// XX replace this in a more saner way
-//     pmac_nvram_init();
+       chrp_nvram_init();
 #endif
 
        request_region(0x20,0x20,"pic1");
index eb30c09516ae3fca2f000d0bf7d90337ca8e37f3..bd99cb53a19fb512b024e6a184f8f7b3359102ea 100644 (file)
@@ -70,6 +70,7 @@ extern void _set_L3CR(unsigned long);
 #endif
 extern void via_cuda_init(void);
 extern void pmac_nvram_init(void);
+extern void chrp_nvram_init(void);
 extern void read_rtc_time(void);
 extern void pmac_find_display(void);
 extern void giveup_fpu(struct task_struct *);