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.
10 #include <linux/list.h>
11 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/slab.h>
16 #include "../soundbus/soundbus.h"
18 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
19 MODULE_LICENSE("GPL");
20 MODULE_DESCRIPTION("Layout-ID fabric for snd-aoa");
22 #define MAX_CODECS_PER_BUS 2
24 /* These are the connections the layout fabric
25 * knows about. It doesn't really care about the
26 * input ones, but I thought I'd separate them
27 * to give them proper names. The thing is that
28 * Apple usually will distinguish the active output
29 * by GPIOs, while the active input is set directly
30 * on the codec. Hence we here tell the codec what
31 * we think is connected. This information is hard-
33 #define CC_SPEAKERS (1<<0)
34 #define CC_HEADPHONE (1<<1)
35 #define CC_LINEOUT (1<<2)
36 #define CC_DIGITALOUT (1<<3)
37 #define CC_LINEIN (1<<4)
38 #define CC_MICROPHONE (1<<5)
39 #define CC_DIGITALIN (1<<6)
40 /* pretty bogus but users complain...
41 * This is a flag saying that the LINEOUT
42 * should be renamed to HEADPHONE.
43 * be careful with input detection! */
44 #define CC_LINEOUT_LABELLED_HEADPHONE (1<<7)
46 struct codec_connection {
47 /* CC_ flags from above */
49 /* codec dependent bit to be set in the aoa_codec.connected field.
50 * This intentionally doesn't have any generic flags because the
51 * fabric has to know the codec anyway and all codecs might have
52 * different connectors */
56 struct codec_connect_info {
58 struct codec_connection *connections;
61 #define LAYOUT_FLAG_COMBO_LINEOUT_SPDIF (1<<0)
64 unsigned int layout_id, device_id;
65 struct codec_connect_info codecs[MAX_CODECS_PER_BUS];
68 /* if busname is not assigned, we use 'Master' below,
69 * so that our layout table doesn't need to be filled
71 * We only assign these two if we expect to find more
72 * than one soundbus, i.e. on those machines with
73 * multiple layout-ids */
78 MODULE_ALIAS("sound-layout-36");
79 MODULE_ALIAS("sound-layout-41");
80 MODULE_ALIAS("sound-layout-45");
81 MODULE_ALIAS("sound-layout-47");
82 MODULE_ALIAS("sound-layout-48");
83 MODULE_ALIAS("sound-layout-49");
84 MODULE_ALIAS("sound-layout-50");
85 MODULE_ALIAS("sound-layout-51");
86 MODULE_ALIAS("sound-layout-56");
87 MODULE_ALIAS("sound-layout-57");
88 MODULE_ALIAS("sound-layout-58");
89 MODULE_ALIAS("sound-layout-60");
90 MODULE_ALIAS("sound-layout-61");
91 MODULE_ALIAS("sound-layout-62");
92 MODULE_ALIAS("sound-layout-64");
93 MODULE_ALIAS("sound-layout-65");
94 MODULE_ALIAS("sound-layout-66");
95 MODULE_ALIAS("sound-layout-67");
96 MODULE_ALIAS("sound-layout-68");
97 MODULE_ALIAS("sound-layout-69");
98 MODULE_ALIAS("sound-layout-70");
99 MODULE_ALIAS("sound-layout-72");
100 MODULE_ALIAS("sound-layout-76");
101 MODULE_ALIAS("sound-layout-80");
102 MODULE_ALIAS("sound-layout-82");
103 MODULE_ALIAS("sound-layout-84");
104 MODULE_ALIAS("sound-layout-86");
105 MODULE_ALIAS("sound-layout-90");
106 MODULE_ALIAS("sound-layout-92");
107 MODULE_ALIAS("sound-layout-94");
108 MODULE_ALIAS("sound-layout-96");
109 MODULE_ALIAS("sound-layout-98");
110 MODULE_ALIAS("sound-layout-100");
112 MODULE_ALIAS("aoa-device-id-14");
113 MODULE_ALIAS("aoa-device-id-22");
114 MODULE_ALIAS("aoa-device-id-31");
115 MODULE_ALIAS("aoa-device-id-35");
116 MODULE_ALIAS("aoa-device-id-44");
118 /* onyx with all but microphone connected */
119 static struct codec_connection onyx_connections_nomic[] = {
121 .connected = CC_SPEAKERS | CC_HEADPHONE | CC_LINEOUT,
125 .connected = CC_DIGITALOUT,
129 .connected = CC_LINEIN,
132 {} /* terminate array by .connected == 0 */
135 /* onyx on machines without headphone */
136 static struct codec_connection onyx_connections_noheadphones[] = {
138 .connected = CC_SPEAKERS | CC_LINEOUT |
139 CC_LINEOUT_LABELLED_HEADPHONE,
143 .connected = CC_DIGITALOUT,
146 /* FIXME: are these correct? probably not for all the machines
147 * below ... If not this will need separating. */
149 .connected = CC_LINEIN,
153 .connected = CC_MICROPHONE,
156 {} /* terminate array by .connected == 0 */
159 /* onyx on machines with real line-out */
160 static struct codec_connection onyx_connections_reallineout[] = {
162 .connected = CC_SPEAKERS | CC_LINEOUT | CC_HEADPHONE,
166 .connected = CC_DIGITALOUT,
170 .connected = CC_LINEIN,
173 {} /* terminate array by .connected == 0 */
176 /* tas on machines without line out */
177 static struct codec_connection tas_connections_nolineout[] = {
179 .connected = CC_SPEAKERS | CC_HEADPHONE,
183 .connected = CC_LINEIN,
187 .connected = CC_MICROPHONE,
190 {} /* terminate array by .connected == 0 */
193 /* tas on machines with neither line out nor line in */
194 static struct codec_connection tas_connections_noline[] = {
196 .connected = CC_SPEAKERS | CC_HEADPHONE,
200 .connected = CC_MICROPHONE,
203 {} /* terminate array by .connected == 0 */
206 /* tas on machines without microphone */
207 static struct codec_connection tas_connections_nomic[] = {
209 .connected = CC_SPEAKERS | CC_HEADPHONE | CC_LINEOUT,
213 .connected = CC_LINEIN,
216 {} /* terminate array by .connected == 0 */
219 /* tas on machines with everything connected */
220 static struct codec_connection tas_connections_all[] = {
222 .connected = CC_SPEAKERS | CC_HEADPHONE | CC_LINEOUT,
226 .connected = CC_LINEIN,
230 .connected = CC_MICROPHONE,
233 {} /* terminate array by .connected == 0 */
236 static struct codec_connection toonie_connections[] = {
238 .connected = CC_SPEAKERS | CC_HEADPHONE,
241 {} /* terminate array by .connected == 0 */
244 static struct codec_connection topaz_input[] = {
246 .connected = CC_DIGITALIN,
249 {} /* terminate array by .connected == 0 */
252 static struct codec_connection topaz_output[] = {
254 .connected = CC_DIGITALOUT,
257 {} /* terminate array by .connected == 0 */
260 static struct codec_connection topaz_inout[] = {
262 .connected = CC_DIGITALIN,
266 .connected = CC_DIGITALOUT,
269 {} /* terminate array by .connected == 0 */
272 static struct layout layouts[] = {
273 /* last PowerBooks (15" Oct 2005) */
275 .flags = LAYOUT_FLAG_COMBO_LINEOUT_SPDIF,
278 .connections = onyx_connections_noheadphones,
282 .connections = topaz_input,
289 .connections = onyx_connections_reallineout,
296 .connections = topaz_input,
301 .flags = LAYOUT_FLAG_COMBO_LINEOUT_SPDIF,
304 .connections = onyx_connections_noheadphones,
311 .connections = topaz_input,
314 /* PowerBook5,9 [17" Oct 2005] */
316 .flags = LAYOUT_FLAG_COMBO_LINEOUT_SPDIF,
319 .connections = onyx_connections_noheadphones,
323 .connections = topaz_input,
330 .connections = onyx_connections_noheadphones,
334 .connections = topaz_input,
337 /* Quad PowerMac (analog in, analog/digital out) */
341 .connections = onyx_connections_nomic,
344 /* Quad PowerMac (digital in) */
348 .connections = topaz_input,
350 .busname = "digital in", .pcmid = 1 },
351 /* Early 2005 PowerBook (PowerBook 5,6) */
355 .connections = tas_connections_nolineout,
362 .connections = tas_connections_nolineout,
369 .connections = tas_connections_nolineout,
376 .connections = tas_connections_all,
383 .connections = tas_connections_noline,
390 .connections = tas_connections_nolineout,
397 .connections = onyx_connections_nomic,
401 .connections = topaz_input,
408 .connections = tas_connections_nolineout,
411 /* PowerMac10,1 (Mac Mini) */
415 .connections = toonie_connections,
422 .connections = onyx_connections_noheadphones,
425 /* unknown, untested, but this comes from Apple */
429 .connections = tas_connections_all,
435 .connections = tas_connections_nomic,
439 .connections = topaz_inout,
445 .connections = onyx_connections_noheadphones,
451 .connections = topaz_input,
457 .connections = onyx_connections_nomic,
463 .connections = topaz_input,
469 .connections = onyx_connections_noheadphones,
475 .connections = topaz_input,
481 .connections = onyx_connections_noheadphones,
485 .connections = topaz_output,
491 .connections = onyx_connections_noheadphones,
497 .connections = topaz_input,
503 .connections = tas_connections_nomic,
507 .connections = topaz_inout,
513 .connections = tas_connections_noline,
519 /* but it has an external mic?? how to select? */
520 .connections = onyx_connections_noheadphones,
526 .connections = toonie_connections,
532 .connections = topaz_input,
536 .connections = onyx_connections_noheadphones,
543 .connections = tas_connections_noline,
550 .connections = tas_connections_all,
557 .connections = tas_connections_all,
563 static struct layout *find_layout_by_id(unsigned int id)
568 while (l->codecs[0].name) {
569 if (l->layout_id == id)
576 static struct layout *find_layout_by_device(unsigned int id)
581 while (l->codecs[0].name) {
582 if (l->device_id == id)
589 static void use_layout(struct layout *l)
593 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
594 if (l->codecs[i].name) {
595 request_module("snd-aoa-codec-%s", l->codecs[i].name);
598 /* now we wait for the codecs to call us back */
603 struct layout_dev_ptr {
604 struct layout_dev *ptr;
608 struct list_head list;
609 struct soundbus_dev *sdev;
610 struct device_node *sound;
611 struct aoa_codec *codecs[MAX_CODECS_PER_BUS];
612 struct layout *layout;
613 struct gpio_runtime gpio;
615 /* we need these for headphone/lineout detection */
616 struct snd_kcontrol *headphone_ctrl;
617 struct snd_kcontrol *lineout_ctrl;
618 struct snd_kcontrol *speaker_ctrl;
619 struct snd_kcontrol *master_ctrl;
620 struct snd_kcontrol *headphone_detected_ctrl;
621 struct snd_kcontrol *lineout_detected_ctrl;
623 struct layout_dev_ptr selfptr_headphone;
624 struct layout_dev_ptr selfptr_lineout;
626 u32 have_lineout_detect:1,
627 have_headphone_detect:1,
628 switch_on_headphone:1,
632 static LIST_HEAD(layouts_list);
633 static int layouts_list_items;
634 /* this can go away but only if we allow multiple cards,
635 * make the fabric handle all the card stuff, etc... */
636 static struct layout_dev *layout_device;
638 #define control_info snd_ctl_boolean_mono_info
640 #define AMP_CONTROL(n, description) \
641 static int n##_control_get(struct snd_kcontrol *kcontrol, \
642 struct snd_ctl_elem_value *ucontrol) \
644 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
645 if (gpio->methods && gpio->methods->get_##n) \
646 ucontrol->value.integer.value[0] = \
647 gpio->methods->get_##n(gpio); \
650 static int n##_control_put(struct snd_kcontrol *kcontrol, \
651 struct snd_ctl_elem_value *ucontrol) \
653 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
654 if (gpio->methods && gpio->methods->set_##n) \
655 gpio->methods->set_##n(gpio, \
656 !!ucontrol->value.integer.value[0]); \
659 static const struct snd_kcontrol_new n##_ctl = { \
660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
661 .name = description, \
662 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
663 .info = control_info, \
664 .get = n##_control_get, \
665 .put = n##_control_put, \
668 AMP_CONTROL(headphone, "Headphone Switch");
669 AMP_CONTROL(speakers, "Speakers Switch");
670 AMP_CONTROL(lineout, "Line-Out Switch");
671 AMP_CONTROL(master, "Master Switch");
673 static int detect_choice_get(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_value *ucontrol)
676 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
678 switch (kcontrol->private_value) {
680 ucontrol->value.integer.value[0] = ldev->switch_on_headphone;
683 ucontrol->value.integer.value[0] = ldev->switch_on_lineout;
691 static int detect_choice_put(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_value *ucontrol)
694 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
696 switch (kcontrol->private_value) {
698 ldev->switch_on_headphone = !!ucontrol->value.integer.value[0];
701 ldev->switch_on_lineout = !!ucontrol->value.integer.value[0];
709 static const struct snd_kcontrol_new headphone_detect_choice = {
710 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
711 .name = "Headphone Detect Autoswitch",
712 .info = control_info,
713 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
714 .get = detect_choice_get,
715 .put = detect_choice_put,
719 static const struct snd_kcontrol_new lineout_detect_choice = {
720 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
721 .name = "Line-Out Detect Autoswitch",
722 .info = control_info,
723 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
724 .get = detect_choice_get,
725 .put = detect_choice_put,
729 static int detected_get(struct snd_kcontrol *kcontrol,
730 struct snd_ctl_elem_value *ucontrol)
732 struct layout_dev *ldev = snd_kcontrol_chip(kcontrol);
735 switch (kcontrol->private_value) {
737 v = ldev->gpio.methods->get_detect(&ldev->gpio,
738 AOA_NOTIFY_HEADPHONE);
741 v = ldev->gpio.methods->get_detect(&ldev->gpio,
742 AOA_NOTIFY_LINE_OUT);
747 ucontrol->value.integer.value[0] = v;
751 static const struct snd_kcontrol_new headphone_detected = {
752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
753 .name = "Headphone Detected",
754 .info = control_info,
755 .access = SNDRV_CTL_ELEM_ACCESS_READ,
760 static const struct snd_kcontrol_new lineout_detected = {
761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
762 .name = "Line-Out Detected",
763 .info = control_info,
764 .access = SNDRV_CTL_ELEM_ACCESS_READ,
769 static int check_codec(struct aoa_codec *codec,
770 struct layout_dev *ldev,
771 struct codec_connect_info *cci)
775 struct codec_connection *cc;
777 /* if the codec has a 'codec' node, we require a reference */
778 if (of_node_name_eq(codec->node, "codec")) {
779 snprintf(propname, sizeof(propname),
780 "platform-%s-codec-ref", codec->name);
781 ref = of_get_property(ldev->sound, propname, NULL);
783 printk(KERN_INFO "snd-aoa-fabric-layout: "
784 "required property %s not present\n", propname);
787 if (*ref != codec->node->phandle) {
788 printk(KERN_INFO "snd-aoa-fabric-layout: "
789 "%s doesn't match!\n", propname);
793 if (layouts_list_items != 1) {
794 printk(KERN_INFO "snd-aoa-fabric-layout: "
795 "more than one soundbus, but no references.\n");
799 codec->soundbus_dev = ldev->sdev;
800 codec->gpio = &ldev->gpio;
802 cc = cci->connections;
806 printk(KERN_INFO "snd-aoa-fabric-layout: can use this codec\n");
808 codec->connected = 0;
809 codec->fabric_data = cc;
811 while (cc->connected) {
812 codec->connected |= 1<<cc->codec_bit;
819 static int layout_found_codec(struct aoa_codec *codec)
821 struct layout_dev *ldev;
824 list_for_each_entry(ldev, &layouts_list, list) {
825 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
826 if (!ldev->layout->codecs[i].name)
828 if (strcmp(ldev->layout->codecs[i].name, codec->name) == 0) {
829 if (check_codec(codec,
831 &ldev->layout->codecs[i]) == 0)
839 static void layout_remove_codec(struct aoa_codec *codec)
842 /* here remove the codec from the layout dev's
845 codec->soundbus_dev = NULL;
847 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
851 static void layout_notify(void *data)
853 struct layout_dev_ptr *dptr = data;
854 struct layout_dev *ldev;
856 struct snd_kcontrol *detected, *c;
857 struct snd_card *card = aoa_get_card();
860 if (data == &ldev->selfptr_headphone) {
861 v = ldev->gpio.methods->get_detect(&ldev->gpio, AOA_NOTIFY_HEADPHONE);
862 detected = ldev->headphone_detected_ctrl;
863 update = ldev->switch_on_headphone;
865 ldev->gpio.methods->set_speakers(&ldev->gpio, !v);
866 ldev->gpio.methods->set_headphone(&ldev->gpio, v);
867 ldev->gpio.methods->set_lineout(&ldev->gpio, 0);
869 } else if (data == &ldev->selfptr_lineout) {
870 v = ldev->gpio.methods->get_detect(&ldev->gpio, AOA_NOTIFY_LINE_OUT);
871 detected = ldev->lineout_detected_ctrl;
872 update = ldev->switch_on_lineout;
874 ldev->gpio.methods->set_speakers(&ldev->gpio, !v);
875 ldev->gpio.methods->set_headphone(&ldev->gpio, 0);
876 ldev->gpio.methods->set_lineout(&ldev->gpio, v);
882 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &detected->id);
884 c = ldev->headphone_ctrl;
886 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
887 c = ldev->speaker_ctrl;
889 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
890 c = ldev->lineout_ctrl;
892 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &c->id);
896 static void layout_attached_codec(struct aoa_codec *codec)
898 struct codec_connection *cc;
899 struct snd_kcontrol *ctl;
900 int headphones, lineout;
901 struct layout_dev *ldev = layout_device;
903 /* need to add this codec to our codec array! */
905 cc = codec->fabric_data;
907 headphones = codec->gpio->methods->get_detect(codec->gpio,
908 AOA_NOTIFY_HEADPHONE);
909 lineout = codec->gpio->methods->get_detect(codec->gpio,
910 AOA_NOTIFY_LINE_OUT);
912 if (codec->gpio->methods->set_master) {
913 ctl = snd_ctl_new1(&master_ctl, codec->gpio);
914 ldev->master_ctrl = ctl;
915 aoa_snd_ctl_add(ctl);
917 while (cc->connected) {
918 if (cc->connected & CC_SPEAKERS) {
919 if (headphones <= 0 && lineout <= 0)
920 ldev->gpio.methods->set_speakers(codec->gpio, 1);
921 ctl = snd_ctl_new1(&speakers_ctl, codec->gpio);
922 ldev->speaker_ctrl = ctl;
923 aoa_snd_ctl_add(ctl);
925 if (cc->connected & CC_HEADPHONE) {
927 ldev->gpio.methods->set_headphone(codec->gpio, 1);
928 ctl = snd_ctl_new1(&headphone_ctl, codec->gpio);
929 ldev->headphone_ctrl = ctl;
930 aoa_snd_ctl_add(ctl);
931 ldev->have_headphone_detect =
933 ->set_notify(&ldev->gpio,
934 AOA_NOTIFY_HEADPHONE,
936 &ldev->selfptr_headphone);
937 if (ldev->have_headphone_detect) {
938 ctl = snd_ctl_new1(&headphone_detect_choice,
940 aoa_snd_ctl_add(ctl);
941 ctl = snd_ctl_new1(&headphone_detected,
943 ldev->headphone_detected_ctrl = ctl;
944 aoa_snd_ctl_add(ctl);
947 if (cc->connected & CC_LINEOUT) {
949 ldev->gpio.methods->set_lineout(codec->gpio, 1);
950 ctl = snd_ctl_new1(&lineout_ctl, codec->gpio);
951 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
952 strscpy(ctl->id.name,
953 "Headphone Switch", sizeof(ctl->id.name));
954 ldev->lineout_ctrl = ctl;
955 aoa_snd_ctl_add(ctl);
956 ldev->have_lineout_detect =
958 ->set_notify(&ldev->gpio,
961 &ldev->selfptr_lineout);
962 if (ldev->have_lineout_detect) {
963 ctl = snd_ctl_new1(&lineout_detect_choice,
965 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
966 strscpy(ctl->id.name,
967 "Headphone Detect Autoswitch",
968 sizeof(ctl->id.name));
969 aoa_snd_ctl_add(ctl);
970 ctl = snd_ctl_new1(&lineout_detected,
972 if (cc->connected & CC_LINEOUT_LABELLED_HEADPHONE)
973 strscpy(ctl->id.name,
974 "Headphone Detected",
975 sizeof(ctl->id.name));
976 ldev->lineout_detected_ctrl = ctl;
977 aoa_snd_ctl_add(ctl);
982 /* now update initial state */
983 if (ldev->have_headphone_detect)
984 layout_notify(&ldev->selfptr_headphone);
985 if (ldev->have_lineout_detect)
986 layout_notify(&ldev->selfptr_lineout);
989 static struct aoa_fabric layout_fabric = {
990 .name = "SoundByLayout",
991 .owner = THIS_MODULE,
992 .found_codec = layout_found_codec,
993 .remove_codec = layout_remove_codec,
994 .attached_codec = layout_attached_codec,
997 static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
999 struct device_node *sound = NULL;
1000 const unsigned int *id;
1001 struct layout *layout = NULL;
1002 struct layout_dev *ldev = NULL;
1005 /* hm, currently we can only have one ... */
1009 /* by breaking out we keep a reference */
1010 for_each_child_of_node(sdev->ofdev.dev.of_node, sound) {
1011 if (of_node_is_type(sound, "soundchip"))
1017 id = of_get_property(sound, "layout-id", NULL);
1019 layout = find_layout_by_id(*id);
1021 id = of_get_property(sound, "device-id", NULL);
1023 layout = find_layout_by_device(*id);
1027 printk(KERN_ERR "snd-aoa-fabric-layout: unknown layout\n");
1031 ldev = kzalloc(sizeof(struct layout_dev), GFP_KERNEL);
1035 layout_device = ldev;
1037 ldev->sound = sound;
1038 ldev->layout = layout;
1039 ldev->gpio.node = sound->parent;
1040 switch (layout->layout_id) {
1041 case 0: /* anything with device_id, not layout_id */
1042 case 41: /* that unknown machine no one seems to have */
1043 case 51: /* PowerBook5,4 */
1044 case 58: /* Mac Mini */
1045 ldev->gpio.methods = ftr_gpio_methods;
1047 "snd-aoa-fabric-layout: Using direct GPIOs\n");
1050 ldev->gpio.methods = pmf_gpio_methods;
1052 "snd-aoa-fabric-layout: Using PMF GPIOs\n");
1054 ldev->selfptr_headphone.ptr = ldev;
1055 ldev->selfptr_lineout.ptr = ldev;
1056 dev_set_drvdata(&sdev->ofdev.dev, ldev);
1057 list_add(&ldev->list, &layouts_list);
1058 layouts_list_items++;
1060 /* assign these before registering ourselves, so
1061 * callbacks that are done during registration
1062 * already have the values */
1063 sdev->pcmid = ldev->layout->pcmid;
1064 if (ldev->layout->busname) {
1065 sdev->pcmname = ldev->layout->busname;
1067 sdev->pcmname = "Master";
1070 ldev->gpio.methods->init(&ldev->gpio);
1072 err = aoa_fabric_register(&layout_fabric, &sdev->ofdev.dev);
1073 if (err && err != -EALREADY) {
1074 printk(KERN_INFO "snd-aoa-fabric-layout: can't use,"
1075 " another fabric is active!\n");
1080 ldev->switch_on_headphone = 1;
1081 ldev->switch_on_lineout = 1;
1084 /* we won't be using these then... */
1085 ldev->gpio.methods->exit(&ldev->gpio);
1086 /* reset if we didn't use it */
1087 sdev->pcmname = NULL;
1089 list_del(&ldev->list);
1090 layouts_list_items--;
1094 layout_device = NULL;
1098 static void aoa_fabric_layout_remove(struct soundbus_dev *sdev)
1100 struct layout_dev *ldev = dev_get_drvdata(&sdev->ofdev.dev);
1103 for (i=0; i<MAX_CODECS_PER_BUS; i++) {
1104 if (ldev->codecs[i]) {
1105 aoa_fabric_unlink_codec(ldev->codecs[i]);
1107 ldev->codecs[i] = NULL;
1109 list_del(&ldev->list);
1110 layouts_list_items--;
1111 of_node_put(ldev->sound);
1113 ldev->gpio.methods->set_notify(&ldev->gpio,
1114 AOA_NOTIFY_HEADPHONE,
1117 ldev->gpio.methods->set_notify(&ldev->gpio,
1118 AOA_NOTIFY_LINE_OUT,
1122 ldev->gpio.methods->exit(&ldev->gpio);
1123 layout_device = NULL;
1126 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);