1 // SPDX-License-Identifier: GPL-2.0-only
3 * Apple Onboard Audio driver -- layout/machine id fabric
5 * Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
7 * This fabric module looks for sound codecs based on the
8 * layout-id or device-id property in the device tree.
11 #include <linux/list.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
15 #include "../soundbus/soundbus.h"
17 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
18 MODULE_LICENSE("GPL");
19 MODULE_DESCRIPTION("Layout-ID fabric for snd-aoa");
21 #define MAX_CODECS_PER_BUS 2
23 /* These are the connections the layout fabric
24 * knows about. It doesn't really care about the
25 * input ones, but I thought I'd separate them
26 * to give them proper names. The thing is that
27 * Apple usually will distinguish the active output
28 * by GPIOs, while the active input is set directly
29 * on the codec. Hence we here tell the codec what
30 * we think is connected. This information is hard-
32 #define CC_SPEAKERS (1<<0)
33 #define CC_HEADPHONE (1<<1)
34 #define CC_LINEOUT (1<<2)
35 #define CC_DIGITALOUT (1<<3)
36 #define CC_LINEIN (1<<4)
37 #define CC_MICROPHONE (1<<5)
38 #define CC_DIGITALIN (1<<6)
39 /* pretty bogus but users complain...
40 * This is a flag saying that the LINEOUT
41 * should be renamed to HEADPHONE.
42 * be careful with input detection! */
43 #define CC_LINEOUT_LABELLED_HEADPHONE (1<<7)
45 struct codec_connection {
46 /* CC_ flags from above */
48 /* codec dependent bit to be set in the aoa_codec.connected field.
49 * This intentionally doesn't have any generic flags because the
50 * fabric has to know the codec anyway and all codecs might have
51 * different connectors */
55 struct codec_connect_info {
57 struct codec_connection *connections;
60 #define LAYOUT_FLAG_COMBO_LINEOUT_SPDIF (1<<0)
63 unsigned int layout_id, device_id;
64 struct codec_connect_info codecs[MAX_CODECS_PER_BUS];
67 /* if busname is not assigned, we use 'Master' below,
68 * so that our layout table doesn't need to be filled
70 * We only assign these two if we expect to find more
71 * than one soundbus, i.e. on those machines with
72 * multiple layout-ids */
77 MODULE_ALIAS("sound-layout-36");
78 MODULE_ALIAS("sound-layout-41");
79 MODULE_ALIAS("sound-layout-45");
80 MODULE_ALIAS("sound-layout-47");
81 MODULE_ALIAS("sound-layout-48");
82 MODULE_ALIAS("sound-layout-49");
83 MODULE_ALIAS("sound-layout-50");
84 MODULE_ALIAS("sound-layout-51");
85 MODULE_ALIAS("sound-layout-56");
86 MODULE_ALIAS("sound-layout-57");
87 MODULE_ALIAS("sound-layout-58");
88 MODULE_ALIAS("sound-layout-60");
89 MODULE_ALIAS("sound-layout-61");
90 MODULE_ALIAS("sound-layout-62");
91 MODULE_ALIAS("sound-layout-64");
92 MODULE_ALIAS("sound-layout-65");
93 MODULE_ALIAS("sound-layout-66");
94 MODULE_ALIAS("sound-layout-67");
95 MODULE_ALIAS("sound-layout-68");
96 MODULE_ALIAS("sound-layout-69");
97 MODULE_ALIAS("sound-layout-70");
98 MODULE_ALIAS("sound-layout-72");
99 MODULE_ALIAS("sound-layout-76");
100 MODULE_ALIAS("sound-layout-80");
101 MODULE_ALIAS("sound-layout-82");
102 MODULE_ALIAS("sound-layout-84");
103 MODULE_ALIAS("sound-layout-86");
104 MODULE_ALIAS("sound-layout-90");
105 MODULE_ALIAS("sound-layout-92");
106 MODULE_ALIAS("sound-layout-94");
107 MODULE_ALIAS("sound-layout-96");
108 MODULE_ALIAS("sound-layout-98");
109 MODULE_ALIAS("sound-layout-100");
111 MODULE_ALIAS("aoa-device-id-14");
112 MODULE_ALIAS("aoa-device-id-22");
113 MODULE_ALIAS("aoa-device-id-31");
114 MODULE_ALIAS("aoa-device-id-35");
115 MODULE_ALIAS("aoa-device-id-44");
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_nolineout,
375 .connections = tas_connections_all,
382 .connections = tas_connections_noline,
389 .connections = tas_connections_nolineout,
396 .connections = onyx_connections_nomic,
400 .connections = topaz_input,
407 .connections = tas_connections_nolineout,
410 /* PowerMac10,1 (Mac Mini) */
414 .connections = toonie_connections,
421 .connections = onyx_connections_noheadphones,
424 /* unknown, untested, but this comes from Apple */
428 .connections = tas_connections_all,
434 .connections = tas_connections_nomic,
438 .connections = topaz_inout,
444 .connections = onyx_connections_noheadphones,
450 .connections = topaz_input,
456 .connections = onyx_connections_nomic,
462 .connections = topaz_input,
468 .connections = onyx_connections_noheadphones,
474 .connections = topaz_input,
480 .connections = onyx_connections_noheadphones,
484 .connections = topaz_output,
490 .connections = onyx_connections_noheadphones,
496 .connections = topaz_input,
502 .connections = tas_connections_nomic,
506 .connections = topaz_inout,
512 .connections = tas_connections_noline,
518 /* but it has an external mic?? how to select? */
519 .connections = onyx_connections_noheadphones,
525 .connections = toonie_connections,
531 .connections = topaz_input,
535 .connections = onyx_connections_noheadphones,
542 .connections = tas_connections_noline,
549 .connections = tas_connections_all,
556 .connections = tas_connections_all,
562 static struct layout *find_layout_by_id(unsigned int id)
567 while (l->codecs[0].name) {
568 if (l->layout_id == id)
575 static struct layout *find_layout_by_device(unsigned int id)
580 while (l->codecs[0].name) {
581 if (l->device_id == id)
588 static void use_layout(struct layout *l)
592 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
593 if (l->codecs[i].name) {
594 request_module("snd-aoa-codec-%s", l->codecs[i].name);
597 /* now we wait for the codecs to call us back */
602 struct layout_dev_ptr {
603 struct layout_dev *ptr;
607 struct list_head list;
608 struct soundbus_dev *sdev;
609 struct device_node *sound;
610 struct aoa_codec *codecs[MAX_CODECS_PER_BUS];
611 struct layout *layout;
612 struct gpio_runtime gpio;
614 /* we need these for headphone/lineout detection */
615 struct snd_kcontrol *headphone_ctrl;
616 struct snd_kcontrol *lineout_ctrl;
617 struct snd_kcontrol *speaker_ctrl;
618 struct snd_kcontrol *master_ctrl;
619 struct snd_kcontrol *headphone_detected_ctrl;
620 struct snd_kcontrol *lineout_detected_ctrl;
622 struct layout_dev_ptr selfptr_headphone;
623 struct layout_dev_ptr selfptr_lineout;
625 u32 have_lineout_detect:1,
626 have_headphone_detect:1,
627 switch_on_headphone:1,
631 static LIST_HEAD(layouts_list);
632 static int layouts_list_items;
633 /* this can go away but only if we allow multiple cards,
634 * make the fabric handle all the card stuff, etc... */
635 static struct layout_dev *layout_device;
637 #define control_info snd_ctl_boolean_mono_info
639 #define AMP_CONTROL(n, description) \
640 static int n##_control_get(struct snd_kcontrol *kcontrol, \
641 struct snd_ctl_elem_value *ucontrol) \
643 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
644 if (gpio->methods && gpio->methods->get_##n) \
645 ucontrol->value.integer.value[0] = \
646 gpio->methods->get_##n(gpio); \
649 static int n##_control_put(struct snd_kcontrol *kcontrol, \
650 struct snd_ctl_elem_value *ucontrol) \
652 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
653 if (gpio->methods && gpio->methods->set_##n) \
654 gpio->methods->set_##n(gpio, \
655 !!ucontrol->value.integer.value[0]); \
658 static const struct snd_kcontrol_new n##_ctl = { \
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
660 .name = description, \
661 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
662 .info = control_info, \
663 .get = n##_control_get, \
664 .put = n##_control_put, \
667 AMP_CONTROL(headphone, "Headphone Switch");
668 AMP_CONTROL(speakers, "Speakers Switch");
669 AMP_CONTROL(lineout, "Line-Out Switch");
670 AMP_CONTROL(master, "Master Switch");
672 static int detect_choice_get(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
675 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
677 switch (kcontrol->private_value) {
679 ucontrol->value.integer.value[0] = ldev->switch_on_headphone;
682 ucontrol->value.integer.value[0] = ldev->switch_on_lineout;
690 static int detect_choice_put(struct snd_kcontrol *kcontrol,
691 struct snd_ctl_elem_value *ucontrol)
693 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
695 switch (kcontrol->private_value) {
697 ldev->switch_on_headphone = !!ucontrol->value.integer.value[0];
700 ldev->switch_on_lineout = !!ucontrol->value.integer.value[0];
708 static const struct snd_kcontrol_new headphone_detect_choice = {
709 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
710 .name = "Headphone Detect Autoswitch",
711 .info = control_info,
712 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
713 .get = detect_choice_get,
714 .put = detect_choice_put,
718 static const struct snd_kcontrol_new lineout_detect_choice = {
719 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
720 .name = "Line-Out Detect Autoswitch",
721 .info = control_info,
722 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
723 .get = detect_choice_get,
724 .put = detect_choice_put,
728 static int detected_get(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
731 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
734 switch (kcontrol->private_value) {
736 v = ldev->gpio.methods->get_detect(&ldev->gpio,
737 AOA_NOTIFY_HEADPHONE);
740 v = ldev->gpio.methods->get_detect(&ldev->gpio,
741 AOA_NOTIFY_LINE_OUT);
746 ucontrol->value.integer.value[0] = v;
750 static const struct snd_kcontrol_new headphone_detected = {
751 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
752 .name = "Headphone Detected",
753 .info = control_info,
754 .access = SNDRV_CTL_ELEM_ACCESS_READ,
759 static const struct snd_kcontrol_new lineout_detected = {
760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
761 .name = "Line-Out Detected",
762 .info = control_info,
763 .access = SNDRV_CTL_ELEM_ACCESS_READ,
768 static int check_codec(struct aoa_codec *codec,
769 struct layout_dev *ldev,
770 struct codec_connect_info *cci)
774 struct codec_connection *cc;
776 /* if the codec has a 'codec' node, we require a reference */
777 if (of_node_name_eq(codec->node, "codec")) {
778 snprintf(propname, sizeof(propname),
779 "platform-%s-codec-ref", codec->name);
780 ref = of_get_property(ldev->sound, propname, NULL);
782 printk(KERN_INFO "snd-aoa-fabric-layout: "
783 "required property %s not present\n", propname);
786 if (*ref != codec->node->phandle) {
787 printk(KERN_INFO "snd-aoa-fabric-layout: "
788 "%s doesn't match!\n", propname);
792 if (layouts_list_items != 1) {
793 printk(KERN_INFO "snd-aoa-fabric-layout: "
794 "more than one soundbus, but no references.\n");
798 codec->soundbus_dev = ldev->sdev;
799 codec->gpio = &ldev->gpio;
801 cc = cci->connections;
805 printk(KERN_INFO "snd-aoa-fabric-layout: can use this codec\n");
807 codec->connected = 0;
808 codec->fabric_data = cc;
810 while (cc->connected) {
811 codec->connected |= 1<<cc->codec_bit;
818 static int layout_found_codec(struct aoa_codec *codec)
820 struct layout_dev *ldev;
823 list_for_each_entry(ldev, &layouts_list, list) {
824 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
825 if (!ldev->layout->codecs[i].name)
827 if (strcmp(ldev->layout->codecs[i].name, codec->name) == 0) {
828 if (check_codec(codec,
830 &ldev->layout->codecs[i]) == 0)
838 static void layout_remove_codec(struct aoa_codec *codec)
841 /* here remove the codec from the layout dev's
844 codec->soundbus_dev = NULL;
846 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
850 static void layout_notify(void *data)
852 struct layout_dev_ptr *dptr = data;
853 struct layout_dev *ldev;
855 struct snd_kcontrol *detected, *c;
856 struct snd_card *card = aoa_get_card();
859 if (data == &ldev->selfptr_headphone) {
860 v = ldev->gpio.methods->get_detect(&ldev->gpio, AOA_NOTIFY_HEADPHONE);
861 detected = ldev->headphone_detected_ctrl;
862 update = ldev->switch_on_headphone;
864 ldev->gpio.methods->set_speakers(&ldev->gpio, !v);
865 ldev->gpio.methods->set_headphone(&ldev->gpio, v);
866 ldev->gpio.methods->set_lineout(&ldev->gpio, 0);
868 } else if (data == &ldev->selfptr_lineout) {
869 v = ldev->gpio.methods->get_detect(&ldev->gpio, AOA_NOTIFY_LINE_OUT);
870 detected = ldev->lineout_detected_ctrl;
871 update = ldev->switch_on_lineout;
873 ldev->gpio.methods->set_speakers(&ldev->gpio, !v);
874 ldev->gpio.methods->set_headphone(&ldev->gpio, 0);
875 ldev->gpio.methods->set_lineout(&ldev->gpio, v);
881 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &detected->id);
883 c = ldev->headphone_ctrl;
885 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
886 c = ldev->speaker_ctrl;
888 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
889 c = ldev->lineout_ctrl;
891 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
895 static void layout_attached_codec(struct aoa_codec *codec)
897 struct codec_connection *cc;
898 struct snd_kcontrol *ctl;
899 int headphones, lineout;
900 struct layout_dev *ldev = layout_device;
902 /* need to add this codec to our codec array! */
904 cc = codec->fabric_data;
906 headphones = codec->gpio->methods->get_detect(codec->gpio,
907 AOA_NOTIFY_HEADPHONE);
908 lineout = codec->gpio->methods->get_detect(codec->gpio,
909 AOA_NOTIFY_LINE_OUT);
911 if (codec->gpio->methods->set_master) {
912 ctl = snd_ctl_new1(&master_ctl, codec->gpio);
913 ldev->master_ctrl = ctl;
914 aoa_snd_ctl_add(ctl);
916 while (cc->connected) {
917 if (cc->connected & CC_SPEAKERS) {
918 if (headphones <= 0 && lineout <= 0)
919 ldev->gpio.methods->set_speakers(codec->gpio, 1);
920 ctl = snd_ctl_new1(&speakers_ctl, codec->gpio);
921 ldev->speaker_ctrl = ctl;
922 aoa_snd_ctl_add(ctl);
924 if (cc->connected & CC_HEADPHONE) {
926 ldev->gpio.methods->set_headphone(codec->gpio, 1);
927 ctl = snd_ctl_new1(&headphone_ctl, codec->gpio);
928 ldev->headphone_ctrl = ctl;
929 aoa_snd_ctl_add(ctl);
930 ldev->have_headphone_detect =
932 ->set_notify(&ldev->gpio,
933 AOA_NOTIFY_HEADPHONE,
935 &ldev->selfptr_headphone);
936 if (ldev->have_headphone_detect) {
937 ctl = snd_ctl_new1(&headphone_detect_choice,
939 aoa_snd_ctl_add(ctl);
940 ctl = snd_ctl_new1(&headphone_detected,
942 ldev->headphone_detected_ctrl = ctl;
943 aoa_snd_ctl_add(ctl);
946 if (cc->connected & CC_LINEOUT) {
948 ldev->gpio.methods->set_lineout(codec->gpio, 1);
949 ctl = snd_ctl_new1(&lineout_ctl, codec->gpio);
950 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
951 strscpy(ctl->id.name,
952 "Headphone Switch", sizeof(ctl->id.name));
953 ldev->lineout_ctrl = ctl;
954 aoa_snd_ctl_add(ctl);
955 ldev->have_lineout_detect =
957 ->set_notify(&ldev->gpio,
960 &ldev->selfptr_lineout);
961 if (ldev->have_lineout_detect) {
962 ctl = snd_ctl_new1(&lineout_detect_choice,
964 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
965 strscpy(ctl->id.name,
966 "Headphone Detect Autoswitch",
967 sizeof(ctl->id.name));
968 aoa_snd_ctl_add(ctl);
969 ctl = snd_ctl_new1(&lineout_detected,
971 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
972 strscpy(ctl->id.name,
973 "Headphone Detected",
974 sizeof(ctl->id.name));
975 ldev->lineout_detected_ctrl = ctl;
976 aoa_snd_ctl_add(ctl);
981 /* now update initial state */
982 if (ldev->have_headphone_detect)
983 layout_notify(&ldev->selfptr_headphone);
984 if (ldev->have_lineout_detect)
985 layout_notify(&ldev->selfptr_lineout);
988 static struct aoa_fabric layout_fabric = {
989 .name = "SoundByLayout",
990 .owner = THIS_MODULE,
991 .found_codec = layout_found_codec,
992 .remove_codec = layout_remove_codec,
993 .attached_codec = layout_attached_codec,
996 static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
998 struct device_node *sound = NULL;
999 const unsigned int *id;
1000 struct layout *layout = NULL;
1001 struct layout_dev *ldev = NULL;
1004 /* hm, currently we can only have one ... */
1008 /* by breaking out we keep a reference */
1009 for_each_child_of_node(sdev->ofdev.dev.of_node, sound) {
1010 if (of_node_is_type(sound, "soundchip"))
1016 id = of_get_property(sound, "layout-id", NULL);
1018 layout = find_layout_by_id(*id);
1020 id = of_get_property(sound, "device-id", NULL);
1022 layout = find_layout_by_device(*id);
1026 printk(KERN_ERR "snd-aoa-fabric-layout: unknown layout\n");
1030 ldev = kzalloc(sizeof(struct layout_dev), GFP_KERNEL);
1034 layout_device = ldev;
1036 ldev->sound = sound;
1037 ldev->layout = layout;
1038 ldev->gpio.node = sound->parent;
1039 switch (layout->layout_id) {
1040 case 0: /* anything with device_id, not layout_id */
1041 case 41: /* that unknown machine no one seems to have */
1042 case 51: /* PowerBook5,4 */
1043 case 58: /* Mac Mini */
1044 ldev->gpio.methods = ftr_gpio_methods;
1046 "snd-aoa-fabric-layout: Using direct GPIOs\n");
1049 ldev->gpio.methods = pmf_gpio_methods;
1051 "snd-aoa-fabric-layout: Using PMF GPIOs\n");
1053 ldev->selfptr_headphone.ptr = ldev;
1054 ldev->selfptr_lineout.ptr = ldev;
1055 dev_set_drvdata(&sdev->ofdev.dev, ldev);
1056 list_add(&ldev->list, &layouts_list);
1057 layouts_list_items++;
1059 /* assign these before registering ourselves, so
1060 * callbacks that are done during registration
1061 * already have the values */
1062 sdev->pcmid = ldev->layout->pcmid;
1063 if (ldev->layout->busname) {
1064 sdev->pcmname = ldev->layout->busname;
1066 sdev->pcmname = "Master";
1069 ldev->gpio.methods->init(&ldev->gpio);
1071 err = aoa_fabric_register(&layout_fabric, &sdev->ofdev.dev);
1072 if (err && err != -EALREADY) {
1073 printk(KERN_INFO "snd-aoa-fabric-layout: can't use,"
1074 " another fabric is active!\n");
1079 ldev->switch_on_headphone = 1;
1080 ldev->switch_on_lineout = 1;
1083 /* we won't be using these then... */
1084 ldev->gpio.methods->exit(&ldev->gpio);
1085 /* reset if we didn't use it */
1086 sdev->pcmname = NULL;
1088 list_del(&ldev->list);
1089 layouts_list_items--;
1093 layout_device = NULL;
1097 static int aoa_fabric_layout_remove(struct soundbus_dev *sdev)
1099 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
1102 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
1103 if (ldev->codecs[i]) {
1104 aoa_fabric_unlink_codec(ldev->codecs[i]);
1106 ldev->codecs[i] = NULL;
1108 list_del(&ldev->list);
1109 layouts_list_items--;
1110 of_node_put(ldev->sound);
1112 ldev->gpio.methods->set_notify(&ldev->gpio,
1113 AOA_NOTIFY_HEADPHONE,
1116 ldev->gpio.methods->set_notify(&ldev->gpio,
1117 AOA_NOTIFY_LINE_OUT,
1121 ldev->gpio.methods->exit(&ldev->gpio);
1122 layout_device = NULL;
1125 sdev->pcmname = NULL;
1129 #ifdef CONFIG_PM_SLEEP
1130 static int aoa_fabric_layout_suspend(struct device *dev)
1132 struct layout_dev *ldev = dev_get_drvdata(dev);
1134 if (ldev->gpio.methods && ldev->gpio.methods->all_amps_off)
1135 ldev->gpio.methods->all_amps_off(&ldev->gpio);
1140 static int aoa_fabric_layout_resume(struct device *dev)
1142 struct layout_dev *ldev = dev_get_drvdata(dev);
1144 if (ldev->gpio.methods && ldev->gpio.methods->all_amps_restore)
1145 ldev->gpio.methods->all_amps_restore(&ldev->gpio);
1150 static SIMPLE_DEV_PM_OPS(aoa_fabric_layout_pm_ops,
1151 aoa_fabric_layout_suspend, aoa_fabric_layout_resume);
1155 static struct soundbus_driver aoa_soundbus_driver = {
1156 .name = "snd_aoa_soundbus_drv",
1157 .owner = THIS_MODULE,
1158 .probe = aoa_fabric_layout_probe,
1159 .remove = aoa_fabric_layout_remove,
1161 .owner = THIS_MODULE,
1162 #ifdef CONFIG_PM_SLEEP
1163 .pm = &aoa_fabric_layout_pm_ops,
1168 static int __init aoa_fabric_layout_init(void)
1170 return soundbus_register_driver(&aoa_soundbus_driver);
1173 static void __exit aoa_fabric_layout_exit(void)
1175 soundbus_unregister_driver(&aoa_soundbus_driver);
1176 aoa_fabric_unregister(&layout_fabric);
1179 module_init(aoa_fabric_layout_init);
1180 module_exit(aoa_fabric_layout_exit);