blob: 8abb521b4814b413a9423edf48bf2d7e41c08e2e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
Takashi Iwai5e12bea2005-11-17 17:17:08 +010022#include <linux/err.h>
23#include <linux/platform_device.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040024#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#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
33MODULE_DESCRIPTION("PowerMac");
34MODULE_SUPPORTED_DEVICE("{{Apple,PowerMac}}");
35MODULE_LICENSE("GPL");
36
37static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
38static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103039static bool enable_beep = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41module_param(index, int, 0444);
42MODULE_PARM_DESC(index, "Index value for " CHIP_NAME " soundchip.");
43module_param(id, charp, 0444);
44MODULE_PARM_DESC(id, "ID string for " CHIP_NAME " soundchip.");
45module_param(enable_beep, bool, 0444);
46MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
47
Clemens Ladischf7a92752005-12-07 09:13:42 +010048static struct platform_device *device;
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 */
53
Bill Pemberton15afafc2012-12-06 12:35:23 -050054static int snd_pmac_probe(struct platform_device *devptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Takashi Iwai65b29f52005-11-17 15:09:46 +010056 struct snd_card *card;
57 struct snd_pmac *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 char *name_ext;
59 int err;
60
Takashi Iwaibd7dd772008-12-28 16:45:02 +010061 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
62 if (err < 0)
63 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 if ((err = snd_pmac_new(card, &chip)) < 0)
66 goto __error;
Takashi Iwai5e12bea2005-11-17 17:17:08 +010067 card->private_data = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
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);
93 if ( snd_pmac_tumbler_init(chip) < 0 || snd_pmac_tumbler_post_init() < 0)
94 goto __error;
95 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 case PMAC_AWACS:
97 case PMAC_SCREAMER:
98 name_ext = chip->model == PMAC_SCREAMER ? "Screamer" : "AWACS";
99 sprintf(card->driver, "PMac %s", name_ext);
100 sprintf(card->shortname, "PowerMac %s", name_ext);
101 if (chip->is_pbook_3400)
102 name_ext = " [PB3400]";
103 else if (chip->is_pbook_G3)
104 name_ext = " [PBG3]";
105 else
106 name_ext = "";
107 sprintf(card->longname, "%s%s Rev %d",
108 card->shortname, name_ext, chip->revision);
109 if ((err = snd_pmac_awacs_init(chip)) < 0)
110 goto __error;
111 break;
112 default:
Takashi Iwai6da67112009-02-05 16:02:46 +0100113 snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 err = -EINVAL;
115 goto __error;
116 }
117
118 if ((err = snd_pmac_pcm_new(chip)) < 0)
119 goto __error;
120
121 chip->initialized = 1;
122 if (enable_beep)
123 snd_pmac_attach_beep(chip);
124
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100125 snd_card_set_dev(card, &devptr->dev);
Takashi Iwai16dab542005-09-05 17:17:58 +0200126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if ((err = snd_card_register(card)) < 0)
128 goto __error;
129
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100130 platform_set_drvdata(devptr, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 return 0;
132
133__error:
134 snd_card_free(card);
135 return err;
136}
137
138
Bill Pemberton15afafc2012-12-06 12:35:23 -0500139static int snd_pmac_remove(struct platform_device *devptr)
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100140{
141 snd_card_free(platform_get_drvdata(devptr));
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100142 return 0;
143}
144
Takashi Iwaid34e4e02012-08-09 15:47:15 +0200145#ifdef CONFIG_PM_SLEEP
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200146static int snd_pmac_driver_suspend(struct device *dev)
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100147{
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200148 struct snd_card *card = dev_get_drvdata(dev);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100149 snd_pmac_suspend(card->private_data);
150 return 0;
151}
152
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200153static int snd_pmac_driver_resume(struct device *dev)
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100154{
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200155 struct snd_card *card = dev_get_drvdata(dev);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100156 snd_pmac_resume(card->private_data);
157 return 0;
158}
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200159
160static SIMPLE_DEV_PM_OPS(snd_pmac_pm, snd_pmac_driver_suspend, snd_pmac_driver_resume);
161#define SND_PMAC_PM_OPS &snd_pmac_pm
162#else
163#define SND_PMAC_PM_OPS NULL
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100164#endif
165
166#define SND_PMAC_DRIVER "snd_powermac"
167
168static struct platform_driver snd_pmac_driver = {
169 .probe = snd_pmac_probe,
Bill Pemberton15afafc2012-12-06 12:35:23 -0500170 .remove = snd_pmac_remove,
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100171 .driver = {
Takashi Iwai8bf01d82012-07-02 10:50:24 +0200172 .name = SND_PMAC_DRIVER,
173 .owner = THIS_MODULE,
Takashi Iwai284e7ca2012-07-02 11:22:40 +0200174 .pm = SND_PMAC_PM_OPS,
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100175 },
176};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178static int __init alsa_card_pmac_init(void)
179{
180 int err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100181
182 if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 return err;
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100184 device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
Johannes Berg545b07d2006-07-25 16:14:16 +0200185 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187}
188
189static void __exit alsa_card_pmac_exit(void)
190{
Johannes Berg545b07d2006-07-25 16:14:16 +0200191 if (!IS_ERR(device))
192 platform_device_unregister(device);
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100193 platform_driver_unregister(&snd_pmac_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196module_init(alsa_card_pmac_init)
197module_exit(alsa_card_pmac_exit)