From edf03c1ee84e5095e8f4a4b8ad6e0784118cb176 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 31 Oct 2005 20:08:40 -0500 Subject: [PATCH] powerpc: move mmio_nvram.c over to arch/powerpc The nvram code formally known as bpa_nvram.c is rather generic really, so it is quite likely to be useful to future boards not based on cell. This patch puts it into arch/powerpc/sysdev. Signed-off-by: Arnd Bergmann Signed-off-by: Paul Mackerras --- arch/powerpc/Kconfig | 5 ++ arch/powerpc/sysdev/Makefile | 1 + arch/powerpc/sysdev/mmio_nvram.c | 118 +++++++++++++++++++++++++++++++++++++++ arch/ppc64/kernel/Makefile | 2 +- arch/ppc64/kernel/bpa_nvram.c | 118 --------------------------------------- 5 files changed, 125 insertions(+), 119 deletions(-) create mode 100644 arch/powerpc/sysdev/mmio_nvram.c delete mode 100644 arch/ppc64/kernel/bpa_nvram.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index aa13a9d95ea2..1c44a1dac421 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -325,6 +325,7 @@ config PPC_CELL depends on PPC_MULTIPLATFORM && PPC64 select PPC_RTAS select RTAS_FW + select MMIO_NVRAM config PPC_OF bool @@ -360,6 +361,10 @@ config RTAS_FW depends on PPC_RTAS default n +config MMIO_NVRAM + bool + default n + config MPIC_BROKEN_U3 bool depends on PPC_MAPLE diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile index 8acd21dee05d..6b7efcfc352a 100644 --- a/arch/powerpc/sysdev/Makefile +++ b/arch/powerpc/sysdev/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_PPC_MPC106) += grackle.o obj-$(CONFIG_BOOKE) += dcr.o obj-$(CONFIG_40x) += dcr.o obj-$(CONFIG_U3_DART) += u3_iommu.o +obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o diff --git a/arch/powerpc/sysdev/mmio_nvram.c b/arch/powerpc/sysdev/mmio_nvram.c new file mode 100644 index 000000000000..74e0d31a3559 --- /dev/null +++ b/arch/powerpc/sysdev/mmio_nvram.c @@ -0,0 +1,118 @@ +/* + * memory mapped NVRAM + * + * (C) Copyright IBM Corp. 2005 + * + * Authors : Utz Bacher + * + * 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, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +static void __iomem *mmio_nvram_start; +static long mmio_nvram_len; +static spinlock_t mmio_nvram_lock = SPIN_LOCK_UNLOCKED; + +static ssize_t mmio_nvram_read(char *buf, size_t count, loff_t *index) +{ + unsigned long flags; + + if (*index >= mmio_nvram_len) + return 0; + if (*index + count > mmio_nvram_len) + count = mmio_nvram_len - *index; + + spin_lock_irqsave(&mmio_nvram_lock, flags); + + memcpy_fromio(buf, mmio_nvram_start + *index, count); + + spin_unlock_irqrestore(&mmio_nvram_lock, flags); + + *index += count; + return count; +} + +static ssize_t mmio_nvram_write(char *buf, size_t count, loff_t *index) +{ + unsigned long flags; + + if (*index >= mmio_nvram_len) + return 0; + if (*index + count > mmio_nvram_len) + count = mmio_nvram_len - *index; + + spin_lock_irqsave(&mmio_nvram_lock, flags); + + memcpy_toio(mmio_nvram_start + *index, buf, count); + + spin_unlock_irqrestore(&mmio_nvram_lock, flags); + + *index += count; + return count; +} + +static ssize_t mmio_nvram_get_size(void) +{ + return mmio_nvram_len; +} + +int __init mmio_nvram_init(void) +{ + struct device_node *nvram_node; + unsigned long *buffer; + int proplen; + unsigned long nvram_addr; + int ret; + + ret = -ENODEV; + nvram_node = of_find_node_by_type(NULL, "nvram"); + if (!nvram_node) + goto out; + + ret = -EIO; + buffer = (unsigned long *)get_property(nvram_node, "reg", &proplen); + if (proplen != 2*sizeof(unsigned long)) + goto out; + + ret = -ENODEV; + nvram_addr = buffer[0]; + mmio_nvram_len = buffer[1]; + if ( (!mmio_nvram_len) || (!nvram_addr) ) + goto out; + + mmio_nvram_start = ioremap(nvram_addr, mmio_nvram_len); + if (!mmio_nvram_start) + goto out; + + printk(KERN_INFO "mmio NVRAM, %luk mapped to %p\n", + mmio_nvram_len >> 10, mmio_nvram_start); + + ppc_md.nvram_read = mmio_nvram_read; + ppc_md.nvram_write = mmio_nvram_write; + ppc_md.nvram_size = mmio_nvram_get_size; + +out: + of_node_put(nvram_node); + return ret; +} diff --git a/arch/ppc64/kernel/Makefile b/arch/ppc64/kernel/Makefile index a01a9de9eb56..afd445114446 100644 --- a/arch/ppc64/kernel/Makefile +++ b/arch/ppc64/kernel/Makefile @@ -31,7 +31,7 @@ endif obj-$(CONFIG_PPC_PSERIES) += rtasd.o udbg_16550.o -obj-$(CONFIG_PPC_CELL) += bpa_setup.o bpa_iommu.o bpa_nvram.o \ +obj-$(CONFIG_PPC_CELL) += bpa_setup.o bpa_iommu.o \ bpa_iic.o spider-pic.o obj-$(CONFIG_KEXEC) += machine_kexec.o diff --git a/arch/ppc64/kernel/bpa_nvram.c b/arch/ppc64/kernel/bpa_nvram.c deleted file mode 100644 index 74e0d31a3559..000000000000 --- a/arch/ppc64/kernel/bpa_nvram.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * memory mapped NVRAM - * - * (C) Copyright IBM Corp. 2005 - * - * Authors : Utz Bacher - * - * 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, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -static void __iomem *mmio_nvram_start; -static long mmio_nvram_len; -static spinlock_t mmio_nvram_lock = SPIN_LOCK_UNLOCKED; - -static ssize_t mmio_nvram_read(char *buf, size_t count, loff_t *index) -{ - unsigned long flags; - - if (*index >= mmio_nvram_len) - return 0; - if (*index + count > mmio_nvram_len) - count = mmio_nvram_len - *index; - - spin_lock_irqsave(&mmio_nvram_lock, flags); - - memcpy_fromio(buf, mmio_nvram_start + *index, count); - - spin_unlock_irqrestore(&mmio_nvram_lock, flags); - - *index += count; - return count; -} - -static ssize_t mmio_nvram_write(char *buf, size_t count, loff_t *index) -{ - unsigned long flags; - - if (*index >= mmio_nvram_len) - return 0; - if (*index + count > mmio_nvram_len) - count = mmio_nvram_len - *index; - - spin_lock_irqsave(&mmio_nvram_lock, flags); - - memcpy_toio(mmio_nvram_start + *index, buf, count); - - spin_unlock_irqrestore(&mmio_nvram_lock, flags); - - *index += count; - return count; -} - -static ssize_t mmio_nvram_get_size(void) -{ - return mmio_nvram_len; -} - -int __init mmio_nvram_init(void) -{ - struct device_node *nvram_node; - unsigned long *buffer; - int proplen; - unsigned long nvram_addr; - int ret; - - ret = -ENODEV; - nvram_node = of_find_node_by_type(NULL, "nvram"); - if (!nvram_node) - goto out; - - ret = -EIO; - buffer = (unsigned long *)get_property(nvram_node, "reg", &proplen); - if (proplen != 2*sizeof(unsigned long)) - goto out; - - ret = -ENODEV; - nvram_addr = buffer[0]; - mmio_nvram_len = buffer[1]; - if ( (!mmio_nvram_len) || (!nvram_addr) ) - goto out; - - mmio_nvram_start = ioremap(nvram_addr, mmio_nvram_len); - if (!mmio_nvram_start) - goto out; - - printk(KERN_INFO "mmio NVRAM, %luk mapped to %p\n", - mmio_nvram_len >> 10, mmio_nvram_start); - - ppc_md.nvram_read = mmio_nvram_read; - ppc_md.nvram_write = mmio_nvram_write; - ppc_md.nvram_size = mmio_nvram_get_size; - -out: - of_node_put(nvram_node); - return ret; -} -- cgit v1.2.3