2 * LCD, LED and Button interface for Cobalt
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 1996, 1997 by Andrew Bose
10 * Linux kernel version history:
11 * March 2001: Ported from 2.0.34 by Liam Davies
14 #include <linux/types.h>
15 #include <linux/errno.h>
16 #include <linux/miscdevice.h>
17 #include <linux/slab.h>
18 #include <linux/ioport.h>
19 #include <linux/fcntl.h>
20 #include <linux/mc146818rtc.h>
21 #include <linux/netdevice.h>
22 #include <linux/sched.h>
23 #include <linux/smp_lock.h>
24 #include <linux/delay.h>
27 #include <asm/uaccess.h>
28 #include <asm/system.h>
32 static int lcd_ioctl(struct inode *inode, struct file *file,
33 unsigned int cmd, unsigned long arg);
35 static unsigned int lcd_present = 1;
37 /* used in arch/mips/cobalt/reset.c */
40 #if defined(CONFIG_TULIP) && 0
42 #define MAX_INTERFACES 8
43 static linkcheck_func_t linkcheck_callbacks[MAX_INTERFACES];
44 static void *linkcheck_cookies[MAX_INTERFACES];
46 int lcd_register_linkcheck_func(int iface_num, void *func, void *cookie)
49 iface_num >= MAX_INTERFACES ||
50 linkcheck_callbacks[iface_num] != NULL)
52 linkcheck_callbacks[iface_num] = (linkcheck_func_t) func;
53 linkcheck_cookies[iface_num] = cookie;
58 static int lcd_ioctl(struct inode *inode, struct file *file,
59 unsigned int cmd, unsigned long arg)
61 struct lcd_display button_display;
62 unsigned long address, a;
104 case LCD_Cursor_Right:
128 case LCD_Get_Cursor_Pos:{
129 struct lcd_display display;
133 display.cursor_address = (LCDReadInst);
134 display.cursor_address =
135 (display.cursor_address & 0x07F);
137 ((struct lcd_display *) arg, &display,
138 sizeof(struct lcd_display)))
145 case LCD_Set_Cursor_Pos:{
146 struct lcd_display display;
149 (&display, (struct lcd_display *) arg,
150 sizeof(struct lcd_display)))
153 a = (display.cursor_address | kLCD_Addr);
162 case LCD_Get_Cursor:{
163 struct lcd_display display;
167 display.character = LCDReadData;
170 ((struct lcd_display *) arg, &display,
171 sizeof(struct lcd_display)))
180 case LCD_Set_Cursor:{
181 struct lcd_display display;
184 (&display, (struct lcd_display *) arg,
185 sizeof(struct lcd_display)))
190 LCDWriteData(display.character);
218 struct lcd_display display;
223 (&display, (struct lcd_display *) arg,
224 sizeof(struct lcd_display)))
233 for (index = 0; index < (display.size1); index++) {
236 LCDWriteData(display.line1[index]);
245 for (index = 0; index < (display.size2); index++) {
248 LCDWriteData(display.line2[index]);
255 struct lcd_display display;
258 for (address = kDD_R00; address <= kDD_R01;
260 a = (address | kLCD_Addr);
267 display.line1[address] = LCDReadData;
270 display.line1[0x27] = '\0';
272 for (address = kDD_R10; address <= kDD_R11;
274 a = (address | kLCD_Addr);
282 display.line2[address - 0x40] =
286 display.line2[0x27] = '\0';
289 ((struct lcd_display *) arg, &display,
290 sizeof(struct lcd_display)))
295 // set all GPIO leds to led_display.leds
298 struct lcd_display led_display;
302 (&led_display, (struct lcd_display *) arg,
303 sizeof(struct lcd_display)))
306 led_state = led_display.leds;
313 // set only bit led_display.leds
318 struct lcd_display led_display;
322 (&led_display, (struct lcd_display *) arg,
323 sizeof(struct lcd_display)))
326 for (i = 0; i < (int) led_display.leds; i++) {
330 led_state = led_state | bit;
335 // clear only bit led_display.leds
340 struct lcd_display led_display;
344 (&led_display, (struct lcd_display *) arg,
345 sizeof(struct lcd_display)))
348 for (i = 0; i < (int) led_display.leds; i++) {
352 led_state = led_state & ~bit;
359 button_display.buttons = GPIRead;
361 ((struct lcd_display *) arg, &button_display,
362 sizeof(struct lcd_display)))
368 button_display.buttons =
369 *((volatile unsigned long *) (0xB0100060));
371 ((struct lcd_display *) arg, &button_display,
372 sizeof(struct lcd_display)))
380 /* panel-utils should pass in the desired interface status is wanted for
381 * in "buttons" of the structure. We will set this to non-zero if the
382 * link is in fact up for the requested interface. --DaveM
385 (&button_display, (struct lcd_display *) arg,
386 sizeof(button_display)))
388 iface_num = button_display.buttons;
389 #if defined(CONFIG_TULIP) && 0
390 if (iface_num >= 0 &&
391 iface_num < MAX_INTERFACES &&
392 linkcheck_callbacks[iface_num] != NULL) {
393 button_display.buttons =
394 linkcheck_callbacks[iface_num]
395 (linkcheck_cookies[iface_num]);
398 button_display.buttons = 0;
401 ((struct lcd_display *) arg, &button_display,
402 sizeof(struct lcd_display)))
416 static int lcd_open(struct inode *inode, struct file *file)
426 /* Only RESET or NEXT counts as button pressed */
428 static inline int button_pressed(void)
430 unsigned long buttons = GPIRead;
432 if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
433 || (buttons == BUTTON_Reset_B))
438 /* LED daemon sits on this and we wake him up once a key is pressed. */
440 static int lcd_waiters = 0;
442 static ssize_t lcd_read(struct file *file, char *buf,
443 size_t count, loff_t *ofs)
451 while (((buttons_now = (long) button_pressed()) == 0) &&
452 !(signal_pending(current))) {
453 msleep_interruptible(2000);
457 if (signal_pending(current))
463 * The various file operations we support.
466 static const struct file_operations lcd_fops = {
472 static struct miscdevice lcd_dev = {
478 static int lcd_init(void)
483 pr_info("%s\n", LCD_DRIVER);
484 ret = misc_register(&lcd_dev);
486 printk(KERN_WARNING LCD "Unable to register misc device.\n");
490 /* Check region? Naaah! Just snarf it up. */
491 /* request_region(RTC_PORT(0), RTC_IO_EXTENT, "lcd");*/
495 if ((data & 0x000000FF) == (0x00)) {
497 pr_info(LCD "LCD Not Present\n");
500 WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
501 WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
507 static void __exit lcd_exit(void)
509 misc_deregister(&lcd_dev);
512 module_init(lcd_init);
513 module_exit(lcd_exit);
515 MODULE_AUTHOR("Andrew Bose");
516 MODULE_LICENSE("GPL");