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