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-31");
116 MODULE_ALIAS("aoa-device-id-35");
117 MODULE_ALIAS("aoa-device-id-44");
119 /* onyx with all but microphone connected */
120 static struct codec_connection onyx_connections_nomic
[] = {
122 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
126 .connected
= CC_DIGITALOUT
,
130 .connected
= CC_LINEIN
,
133 {} /* terminate array by .connected == 0 */
136 /* onyx on machines without headphone */
137 static struct codec_connection onyx_connections_noheadphones
[] = {
139 .connected
= CC_SPEAKERS
| CC_LINEOUT
|
140 CC_LINEOUT_LABELLED_HEADPHONE
,
144 .connected
= CC_DIGITALOUT
,
147 /* FIXME: are these correct? probably not for all the machines
148 * below ... If not this will need separating. */
150 .connected
= CC_LINEIN
,
154 .connected
= CC_MICROPHONE
,
157 {} /* terminate array by .connected == 0 */
160 /* onyx on machines with real line-out */
161 static struct codec_connection onyx_connections_reallineout
[] = {
163 .connected
= CC_SPEAKERS
| CC_LINEOUT
| CC_HEADPHONE
,
167 .connected
= CC_DIGITALOUT
,
171 .connected
= CC_LINEIN
,
174 {} /* terminate array by .connected == 0 */
177 /* tas on machines without line out */
178 static struct codec_connection tas_connections_nolineout
[] = {
180 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
184 .connected
= CC_LINEIN
,
188 .connected
= CC_MICROPHONE
,
191 {} /* terminate array by .connected == 0 */
194 /* tas on machines with neither line out nor line in */
195 static struct codec_connection tas_connections_noline
[] = {
197 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
201 .connected
= CC_MICROPHONE
,
204 {} /* terminate array by .connected == 0 */
207 /* tas on machines without microphone */
208 static struct codec_connection tas_connections_nomic
[] = {
210 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
214 .connected
= CC_LINEIN
,
217 {} /* terminate array by .connected == 0 */
220 /* tas on machines with everything connected */
221 static struct codec_connection tas_connections_all
[] = {
223 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
227 .connected
= CC_LINEIN
,
231 .connected
= CC_MICROPHONE
,
234 {} /* terminate array by .connected == 0 */
237 static struct codec_connection toonie_connections
[] = {
239 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
242 {} /* terminate array by .connected == 0 */
245 static struct codec_connection topaz_input
[] = {
247 .connected
= CC_DIGITALIN
,
250 {} /* terminate array by .connected == 0 */
253 static struct codec_connection topaz_output
[] = {
255 .connected
= CC_DIGITALOUT
,
258 {} /* terminate array by .connected == 0 */
261 static struct codec_connection topaz_inout
[] = {
263 .connected
= CC_DIGITALIN
,
267 .connected
= CC_DIGITALOUT
,
270 {} /* terminate array by .connected == 0 */
273 static struct layout layouts
[] = {
274 /* last PowerBooks (15" Oct 2005) */
276 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
279 .connections
= onyx_connections_noheadphones
,
283 .connections
= topaz_input
,
290 .connections
= onyx_connections_reallineout
,
297 .connections
= topaz_input
,
302 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
305 .connections
= onyx_connections_noheadphones
,
312 .connections
= topaz_input
,
315 /* PowerBook5,9 [17" Oct 2005] */
317 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
320 .connections
= onyx_connections_noheadphones
,
324 .connections
= topaz_input
,
331 .connections
= onyx_connections_noheadphones
,
335 .connections
= topaz_input
,
338 /* Quad PowerMac (analog in, analog/digital out) */
342 .connections
= onyx_connections_nomic
,
345 /* Quad PowerMac (digital in) */
349 .connections
= topaz_input
,
351 .busname
= "digital in", .pcmid
= 1 },
352 /* Early 2005 PowerBook (PowerBook 5,6) */
356 .connections
= tas_connections_nolineout
,
363 .connections
= tas_connections_nolineout
,
370 .connections
= tas_connections_nolineout
,
377 .connections
= tas_connections_all
,
384 .connections
= tas_connections_noline
,
391 .connections
= tas_connections_nolineout
,
398 .connections
= onyx_connections_nomic
,
402 .connections
= topaz_input
,
409 .connections
= tas_connections_nolineout
,
412 /* PowerMac10,1 (Mac Mini) */
416 .connections
= toonie_connections
,
423 .connections
= onyx_connections_noheadphones
,
426 /* unknown, untested, but this comes from Apple */
430 .connections
= tas_connections_all
,
436 .connections
= tas_connections_nomic
,
440 .connections
= topaz_inout
,
446 .connections
= onyx_connections_noheadphones
,
452 .connections
= topaz_input
,
458 .connections
= onyx_connections_nomic
,
464 .connections
= topaz_input
,
470 .connections
= onyx_connections_noheadphones
,
476 .connections
= topaz_input
,
482 .connections
= onyx_connections_noheadphones
,
486 .connections
= topaz_output
,
492 .connections
= onyx_connections_noheadphones
,
498 .connections
= topaz_input
,
504 .connections
= tas_connections_nomic
,
508 .connections
= topaz_inout
,
514 .connections
= tas_connections_noline
,
520 /* but it has an external mic?? how to select? */
521 .connections
= onyx_connections_noheadphones
,
527 .connections
= toonie_connections
,
533 .connections
= topaz_input
,
537 .connections
= onyx_connections_noheadphones
,
544 .connections
= tas_connections_noline
,
551 .connections
= tas_connections_all
,
558 .connections
= tas_connections_all
,
564 static struct layout
*find_layout_by_id(unsigned int id
)
569 while (l
->codecs
[0].name
) {
570 if (l
->layout_id
== id
)
577 static struct layout
*find_layout_by_device(unsigned int id
)
582 while (l
->codecs
[0].name
) {
583 if (l
->device_id
== id
)
590 static void use_layout(struct layout
*l
)
594 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
595 if (l
->codecs
[i
].name
) {
596 request_module("snd-aoa-codec-%s", l
->codecs
[i
].name
);
599 /* now we wait for the codecs to call us back */
604 struct layout_dev_ptr
{
605 struct layout_dev
*ptr
;
609 struct list_head list
;
610 struct soundbus_dev
*sdev
;
611 struct device_node
*sound
;
612 struct aoa_codec
*codecs
[MAX_CODECS_PER_BUS
];
613 struct layout
*layout
;
614 struct gpio_runtime gpio
;
616 /* we need these for headphone/lineout detection */
617 struct snd_kcontrol
*headphone_ctrl
;
618 struct snd_kcontrol
*lineout_ctrl
;
619 struct snd_kcontrol
*speaker_ctrl
;
620 struct snd_kcontrol
*master_ctrl
;
621 struct snd_kcontrol
*headphone_detected_ctrl
;
622 struct snd_kcontrol
*lineout_detected_ctrl
;
624 struct layout_dev_ptr selfptr_headphone
;
625 struct layout_dev_ptr selfptr_lineout
;
627 u32 have_lineout_detect
:1,
628 have_headphone_detect
:1,
629 switch_on_headphone
:1,
633 static LIST_HEAD(layouts_list
);
634 static int layouts_list_items
;
635 /* this can go away but only if we allow multiple cards,
636 * make the fabric handle all the card stuff, etc... */
637 static struct layout_dev
*layout_device
;
639 #define control_info snd_ctl_boolean_mono_info
641 #define AMP_CONTROL(n, description) \
642 static int n##_control_get(struct snd_kcontrol *kcontrol, \
643 struct snd_ctl_elem_value *ucontrol) \
645 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
646 if (gpio->methods && gpio->methods->get_##n) \
647 ucontrol->value.integer.value[0] = \
648 gpio->methods->get_##n(gpio); \
651 static int n##_control_put(struct snd_kcontrol *kcontrol, \
652 struct snd_ctl_elem_value *ucontrol) \
654 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
655 if (gpio->methods && gpio->methods->set_##n) \
656 gpio->methods->set_##n(gpio, \
657 !!ucontrol->value.integer.value[0]); \
660 static struct snd_kcontrol_new n##_ctl = { \
661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
662 .name = description, \
663 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
664 .info = control_info, \
665 .get = n##_control_get, \
666 .put = n##_control_put, \
669 AMP_CONTROL(headphone
, "Headphone Switch");
670 AMP_CONTROL(speakers
, "Speakers Switch");
671 AMP_CONTROL(lineout
, "Line-Out Switch");
672 AMP_CONTROL(master
, "Master Switch");
674 static int detect_choice_get(struct snd_kcontrol
*kcontrol
,
675 struct snd_ctl_elem_value
*ucontrol
)
677 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
679 switch (kcontrol
->private_value
) {
681 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_headphone
;
684 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_lineout
;
692 static int detect_choice_put(struct snd_kcontrol
*kcontrol
,
693 struct snd_ctl_elem_value
*ucontrol
)
695 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
697 switch (kcontrol
->private_value
) {
699 ldev
->switch_on_headphone
= !!ucontrol
->value
.integer
.value
[0];
702 ldev
->switch_on_lineout
= !!ucontrol
->value
.integer
.value
[0];
710 static struct snd_kcontrol_new headphone_detect_choice
= {
711 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
712 .name
= "Headphone Detect Autoswitch",
713 .info
= control_info
,
714 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
715 .get
= detect_choice_get
,
716 .put
= detect_choice_put
,
720 static struct snd_kcontrol_new lineout_detect_choice
= {
721 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
722 .name
= "Line-Out Detect Autoswitch",
723 .info
= control_info
,
724 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
725 .get
= detect_choice_get
,
726 .put
= detect_choice_put
,
730 static int detected_get(struct snd_kcontrol
*kcontrol
,
731 struct snd_ctl_elem_value
*ucontrol
)
733 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
736 switch (kcontrol
->private_value
) {
738 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
739 AOA_NOTIFY_HEADPHONE
);
742 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
743 AOA_NOTIFY_LINE_OUT
);
748 ucontrol
->value
.integer
.value
[0] = v
;
752 static struct snd_kcontrol_new headphone_detected
= {
753 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
754 .name
= "Headphone Detected",
755 .info
= control_info
,
756 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
761 static struct snd_kcontrol_new lineout_detected
= {
762 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
763 .name
= "Line-Out Detected",
764 .info
= control_info
,
765 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
770 static int check_codec(struct aoa_codec
*codec
,
771 struct layout_dev
*ldev
,
772 struct codec_connect_info
*cci
)
776 struct codec_connection
*cc
;
778 /* if the codec has a 'codec' node, we require a reference */
779 if (codec
->node
&& (strcmp(codec
->node
->name
, "codec") == 0)) {
780 snprintf(propname
, sizeof(propname
),
781 "platform-%s-codec-ref", codec
->name
);
782 ref
= of_get_property(ldev
->sound
, propname
, NULL
);
784 printk(KERN_INFO
"snd-aoa-fabric-layout: "
785 "required property %s not present\n", propname
);
788 if (*ref
!= codec
->node
->phandle
) {
789 printk(KERN_INFO
"snd-aoa-fabric-layout: "
790 "%s doesn't match!\n", propname
);
794 if (layouts_list_items
!= 1) {
795 printk(KERN_INFO
"snd-aoa-fabric-layout: "
796 "more than one soundbus, but no references.\n");
800 codec
->soundbus_dev
= ldev
->sdev
;
801 codec
->gpio
= &ldev
->gpio
;
803 cc
= cci
->connections
;
807 printk(KERN_INFO
"snd-aoa-fabric-layout: can use this codec\n");
809 codec
->connected
= 0;
810 codec
->fabric_data
= cc
;
812 while (cc
->connected
) {
813 codec
->connected
|= 1<<cc
->codec_bit
;
820 static int layout_found_codec(struct aoa_codec
*codec
)
822 struct layout_dev
*ldev
;
825 list_for_each_entry(ldev
, &layouts_list
, list
) {
826 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
827 if (!ldev
->layout
->codecs
[i
].name
)
829 if (strcmp(ldev
->layout
->codecs
[i
].name
, codec
->name
) == 0) {
830 if (check_codec(codec
,
832 &ldev
->layout
->codecs
[i
]) == 0)
840 static void layout_remove_codec(struct aoa_codec
*codec
)
843 /* here remove the codec from the layout dev's
846 codec
->soundbus_dev
= NULL
;
848 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
852 static void layout_notify(void *data
)
854 struct layout_dev_ptr
*dptr
= data
;
855 struct layout_dev
*ldev
;
857 struct snd_kcontrol
*detected
, *c
;
858 struct snd_card
*card
= aoa_get_card();
861 if (data
== &ldev
->selfptr_headphone
) {
862 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_HEADPHONE
);
863 detected
= ldev
->headphone_detected_ctrl
;
864 update
= ldev
->switch_on_headphone
;
866 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
867 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, v
);
868 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, 0);
870 } else if (data
== &ldev
->selfptr_lineout
) {
871 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_LINE_OUT
);
872 detected
= ldev
->lineout_detected_ctrl
;
873 update
= ldev
->switch_on_lineout
;
875 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
876 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, 0);
877 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, v
);
883 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &detected
->id
);
885 c
= ldev
->headphone_ctrl
;
887 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
888 c
= ldev
->speaker_ctrl
;
890 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
891 c
= ldev
->lineout_ctrl
;
893 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
897 static void layout_attached_codec(struct aoa_codec
*codec
)
899 struct codec_connection
*cc
;
900 struct snd_kcontrol
*ctl
;
901 int headphones
, lineout
;
902 struct layout_dev
*ldev
= layout_device
;
904 /* need to add this codec to our codec array! */
906 cc
= codec
->fabric_data
;
908 headphones
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
909 AOA_NOTIFY_HEADPHONE
);
910 lineout
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
911 AOA_NOTIFY_LINE_OUT
);
913 if (codec
->gpio
->methods
->set_master
) {
914 ctl
= snd_ctl_new1(&master_ctl
, codec
->gpio
);
915 ldev
->master_ctrl
= ctl
;
916 aoa_snd_ctl_add(ctl
);
918 while (cc
->connected
) {
919 if (cc
->connected
& CC_SPEAKERS
) {
920 if (headphones
<= 0 && lineout
<= 0)
921 ldev
->gpio
.methods
->set_speakers(codec
->gpio
, 1);
922 ctl
= snd_ctl_new1(&speakers_ctl
, codec
->gpio
);
923 ldev
->speaker_ctrl
= ctl
;
924 aoa_snd_ctl_add(ctl
);
926 if (cc
->connected
& CC_HEADPHONE
) {
928 ldev
->gpio
.methods
->set_headphone(codec
->gpio
, 1);
929 ctl
= snd_ctl_new1(&headphone_ctl
, codec
->gpio
);
930 ldev
->headphone_ctrl
= ctl
;
931 aoa_snd_ctl_add(ctl
);
932 ldev
->have_headphone_detect
=
934 ->set_notify(&ldev
->gpio
,
935 AOA_NOTIFY_HEADPHONE
,
937 &ldev
->selfptr_headphone
);
938 if (ldev
->have_headphone_detect
) {
939 ctl
= snd_ctl_new1(&headphone_detect_choice
,
941 aoa_snd_ctl_add(ctl
);
942 ctl
= snd_ctl_new1(&headphone_detected
,
944 ldev
->headphone_detected_ctrl
= ctl
;
945 aoa_snd_ctl_add(ctl
);
948 if (cc
->connected
& CC_LINEOUT
) {
950 ldev
->gpio
.methods
->set_lineout(codec
->gpio
, 1);
951 ctl
= snd_ctl_new1(&lineout_ctl
, codec
->gpio
);
952 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
953 strlcpy(ctl
->id
.name
,
954 "Headphone Switch", sizeof(ctl
->id
.name
));
955 ldev
->lineout_ctrl
= ctl
;
956 aoa_snd_ctl_add(ctl
);
957 ldev
->have_lineout_detect
=
959 ->set_notify(&ldev
->gpio
,
962 &ldev
->selfptr_lineout
);
963 if (ldev
->have_lineout_detect
) {
964 ctl
= snd_ctl_new1(&lineout_detect_choice
,
966 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
967 strlcpy(ctl
->id
.name
,
968 "Headphone Detect Autoswitch",
969 sizeof(ctl
->id
.name
));
970 aoa_snd_ctl_add(ctl
);
971 ctl
= snd_ctl_new1(&lineout_detected
,
973 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
974 strlcpy(ctl
->id
.name
,
975 "Headphone Detected",
976 sizeof(ctl
->id
.name
));
977 ldev
->lineout_detected_ctrl
= ctl
;
978 aoa_snd_ctl_add(ctl
);
983 /* now update initial state */
984 if (ldev
->have_headphone_detect
)
985 layout_notify(&ldev
->selfptr_headphone
);
986 if (ldev
->have_lineout_detect
)
987 layout_notify(&ldev
->selfptr_lineout
);
990 static struct aoa_fabric layout_fabric
= {
991 .name
= "SoundByLayout",
992 .owner
= THIS_MODULE
,
993 .found_codec
= layout_found_codec
,
994 .remove_codec
= layout_remove_codec
,
995 .attached_codec
= layout_attached_codec
,
998 static int aoa_fabric_layout_probe(struct soundbus_dev
*sdev
)
1000 struct device_node
*sound
= NULL
;
1001 const unsigned int *id
;
1002 struct layout
*layout
= NULL
;
1003 struct layout_dev
*ldev
= NULL
;
1006 /* hm, currently we can only have one ... */
1010 /* by breaking out we keep a reference */
1011 while ((sound
= of_get_next_child(sdev
->ofdev
.dev
.of_node
, sound
))) {
1012 if (sound
->type
&& strcasecmp(sound
->type
, "soundchip") == 0)
1018 id
= of_get_property(sound
, "layout-id", NULL
);
1020 layout
= find_layout_by_id(*id
);
1022 id
= of_get_property(sound
, "device-id", NULL
);
1024 layout
= find_layout_by_device(*id
);
1028 printk(KERN_ERR
"snd-aoa-fabric-layout: unknown layout\n");
1032 ldev
= kzalloc(sizeof(struct layout_dev
), GFP_KERNEL
);
1036 layout_device
= ldev
;
1038 ldev
->sound
= sound
;
1039 ldev
->layout
= layout
;
1040 ldev
->gpio
.node
= sound
->parent
;
1041 switch (layout
->layout_id
) {
1042 case 0: /* anything with device_id, not layout_id */
1043 case 41: /* that unknown machine no one seems to have */
1044 case 51: /* PowerBook5,4 */
1045 case 58: /* Mac Mini */
1046 ldev
->gpio
.methods
= ftr_gpio_methods
;
1048 "snd-aoa-fabric-layout: Using direct GPIOs\n");
1051 ldev
->gpio
.methods
= pmf_gpio_methods
;
1053 "snd-aoa-fabric-layout: Using PMF GPIOs\n");
1055 ldev
->selfptr_headphone
.ptr
= ldev
;
1056 ldev
->selfptr_lineout
.ptr
= ldev
;
1057 dev_set_drvdata(&sdev
->ofdev
.dev
, ldev
);
1058 list_add(&ldev
->list
, &layouts_list
);
1059 layouts_list_items
++;
1061 /* assign these before registering ourselves, so
1062 * callbacks that are done during registration
1063 * already have the values */
1064 sdev
->pcmid
= ldev
->layout
->pcmid
;
1065 if (ldev
->layout
->busname
) {
1066 sdev
->pcmname
= ldev
->layout
->busname
;
1068 sdev
->pcmname
= "Master";
1071 ldev
->gpio
.methods
->init(&ldev
->gpio
);
1073 err
= aoa_fabric_register(&layout_fabric
, &sdev
->ofdev
.dev
);
1074 if (err
&& err
!= -EALREADY
) {
1075 printk(KERN_INFO
"snd-aoa-fabric-layout: can't use,"
1076 " another fabric is active!\n");
1081 ldev
->switch_on_headphone
= 1;
1082 ldev
->switch_on_lineout
= 1;
1085 /* we won't be using these then... */
1086 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1087 /* reset if we didn't use it */
1088 sdev
->pcmname
= NULL
;
1090 list_del(&ldev
->list
);
1091 layouts_list_items
--;
1095 layout_device
= NULL
;
1099 static int aoa_fabric_layout_remove(struct soundbus_dev
*sdev
)
1101 struct layout_dev
*ldev
= dev_get_drvdata(&sdev
->ofdev
.dev
);
1104 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
1105 if (ldev
->codecs
[i
]) {
1106 aoa_fabric_unlink_codec(ldev
->codecs
[i
]);
1108 ldev
->codecs
[i
] = NULL
;
1110 list_del(&ldev
->list
);
1111 layouts_list_items
--;
1112 of_node_put(ldev
->sound
);
1114 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1115 AOA_NOTIFY_HEADPHONE
,
1118 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1119 AOA_NOTIFY_LINE_OUT
,
1123 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1124 layout_device
= NULL
;
1127 sdev
->pcmname
= NULL
;
1131 #ifdef CONFIG_PM_SLEEP
1132 static int aoa_fabric_layout_suspend(struct device
*dev
)
1134 struct layout_dev
*ldev
= dev_get_drvdata(dev
);
1136 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_off
)
1137 ldev
->gpio
.methods
->all_amps_off(&ldev
->gpio
);
1142 static int aoa_fabric_layout_resume(struct device
*dev
)
1144 struct layout_dev
*ldev
= dev_get_drvdata(dev
);
1146 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_restore
)
1147 ldev
->gpio
.methods
->all_amps_restore(&ldev
->gpio
);
1152 static SIMPLE_DEV_PM_OPS(aoa_fabric_layout_pm_ops
,
1153 aoa_fabric_layout_suspend
, aoa_fabric_layout_resume
);
1157 static struct soundbus_driver aoa_soundbus_driver
= {
1158 .name
= "snd_aoa_soundbus_drv",
1159 .owner
= THIS_MODULE
,
1160 .probe
= aoa_fabric_layout_probe
,
1161 .remove
= aoa_fabric_layout_remove
,
1163 .owner
= THIS_MODULE
,
1164 #ifdef CONFIG_PM_SLEEP
1165 .pm
= &aoa_fabric_layout_pm_ops
,
1170 static int __init
aoa_fabric_layout_init(void)
1172 return soundbus_register_driver(&aoa_soundbus_driver
);
1175 static void __exit
aoa_fabric_layout_exit(void)
1177 soundbus_unregister_driver(&aoa_soundbus_driver
);
1178 aoa_fabric_unregister(&layout_fabric
);
1181 module_init(aoa_fabric_layout_init
);
1182 module_exit(aoa_fabric_layout_exit
);