2 * Apple Onboard Audio driver -- layout/machine id fabric
4 * Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
6 * GPL v2, can be found in COPYING.
9 * This fabric module looks for sound codecs based on the
10 * layout-id or device-id property in the device tree.
13 #include <linux/list.h>
14 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include "../soundbus/soundbus.h"
19 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
20 MODULE_LICENSE("GPL");
21 MODULE_DESCRIPTION("Layout-ID fabric for snd-aoa");
23 #define MAX_CODECS_PER_BUS 2
25 /* These are the connections the layout fabric
26 * knows about. It doesn't really care about the
27 * input ones, but I thought I'd separate them
28 * to give them proper names. The thing is that
29 * Apple usually will distinguish the active output
30 * by GPIOs, while the active input is set directly
31 * on the codec. Hence we here tell the codec what
32 * we think is connected. This information is hard-
34 #define CC_SPEAKERS (1<<0)
35 #define CC_HEADPHONE (1<<1)
36 #define CC_LINEOUT (1<<2)
37 #define CC_DIGITALOUT (1<<3)
38 #define CC_LINEIN (1<<4)
39 #define CC_MICROPHONE (1<<5)
40 #define CC_DIGITALIN (1<<6)
41 /* pretty bogus but users complain...
42 * This is a flag saying that the LINEOUT
43 * should be renamed to HEADPHONE.
44 * be careful with input detection! */
45 #define CC_LINEOUT_LABELLED_HEADPHONE (1<<7)
47 struct codec_connection {
48 /* CC_ flags from above */
50 /* codec dependent bit to be set in the aoa_codec.connected field.
51 * This intentionally doesn't have any generic flags because the
52 * fabric has to know the codec anyway and all codecs might have
53 * different connectors */
57 struct codec_connect_info {
59 struct codec_connection *connections;
62 #define LAYOUT_FLAG_COMBO_LINEOUT_SPDIF (1<<0)
65 unsigned int layout_id, device_id;
66 struct codec_connect_info codecs[MAX_CODECS_PER_BUS];
69 /* if busname is not assigned, we use 'Master' below,
70 * so that our layout table doesn't need to be filled
72 * We only assign these two if we expect to find more
73 * than one soundbus, i.e. on those machines with
74 * multiple layout-ids */
79 MODULE_ALIAS("sound-layout-36");
80 MODULE_ALIAS("sound-layout-41");
81 MODULE_ALIAS("sound-layout-45");
82 MODULE_ALIAS("sound-layout-47");
83 MODULE_ALIAS("sound-layout-48");
84 MODULE_ALIAS("sound-layout-49");
85 MODULE_ALIAS("sound-layout-50");
86 MODULE_ALIAS("sound-layout-51");
87 MODULE_ALIAS("sound-layout-56");
88 MODULE_ALIAS("sound-layout-57");
89 MODULE_ALIAS("sound-layout-58");
90 MODULE_ALIAS("sound-layout-60");
91 MODULE_ALIAS("sound-layout-61");
92 MODULE_ALIAS("sound-layout-62");
93 MODULE_ALIAS("sound-layout-64");
94 MODULE_ALIAS("sound-layout-65");
95 MODULE_ALIAS("sound-layout-66");
96 MODULE_ALIAS("sound-layout-67");
97 MODULE_ALIAS("sound-layout-68");
98 MODULE_ALIAS("sound-layout-69");
99 MODULE_ALIAS("sound-layout-70");
100 MODULE_ALIAS("sound-layout-72");
101 MODULE_ALIAS("sound-layout-76");
102 MODULE_ALIAS("sound-layout-80");
103 MODULE_ALIAS("sound-layout-82");
104 MODULE_ALIAS("sound-layout-84");
105 MODULE_ALIAS("sound-layout-86");
106 MODULE_ALIAS("sound-layout-90");
107 MODULE_ALIAS("sound-layout-92");
108 MODULE_ALIAS("sound-layout-94");
109 MODULE_ALIAS("sound-layout-96");
110 MODULE_ALIAS("sound-layout-98");
111 MODULE_ALIAS("sound-layout-100");
113 MODULE_ALIAS("aoa-device-id-14");
114 MODULE_ALIAS("aoa-device-id-22");
115 MODULE_ALIAS("aoa-device-id-35");
117 /* onyx with all but microphone connected */
118 static struct codec_connection onyx_connections_nomic[] = {
120 .connected = CC_SPEAKERS | CC_HEADPHONE | CC_LINEOUT,
124 .connected = CC_DIGITALOUT,
128 .connected = CC_LINEIN,
131 {} /* terminate array by .connected == 0 */
134 /* onyx on machines without headphone */
135 static struct codec_connection onyx_connections_noheadphones[] = {
137 .connected = CC_SPEAKERS | CC_LINEOUT |
138 CC_LINEOUT_LABELLED_HEADPHONE,
142 .connected = CC_DIGITALOUT,
145 /* FIXME: are these correct? probably not for all the machines
146 * below ... If not this will need separating. */
148 .connected = CC_LINEIN,
152 .connected = CC_MICROPHONE,
155 {} /* terminate array by .connected == 0 */
158 /* onyx on machines with real line-out */
159 static struct codec_connection onyx_connections_reallineout[] = {
161 .connected = CC_SPEAKERS | CC_LINEOUT | CC_HEADPHONE,
165 .connected = CC_DIGITALOUT,
169 .connected = CC_LINEIN,
172 {} /* terminate array by .connected == 0 */
175 /* tas on machines without line out */
176 static struct codec_connection tas_connections_nolineout[] = {
178 .connected = CC_SPEAKERS | CC_HEADPHONE,
182 .connected = CC_LINEIN,
186 .connected = CC_MICROPHONE,
189 {} /* terminate array by .connected == 0 */
192 /* tas on machines with neither line out nor line in */
193 static struct codec_connection tas_connections_noline[] = {
195 .connected = CC_SPEAKERS | CC_HEADPHONE,
199 .connected = CC_MICROPHONE,
202 {} /* terminate array by .connected == 0 */
205 /* tas on machines without microphone */
206 static struct codec_connection tas_connections_nomic[] = {
208 .connected = CC_SPEAKERS | CC_HEADPHONE | CC_LINEOUT,
212 .connected = CC_LINEIN,
215 {} /* terminate array by .connected == 0 */
218 /* tas on machines with everything connected */
219 static struct codec_connection tas_connections_all[] = {
221 .connected = CC_SPEAKERS | CC_HEADPHONE | CC_LINEOUT,
225 .connected = CC_LINEIN,
229 .connected = CC_MICROPHONE,
232 {} /* terminate array by .connected == 0 */
235 static struct codec_connection toonie_connections[] = {
237 .connected = CC_SPEAKERS | CC_HEADPHONE,
240 {} /* terminate array by .connected == 0 */
243 static struct codec_connection topaz_input[] = {
245 .connected = CC_DIGITALIN,
248 {} /* terminate array by .connected == 0 */
251 static struct codec_connection topaz_output[] = {
253 .connected = CC_DIGITALOUT,
256 {} /* terminate array by .connected == 0 */
259 static struct codec_connection topaz_inout[] = {
261 .connected = CC_DIGITALIN,
265 .connected = CC_DIGITALOUT,
268 {} /* terminate array by .connected == 0 */
271 static struct layout layouts[] = {
272 /* last PowerBooks (15" Oct 2005) */
274 .flags = LAYOUT_FLAG_COMBO_LINEOUT_SPDIF,
277 .connections = onyx_connections_noheadphones,
281 .connections = topaz_input,
288 .connections = onyx_connections_reallineout,
295 .connections = topaz_input,
300 .flags = LAYOUT_FLAG_COMBO_LINEOUT_SPDIF,
303 .connections = onyx_connections_noheadphones,
310 .connections = topaz_input,
313 /* PowerBook5,9 [17" Oct 2005] */
315 .flags = LAYOUT_FLAG_COMBO_LINEOUT_SPDIF,
318 .connections = onyx_connections_noheadphones,
322 .connections = topaz_input,
329 .connections = onyx_connections_noheadphones,
333 .connections = topaz_input,
336 /* Quad PowerMac (analog in, analog/digital out) */
340 .connections = onyx_connections_nomic,
343 /* Quad PowerMac (digital in) */
347 .connections = topaz_input,
349 .busname = "digital in", .pcmid = 1 },
350 /* Early 2005 PowerBook (PowerBook 5,6) */
354 .connections = tas_connections_nolineout,
361 .connections = tas_connections_nolineout,
368 .connections = tas_connections_noline,
375 .connections = tas_connections_nolineout,
382 .connections = onyx_connections_nomic,
386 .connections = topaz_input,
393 .connections = tas_connections_nolineout,
396 /* PowerMac10,1 (Mac Mini) */
400 .connections = toonie_connections,
407 .connections = onyx_connections_noheadphones,
410 /* unknown, untested, but this comes from Apple */
414 .connections = tas_connections_all,
420 .connections = tas_connections_nomic,
424 .connections = topaz_inout,
430 .connections = onyx_connections_noheadphones,
436 .connections = topaz_input,
442 .connections = onyx_connections_nomic,
448 .connections = topaz_input,
454 .connections = onyx_connections_noheadphones,
460 .connections = topaz_input,
466 .connections = onyx_connections_noheadphones,
470 .connections = topaz_output,
476 .connections = onyx_connections_noheadphones,
482 .connections = topaz_input,
488 .connections = tas_connections_nomic,
492 .connections = topaz_inout,
498 .connections = tas_connections_noline,
504 /* but it has an external mic?? how to select? */
505 .connections = onyx_connections_noheadphones,
511 .connections = toonie_connections,
517 .connections = topaz_input,
521 .connections = onyx_connections_noheadphones,
528 .connections = tas_connections_noline,
535 .connections = tas_connections_all,
542 .connections = tas_connections_all,
548 static struct layout *find_layout_by_id(unsigned int id)
553 while (l->codecs[0].name) {
554 if (l->layout_id == id)
561 static struct layout *find_layout_by_device(unsigned int id)
566 while (l->codecs[0].name) {
567 if (l->device_id == id)
574 static void use_layout(struct layout *l)
578 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
579 if (l->codecs[i].name) {
580 request_module("snd-aoa-codec-%s", l->codecs[i].name);
583 /* now we wait for the codecs to call us back */
588 struct layout_dev_ptr {
589 struct layout_dev *ptr;
593 struct list_head list;
594 struct soundbus_dev *sdev;
595 struct device_node *sound;
596 struct aoa_codec *codecs[MAX_CODECS_PER_BUS];
597 struct layout *layout;
598 struct gpio_runtime gpio;
600 /* we need these for headphone/lineout detection */
601 struct snd_kcontrol *headphone_ctrl;
602 struct snd_kcontrol *lineout_ctrl;
603 struct snd_kcontrol *speaker_ctrl;
604 struct snd_kcontrol *master_ctrl;
605 struct snd_kcontrol *headphone_detected_ctrl;
606 struct snd_kcontrol *lineout_detected_ctrl;
608 struct layout_dev_ptr selfptr_headphone;
609 struct layout_dev_ptr selfptr_lineout;
611 u32 have_lineout_detect:1,
612 have_headphone_detect:1,
613 switch_on_headphone:1,
617 static LIST_HEAD(layouts_list);
618 static int layouts_list_items;
619 /* this can go away but only if we allow multiple cards,
620 * make the fabric handle all the card stuff, etc... */
621 static struct layout_dev *layout_device;
623 #define control_info snd_ctl_boolean_mono_info
625 #define AMP_CONTROL(n, description) \
626 static int n##_control_get(struct snd_kcontrol *kcontrol, \
627 struct snd_ctl_elem_value *ucontrol) \
629 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
630 if (gpio->methods && gpio->methods->get_##n) \
631 ucontrol->value.integer.value[0] = \
632 gpio->methods->get_##n(gpio); \
635 static int n##_control_put(struct snd_kcontrol *kcontrol, \
636 struct snd_ctl_elem_value *ucontrol) \
638 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
639 if (gpio->methods && gpio->methods->get_##n) \
640 gpio->methods->set_##n(gpio, \
641 !!ucontrol->value.integer.value[0]); \
644 static struct snd_kcontrol_new n##_ctl = { \
645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
646 .name = description, \
647 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
648 .info = control_info, \
649 .get = n##_control_get, \
650 .put = n##_control_put, \
653 AMP_CONTROL(headphone, "Headphone Switch");
654 AMP_CONTROL(speakers, "Speakers Switch");
655 AMP_CONTROL(lineout, "Line-Out Switch");
656 AMP_CONTROL(master, "Master Switch");
658 static int detect_choice_get(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *ucontrol)
661 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
663 switch (kcontrol->private_value) {
665 ucontrol->value.integer.value[0] = ldev->switch_on_headphone;
668 ucontrol->value.integer.value[0] = ldev->switch_on_lineout;
676 static int detect_choice_put(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
679 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
681 switch (kcontrol->private_value) {
683 ldev->switch_on_headphone = !!ucontrol->value.integer.value[0];
686 ldev->switch_on_lineout = !!ucontrol->value.integer.value[0];
694 static struct snd_kcontrol_new headphone_detect_choice = {
695 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
696 .name = "Headphone Detect Autoswitch",
697 .info = control_info,
698 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
699 .get = detect_choice_get,
700 .put = detect_choice_put,
704 static struct snd_kcontrol_new lineout_detect_choice = {
705 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
706 .name = "Line-Out Detect Autoswitch",
707 .info = control_info,
708 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
709 .get = detect_choice_get,
710 .put = detect_choice_put,
714 static int detected_get(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
717 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
720 switch (kcontrol->private_value) {
722 v = ldev->gpio.methods->get_detect(&ldev->gpio,
723 AOA_NOTIFY_HEADPHONE);
726 v = ldev->gpio.methods->get_detect(&ldev->gpio,
727 AOA_NOTIFY_LINE_OUT);
732 ucontrol->value.integer.value[0] = v;
736 static struct snd_kcontrol_new headphone_detected = {
737 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
738 .name = "Headphone Detected",
739 .info = control_info,
740 .access = SNDRV_CTL_ELEM_ACCESS_READ,
745 static struct snd_kcontrol_new lineout_detected = {
746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
747 .name = "Line-Out Detected",
748 .info = control_info,
749 .access = SNDRV_CTL_ELEM_ACCESS_READ,
754 static int check_codec(struct aoa_codec *codec,
755 struct layout_dev *ldev,
756 struct codec_connect_info *cci)
760 struct codec_connection *cc;
762 /* if the codec has a 'codec' node, we require a reference */
763 if (codec->node && (strcmp(codec->node->name, "codec") == 0)) {
764 snprintf(propname, sizeof(propname),
765 "platform-%s-codec-ref", codec->name);
766 ref = of_get_property(ldev->sound, propname, NULL);
768 printk(KERN_INFO "snd-aoa-fabric-layout: "
769 "required property %s not present\n", propname);
772 if (*ref != codec->node->phandle) {
773 printk(KERN_INFO "snd-aoa-fabric-layout: "
774 "%s doesn't match!\n", propname);
778 if (layouts_list_items != 1) {
779 printk(KERN_INFO "snd-aoa-fabric-layout: "
780 "more than one soundbus, but no references.\n");
784 codec->soundbus_dev = ldev->sdev;
785 codec->gpio = &ldev->gpio;
787 cc = cci->connections;
791 printk(KERN_INFO "snd-aoa-fabric-layout: can use this codec\n");
793 codec->connected = 0;
794 codec->fabric_data = cc;
796 while (cc->connected) {
797 codec->connected |= 1<<cc->codec_bit;
804 static int layout_found_codec(struct aoa_codec *codec)
806 struct layout_dev *ldev;
809 list_for_each_entry(ldev, &layouts_list, list) {
810 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
811 if (!ldev->layout->codecs[i].name)
813 if (strcmp(ldev->layout->codecs[i].name, codec->name) == 0) {
814 if (check_codec(codec,
816 &ldev->layout->codecs[i]) == 0)
824 static void layout_remove_codec(struct aoa_codec *codec)
827 /* here remove the codec from the layout dev's
830 codec->soundbus_dev = NULL;
832 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
836 static void layout_notify(void *data)
838 struct layout_dev_ptr *dptr = data;
839 struct layout_dev *ldev;
841 struct snd_kcontrol *detected, *c;
842 struct snd_card *card = aoa_get_card();
845 if (data == &ldev->selfptr_headphone) {
846 v = ldev->gpio.methods->get_detect(&ldev->gpio, AOA_NOTIFY_HEADPHONE);
847 detected = ldev->headphone_detected_ctrl;
848 update = ldev->switch_on_headphone;
850 ldev->gpio.methods->set_speakers(&ldev->gpio, !v);
851 ldev->gpio.methods->set_headphone(&ldev->gpio, v);
852 ldev->gpio.methods->set_lineout(&ldev->gpio, 0);
854 } else if (data == &ldev->selfptr_lineout) {
855 v = ldev->gpio.methods->get_detect(&ldev->gpio, AOA_NOTIFY_LINE_OUT);
856 detected = ldev->lineout_detected_ctrl;
857 update = ldev->switch_on_lineout;
859 ldev->gpio.methods->set_speakers(&ldev->gpio, !v);
860 ldev->gpio.methods->set_headphone(&ldev->gpio, 0);
861 ldev->gpio.methods->set_lineout(&ldev->gpio, v);
867 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &detected->id);
869 c = ldev->headphone_ctrl;
871 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
872 c = ldev->speaker_ctrl;
874 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
875 c = ldev->lineout_ctrl;
877 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
881 static void layout_attached_codec(struct aoa_codec *codec)
883 struct codec_connection *cc;
884 struct snd_kcontrol *ctl;
885 int headphones, lineout;
886 struct layout_dev *ldev = layout_device;
888 /* need to add this codec to our codec array! */
890 cc = codec->fabric_data;
892 headphones = codec->gpio->methods->get_detect(codec->gpio,
893 AOA_NOTIFY_HEADPHONE);
894 lineout = codec->gpio->methods->get_detect(codec->gpio,
895 AOA_NOTIFY_LINE_OUT);
897 if (codec->gpio->methods->set_master) {
898 ctl = snd_ctl_new1(&master_ctl, codec->gpio);
899 ldev->master_ctrl = ctl;
900 aoa_snd_ctl_add(ctl);
902 while (cc->connected) {
903 if (cc->connected & CC_SPEAKERS) {
904 if (headphones <= 0 && lineout <= 0)
905 ldev->gpio.methods->set_speakers(codec->gpio, 1);
906 ctl = snd_ctl_new1(&speakers_ctl, codec->gpio);
907 ldev->speaker_ctrl = ctl;
908 aoa_snd_ctl_add(ctl);
910 if (cc->connected & CC_HEADPHONE) {
912 ldev->gpio.methods->set_headphone(codec->gpio, 1);
913 ctl = snd_ctl_new1(&headphone_ctl, codec->gpio);
914 ldev->headphone_ctrl = ctl;
915 aoa_snd_ctl_add(ctl);
916 ldev->have_headphone_detect =
918 ->set_notify(&ldev->gpio,
919 AOA_NOTIFY_HEADPHONE,
921 &ldev->selfptr_headphone);
922 if (ldev->have_headphone_detect) {
923 ctl = snd_ctl_new1(&headphone_detect_choice,
925 aoa_snd_ctl_add(ctl);
926 ctl = snd_ctl_new1(&headphone_detected,
928 ldev->headphone_detected_ctrl = ctl;
929 aoa_snd_ctl_add(ctl);
932 if (cc->connected & CC_LINEOUT) {
934 ldev->gpio.methods->set_lineout(codec->gpio, 1);
935 ctl = snd_ctl_new1(&lineout_ctl, codec->gpio);
936 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
937 strlcpy(ctl->id.name,
938 "Headphone Switch", sizeof(ctl->id.name));
939 ldev->lineout_ctrl = ctl;
940 aoa_snd_ctl_add(ctl);
941 ldev->have_lineout_detect =
943 ->set_notify(&ldev->gpio,
946 &ldev->selfptr_lineout);
947 if (ldev->have_lineout_detect) {
948 ctl = snd_ctl_new1(&lineout_detect_choice,
950 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
951 strlcpy(ctl->id.name,
952 "Headphone Detect Autoswitch",
953 sizeof(ctl->id.name));
954 aoa_snd_ctl_add(ctl);
955 ctl = snd_ctl_new1(&lineout_detected,
957 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
958 strlcpy(ctl->id.name,
959 "Headphone Detected",
960 sizeof(ctl->id.name));
961 ldev->lineout_detected_ctrl = ctl;
962 aoa_snd_ctl_add(ctl);
967 /* now update initial state */
968 if (ldev->have_headphone_detect)
969 layout_notify(&ldev->selfptr_headphone);
970 if (ldev->have_lineout_detect)
971 layout_notify(&ldev->selfptr_lineout);
974 static struct aoa_fabric layout_fabric = {
975 .name = "SoundByLayout",
976 .owner = THIS_MODULE,
977 .found_codec = layout_found_codec,
978 .remove_codec = layout_remove_codec,
979 .attached_codec = layout_attached_codec,
982 static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
984 struct device_node *sound = NULL;
985 const unsigned int *id;
986 struct layout *layout = NULL;
987 struct layout_dev *ldev = NULL;
990 /* hm, currently we can only have one ... */
994 /* by breaking out we keep a reference */
995 while ((sound = of_get_next_child(sdev->ofdev.dev.of_node, sound))) {
996 if (sound->type && strcasecmp(sound->type, "soundchip") == 0)
1002 id = of_get_property(sound, "layout-id", NULL);
1004 layout = find_layout_by_id(*id);
1006 id = of_get_property(sound, "device-id", NULL);
1008 layout = find_layout_by_device(*id);
1012 printk(KERN_ERR "snd-aoa-fabric-layout: unknown layout\n");
1016 ldev = kzalloc(sizeof(struct layout_dev), GFP_KERNEL);
1020 layout_device = ldev;
1022 ldev->sound = sound;
1023 ldev->layout = layout;
1024 ldev->gpio.node = sound->parent;
1025 switch (layout->layout_id) {
1026 case 0: /* anything with device_id, not layout_id */
1027 case 41: /* that unknown machine no one seems to have */
1028 case 51: /* PowerBook5,4 */
1029 case 58: /* Mac Mini */
1030 ldev->gpio.methods = ftr_gpio_methods;
1032 "snd-aoa-fabric-layout: Using direct GPIOs\n");
1035 ldev->gpio.methods = pmf_gpio_methods;
1037 "snd-aoa-fabric-layout: Using PMF GPIOs\n");
1039 ldev->selfptr_headphone.ptr = ldev;
1040 ldev->selfptr_lineout.ptr = ldev;
1041 dev_set_drvdata(&sdev->ofdev.dev, ldev);
1042 list_add(&ldev->list, &layouts_list);
1043 layouts_list_items++;
1045 /* assign these before registering ourselves, so
1046 * callbacks that are done during registration
1047 * already have the values */
1048 sdev->pcmid = ldev->layout->pcmid;
1049 if (ldev->layout->busname) {
1050 sdev->pcmname = ldev->layout->busname;
1052 sdev->pcmname = "Master";
1055 ldev->gpio.methods->init(&ldev->gpio);
1057 err = aoa_fabric_register(&layout_fabric, &sdev->ofdev.dev);
1058 if (err && err != -EALREADY) {
1059 printk(KERN_INFO "snd-aoa-fabric-layout: can't use,"
1060 " another fabric is active!\n");
1065 ldev->switch_on_headphone = 1;
1066 ldev->switch_on_lineout = 1;
1069 /* we won't be using these then... */
1070 ldev->gpio.methods->exit(&ldev->gpio);
1071 /* reset if we didn't use it */
1072 sdev->pcmname = NULL;
1074 list_del(&ldev->list);
1075 layouts_list_items--;
1078 layout_device = NULL;
1083 static int aoa_fabric_layout_remove(struct soundbus_dev *sdev)
1085 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
1088 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
1089 if (ldev->codecs[i]) {
1090 aoa_fabric_unlink_codec(ldev->codecs[i]);
1092 ldev->codecs[i] = NULL;
1094 list_del(&ldev->list);
1095 layouts_list_items--;
1096 of_node_put(ldev->sound);
1098 ldev->gpio.methods->set_notify(&ldev->gpio,
1099 AOA_NOTIFY_HEADPHONE,
1102 ldev->gpio.methods->set_notify(&ldev->gpio,
1103 AOA_NOTIFY_LINE_OUT,
1107 ldev->gpio.methods->exit(&ldev->gpio);
1108 layout_device = NULL;
1111 sdev->pcmname = NULL;
1116 static int aoa_fabric_layout_suspend(struct soundbus_dev *sdev, pm_message_t state)
1118 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
1120 if (ldev->gpio.methods && ldev->gpio.methods->all_amps_off)
1121 ldev->gpio.methods->all_amps_off(&ldev->gpio);
1126 static int aoa_fabric_layout_resume(struct soundbus_dev *sdev)
1128 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
1130 if (ldev->gpio.methods && ldev->gpio.methods->all_amps_off)
1131 ldev->gpio.methods->all_amps_restore(&ldev->gpio);
1137 static struct soundbus_driver aoa_soundbus_driver = {
1138 .name = "snd_aoa_soundbus_drv",
1139 .owner = THIS_MODULE,
1140 .probe = aoa_fabric_layout_probe,
1141 .remove = aoa_fabric_layout_remove,
1143 .suspend = aoa_fabric_layout_suspend,
1144 .resume = aoa_fabric_layout_resume,
1147 .owner = THIS_MODULE,
1151 static int __init aoa_fabric_layout_init(void)
1155 err = soundbus_register_driver(&aoa_soundbus_driver);
1161 static void __exit aoa_fabric_layout_exit(void)
1163 soundbus_unregister_driver(&aoa_soundbus_driver);
1164 aoa_fabric_unregister(&layout_fabric);
1167 module_init(aoa_fabric_layout_init);
1168 module_exit(aoa_fabric_layout_exit);