Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * m68k beeper driver for Linux |
| 3 | * |
| 4 | * Copyright (c) 2002 Richard Zidlicky |
| 5 | * Copyright (c) 2002 Vojtech Pavlik |
| 6 | * Copyright (c) 1992 Orest Zborowski |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License version 2 as published by |
| 13 | * the Free Software Foundation |
| 14 | */ |
| 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/input.h> |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/machdep.h> |
| 22 | #include <asm/io.h> |
| 23 | |
| 24 | MODULE_AUTHOR("Richard Zidlicky <rz@linux-m68k.org>"); |
| 25 | MODULE_DESCRIPTION("m68k beeper driver"); |
| 26 | MODULE_LICENSE("GPL"); |
| 27 | |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 28 | static struct platform_device *m68kspkr_platform_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | static int m68kspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) |
| 31 | { |
| 32 | unsigned int count = 0; |
| 33 | |
| 34 | if (type != EV_SND) |
| 35 | return -1; |
| 36 | |
| 37 | switch (code) { |
| 38 | case SND_BELL: if (value) value = 1000; |
| 39 | case SND_TONE: break; |
| 40 | default: return -1; |
| 41 | } |
| 42 | |
| 43 | if (value > 20 && value < 32767) |
| 44 | count = 1193182 / value; |
| 45 | |
| 46 | mach_beep(count, -1); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 51 | static int __devinit m68kspkr_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 53 | struct input_dev *input_dev; |
| 54 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 56 | input_dev = input_allocate_device(); |
| 57 | if (!input_dev) |
Dmitry Torokhov | 76b7cddf | 2005-09-15 02:01:51 -0500 | [diff] [blame] | 58 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 60 | input_dev->name = "m68k beeper"; |
| 61 | input_dev->phys = "m68k/generic"; |
| 62 | input_dev->id.bustype = BUS_HOST; |
| 63 | input_dev->id.vendor = 0x001f; |
| 64 | input_dev->id.product = 0x0001; |
| 65 | input_dev->id.version = 0x0100; |
Dmitry Torokhov | 293e639 | 2007-04-12 01:35:32 -0400 | [diff] [blame] | 66 | input_dev->dev.parent = &dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 68 | input_dev->evbit[0] = BIT_MASK(EV_SND); |
| 69 | input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 70 | input_dev->event = m68kspkr_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 72 | err = input_register_device(input_dev); |
| 73 | if (err) { |
| 74 | input_free_device(input_dev); |
| 75 | return err; |
| 76 | } |
| 77 | |
| 78 | platform_set_drvdata(dev, input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 83 | static int __devexit m68kspkr_remove(struct platform_device *dev) |
| 84 | { |
| 85 | struct input_dev *input_dev = platform_get_drvdata(dev); |
| 86 | |
| 87 | input_unregister_device(input_dev); |
| 88 | platform_set_drvdata(dev, NULL); |
| 89 | /* turn off the speaker */ |
| 90 | m68kspkr_event(NULL, EV_SND, SND_BELL, 0); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static void m68kspkr_shutdown(struct platform_device *dev) |
| 96 | { |
| 97 | /* turn off the speaker */ |
| 98 | m68kspkr_event(NULL, EV_SND, SND_BELL, 0); |
| 99 | } |
| 100 | |
| 101 | static struct platform_driver m68kspkr_platform_driver = { |
| 102 | .driver = { |
| 103 | .name = "m68kspkr", |
| 104 | .owner = THIS_MODULE, |
| 105 | }, |
| 106 | .probe = m68kspkr_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame^] | 107 | .remove = m68kspkr_remove, |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 108 | .shutdown = m68kspkr_shutdown, |
| 109 | }; |
| 110 | |
| 111 | static int __init m68kspkr_init(void) |
| 112 | { |
| 113 | int err; |
| 114 | |
| 115 | if (!mach_beep) { |
| 116 | printk(KERN_INFO "m68kspkr: no lowlevel beep support\n"); |
| 117 | return -ENODEV; |
| 118 | } |
| 119 | |
| 120 | err = platform_driver_register(&m68kspkr_platform_driver); |
| 121 | if (err) |
| 122 | return err; |
| 123 | |
| 124 | m68kspkr_platform_device = platform_device_alloc("m68kspkr", -1); |
| 125 | if (!m68kspkr_platform_device) { |
| 126 | err = -ENOMEM; |
| 127 | goto err_unregister_driver; |
| 128 | } |
| 129 | |
| 130 | err = platform_device_add(m68kspkr_platform_device); |
| 131 | if (err) |
| 132 | goto err_free_device; |
| 133 | |
| 134 | return 0; |
| 135 | |
| 136 | err_free_device: |
| 137 | platform_device_put(m68kspkr_platform_device); |
| 138 | err_unregister_driver: |
| 139 | platform_driver_unregister(&m68kspkr_platform_driver); |
| 140 | |
| 141 | return err; |
| 142 | } |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static void __exit m68kspkr_exit(void) |
| 145 | { |
Dmitry Torokhov | 1f75e6b | 2005-12-21 00:52:29 -0500 | [diff] [blame] | 146 | platform_device_unregister(m68kspkr_platform_device); |
| 147 | platform_driver_unregister(&m68kspkr_platform_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | module_init(m68kspkr_init); |
| 151 | module_exit(m68kspkr_exit); |