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>
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-35");
116 /* onyx with all but microphone connected */
117 static struct codec_connection onyx_connections_nomic
[] = {
119 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
123 .connected
= CC_DIGITALOUT
,
127 .connected
= CC_LINEIN
,
130 {} /* terminate array by .connected == 0 */
133 /* onyx on machines without headphone */
134 static struct codec_connection onyx_connections_noheadphones
[] = {
136 .connected
= CC_SPEAKERS
| CC_LINEOUT
|
137 CC_LINEOUT_LABELLED_HEADPHONE
,
141 .connected
= CC_DIGITALOUT
,
144 /* FIXME: are these correct? probably not for all the machines
145 * below ... If not this will need separating. */
147 .connected
= CC_LINEIN
,
151 .connected
= CC_MICROPHONE
,
154 {} /* terminate array by .connected == 0 */
157 /* onyx on machines with real line-out */
158 static struct codec_connection onyx_connections_reallineout
[] = {
160 .connected
= CC_SPEAKERS
| CC_LINEOUT
| CC_HEADPHONE
,
164 .connected
= CC_DIGITALOUT
,
168 .connected
= CC_LINEIN
,
171 {} /* terminate array by .connected == 0 */
174 /* tas on machines without line out */
175 static struct codec_connection tas_connections_nolineout
[] = {
177 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
181 .connected
= CC_LINEIN
,
185 .connected
= CC_MICROPHONE
,
188 {} /* terminate array by .connected == 0 */
191 /* tas on machines with neither line out nor line in */
192 static struct codec_connection tas_connections_noline
[] = {
194 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
198 .connected
= CC_MICROPHONE
,
201 {} /* terminate array by .connected == 0 */
204 /* tas on machines without microphone */
205 static struct codec_connection tas_connections_nomic
[] = {
207 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
211 .connected
= CC_LINEIN
,
214 {} /* terminate array by .connected == 0 */
217 /* tas on machines with everything connected */
218 static struct codec_connection tas_connections_all
[] = {
220 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
224 .connected
= CC_LINEIN
,
228 .connected
= CC_MICROPHONE
,
231 {} /* terminate array by .connected == 0 */
234 static struct codec_connection toonie_connections
[] = {
236 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
239 {} /* terminate array by .connected == 0 */
242 static struct codec_connection topaz_input
[] = {
244 .connected
= CC_DIGITALIN
,
247 {} /* terminate array by .connected == 0 */
250 static struct codec_connection topaz_output
[] = {
252 .connected
= CC_DIGITALOUT
,
255 {} /* terminate array by .connected == 0 */
258 static struct codec_connection topaz_inout
[] = {
260 .connected
= CC_DIGITALIN
,
264 .connected
= CC_DIGITALOUT
,
267 {} /* terminate array by .connected == 0 */
270 static struct layout layouts
[] = {
271 /* last PowerBooks (15" Oct 2005) */
273 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
276 .connections
= onyx_connections_noheadphones
,
280 .connections
= topaz_input
,
287 .connections
= onyx_connections_reallineout
,
294 .connections
= topaz_input
,
299 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
302 .connections
= onyx_connections_noheadphones
,
309 .connections
= topaz_input
,
312 /* PowerBook5,9 [17" Oct 2005] */
314 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
317 .connections
= onyx_connections_noheadphones
,
321 .connections
= topaz_input
,
328 .connections
= onyx_connections_noheadphones
,
332 .connections
= topaz_input
,
335 /* Quad PowerMac (analog in, analog/digital out) */
339 .connections
= onyx_connections_nomic
,
342 /* Quad PowerMac (digital in) */
346 .connections
= topaz_input
,
348 .busname
= "digital in", .pcmid
= 1 },
349 /* Early 2005 PowerBook (PowerBook 5,6) */
353 .connections
= tas_connections_nolineout
,
360 .connections
= tas_connections_nolineout
,
367 .connections
= tas_connections_noline
,
374 .connections
= tas_connections_nolineout
,
381 .connections
= onyx_connections_nomic
,
385 .connections
= topaz_input
,
392 .connections
= tas_connections_nolineout
,
395 /* PowerMac10,1 (Mac Mini) */
399 .connections
= toonie_connections
,
406 .connections
= onyx_connections_noheadphones
,
409 /* unknown, untested, but this comes from Apple */
413 .connections
= tas_connections_all
,
419 .connections
= tas_connections_nomic
,
423 .connections
= topaz_inout
,
429 .connections
= onyx_connections_noheadphones
,
435 .connections
= topaz_input
,
441 .connections
= onyx_connections_nomic
,
447 .connections
= topaz_input
,
453 .connections
= onyx_connections_noheadphones
,
459 .connections
= topaz_input
,
465 .connections
= onyx_connections_noheadphones
,
469 .connections
= topaz_output
,
475 .connections
= onyx_connections_noheadphones
,
481 .connections
= topaz_input
,
487 .connections
= tas_connections_nomic
,
491 .connections
= topaz_inout
,
497 .connections
= tas_connections_noline
,
503 /* but it has an external mic?? how to select? */
504 .connections
= onyx_connections_noheadphones
,
510 .connections
= toonie_connections
,
516 .connections
= topaz_input
,
520 .connections
= onyx_connections_noheadphones
,
527 .connections
= tas_connections_noline
,
534 .connections
= tas_connections_all
,
541 .connections
= tas_connections_all
,
547 static struct layout
*find_layout_by_id(unsigned int id
)
552 while (l
->codecs
[0].name
) {
553 if (l
->layout_id
== id
)
560 static struct layout
*find_layout_by_device(unsigned int id
)
565 while (l
->codecs
[0].name
) {
566 if (l
->device_id
== id
)
573 static void use_layout(struct layout
*l
)
577 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
578 if (l
->codecs
[i
].name
) {
579 request_module("snd-aoa-codec-%s", l
->codecs
[i
].name
);
582 /* now we wait for the codecs to call us back */
587 struct layout_dev_ptr
{
588 struct layout_dev
*ptr
;
592 struct list_head list
;
593 struct soundbus_dev
*sdev
;
594 struct device_node
*sound
;
595 struct aoa_codec
*codecs
[MAX_CODECS_PER_BUS
];
596 struct layout
*layout
;
597 struct gpio_runtime gpio
;
599 /* we need these for headphone/lineout detection */
600 struct snd_kcontrol
*headphone_ctrl
;
601 struct snd_kcontrol
*lineout_ctrl
;
602 struct snd_kcontrol
*speaker_ctrl
;
603 struct snd_kcontrol
*master_ctrl
;
604 struct snd_kcontrol
*headphone_detected_ctrl
;
605 struct snd_kcontrol
*lineout_detected_ctrl
;
607 struct layout_dev_ptr selfptr_headphone
;
608 struct layout_dev_ptr selfptr_lineout
;
610 u32 have_lineout_detect
:1,
611 have_headphone_detect
:1,
612 switch_on_headphone
:1,
616 static LIST_HEAD(layouts_list
);
617 static int layouts_list_items
;
618 /* this can go away but only if we allow multiple cards,
619 * make the fabric handle all the card stuff, etc... */
620 static struct layout_dev
*layout_device
;
622 #define control_info snd_ctl_boolean_mono_info
624 #define AMP_CONTROL(n, description) \
625 static int n##_control_get(struct snd_kcontrol *kcontrol, \
626 struct snd_ctl_elem_value *ucontrol) \
628 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
629 if (gpio->methods && gpio->methods->get_##n) \
630 ucontrol->value.integer.value[0] = \
631 gpio->methods->get_##n(gpio); \
634 static int n##_control_put(struct snd_kcontrol *kcontrol, \
635 struct snd_ctl_elem_value *ucontrol) \
637 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
638 if (gpio->methods && gpio->methods->get_##n) \
639 gpio->methods->set_##n(gpio, \
640 !!ucontrol->value.integer.value[0]); \
643 static struct snd_kcontrol_new n##_ctl = { \
644 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
645 .name = description, \
646 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
647 .info = control_info, \
648 .get = n##_control_get, \
649 .put = n##_control_put, \
652 AMP_CONTROL(headphone
, "Headphone Switch");
653 AMP_CONTROL(speakers
, "Speakers Switch");
654 AMP_CONTROL(lineout
, "Line-Out Switch");
655 AMP_CONTROL(master
, "Master Switch");
657 static int detect_choice_get(struct snd_kcontrol
*kcontrol
,
658 struct snd_ctl_elem_value
*ucontrol
)
660 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
662 switch (kcontrol
->private_value
) {
664 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_headphone
;
667 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_lineout
;
675 static int detect_choice_put(struct snd_kcontrol
*kcontrol
,
676 struct snd_ctl_elem_value
*ucontrol
)
678 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
680 switch (kcontrol
->private_value
) {
682 ldev
->switch_on_headphone
= !!ucontrol
->value
.integer
.value
[0];
685 ldev
->switch_on_lineout
= !!ucontrol
->value
.integer
.value
[0];
693 static struct snd_kcontrol_new headphone_detect_choice
= {
694 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
695 .name
= "Headphone Detect Autoswitch",
696 .info
= control_info
,
697 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
698 .get
= detect_choice_get
,
699 .put
= detect_choice_put
,
703 static struct snd_kcontrol_new lineout_detect_choice
= {
704 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
705 .name
= "Line-Out Detect Autoswitch",
706 .info
= control_info
,
707 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
708 .get
= detect_choice_get
,
709 .put
= detect_choice_put
,
713 static int detected_get(struct snd_kcontrol
*kcontrol
,
714 struct snd_ctl_elem_value
*ucontrol
)
716 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
719 switch (kcontrol
->private_value
) {
721 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
722 AOA_NOTIFY_HEADPHONE
);
725 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
726 AOA_NOTIFY_LINE_OUT
);
731 ucontrol
->value
.integer
.value
[0] = v
;
735 static struct snd_kcontrol_new headphone_detected
= {
736 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
737 .name
= "Headphone Detected",
738 .info
= control_info
,
739 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
744 static struct snd_kcontrol_new lineout_detected
= {
745 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
746 .name
= "Line-Out Detected",
747 .info
= control_info
,
748 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
753 static int check_codec(struct aoa_codec
*codec
,
754 struct layout_dev
*ldev
,
755 struct codec_connect_info
*cci
)
759 struct codec_connection
*cc
;
761 /* if the codec has a 'codec' node, we require a reference */
762 if (codec
->node
&& (strcmp(codec
->node
->name
, "codec") == 0)) {
763 snprintf(propname
, sizeof(propname
),
764 "platform-%s-codec-ref", codec
->name
);
765 ref
= of_get_property(ldev
->sound
, propname
, NULL
);
767 printk(KERN_INFO
"snd-aoa-fabric-layout: "
768 "required property %s not present\n", propname
);
771 if (*ref
!= codec
->node
->linux_phandle
) {
772 printk(KERN_INFO
"snd-aoa-fabric-layout: "
773 "%s doesn't match!\n", propname
);
777 if (layouts_list_items
!= 1) {
778 printk(KERN_INFO
"snd-aoa-fabric-layout: "
779 "more than one soundbus, but no references.\n");
783 codec
->soundbus_dev
= ldev
->sdev
;
784 codec
->gpio
= &ldev
->gpio
;
786 cc
= cci
->connections
;
790 printk(KERN_INFO
"snd-aoa-fabric-layout: can use this codec\n");
792 codec
->connected
= 0;
793 codec
->fabric_data
= cc
;
795 while (cc
->connected
) {
796 codec
->connected
|= 1<<cc
->codec_bit
;
803 static int layout_found_codec(struct aoa_codec
*codec
)
805 struct layout_dev
*ldev
;
808 list_for_each_entry(ldev
, &layouts_list
, list
) {
809 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
810 if (!ldev
->layout
->codecs
[i
].name
)
812 if (strcmp(ldev
->layout
->codecs
[i
].name
, codec
->name
) == 0) {
813 if (check_codec(codec
,
815 &ldev
->layout
->codecs
[i
]) == 0)
823 static void layout_remove_codec(struct aoa_codec
*codec
)
826 /* here remove the codec from the layout dev's
829 codec
->soundbus_dev
= NULL
;
831 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
835 static void layout_notify(void *data
)
837 struct layout_dev_ptr
*dptr
= data
;
838 struct layout_dev
*ldev
;
840 struct snd_kcontrol
*detected
, *c
;
841 struct snd_card
*card
= aoa_get_card();
844 if (data
== &ldev
->selfptr_headphone
) {
845 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_HEADPHONE
);
846 detected
= ldev
->headphone_detected_ctrl
;
847 update
= ldev
->switch_on_headphone
;
849 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
850 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, v
);
851 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, 0);
853 } else if (data
== &ldev
->selfptr_lineout
) {
854 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_LINE_OUT
);
855 detected
= ldev
->lineout_detected_ctrl
;
856 update
= ldev
->switch_on_lineout
;
858 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
859 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, 0);
860 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, v
);
866 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &detected
->id
);
868 c
= ldev
->headphone_ctrl
;
870 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
871 c
= ldev
->speaker_ctrl
;
873 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
874 c
= ldev
->lineout_ctrl
;
876 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
880 static void layout_attached_codec(struct aoa_codec
*codec
)
882 struct codec_connection
*cc
;
883 struct snd_kcontrol
*ctl
;
884 int headphones
, lineout
;
885 struct layout_dev
*ldev
= layout_device
;
887 /* need to add this codec to our codec array! */
889 cc
= codec
->fabric_data
;
891 headphones
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
892 AOA_NOTIFY_HEADPHONE
);
893 lineout
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
894 AOA_NOTIFY_LINE_OUT
);
896 if (codec
->gpio
->methods
->set_master
) {
897 ctl
= snd_ctl_new1(&master_ctl
, codec
->gpio
);
898 ldev
->master_ctrl
= ctl
;
899 aoa_snd_ctl_add(ctl
);
901 while (cc
->connected
) {
902 if (cc
->connected
& CC_SPEAKERS
) {
903 if (headphones
<= 0 && lineout
<= 0)
904 ldev
->gpio
.methods
->set_speakers(codec
->gpio
, 1);
905 ctl
= snd_ctl_new1(&speakers_ctl
, codec
->gpio
);
906 ldev
->speaker_ctrl
= ctl
;
907 aoa_snd_ctl_add(ctl
);
909 if (cc
->connected
& CC_HEADPHONE
) {
911 ldev
->gpio
.methods
->set_headphone(codec
->gpio
, 1);
912 ctl
= snd_ctl_new1(&headphone_ctl
, codec
->gpio
);
913 ldev
->headphone_ctrl
= ctl
;
914 aoa_snd_ctl_add(ctl
);
915 ldev
->have_headphone_detect
=
917 ->set_notify(&ldev
->gpio
,
918 AOA_NOTIFY_HEADPHONE
,
920 &ldev
->selfptr_headphone
);
921 if (ldev
->have_headphone_detect
) {
922 ctl
= snd_ctl_new1(&headphone_detect_choice
,
924 aoa_snd_ctl_add(ctl
);
925 ctl
= snd_ctl_new1(&headphone_detected
,
927 ldev
->headphone_detected_ctrl
= ctl
;
928 aoa_snd_ctl_add(ctl
);
931 if (cc
->connected
& CC_LINEOUT
) {
933 ldev
->gpio
.methods
->set_lineout(codec
->gpio
, 1);
934 ctl
= snd_ctl_new1(&lineout_ctl
, codec
->gpio
);
935 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
936 strlcpy(ctl
->id
.name
,
937 "Headphone Switch", sizeof(ctl
->id
.name
));
938 ldev
->lineout_ctrl
= ctl
;
939 aoa_snd_ctl_add(ctl
);
940 ldev
->have_lineout_detect
=
942 ->set_notify(&ldev
->gpio
,
945 &ldev
->selfptr_lineout
);
946 if (ldev
->have_lineout_detect
) {
947 ctl
= snd_ctl_new1(&lineout_detect_choice
,
949 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
950 strlcpy(ctl
->id
.name
,
951 "Headphone Detect Autoswitch",
952 sizeof(ctl
->id
.name
));
953 aoa_snd_ctl_add(ctl
);
954 ctl
= snd_ctl_new1(&lineout_detected
,
956 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
957 strlcpy(ctl
->id
.name
,
958 "Headphone Detected",
959 sizeof(ctl
->id
.name
));
960 ldev
->lineout_detected_ctrl
= ctl
;
961 aoa_snd_ctl_add(ctl
);
966 /* now update initial state */
967 if (ldev
->have_headphone_detect
)
968 layout_notify(&ldev
->selfptr_headphone
);
969 if (ldev
->have_lineout_detect
)
970 layout_notify(&ldev
->selfptr_lineout
);
973 static struct aoa_fabric layout_fabric
= {
974 .name
= "SoundByLayout",
975 .owner
= THIS_MODULE
,
976 .found_codec
= layout_found_codec
,
977 .remove_codec
= layout_remove_codec
,
978 .attached_codec
= layout_attached_codec
,
981 static int aoa_fabric_layout_probe(struct soundbus_dev
*sdev
)
983 struct device_node
*sound
= NULL
;
984 const unsigned int *id
;
985 struct layout
*layout
= NULL
;
986 struct layout_dev
*ldev
= NULL
;
989 /* hm, currently we can only have one ... */
993 /* by breaking out we keep a reference */
994 while ((sound
= of_get_next_child(sdev
->ofdev
.node
, sound
))) {
995 if (sound
->type
&& strcasecmp(sound
->type
, "soundchip") == 0)
1001 id
= of_get_property(sound
, "layout-id", NULL
);
1003 layout
= find_layout_by_id(*id
);
1005 id
= of_get_property(sound
, "device-id", NULL
);
1007 layout
= find_layout_by_device(*id
);
1011 printk(KERN_ERR
"snd-aoa-fabric-layout: unknown layout\n");
1015 ldev
= kzalloc(sizeof(struct layout_dev
), GFP_KERNEL
);
1019 layout_device
= ldev
;
1021 ldev
->sound
= sound
;
1022 ldev
->layout
= layout
;
1023 ldev
->gpio
.node
= sound
->parent
;
1024 switch (layout
->layout_id
) {
1025 case 0: /* anything with device_id, not layout_id */
1026 case 41: /* that unknown machine no one seems to have */
1027 case 51: /* PowerBook5,4 */
1028 case 58: /* Mac Mini */
1029 ldev
->gpio
.methods
= ftr_gpio_methods
;
1031 "snd-aoa-fabric-layout: Using direct GPIOs\n");
1034 ldev
->gpio
.methods
= pmf_gpio_methods
;
1036 "snd-aoa-fabric-layout: Using PMF GPIOs\n");
1038 ldev
->selfptr_headphone
.ptr
= ldev
;
1039 ldev
->selfptr_lineout
.ptr
= ldev
;
1040 dev_set_drvdata(&sdev
->ofdev
.dev
, ldev
);
1041 list_add(&ldev
->list
, &layouts_list
);
1042 layouts_list_items
++;
1044 /* assign these before registering ourselves, so
1045 * callbacks that are done during registration
1046 * already have the values */
1047 sdev
->pcmid
= ldev
->layout
->pcmid
;
1048 if (ldev
->layout
->busname
) {
1049 sdev
->pcmname
= ldev
->layout
->busname
;
1051 sdev
->pcmname
= "Master";
1054 ldev
->gpio
.methods
->init(&ldev
->gpio
);
1056 err
= aoa_fabric_register(&layout_fabric
, &sdev
->ofdev
.dev
);
1057 if (err
&& err
!= -EALREADY
) {
1058 printk(KERN_INFO
"snd-aoa-fabric-layout: can't use,"
1059 " another fabric is active!\n");
1064 ldev
->switch_on_headphone
= 1;
1065 ldev
->switch_on_lineout
= 1;
1068 /* we won't be using these then... */
1069 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1070 /* reset if we didn't use it */
1071 sdev
->pcmname
= NULL
;
1073 list_del(&ldev
->list
);
1074 layouts_list_items
--;
1077 layout_device
= NULL
;
1082 static int aoa_fabric_layout_remove(struct soundbus_dev
*sdev
)
1084 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1087 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
1088 if (ldev
->codecs
[i
]) {
1089 aoa_fabric_unlink_codec(ldev
->codecs
[i
]);
1091 ldev
->codecs
[i
] = NULL
;
1093 list_del(&ldev
->list
);
1094 layouts_list_items
--;
1095 of_node_put(ldev
->sound
);
1097 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1098 AOA_NOTIFY_HEADPHONE
,
1101 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1102 AOA_NOTIFY_LINE_OUT
,
1106 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1107 layout_device
= NULL
;
1110 sdev
->pcmname
= NULL
;
1115 static int aoa_fabric_layout_suspend(struct soundbus_dev
*sdev
, pm_message_t state
)
1117 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1119 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_off
)
1120 ldev
->gpio
.methods
->all_amps_off(&ldev
->gpio
);
1125 static int aoa_fabric_layout_resume(struct soundbus_dev
*sdev
)
1127 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1129 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_off
)
1130 ldev
->gpio
.methods
->all_amps_restore(&ldev
->gpio
);
1136 static struct soundbus_driver aoa_soundbus_driver
= {
1137 .name
= "snd_aoa_soundbus_drv",
1138 .owner
= THIS_MODULE
,
1139 .probe
= aoa_fabric_layout_probe
,
1140 .remove
= aoa_fabric_layout_remove
,
1142 .suspend
= aoa_fabric_layout_suspend
,
1143 .resume
= aoa_fabric_layout_resume
,
1146 .owner
= THIS_MODULE
,
1150 static int __init
aoa_fabric_layout_init(void)
1154 err
= soundbus_register_driver(&aoa_soundbus_driver
);
1160 static void __exit
aoa_fabric_layout_exit(void)
1162 soundbus_unregister_driver(&aoa_soundbus_driver
);
1163 aoa_fabric_unregister(&layout_fabric
);
1166 module_init(aoa_fabric_layout_init
);
1167 module_exit(aoa_fabric_layout_exit
);