Android邁進了4.0,相應的Linux內核也進入了3.x時代。之後的一個工作估計要將2.6.32的驅動移植到3.x上面來。因此趁現在有空,看看alsa在這方面有什麼改動。
總的來說,架構大的改動是不大可能的。codec中幾個關鍵結構體沒有大的變化,如snd_soc_dai_ops、snd_soc_dai_driver(相當於2.6.32中的snd_soc_dai),倒是以前的snd_soc_codec_device重定義為snd_soc_codec_driver,這個算是最明顯的。
注冊用結構體-snd_soc_codec_driver
2.6.32:
[cpp]
- /* codec device */
- struct snd_soc_codec_device {
- int (*probe)(struct platform_device *pdev);
- int (*remove)(struct platform_device *pdev);
- int (*suspend)(struct platform_device *pdev, pm_message_t state);
- int (*resume)(struct platform_device *pdev);
- };
3.1.1:
[cpp]
- /* codec driver */
- struct snd_soc_codec_driver {
-
- /* driver ops */
- int (*probe)(struct snd_soc_codec *);
- int (*remove)(struct snd_soc_codec *);
- int (*suspend)(struct snd_soc_codec *,
- pm_message_t state);
- int (*resume)(struct snd_soc_codec *);
-
- /* Default control and setup, added after probe() is run */
- const struct snd_kcontrol_new *controls;
- int num_controls;
- const struct snd_soc_dapm_widget *dapm_widgets;
- int num_dapm_widgets;
- const struct snd_soc_dapm_route *dapm_routes;
- int num_dapm_routes;
-
- /* codec wide operations */
- int (*set_sysclk)(struct snd_soc_codec *codec,
- int clk_id, unsigned int freq, int dir);
- int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
- unsigned int freq_in, unsigned int freq_out);
-
- /* codec IO */
- unsigned int (*read)(struct snd_soc_codec *, unsigned int);
- int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
- int (*display_register)(struct snd_soc_codec *, char *,
- size_t, unsigned int);
- int (*volatile_register)(struct snd_soc_codec *, unsigned int);
- int (*readable_register)(struct snd_soc_codec *, unsigned int);
- int (*writable_register)(struct snd_soc_codec *, unsigned int);
- short reg_cache_size;
- short reg_cache_step;
- short reg_word_size;
- const void *reg_cache_default;
- short reg_access_size;
- const struct snd_soc_reg_access *reg_access_default;
- enum snd_soc_compress_type compress_type;
-
- /* codec bias level */
- int (*set_bias_level)(struct snd_soc_codec *,
- enum snd_soc_bias_level level);
-
- void (*seq_notifier)(struct snd_soc_dapm_context *,
- enum snd_soc_dapm_type, int);
-
- /* probe ordering - for components with runtime dependencies */
- int probe_order;
- int remove_order;
- };
位於snd_soc_codec_driver中的一些codec IO成員函數和set_bias_level回調函數原來都放在另外一個結構體snd_soc_codec中,現在放置在這裡了,這是根據源碼結構調整的結果。事實真正需要設置的成員也不是很多,如下:
[cpp]
- static struct snd_soc_codec_driver soc_codec_dev_wm9713 = {
- .probe = wm9713_soc_probe,
- .remove = wm9713_soc_remove,
- .suspend = wm9713_soc_suspend,
- .resume = wm9713_soc_resume,
- .read = ac97_read,
- .write = ac97_write,
- .set_bias_level = wm9713_set_bias_level,
- .reg_cache_size = ARRAY_SIZE(wm9713_reg),
- .reg_word_size = sizeof(u16),
- .reg_cache_step = 2,
- .reg_cache_default = wm9713_reg,
- .dapm_widgets = wm9713_dapm_widgets,
- .num_dapm_widgets = ARRAY_SIZE(wm9713_dapm_widgets),
- .dapm_routes = wm9713_audio_map,
- .num_dapm_routes = ARRAY_SIZE(wm9713_audio_map),
- };
probe、remove、suspend、resume相信不用累述了,volatile_register函數判斷指定的寄存器是否volatile,reg_cache_size一般為寄存器數目,reg_word_size為寄存器的字長,reg_cache_default為寄存器默認值配置表。
而dapm_widgets、dapm_routes就比較“犀利”了。之前的dapm widgets和routes分別通過函數snd_soc_dapm_new_controls和snd_soc_dapm_add_routes來注冊的(當然現在還保留這些接口),現在則可以填入到這個結構體,在soc-core裡注冊,省了不少功夫:
[cpp]
- static int soc_probe_codec(struct snd_soc_card *card,
- struct snd_soc_codec *codec)
- {
- //...
-
- if (driver->dapm_widgets)
- snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
- driver->num_dapm_widgets);
-
- //...
-
- if (driver->controls)
- snd_soc_add_controls(codec, driver->controls,
- driver->num_controls);
- if (driver->dapm_routes)
- snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
- driver->num_dapm_routes);
- //...
- }
同時可看到dirver ops的函數參數有所不同了,以前是struct platform_device *pdev,現在改為struct snd_soc_codec *codec,這個與codec的注冊函數snd_soc_register_codec和設備的drvdata有關,之後會逐一分析。