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");
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_all
,
376 .connections
= tas_connections_noline
,
383 .connections
= tas_connections_nolineout
,
390 .connections
= onyx_connections_nomic
,
394 .connections
= topaz_input
,
401 .connections
= tas_connections_nolineout
,
404 /* PowerMac10,1 (Mac Mini) */
408 .connections
= toonie_connections
,
415 .connections
= onyx_connections_noheadphones
,
418 /* unknown, untested, but this comes from Apple */
422 .connections
= tas_connections_all
,
428 .connections
= tas_connections_nomic
,
432 .connections
= topaz_inout
,
438 .connections
= onyx_connections_noheadphones
,
444 .connections
= topaz_input
,
450 .connections
= onyx_connections_nomic
,
456 .connections
= topaz_input
,
462 .connections
= onyx_connections_noheadphones
,
468 .connections
= topaz_input
,
474 .connections
= onyx_connections_noheadphones
,
478 .connections
= topaz_output
,
484 .connections
= onyx_connections_noheadphones
,
490 .connections
= topaz_input
,
496 .connections
= tas_connections_nomic
,
500 .connections
= topaz_inout
,
506 .connections
= tas_connections_noline
,
512 /* but it has an external mic?? how to select? */
513 .connections
= onyx_connections_noheadphones
,
519 .connections
= toonie_connections
,
525 .connections
= topaz_input
,
529 .connections
= onyx_connections_noheadphones
,
536 .connections
= tas_connections_noline
,
543 .connections
= tas_connections_all
,
550 .connections
= tas_connections_all
,
556 static struct layout
*find_layout_by_id(unsigned int id
)
561 while (l
->codecs
[0].name
) {
562 if (l
->layout_id
== id
)
569 static struct layout
*find_layout_by_device(unsigned int id
)
574 while (l
->codecs
[0].name
) {
575 if (l
->device_id
== id
)
582 static void use_layout(struct layout
*l
)
586 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
587 if (l
->codecs
[i
].name
) {
588 request_module("snd-aoa-codec-%s", l
->codecs
[i
].name
);
591 /* now we wait for the codecs to call us back */
596 struct layout_dev_ptr
{
597 struct layout_dev
*ptr
;
601 struct list_head list
;
602 struct soundbus_dev
*sdev
;
603 struct device_node
*sound
;
604 struct aoa_codec
*codecs
[MAX_CODECS_PER_BUS
];
605 struct layout
*layout
;
606 struct gpio_runtime gpio
;
608 /* we need these for headphone/lineout detection */
609 struct snd_kcontrol
*headphone_ctrl
;
610 struct snd_kcontrol
*lineout_ctrl
;
611 struct snd_kcontrol
*speaker_ctrl
;
612 struct snd_kcontrol
*master_ctrl
;
613 struct snd_kcontrol
*headphone_detected_ctrl
;
614 struct snd_kcontrol
*lineout_detected_ctrl
;
616 struct layout_dev_ptr selfptr_headphone
;
617 struct layout_dev_ptr selfptr_lineout
;
619 u32 have_lineout_detect
:1,
620 have_headphone_detect
:1,
621 switch_on_headphone
:1,
625 static LIST_HEAD(layouts_list
);
626 static int layouts_list_items
;
627 /* this can go away but only if we allow multiple cards,
628 * make the fabric handle all the card stuff, etc... */
629 static struct layout_dev
*layout_device
;
631 #define control_info snd_ctl_boolean_mono_info
633 #define AMP_CONTROL(n, description) \
634 static int n##_control_get(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 ucontrol->value.integer.value[0] = \
640 gpio->methods->get_##n(gpio); \
643 static int n##_control_put(struct snd_kcontrol *kcontrol, \
644 struct snd_ctl_elem_value *ucontrol) \
646 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
647 if (gpio->methods && gpio->methods->set_##n) \
648 gpio->methods->set_##n(gpio, \
649 !!ucontrol->value.integer.value[0]); \
652 static struct snd_kcontrol_new n##_ctl = { \
653 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
654 .name = description, \
655 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
656 .info = control_info, \
657 .get = n##_control_get, \
658 .put = n##_control_put, \
661 AMP_CONTROL(headphone
, "Headphone Switch");
662 AMP_CONTROL(speakers
, "Speakers Switch");
663 AMP_CONTROL(lineout
, "Line-Out Switch");
664 AMP_CONTROL(master
, "Master Switch");
666 static int detect_choice_get(struct snd_kcontrol
*kcontrol
,
667 struct snd_ctl_elem_value
*ucontrol
)
669 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
671 switch (kcontrol
->private_value
) {
673 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_headphone
;
676 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_lineout
;
684 static int detect_choice_put(struct snd_kcontrol
*kcontrol
,
685 struct snd_ctl_elem_value
*ucontrol
)
687 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
689 switch (kcontrol
->private_value
) {
691 ldev
->switch_on_headphone
= !!ucontrol
->value
.integer
.value
[0];
694 ldev
->switch_on_lineout
= !!ucontrol
->value
.integer
.value
[0];
702 static struct snd_kcontrol_new headphone_detect_choice
= {
703 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
704 .name
= "Headphone Detect Autoswitch",
705 .info
= control_info
,
706 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
707 .get
= detect_choice_get
,
708 .put
= detect_choice_put
,
712 static struct snd_kcontrol_new lineout_detect_choice
= {
713 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
714 .name
= "Line-Out Detect Autoswitch",
715 .info
= control_info
,
716 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
717 .get
= detect_choice_get
,
718 .put
= detect_choice_put
,
722 static int detected_get(struct snd_kcontrol
*kcontrol
,
723 struct snd_ctl_elem_value
*ucontrol
)
725 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
728 switch (kcontrol
->private_value
) {
730 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
731 AOA_NOTIFY_HEADPHONE
);
734 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
735 AOA_NOTIFY_LINE_OUT
);
740 ucontrol
->value
.integer
.value
[0] = v
;
744 static struct snd_kcontrol_new headphone_detected
= {
745 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
746 .name
= "Headphone Detected",
747 .info
= control_info
,
748 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
753 static struct snd_kcontrol_new lineout_detected
= {
754 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
755 .name
= "Line-Out Detected",
756 .info
= control_info
,
757 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
762 static int check_codec(struct aoa_codec
*codec
,
763 struct layout_dev
*ldev
,
764 struct codec_connect_info
*cci
)
768 struct codec_connection
*cc
;
770 /* if the codec has a 'codec' node, we require a reference */
771 if (codec
->node
&& (strcmp(codec
->node
->name
, "codec") == 0)) {
772 snprintf(propname
, sizeof(propname
),
773 "platform-%s-codec-ref", codec
->name
);
774 ref
= of_get_property(ldev
->sound
, propname
, NULL
);
776 printk(KERN_INFO
"snd-aoa-fabric-layout: "
777 "required property %s not present\n", propname
);
780 if (*ref
!= codec
->node
->phandle
) {
781 printk(KERN_INFO
"snd-aoa-fabric-layout: "
782 "%s doesn't match!\n", propname
);
786 if (layouts_list_items
!= 1) {
787 printk(KERN_INFO
"snd-aoa-fabric-layout: "
788 "more than one soundbus, but no references.\n");
792 codec
->soundbus_dev
= ldev
->sdev
;
793 codec
->gpio
= &ldev
->gpio
;
795 cc
= cci
->connections
;
799 printk(KERN_INFO
"snd-aoa-fabric-layout: can use this codec\n");
801 codec
->connected
= 0;
802 codec
->fabric_data
= cc
;
804 while (cc
->connected
) {
805 codec
->connected
|= 1<<cc
->codec_bit
;
812 static int layout_found_codec(struct aoa_codec
*codec
)
814 struct layout_dev
*ldev
;
817 list_for_each_entry(ldev
, &layouts_list
, list
) {
818 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
819 if (!ldev
->layout
->codecs
[i
].name
)
821 if (strcmp(ldev
->layout
->codecs
[i
].name
, codec
->name
) == 0) {
822 if (check_codec(codec
,
824 &ldev
->layout
->codecs
[i
]) == 0)
832 static void layout_remove_codec(struct aoa_codec
*codec
)
835 /* here remove the codec from the layout dev's
838 codec
->soundbus_dev
= NULL
;
840 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
844 static void layout_notify(void *data
)
846 struct layout_dev_ptr
*dptr
= data
;
847 struct layout_dev
*ldev
;
849 struct snd_kcontrol
*detected
, *c
;
850 struct snd_card
*card
= aoa_get_card();
853 if (data
== &ldev
->selfptr_headphone
) {
854 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_HEADPHONE
);
855 detected
= ldev
->headphone_detected_ctrl
;
856 update
= ldev
->switch_on_headphone
;
858 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
859 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, v
);
860 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, 0);
862 } else if (data
== &ldev
->selfptr_lineout
) {
863 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_LINE_OUT
);
864 detected
= ldev
->lineout_detected_ctrl
;
865 update
= ldev
->switch_on_lineout
;
867 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
868 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, 0);
869 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, v
);
875 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &detected
->id
);
877 c
= ldev
->headphone_ctrl
;
879 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
880 c
= ldev
->speaker_ctrl
;
882 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
883 c
= ldev
->lineout_ctrl
;
885 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
889 static void layout_attached_codec(struct aoa_codec
*codec
)
891 struct codec_connection
*cc
;
892 struct snd_kcontrol
*ctl
;
893 int headphones
, lineout
;
894 struct layout_dev
*ldev
= layout_device
;
896 /* need to add this codec to our codec array! */
898 cc
= codec
->fabric_data
;
900 headphones
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
901 AOA_NOTIFY_HEADPHONE
);
902 lineout
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
903 AOA_NOTIFY_LINE_OUT
);
905 if (codec
->gpio
->methods
->set_master
) {
906 ctl
= snd_ctl_new1(&master_ctl
, codec
->gpio
);
907 ldev
->master_ctrl
= ctl
;
908 aoa_snd_ctl_add(ctl
);
910 while (cc
->connected
) {
911 if (cc
->connected
& CC_SPEAKERS
) {
912 if (headphones
<= 0 && lineout
<= 0)
913 ldev
->gpio
.methods
->set_speakers(codec
->gpio
, 1);
914 ctl
= snd_ctl_new1(&speakers_ctl
, codec
->gpio
);
915 ldev
->speaker_ctrl
= ctl
;
916 aoa_snd_ctl_add(ctl
);
918 if (cc
->connected
& CC_HEADPHONE
) {
920 ldev
->gpio
.methods
->set_headphone(codec
->gpio
, 1);
921 ctl
= snd_ctl_new1(&headphone_ctl
, codec
->gpio
);
922 ldev
->headphone_ctrl
= ctl
;
923 aoa_snd_ctl_add(ctl
);
924 ldev
->have_headphone_detect
=
926 ->set_notify(&ldev
->gpio
,
927 AOA_NOTIFY_HEADPHONE
,
929 &ldev
->selfptr_headphone
);
930 if (ldev
->have_headphone_detect
) {
931 ctl
= snd_ctl_new1(&headphone_detect_choice
,
933 aoa_snd_ctl_add(ctl
);
934 ctl
= snd_ctl_new1(&headphone_detected
,
936 ldev
->headphone_detected_ctrl
= ctl
;
937 aoa_snd_ctl_add(ctl
);
940 if (cc
->connected
& CC_LINEOUT
) {
942 ldev
->gpio
.methods
->set_lineout(codec
->gpio
, 1);
943 ctl
= snd_ctl_new1(&lineout_ctl
, codec
->gpio
);
944 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
945 strlcpy(ctl
->id
.name
,
946 "Headphone Switch", sizeof(ctl
->id
.name
));
947 ldev
->lineout_ctrl
= ctl
;
948 aoa_snd_ctl_add(ctl
);
949 ldev
->have_lineout_detect
=
951 ->set_notify(&ldev
->gpio
,
954 &ldev
->selfptr_lineout
);
955 if (ldev
->have_lineout_detect
) {
956 ctl
= snd_ctl_new1(&lineout_detect_choice
,
958 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
959 strlcpy(ctl
->id
.name
,
960 "Headphone Detect Autoswitch",
961 sizeof(ctl
->id
.name
));
962 aoa_snd_ctl_add(ctl
);
963 ctl
= snd_ctl_new1(&lineout_detected
,
965 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
966 strlcpy(ctl
->id
.name
,
967 "Headphone Detected",
968 sizeof(ctl
->id
.name
));
969 ldev
->lineout_detected_ctrl
= ctl
;
970 aoa_snd_ctl_add(ctl
);
975 /* now update initial state */
976 if (ldev
->have_headphone_detect
)
977 layout_notify(&ldev
->selfptr_headphone
);
978 if (ldev
->have_lineout_detect
)
979 layout_notify(&ldev
->selfptr_lineout
);
982 static struct aoa_fabric layout_fabric
= {
983 .name
= "SoundByLayout",
984 .owner
= THIS_MODULE
,
985 .found_codec
= layout_found_codec
,
986 .remove_codec
= layout_remove_codec
,
987 .attached_codec
= layout_attached_codec
,
990 static int aoa_fabric_layout_probe(struct soundbus_dev
*sdev
)
992 struct device_node
*sound
= NULL
;
993 const unsigned int *id
;
994 struct layout
*layout
= NULL
;
995 struct layout_dev
*ldev
= NULL
;
998 /* hm, currently we can only have one ... */
1002 /* by breaking out we keep a reference */
1003 while ((sound
= of_get_next_child(sdev
->ofdev
.dev
.of_node
, sound
))) {
1004 if (sound
->type
&& strcasecmp(sound
->type
, "soundchip") == 0)
1010 id
= of_get_property(sound
, "layout-id", NULL
);
1012 layout
= find_layout_by_id(*id
);
1014 id
= of_get_property(sound
, "device-id", NULL
);
1016 layout
= find_layout_by_device(*id
);
1020 printk(KERN_ERR
"snd-aoa-fabric-layout: unknown layout\n");
1024 ldev
= kzalloc(sizeof(struct layout_dev
), GFP_KERNEL
);
1028 layout_device
= ldev
;
1030 ldev
->sound
= sound
;
1031 ldev
->layout
= layout
;
1032 ldev
->gpio
.node
= sound
->parent
;
1033 switch (layout
->layout_id
) {
1034 case 0: /* anything with device_id, not layout_id */
1035 case 41: /* that unknown machine no one seems to have */
1036 case 51: /* PowerBook5,4 */
1037 case 58: /* Mac Mini */
1038 ldev
->gpio
.methods
= ftr_gpio_methods
;
1040 "snd-aoa-fabric-layout: Using direct GPIOs\n");
1043 ldev
->gpio
.methods
= pmf_gpio_methods
;
1045 "snd-aoa-fabric-layout: Using PMF GPIOs\n");
1047 ldev
->selfptr_headphone
.ptr
= ldev
;
1048 ldev
->selfptr_lineout
.ptr
= ldev
;
1049 dev_set_drvdata(&sdev
->ofdev
.dev
, ldev
);
1050 list_add(&ldev
->list
, &layouts_list
);
1051 layouts_list_items
++;
1053 /* assign these before registering ourselves, so
1054 * callbacks that are done during registration
1055 * already have the values */
1056 sdev
->pcmid
= ldev
->layout
->pcmid
;
1057 if (ldev
->layout
->busname
) {
1058 sdev
->pcmname
= ldev
->layout
->busname
;
1060 sdev
->pcmname
= "Master";
1063 ldev
->gpio
.methods
->init(&ldev
->gpio
);
1065 err
= aoa_fabric_register(&layout_fabric
, &sdev
->ofdev
.dev
);
1066 if (err
&& err
!= -EALREADY
) {
1067 printk(KERN_INFO
"snd-aoa-fabric-layout: can't use,"
1068 " another fabric is active!\n");
1073 ldev
->switch_on_headphone
= 1;
1074 ldev
->switch_on_lineout
= 1;
1077 /* we won't be using these then... */
1078 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1079 /* reset if we didn't use it */
1080 sdev
->pcmname
= NULL
;
1082 list_del(&ldev
->list
);
1083 layouts_list_items
--;
1087 layout_device
= NULL
;
1091 static int aoa_fabric_layout_remove(struct soundbus_dev
*sdev
)
1093 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1096 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
1097 if (ldev
->codecs
[i
]) {
1098 aoa_fabric_unlink_codec(ldev
->codecs
[i
]);
1100 ldev
->codecs
[i
] = NULL
;
1102 list_del(&ldev
->list
);
1103 layouts_list_items
--;
1104 of_node_put(ldev
->sound
);
1106 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1107 AOA_NOTIFY_HEADPHONE
,
1110 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1111 AOA_NOTIFY_LINE_OUT
,
1115 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1116 layout_device
= NULL
;
1119 sdev
->pcmname
= NULL
;
1124 static int aoa_fabric_layout_suspend(struct soundbus_dev
*sdev
, pm_message_t state
)
1126 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1128 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_off
)
1129 ldev
->gpio
.methods
->all_amps_off(&ldev
->gpio
);
1134 static int aoa_fabric_layout_resume(struct soundbus_dev
*sdev
)
1136 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1138 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_restore
)
1139 ldev
->gpio
.methods
->all_amps_restore(&ldev
->gpio
);
1145 static struct soundbus_driver aoa_soundbus_driver
= {
1146 .name
= "snd_aoa_soundbus_drv",
1147 .owner
= THIS_MODULE
,
1148 .probe
= aoa_fabric_layout_probe
,
1149 .remove
= aoa_fabric_layout_remove
,
1151 .suspend
= aoa_fabric_layout_suspend
,
1152 .resume
= aoa_fabric_layout_resume
,
1155 .owner
= THIS_MODULE
,
1159 static int __init
aoa_fabric_layout_init(void)
1163 err
= soundbus_register_driver(&aoa_soundbus_driver
);
1169 static void __exit
aoa_fabric_layout_exit(void)
1171 soundbus_unregister_driver(&aoa_soundbus_driver
);
1172 aoa_fabric_unregister(&layout_fabric
);
1175 module_init(aoa_fabric_layout_init
);
1176 module_exit(aoa_fabric_layout_exit
);