Merge signal handler branch
[sfrench/cifs-2.6.git] / sound / aoa / codecs / snd-aoa-codec-toonie.c
1 /*
2  * Apple Onboard Audio driver for Toonie codec
3  *
4  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
5  *
6  * GPL v2, can be found in COPYING.
7  *
8  *
9  * This is a driver for the toonie codec chip. This chip is present
10  * on the Mac Mini and is nothing but a DAC.
11  */
12 #include <linux/delay.h>
13 #include <linux/module.h>
14 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
15 MODULE_LICENSE("GPL");
16 MODULE_DESCRIPTION("toonie codec driver for snd-aoa");
17
18 #include "../aoa.h"
19 #include "../soundbus/soundbus.h"
20
21
22 #define PFX "snd-aoa-codec-toonie: "
23
24 struct toonie {
25         struct aoa_codec        codec;
26 };
27 #define codec_to_toonie(c) container_of(c, struct toonie, codec)
28
29 static int toonie_dev_register(struct snd_device *dev)
30 {
31         return 0;
32 }
33
34 static struct snd_device_ops ops = {
35         .dev_register = toonie_dev_register,
36 };
37
38 static struct transfer_info toonie_transfers[] = {
39         /* This thing *only* has analog output,
40          * the rates are taken from Info.plist
41          * from Darwin. */
42         {
43                 .formats = SNDRV_PCM_FMTBIT_S16_BE |
44                            SNDRV_PCM_FMTBIT_S24_BE,
45                 .rates = SNDRV_PCM_RATE_32000 |
46                          SNDRV_PCM_RATE_44100 |
47                          SNDRV_PCM_RATE_48000 |
48                          SNDRV_PCM_RATE_88200 |
49                          SNDRV_PCM_RATE_96000,
50         },
51         {}
52 };
53
54 #ifdef CONFIG_PM
55 static int toonie_suspend(struct codec_info_item *cii, pm_message_t state)
56 {
57         /* can we turn it off somehow? */
58         return 0;
59 }
60
61 static int toonie_resume(struct codec_info_item *cii)
62 {
63         return 0;
64 }
65 #endif /* CONFIG_PM */
66
67 static struct codec_info toonie_codec_info = {
68         .transfers = toonie_transfers,
69         .sysclock_factor = 256,
70         .bus_factor = 64,
71         .owner = THIS_MODULE,
72 #ifdef CONFIG_PM
73         .suspend = toonie_suspend,
74         .resume = toonie_resume,
75 #endif
76 };
77
78 static int toonie_init_codec(struct aoa_codec *codec)
79 {
80         struct toonie *toonie = codec_to_toonie(codec);
81
82         if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, toonie, &ops)) {
83                 printk(KERN_ERR PFX "failed to create toonie snd device!\n");
84                 return -ENODEV;
85         }
86
87         /* nothing connected? what a joke! */
88         if (toonie->codec.connected != 1)
89                 return -ENOTCONN;
90
91         if (toonie->codec.soundbus_dev->attach_codec(toonie->codec.soundbus_dev,
92                                                      aoa_get_card(),
93                                                      &toonie_codec_info, toonie)) {
94                 printk(KERN_ERR PFX "error creating toonie pcm\n");
95                 return -ENODEV;
96         }
97
98         return 0;
99 }
100
101 static void toonie_exit_codec(struct aoa_codec *codec)
102 {
103         struct toonie *toonie = codec_to_toonie(codec);
104
105         if (!toonie->codec.soundbus_dev) {
106                 printk(KERN_ERR PFX "toonie_exit_codec called without soundbus_dev!\n");
107                 return;
108         }
109         toonie->codec.soundbus_dev->detach_codec(toonie->codec.soundbus_dev, toonie);
110 }
111
112 static struct toonie *toonie;
113
114 static int __init toonie_init(void)
115 {
116         toonie = kzalloc(sizeof(struct toonie), GFP_KERNEL);
117
118         if (!toonie)
119                 return -ENOMEM;
120
121         strlcpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name));
122         toonie->codec.owner = THIS_MODULE;
123         toonie->codec.init = toonie_init_codec;
124         toonie->codec.exit = toonie_exit_codec;
125                                         
126         if (aoa_codec_register(&toonie->codec)) {
127                 kfree(toonie);
128                 return -EINVAL;
129         }
130
131         return 0;
132 }
133
134 static void __exit toonie_exit(void)
135 {
136         aoa_codec_unregister(&toonie->codec);
137         kfree(toonie);
138 }
139
140 module_init(toonie_init);
141 module_exit(toonie_exit);