Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for PowerMac AWACS |
| 4 | * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de> |
| 5 | * based on dmasound.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/init.h> |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 9 | #include <linux/err.h> |
| 10 | #include <linux/platform_device.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 11 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <sound/core.h> |
| 13 | #include <sound/initval.h> |
| 14 | #include "pmac.h" |
| 15 | #include "awacs.h" |
| 16 | #include "burgundy.h" |
| 17 | |
| 18 | #define CHIP_NAME "PMac" |
| 19 | |
| 20 | MODULE_DESCRIPTION("PowerMac"); |
| 21 | MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
| 24 | static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ |
| 25 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 26 | static bool enable_beep = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | module_param(index, int, 0444); |
| 29 | MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip."); |
| 30 | module_param(id, charp, 0444); |
| 31 | MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip."); |
| 32 | module_param(enable_beep, bool, 0444); |
| 33 | MODULE_PARM_DESC(enable_beep, "Enable beep using PCM."); |
| 34 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 35 | static struct platform_device *device; |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | */ |
| 40 | |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 41 | static int snd_pmac_probe(struct platform_device *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 43 | struct snd_card *card; |
| 44 | struct snd_pmac *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | char *name_ext; |
| 46 | int err; |
| 47 | |
Takashi Iwai | 1076879 | 2014-01-29 14:38:59 +0100 | [diff] [blame] | 48 | err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card); |
Takashi Iwai | bd7dd77 | 2008-12-28 16:45:02 +0100 | [diff] [blame] | 49 | if (err < 0) |
| 50 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | if ((err = snd_pmac_new(card, &chip)) < 0) |
| 53 | goto __error; |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 54 | card->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | switch (chip->model) { |
| 57 | case PMAC_BURGUNDY: |
| 58 | strcpy(card->driver, "PMac Burgundy"); |
| 59 | strcpy(card->shortname, "PowerMac Burgundy"); |
| 60 | sprintf(card->longname, "%s (Dev %d) Sub-frame %d", |
| 61 | card->shortname, chip->device_id, chip->subframe); |
| 62 | if ((err = snd_pmac_burgundy_init(chip)) < 0) |
| 63 | goto __error; |
| 64 | break; |
| 65 | case PMAC_DACA: |
| 66 | strcpy(card->driver, "PMac DACA"); |
| 67 | strcpy(card->shortname, "PowerMac DACA"); |
| 68 | sprintf(card->longname, "%s (Dev %d) Sub-frame %d", |
| 69 | card->shortname, chip->device_id, chip->subframe); |
| 70 | if ((err = snd_pmac_daca_init(chip)) < 0) |
| 71 | goto __error; |
| 72 | break; |
| 73 | case PMAC_TUMBLER: |
| 74 | case PMAC_SNAPPER: |
| 75 | name_ext = chip->model == PMAC_TUMBLER ? "Tumbler" : "Snapper"; |
| 76 | sprintf(card->driver, "PMac %s", name_ext); |
| 77 | sprintf(card->shortname, "PowerMac %s", name_ext); |
| 78 | sprintf(card->longname, "%s (Dev %d) Sub-frame %d", |
| 79 | card->shortname, chip->device_id, chip->subframe); |
| 80 | if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0) |
| 81 | goto __error; |
| 82 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | case PMAC_AWACS: |
| 84 | case PMAC_SCREAMER: |
| 85 | name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS"; |
| 86 | sprintf(card->driver, "PMac %s", name_ext); |
| 87 | sprintf(card->shortname, "PowerMac %s", name_ext); |
| 88 | if (chip->is_pbook_3400) |
| 89 | name_ext = " [PB3400]"; |
| 90 | else if (chip->is_pbook_G3) |
| 91 | name_ext = " [PBG3]"; |
| 92 | else |
| 93 | name_ext = ""; |
| 94 | sprintf(card->longname, "%s%s Rev %d", |
| 95 | card->shortname, name_ext, chip->revision); |
| 96 | if ((err = snd_pmac_awacs_init(chip)) < 0) |
| 97 | goto __error; |
| 98 | break; |
| 99 | default: |
Takashi Iwai | 6da6711 | 2009-02-05 16:02:46 +0100 | [diff] [blame] | 100 | snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | err = -EINVAL; |
| 102 | goto __error; |
| 103 | } |
| 104 | |
| 105 | if ((err = snd_pmac_pcm_new(chip)) < 0) |
| 106 | goto __error; |
| 107 | |
| 108 | chip->initialized = 1; |
| 109 | if (enable_beep) |
| 110 | snd_pmac_attach_beep(chip); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | if ((err = snd_card_register(card)) < 0) |
| 113 | goto __error; |
| 114 | |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 115 | platform_set_drvdata(devptr, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return 0; |
| 117 | |
| 118 | __error: |
| 119 | snd_card_free(card); |
| 120 | return err; |
| 121 | } |
| 122 | |
| 123 | |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 124 | static int snd_pmac_remove(struct platform_device *devptr) |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 125 | { |
| 126 | snd_card_free(platform_get_drvdata(devptr)); |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Takashi Iwai | d34e4e0 | 2012-08-09 15:47:15 +0200 | [diff] [blame] | 130 | #ifdef CONFIG_PM_SLEEP |
Takashi Iwai | 284e7ca | 2012-07-02 11:22:40 +0200 | [diff] [blame] | 131 | static int snd_pmac_driver_suspend(struct device *dev) |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 132 | { |
Takashi Iwai | 284e7ca | 2012-07-02 11:22:40 +0200 | [diff] [blame] | 133 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 134 | snd_pmac_suspend(card->private_data); |
| 135 | return 0; |
| 136 | } |
| 137 | |
Takashi Iwai | 284e7ca | 2012-07-02 11:22:40 +0200 | [diff] [blame] | 138 | static int snd_pmac_driver_resume(struct device *dev) |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 139 | { |
Takashi Iwai | 284e7ca | 2012-07-02 11:22:40 +0200 | [diff] [blame] | 140 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 141 | snd_pmac_resume(card->private_data); |
| 142 | return 0; |
| 143 | } |
Takashi Iwai | 284e7ca | 2012-07-02 11:22:40 +0200 | [diff] [blame] | 144 | |
| 145 | static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume); |
| 146 | #define SND_PMAC_PM_OPS &snd_pmac_pm |
| 147 | #else |
| 148 | #define SND_PMAC_PM_OPS NULL |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 149 | #endif |
| 150 | |
| 151 | #define SND_PMAC_DRIVER "snd_powermac" |
| 152 | |
| 153 | static struct platform_driver snd_pmac_driver = { |
| 154 | .probe = snd_pmac_probe, |
Bill Pemberton | 15afafc | 2012-12-06 12:35:23 -0500 | [diff] [blame] | 155 | .remove = snd_pmac_remove, |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 156 | .driver = { |
Takashi Iwai | 8bf01d8 | 2012-07-02 10:50:24 +0200 | [diff] [blame] | 157 | .name = SND_PMAC_DRIVER, |
Takashi Iwai | 284e7ca | 2012-07-02 11:22:40 +0200 | [diff] [blame] | 158 | .pm = SND_PMAC_PM_OPS, |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 159 | }, |
| 160 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | static int __init alsa_card_pmac_init(void) |
| 163 | { |
| 164 | int err; |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 165 | |
| 166 | if ((err = platform_driver_register(&snd_pmac_driver)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return err; |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 168 | device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0); |
Johannes Berg | 545b07d | 2006-07-25 16:14:16 +0200 | [diff] [blame] | 169 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | } |
| 172 | |
| 173 | static void __exit alsa_card_pmac_exit(void) |
| 174 | { |
Johannes Berg | 545b07d | 2006-07-25 16:14:16 +0200 | [diff] [blame] | 175 | if (!IS_ERR(device)) |
| 176 | platform_device_unregister(device); |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 177 | platform_driver_unregister(&snd_pmac_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | module_init(alsa_card_pmac_init) |
| 181 | module_exit(alsa_card_pmac_exit) |