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>
26 MODULE_AUTHOR("Microtronix Datacom Ltd.");
27 MODULE_DESCRIPTION("Drivers of PIO devices (LEDs and 7 seg) on Nios kit");
28 MODULE_LICENSE("GPL");
31 #ifdef na_seven_seg_pio
32 #define CONFIG_PIO_SEG
33 #define PIO_SEG_IO na_seven_seg_pio
38 #define CONFIG_PIO_LED
39 #define PIO_LED_IO na_led_pio
44 /* routines for 7-segment hex display */
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 */
53 void pio_seg_write(int 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)
71 /* routines for LED display */
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
);
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
)
98 pio_seg_write(++timer_counter
);
101 #ifdef CONFIG_PIO_LED
102 pio_led_write(timer_counter
);
105 display_timer
.expires
= jiffies
+ HZ
; /* one second */
106 add_timer(&display_timer
);
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");
118 #ifdef CONFIG_PIO_LED
119 request_mem_region((unsigned long)PIO_LED_IO
, sizeof(np_pio
), "pio_led");
123 #if defined(CONFIG_PIO_SEG) || defined(CONFIG_PIO_LED)
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
);
135 static void __exit
pio_exit(void)
137 #ifdef CONFIG_PIO_SEG
139 release_mem_region((unsigned long)PIO_SEG_IO
, sizeof(np_pio
));
142 #ifdef CONFIG_PIO_LED
144 release_mem_region((unsigned long)PIO_LED_IO
, sizeof(np_pio
));
147 #if defined(CONFIG_PIO_SEG) || defined(CONFIG_PIO_LED)
149 del_timer_sync(&display_timer
);
152 module_init(pio_init
);
153 module_exit(pio_exit
);