summaryrefslogtreecommitdiff
path: root/recipes/linux/opensimpad/simpad-backlight-if.patch
blob: 4e04afb5e9d03e0d8bea1bcd2f1a0e9c6a8e17a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

#
# Patch managed by http://www.holgerschurig.de/patcher.html
#

--- linux-2.4.27/drivers/video/mq200fb.c~simpad-backlight-if
+++ linux-2.4.27/drivers/video/mq200fb.c
@@ -82,6 +82,20 @@
 	write:	proc_write_reg
 };
 
+#ifdef CONFIG_SA1100_SIMPAD
+
+static ssize_t proc_read_light(struct file * file, char * buf,
+		size_t nbytes, loff_t *ppos);
+static ssize_t proc_write_light(struct file * file, const char * buffer,
+		size_t count, loff_t *ppos);
+
+static struct file_operations proc_light_operations = {
+	read:	proc_read_light,
+	write:	proc_write_light
+};
+#endif
+
+
 typedef struct sa1110_reg_entry {
 	u32 phyaddr;
 	char* name;
@@ -622,6 +636,20 @@
        }
     }
 
+#ifdef CONFIG_SA1100_SIMPAD
+	entry = create_proc_entry("backlight",
+				 S_IRWXU | S_IRWXG | S_IRWXO,
+				 mq200dir);
+	if(entry) {
+	  entry->proc_fops = &proc_light_operations;
+	} 
+    else {
+	  printk( KERN_ERR
+		  "mq200fb: can't create /proc/" MQ200_DIRNAME
+		  "/backlight\n");
+	  return(-ENOMEM);
+    }
+ #endif
 
 #ifdef MQ_SA1110
 
@@ -1879,7 +1907,7 @@
 static void writeBrightness(void *pMQMMIO, int brightness)
 {
     unsigned long dutyCycle, pwmcontrol;
-    int MAX_BRIGHT_REG = 0x000000fc; /* int 254 */
+    int MAX_BRIGHT_REG = 0x000000fe; /* int 254 */
     
     if(brightness > MAX_BRIGHT_REG)
       return;
@@ -1961,3 +1989,43 @@
 	return (count+endp-buffer);
 }
 
+#ifdef CONFIG_SA1100_SIMPAD
+
+#define SIMPAD_BACKLIGHT_MASK	0x00a10044
+
+static int proc_read_light(struct file * file, char * buf,
+		size_t nbytes, loff_t *ppos)
+{
+	char outputbuf[15];
+	int count;
+	u32 pwmctl;
+	if (*ppos>0) /* Assume reading completed in previous read*/
+		return 0;
+
+	pwmctl = *((volatile *) mq200_p2v(0x4be0e03c));
+	pwmctl &= ~SIMPAD_BACKLIGHT_MASK;
+	pwmctl = pwmctl >> 8;	
+	pwmctl = 254 - pwmctl;
+		
+	count = sprintf(outputbuf, "%d\n",pwmctl);
+	*ppos+=count;
+	if (count>nbytes)  /* Assume output can be read at one time */
+		return -EINVAL;
+	if (copy_to_user(buf, outputbuf, count))
+		return -EFAULT;
+	return count;
+}
+
+static ssize_t proc_write_light(struct file * file, const char * buffer,
+		size_t count, loff_t *ppos)
+{
+	void * pMQMMIO = (void *) mqMmioAddr;
+	char *endp;
+	unsigned long newvalue = simple_strtoul(buffer,&endp,0);
+	if (newvalue > 254)
+		newvalue = 254;
+	writeBrightness(pMQMMIO,newvalue);
+	mq200_backlight(pMQMMIO,(int)newvalue);
+	return (count+endp-buffer);
+}
+#endif