Audio Drivers



© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>
               All Rights Reserved.
What to Expect?
Introduction to Linux' Audio Subsystem
Audio Vertical: Sound Core
Audio Horizontal
Putting them all together: Porting




        © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   2
                       All Rights Reserved.
Audio Subsystem
   ALSA conforming Apps            User Space          OSS conforming Apps
(aplay, arecord, mplayer, ...)                         (rawplay, rawrec, ...)


     /dev/snd/pcmCXDYz,
                                   /proc/asound            /dev/dsp, /dev/adsp,
      /dev/snd/controlCX,
                                 /sys/class/sound         /dev/mixer, /dev/audio
        /dev/snd/timer
                                                           OSS Emulation Layer
                                                      (snd_pcm_oss, snd_mixer_oss)

                            ALSA (Sound) Core

              Control                                  Data
                          Audio Codec Driver
                 I2C     Audio Controller Driver
                                Kernel Space
                                                        I2S
                                 Hardware Space
                                                                        MIC
              Audio Controller                    Audio Codec
                                                                        Speaker
                    © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>                3
                                   All Rights Reserved.
ALSA Sound Card Interface
Header: <linux/sound/core.h>
Data Structure: struct snd_card
APIs
  int snd_card_create(int idx, const char *id,
  struct module *module, int extra_size, struct
  snd_card **card_ret);
  int snd_card_register(struct snd_card *card);
  int snd_card_free(struct snd_card *card);
       Inverse of both the above
            © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   4
                           All Rights Reserved.
ALSA PCM Interface
Header: <linux/sound/pcm.h>
Data Structure
  struct snd_pcm
  struct snd_pcm_ops
APIs
  int snd_pcm_new(struct snd_card *card, const char *id, int device,
  int playback_count, int capture_count, struct snd_pcm **rpcm);
  void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct
  snd_pcm_ops *ops);
  int snd_pcm_lib_malloc_pages(struct snd_pcm_substream
  *substream, size_t size); // Typically used in hw_params
  int snd_pcm_lib_free_pages(struct snd_pcm_substream
  *substream); // Typically used in hw_free

              © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>        5
                             All Rights Reserved.
struct pcm_ops
int (*open)(struct snd_pcm_substream *substream);
int (*close)(struct snd_pcm_substream *substream);
int (*ioctl) /* Miscellaneous controls */
  (struct snd_pcm_substream * substream, unsigned int cmd, void *arg);
int (*hw_params) /* Set h/w params & allocate the buffer */
  (struct snd_pcm_substream *substream, struct snd_pcm_hw_params
  *params);
int (*hw_free) /* Free the buffer */
  (struct snd_pcm_substream *substream);
int (*prepare) /* Set audio parameters for transfer */
  (struct snd_pcm_substream *substream);
int (*trigger) /* Trigger the transfer */
  (struct snd_pcm_substream *substream, int cmd);
               © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>         6
                              All Rights Reserved.
ALSA Sound Card Interface
Header: <linux/sound/control.h>
Data Structure: struct snd_kcontrol_new
APIs
  int snd_ctl_add(struct snd_card * card, struct
  snd_kcontrol * kcontrol);
  int snd_ctl_remove(struct snd_card * card,
  struct snd_kcontrol * kcontrol);



         © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   7
                        All Rights Reserved.
Porting a Audio Driver
Standard Audio Codec
 Mostly involves changing pin assignments as
 per the Board Design
New Audio Codec
 Complete Driver as per the preceeding
 discussions, need to be implemented




       © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   8
                      All Rights Reserved.
Browse some Audio Drivers
ALSA driver examples: sound/
 arm/aaci.c
 soc/soc-*.c {core, pcm, utils}
Codec driver examples: sound/
 arm/aaci.c
 soc/codecs/twl4030.c
Browse & Discuss any


        © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   9
                       All Rights Reserved.
What all have we learnt?
Introduction to Linux' Audio Subsystem
Audio Vertical
  ALSA Sound Core & its Programming I/f
Audio Horizontal
  Audio Codec Driver
  Audio Controller Driver
Putting them all together: Porting


         © 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   10
                        All Rights Reserved.
Any Queries?




© 2010 Anil Kumar Pugalia <email@sarika-pugs.com>   11
               All Rights Reserved.

Audio Drivers

  • 1.
    Audio Drivers © 2010Anil Kumar Pugalia <email@sarika-pugs.com> All Rights Reserved.
  • 2.
    What to Expect? Introductionto Linux' Audio Subsystem Audio Vertical: Sound Core Audio Horizontal Putting them all together: Porting © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 2 All Rights Reserved.
  • 3.
    Audio Subsystem ALSA conforming Apps User Space OSS conforming Apps (aplay, arecord, mplayer, ...) (rawplay, rawrec, ...) /dev/snd/pcmCXDYz, /proc/asound /dev/dsp, /dev/adsp, /dev/snd/controlCX, /sys/class/sound /dev/mixer, /dev/audio /dev/snd/timer OSS Emulation Layer (snd_pcm_oss, snd_mixer_oss) ALSA (Sound) Core Control Data Audio Codec Driver I2C Audio Controller Driver Kernel Space I2S Hardware Space MIC Audio Controller Audio Codec Speaker © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 3 All Rights Reserved.
  • 4.
    ALSA Sound CardInterface Header: <linux/sound/core.h> Data Structure: struct snd_card APIs int snd_card_create(int idx, const char *id, struct module *module, int extra_size, struct snd_card **card_ret); int snd_card_register(struct snd_card *card); int snd_card_free(struct snd_card *card); Inverse of both the above © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 4 All Rights Reserved.
  • 5.
    ALSA PCM Interface Header:<linux/sound/pcm.h> Data Structure struct snd_pcm struct snd_pcm_ops APIs int snd_pcm_new(struct snd_card *card, const char *id, int device, int playback_count, int capture_count, struct snd_pcm **rpcm); void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops); int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size); // Typically used in hw_params int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream); // Typically used in hw_free © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 5 All Rights Reserved.
  • 6.
    struct pcm_ops int (*open)(structsnd_pcm_substream *substream); int (*close)(struct snd_pcm_substream *substream); int (*ioctl) /* Miscellaneous controls */ (struct snd_pcm_substream * substream, unsigned int cmd, void *arg); int (*hw_params) /* Set h/w params & allocate the buffer */ (struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params); int (*hw_free) /* Free the buffer */ (struct snd_pcm_substream *substream); int (*prepare) /* Set audio parameters for transfer */ (struct snd_pcm_substream *substream); int (*trigger) /* Trigger the transfer */ (struct snd_pcm_substream *substream, int cmd); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 6 All Rights Reserved.
  • 7.
    ALSA Sound CardInterface Header: <linux/sound/control.h> Data Structure: struct snd_kcontrol_new APIs int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol); int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol); © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 7 All Rights Reserved.
  • 8.
    Porting a AudioDriver Standard Audio Codec Mostly involves changing pin assignments as per the Board Design New Audio Codec Complete Driver as per the preceeding discussions, need to be implemented © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 8 All Rights Reserved.
  • 9.
    Browse some AudioDrivers ALSA driver examples: sound/ arm/aaci.c soc/soc-*.c {core, pcm, utils} Codec driver examples: sound/ arm/aaci.c soc/codecs/twl4030.c Browse & Discuss any © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 9 All Rights Reserved.
  • 10.
    What all havewe learnt? Introduction to Linux' Audio Subsystem Audio Vertical ALSA Sound Core & its Programming I/f Audio Horizontal Audio Codec Driver Audio Controller Driver Putting them all together: Porting © 2010 Anil Kumar Pugalia <email@sarika-pugs.com> 10 All Rights Reserved.
  • 11.
    Any Queries? © 2010Anil Kumar Pugalia <email@sarika-pugs.com> 11 All Rights Reserved.