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