Subject: Cell: add temperature to SPU sysfs entries Signed-off-by: Christian Krafft Index: linux-2.6/arch/powerpc/platforms/cell/Kconfig =================================================================== --- linux-2.6.orig/arch/powerpc/platforms/cell/Kconfig +++ linux-2.6/arch/powerpc/platforms/cell/Kconfig @@ -35,4 +35,9 @@ config CBE_RAS bool "RAS features for bare metal Cell BE" default y +config CBE_THERM + tristate "CBE thermal support" + default m + depends on CBE_RAS + endmenu Index: linux-2.6/arch/powerpc/platforms/cell/Makefile =================================================================== --- linux-2.6.orig/arch/powerpc/platforms/cell/Makefile +++ linux-2.6/arch/powerpc/platforms/cell/Makefile @@ -2,6 +2,8 @@ obj-$(CONFIG_PPC_CELL_NATIVE) += interr cbe_regs.o spider-pic.o pervasive.o obj-$(CONFIG_CBE_RAS) += ras.o +obj-$(CONFIG_CBE_THERM) += thermal.o + ifeq ($(CONFIG_SMP),y) obj-$(CONFIG_PPC_CELL_NATIVE) += smp.o endif Index: linux-2.6/arch/powerpc/platforms/cell/thermal.c =================================================================== --- /dev/null +++ linux-2.6/arch/powerpc/platforms/cell/thermal.c @@ -0,0 +1,73 @@ +/* + * thermal support for the cell processor + * + * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 + * + * Author: Christian Krafft + * + * 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 "cbe_regs.h" + +static ssize_t spu_show_temp(struct sys_device *sysdev, char *buf) +{ + struct spu *spu = container_of(sysdev, struct spu, sysdev); + struct cbe_pmd_regs *pmd_regs; + struct device_node *devnode; + u64 value; + unsigned int *id; + + devnode = spu->devnode; + pmd_regs = cbe_get_pmd_regs(devnode); + value = in_be64(&pmd_regs->ts_ctsr1); + + id = (unsigned int *)get_property(spu->devnode, "reg", NULL); + + /* access the corresponding byte */ + value >>= ((*id)*8); + /* clear all other bits */ + value &= 0x3F; + /* temp is stored in steps of 2 degrees */ + value *= 2; + /* base temp is 65 degrees */ + value += 65; + + return sprintf(buf, "%d\n", (int) value); +} +static SYSDEV_ATTR(temperature, 0400, spu_show_temp, NULL); + +static int __init thermal_init(void) +{ + return spu_add_sysdev_attr(&attr_temperature); +} +module_init(thermal_init); + +static void __exit thermal_exit(void) +{ + spu_remove_sysdev_attr(&attr_temperature); +} +module_exit(thermal_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Christian Krafft "); + Index: linux-2.6/arch/powerpc/platforms/cell/cbe_regs.c =================================================================== --- linux-2.6.orig/arch/powerpc/platforms/cell/cbe_regs.c +++ linux-2.6/arch/powerpc/platforms/cell/cbe_regs.c @@ -71,6 +71,7 @@ struct cbe_pmd_regs __iomem *cbe_get_pmd return NULL; return map->pmd_regs; } +EXPORT_SYMBOL_GPL(cbe_get_pmd_regs); struct cbe_pmd_regs __iomem *cbe_get_cpu_pmd_regs(int cpu) { Index: linux-2.6/include/asm-powerpc/spu.h =================================================================== --- linux-2.6.orig/include/asm-powerpc/spu.h +++ linux-2.6/include/asm-powerpc/spu.h @@ -185,6 +185,8 @@ static inline void unregister_spu_syscal } #endif /* MODULE */ +int spu_add_sysdev_attr(struct sysdev_attribute *attr); +void spu_remove_sysdev_attr(struct sysdev_attribute *attr); /* * This defines the Local Store, Problem Area and Privlege Area of an SPU. Index: linux-2.6/arch/powerpc/configs/cell_defconfig =================================================================== --- linux-2.6.orig/arch/powerpc/configs/cell_defconfig +++ linux-2.6/arch/powerpc/configs/cell_defconfig @@ -147,6 +147,7 @@ CONFIG_SPU_FS=m CONFIG_SPU_BASE=y CONFIG_SPUFS_MMAP=y CONFIG_CBE_RAS=y +CONFIG_CBE_THERM=m # # Kernel options