diff target-utils/pirexplore/lcd.c @ 76:07b686248ab7

pirexplore: finally got the backlight to turn on
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 01 Aug 2013 00:26:29 +0000
parents 8138a6380ae3
children fcbe1332b197
line wrap: on
line diff
--- a/target-utils/pirexplore/lcd.c	Sun Jul 28 01:30:22 2013 +0000
+++ b/target-utils/pirexplore/lcd.c	Thu Aug 01 00:26:29 2013 +0000
@@ -1,6 +1,17 @@
 #include <sys/types.h>
 #include "types.h"
 
+#define	GPIO_OUT_REG	(*(volatile u16 *)0xFFFE4802)
+#define	nCS4_ADDR0	(*(volatile u16 *)0x02800000)
+#define	nCS4_ADDR2	(*(volatile u16 *)0x02800002)
+
+fb_spca_write(addr, data)
+{
+	GPIO_OUT_REG &= 0xFF7F;
+	nCS4_ADDR0 = addr;
+	nCS4_ADDR2 = data;
+}
+
 void
 cmd_spca(argbulk)
 	char *argbulk;
@@ -18,6 +29,31 @@
 		printf("ERROR: arg2 must be a valid 16-bit hex value\n");
 		return;
 	}
-	*(volatile u16 *)0x02800000 = addr;
-	*(volatile u16 *)0x02800002 = data;
+	fb_spca_write(addr, data);
 }
+
+void
+cmd_spcainit()
+{
+	/*
+	 * Apparently we have to give it a reset pulse, then immediately
+	 * do the black magic register write sequence.
+	 */
+	GPIO_OUT_REG = 0x0000;
+	GPIO_OUT_REG = 0x0012;
+	/* non-understandable voodoo copied from OsmocomBB */
+	fb_spca_write(0x7e, 0x00);	/* internal register access */
+	osmo_delay_ms(10);
+	fb_spca_write(0x7a, 0x00);	/* keep CPU in reset state */
+	osmo_delay_ms(10);
+	fb_spca_write(0x7f, 0x00);	/* select main page */
+	osmo_delay_ms(5);
+	fb_spca_write(0x72, 0x07);	/* don't reshape timing, 16 bit mode */
+	fb_spca_write(0x14, 0x03);
+	fb_spca_write(0x7f, 0x00);	/* select main page */
+	osmo_delay_ms(5);
+	fb_spca_write(0x06, 0xff);
+	fb_spca_write(0x7f, 0x09);
+	fb_spca_write(0x19, 0x08);	/* backlight: 0x08 is on, 0x0c is off */
+	fb_spca_write(0x23, 0x18);
+}