diff options
author | Jim Cromie <jim.cromie@gmail.com> | 2006-06-27 05:54:22 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-27 20:32:43 -0400 |
commit | 58b087cda1e9e46c7061c2282f92bd8e1970bfe7 (patch) | |
tree | cfc7e0df87fd0f27d3d0da04a3136d7104ab10a4 /drivers/char | |
parent | 681a3e7dab868a8c390724494e8b79dc596b9e0f (diff) |
[PATCH] chardev: GPIO for SCx200 & PC-8736x: add platform_device for use w dev_dbg
Adds platform-device to (just introduced) driver, and uses it to replace many
printks with dev_dbg() etc. This could trivially be merged into previous
patch, but this way matches better with the corresponding patch that does the
same change to scx200_gpio.
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/pc8736x_gpio.c | 102 |
1 files changed, 64 insertions, 38 deletions
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c index 83f24279f54e..b16fbef816c2 100644 --- a/drivers/char/pc8736x_gpio.c +++ b/drivers/char/pc8736x_gpio.c | |||
@@ -17,13 +17,14 @@ | |||
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/ioport.h> | 18 | #include <linux/ioport.h> |
19 | #include <linux/nsc_gpio.h> | 19 | #include <linux/nsc_gpio.h> |
20 | #include <linux/platform_device.h> | ||
20 | #include <asm/uaccess.h> | 21 | #include <asm/uaccess.h> |
21 | #include <asm/io.h> | 22 | #include <asm/io.h> |
22 | 23 | ||
23 | #define NAME "pc8736x_gpio" | 24 | #define DEVNAME "pc8736x_gpio" |
24 | 25 | ||
25 | MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); | 26 | MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>"); |
26 | MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver"); | 27 | MODULE_DESCRIPTION("NatSemi PC-8736x GPIO Pin Driver"); |
27 | MODULE_LICENSE("GPL"); | 28 | MODULE_LICENSE("GPL"); |
28 | 29 | ||
29 | static int major; /* default to dynamic major */ | 30 | static int major; /* default to dynamic major */ |
@@ -42,6 +43,8 @@ static unsigned pc8736x_gpio_base; | |||
42 | 43 | ||
43 | #define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ | 44 | #define SIO_CF1 0x21 /* chip config, bit0 is chip enable */ |
44 | 45 | ||
46 | #define PC8736X_GPIO_SIZE 16 | ||
47 | |||
45 | #define SIO_UNIT_SEL 0x7 /* unit select reg */ | 48 | #define SIO_UNIT_SEL 0x7 /* unit select reg */ |
46 | #define SIO_UNIT_ACT 0x30 /* unit enable */ | 49 | #define SIO_UNIT_ACT 0x30 /* unit enable */ |
47 | #define SIO_GPIO_UNIT 0x7 /* unit number of GPIO */ | 50 | #define SIO_GPIO_UNIT 0x7 /* unit number of GPIO */ |
@@ -69,6 +72,8 @@ static int port_offset[] = { 0, 4, 8, 10 }; /* non-uniform offsets ! */ | |||
69 | #define PORT_EVT_EN 2 | 72 | #define PORT_EVT_EN 2 |
70 | #define PORT_EVT_STST 3 | 73 | #define PORT_EVT_STST 3 |
71 | 74 | ||
75 | static struct platform_device *pdev; /* use in dev_*() */ | ||
76 | |||
72 | static inline void superio_outb(int addr, int val) | 77 | static inline void superio_outb(int addr, int val) |
73 | { | 78 | { |
74 | outb_p(addr, superio_cmd); | 79 | outb_p(addr, superio_cmd); |
@@ -148,9 +153,9 @@ static int pc8736x_gpio_get(unsigned minor) | |||
148 | val >>= bit; | 153 | val >>= bit; |
149 | val &= 1; | 154 | val &= 1; |
150 | 155 | ||
151 | printk(KERN_INFO NAME ": _gpio_get(%d from %x bit %d) == val %d\n", | 156 | dev_dbg(&pdev->dev, "_gpio_get(%d from %x bit %d) == val %d\n", |
152 | minor, pc8736x_gpio_base + port_offset[port] + PORT_IN, bit, | 157 | minor, pc8736x_gpio_base + port_offset[port] + PORT_IN, bit, |
153 | val); | 158 | val); |
154 | 159 | ||
155 | return val; | 160 | return val; |
156 | } | 161 | } |
@@ -164,22 +169,21 @@ static void pc8736x_gpio_set(unsigned minor, int val) | |||
164 | bit = minor & 7; | 169 | bit = minor & 7; |
165 | curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT); | 170 | curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT); |
166 | 171 | ||
167 | printk(KERN_INFO NAME | 172 | dev_dbg(&pdev->dev, "addr:%x cur:%x bit-pos:%d cur-bit:%x + new:%d -> bit-new:%d\n", |
168 | ": addr:%x cur:%x bit-pos:%d cur-bit:%x + new:%d -> bit-new:%d\n", | 173 | pc8736x_gpio_base + port_offset[port] + PORT_OUT, |
169 | pc8736x_gpio_base + port_offset[port] + PORT_OUT, | 174 | curval, bit, (curval & ~(1 << bit)), val, (val << bit)); |
170 | curval, bit, (curval & ~(1 << bit)), val, (val << bit)); | ||
171 | 175 | ||
172 | val = (curval & ~(1 << bit)) | (val << bit); | 176 | val = (curval & ~(1 << bit)) | (val << bit); |
173 | 177 | ||
174 | printk(KERN_INFO NAME ": gpio_set(minor:%d port:%d bit:%d" | 178 | dev_dbg(&pdev->dev, "gpio_set(minor:%d port:%d bit:%d)" |
175 | ") %2x -> %2x\n", minor, port, bit, curval, val); | 179 | " %2x -> %2x\n", minor, port, bit, curval, val); |
176 | 180 | ||
177 | outb_p(val, pc8736x_gpio_base + port_offset[port] + PORT_OUT); | 181 | outb_p(val, pc8736x_gpio_base + port_offset[port] + PORT_OUT); |
178 | 182 | ||
179 | curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT); | 183 | curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT); |
180 | val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN); | 184 | val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN); |
181 | 185 | ||
182 | printk(KERN_INFO NAME ": wrote %x, read: %x\n", curval, val); | 186 | dev_dbg(&pdev->dev, "wrote %x, read: %x\n", curval, val); |
183 | } | 187 | } |
184 | 188 | ||
185 | static void pc8736x_gpio_set_high(unsigned index) | 189 | static void pc8736x_gpio_set_high(unsigned index) |
@@ -194,7 +198,7 @@ static void pc8736x_gpio_set_low(unsigned index) | |||
194 | 198 | ||
195 | static int pc8736x_gpio_current(unsigned index) | 199 | static int pc8736x_gpio_current(unsigned index) |
196 | { | 200 | { |
197 | printk(KERN_WARNING NAME ": pc8736x_gpio_current unimplemented\n"); | 201 | dev_warn(&pdev->dev, "pc8736x_gpio_current unimplemented\n"); |
198 | return 0; | 202 | return 0; |
199 | } | 203 | } |
200 | 204 | ||
@@ -222,7 +226,7 @@ static int pc8736x_gpio_open(struct inode *inode, struct file *file) | |||
222 | unsigned m = iminor(inode); | 226 | unsigned m = iminor(inode); |
223 | file->private_data = &pc8736x_access; | 227 | file->private_data = &pc8736x_access; |
224 | 228 | ||
225 | printk(KERN_NOTICE NAME " open %d\n", m); | 229 | dev_dbg(&pdev->dev, "open %d\n", m); |
226 | 230 | ||
227 | if (m > 63) | 231 | if (m > 63) |
228 | return -EINVAL; | 232 | return -EINVAL; |
@@ -230,21 +234,31 @@ static int pc8736x_gpio_open(struct inode *inode, struct file *file) | |||
230 | } | 234 | } |
231 | 235 | ||
232 | static struct file_operations pc8736x_gpio_fops = { | 236 | static struct file_operations pc8736x_gpio_fops = { |
233 | .owner = THIS_MODULE, | 237 | .owner = THIS_MODULE, |
234 | .open = pc8736x_gpio_open, | 238 | .open = pc8736x_gpio_open, |
235 | .write = nsc_gpio_write, | 239 | .write = nsc_gpio_write, |
236 | .read = nsc_gpio_read, | 240 | .read = nsc_gpio_read, |
237 | }; | 241 | }; |
238 | 242 | ||
239 | static int __init pc8736x_gpio_init(void) | 243 | static int __init pc8736x_gpio_init(void) |
240 | { | 244 | { |
241 | int r, rc; | 245 | int rc = 0; |
246 | |||
247 | pdev = platform_device_alloc(DEVNAME, 0); | ||
248 | if (!pdev) | ||
249 | return -ENOMEM; | ||
242 | 250 | ||
243 | printk(KERN_DEBUG NAME " initializing\n"); | 251 | rc = platform_device_add(pdev); |
252 | if (rc) { | ||
253 | rc = -ENODEV; | ||
254 | goto undo_platform_dev_alloc; | ||
255 | } | ||
256 | dev_info(&pdev->dev, "NatSemi pc8736x GPIO Driver Initializing\n"); | ||
244 | 257 | ||
245 | if (!pc8736x_superio_present()) { | 258 | if (!pc8736x_superio_present()) { |
246 | printk(KERN_ERR NAME ": no device found\n"); | 259 | rc = -ENODEV; |
247 | return -ENODEV; | 260 | dev_err(&pdev->dev, "no device found\n"); |
261 | goto undo_platform_dev_add; | ||
248 | } | 262 | } |
249 | 263 | ||
250 | /* Verify that chip and it's GPIO unit are both enabled. | 264 | /* Verify that chip and it's GPIO unit are both enabled. |
@@ -252,44 +266,56 @@ static int __init pc8736x_gpio_init(void) | |||
252 | */ | 266 | */ |
253 | rc = superio_inb(SIO_CF1); | 267 | rc = superio_inb(SIO_CF1); |
254 | if (!(rc & 0x01)) { | 268 | if (!(rc & 0x01)) { |
255 | printk(KERN_ERR NAME ": device not enabled\n"); | 269 | rc = -ENODEV; |
256 | return -ENODEV; | 270 | dev_err(&pdev->dev, "device not enabled\n"); |
271 | goto undo_platform_dev_add; | ||
257 | } | 272 | } |
258 | device_select(SIO_GPIO_UNIT); | 273 | device_select(SIO_GPIO_UNIT); |
259 | if (!superio_inb(SIO_UNIT_ACT)) { | 274 | if (!superio_inb(SIO_UNIT_ACT)) { |
260 | printk(KERN_ERR NAME ": GPIO unit not enabled\n"); | 275 | rc = -ENODEV; |
261 | return -ENODEV; | 276 | dev_err(&pdev->dev, "GPIO unit not enabled\n"); |
277 | goto undo_platform_dev_add; | ||
262 | } | 278 | } |
263 | 279 | ||
264 | /* read GPIO unit base address */ | 280 | /* read the GPIO unit base addr that chip responds to */ |
265 | pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 | 281 | pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8 |
266 | | superio_inb(SIO_BASE_LADDR)); | 282 | | superio_inb(SIO_BASE_LADDR)); |
267 | 283 | ||
268 | if (request_region(pc8736x_gpio_base, 16, NAME)) | 284 | if (!request_region(pc8736x_gpio_base, 16, DEVNAME)) { |
269 | printk(KERN_INFO NAME ": GPIO ioport %x reserved\n", | 285 | rc = -ENODEV; |
270 | pc8736x_gpio_base); | 286 | dev_err(&pdev->dev, "GPIO ioport %x busy\n", |
287 | pc8736x_gpio_base); | ||
288 | goto undo_platform_dev_add; | ||
289 | } | ||
290 | dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base); | ||
271 | 291 | ||
272 | r = register_chrdev(major, NAME, &pc8736x_gpio_fops); | 292 | rc = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops); |
273 | if (r < 0) { | 293 | if (rc < 0) { |
274 | printk(KERN_ERR NAME ": unable to register character device\n"); | 294 | dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc); |
275 | return r; | 295 | goto undo_platform_dev_add; |
276 | } | 296 | } |
277 | if (!major) { | 297 | if (!major) { |
278 | major = r; | 298 | major = rc; |
279 | printk(KERN_DEBUG NAME ": got dynamic major %d\n", major); | 299 | dev_dbg(&pdev->dev, "got dynamic major %d\n", major); |
280 | } | 300 | } |
281 | 301 | ||
282 | pc8736x_init_shadow(); | 302 | pc8736x_init_shadow(); |
283 | return 0; | 303 | return 0; |
304 | |||
305 | undo_platform_dev_add: | ||
306 | platform_device_put(pdev); | ||
307 | undo_platform_dev_alloc: | ||
308 | kfree(pdev); | ||
309 | return rc; | ||
284 | } | 310 | } |
285 | 311 | ||
286 | static void __exit pc8736x_gpio_cleanup(void) | 312 | static void __exit pc8736x_gpio_cleanup(void) |
287 | { | 313 | { |
288 | printk(KERN_DEBUG NAME " cleanup\n"); | 314 | dev_dbg(&pdev->dev, " cleanup\n"); |
289 | 315 | ||
290 | release_region(pc8736x_gpio_base, 16); | 316 | release_region(pc8736x_gpio_base, 16); |
291 | 317 | ||
292 | unregister_chrdev(major, NAME); | 318 | unregister_chrdev(major, DEVNAME); |
293 | } | 319 | } |
294 | 320 | ||
295 | module_init(pc8736x_gpio_init); | 321 | module_init(pc8736x_gpio_init); |