aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sbus
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2008-08-29 21:01:58 -0400
committerDavid S. Miller <davem@davemloft.net>2008-08-29 21:01:58 -0400
commit95d4390579e02e168a14f19506fbadd30daffced (patch)
tree48043296d43fa54d02a0af9fe29bd5d2faca2f65 /drivers/sbus
parent0e52fe8c01e7945881aac6aeb7c96af3f59976a8 (diff)
display7seg: Convert to pure OF device driver.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/sbus')
-rw-r--r--drivers/sbus/char/display7seg.c251
1 files changed, 146 insertions, 105 deletions
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index d8f5c0ca236d..2f16d78e92d7 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -1,10 +1,7 @@
1/* $Id: display7seg.c,v 1.6 2002/01/08 16:00:16 davem Exp $ 1/* display7seg.c - Driver implementation for the 7-segment display
2 * 2 * present on Sun Microsystems CP1400 and CP1500
3 * display7seg - Driver implementation for the 7-segment display
4 * present on Sun Microsystems CP1400 and CP1500
5 * 3 *
6 * Copyright (c) 2000 Eric Brower (ebrower@usa.net) 4 * Copyright (c) 2000 Eric Brower (ebrower@usa.net)
7 *
8 */ 5 */
9 6
10#include <linux/kernel.h> 7#include <linux/kernel.h>
@@ -16,22 +13,20 @@
16#include <linux/miscdevice.h> 13#include <linux/miscdevice.h>
17#include <linux/ioport.h> /* request_region */ 14#include <linux/ioport.h> /* request_region */
18#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
16#include <linux/of.h>
17#include <linux/of_device.h>
19#include <asm/atomic.h> 18#include <asm/atomic.h>
20#include <asm/ebus.h> /* EBus device */
21#include <asm/oplib.h> /* OpenProm Library */
22#include <asm/uaccess.h> /* put_/get_user */ 19#include <asm/uaccess.h> /* put_/get_user */
23#include <asm/io.h> 20#include <asm/io.h>
24 21
25#include <asm/display7seg.h> 22#include <asm/display7seg.h>
26 23
27#define D7S_MINOR 193 24#define D7S_MINOR 193
28#define D7S_OBPNAME "display7seg" 25#define DRIVER_NAME "d7s"
29#define D7S_DEVNAME "d7s" 26#define PFX DRIVER_NAME ": "
30 27
31static int sol_compat = 0; /* Solaris compatibility mode */ 28static int sol_compat = 0; /* Solaris compatibility mode */
32 29
33#ifdef MODULE
34
35/* Solaris compatibility flag - 30/* Solaris compatibility flag -
36 * The Solaris implementation omits support for several 31 * The Solaris implementation omits support for several
37 * documented driver features (ref Sun doc 806-0180-03). 32 * documented driver features (ref Sun doc 806-0180-03).
@@ -46,20 +41,20 @@ static int sol_compat = 0; /* Solaris compatibility mode */
46 * If you wish the device to operate as under Solaris, 41 * If you wish the device to operate as under Solaris,
47 * omitting above features, set this parameter to non-zero. 42 * omitting above features, set this parameter to non-zero.
48 */ 43 */
49module_param 44module_param(sol_compat, int, 0);
50 (sol_compat, int, 0); 45MODULE_PARM_DESC(sol_compat,
51MODULE_PARM_DESC 46 "Disables documented functionality omitted from Solaris driver");
52 (sol_compat, 47
53 "Disables documented functionality omitted from Solaris driver"); 48MODULE_AUTHOR("Eric Brower <ebrower@usa.net>");
54 49MODULE_DESCRIPTION("7-Segment Display driver for Sun Microsystems CP1400/1500");
55MODULE_AUTHOR
56 ("Eric Brower <ebrower@usa.net>");
57MODULE_DESCRIPTION
58 ("7-Segment Display driver for Sun Microsystems CP1400/1500");
59MODULE_LICENSE("GPL"); 50MODULE_LICENSE("GPL");
60MODULE_SUPPORTED_DEVICE 51MODULE_SUPPORTED_DEVICE("d7s");
61 ("d7s"); 52
62#endif /* ifdef MODULE */ 53struct d7s {
54 void __iomem *regs;
55 bool flipped;
56};
57struct d7s *d7s_device;
63 58
64/* 59/*
65 * Register block address- see header for details 60 * Register block address- see header for details
@@ -72,22 +67,6 @@ MODULE_SUPPORTED_DEVICE
72 * FLIP - Inverts display for upside-down mounted board 67 * FLIP - Inverts display for upside-down mounted board
73 * bits 0-4 - 7-segment display contents 68 * bits 0-4 - 7-segment display contents
74 */ 69 */
75static void __iomem* d7s_regs;
76
77static inline void d7s_free(void)
78{
79 iounmap(d7s_regs);
80}
81
82static inline int d7s_obpflipped(void)
83{
84 int opt_node;
85
86 opt_node = prom_getchild(prom_root_node);
87 opt_node = prom_searchsiblings(opt_node, "options");
88 return ((-1 != prom_getintdefault(opt_node, "d7s-flipped?", -1)) ? 0 : 1);
89}
90
91static atomic_t d7s_users = ATOMIC_INIT(0); 70static atomic_t d7s_users = ATOMIC_INIT(0);
92 71
93static int d7s_open(struct inode *inode, struct file *f) 72static int d7s_open(struct inode *inode, struct file *f)
@@ -106,12 +85,15 @@ static int d7s_release(struct inode *inode, struct file *f)
106 * are not operating in solaris-compat mode 85 * are not operating in solaris-compat mode
107 */ 86 */
108 if (atomic_dec_and_test(&d7s_users) && !sol_compat) { 87 if (atomic_dec_and_test(&d7s_users) && !sol_compat) {
109 int regval = 0; 88 struct d7s *p = d7s_device;
110 89 u8 regval = 0;
111 regval = readb(d7s_regs); 90
112 (0 == d7s_obpflipped()) ? 91 regval = readb(p->regs);
113 writeb(regval |= D7S_FLIP, d7s_regs): 92 if (p->flipped)
114 writeb(regval &= ~D7S_FLIP, d7s_regs); 93 regval |= D7S_FLIP;
94 else
95 regval &= ~D7S_FLIP;
96 writeb(regval, p->regs);
115 } 97 }
116 98
117 return 0; 99 return 0;
@@ -119,9 +101,10 @@ static int d7s_release(struct inode *inode, struct file *f)
119 101
120static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 102static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
121{ 103{
122 __u8 regs = readb(d7s_regs); 104 struct d7s *p = d7s_device;
123 __u8 ireg = 0; 105 u8 regs = readb(p->regs);
124 int error = 0; 106 int error = 0;
107 u8 ireg = 0;
125 108
126 if (D7S_MINOR != iminor(file->f_path.dentry->d_inode)) 109 if (D7S_MINOR != iminor(file->f_path.dentry->d_inode))
127 return -ENODEV; 110 return -ENODEV;
@@ -129,18 +112,20 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
129 lock_kernel(); 112 lock_kernel();
130 switch (cmd) { 113 switch (cmd) {
131 case D7SIOCWR: 114 case D7SIOCWR:
132 /* assign device register values 115 /* assign device register values we mask-out D7S_FLIP
133 * we mask-out D7S_FLIP if in sol_compat mode 116 * if in sol_compat mode
134 */ 117 */
135 if (get_user(ireg, (int __user *) arg)) { 118 if (get_user(ireg, (int __user *) arg)) {
136 error = -EFAULT; 119 error = -EFAULT;
137 break; 120 break;
138 } 121 }
139 if (0 != sol_compat) { 122 if (sol_compat) {
140 (regs & D7S_FLIP) ? 123 if (regs & D7S_FLIP)
141 (ireg |= D7S_FLIP) : (ireg &= ~D7S_FLIP); 124 ireg |= D7S_FLIP;
125 else
126 ireg &= ~D7S_FLIP;
142 } 127 }
143 writeb(ireg, d7s_regs); 128 writeb(ireg, p->regs);
144 break; 129 break;
145 130
146 case D7SIOCRD: 131 case D7SIOCRD:
@@ -158,9 +143,11 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
158 143
159 case D7SIOCTM: 144 case D7SIOCTM:
160 /* toggle device mode-- flip display orientation */ 145 /* toggle device mode-- flip display orientation */
161 (regs & D7S_FLIP) ? 146 if (regs & D7S_FLIP)
162 (regs &= ~D7S_FLIP) : (regs |= D7S_FLIP); 147 regs &= ~D7S_FLIP;
163 writeb(regs, d7s_regs); 148 else
149 regs |= D7S_FLIP;
150 writeb(regs, p->regs);
164 break; 151 break;
165 }; 152 };
166 unlock_kernel(); 153 unlock_kernel();
@@ -176,69 +163,123 @@ static const struct file_operations d7s_fops = {
176 .release = d7s_release, 163 .release = d7s_release,
177}; 164};
178 165
179static struct miscdevice d7s_miscdev = { D7S_MINOR, D7S_DEVNAME, &d7s_fops }; 166static struct miscdevice d7s_miscdev = {
167 .minor = D7S_MINOR,
168 .name = DRIVER_NAME,
169 .fops = &d7s_fops
170};
180 171
181static int __init d7s_init(void) 172static int __devinit d7s_probe(struct of_device *op,
173 const struct of_device_id *match)
182{ 174{
183 struct linux_ebus *ebus = NULL; 175 struct device_node *opts;
184 struct linux_ebus_device *edev = NULL; 176 int err = -EINVAL;
185 int iTmp = 0, regs = 0; 177 struct d7s *p;
186 178 u8 regs;
187 for_each_ebus(ebus) { 179
188 for_each_ebusdev(edev, ebus) { 180 if (d7s_device)
189 if (!strcmp(edev->prom_node->name, D7S_OBPNAME)) 181 goto out;
190 goto ebus_done; 182
191 } 183 p = kzalloc(sizeof(*p), GFP_KERNEL);
184 err = -ENOMEM;
185 if (!p)
186 goto out;
187
188 p->regs = of_ioremap(&op->resource[0], 0, sizeof(u8), "d7s");
189 if (!p->regs) {
190 printk(KERN_ERR PFX "Cannot map chip registers\n");
191 goto out_free;
192 } 192 }
193 193
194ebus_done: 194 err = misc_register(&d7s_miscdev);
195 if(!edev) { 195 if (err) {
196 printk("%s: unable to locate device\n", D7S_DEVNAME); 196 printk(KERN_ERR PFX "Unable to acquire miscdevice minor %i\n",
197 return -ENODEV; 197 D7S_MINOR);
198 goto out_iounmap;
198 } 199 }
199 200
200 d7s_regs = ioremap(edev->resource[0].start, sizeof(__u8)); 201 /* OBP option "d7s-flipped?" is honored as default for the
201 202 * device, and reset default when detached
202 iTmp = misc_register(&d7s_miscdev);
203 if (0 != iTmp) {
204 printk("%s: unable to acquire miscdevice minor %i\n",
205 D7S_DEVNAME, D7S_MINOR);
206 iounmap(d7s_regs);
207 return iTmp;
208 }
209
210 /* OBP option "d7s-flipped?" is honored as default
211 * for the device, and reset default when detached
212 */ 203 */
213 regs = readb(d7s_regs); 204 regs = readb(p->regs);
214 iTmp = d7s_obpflipped(); 205 opts = of_find_node_by_path("/options");
215 (0 == iTmp) ? 206 if (opts &&
216 writeb(regs |= D7S_FLIP, d7s_regs): 207 of_get_property(opts, "d7s-flipped?", NULL))
217 writeb(regs &= ~D7S_FLIP, d7s_regs); 208 p->flipped = true;
218 209
219 printk("%s: 7-Segment Display%s at 0x%lx %s\n", 210 if (p->flipped)
220 D7S_DEVNAME, 211 regs |= D7S_FLIP;
221 (0 == iTmp) ? (" (FLIPPED)") : (""), 212 else
222 edev->resource[0].start, 213 regs &= ~D7S_FLIP;
223 (0 != sol_compat) ? ("in sol_compat mode") : ("")); 214
224 215 writeb(regs, p->regs);
225 return 0; 216
217 printk(KERN_INFO PFX "7-Segment Display%s at [%s:0x%lx] %s\n",
218 op->node->full_name,
219 (regs & D7S_FLIP) ? " (FLIPPED)" : "",
220 op->resource[0].start,
221 sol_compat ? "in sol_compat mode" : "");
222
223 dev_set_drvdata(&op->dev, p);
224 d7s_device = p;
225 err = 0;
226
227out:
228 return err;
229
230out_iounmap:
231 of_iounmap(&op->resource[0], p->regs, sizeof(u8));
232
233out_free:
234 kfree(p);
235 goto out;
226} 236}
227 237
228static void __exit d7s_cleanup(void) 238static int __devexit d7s_remove(struct of_device *op)
229{ 239{
230 int regs = readb(d7s_regs); 240 struct d7s *p = dev_get_drvdata(&op->dev);
241 u8 regs = readb(p->regs);
231 242
232 /* Honor OBP d7s-flipped? unless operating in solaris-compat mode */ 243 /* Honor OBP d7s-flipped? unless operating in solaris-compat mode */
233 if (0 == sol_compat) { 244 if (sol_compat) {
234 (0 == d7s_obpflipped()) ? 245 if (p->flipped)
235 writeb(regs |= D7S_FLIP, d7s_regs): 246 regs |= D7S_FLIP;
236 writeb(regs &= ~D7S_FLIP, d7s_regs); 247 else
248 regs &= ~D7S_FLIP;
249 writeb(regs, p->regs);
237 } 250 }
238 251
239 misc_deregister(&d7s_miscdev); 252 misc_deregister(&d7s_miscdev);
240 d7s_free(); 253 of_iounmap(&op->resource[0], p->regs, sizeof(u8));
254 kfree(p);
255
256 return 0;
257}
258
259static struct of_device_id d7s_match[] = {
260 {
261 .name = "display7seg",
262 },
263 {},
264};
265MODULE_DEVICE_TABLE(of, d7s_match);
266
267static struct of_platform_driver d7s_driver = {
268 .name = DRIVER_NAME,
269 .match_table = d7s_match,
270 .probe = d7s_probe,
271 .remove = __devexit_p(d7s_remove),
272};
273
274static int __init d7s_init(void)
275{
276 return of_register_driver(&d7s_driver, &of_bus_type);
277}
278
279static void __exit d7s_exit(void)
280{
281 of_unregister_driver(&d7s_driver);
241} 282}
242 283
243module_init(d7s_init); 284module_init(d7s_init);
244module_exit(d7s_cleanup); 285module_exit(d7s_exit);