diff options
-rw-r--r-- | arch/powerpc/sysdev/mmio_nvram.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/arch/powerpc/sysdev/mmio_nvram.c b/arch/powerpc/sysdev/mmio_nvram.c index ff23f5a4d4b9..e073e246293d 100644 --- a/arch/powerpc/sysdev/mmio_nvram.c +++ b/arch/powerpc/sysdev/mmio_nvram.c | |||
@@ -80,33 +80,39 @@ static ssize_t mmio_nvram_get_size(void) | |||
80 | int __init mmio_nvram_init(void) | 80 | int __init mmio_nvram_init(void) |
81 | { | 81 | { |
82 | struct device_node *nvram_node; | 82 | struct device_node *nvram_node; |
83 | const unsigned long *buffer; | ||
84 | int proplen; | ||
85 | unsigned long nvram_addr; | 83 | unsigned long nvram_addr; |
84 | struct resource r; | ||
86 | int ret; | 85 | int ret; |
87 | 86 | ||
88 | ret = -ENODEV; | ||
89 | nvram_node = of_find_node_by_type(NULL, "nvram"); | 87 | nvram_node = of_find_node_by_type(NULL, "nvram"); |
90 | if (!nvram_node) | 88 | if (!nvram_node) { |
89 | printk(KERN_WARNING "nvram: no node found in device-tree\n"); | ||
90 | return -ENODEV; | ||
91 | } | ||
92 | |||
93 | ret = of_address_to_resource(nvram_node, 0, &r); | ||
94 | if (ret) { | ||
95 | printk(KERN_WARNING "nvram: failed to get address (err %d)\n", | ||
96 | ret); | ||
91 | goto out; | 97 | goto out; |
92 | 98 | } | |
93 | ret = -EIO; | 99 | nvram_addr = r.start; |
94 | buffer = get_property(nvram_node, "reg", &proplen); | 100 | mmio_nvram_len = r.end - r.start + 1; |
95 | if (proplen != 2*sizeof(unsigned long)) | 101 | if ( (!mmio_nvram_len) || (!nvram_addr) ) { |
96 | goto out; | 102 | printk(KERN_WARNING "nvram: address or lenght is 0\n"); |
97 | 103 | ret = -EIO; | |
98 | ret = -ENODEV; | ||
99 | nvram_addr = buffer[0]; | ||
100 | mmio_nvram_len = buffer[1]; | ||
101 | if ( (!mmio_nvram_len) || (!nvram_addr) ) | ||
102 | goto out; | 104 | goto out; |
105 | } | ||
103 | 106 | ||
104 | mmio_nvram_start = ioremap(nvram_addr, mmio_nvram_len); | 107 | mmio_nvram_start = ioremap(nvram_addr, mmio_nvram_len); |
105 | if (!mmio_nvram_start) | 108 | if (!mmio_nvram_start) { |
109 | printk(KERN_WARNING "nvram: failed to ioremap\n"); | ||
110 | ret = -ENOMEM; | ||
106 | goto out; | 111 | goto out; |
112 | } | ||
107 | 113 | ||
108 | printk(KERN_INFO "mmio NVRAM, %luk mapped to %p\n", | 114 | printk(KERN_INFO "mmio NVRAM, %luk at 0x%lx mapped to %p\n", |
109 | mmio_nvram_len >> 10, mmio_nvram_start); | 115 | mmio_nvram_len >> 10, nvram_addr, mmio_nvram_start); |
110 | 116 | ||
111 | ppc_md.nvram_read = mmio_nvram_read; | 117 | ppc_md.nvram_read = mmio_nvram_read; |
112 | ppc_md.nvram_write = mmio_nvram_write; | 118 | ppc_md.nvram_write = mmio_nvram_write; |