aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2014-01-29 06:51:12 -0500
committerTakashi Iwai <tiwai@suse.de>2014-02-12 04:58:20 -0500
commit393aa9c1cc514774332d7bc861307a76206e358d (patch)
treeb419a57e8af4b904247c0ffd3a7f0cc924bf2278
parent80d7d771ae839d6fc2286f443ad8445b6721a7f3 (diff)
ALSA: Mandate to pass a device pointer at card creation time
This is a part of preliminary works for modernizing the ALSA device structure. So far, we set card->dev at later point after the object creation. Because of this, the core layer doesn't always know which device is being handled before it's actually registered, and it makes impossible to show the device in error messages, for example. The first goal is to achieve a proper struct device initialization at the very beginning of probing. As a first step, this patch introduces snd_card_new() function (yes there was the same named function in the very past), in order to receive the parent device pointer from the very beginning. snd_card_create() is marked as deprecated. At this point, there is no functional change other than that. The actual change of the device creation scheme will follow later. Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--Documentation/DocBook/writing-an-alsa-driver.tmpl72
-rw-r--r--include/sound/core.h13
-rw-r--r--sound/core/init.c8
3 files changed, 42 insertions, 51 deletions
diff --git a/Documentation/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl
index 06741e925985..d0056a4e9c53 100644
--- a/Documentation/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl
@@ -468,8 +468,6 @@
468 return err; 468 return err;
469 } 469 }
470 470
471 snd_card_set_dev(card, &pci->dev);
472
473 *rchip = chip; 471 *rchip = chip;
474 return 0; 472 return 0;
475 } 473 }
@@ -492,7 +490,8 @@
492 } 490 }
493 491
494 /* (2) */ 492 /* (2) */
495 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 493 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
494 0, &card);
496 if (err < 0) 495 if (err < 0)
497 return err; 496 return err;
498 497
@@ -591,7 +590,8 @@
591 struct snd_card *card; 590 struct snd_card *card;
592 int err; 591 int err;
593 .... 592 ....
594 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 593 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
594 0, &card);
595]]> 595]]>
596 </programlisting> 596 </programlisting>
597 </informalexample> 597 </informalexample>
@@ -809,28 +809,34 @@
809 809
810 <para> 810 <para>
811 As mentioned above, to create a card instance, call 811 As mentioned above, to create a card instance, call
812 <function>snd_card_create()</function>. 812 <function>snd_card_new()</function>.
813 813
814 <informalexample> 814 <informalexample>
815 <programlisting> 815 <programlisting>
816<![CDATA[ 816<![CDATA[
817 struct snd_card *card; 817 struct snd_card *card;
818 int err; 818 int err;
819 err = snd_card_create(index, id, module, extra_size, &card); 819 err = snd_card_new(&pci->dev, index, id, module, extra_size, &card);
820]]> 820]]>
821 </programlisting> 821 </programlisting>
822 </informalexample> 822 </informalexample>
823 </para> 823 </para>
824 824
825 <para> 825 <para>
826 The function takes five arguments, the card-index number, the 826 The function takes six arguments: the parent device pointer,
827 id string, the module pointer (usually 827 the card-index number, the id string, the module pointer (usually
828 <constant>THIS_MODULE</constant>), 828 <constant>THIS_MODULE</constant>),
829 the size of extra-data space, and the pointer to return the 829 the size of extra-data space, and the pointer to return the
830 card instance. The extra_size argument is used to 830 card instance. The extra_size argument is used to
831 allocate card-&gt;private_data for the 831 allocate card-&gt;private_data for the
832 chip-specific data. Note that these data 832 chip-specific data. Note that these data
833 are allocated by <function>snd_card_create()</function>. 833 are allocated by <function>snd_card_new()</function>.
834 </para>
835
836 <para>
837 The first argument, the pointer of struct
838 <structname>device</structname>, specifies the parent device.
839 For PCI devices, typically &amp;pci-&gt; is passed there.
834 </para> 840 </para>
835 </section> 841 </section>
836 842
@@ -916,16 +922,16 @@
916 </para> 922 </para>
917 923
918 <section id="card-management-chip-specific-snd-card-new"> 924 <section id="card-management-chip-specific-snd-card-new">
919 <title>1. Allocating via <function>snd_card_create()</function>.</title> 925 <title>1. Allocating via <function>snd_card_new()</function>.</title>
920 <para> 926 <para>
921 As mentioned above, you can pass the extra-data-length 927 As mentioned above, you can pass the extra-data-length
922 to the 4th argument of <function>snd_card_create()</function>, i.e. 928 to the 5th argument of <function>snd_card_new()</function>, i.e.
923 929
924 <informalexample> 930 <informalexample>
925 <programlisting> 931 <programlisting>
926<![CDATA[ 932<![CDATA[
927 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 933 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
928 sizeof(struct mychip), &card); 934 sizeof(struct mychip), &card);
929]]> 935]]>
930 </programlisting> 936 </programlisting>
931 </informalexample> 937 </informalexample>
@@ -954,7 +960,7 @@
954 960
955 <para> 961 <para>
956 After allocating a card instance via 962 After allocating a card instance via
957 <function>snd_card_create()</function> (with 963 <function>snd_card_new()</function> (with
958 <constant>0</constant> on the 4th arg), call 964 <constant>0</constant> on the 4th arg), call
959 <function>kzalloc()</function>. 965 <function>kzalloc()</function>.
960 966
@@ -963,7 +969,8 @@
963<![CDATA[ 969<![CDATA[
964 struct snd_card *card; 970 struct snd_card *card;
965 struct mychip *chip; 971 struct mychip *chip;
966 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 972 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
973 0, &card);
967 ..... 974 .....
968 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 975 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
969]]> 976]]>
@@ -1170,8 +1177,6 @@
1170 return err; 1177 return err;
1171 } 1178 }
1172 1179
1173 snd_card_set_dev(card, &pci->dev);
1174
1175 *rchip = chip; 1180 *rchip = chip;
1176 return 0; 1181 return 0;
1177 } 1182 }
@@ -1526,30 +1531,6 @@
1526 1531
1527 </section> 1532 </section>
1528 1533
1529 <section id="pci-resource-device-struct">
1530 <title>Registration of Device Struct</title>
1531 <para>
1532 At some point, typically after calling <function>snd_device_new()</function>,
1533 you need to register the struct <structname>device</structname> of the chip
1534 you're handling for udev and co. ALSA provides a macro for compatibility with
1535 older kernels. Simply call like the following:
1536 <informalexample>
1537 <programlisting>
1538<![CDATA[
1539 snd_card_set_dev(card, &pci->dev);
1540]]>
1541 </programlisting>
1542 </informalexample>
1543 so that it stores the PCI's device pointer to the card. This will be
1544 referred by ALSA core functions later when the devices are registered.
1545 </para>
1546 <para>
1547 In the case of non-PCI, pass the proper device struct pointer of the BUS
1548 instead. (In the case of legacy ISA without PnP, you don't have to do
1549 anything.)
1550 </para>
1551 </section>
1552
1553 <section id="pci-resource-entries"> 1534 <section id="pci-resource-entries">
1554 <title>PCI Entries</title> 1535 <title>PCI Entries</title>
1555 <para> 1536 <para>
@@ -5740,7 +5721,8 @@ struct _snd_pcm_runtime {
5740 struct mychip *chip; 5721 struct mychip *chip;
5741 int err; 5722 int err;
5742 .... 5723 ....
5743 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 5724 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5725 0, &card);
5744 .... 5726 ....
5745 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 5727 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
5746 .... 5728 ....
@@ -5752,7 +5734,7 @@ struct _snd_pcm_runtime {
5752 </informalexample> 5734 </informalexample>
5753 5735
5754 When you created the chip data with 5736 When you created the chip data with
5755 <function>snd_card_create()</function>, it's anyway accessible 5737 <function>snd_card_new()</function>, it's anyway accessible
5756 via <structfield>private_data</structfield> field. 5738 via <structfield>private_data</structfield> field.
5757 5739
5758 <informalexample> 5740 <informalexample>
@@ -5766,8 +5748,8 @@ struct _snd_pcm_runtime {
5766 struct mychip *chip; 5748 struct mychip *chip;
5767 int err; 5749 int err;
5768 .... 5750 ....
5769 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 5751 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5770 sizeof(struct mychip), &card); 5752 sizeof(struct mychip), &card);
5771 .... 5753 ....
5772 chip = card->private_data; 5754 chip = card->private_data;
5773 .... 5755 ....
diff --git a/include/sound/core.h b/include/sound/core.h
index d0cee2c8c04f..e946b2428ea0 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -283,9 +283,16 @@ int snd_card_locked(int card);
283extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd); 283extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
284#endif 284#endif
285 285
286int snd_card_create(int idx, const char *id, 286int snd_card_new(struct device *parent, int idx, const char *xid,
287 struct module *module, int extra_size, 287 struct module *module, int extra_size,
288 struct snd_card **card_ret); 288 struct snd_card **card_ret);
289
290static inline int __deprecated
291snd_card_create(int idx, const char *id, struct module *module, int extra_size,
292 struct snd_card **ret)
293{
294 return snd_card_new(NULL, idx, id, module, extra_size, ret);
295}
289 296
290int snd_card_disconnect(struct snd_card *card); 297int snd_card_disconnect(struct snd_card *card);
291int snd_card_free(struct snd_card *card); 298int snd_card_free(struct snd_card *card);
diff --git a/sound/core/init.c b/sound/core/init.c
index a16d765cdf47..f4d3ac633ff8 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -157,7 +157,8 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
157} 157}
158 158
159/** 159/**
160 * snd_card_create - create and initialize a soundcard structure 160 * snd_card_new - create and initialize a soundcard structure
161 * @parent: the parent device object
161 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 162 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
162 * @xid: card identification (ASCII string) 163 * @xid: card identification (ASCII string)
163 * @module: top level module for locking 164 * @module: top level module for locking
@@ -172,7 +173,7 @@ static int get_slot_from_bitmask(int mask, int (*check)(struct module *, int),
172 * 173 *
173 * Return: Zero if successful or a negative error code. 174 * Return: Zero if successful or a negative error code.
174 */ 175 */
175int snd_card_create(int idx, const char *xid, 176int snd_card_new(struct device *parent, int idx, const char *xid,
176 struct module *module, int extra_size, 177 struct module *module, int extra_size,
177 struct snd_card **card_ret) 178 struct snd_card **card_ret)
178{ 179{
@@ -213,6 +214,7 @@ int snd_card_create(int idx, const char *xid,
213 if (idx >= snd_ecards_limit) 214 if (idx >= snd_ecards_limit)
214 snd_ecards_limit = idx + 1; /* increase the limit */ 215 snd_ecards_limit = idx + 1; /* increase the limit */
215 mutex_unlock(&snd_card_mutex); 216 mutex_unlock(&snd_card_mutex);
217 card->dev = parent;
216 card->number = idx; 218 card->number = idx;
217 card->module = module; 219 card->module = module;
218 INIT_LIST_HEAD(&card->devices); 220 INIT_LIST_HEAD(&card->devices);
@@ -251,7 +253,7 @@ int snd_card_create(int idx, const char *xid,
251 kfree(card); 253 kfree(card);
252 return err; 254 return err;
253} 255}
254EXPORT_SYMBOL(snd_card_create); 256EXPORT_SYMBOL(snd_card_new);
255 257
256/* return non-zero if a card is already locked */ 258/* return non-zero if a card is already locked */
257int snd_card_locked(int card) 259int snd_card_locked(int card)