2 * Apple Onboard Audio driver -- layout fabric
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6 * GPL v2, can be found in COPYING.
9 * This fabric module looks for sound codecs
10 * based on the layout-id property in the device tree.
15 #include <linux/list.h>
16 #include <linux/module.h>
18 #include "../soundbus/soundbus.h"
20 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
21 MODULE_LICENSE("GPL");
22 MODULE_DESCRIPTION("Layout-ID fabric for snd-aoa");
24 #define MAX_CODECS_PER_BUS 2
26 /* These are the connections the layout fabric
27 * knows about. It doesn't really care about the
28 * input ones, but I thought I'd separate them
29 * to give them proper names. The thing is that
30 * Apple usually will distinguish the active output
31 * by GPIOs, while the active input is set directly
32 * on the codec. Hence we here tell the codec what
33 * we think is connected. This information is hard-
35 #define CC_SPEAKERS (1<<0)
36 #define CC_HEADPHONE (1<<1)
37 #define CC_LINEOUT (1<<2)
38 #define CC_DIGITALOUT (1<<3)
39 #define CC_LINEIN (1<<4)
40 #define CC_MICROPHONE (1<<5)
41 #define CC_DIGITALIN (1<<6)
42 /* pretty bogus but users complain...
43 * This is a flag saying that the LINEOUT
44 * should be renamed to HEADPHONE.
45 * be careful with input detection! */
46 #define CC_LINEOUT_LABELLED_HEADPHONE (1<<7)
48 struct codec_connection
{
49 /* CC_ flags from above */
51 /* codec dependent bit to be set in the aoa_codec.connected field.
52 * This intentionally doesn't have any generic flags because the
53 * fabric has to know the codec anyway and all codecs might have
54 * different connectors */
58 struct codec_connect_info
{
60 struct codec_connection
*connections
;
63 #define LAYOUT_FLAG_COMBO_LINEOUT_SPDIF (1<<0)
66 unsigned int layout_id
;
67 struct codec_connect_info codecs
[MAX_CODECS_PER_BUS
];
70 /* if busname is not assigned, we use 'Master' below,
71 * so that our layout table doesn't need to be filled
73 * We only assign these two if we expect to find more
74 * than one soundbus, i.e. on those machines with
75 * multiple layout-ids */
80 MODULE_ALIAS("sound-layout-41");
81 MODULE_ALIAS("sound-layout-45");
82 MODULE_ALIAS("sound-layout-51");
83 MODULE_ALIAS("sound-layout-58");
84 MODULE_ALIAS("sound-layout-60");
85 MODULE_ALIAS("sound-layout-61");
86 MODULE_ALIAS("sound-layout-64");
87 MODULE_ALIAS("sound-layout-65");
88 MODULE_ALIAS("sound-layout-68");
89 MODULE_ALIAS("sound-layout-69");
90 MODULE_ALIAS("sound-layout-70");
91 MODULE_ALIAS("sound-layout-72");
92 MODULE_ALIAS("sound-layout-80");
93 MODULE_ALIAS("sound-layout-82");
94 MODULE_ALIAS("sound-layout-84");
95 MODULE_ALIAS("sound-layout-86");
96 MODULE_ALIAS("sound-layout-92");
98 /* onyx with all but microphone connected */
99 static struct codec_connection onyx_connections_nomic
[] = {
101 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
105 .connected
= CC_DIGITALOUT
,
109 .connected
= CC_LINEIN
,
112 {} /* terminate array by .connected == 0 */
115 /* onyx on machines without headphone */
116 static struct codec_connection onyx_connections_noheadphones
[] = {
118 .connected
= CC_SPEAKERS
| CC_LINEOUT
|
119 CC_LINEOUT_LABELLED_HEADPHONE
,
123 .connected
= CC_DIGITALOUT
,
126 /* FIXME: are these correct? probably not for all the machines
127 * below ... If not this will need separating. */
129 .connected
= CC_LINEIN
,
133 .connected
= CC_MICROPHONE
,
136 {} /* terminate array by .connected == 0 */
139 /* onyx on machines with real line-out */
140 static struct codec_connection onyx_connections_reallineout
[] = {
142 .connected
= CC_SPEAKERS
| CC_LINEOUT
| CC_HEADPHONE
,
146 .connected
= CC_DIGITALOUT
,
150 .connected
= CC_LINEIN
,
153 {} /* terminate array by .connected == 0 */
156 /* tas on machines without line out */
157 static struct codec_connection tas_connections_nolineout
[] = {
159 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
163 .connected
= CC_LINEIN
,
167 .connected
= CC_MICROPHONE
,
170 {} /* terminate array by .connected == 0 */
173 /* tas on machines with neither line out nor line in */
174 static struct codec_connection tas_connections_noline
[] = {
176 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
180 .connected
= CC_MICROPHONE
,
183 {} /* terminate array by .connected == 0 */
186 /* tas on machines without microphone */
187 static struct codec_connection tas_connections_nomic
[] = {
189 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
193 .connected
= CC_LINEIN
,
196 {} /* terminate array by .connected == 0 */
199 /* tas on machines with everything connected */
200 static struct codec_connection tas_connections_all
[] = {
202 .connected
= CC_SPEAKERS
| CC_HEADPHONE
| CC_LINEOUT
,
206 .connected
= CC_LINEIN
,
210 .connected
= CC_MICROPHONE
,
213 {} /* terminate array by .connected == 0 */
216 static struct codec_connection toonie_connections
[] = {
218 .connected
= CC_SPEAKERS
| CC_HEADPHONE
,
221 {} /* terminate array by .connected == 0 */
224 static struct codec_connection topaz_input
[] = {
226 .connected
= CC_DIGITALIN
,
229 {} /* terminate array by .connected == 0 */
232 static struct codec_connection topaz_output
[] = {
234 .connected
= CC_DIGITALOUT
,
237 {} /* terminate array by .connected == 0 */
240 static struct codec_connection topaz_inout
[] = {
242 .connected
= CC_DIGITALIN
,
246 .connected
= CC_DIGITALOUT
,
249 {} /* terminate array by .connected == 0 */
252 static struct layout layouts
[] = {
253 /* last PowerBooks (15" Oct 2005) */
255 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
258 .connections
= onyx_connections_noheadphones
,
262 .connections
= topaz_input
,
269 .connections
= onyx_connections_reallineout
,
276 .connections
= topaz_input
,
281 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
284 .connections
= onyx_connections_noheadphones
,
291 .connections
= topaz_input
,
294 /* PowerBook5,9 [17" Oct 2005] */
296 .flags
= LAYOUT_FLAG_COMBO_LINEOUT_SPDIF
,
299 .connections
= onyx_connections_noheadphones
,
303 .connections
= topaz_input
,
310 .connections
= onyx_connections_noheadphones
,
314 .connections
= topaz_input
,
317 /* Quad PowerMac (analog in, analog/digital out) */
321 .connections
= onyx_connections_nomic
,
324 /* Quad PowerMac (digital in) */
328 .connections
= topaz_input
,
330 .busname
= "digital in", .pcmid
= 1 },
331 /* Early 2005 PowerBook (PowerBook 5,6) */
335 .connections
= tas_connections_nolineout
,
342 .connections
= tas_connections_nolineout
,
349 .connections
= tas_connections_noline
,
356 .connections
= tas_connections_nolineout
,
363 .connections
= onyx_connections_nomic
,
367 .connections
= topaz_input
,
374 .connections
= tas_connections_nolineout
,
377 /* PowerMac10,1 (Mac Mini) */
381 .connections
= toonie_connections
,
384 /* unknown, untested, but this comes from Apple */
388 .connections
= tas_connections_all
,
394 .connections
= tas_connections_nomic
,
398 .connections
= topaz_inout
,
404 .connections
= onyx_connections_noheadphones
,
410 .connections
= topaz_input
,
416 .connections
= onyx_connections_nomic
,
422 .connections
= topaz_input
,
428 .connections
= onyx_connections_noheadphones
,
434 .connections
= topaz_input
,
440 .connections
= onyx_connections_noheadphones
,
444 .connections
= topaz_output
,
450 .connections
= onyx_connections_noheadphones
,
456 .connections
= topaz_input
,
462 .connections
= tas_connections_nomic
,
466 .connections
= topaz_inout
,
472 .connections
= tas_connections_noline
,
478 /* but it has an external mic?? how to select? */
479 .connections
= onyx_connections_noheadphones
,
485 .connections
= onyx_connections_noheadphones
,
491 .connections
= toonie_connections
,
497 .connections
= topaz_input
,
501 .connections
= onyx_connections_noheadphones
,
507 static struct layout
*find_layout_by_id(unsigned int id
)
512 while (l
->layout_id
) {
513 if (l
->layout_id
== id
)
520 static void use_layout(struct layout
*l
)
524 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
525 if (l
->codecs
[i
].name
) {
526 request_module("snd-aoa-codec-%s", l
->codecs
[i
].name
);
529 /* now we wait for the codecs to call us back */
534 struct layout_dev_ptr
{
535 struct layout_dev
*ptr
;
539 struct list_head list
;
540 struct soundbus_dev
*sdev
;
541 struct device_node
*sound
;
542 struct aoa_codec
*codecs
[MAX_CODECS_PER_BUS
];
543 struct layout
*layout
;
544 struct gpio_runtime gpio
;
546 /* we need these for headphone/lineout detection */
547 struct snd_kcontrol
*headphone_ctrl
;
548 struct snd_kcontrol
*lineout_ctrl
;
549 struct snd_kcontrol
*speaker_ctrl
;
550 struct snd_kcontrol
*headphone_detected_ctrl
;
551 struct snd_kcontrol
*lineout_detected_ctrl
;
553 struct layout_dev_ptr selfptr_headphone
;
554 struct layout_dev_ptr selfptr_lineout
;
556 u32 have_lineout_detect
:1,
557 have_headphone_detect
:1,
558 switch_on_headphone
:1,
562 static LIST_HEAD(layouts_list
);
563 static int layouts_list_items
;
564 /* this can go away but only if we allow multiple cards,
565 * make the fabric handle all the card stuff, etc... */
566 static struct layout_dev
*layout_device
;
568 static int control_info(struct snd_kcontrol
*kcontrol
,
569 struct snd_ctl_elem_info
*uinfo
)
571 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
573 uinfo
->value
.integer
.min
= 0;
574 uinfo
->value
.integer
.max
= 1;
578 #define AMP_CONTROL(n, description) \
579 static int n##_control_get(struct snd_kcontrol *kcontrol, \
580 struct snd_ctl_elem_value *ucontrol) \
582 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
583 if (gpio->methods && gpio->methods->get_##n) \
584 ucontrol->value.integer.value[0] = \
585 gpio->methods->get_##n(gpio); \
588 static int n##_control_put(struct snd_kcontrol *kcontrol, \
589 struct snd_ctl_elem_value *ucontrol) \
591 struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
592 if (gpio->methods && gpio->methods->get_##n) \
593 gpio->methods->set_##n(gpio, \
594 ucontrol->value.integer.value[0]); \
597 static struct snd_kcontrol_new n##_ctl = { \
598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
599 .name = description, \
600 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
601 .info = control_info, \
602 .get = n##_control_get, \
603 .put = n##_control_put, \
606 AMP_CONTROL(headphone
, "Headphone Switch");
607 AMP_CONTROL(speakers
, "Speakers Switch");
608 AMP_CONTROL(lineout
, "Line-Out Switch");
610 static int detect_choice_get(struct snd_kcontrol
*kcontrol
,
611 struct snd_ctl_elem_value
*ucontrol
)
613 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
615 switch (kcontrol
->private_value
) {
617 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_headphone
;
620 ucontrol
->value
.integer
.value
[0] = ldev
->switch_on_lineout
;
628 static int detect_choice_put(struct snd_kcontrol
*kcontrol
,
629 struct snd_ctl_elem_value
*ucontrol
)
631 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
633 switch (kcontrol
->private_value
) {
635 ldev
->switch_on_headphone
= !!ucontrol
->value
.integer
.value
[0];
638 ldev
->switch_on_lineout
= !!ucontrol
->value
.integer
.value
[0];
646 static struct snd_kcontrol_new headphone_detect_choice
= {
647 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
648 .name
= "Headphone Detect Autoswitch",
649 .info
= control_info
,
650 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
651 .get
= detect_choice_get
,
652 .put
= detect_choice_put
,
656 static struct snd_kcontrol_new lineout_detect_choice
= {
657 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
658 .name
= "Line-Out Detect Autoswitch",
659 .info
= control_info
,
660 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
661 .get
= detect_choice_get
,
662 .put
= detect_choice_put
,
666 static int detected_get(struct snd_kcontrol
*kcontrol
,
667 struct snd_ctl_elem_value
*ucontrol
)
669 struct layout_dev
*ldev
= snd_kcontrol_chip(kcontrol
);
672 switch (kcontrol
->private_value
) {
674 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
675 AOA_NOTIFY_HEADPHONE
);
678 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
,
679 AOA_NOTIFY_LINE_OUT
);
684 ucontrol
->value
.integer
.value
[0] = v
;
688 static struct snd_kcontrol_new headphone_detected
= {
689 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
690 .name
= "Headphone Detected",
691 .info
= control_info
,
692 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
697 static struct snd_kcontrol_new lineout_detected
= {
698 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
699 .name
= "Line-Out Detected",
700 .info
= control_info
,
701 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
706 static int check_codec(struct aoa_codec
*codec
,
707 struct layout_dev
*ldev
,
708 struct codec_connect_info
*cci
)
712 struct codec_connection
*cc
;
714 /* if the codec has a 'codec' node, we require a reference */
715 if (codec
->node
&& (strcmp(codec
->node
->name
, "codec") == 0)) {
716 snprintf(propname
, sizeof(propname
),
717 "platform-%s-codec-ref", codec
->name
);
718 ref
= (u32
*)get_property(ldev
->sound
, propname
, NULL
);
720 printk(KERN_INFO
"snd-aoa-fabric-layout: "
721 "required property %s not present\n", propname
);
724 if (*ref
!= codec
->node
->linux_phandle
) {
725 printk(KERN_INFO
"snd-aoa-fabric-layout: "
726 "%s doesn't match!\n", propname
);
730 if (layouts_list_items
!= 1) {
731 printk(KERN_INFO
"snd-aoa-fabric-layout: "
732 "more than one soundbus, but no references.\n");
736 codec
->soundbus_dev
= ldev
->sdev
;
737 codec
->gpio
= &ldev
->gpio
;
739 cc
= cci
->connections
;
743 printk(KERN_INFO
"snd-aoa-fabric-layout: can use this codec\n");
745 codec
->connected
= 0;
746 codec
->fabric_data
= cc
;
748 while (cc
->connected
) {
749 codec
->connected
|= 1<<cc
->codec_bit
;
756 static int layout_found_codec(struct aoa_codec
*codec
)
758 struct layout_dev
*ldev
;
761 list_for_each_entry(ldev
, &layouts_list
, list
) {
762 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
763 if (!ldev
->layout
->codecs
[i
].name
)
765 if (strcmp(ldev
->layout
->codecs
[i
].name
, codec
->name
) == 0) {
766 if (check_codec(codec
,
768 &ldev
->layout
->codecs
[i
]) == 0)
776 static void layout_remove_codec(struct aoa_codec
*codec
)
779 /* here remove the codec from the layout dev's
782 codec
->soundbus_dev
= NULL
;
784 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
788 static void layout_notify(void *data
)
790 struct layout_dev_ptr
*dptr
= data
;
791 struct layout_dev
*ldev
;
793 struct snd_kcontrol
*detected
, *c
;
794 struct snd_card
*card
= aoa_get_card();
797 if (data
== &ldev
->selfptr_headphone
) {
798 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_HEADPHONE
);
799 detected
= ldev
->headphone_detected_ctrl
;
800 update
= ldev
->switch_on_headphone
;
802 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
803 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, v
);
804 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, 0);
806 } else if (data
== &ldev
->selfptr_lineout
) {
807 v
= ldev
->gpio
.methods
->get_detect(&ldev
->gpio
, AOA_NOTIFY_LINE_OUT
);
808 detected
= ldev
->lineout_detected_ctrl
;
809 update
= ldev
->switch_on_lineout
;
811 ldev
->gpio
.methods
->set_speakers(&ldev
->gpio
, !v
);
812 ldev
->gpio
.methods
->set_headphone(&ldev
->gpio
, 0);
813 ldev
->gpio
.methods
->set_lineout(&ldev
->gpio
, v
);
819 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &detected
->id
);
821 c
= ldev
->headphone_ctrl
;
823 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
824 c
= ldev
->speaker_ctrl
;
826 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
827 c
= ldev
->lineout_ctrl
;
829 snd_ctl_notify(card
, SNDRV_CTL_EVENT_MASK_VALUE
, &c
->id
);
833 static void layout_attached_codec(struct aoa_codec
*codec
)
835 struct codec_connection
*cc
;
836 struct snd_kcontrol
*ctl
;
837 int headphones
, lineout
;
838 struct layout_dev
*ldev
= layout_device
;
840 /* need to add this codec to our codec array! */
842 cc
= codec
->fabric_data
;
844 headphones
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
845 AOA_NOTIFY_HEADPHONE
);
846 lineout
= codec
->gpio
->methods
->get_detect(codec
->gpio
,
847 AOA_NOTIFY_LINE_OUT
);
849 while (cc
->connected
) {
850 if (cc
->connected
& CC_SPEAKERS
) {
851 if (headphones
<= 0 && lineout
<= 0)
852 ldev
->gpio
.methods
->set_speakers(codec
->gpio
, 1);
853 ctl
= snd_ctl_new1(&speakers_ctl
, codec
->gpio
);
854 ldev
->speaker_ctrl
= ctl
;
855 aoa_snd_ctl_add(ctl
);
857 if (cc
->connected
& CC_HEADPHONE
) {
859 ldev
->gpio
.methods
->set_headphone(codec
->gpio
, 1);
860 ctl
= snd_ctl_new1(&headphone_ctl
, codec
->gpio
);
861 ldev
->headphone_ctrl
= ctl
;
862 aoa_snd_ctl_add(ctl
);
863 ldev
->have_headphone_detect
=
865 ->set_notify(&ldev
->gpio
,
866 AOA_NOTIFY_HEADPHONE
,
868 &ldev
->selfptr_headphone
);
869 if (ldev
->have_headphone_detect
) {
870 ctl
= snd_ctl_new1(&headphone_detect_choice
,
872 aoa_snd_ctl_add(ctl
);
873 ctl
= snd_ctl_new1(&headphone_detected
,
875 ldev
->headphone_detected_ctrl
= ctl
;
876 aoa_snd_ctl_add(ctl
);
879 if (cc
->connected
& CC_LINEOUT
) {
881 ldev
->gpio
.methods
->set_lineout(codec
->gpio
, 1);
882 ctl
= snd_ctl_new1(&lineout_ctl
, codec
->gpio
);
883 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
884 strlcpy(ctl
->id
.name
,
885 "Headphone Switch", sizeof(ctl
->id
.name
));
886 ldev
->lineout_ctrl
= ctl
;
887 aoa_snd_ctl_add(ctl
);
888 ldev
->have_lineout_detect
=
890 ->set_notify(&ldev
->gpio
,
893 &ldev
->selfptr_lineout
);
894 if (ldev
->have_lineout_detect
) {
895 ctl
= snd_ctl_new1(&lineout_detect_choice
,
897 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
898 strlcpy(ctl
->id
.name
,
899 "Headphone Detect Autoswitch",
900 sizeof(ctl
->id
.name
));
901 aoa_snd_ctl_add(ctl
);
902 ctl
= snd_ctl_new1(&lineout_detected
,
904 if (cc
->connected
& CC_LINEOUT_LABELLED_HEADPHONE
)
905 strlcpy(ctl
->id
.name
,
906 "Headphone Detected",
907 sizeof(ctl
->id
.name
));
908 ldev
->lineout_detected_ctrl
= ctl
;
909 aoa_snd_ctl_add(ctl
);
914 /* now update initial state */
915 if (ldev
->have_headphone_detect
)
916 layout_notify(&ldev
->selfptr_headphone
);
917 if (ldev
->have_lineout_detect
)
918 layout_notify(&ldev
->selfptr_lineout
);
921 static struct aoa_fabric layout_fabric
= {
922 .name
= "SoundByLayout",
923 .owner
= THIS_MODULE
,
924 .found_codec
= layout_found_codec
,
925 .remove_codec
= layout_remove_codec
,
926 .attached_codec
= layout_attached_codec
,
929 static int aoa_fabric_layout_probe(struct soundbus_dev
*sdev
)
931 struct device_node
*sound
= NULL
;
932 unsigned int *layout_id
;
933 struct layout
*layout
;
934 struct layout_dev
*ldev
= NULL
;
937 /* hm, currently we can only have one ... */
941 /* by breaking out we keep a reference */
942 while ((sound
= of_get_next_child(sdev
->ofdev
.node
, sound
))) {
943 if (sound
->type
&& strcasecmp(sound
->type
, "soundchip") == 0)
946 if (!sound
) return -ENODEV
;
948 layout_id
= (unsigned int *) get_property(sound
, "layout-id", NULL
);
951 printk(KERN_INFO
"snd-aoa-fabric-layout: found bus with layout %d ", *layout_id
);
953 layout
= find_layout_by_id(*layout_id
);
955 printk("(no idea how to handle)\n");
959 ldev
= kzalloc(sizeof(struct layout_dev
), GFP_KERNEL
);
963 layout_device
= ldev
;
966 ldev
->layout
= layout
;
967 ldev
->gpio
.node
= sound
->parent
;
968 switch (layout
->layout_id
) {
969 case 41: /* that unknown machine no one seems to have */
970 case 51: /* PowerBook5,4 */
971 case 58: /* Mac Mini */
972 ldev
->gpio
.methods
= ftr_gpio_methods
;
975 ldev
->gpio
.methods
= pmf_gpio_methods
;
977 ldev
->selfptr_headphone
.ptr
= ldev
;
978 ldev
->selfptr_lineout
.ptr
= ldev
;
979 sdev
->ofdev
.dev
.driver_data
= ldev
;
982 list_add(&ldev
->list
, &layouts_list
);
983 layouts_list_items
++;
985 /* assign these before registering ourselves, so
986 * callbacks that are done during registration
987 * already have the values */
988 sdev
->pcmid
= ldev
->layout
->pcmid
;
989 if (ldev
->layout
->busname
) {
990 sdev
->pcmname
= ldev
->layout
->busname
;
992 sdev
->pcmname
= "Master";
995 ldev
->gpio
.methods
->init(&ldev
->gpio
);
997 err
= aoa_fabric_register(&layout_fabric
);
998 if (err
&& err
!= -EALREADY
) {
999 printk(KERN_INFO
"snd-aoa-fabric-layout: can't use,"
1000 " another fabric is active!\n");
1005 ldev
->switch_on_headphone
= 1;
1006 ldev
->switch_on_lineout
= 1;
1009 /* we won't be using these then... */
1010 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1011 /* reset if we didn't use it */
1012 sdev
->pcmname
= NULL
;
1014 list_del(&ldev
->list
);
1015 layouts_list_items
--;
1017 if (sound
) of_node_put(sound
);
1018 layout_device
= NULL
;
1019 if (ldev
) kfree(ldev
);
1023 static int aoa_fabric_layout_remove(struct soundbus_dev
*sdev
)
1025 struct layout_dev
*ldev
= sdev
->ofdev
.dev
.driver_data
;
1028 for (i
=0; i
<MAX_CODECS_PER_BUS
; i
++) {
1029 if (ldev
->codecs
[i
]) {
1030 aoa_fabric_unlink_codec(ldev
->codecs
[i
]);
1032 ldev
->codecs
[i
] = NULL
;
1034 list_del(&ldev
->list
);
1035 layouts_list_items
--;
1036 of_node_put(ldev
->sound
);
1038 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1039 AOA_NOTIFY_HEADPHONE
,
1042 ldev
->gpio
.methods
->set_notify(&ldev
->gpio
,
1043 AOA_NOTIFY_LINE_OUT
,
1047 ldev
->gpio
.methods
->exit(&ldev
->gpio
);
1048 layout_device
= NULL
;
1051 sdev
->pcmname
= NULL
;
1056 static int aoa_fabric_layout_suspend(struct soundbus_dev
*sdev
, pm_message_t state
)
1058 struct layout_dev
*ldev
= sdev
->ofdev
.dev
.driver_data
;
1060 printk("aoa_fabric_layout_suspend()\n");
1062 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_off
)
1063 ldev
->gpio
.methods
->all_amps_off(&ldev
->gpio
);
1068 static int aoa_fabric_layout_resume(struct soundbus_dev
*sdev
)
1070 struct layout_dev
*ldev
= sdev
->ofdev
.dev
.driver_data
;
1072 printk("aoa_fabric_layout_resume()\n");
1074 if (ldev
->gpio
.methods
&& ldev
->gpio
.methods
->all_amps_off
)
1075 ldev
->gpio
.methods
->all_amps_restore(&ldev
->gpio
);
1081 static struct soundbus_driver aoa_soundbus_driver
= {
1082 .name
= "snd_aoa_soundbus_drv",
1083 .owner
= THIS_MODULE
,
1084 .probe
= aoa_fabric_layout_probe
,
1085 .remove
= aoa_fabric_layout_remove
,
1087 .suspend
= aoa_fabric_layout_suspend
,
1088 .resume
= aoa_fabric_layout_resume
,
1092 static int __init
aoa_fabric_layout_init(void)
1096 err
= soundbus_register_driver(&aoa_soundbus_driver
);
1102 static void __exit
aoa_fabric_layout_exit(void)
1104 soundbus_unregister_driver(&aoa_soundbus_driver
);
1105 aoa_fabric_unregister(&layout_fabric
);
1108 module_init(aoa_fabric_layout_init
);
1109 module_exit(aoa_fabric_layout_exit
);