Update DEP-5 uri
[debian/omnibook.git] / blank.c
1 /*
2  * blank.c -- blanking lcd console
3  * 
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2, or (at your option) any
7  * later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * Written by Soós Péter <sp@osb.hu>, 2002-2004
15  * Modified by Mathieu Bérard <mathieu.berard@crans.org>, 2006
16  */
17
18 #include "omnibook.h"
19
20 #include <asm/io.h>
21 #include "hardware.h"
22
23 static struct omnibook_feature blank_driver;
24
25 /* 
26  * console_blank_hook pointer manipulation is lock protected
27  */
28 extern int (*console_blank_hook) (int);
29 static DEFINE_SPINLOCK(blank_spinlock);
30
31
32 int omnibook_lcd_blank(int blank)
33 {
34         struct omnibook_feature *blank_feature = omnibook_find_feature("blank");
35
36         if(!blank_feature)
37                 return -ENODEV;
38
39         return omnibook_apply_write_mask(blank_feature->io_op, blank);
40 }
41
42 static int console_blank_register_hook(void)
43 {
44         spin_lock(&blank_spinlock);
45         if (console_blank_hook != omnibook_lcd_blank) {
46                 if (console_blank_hook == NULL) {
47                         console_blank_hook = omnibook_lcd_blank;
48                         printk(O_INFO "LCD backlight turn off at console blanking is enabled.\n");
49                 } else 
50                         printk(O_INFO "There is a console blanking solution already registered.\n");
51         }
52         spin_unlock(&blank_spinlock);
53         return 0;
54 }
55
56 static int console_blank_unregister_hook(void)
57 {
58         int retval;
59         spin_lock(&blank_spinlock);
60         if (console_blank_hook == omnibook_lcd_blank) {
61                 console_blank_hook = NULL;
62                 printk(O_INFO "LCD backlight turn off at console blanking is disabled.\n");
63         } else if (console_blank_hook) {
64                 printk(O_WARN "You can not disable another console blanking solution.\n");
65                 retval = -EBUSY;
66         } else {
67                 printk(O_INFO "Console blanking already disabled.\n");
68         }
69         spin_unlock(&blank_spinlock);
70         return retval;
71 }
72
73 static int omnibook_console_blank_read(char *buffer, struct omnibook_operation *io_op)
74 {
75         int len = 0;
76
77         spin_lock(&blank_spinlock);
78
79         len +=
80             sprintf(buffer + len, "LCD console blanking hook is %s\n",
81                     (console_blank_hook == omnibook_lcd_blank) ? "enabled" : "disabled");
82
83         spin_unlock(&blank_spinlock);
84
85         return len;
86 }
87
88 static int omnibook_console_blank_write(char *buffer, struct omnibook_operation *io_op)
89 {
90         int retval;
91
92         switch (*buffer) {
93         case '0':
94                 retval = console_blank_unregister_hook();
95                 break;
96         case '1':
97                 retval = console_blank_register_hook();
98                 break;
99         default:
100                 retval = -EINVAL;
101         }
102         return retval;
103 }
104
105 static int __init omnibook_console_blank_init(struct omnibook_operation *io_op)
106 {       
107         return console_blank_register_hook();
108 }
109
110 static void __exit omnibook_console_blank_cleanup(struct omnibook_operation *io_op)
111 {
112         console_blank_unregister_hook();
113 }
114
115 static struct omnibook_tbl blank_table[] __initdata = {
116         {TSM70 | TSX205, {CDI, 0, TSM100_BLANK_INDEX, 0, TSM100_LCD_OFF, TSM100_LCD_ON}},
117         {XE3GF | XE3GC | AMILOD | TSP10 | TSM70 | TSM30X,
118          COMMAND(KBC, OMNIBOOK_KBC_CMD_LCD_OFF, OMNIBOOK_KBC_CMD_LCD_ON)},
119         {OB500 | OB6000 | XE2, {PIO, OB500_GPO1, OB500_GPO1, 0, -OB500_BKLT_MASK, OB500_BKLT_MASK}},
120         {OB510 | OB6100, {PIO, OB510_GPO2, OB510_GPO2, 0, -OB510_BKLT_MASK, OB510_BKLT_MASK}},
121         {0,}
122 };
123
124 static struct omnibook_feature __declared_feature blank_driver = {
125         .name = "blank",
126         .enabled = 1,
127         .read = omnibook_console_blank_read,
128         .write = omnibook_console_blank_write,
129         .init = omnibook_console_blank_init,
130         .exit = omnibook_console_blank_cleanup,
131         .ectypes =
132             XE3GF | XE3GC | OB500 | OB510 | OB6000 | OB6100 | XE2 | AMILOD | TSP10 | TSM70 | TSM30X | TSX205,
133         .tbl = blank_table,
134 };
135
136 module_param_named(blank, blank_driver.enabled, int, S_IRUGO);
137 MODULE_PARM_DESC(blank, "Use 0 to disable, 1 to enable lcd console blanking");
138 /* End of file */