2 * PC Speaker beeper driver for Linux
4 * Copyright (c) 2002 Vojtech Pavlik
5 * Copyright (c) 1992 Orest Zborowski
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation
15 #include <linux/init.h>
16 #include <linux/input.h>
20 static void pcspkr_do_sound(unsigned int count)
24 spin_lock_irqsave(&i8253_lock, flags);
27 /* enable counter 2 */
28 outb_p(inb_p(0x61) | 3, 0x61);
29 /* set command for counter 2, 2 byte write */
31 /* select desired HZ */
32 outb_p(count & 0xff, 0x42);
33 outb((count >> 8) & 0xff, 0x42);
35 /* disable counter 2 */
36 outb(inb_p(0x61) & 0xFC, 0x61);
39 spin_unlock_irqrestore(&i8253_lock, flags);
42 void pcspkr_stop_sound(void)
47 static int pcspkr_input_event(struct input_dev *dev, unsigned int type,
48 unsigned int code, int value)
50 unsigned int count = 0;
52 if (atomic_read(&pcsp_chip.timer_active) || !pcsp_chip.pcspkr)
72 if (value > 20 && value < 32767)
73 count = PIT_TICK_RATE / value;
75 pcspkr_do_sound(count);
80 int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev)
84 struct input_dev *input_dev = input_allocate_device();
88 input_dev->name = "PC Speaker";
89 input_dev->phys = "isa0061/input0";
90 input_dev->id.bustype = BUS_ISA;
91 input_dev->id.vendor = 0x001f;
92 input_dev->id.product = 0x0001;
93 input_dev->id.version = 0x0100;
94 input_dev->dev.parent = dev;
96 input_dev->evbit[0] = BIT(EV_SND);
97 input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
98 input_dev->event = pcspkr_input_event;
100 err = input_register_device(input_dev);
102 input_free_device(input_dev);
110 int pcspkr_input_remove(struct input_dev *dev)
113 input_unregister_device(dev); /* this also does kfree() */