Index: include/asm-arm/arch-nds/fifo.h =================================================================== --- include/asm-arm/arch-nds/fifo.h (revisjon 2036) +++ include/asm-arm/arch-nds/fifo.h (arbeidskopi) @@ -35,6 +35,7 @@ #define FIFO_WIFI (4 << 29) #define FIFO_SOUND (5 << 29) #define FIFO_POWER (6 << 29) +#define FIFO_TSC_TEMP (6 << 29) #define FIFO_TIME (7 << 29) #define FIFO_GET_TYPE(x) (((x)) & 0xe0000000) #define FIFO_GET_TYPE_DATA(x) ((x) & 0x1fffffff) @@ -133,6 +134,7 @@ void (*touch_handler)(u8 pressed, u8 x, u8 y); void (*time_handler)(u32 seconds); void (*wifi_handler)(u8 cmd, u32 data); + void (*tsc_temp_handler)(u32 temperature); /* ... */ } handler; }; Index: arch/arm/mach-nds/fifo.c =================================================================== --- arch/arm/mach-nds/fifo.c (revisjon 2036) +++ arch/arm/mach-nds/fifo.c (arbeidskopi) @@ -62,6 +62,9 @@ FIFO_WIFI_GET_CMD(data), FIFO_WIFI_GET_DATA(data)); break; + case FIFO_TSC_TEMP: + cb->handler.tsc_temp_handler(data); + break; default: break; } Index: arch/arm/mach-nds/arm7/spi.h =================================================================== --- arch/arm/mach-nds/arm7/spi.h (revisjon 2036) +++ arch/arm/mach-nds/arm7/spi.h (arbeidskopi) @@ -2,6 +2,7 @@ #define SPI_H s32 touch_read_value(int measure, int retry , int range); +u16 touch_read(u32 command); #define POWER0_SOUND_AMP (1<<0) #define POWER0_LOWER_BACKLIGHT (1<<2) Index: arch/arm/mach-nds/arm7/main.c =================================================================== --- arch/arm/mach-nds/arm7/main.c (revisjon 2036) +++ arch/arm/mach-nds/arm7/main.c (arbeidskopi) @@ -15,6 +15,8 @@ static s32 xscale, yscale; static s32 xoffset, yoffset; +static int temperature = 0; + static struct nds_firmware_block *firmware_block; /* recieve outstanding FIFO commands from ARM9 */ @@ -48,7 +50,12 @@ } break; case FIFO_POWER: - power_write(POWER_CONTROL, POWER0_SYSTEM_POWER); + /* case FIFO_TSC_TEMP: Equal to FIFO_POWER. */ + if (!data) { /* POWER */ + power_write(POWER_CONTROL, POWER0_SYSTEM_POWER); + } else { /* TSC_TEMP */ + nds_fifo_send(FIFO_TSC_TEMP + temperature); + } break; case FIFO_TIME: seconds = nds_get_time7(); @@ -220,6 +227,7 @@ u16 buttons; static u16 oldbuttons = 0x43; /* default stats */ u32 wif; + int t1, t2; wif = NDS_IF; @@ -243,6 +251,10 @@ sendTouchState(buttons); + t1 = touch_read(TSC_MEASURE_TEMP1); + t2 = touch_read(TSC_MEASURE_TEMP2); + temperature = 8490 * (t2 - t1) - 273*4096; + /* clear FIFO errors (just in case) */ if (NDS_REG_IPCFIFOCNT & (1 << 14)) NDS_REG_IPCFIFOCNT |= (1 << 15) | (1 << 14); Index: arch/arm/mach-nds/arm7/arm7.h =================================================================== --- arch/arm/mach-nds/arm7/arm7.h (revisjon 2036) +++ arch/arm/mach-nds/arm7/arm7.h (arbeidskopi) @@ -142,6 +142,8 @@ #define TSC_MEASURE_Z1 0xB0 #define TSC_MEASURE_Z2 0xC0 #define TSC_MEASURE_X 0xD0 +#define TSC_MEASURE_TEMP1 0x84 +#define TSC_MEASURE_TEMP2 0xF4 #define MIN(x,y) ((x)<(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y)) Index: arch/arm/mach-nds/arm7/spi.c =================================================================== --- arch/arm/mach-nds/arm7/spi.c (revisjon 2036) +++ arch/arm/mach-nds/arm7/spi.c (arbeidskopi) @@ -31,7 +31,7 @@ #define WAIT_FOR_NOT_BUSY() {while (REG_SPI_CR & SPI_BUSY) swiDelay(1);} -static u16 touch_read(u32 command) +u16 touch_read(u32 command) { u16 result; Index: arch/arm/mach-nds/Makefile =================================================================== --- arch/arm/mach-nds/Makefile (revisjon 2036) +++ arch/arm/mach-nds/Makefile (arbeidskopi) @@ -4,7 +4,7 @@ # Object file lists. -obj-y += arch.o irq.o time.o button.o fifo.o rtc.o disable-itcm-writes.o +obj-y += arch.o irq.o time.o button.o fifo.o rtc.o disable-itcm-writes.o tsc_temp.o obj-$(CONFIG_NDS_TEXT_CONSOLE) += console.o obj-$(CONFIG_NDS_SOUNDTEST) += soundtest.o --- /dev/null 2007-11-14 12:07:04.440078500 +0100 +++ arch/arm/mach-nds/tsc_temp.c 2007-11-14 23:13:50.000000000 +0100 @@ -0,0 +1,60 @@ +/* Make DS touchscreen controller temperature available in + * /proc/tsc_temp. + * + * Copyright (c) 2007 John S. Skogtvedt + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include + +static DECLARE_WAIT_QUEUE_HEAD(tsc_temp_wait); + +static int tsc_temp; + +static void my_temp_handler(u32 temp) { + tsc_temp = temp; +} + +static struct fifo_cb tsc_temp_fifocb = { + .type = FIFO_TSC_TEMP, + .handler.tsc_temp_handler = my_temp_handler +}; + +static int tsc_temp_read_proc(char *page, char **start, off_t off, + int count, int *eof, void *data) +{ + int len = 10; + + if (count < len) + return -EINVAL; + if (off != 0) + return 0; + + tsc_temp = 0; + nds_fifo_send(FIFO_TSC_TEMP + 1); + wait_event_interruptible(tsc_temp_wait, tsc_temp != 0); + + /* Temperature is in 20.12 fixed point. */ + + len = sprintf(page, "%d.%d\n", + tsc_temp / 4096, 10000 * (tsc_temp & 4095) / 4096); + *eof = 1; + return len; +} + +static int __init tsc_temp_init(void) { + register_fifocb(&tsc_temp_fifocb); + create_proc_read_entry("tsc_temp", 0, NULL, tsc_temp_read_proc, NULL); + + return 0; +} + +module_init(tsc_temp_init);