Import 2.3.18pre1
[davej-history.git] / drivers / sbus / char / uctrl.c
blobb11de29ebd0a61d3471947467dca07dbc38c69db
1 /* $Id: uctrl.c,v 1.2 1999/09/07 23:11:08 shadow Exp $
2 * uctrl.c: TS102 Microcontroller interface on Tadpole Sparcbook 3
4 * Copyright 1999 Derrick J Brashear (shadow@dementia.org)
5 */
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/errno.h>
11 #include <linux/delay.h>
12 #include <linux/interrupt.h>
13 #include <linux/malloc.h>
14 #include <linux/ioport.h>
15 #include <linux/init.h>
16 #include <linux/miscdevice.h>
17 #include <linux/mm.h>
19 #include <asm/openprom.h>
20 #include <asm/oplib.h>
21 #include <asm/system.h>
22 #include <asm/irq.h>
23 #include <asm/io.h>
24 #include <asm/pgtable.h>
25 #include <asm/sbus.h>
27 #define UCTRL_MINOR 174
29 struct uctrl_driver {
30 volatile u32 *regs;
31 int irq;
34 static struct uctrl_driver drv;
36 static loff_t
37 uctrl_llseek(struct file *file, loff_t offset, int type)
39 return -ESPIPE;
42 static int
43 uctrl_ioctl(struct inode *inode, struct file *file,
44 unsigned int cmd, unsigned long arg)
46 switch (cmd) {
47 default:
48 return -EINVAL;
50 return 0;
53 static int
54 uctrl_open(struct inode *inode, struct file *file)
56 MOD_INC_USE_COUNT;
57 return 0;
60 static int
61 uctrl_release(struct inode *inode, struct file *file)
63 MOD_DEC_USE_COUNT;
64 return 0;
67 void uctrl_interrupt(int irq, void *dev_id, struct pt_regs *regs)
69 struct uctrl_driver *driver = (struct uctrl_driver *)dev_id;
70 printk("in uctrl_interrupt\n");
73 static struct file_operations uctrl_fops = {
74 uctrl_llseek,
75 NULL, /* read */
76 NULL, /* write */
77 NULL, /* readdir */
78 NULL, /* poll */
79 uctrl_ioctl,
80 NULL, /* mmap */
81 uctrl_open,
82 NULL, /* flush */
83 uctrl_release
86 static struct miscdevice uctrl_dev = {
87 UCTRL_MINOR,
88 "uctrl",
89 &uctrl_fops
92 #ifdef MODULE
93 int init_module(void)
94 #else
95 __initfunc(int uctrl_init(void))
96 #endif
98 struct uctrl_driver *driver = &drv;
99 int len;
100 struct linux_prom_irqs tmp_irq[2];
101 unsigned int vaddr[2] = { 0, 0 };
102 int tmpnode, uctrlnode = prom_getchild(prom_root_node);
104 tmpnode = prom_searchsiblings(uctrlnode, "obio");
106 if (tmpnode)
107 uctrlnode = prom_getchild(tmpnode);
109 uctrlnode = prom_searchsiblings(uctrlnode, "uctrl");
111 if (!uctrlnode)
112 return -ENODEV;
114 /* the prom mapped it for us */
115 len = prom_getproperty(uctrlnode, "address", (void *) vaddr,
116 sizeof(vaddr));
117 driver->regs = vaddr[0];
119 len = prom_getproperty(uctrlnode, "intr", (char *) tmp_irq,
120 sizeof(tmp_irq));
121 if(!driver->irq)
122 driver->irq = tmp_irq[0].pri;
124 request_irq(driver->irq, uctrl_interrupt, 0,
125 "uctrl", driver);
127 enable_irq(driver->irq);
129 if (misc_register(&uctrl_dev)) {
130 printk("%s: unable to get misc minor %d\n",
131 __FUNCTION__, uctrl_dev.minor);
132 disable_irq(driver->irq);
133 free_irq(driver->irq, driver);
134 return -ENODEV;
137 printk(KERN_INFO, "uctrl: 0x%x (irq %d)\n", driver->regs, __irq_itoa(driver->irq));
138 return 0;
142 #ifdef MODULE
143 void cleanup_module(void)
145 struct uctrl_driver *driver = &drv;
147 misc_deregister(&uctrl_dev);
148 if (driver->irq) {
149 disable_irq(driver->irq);
150 free_irq(driver->irq, driver);
152 if (driver->regs)
153 driver->regs = 0;
155 #endif