1 /* $Id: display7seg.c,v 1.5 2001/10/08 22:19:51 davem Exp $
3 * display7seg - Driver implementation for the 7-segment display
4 * present on Sun Microsystems CP1400 and CP1500
6 * Copyright (c) 2000 Eric Brower (ebrower@usa.net)
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/version.h>
14 #include <linux/errno.h>
15 #include <linux/major.h>
16 #include <linux/init.h>
17 #include <linux/miscdevice.h>
18 #include <linux/ioport.h> /* request_region, check_region */
19 #include <asm/ebus.h> /* EBus device */
20 #include <asm/oplib.h> /* OpenProm Library */
21 #include <asm/uaccess.h> /* put_/get_user */
23 #include <asm/display7seg.h>
26 #define D7S_OBPNAME "display7seg"
27 #define D7S_DEVNAME "d7s"
29 static int sol_compat = 0; /* Solaris compatibility mode */
34 /* Solaris compatibility flag -
35 * The Solaris implementation omits support for several
36 * documented driver features (ref Sun doc 806-0180-03).
37 * By default, this module supports the documented driver
38 * abilities, rather than the Solaris implementation:
40 * 1) Device ALWAYS reverts to OBP-specified FLIPPED mode
41 * upon closure of device or module unload.
42 * 2) Device ioctls D7SIOCRD/D7SIOCWR honor toggling of
45 * If you wish the device to operate as under Solaris,
46 * omitting above features, set this parameter to non-zero.
52 "Disables documented functionality omitted from Solaris driver");
55 ("Eric Brower <ebrower@usa.net>");
57 ("7-Segment Display driver for Sun Microsystems CP1400/1500");
58 MODULE_LICENSE("GPL");
59 MODULE_SUPPORTED_DEVICE
61 #endif /* ifdef MODULE */
64 * Register block address- see header for details
65 * -----------------------------------------
66 * | DP | ALARM | FLIP | 4 | 3 | 2 | 1 | 0 |
67 * -----------------------------------------
69 * DP - Toggles decimal point on/off
70 * ALARM - Toggles "Alarm" LED green/red
71 * FLIP - Inverts display for upside-down mounted board
72 * bits 0-4 - 7-segment display contents
74 volatile u8* d7s_regs = 0;
76 static inline void d7s_free(void)
81 static inline int d7s_obpflipped(void)
85 opt_node = prom_getchild(prom_root_node);
86 opt_node = prom_searchsiblings(opt_node, "options");
87 return ((-1 != prom_getintdefault(opt_node, "d7s-flipped?", -1)) ? 0 : 1);
90 static int d7s_open(struct inode *inode, struct file *f)
92 if (D7S_MINOR != MINOR(inode->i_rdev))
99 static int d7s_release(struct inode *inode, struct file *f)
101 if (D7S_MINOR != MINOR(inode->i_rdev))
106 /* Reset flipped state to OBP default only if
107 * no other users have the device open and we
108 * are not operating in solaris-compat mode
110 if (0 == MOD_IN_USE && 0 == sol_compat) {
113 regval = readb(d7s_regs);
114 (0 == d7s_obpflipped()) ?
115 writeb(regval |= D7S_FLIP, d7s_regs):
116 writeb(regval &= ~D7S_FLIP, d7s_regs);
122 static int d7s_ioctl(struct inode *inode, struct file *f,
123 unsigned int cmd, unsigned long arg)
125 __u8 regs = readb(d7s_regs);
128 if (D7S_MINOR != MINOR(inode->i_rdev))
133 /* assign device register values
134 * we mask-out D7S_FLIP if in sol_compat mode
136 if (get_user(ireg, (int *) arg))
138 if (0 != sol_compat) {
140 (ireg |= D7S_FLIP) : (ireg &= ~D7S_FLIP);
142 writeb(ireg, d7s_regs);
146 /* retrieve device register values
147 * NOTE: Solaris implementation returns D7S_FLIP bit
148 * as toggled by user, even though it does not honor it.
149 * This driver will not misinform you about the state
150 * of your hardware while in sol_compat mode
152 if (put_user(regs, (int *) arg))
157 /* toggle device mode-- flip display orientation */
159 (regs &= ~D7S_FLIP) : (regs |= D7S_FLIP);
160 writeb(regs, d7s_regs);
167 static struct file_operations d7s_fops = {
171 release: d7s_release,
174 static struct miscdevice d7s_miscdev = { D7S_MINOR, D7S_DEVNAME, &d7s_fops };
176 static int __init d7s_init(void)
178 struct linux_ebus *ebus = NULL;
179 struct linux_ebus_device *edev = NULL;
180 int iTmp = 0, regs = 0;
182 for_each_ebus(ebus) {
183 for_each_ebusdev(edev, ebus) {
184 if (!strcmp(edev->prom_name, D7S_OBPNAME))
191 printk("%s: unable to locate device\n", D7S_DEVNAME);
195 d7s_regs = ioremap(edev->resource[0].start, sizeof(__u8));
197 iTmp = misc_register(&d7s_miscdev);
199 printk("%s: unable to acquire miscdevice minor %i\n",
200 D7S_DEVNAME, D7S_MINOR);
205 /* OBP option "d7s-flipped?" is honored as default
206 * for the device, and reset default when detached
208 regs = readb(d7s_regs);
209 iTmp = d7s_obpflipped();
211 writeb(regs |= D7S_FLIP, d7s_regs):
212 writeb(regs &= ~D7S_FLIP, d7s_regs);
214 printk("%s: 7-Segment Display%s at 0x%lx %s\n",
216 (0 == iTmp) ? (" (FLIPPED)") : (""),
217 edev->resource[0].start,
218 (0 != sol_compat) ? ("in sol_compat mode") : (""));
223 static void __exit d7s_cleanup(void)
225 int regs = readb(d7s_regs);
227 /* Honor OBP d7s-flipped? unless operating in solaris-compat mode */
228 if (0 == sol_compat) {
229 (0 == d7s_obpflipped()) ?
230 writeb(regs |= D7S_FLIP, d7s_regs):
231 writeb(regs &= ~D7S_FLIP, d7s_regs);
234 misc_deregister(&d7s_miscdev);
238 module_init(d7s_init);
239 module_exit(d7s_cleanup);