^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for PC-speaker like devices found on various Sparc systems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2002 Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2002, 2006, 2008 David S. Miller (davem@davemloft.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) MODULE_DESCRIPTION("Sparc Speaker beeper driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct grover_beep_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) void __iomem *freq_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) void __iomem *enable_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct bbc_beep_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u32 clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) void __iomem *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct sparcspkr_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct grover_beep_info grover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct bbc_beep_info bbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) } u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static u32 bbc_count_to_reg(struct bbc_beep_info *info, unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u32 val, clock_freq = info->clock_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (count <= clock_freq >> 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return 1 << 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (count >= clock_freq >> 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return 1 << 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) val = 1 << 18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) for (i = 19; i >= 11; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) val >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (count <= clock_freq >> i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static int bbc_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct bbc_beep_info *info = &state->u.bbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (type != EV_SND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) case SND_BELL: if (value) value = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) case SND_TONE: break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) default: return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (value > 20 && value < 32767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) count = 1193182 / value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) count = bbc_count_to_reg(info, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) spin_lock_irqsave(&state->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) sbus_writeb(0x01, info->regs + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sbus_writeb(0x00, info->regs + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) sbus_writeb((count >> 16) & 0xff, info->regs + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) sbus_writeb((count >> 8) & 0xff, info->regs + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sbus_writeb(0x00, info->regs + 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) sbus_writeb(0x00, info->regs + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) spin_unlock_irqrestore(&state->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int grover_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct sparcspkr_state *state = dev_get_drvdata(dev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct grover_beep_info *info = &state->u.grover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (type != EV_SND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) switch (code) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case SND_BELL: if (value) value = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) case SND_TONE: break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) default: return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (value > 20 && value < 32767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) count = 1193182 / value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) spin_lock_irqsave(&state->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /* enable counter 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) sbus_writeb(sbus_readb(info->enable_reg) | 3, info->enable_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* set command for counter 2, 2 byte write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) sbus_writeb(0xB6, info->freq_regs + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* select desired HZ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) sbus_writeb(count & 0xff, info->freq_regs + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) sbus_writeb((count >> 8) & 0xff, info->freq_regs + 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* disable counter 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) sbus_writeb(sbus_readb(info->enable_reg) & 0xFC, info->enable_reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) spin_unlock_irqrestore(&state->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int sparcspkr_probe(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct sparcspkr_state *state = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!input_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) input_dev->name = state->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) input_dev->phys = "sparc/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) input_dev->id.bustype = BUS_ISA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) input_dev->id.vendor = 0x001f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) input_dev->id.product = 0x0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) input_dev->dev.parent = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) input_dev->evbit[0] = BIT_MASK(EV_SND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) input_dev->event = state->event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) state->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static void sparcspkr_shutdown(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct sparcspkr_state *state = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct input_dev *input_dev = state->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* turn off the speaker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) state->event(input_dev, EV_SND, SND_BELL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int bbc_beep_probe(struct platform_device *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct sparcspkr_state *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct bbc_beep_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct device_node *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) state = kzalloc(sizeof(*state), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) state->name = "Sparc BBC Speaker";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) state->event = bbc_spkr_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) spin_lock_init(&state->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) dp = of_find_node_by_path("/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (!dp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) info = &state->u.bbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (!info->clock_freq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) info->regs = of_ioremap(&op->resource[0], 0, 6, "bbc beep");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (!info->regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) platform_set_drvdata(op, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) err = sparcspkr_probe(&op->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) goto out_clear_drvdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) out_clear_drvdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) of_iounmap(&op->resource[0], info->regs, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int bbc_remove(struct platform_device *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct sparcspkr_state *state = platform_get_drvdata(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct input_dev *input_dev = state->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct bbc_beep_info *info = &state->u.bbc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /* turn off the speaker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) state->event(input_dev, EV_SND, SND_BELL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) input_unregister_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) of_iounmap(&op->resource[0], info->regs, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static const struct of_device_id bbc_beep_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .name = "beep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) .compatible = "SUNW,bbc-beep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) MODULE_DEVICE_TABLE(of, bbc_beep_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static struct platform_driver bbc_beep_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .name = "bbcbeep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .of_match_table = bbc_beep_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .probe = bbc_beep_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .remove = bbc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .shutdown = sparcspkr_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int grover_beep_probe(struct platform_device *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct sparcspkr_state *state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct grover_beep_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) state = kzalloc(sizeof(*state), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) state->name = "Sparc Grover Speaker";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) state->event = grover_spkr_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) spin_lock_init(&state->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) info = &state->u.grover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) info->freq_regs = of_ioremap(&op->resource[2], 0, 2, "grover beep freq");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!info->freq_regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) info->enable_reg = of_ioremap(&op->resource[3], 0, 1, "grover beep enable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (!info->enable_reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) goto out_unmap_freq_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) platform_set_drvdata(op, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) err = sparcspkr_probe(&op->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) goto out_clear_drvdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) out_clear_drvdata:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) of_iounmap(&op->resource[3], info->enable_reg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) out_unmap_freq_regs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) of_iounmap(&op->resource[2], info->freq_regs, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int grover_remove(struct platform_device *op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct sparcspkr_state *state = platform_get_drvdata(op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct grover_beep_info *info = &state->u.grover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct input_dev *input_dev = state->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* turn off the speaker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) state->event(input_dev, EV_SND, SND_BELL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) input_unregister_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) of_iounmap(&op->resource[3], info->enable_reg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) of_iounmap(&op->resource[2], info->freq_regs, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) kfree(state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static const struct of_device_id grover_beep_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .name = "beep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .compatible = "SUNW,smbus-beep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) MODULE_DEVICE_TABLE(of, grover_beep_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static struct platform_driver grover_beep_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .name = "groverbeep",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .of_match_table = grover_beep_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .probe = grover_beep_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .remove = grover_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .shutdown = sparcspkr_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static struct platform_driver * const drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) &bbc_beep_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) &grover_beep_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static int __init sparcspkr_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static void __exit sparcspkr_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) module_init(sparcspkr_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) module_exit(sparcspkr_exit);