*参照元 [#occ0d570]
#backlinks

*説明 [#o4e77465]
-パス: [[linux-4.4.1/sound/soc/soc-core.c]]

-FIXME: これは何?
--説明


**引数 [#kc649533]
-struct device *dev
--
--[[linux-4.4.1/device]]
-const struct snd_soc_codec_driver *codec_drv
--
--[[linux-4.4.1/snd_soc_codec_driver]]
-struct snd_soc_dai_driver *dai_drv
--
--[[linux-4.4.1/snd_soc_dai_driver]]
-int num_dai
--


**返り値 [#t00a94d3]
-int
--


**参考 [#h7a57f3d]


*実装 [#ge3d5546]
 /**
  * snd_soc_register_codec - Register a codec with the ASoC core
  *
  * @dev: The parent device for this codec
  * @codec_drv: Codec driver
  * @dai_drv: The associated DAI driver
  * @num_dai: Number of DAIs
  */
 int snd_soc_register_codec(struct device *dev,
                            const struct snd_soc_codec_driver *codec_drv,
                            struct snd_soc_dai_driver *dai_drv,
                            int num_dai)
 {
         struct snd_soc_dapm_context *dapm;
         struct snd_soc_codec *codec;
         struct snd_soc_dai *dai;
         int ret, i;
 
-
--[[linux-4.4.1/snd_soc_dapm_context]]
--[[linux-4.4.1/snd_soc_codec]]
--[[linux-4.4.1/snd_soc_dai]]

         dev_dbg(dev, "codec register %s\n", dev_name(dev));
 
-
--[[linux-4.4.1/dev_dbg()]]
--[[linux-4.4.1/dev_name()]]

         codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
         if (codec == NULL)
                 return -ENOMEM;
 
         codec->component.codec = codec;
 
-codec->component は struct snd_soc_component 型
--[[linux-4.4.1/snd_soc_component]]
--[[linux-4.4.1/kzalloc()]]

         ret = snd_soc_component_initialize(&codec->component,
                         &codec_drv->component_driver, dev);
         if (ret)
                 goto err_free;
 
-
-codec->component は struct snd_soc_component 型
--[[linux-4.4.1/snd_soc_component]]
--[[linux-4.4.1/snd_soc_component_initialize()]]

         if (codec_drv->controls) {
                 codec->component.controls = codec_drv->controls;
                 codec->component.num_controls = codec_drv->num_controls;
         }
         if (codec_drv->dapm_widgets) {
                 codec->component.dapm_widgets = codec_drv->dapm_widgets;
                 codec->component.num_dapm_widgets = codec_drv->num_dapm_widgets;
         }
         if (codec_drv->dapm_routes) {
                 codec->component.dapm_routes = codec_drv->dapm_routes;
                 codec->component.num_dapm_routes = codec_drv->num_dapm_routes;
         }
 
-controls, dapm_widgets, dapm_routes の 3つのメンバは、
struct snd_soc_codec_driver と struct snd_soc_component_driver の両方に存在する。
恐らく codec_driver から component_driver に移動させている途中なのだと思われる。
--[[linux-4.4.1/snd_soc_codec_driver]]
--[[linux-4.4.1/snd_soc_component_driver]]
-codec_driver は component_driver を内包しているので、
codec_driver 側のメンバは完全に要らない子になる。
(Linux 4.4.1 では存在するが、将来のバージョンでは codec_driver 側のメンバは削除されているようだ)

         if (codec_drv->probe)
                 codec->component.probe = snd_soc_codec_drv_probe;
         if (codec_drv->remove)
                 codec->component.remove = snd_soc_codec_drv_remove;
         if (codec_drv->write)
                 codec->component.write = snd_soc_codec_drv_write;
         if (codec_drv->read)
                 codec->component.read = snd_soc_codec_drv_read;
         codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
 
-
--[[linux-4.4.1/snd_soc_codec_drv_probe()]]
--[[linux-4.4.1/snd_soc_codec_drv_remove()]]
--[[linux-4.4.1/snd_soc_codec_drv_write()]]
--[[linux-4.4.1/snd_soc_codec_drv_read()]]

         dapm = snd_soc_codec_get_dapm(codec);
         dapm->idle_bias_off = codec_drv->idle_bias_off;
         dapm->suspend_bias_off = codec_drv->suspend_bias_off;
-
--[[linux-4.4.1/snd_soc_codec_get_dapm()]]

         if (codec_drv->seq_notifier)
                 dapm->seq_notifier = codec_drv->seq_notifier;
         if (codec_drv->set_bias_level)
                 dapm->set_bias_level = snd_soc_codec_set_bias_level;
         codec->dev = dev;
         codec->driver = codec_drv;
         codec->component.val_bytes = codec_drv->reg_word_size;
 
 #ifdef CONFIG_DEBUG_FS
-
--[[linux-4.4.1/CONFIG_DEBUG_FS]]

         codec->component.init_debugfs = soc_init_codec_debugfs;
         codec->component.debugfs_prefix = "codec";
-
--[[linux-4.4.1/soc_init_codec_debugfs()]]

 #endif
 
         if (codec_drv->get_regmap)
                 codec->component.regmap = codec_drv->get_regmap(dev);
 
-codec->component は struct snd_soc_component 型
--[[linux-4.4.1/snd_soc_component]]

         for (i = 0; i < num_dai; i++) {
                 fixup_codec_formats(&dai_drv[i].playback);
                 fixup_codec_formats(&dai_drv[i].capture);
         }
 
-
--[[linux-4.4.1/fixup_codec_formats()]]

         ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false);
         if (ret < 0) {
                 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
                 goto err_cleanup;
         }
 
-
--[[linux-4.4.1/snd_soc_register_dais()]]
--[[linux-4.4.1/dev_err()]]

         list_for_each_entry(dai, &codec->component.dai_list, list)
                 dai->codec = codec;
 
-
--[[linux-4.4.1/list_for_each_entry()]]

         mutex_lock(&client_mutex);
         snd_soc_component_add_unlocked(&codec->component);
         list_add(&codec->list, &codec_list);
         mutex_unlock(&client_mutex);
 
-
-わかりづらいけど、snd_soc_component_add_unlocked() にて、
component->dev の devres に登録されているregmap を component->regmap にコピーする処理が行われる。
--コーデックドライバ内で snd_soc_read() や snd_soc_component_read() が使えるようになる。
--kcontrols を使う時に ALSA が必ず snd_soc_component_read() を使うので、ミキサーの機能を使うなら必須。
-dev しか渡してないのに、こいつらはどこから来ているか?
--component->dev は snd_soc_component_initialize() が初期化する。
---簡単に言えば引数の dev を component->dev = dev のようにコピーするだけ。
--dev の devres の regmap は devm_init_regmap() を使って初期化する。
---regmap を使いたいだけなら regmap_init() でも良いけど、devres に登録されないので、
ALSA で使うときは devm_init_regmap() じゃないとダメ。
-参考
--[[linux-4.4.1/client_mutex(global)]]
--[[linux-4.4.1/mutex_lock()]]
--[[linux-4.4.1/snd_soc_component_add_unlocked()]]
---[[linux-4.4.1/snd_soc_read()]]
---[[linux-4.4.1/snd_soc_component_read()]]
---[[linux-4.4.1/snd_soc_component_initialize()]]
---[[linux-4.4.1/devm_init_regmap()]]
---[[linux-4.4.1/init_regmap()]]
--[[linux-4.4.1/list_add()]]
--[[linux-4.4.1/mutex_unlock()]]

         dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n",
                 codec->component.name);
         return 0;
 
 err_cleanup:
         snd_soc_component_cleanup(&codec->component);
-
--[[linux-4.4.1/snd_soc_component_cleanup()]]

 err_free:
         kfree(codec);
-
--[[linux-4.4.1/kfree()]]

         return ret;
 }
 EXPORT_SYMBOL_GPL(snd_soc_register_codec);
-
--[[linux-4.4.1/EXPORT_SYMBOL_GPL()]]


*コメント [#u2dfba55]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS