1 // SPDX-License-Identifier: GPL-2.0-only
3 * Apple Onboard Audio driver for Toonie codec
5 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
7 * This is a driver for the toonie codec chip. This chip is present
8 * on the Mac Mini and is nothing but a DAC.
10 #include <linux/delay.h>
11 #include <linux/module.h>
12 #include <linux/slab.h>
13 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
14 MODULE_LICENSE("GPL");
15 MODULE_DESCRIPTION("toonie codec driver for snd-aoa");
18 #include "../soundbus/soundbus.h"
21 #define PFX "snd-aoa-codec-toonie: "
24 struct aoa_codec codec;
26 #define codec_to_toonie(c) container_of(c, struct toonie, codec)
28 static int toonie_dev_register(struct snd_device *dev)
33 static const struct snd_device_ops ops = {
34 .dev_register = toonie_dev_register,
37 static struct transfer_info toonie_transfers[] = {
38 /* This thing *only* has analog output,
39 * the rates are taken from Info.plist
42 .formats = SNDRV_PCM_FMTBIT_S16_BE |
43 SNDRV_PCM_FMTBIT_S24_BE,
44 .rates = SNDRV_PCM_RATE_32000 |
45 SNDRV_PCM_RATE_44100 |
46 SNDRV_PCM_RATE_48000 |
47 SNDRV_PCM_RATE_88200 |
53 static int toonie_usable(struct codec_info_item *cii,
54 struct transfer_info *ti,
55 struct transfer_info *out)
61 static int toonie_suspend(struct codec_info_item *cii, pm_message_t state)
63 /* can we turn it off somehow? */
67 static int toonie_resume(struct codec_info_item *cii)
71 #endif /* CONFIG_PM */
73 static struct codec_info toonie_codec_info = {
74 .transfers = toonie_transfers,
75 .sysclock_factor = 256,
78 .usable = toonie_usable,
80 .suspend = toonie_suspend,
81 .resume = toonie_resume,
85 static int toonie_init_codec(struct aoa_codec *codec)
87 struct toonie *toonie = codec_to_toonie(codec);
89 /* nothing connected? what a joke! */
90 if (toonie->codec.connected != 1)
93 if (aoa_snd_device_new(SNDRV_DEV_CODEC, toonie, &ops)) {
94 printk(KERN_ERR PFX "failed to create toonie snd device!\n");
98 if (toonie->codec.soundbus_dev->attach_codec(toonie->codec.soundbus_dev,
100 &toonie_codec_info, toonie)) {
101 printk(KERN_ERR PFX "error creating toonie pcm\n");
102 snd_device_free(aoa_get_card(), toonie);
109 static void toonie_exit_codec(struct aoa_codec *codec)
111 struct toonie *toonie = codec_to_toonie(codec);
113 if (!toonie->codec.soundbus_dev) {
114 printk(KERN_ERR PFX "toonie_exit_codec called without soundbus_dev!\n");
117 toonie->codec.soundbus_dev->detach_codec(toonie->codec.soundbus_dev, toonie);
120 static struct toonie *toonie;
122 static int __init toonie_init(void)
124 toonie = kzalloc(sizeof(struct toonie), GFP_KERNEL);
129 strscpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name));
130 toonie->codec.owner = THIS_MODULE;
131 toonie->codec.init = toonie_init_codec;
132 toonie->codec.exit = toonie_exit_codec;
134 if (aoa_codec_register(&toonie->codec)) {
142 static void __exit toonie_exit(void)
144 aoa_codec_unregister(&toonie->codec);
148 module_init(toonie_init);
149 module_exit(toonie_exit);