Index: linux-2.6.15-rc1/arch/arm/mach-pxa/hx2750_test.c
===================================================================
--- linux-2.6.15-rc1.orig/arch/arm/mach-pxa/hx2750_test.c	2005-11-19 23:13:40.000000000 +0000
+++ linux-2.6.15-rc1/arch/arm/mach-pxa/hx2750_test.c	2005-11-19 23:38:51.000000000 +0000
@@ -14,7 +14,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/ioport.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
 #include <linux/input.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -23,6 +23,7 @@
 #include <asm/hardware.h>
 #include <asm/mach/arch.h>
 
+#include <asm/arch/pm.h>
 #include <asm/arch/hx2750.h>
 #include <asm/arch/pxa-regs.h>
  
@@ -32,7 +33,7 @@
 /*    
  * Sysfs functions       
  */   
-static ssize_t test1_show(struct device *dev, char *buf) 
+static ssize_t test1_show(struct device *dev, struct device_attribute *attr, char *buf) 
 {
 	unsigned long rp;
 
@@ -56,7 +57,7 @@
 extern void tsc2101_print_miscdata(struct device *dev);
 extern struct platform_device tsc2101_device;
  
-static ssize_t test1_store(struct device *dev, const char *buf, size_t count)
+static ssize_t test1_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
 	prodval = simple_strtoul(buf, NULL, 10);  
  
@@ -67,7 +68,7 @@
  
 static DEVICE_ATTR(test1, 0644, test1_show, test1_store);
 
-static ssize_t test2_show(struct device *dev, char *buf) 
+static ssize_t test2_show(struct device *dev, struct device_attribute *attr, char *buf) 
 {
 	printk(KERN_ERR "SSCR0_P2: %08x\n", SSCR0_P2);
 	printk(KERN_ERR "SSCR1_P2: %08x\n", SSCR1_P2);
@@ -94,28 +95,39 @@
 
 extern unsigned int hx2750_egpio_current;
 
-static ssize_t setegpio_show(struct device *dev, char *buf) 
+static ssize_t setegpio_show(struct device *dev, struct device_attribute *attr, char *buf) 
 {
 	return sprintf(buf, "%x\n",hx2750_egpio_current); 
 } 
 
-static ssize_t setegpio_store(struct device *dev, const char *buf, size_t count)
+static ssize_t setegpio_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
 	unsigned int val = simple_strtoul(buf, NULL, 10);
 
-	hx2750_set_egpio(1 << val);
+	hx2750_set_egpio(val);
 
 	return count; 
 } 
 
 static DEVICE_ATTR(setegpio, 0644, setegpio_show, setegpio_store);
 
-static ssize_t clregpio_show(struct device *dev, char *buf) 
+static ssize_t clregpio_show(struct device *dev, struct device_attribute *attr, char *buf) 
 {
 	return sprintf(buf, "%x\n",hx2750_egpio_current); 
 } 
 
-static ssize_t gpio_show(struct device *dev, char *buf) 
+static ssize_t clregpio_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+	unsigned int val = simple_strtoul(buf, NULL, 10);
+
+	hx2750_clear_egpio(val);
+
+	return count; 
+} 
+
+static DEVICE_ATTR(clregpio, 0644, clregpio_show, clregpio_store);
+
+static ssize_t gpio_show(struct device *dev, struct device_attribute *attr, char *buf) 
 {
 	int i;
 	
@@ -141,19 +153,8 @@
 	return sprintf(buf, "EGPIO: %x\n",hx2750_egpio_current); 
 } 
 
-static ssize_t clregpio_store(struct device *dev, const char *buf, size_t count)
-{
-	unsigned int val = simple_strtoul(buf, NULL, 10);
-
-	hx2750_clear_egpio(1 << val);
-
-	return count; 
-} 
 
-static DEVICE_ATTR(clregpio, 0644, clregpio_show, clregpio_store);
-
-
-static ssize_t gpioclr_store(struct device *dev, const char *buf, size_t count)
+static ssize_t gpioclr_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
 	int prod;
 	prod = simple_strtoul(buf, NULL, 10);  
@@ -165,7 +166,7 @@
  
 static DEVICE_ATTR(gpioclr, 0644, gpio_show, gpioclr_store);
 
-static ssize_t gpioset_store(struct device *dev, const char *buf, size_t count)
+static ssize_t gpioset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
 	int prod;
 	prod = simple_strtoul(buf, NULL, 10);  
@@ -177,23 +178,25 @@
  
 static DEVICE_ATTR(gpioset, 0644, gpio_show, gpioset_store);
 
+void do_ds2760(void);
 
-static ssize_t ssp2read_store(struct device *dev, const char *buf, size_t count)
+static ssize_t ssp2read_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-	unsigned int val = simple_strtoul(buf, NULL, 16);
+	//unsigned int val = simple_strtoul(buf, NULL, 16);
 
-	printk("Read: %08x\n",hx2750_ssp2_read(val));
+	//printk("Read: %08x\n",hx2750_ssp2_read(val));
+	do_ds2760();
 
 	return count; 
 } 
 
-static DEVICE_ATTR(ssp2read, 0200, NULL, ssp2read_store);
-
-static ssize_t ssp2write_store(struct device *dev, const char *buf, size_t count)
+static DEVICE_ATTR(ssp2read, 0200, NULL, ssp2read_store);
+
+static ssize_t ssp2write_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-	unsigned int val = simple_strtoul(buf, NULL, 16);
+	//unsigned int val = simple_strtoul(buf, NULL, 16);
 
-	printk("Write: %08x\n",hx2750_ssp2_write(val));
+	//printk("Write: %08x\n",hx2750_ssp2_write(val));
 
 	return count; 
 } 
@@ -201,23 +204,23 @@
 static DEVICE_ATTR(ssp2write, 0200, NULL, ssp2write_store);
 
 
-static ssize_t sspr_store(struct device *dev, const char *buf, size_t count)
+static ssize_t sspr_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {        
 	unsigned long val,ret;        
 	val = simple_strtoul(buf, NULL, 0);   
 	
 	hx2750_tsc2101_send(1<<15,val,&ret,1);
 
-	printk("Response: %x\n",ret);  
+	printk("Response: %lx\n", ret);  
 	
 	return count;
 }   
 
 static DEVICE_ATTR(sspr, 0200, NULL, sspr_store);
  
-static ssize_t sspw_store(struct device *dev, const char *buf, size_t count)
+static ssize_t sspw_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {        
-	int val,ret;        
+	unsigned long val,ret;        
 	sscanf(buf, "%lx %lx", &val, &ret);	
 	
 	hx2750_tsc2101_send(0,val,&ret,1);
@@ -242,8 +245,8 @@
 
 static int hx2750_pxa_pm_enter(suspend_state_t state)
 {
-	int i;
-	u32 save[10];
+	//int i;
+	//u32 save[10];
 
 	PWER = 0xC0000003;// | PWER_RTC;
 	PFER = 0x00000003;
@@ -331,9 +334,19 @@
 	return IRQ_HANDLED;
 }
 
+static struct pm_ops hx2750_pm_ops = {
+	.pm_disk_mode	= PM_DISK_FIRMWARE,
+	.prepare	= pxa_pm_prepare,
+	.enter		= hx2750_pxa_pm_enter,
+	.finish		= pxa_pm_finish,
+};
+
 
 static int __init hx2750_test_probe(struct device *dev)
 {
+	pxa_gpio_mode(86 | GPIO_IN);
+	pxa_gpio_mode(87 | GPIO_OUT | GPIO_DFLT_HIGH);	
+
 	pxa_gpio_mode(21 | GPIO_OUT | GPIO_DFLT_HIGH);
 	pxa_gpio_mode(HX2750_GPIO_CHARGE | GPIO_OUT | GPIO_DFLT_HIGH);
 	pxa_gpio_mode(83 | GPIO_OUT | GPIO_DFLT_HIGH);
@@ -350,6 +363,7 @@
 	pxa_gpio_mode(HX2750_GPIO_LEDMAIL | GPIO_OUT | GPIO_DFLT_LOW);
 	pxa_gpio_mode(107 | GPIO_OUT | GPIO_DFLT_LOW);
 	pxa_gpio_mode(114 | GPIO_OUT | GPIO_DFLT_LOW);	
+
 	
 	pxa_gpio_mode(HX2750_GPIO_BATTCOVER1 | GPIO_IN);
 	pxa_gpio_mode(HX2750_GPIO_BATTCOVER2 | GPIO_IN);
@@ -398,9 +412,8 @@
 	request_irq(HX2750_IRQ_GPIO_EXTPWR, hx2750_charge_int, SA_INTERRUPT, "hx2750_extpwr", NULL);
 	set_irq_type(HX2750_IRQ_GPIO_EXTPWR, IRQT_BOTHEDGE);
 	
-	pxa_pm_enter_orig=pxa_pm_ops.enter;
-	pxa_pm_ops.enter=hx2750_pxa_pm_enter;
-	
+	pm_set_ops(&hx2750_pm_ops);
+
 	return 0;
 }
 
@@ -425,9 +438,241 @@
  	driver_unregister(&hx2750_test_driver);
 }
 
-module_init(hx2750_test_init);
+late_initcall(hx2750_test_init);
 module_exit(hx2750_test_exit);
 
 MODULE_AUTHOR("Richard Purdie <richard@o-hand.com>");
-MODULE_DESCRIPTION("iPAQ hx2750 Backlight Driver");
+MODULE_DESCRIPTION("iPAQ hx2750 Test Code");
 MODULE_LICENSE("GPLv2");
+
+/*(SSCR0_TI | (SSCR0_DSS & 0x09 )) , 0, 0, SSCR0_SerClkDiv(212)
+Serial Bit Rate = 13Mhz / 106
+122641.5khz
+0.0000163s
+0.0163ms
+Each half clock pulse lasts 16.3us
+32.6us pulse length
+10 Bit TI Mode*/
+
+
+static void setportlow(void)
+{
+	GPCR(87) = GPIO_bit(87);
+}
+
+void setporthigh(void)
+{
+	GPSR(87) = GPIO_bit(87);
+}
+
+static int readport(void)
+{
+	if (GPLR(86) & GPIO_bit(86))
+		return 1;
+	return 0;
+}
+
+// Pause for exactly 'tick' number of ticks = 0.25us
+static void tickDelay(int tick)
+{
+	udelay(tick/4);
+}
+// 'tick' values
+static int A,B,C,D,E,F,G,H,I,J;
+//-----------------------------------------------------------------------------
+// Set the 1-Wire timing to 'standard' (standard=1) or 'overdrive' (standard=0).
+//
+static void SetSpeed(int standard)
+{
+		// Standard Speed
+		A = 6 * 4;
+		B = 64 * 4;
+		C = 60 * 4;
+		D = 10 * 4;
+		E = 9 * 4;
+		F = 55 * 4;
+		G = 0;
+		H = 480 * 4;
+		I = 70 * 4;
+		J = 410 * 4;
+}
+
+//-----------------------------------------------------------------------------
+// Generate a 1-Wire reset, return 1 if no presence detect was found,
+// return 0 otherwise.
+// (NOTE: Does not handle alarm presence from DS2404/DS1994)
+//
+static int OWTouchReset(void)
+{
+	int result;
+	tickDelay(G);
+	setportlow(); // Drives DQ low
+	tickDelay(H);
+	setporthigh(); // Releases the bus
+	tickDelay(I);
+	result = readport(); // Sample for presence pulse from slave
+	tickDelay(J); // Complete the reset sequence recovery
+	return result; // Return sample presence pulse result
+}
+//-----------------------------------------------------------------------------
+// Send a 1-Wire write bit. Provide 10us recovery time.
+//
+static void OWWriteBit(int bit)
+{
+	if (bit)
+	{
+		// Write '1' bit
+		setportlow(); // Drives DQ low
+		tickDelay(A);
+		setporthigh(); // Releases the bus
+		tickDelay(B); // Complete the time slot and 10us recovery
+	}
+	else
+	{
+		// Write '0' bit
+		setportlow(); // Drives DQ low
+		tickDelay(C);
+		setporthigh(); // Releases the bus
+		tickDelay(D);
+	}
+}
+//-----------------------------------------------------------------------------
+// Read a bit from the 1-Wire bus and return it. Provide 10us recovery time.
+//
+static int OWReadBit(void)
+{
+	int result;
+	setportlow(); // Drives DQ low
+	tickDelay(A);
+	setporthigh(); // Releases the bus
+	tickDelay(E);
+	result = readport(); // Sample the bit value from the slave
+	tickDelay(F); // Complete the time slot and 10us recovery
+	return result;
+}
+
+
+
+//-----------------------------------------------------------------------------
+// Write 1-Wire data byte
+//
+static void OWWriteByte(int data)
+{
+	int loop;
+	// Loop to write each bit in the byte, LS-bit first
+	for (loop = 0; loop < 8; loop++)
+	{
+		OWWriteBit(data & 0x01);
+		// shift the data byte for the next bit
+		data >>= 1;
+	}
+}
+//-----------------------------------------------------------------------------
+// Read 1-Wire data byte and return it
+//
+static int OWReadByte(void)
+{
+	int loop, result=0;
+	for (loop = 0; loop < 8; loop++)
+	{
+		// shift the result to get it ready for the next bit
+		result >>= 1;
+		// if result is one, then set MS bit
+		if (OWReadBit())
+			result |= 0x80;
+	}
+	return result;
+}
+//-----------------------------------------------------------------------------
+// Write a 1-Wire data byte and return the sampled result.
+//
+static int OWTouchByte(int data)
+{
+	int loop, result=0;
+	for (loop = 0; loop < 8; loop++)
+	{
+		// shift the result to get it ready for the next bit
+		result >>= 1;
+		// If sending a '1' then read a bit else write a '0'
+		if (data & 0x01)
+		{
+			if (OWReadBit())
+				result |= 0x80;
+		}
+		else
+			OWWriteBit(0);
+		// shift the data byte for the next bit
+		data >>= 1;
+	}
+	return result;
+}
+
+//-----------------------------------------------------------------------------
+// Write a block 1-Wire data bytes and return the sampled result in the same
+// buffer.
+//
+static void OWBlock(unsigned char *data, int data_len)
+{
+	int loop;
+	for (loop = 0; loop < data_len; loop++)
+	{
+		data[loop] = OWTouchByte(data[loop]);
+	}
+}
+//-----------------------------------------------------------------------------
+// Set all devices on 1-Wire to overdrive speed. Return '1' if at least one
+// overdrive capable device is detected.
+//
+static int OWOverdriveSkip(unsigned char *data, int data_len)
+{
+	// set the speed to 'standard'
+	SetSpeed(1);
+	// reset all devices
+	if (OWTouchReset()) // Reset the 1-Wire bus
+		return 0; // Return if no devices found
+	// overdrive skip command
+	OWWriteByte(0x3C);
+	// set the speed to 'overdrive'
+	SetSpeed(0);
+	// do a 1-Wire reset in 'overdrive' and return presence result
+	return OWTouchReset();
+}
+
+
+
+// DS2760 Code
+
+int ReadPageData(int page, unsigned char *page_data)
+{
+	int i;
+	// set the speed to 'standard'
+	SetSpeed(1);
+	// select the device
+	if (OWTouchReset()) // Reset the 1-Wire bus
+		return 0; // Return if no devices found
+	OWWriteByte(0xCC); // Send Skip ROM command to select single device
+	// read the page
+	OWWriteByte(0x69); // Read Page command
+	OWWriteByte(0); // Start reading at byte 0
+	// read the page data
+	for (i = 0; i < 32; i++)
+		page_data[i] = OWReadByte();
+	OWWriteByte(0xFF);
+	return 1;
+}
+
+void do_ds2760(void)
+{
+	unsigned char data[32];
+	int i;
+	if (ReadPageData(0,&data))
+	{
+		printk("Data Received: ");
+		for (i = 0; i < 32; i++)
+			printk("%02x ",data[i]);
+		printk("\n");
+
+	} else
+		printk("Couldn't reset 1 wire bus\n");
+
+}
