From 108bbfd909c4ab6ddcb363ea6ed06685c022f14b Mon Sep 17 00:00:00 2001
From: z3deverp <z3@vmsv-debian.(none)>
Date: Mon, 14 Dec 2009 22:43:22 +0900
Subject: [PATCH] test touchscreen for sha_pon011

---
 arch/arm/mach-pxa/include/mach/sha_pon.h |  134 +++++++++++++++--------------
 arch/arm/mach-pxa/sha_pon.c              |   86 +++++++++++++++++++
 2 files changed, 155 insertions(+), 65 deletions(-)

diff --git a/arch/arm/mach-pxa/include/mach/sha_pon.h b/arch/arm/mach-pxa/include/mach/sha_pon.h
old mode 100644
new mode 100755
index 6e6775b..2de227d
--- a/arch/arm/mach-pxa/include/mach/sha_pon.h
+++ b/arch/arm/mach-pxa/include/mach/sha_pon.h
@@ -169,6 +169,11 @@ void sha_pon_gpio_bit_set(unsigned cpld_bitoffset, int value);
 #define SHA_PON007_I_DET_HSYNC		75	/*L_LCLK_A0 at TFT LCD: 0/1=HSync Enable/Disable*/
 #define SHA_PON007_I_DET_TOUCHSCREEN	21	/*Touchscreen: 0/1=Pressed/Relesed*/
 #define SHA_PON007_O_CS_TOUCHSCREEN	33	/*Touchscreen CS: 0/1=Enabel/Disable*/
+#define SHA_PON011_I_DET_HSYNC		75	/*L_LCLK_A0 at TFT LCD: 0/1=HSync Enable/Disable*/
+#define SHA_PON011_I_DET_TOUCHSCREEN	21	/*Touchscreen: 0/1=Pressed/Relesed*/
+
+#define SHA_PON011_O_CS_TOUCHSCREEN	33	/*not tested*/	/*Touchscreen CS: 0/1=Enabel/Disable*/
+
 
 #define SHA_PON007_I_DET_HEADSET_ANSWER	114	/*Headset answer key: 0/1=pressed/released*/
 #define SHA_PON007_I_DET_HEADSET_CONNECT	116	/*Headset: 0/1=connected/not connected*/
@@ -286,71 +291,70 @@ void sha_pon_gpio_bit_set(unsigned cpld_bitoffset, int value);
 
 
 /*SHA_PON011 gpio */
-#define SHA_PON011_P_	0	/**/
-#define SHA_PON011_P_	1	/**/
-#define SHA_PON011_P_	2	/**/
-#define SHA_PON011_P_	3	/**/
-#define SHA_PON011_P_	4	/**/
-#define SHA_PON011_P_	5	/**/
-#define SHA_PON011_P_	6	/**/
-#define SHA_PON011_P_	7	/**/
-#define SHA_PON011_P_	8	/**/
-#define SHA_PON011_P_	9	/**/
-#define SHA_PON011_P_	10	/**/
-#define SHA_PON011_P_	11	/**/
-#define SHA_PON011_P_	12	/**/
-#define SHA_PON011_P_	13	/**/
-#define SHA_PON011_P_	14	/**/
-#define SHA_PON011_P_	15	/**/
-#define SHA_PON011_P_	16	/**/
-#define SHA_PON011_P_	17	/**/
-#define SHA_PON011_P_	20	/**/
-#define SHA_PON011_P_	21	/**/
-#define SHA_PON011_P_	22	/**/
-#define SHA_PON011_P_	23	/**/
-#define SHA_PON011_P_	33	/**/
-#define SHA_PON011_P_	34	/**/
-#define SHA_PON011_P_	35	/**/
-#define SHA_PON011_P_	36	/**/
-#define SHA_PON011_P_	37	/**/
-#define SHA_PON011_P_	39	/**/
-#define SHA_PON011_P_	40	/**/
-#define SHA_PON011_P_	41	/**/
-#define SHA_PON011_P_	44	/**/
-#define SHA_PON011_P_	45	/**/
-#define SHA_PON011_P_	46	/**/
-#define SHA_PON011_P_	48	/**/
-#define SHA_PON011_P_	50	/**/
-#define SHA_PON011_P_	51	/**/
-#define SHA_PON011_P_	52	/**/
-#define SHA_PON011_P_	53	/**/
-#define SHA_PON011_P_	54	/**/
-#define SHA_PON011_P_	55	/**/
-#define SHA_PON011_P_	56	/**/
-#define SHA_PON011_P_	57	/**/
-#define SHA_PON011_P_	77	/**/
-#define SHA_PON011_P_	78	/**/
-#define SHA_PON011_P_	79	/**/
-#define SHA_PON011_P_	80	/**/
-#define SHA_PON011_P_	81	/**/
-#define SHA_PON011_P_	82	/**/
-#define SHA_PON011_P_	83	/**/
-#define SHA_PON011_P_	84	/**/
-#define SHA_PON011_P_	85	/**/
-#define SHA_PON011_P_	88	/**/
-#define SHA_PON011_P_	89	/**/
-#define SHA_PON011_P_	90	/**/
-#define SHA_PON011_P_	91	/**/
-#define SHA_PON011_P_	96	/**/
-#define SHA_PON011_P_	97	/**/
-#define SHA_PON011_P_	101	/**/
-#define SHA_PON011_P_	105	/**/
-#define SHA_PON011_P_	106	/**/
-#define SHA_PON011_P_	107	/**/
-#define SHA_PON011_P_	115	/**/
-#define SHA_PON011_P_	116	/**/
-#define SHA_PON011_P_	119	/**/
-#define SHA_PON011_P_	120	/**/
+#define SHA_PON011_I_	0	/**/
+#define SHA_PON011_I_	1	/**/
+#define SHA_PON011_I_	2	/**/
+#define SHA_PON011_I_	3	/**/
+#define SHA_PON011_I_	4	/**/
+#define SHA_PON011_I_	5	/**/
+#define SHA_PON011_I_	6	/**/
+#define SHA_PON011_I_	7	/**/
+#define SHA_PON011_I_	8	/**/
+#define SHA_PON011_I_	9	/**/
+#define SHA_PON011_O_	10	/**/
+#define SHA_PON011_I_	11	/**/
+#define SHA_PON011_I_	12	/**/
+#define SHA_PON011_O_	13	/**/
+#define SHA_PON011_I_	14	/**/
+#define SHA_PON011_O_	15	/**/
+#define SHA_PON011_O_	16	/**/
+#define SHA_PON011_O_	17	/**/
+#define SHA_PON011_I_	20	/**/
+#define SHA_PON011_I_	22	/**/
+#define SHA_PON011_O_	23	/**/
+#define SHA_PON011_O_	33	/**/
+#define SHA_PON011_O_	34	/**/
+#define SHA_PON011_O_	35	/**/
+#define SHA_PON011_I_	36	/**/
+#define SHA_PON011_O_	37	/**/
+#define SHA_PON011_O_	39	/**/
+#define SHA_PON011_O_	40	/**/
+#define SHA_PON011_I_	41	/**/
+#define SHA_PON011_O_	44	/**/
+#define SHA_PON011_I_	45	/**/
+#define SHA_PON011_I_	46	/**/
+#define SHA_PON011_I_	48	/**/
+#define SHA_PON011_O_	50	/**/
+#define SHA_PON011_I_	51	/**/
+#define SHA_PON011_O_	52	/**/
+#define SHA_PON011_I_	53	/**/
+#define SHA_PON011_O_	54	/**/
+#define SHA_PON011_O_	55	/**/
+#define SHA_PON011_O_	56	/**/
+#define SHA_PON011_I_	57	/**/
+#define SHA_PON011_I_	77	/**/
+#define SHA_PON011_O_	78	/**/
+#define SHA_PON011_O_	79	/**/
+#define SHA_PON011_I_	80	/**/
+#define SHA_PON011_I_	81	/**/
+#define SHA_PON011_I_	82	/**/
+#define SHA_PON011_I_	83	/**/
+#define SHA_PON011_O_	84	/**/
+#define SHA_PON011_I_	85	/**/
+#define SHA_PON011_O_	88	/**/
+#define SHA_PON011_O_	89	/**/
+#define SHA_PON011_O_	90	/**/
+#define SHA_PON011_I_	91	/**/
+#define SHA_PON011_I_	96	/**/
+#define SHA_PON011_O_	97	/**/
+#define SHA_PON011_I_	101	/**/
+#define SHA_PON011_I_	105	/**/
+#define SHA_PON011_I_	106	/**/
+#define SHA_PON011_O_	107	/**/
+#define SHA_PON011_I_	115	/**/
+#define SHA_PON011_I_	116	/**/
+#define SHA_PON011_O_	119	/**/
+#define SHA_PON011_O_	120	/**/
 
 
 /*CPLD*/
diff --git a/arch/arm/mach-pxa/sha_pon.c b/arch/arm/mach-pxa/sha_pon.c
old mode 100644
new mode 100755
index 70c1ba7..61ce0e9
--- a/arch/arm/mach-pxa/sha_pon.c
+++ b/arch/arm/mach-pxa/sha_pon.c
@@ -485,6 +485,16 @@ static struct pxafb_mach_info pxa_sharp_ws011sh = {
 
 #define	SHA_PON_SSP(n)	(n)	/* bus No. */
 
+static void __init sha_pon003_init_spi(void)
+{
+/* MAX1233 touchscreen driver */
+/*
+	pxa2xx_set_spi_info( SHA_PON_SSP(2), &sha_pon003_spi_info);
+	spi_register_board_info(ARRAY_AND_SIZE(sha_pon003_spi_devices));
+*/
+}
+
+
 static void sha_pon007_wait_for_hsync(void)
 {
 	while( gpio_get_value(SHA_PON007_I_DET_HSYNC) )
@@ -555,9 +565,83 @@ static void __init sha_pon007_init_spi(void)
 	spi_register_board_info(ARRAY_AND_SIZE(sha_pon007_spi_devices));
 }
 
+
+static void sha_pon011_wait_for_hsync(void)
+{
+	while( gpio_get_value(SHA_PON011_I_DET_HSYNC) )
+		cpu_relax();
+
+	while( !gpio_get_value(SHA_PON011_I_DET_HSYNC) )
+		cpu_relax();
+}
+
+
+static struct ads7846_platform_data sha_pon011_tsc2046_info = {
+	.model			= 7846,
+	.vref_delay_usecs	= 100,
+
+	.x_min			= 240,
+	.x_max			= 3840,
+	.y_min			= 210,
+	.y_max			= 3950,
+
+	.debounce_max		= 3,
+	.debounce_tol		= 3,
+	
+	.gpio_pendown		= SHA_PON011_I_DET_TOUCHSCREEN,
+	
+	.wait_for_sync		= sha_pon011_wait_for_hsync,
+	.reverse_x		= 1,
+};
+
+static void sha_pon011_tsc2046_cs(u32 command)
+{
+	gpio_set_value(SHA_PON011_O_CS_TOUCHSCREEN, !(command == PXA2XX_CS_ASSERT));
+}
+
+static struct pxa2xx_spi_chip sha_pon011_tsc2046_chip = {
+	.cs_control	= sha_pon011_tsc2046_cs,
+};
+
+
+static struct spi_board_info sha_pon011_spi_devices[] = {
+	{
+		.modalias	= "ads7846",	/* tsc2048 compatible */
+		.max_speed_hz	= 2000000,
+		.bus_num	= SHA_PON_SSP(2),
+		.chip_select	= 0,
+		.platform_data	= &sha_pon011_tsc2046_info,
+		.controller_data= &sha_pon011_tsc2046_chip,
+		.irq		= gpio_to_irq(SHA_PON011_I_DET_TOUCHSCREEN),
+	},
+};
+
+
+static struct pxa2xx_spi_master sha_pon011_spi_info = {
+	.num_chipselect	= ARRAY_SIZE(sha_pon011_spi_devices),
+};
+
+
+static void __init sha_pon011_init_spi(void)
+{
+	int err;
+
+	err = gpio_request(SHA_PON011_O_CS_TOUCHSCREEN, "TSC2046_CS");
+	if (err)
+		return;
+
+	gpio_direction_output(SHA_PON011_O_CS_TOUCHSCREEN, 1);
+
+	pxa2xx_set_spi_info( SHA_PON_SSP(2), &sha_pon011_spi_info);
+	spi_register_board_info(ARRAY_AND_SIZE(sha_pon011_spi_devices));
+}
+
+
 #else	/* defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MASTER) */
 
+static inline void sha_pon003_init_spi(void) {}
 static inline void sha_pon007_init_spi(void) {}
+static inline void sha_pon011_init_spi(void) {}
 
 #endif	/* defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MASTER) */
 
@@ -668,6 +752,7 @@ static void __init sha_pon003_init(void)
 {
 	pxa2xx_mfp_config(ARRAY_AND_SIZE(sha_pon_mfp));
 	sha_pon_init_cpld();
+	sha_pon003_init_spi();
 	set_pxa_fb_info(&sharp_ls037v7dw01);
 	pxa_set_udc_info(&sha_pon_udc_info);
 	pxa_set_ohci_info(&sha_pon_usb_info);
@@ -703,6 +788,7 @@ static void __init sha_pon011_init(void)
 {
 	pxa2xx_mfp_config(ARRAY_AND_SIZE(sha_pon_mfp));
 	sha_pon_init_cpld();
+	sha_pon011_init_spi();
 	set_pxa_fb_info(&pxa_sharp_ws011sh);
 	pxa_set_udc_info(&sha_pon_udc_info);
 	pxa_set_ohci_info(&sha_pon_usb_info);
-- 
1.4.4.4

