diff options
author | Olaf Hering <olh@suse.de> | 2005-10-28 20:46:19 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2005-10-29 00:35:00 -0400 |
commit | 35e95e63995f3e52178db4b769120ce60deb6b54 (patch) | |
tree | 17e81624cd6af0cf645948a175160a62f29b07c8 | |
parent | 8b150478aeb1a8edb9015c2f7ac4da637ff65c45 (diff) |
[PATCH] ppc32: nvram driver for chrp
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>
-rw-r--r-- | arch/powerpc/platforms/chrp/Makefile | 1 | ||||
-rw-r--r-- | arch/powerpc/platforms/chrp/chrp.h | 12 | ||||
-rw-r--r-- | arch/powerpc/platforms/chrp/nvram.c | 84 | ||||
-rw-r--r-- | arch/powerpc/platforms/chrp/setup.c | 11 | ||||
-rw-r--r-- | arch/ppc/platforms/Makefile | 3 | ||||
-rw-r--r-- | arch/ppc/platforms/chrp_nvram.c | 83 | ||||
-rw-r--r-- | arch/ppc/platforms/chrp_setup.c | 3 | ||||
-rw-r--r-- | include/asm-ppc/system.h | 1 |
8 files changed, 190 insertions, 8 deletions
diff --git a/arch/powerpc/platforms/chrp/Makefile b/arch/powerpc/platforms/chrp/Makefile index 1fde4e68414..902feb1ac43 100644 --- a/arch/powerpc/platforms/chrp/Makefile +++ b/arch/powerpc/platforms/chrp/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | obj-y += setup.o time.o pegasos_eth.o | 1 | obj-y += setup.o time.o pegasos_eth.o |
2 | obj-$(CONFIG_PCI) += pci.o | 2 | obj-$(CONFIG_PCI) += pci.o |
3 | obj-$(CONFIG_SMP) += smp.o | 3 | obj-$(CONFIG_SMP) += smp.o |
4 | 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 index 00000000000..3a2057fa314 --- /dev/null +++ b/arch/powerpc/platforms/chrp/chrp.h | |||
@@ -0,0 +1,12 @@ | |||
1 | /* | ||
2 | * Declarations of CHRP platform-specific things. | ||
3 | */ | ||
4 | |||
5 | extern void chrp_nvram_init(void); | ||
6 | extern void chrp_get_rtc_time(struct rtc_time *); | ||
7 | extern int chrp_set_rtc_time(struct rtc_time *); | ||
8 | extern void chrp_calibrate_decr(void); | ||
9 | extern long chrp_time_init(void); | ||
10 | |||
11 | extern void chrp_find_bridges(void); | ||
12 | 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 index 00000000000..4ac7125aa09 --- /dev/null +++ b/arch/powerpc/platforms/chrp/nvram.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* | ||
2 | * c 2001 PPC 64 Team, IBM Corp | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * /dev/nvram driver for PPC | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/spinlock.h> | ||
17 | #include <asm/uaccess.h> | ||
18 | #include <asm/prom.h> | ||
19 | #include <asm/machdep.h> | ||
20 | #include "chrp.h" | ||
21 | |||
22 | static unsigned int nvram_size; | ||
23 | static unsigned char nvram_buf[4]; | ||
24 | static DEFINE_SPINLOCK(nvram_lock); | ||
25 | |||
26 | static unsigned char chrp_nvram_read(int addr) | ||
27 | { | ||
28 | unsigned long done, flags; | ||
29 | unsigned char ret; | ||
30 | |||
31 | if (addr >= nvram_size) { | ||
32 | printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n", | ||
33 | current->comm, addr, nvram_size); | ||
34 | return 0xff; | ||
35 | } | ||
36 | spin_lock_irqsave(&nvram_lock, flags); | ||
37 | if ((call_rtas("nvram-fetch", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done) | ||
38 | ret = 0xff; | ||
39 | else | ||
40 | ret = nvram_buf[0]; | ||
41 | spin_unlock_irqrestore(&nvram_lock, flags); | ||
42 | |||
43 | return ret; | ||
44 | } | ||
45 | |||
46 | static void chrp_nvram_write(int addr, unsigned char val) | ||
47 | { | ||
48 | unsigned long done, flags; | ||
49 | |||
50 | if (addr >= nvram_size) { | ||
51 | printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n", | ||
52 | current->comm, addr, nvram_size); | ||
53 | return; | ||
54 | } | ||
55 | spin_lock_irqsave(&nvram_lock, flags); | ||
56 | nvram_buf[0] = val; | ||
57 | if ((call_rtas("nvram-store", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done) | ||
58 | printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr); | ||
59 | spin_unlock_irqrestore(&nvram_lock, flags); | ||
60 | } | ||
61 | |||
62 | void __init chrp_nvram_init(void) | ||
63 | { | ||
64 | struct device_node *nvram; | ||
65 | unsigned int *nbytes_p, proplen; | ||
66 | |||
67 | nvram = of_find_node_by_type(NULL, "nvram"); | ||
68 | if (nvram == NULL) | ||
69 | return; | ||
70 | |||
71 | nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen); | ||
72 | if (nbytes_p == NULL || proplen != sizeof(unsigned int)) | ||
73 | return; | ||
74 | |||
75 | nvram_size = *nbytes_p; | ||
76 | |||
77 | printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size); | ||
78 | of_node_put(nvram); | ||
79 | |||
80 | ppc_md.nvram_read_val = chrp_nvram_read; | ||
81 | ppc_md.nvram_write_val = chrp_nvram_write; | ||
82 | |||
83 | return; | ||
84 | } | ||
diff --git a/arch/powerpc/platforms/chrp/setup.c b/arch/powerpc/platforms/chrp/setup.c index 5145990e6a0..ecd32d5d85f 100644 --- a/arch/powerpc/platforms/chrp/setup.c +++ b/arch/powerpc/platforms/chrp/setup.c | |||
@@ -55,13 +55,8 @@ | |||
55 | #include <asm/rtas.h> | 55 | #include <asm/rtas.h> |
56 | #include <asm/xmon.h> | 56 | #include <asm/xmon.h> |
57 | 57 | ||
58 | void chrp_get_rtc_time(struct rtc_time *); | 58 | #include "chrp.h" |
59 | int chrp_set_rtc_time(struct rtc_time *); | ||
60 | void chrp_calibrate_decr(void); | ||
61 | long chrp_time_init(void); | ||
62 | 59 | ||
63 | void chrp_find_bridges(void); | ||
64 | void chrp_event_scan(void); | ||
65 | void rtas_indicator_progress(char *, unsigned short); | 60 | void rtas_indicator_progress(char *, unsigned short); |
66 | void btext_progress(char *, unsigned short); | 61 | void btext_progress(char *, unsigned short); |
67 | 62 | ||
@@ -469,6 +464,10 @@ void __init chrp_init_IRQ(void) | |||
469 | void __init | 464 | void __init |
470 | chrp_init2(void) | 465 | chrp_init2(void) |
471 | { | 466 | { |
467 | #ifdef CONFIG_NVRAM | ||
468 | chrp_nvram_init(); | ||
469 | #endif | ||
470 | |||
472 | request_region(0x20,0x20,"pic1"); | 471 | request_region(0x20,0x20,"pic1"); |
473 | request_region(0xa0,0x20,"pic2"); | 472 | request_region(0xa0,0x20,"pic2"); |
474 | request_region(0x00,0x20,"dma1"); | 473 | request_region(0x00,0x20,"dma1"); |
diff --git a/arch/ppc/platforms/Makefile b/arch/ppc/platforms/Makefile index ff7452e5d8e..7c5cdabf6f3 100644 --- a/arch/ppc/platforms/Makefile +++ b/arch/ppc/platforms/Makefile | |||
@@ -14,6 +14,9 @@ obj-$(CONFIG_PPC_PMAC) += pmac_pic.o pmac_setup.o pmac_time.o \ | |||
14 | pmac_low_i2c.o pmac_cache.o | 14 | pmac_low_i2c.o pmac_cache.o |
15 | obj-$(CONFIG_PPC_CHRP) += chrp_setup.o chrp_time.o chrp_pci.o \ | 15 | obj-$(CONFIG_PPC_CHRP) += chrp_setup.o chrp_time.o chrp_pci.o \ |
16 | chrp_pegasos_eth.o | 16 | chrp_pegasos_eth.o |
17 | ifeq ($(CONFIG_PPC_CHRP),y) | ||
18 | obj-$(CONFIG_NVRAM) += chrp_nvram.o | ||
19 | endif | ||
17 | obj-$(CONFIG_PPC_PREP) += prep_pci.o prep_setup.o | 20 | obj-$(CONFIG_PPC_PREP) += prep_pci.o prep_setup.o |
18 | ifeq ($(CONFIG_PPC_PMAC),y) | 21 | ifeq ($(CONFIG_PPC_PMAC),y) |
19 | obj-$(CONFIG_NVRAM) += pmac_nvram.o | 22 | 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 index 00000000000..465ba9b090e --- /dev/null +++ b/arch/ppc/platforms/chrp_nvram.c | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * c 2001 PPC 64 Team, IBM Corp | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * /dev/nvram driver for PPC | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/spinlock.h> | ||
17 | #include <asm/uaccess.h> | ||
18 | #include <asm/prom.h> | ||
19 | #include <asm/machdep.h> | ||
20 | |||
21 | static unsigned int nvram_size; | ||
22 | static unsigned char nvram_buf[4]; | ||
23 | static DEFINE_SPINLOCK(nvram_lock); | ||
24 | |||
25 | static unsigned char chrp_nvram_read(int addr) | ||
26 | { | ||
27 | unsigned long done, flags; | ||
28 | unsigned char ret; | ||
29 | |||
30 | if (addr >= nvram_size) { | ||
31 | printk(KERN_DEBUG "%s: read addr %d > nvram_size %u\n", | ||
32 | current->comm, addr, nvram_size); | ||
33 | return 0xff; | ||
34 | } | ||
35 | spin_lock_irqsave(&nvram_lock, flags); | ||
36 | if ((call_rtas("nvram-fetch", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done) | ||
37 | ret = 0xff; | ||
38 | else | ||
39 | ret = nvram_buf[0]; | ||
40 | spin_unlock_irqrestore(&nvram_lock, flags); | ||
41 | |||
42 | return ret; | ||
43 | } | ||
44 | |||
45 | static void chrp_nvram_write(int addr, unsigned char val) | ||
46 | { | ||
47 | unsigned long done, flags; | ||
48 | |||
49 | if (addr >= nvram_size) { | ||
50 | printk(KERN_DEBUG "%s: write addr %d > nvram_size %u\n", | ||
51 | current->comm, addr, nvram_size); | ||
52 | return; | ||
53 | } | ||
54 | spin_lock_irqsave(&nvram_lock, flags); | ||
55 | nvram_buf[0] = val; | ||
56 | if ((call_rtas("nvram-store", 3, 2, &done, addr, __pa(nvram_buf), 1) != 0) || 1 != done) | ||
57 | printk(KERN_DEBUG "rtas IO error storing 0x%02x at %d", val, addr); | ||
58 | spin_unlock_irqrestore(&nvram_lock, flags); | ||
59 | } | ||
60 | |||
61 | void __init chrp_nvram_init(void) | ||
62 | { | ||
63 | struct device_node *nvram; | ||
64 | unsigned int *nbytes_p, proplen; | ||
65 | |||
66 | nvram = of_find_node_by_type(NULL, "nvram"); | ||
67 | if (nvram == NULL) | ||
68 | return; | ||
69 | |||
70 | nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen); | ||
71 | if (nbytes_p == NULL || proplen != sizeof(unsigned int)) | ||
72 | return; | ||
73 | |||
74 | nvram_size = *nbytes_p; | ||
75 | |||
76 | printk(KERN_INFO "CHRP nvram contains %u bytes\n", nvram_size); | ||
77 | of_node_put(nvram); | ||
78 | |||
79 | ppc_md.nvram_read_val = chrp_nvram_read; | ||
80 | ppc_md.nvram_write_val = chrp_nvram_write; | ||
81 | |||
82 | return; | ||
83 | } | ||
diff --git a/arch/ppc/platforms/chrp_setup.c b/arch/ppc/platforms/chrp_setup.c index dad81ffd401..f1b70ab3c6f 100644 --- a/arch/ppc/platforms/chrp_setup.c +++ b/arch/ppc/platforms/chrp_setup.c | |||
@@ -454,8 +454,7 @@ void __init | |||
454 | chrp_init2(void) | 454 | chrp_init2(void) |
455 | { | 455 | { |
456 | #ifdef CONFIG_NVRAM | 456 | #ifdef CONFIG_NVRAM |
457 | // XX replace this in a more saner way | 457 | chrp_nvram_init(); |
458 | // pmac_nvram_init(); | ||
459 | #endif | 458 | #endif |
460 | 459 | ||
461 | request_region(0x20,0x20,"pic1"); | 460 | request_region(0x20,0x20,"pic1"); |
diff --git a/include/asm-ppc/system.h b/include/asm-ppc/system.h index eb30c09516a..bd99cb53a19 100644 --- a/include/asm-ppc/system.h +++ b/include/asm-ppc/system.h | |||
@@ -70,6 +70,7 @@ extern void _set_L3CR(unsigned long); | |||
70 | #endif | 70 | #endif |
71 | extern void via_cuda_init(void); | 71 | extern void via_cuda_init(void); |
72 | extern void pmac_nvram_init(void); | 72 | extern void pmac_nvram_init(void); |
73 | extern void chrp_nvram_init(void); | ||
73 | extern void read_rtc_time(void); | 74 | extern void read_rtc_time(void); |
74 | extern void pmac_find_display(void); | 75 | extern void pmac_find_display(void); |
75 | extern void giveup_fpu(struct task_struct *); | 76 | extern void giveup_fpu(struct task_struct *); |