ALSA/ASoC:如何正确加载设备/驱动程序?

dex*_*0rb 10 alsa kernel-modules

我正在使用 Buildroot 为 NXP LPC3250 微控制器构建嵌入式 Linux (2.6.39.2) 系统。

现在,我正在尝试启动并运行 ALSA/ASoC,但在让模块协同工作时遇到了一些问题。(我认为!)

一些重要的背景:

我正在测试的板是Embedded Artists 3250 V2 开发板。V2 与 V1 的不同之处在于它没有 LCD 屏幕,但包含I2S 音频编解码器:NXP UDA1380。对 EA3250 V1 的电路板支持包含在内核的LPCLinux版本中。还有一个不同的开发板,称为Phytec 3250,其中包含相同的 UDA1380 编解码器芯片。LPCLinux 发行版还支持 Phytec 板以及音频编解码器芯片。据我所知,Phytec 3250 板在 I2C 地址0x18上具有 UDA1380 编解码器。在我的 EA3250 V2 板上,音频编解码器位于 I2C 地址0x1a(我已经验证芯片已通电,我可以使用 I2C-tools 包与它通信。它响应 i2cdetect,我可以使用 i2cget 从芯片正确读取寄存器。)

修改源码:

我需要编辑 Phytec 3250 驱动程序文件来更改编解码器芯片的地址。我编辑了lpc3xxx-uda1380.c 的这一部分:

static struct snd_soc_dai_link phy3250_uda1380_dai[] = {
       {
                  .name           = "uda1380",
                  .stream_name    = "UDA1380 Duplex",
  #if defined(CONFIG_SND_LPC32XX_USEI2S1)
                  .cpu_dai_name   = "lpc3xxx-i2s1",
  #else
                  .cpu_dai_name   = "lpc3xxx-i2s0",
  #endif
                  .codec_dai_name = "uda1380-hifi",
                  .init           = phy3250_uda1380_init,
                  .platform_name  = "lpc3xxx-audio.0",
         //EDIT// .codec_name     = "uda1380-codec.0-0018",  //EDIT//
                  .codec_name     = "uda1380-codec.0-001a",
                  .ops            = &phy3250_uda1380_ops,
          },
  };
Run Code Online (Sandbox Code Playgroud)

进行此更改后,我继续重新构建系统,一切都编译正常。启动到系统后,我在 中有以下模块(除了标准的核心模块)/lib/modules/2.6.39.2/kernel/sound

 ./soc/codecs: snd-soc-uda1380.ko          <-- ASoC codec driver
./soc/lpc3xxx: snd-soc-lpc3xxx-i2s.ko      <-- ASoC DAI
               snd-soc-lpc3xxx-uda1380.ko  <-- ASoC machine driver
               snd-soc-lpc3xxx.ko          <-- ASoC platform driver
Run Code Online (Sandbox Code Playgroud)

现在,我如何将所有这些东西绑定在一起?

只是插入模块modprobe实际上并没有将设备提供给 ALSA/ASoC。我无法检测到声卡。这是否意味着我现在必须创建一个uda1380-codec在地址0x1a处调用的新设备并将其绑定到驱动程序?我尝试执行以下操作:
echo uda1380-codec 0x01a > /sys/bus/i2c/devices/i2c-0/new_device
并收到:
i2c i2c-0: new_device: Instantiated device uda1380-codec at 0x1a
然后我尝试将驱动程序绑定到设备:
echo 0x1a > /sys/bus/i2c/drivers/uda1380-codec/bind
并收到:
sh: write error: No such device

我尝试的所有操作都收到此错误!我感觉我没有正确创建设备,然后我不确定如何将它绑定到正确的驱动程序。

诺塔·贝内:

昨晚我正在玩这个,不知何故能够让 ASoC 唤醒并至少探测卡。我想我在玩不同的绑定。很晚也很难记住我的步骤,但我至少能够以某种方式得到以下错误:

uda1380-codec 0-001a: asoc: failed to probe CODEC uda1380-codec.0-001a: -22
asoc: failed to instantiate card LPC32XX: -22
Run Code Online (Sandbox Code Playgroud)

我一直无法重现此错误!

编辑:

我已经确认我的修改后的代码正在编译,所以驱动程序现在应该与正确的地址交谈。手动加载模块后,输出lsmod为:

Module                      Size  Used by    Not tainted
snd_soc_lpc3xxx_uda1380     2087  0 
snd_soc_lpc3xxx             3089  0 
snd_soc_lpc3xxx_i2s         4089  1 
snd_soc_uda1380            10865  0 
snd_soc_core               51549  4 snd_soc_lpc3xxx_uda1380,snd_soc_lpc3xxx,snd_soc_lpc3xxx_i2s,snd_soc_uda1380
snd_pcm                    52098  2 snd_soc_lpc3xxx,snd_soc_core
snd_timer                  15590  1 snd_pcm
snd_page_alloc              3021  1 snd_pcm
snd                        37286  3 snd_soc_core,snd_pcm,snd_timer
Run Code Online (Sandbox Code Playgroud)

这看起来对吗?

还有我的设备表:

# Audio stuff
/dev/audio      c       666     0       29      14      4       -       -       -
#/dev/audio1    c       666     0       29      14      20      -       -       -
/dev/dsp        c       666     0       29      14      3       -       -       -
#/dev/dsp1      c       666     0       29      14      19      -       -       -
#/dev/sndstat   c       666     0       29      14      6       -       -       -
/dev/mixer      c       666     0       29      14      0       -       -       -
/dev/snd        d       755     0       29      -       -       -       -       -
/dev/snd/controlC0      c       666     0       29      116     0       -       -       -
/dev/snd/pcmC0D0c       c       666     0       29      116     24      -       -       -
/dev/snd/pcmC0D0p       c       666     0       29      116     16      -       -       -
/dev/snd/seq    c       666     0       29      116     1       -       -       -
/dev/snd/timer  c       666     0       29      116     33      -       -       -
Run Code Online (Sandbox Code Playgroud)

dex*_*0rb 3

需要编辑定义平台设备的板文件。我需要修改arch/arm/mach-lpc32xx/ea3250.c

添加这个:

/*
 * Platform Data for UDA1380 Audiocodec.
 * As there are no GPIOs for codec power & reset pins,
 * dummy GPIO numbers are used.
 */
static struct uda1380_platform_data uda1380_info = {
    .gpio_power = LPC32XX_GPIO(LPC32XX_GPO_P3_GRP,10),
    .gpio_reset = LPC32XX_GPIO(LPC32XX_GPO_P3_GRP,2),
    .dac_clk    = UDA1380_DAC_CLK_WSPLL,
};
Run Code Online (Sandbox Code Playgroud)

编辑此内容以包含编解码器:

static struct i2c_board_info __initdata ea3250_i2c_board_info [] = {
        {   I2C_BOARD_INFO("uda1380", 0x1a),
            .platform_data = &uda1380_info,
        }, 
#if defined (CONFIG_LEDS_PCA9532)
        {
            I2C_BOARD_INFO("pca9532", I2C_PCA9532_ADDR),
            .platform_data = &ea3250_leds,
        },
#endif
#if defined (CONFIG_FB_ARMCLCD)
        {
            /* 8Kb Configuration EEPROM on display board */
            I2C_BOARD_INFO("ea_i2c_disp_cfg", LCDB_CONFIG_EEPROM_I2C_ADDR),
        },
        {
            I2C_BOARD_INFO("ea_i2c_video", LCDB_PCA9532_I2C_ADDR),
        },
#endif
#if defined (CONFIG_EEPROM_AT24)
        {
            I2C_BOARD_INFO("24c256", I2C_24LC256_ADDR),
        },
#endif
    };
#endif
Run Code Online (Sandbox Code Playgroud)

现在我拥有所有设备:

# cat cards
 0 [LPC32XX        ]:  - LPC32XX
                      LPC32XX
# cat devices
  2: [ 0- 0]: digital audio playback
  3: [ 0- 0]: digital audio capture
  4: [ 0]   : control
 33:        : timer

# cat pcm
00-00: UDA1380 Duplex uda1380-hifi-0 :  : playback 1 : capture 1
Run Code Online (Sandbox Code Playgroud)

aplay虽然我还无法检测到任何东西,但也许这是一个不同的问题。

编辑:是的,这是一个不同的问题。显示的设备前面的数字cat devices应与 /dev/snd 设备条目中的次设备号匹配。现在 ALSA 端一切似乎都很好,但我没有来自 LPC3250 的 I2S 数据......

编辑2:已解决已解决。如果没有 I2S 数据/时钟,请确保正确配置输出复用器寄存器以将输出引脚连接到 I2S 外设!