OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [char/] [briq_panel.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * Drivers for the Total Impact PPC based computer "BRIQ"
3
 * by Dr. Karsten Jeppesen
4
 *
5
 *
6
 * 010407               Coding started
7
 *
8
 * 04/20/2002   1.1     Adapted to 2.4, small cleanups
9
 */
10
 
11
#include <linux/module.h>
12
 
13
#include <linux/types.h>
14
#include <linux/errno.h>
15
#include <linux/sched.h>
16
#include <linux/tty.h>
17
#include <linux/timer.h>
18
#include <linux/config.h>
19
#include <linux/kernel.h>
20
#include <linux/wait.h>
21
#include <linux/string.h>
22
#include <linux/malloc.h>
23
#include <linux/ioport.h>
24
#include <linux/delay.h>
25
#include <linux/miscdevice.h>
26
#include <linux/fs.h>
27
#include <linux/mm.h>
28
#include <linux/init.h>
29
 
30
#include <asm/uaccess.h>
31
#include <asm/io.h>
32
 
33
#define         TOTALIMPACT_VFD_MINOR   156
34
#define         VFD_IOPORT              0x0390
35
#define         LED_IOPORT              0x0398
36
#define         TI_VER                  "1.1 (04/20/2002)"
37
#define         TI_MSG0                 "Loading Linux"
38
 
39
static int              vfd_is_open;
40
static unsigned char    vfd[40];
41
static int              vfd_cursor;
42
static unsigned char    ledpb, led;
43
 
44
 
45
static void UpdateVFD( void )
46
{
47
        int     i;
48
        outb(0x02, VFD_IOPORT); /* cursor home */
49
        for (i=0; i<20; i++) outb(vfd[i], VFD_IOPORT + 1);
50
        outb(0xc0, VFD_IOPORT); /* cursor to next line */
51
        for (i=20; i<40; i++) outb(vfd[i], VFD_IOPORT + 1);
52
 
53
}
54
 
55
static void SetLED( char state)
56
{
57
        if ( state == 'R' ) led = 0x01;
58
        else if ( state == 'G' ) led = 0x02;
59
        else if ( state == 'Y' ) led = 0x03;
60
        else if ( state == 'X' ) led = 0x00;
61
        outb(led, LED_IOPORT);
62
}
63
 
64
static int do_open(struct inode *ino, struct file *filep)
65
{
66
        if (vfd_is_open) return -EBUSY;
67
        MOD_INC_USE_COUNT;
68
        vfd_is_open = 1;
69
        return(0);
70
}
71
 
72
static int do_release(struct inode *ino, struct file *filep)
73
{
74
        if (!vfd_is_open) return -ENODEV;
75
        MOD_DEC_USE_COUNT;
76
        vfd_is_open = 0;
77
        return(0);
78
}
79
 
80
 
81
static ssize_t do_read(struct file *file, char *buf, size_t count,
82
                         loff_t *ppos)
83
{
84
        unsigned short c;
85
        unsigned char cp;
86
 
87
        /*  Can't seek (pread) on this device  */
88
        if (ppos != &file->f_pos) return -ESPIPE;
89
        if (!vfd_is_open) return -ENODEV;
90
        c = (inb( LED_IOPORT ) & 0x000c) | (ledpb & 0x0003);
91
        SetLED(' ');
92
        if ((!(ledpb & 0x0004)) && (c & 0x0004))
93
        {       /* upper button released */
94
                cp = ' ';
95
                ledpb = c;
96
                if (copy_to_user(buf, &cp, 1)) return -EFAULT;
97
                return(1);
98
        }
99
        else if ((!(ledpb & 0x0008)) && (c & 0x0008))
100
        {       /* lower button released */
101
                cp = '\r';
102
                ledpb = c;
103
                if (copy_to_user(buf, &cp, 1)) return -EFAULT;
104
                return(1);
105
        } else
106
        {
107
                ledpb = c;
108
                return(0);
109
        }
110
}
111
 
112
 
113
static void ScrollVFD( void )
114
{
115
        int     i;
116
        for (i=0; i<20; i++)
117
        {
118
                vfd[i] = vfd[i+20];
119
                vfd[i+20] = ' ';
120
        }
121
        vfd_cursor = 20;
122
}
123
 
124
 
125
static ssize_t do_write(struct file *file, const char *buf, size_t len,
126
                          loff_t *ppos)
127
{
128
        size_t          indx = len;
129
        int             i, esc=0;
130
        /*  Can't seek (pwrite) on this device  */
131
        if (ppos != &file->f_pos) return -ESPIPE;
132
        if (!vfd_is_open) return -EBUSY;
133
        for (;;)
134
        {
135
                if (!indx) break;
136
                if (esc)
137
                {
138
                        SetLED(*buf);
139
                        esc = 0;
140
                }
141
                else if (*buf == 27)
142
                {
143
                        esc = 1;
144
                }
145
                else if (*buf == 12)
146
                { /* do a form feed */
147
                        for (i=0; i<40; i++) vfd[i] = ' ';
148
                        vfd_cursor = 0;
149
                }
150
                else if (*buf == 10)
151
                {
152
                        if (vfd_cursor < 20) vfd_cursor = 20;
153
                        else if (vfd_cursor < 40) vfd_cursor = 40;
154
                        else if (vfd_cursor < 60) vfd_cursor = 60;
155
                        if (vfd_cursor > 59) ScrollVFD();
156
                }
157
                else
158
                {
159
                        /* just a character */
160
                        if (vfd_cursor > 39) ScrollVFD();
161
                        vfd[vfd_cursor++] = *buf;
162
                }
163
                indx--;
164
                buf++;
165
        }
166
        UpdateVFD();
167
        return len;
168
}
169
 
170
 
171
static struct file_operations vfd_fops = {
172
        read:           do_read,        /* Read */
173
        write:          do_write,       /* Write */
174
        open:           do_open,        /* Open */
175
        release:        do_release,     /* Release */
176
};
177
 
178
 
179
static struct miscdevice ti_vfd_miscdev = {
180
        TOTALIMPACT_VFD_MINOR,
181
        "vfd",
182
        &vfd_fops
183
};
184
 
185
 
186
static int __init briq_panel_init(void)
187
{
188
        struct device_node *root = find_path_device("/");
189
        char *machine;
190
        int i;
191
 
192
        machine = get_property(root, "model", NULL);
193
        if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0)
194
                return -ENODEV;
195
 
196
        printk(KERN_INFO "ti_briq: v%s Dr. Karsten Jeppesen (kj@totalimpact.com)\n", TI_VER);
197
 
198
        if (!request_region( VFD_IOPORT, 4, "BRIQ Front Panel"))
199
                return -EBUSY;
200
        if (!request_region( LED_IOPORT, 2, "BRIQ Front Panel")) {
201
                release_region(VFD_IOPORT, 4);
202
                return -EBUSY;
203
        }
204
        ledpb = inb( LED_IOPORT ) & 0x000c;
205
 
206
        if (misc_register(&ti_vfd_miscdev) < 0) {
207
                release_region(VFD_IOPORT, 4);
208
                release_region(LED_IOPORT, 2);
209
                return -EBUSY;
210
        }
211
 
212
        outb(0x38, VFD_IOPORT); /* Function set */
213
        outb(0x01, VFD_IOPORT); /* Clear display */
214
        outb(0x0c, VFD_IOPORT); /* Display on */
215
        outb(0x06, VFD_IOPORT); /* Entry normal */
216
        for (i=0; i<40; i++) vfd[i]=' ';
217
#ifndef MODULE
218
        vfd[0] = 'L';
219
        vfd[1] = 'o';
220
        vfd[2] = 'a';
221
        vfd[3] = 'd';
222
        vfd[4] = 'i';
223
        vfd[5] = 'n';
224
        vfd[6] = 'g';
225
        vfd[7] = ' ';
226
        vfd[8] = '.';
227
        vfd[9] = '.';
228
        vfd[10] = '.';
229
#endif /* !MODULE */    
230
        UpdateVFD();
231
 
232
        return 0;
233
}
234
 
235
 
236
static void __exit briq_panel_exit(void)
237
{
238
        misc_deregister(&ti_vfd_miscdev);
239
        release_region(VFD_IOPORT, 4);
240
        release_region(LED_IOPORT, 2);
241
}
242
 
243
 
244
module_init(briq_panel_init);
245
module_exit(briq_panel_exit);
246
 
247
 
248
MODULE_LICENSE("GPL");
249
MODULE_AUTHOR("Karsten Jeppesen <karsten@jeppesens.com>");
250
MODULE_DESCRIPTION("Driver for the Total Impact briQ front panel");
251
EXPORT_NO_SYMBOLS;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.