MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / arch / nios2nommu / kernel / pio.c
blob013a64b9f3b4fc498e7827099be4a59dcfa4cc1f
1 /*
2 * linux/arch/nios2nommu/kernel/pio.c
3 * "Example" drivers(LEDs and 7 seg displays) of the PIO interface
4 * on Nios Development Kit.
6 * Copyright (C) 2004 Microtronix Datacom Ltd
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 * Written by Wentao Xu <wentao@microtronix.com>
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/delay.h>
20 #include <linux/timer.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/ioport.h>
24 #include <asm/io.h>
26 MODULE_AUTHOR("Microtronix Datacom Ltd.");
27 MODULE_DESCRIPTION("Drivers of PIO devices (LEDs and 7 seg) on Nios kit");
28 MODULE_LICENSE("GPL");
30 #undef CONFIG_PIO_SEG
31 #ifdef na_seven_seg_pio
32 #define CONFIG_PIO_SEG
33 #define PIO_SEG_IO na_seven_seg_pio
34 #endif
36 #undef CONFIG_PIO_LED
37 #ifdef na_led_pio
38 #define CONFIG_PIO_LED
39 #define PIO_LED_IO na_led_pio
40 #endif
42 #define PDEBUG printk
44 /* routines for 7-segment hex display */
45 #ifdef CONFIG_PIO_SEG
46 static unsigned char _hex_digits_data[] = {
47 0x01, 0x4f, 0x12, 0x06, 0x4c, /* 0-4 */
48 0x24, 0x20, 0x0f, 0x00, 0x04, /* 5-9 */
49 0x08, 0x60, 0x72, 0x42, 0x30, /* a-e */
50 0x38 /* f */
53 void pio_seg_write(int value)
55 int led_value;
57 /* Left Hand Digit, goes to PIO bits 8-14 */
58 led_value = _hex_digits_data[value & 0xF];
59 led_value |= (_hex_digits_data[(value >> 4) & 0xF]) << 8;
61 outl(led_value, &(PIO_SEG_IO->np_piodata));
64 static void __init pio_seg_init(void)
66 pio_seg_write(0);
68 #endif
71 /* routines for LED display */
72 #ifdef CONFIG_PIO_LED
73 void pio_led_write(int value)
75 np_pio *pio=(np_pio *)(PIO_LED_IO);
77 //outl(-1, &pio->np_piodirection);
78 outl(value, &pio->np_piodata);
81 static void __init pio_led_init(void)
83 np_pio *pio=(np_pio *)(PIO_LED_IO);
85 outl(-1, &pio->np_piodirection);
86 outl(0x0, &pio->np_piodata);
88 #endif
90 /* timing routines */
91 #if defined(CONFIG_PIO_SEG) || defined(CONFIG_PIO_LED)
92 static struct timer_list display_timer;
93 static int restart_timer=1;
94 static int timer_counter=0;
95 static void display_timeout(unsigned long unused)
97 #ifdef CONFIG_PIO_SEG
98 pio_seg_write(++timer_counter);
99 #endif
101 #ifdef CONFIG_PIO_LED
102 pio_led_write(timer_counter);
103 #endif
104 if (restart_timer) {
105 display_timer.expires = jiffies + HZ; /* one second */
106 add_timer(&display_timer);
109 #endif
111 int __init pio_init(void)
113 #ifdef CONFIG_PIO_SEG
114 request_mem_region((unsigned long)PIO_SEG_IO, sizeof(np_pio), "pio_7seg");
115 pio_seg_init();
116 #endif
118 #ifdef CONFIG_PIO_LED
119 request_mem_region((unsigned long)PIO_LED_IO, sizeof(np_pio), "pio_led");
120 pio_led_init();
121 #endif
123 #if defined(CONFIG_PIO_SEG) || defined(CONFIG_PIO_LED)
124 /* init timer */
125 init_timer(&display_timer);
126 display_timer.function = display_timeout;
127 display_timer.data = 0;
128 display_timer.expires = jiffies + HZ * 10; /* 10 seconds */
129 add_timer(&display_timer);
130 #endif
132 return 0;
135 static void __exit pio_exit(void)
137 #ifdef CONFIG_PIO_SEG
138 pio_seg_write(0);
139 release_mem_region((unsigned long)PIO_SEG_IO, sizeof(np_pio));
140 #endif
142 #ifdef CONFIG_PIO_LED
143 pio_led_write(0);
144 release_mem_region((unsigned long)PIO_LED_IO, sizeof(np_pio));
145 #endif
147 #if defined(CONFIG_PIO_SEG) || defined(CONFIG_PIO_LED)
148 restart_timer=0;
149 del_timer_sync(&display_timer);
150 #endif
152 module_init(pio_init);
153 module_exit(pio_exit);