2009-07-16 11:42:34     How to let Blackfin SPORT support Standard Ac'97 Device

Document created by Aaronwu Employee on Aug 16, 2013
Version 1Show Document
  • View in full screen mode

2009-07-16 11:42:34     How to let Blackfin SPORT support Standard Ac'97 Device

Wang Mengyin (CHINA)

Message: 77460   

 

Hi guys!

 

Recently , I am working on writing a ALSA SoC Driver. It's used to driver WM9707 with Blackfin BF532 's SPORT port. I know that the driver supports AC'97 Slot mode recently. It's time slot is 16 bit. But the standard AC'97 frame has 20 bit time slot.

 

I have did some modification on Bf5xx-ac97.c ( locate in /sound/soc/blackfin folder).

 

I modify the following structure and function:

 

void bf5xx_pcm_to_frame(struct audio_frame *dst, const __u32 *src, \

  size_t count)

{

__u16 tmpData;

while (count--) {

// data is 16 bit we should convert them

// We use such disgust method to tackle 16 -> 20 bit convert

  tmpData = (__u16)((*src & 0xff000000) >> 24); // Left HIGH 8 bit

  dst->ac97_data8_pcmleft8 = (dst->ac97_data8_pcmleft8 & 0xff00) | tmpData;

  tmpData = (__u16)((*src & 0x00ff0000) >> 4); // Left LOW  8 bit

  dst->ac97_pcmleft12_pcmright4 = (dst->ac97_pcmleft12_pcmright4 & 0x000f) | tmpData;

 

  tmpData = (__u16)((*src & 0x0000f000) >> 12); // Right HIGH 4 bit

  dst->ac97_pcmleft12_pcmright4 = (dst->ac97_pcmleft12_pcmright4 & 0xfff0) | tmpData;

  tmpData = (__u16)((*src & 0x00000fff) << 4);   //      Right Low 12 bit

  dst->ac97_pcmright16 = tmpData;

 

  ++dst;

  ++src;

}

}

 

void bf5xx_frame_to_pcm(const struct audio_frame *src, __u32 *dst, size_t count)

{

__u16 tmpData;

while (count--) {

// *(dst++) = (src++)->ac97_pcm;

// modified by wangmengyin

// the standard AC'97 Frame time slot is 20 Bit the input PCM

// data is 16 bit we should convert them

// We use such disgust method to takle 16 -> 20 bit convert

 

*dst = 0;

tmpData = src->ac97_data8_pcmleft8;

*dst |= ((__u32)(tmpData & 0x00ff) << 24); // Left HIGH 8 bit

tmpData = src->ac97_pcmleft12_pcmright4;

*dst |= ((__u32)(tmpData & 0xff00) << 8); // Left LOW 8 bit

 

tmpData = src->ac97_pcmleft12_pcmright4;

*dst |= ((__u32)(tmpData & 0x000f) << 12); // Right HIGH 4 bit

tmpData = src->ac97_pcmright16;

*dst |= ((__u32)(tmpData) >> 4);  // Right LOW 12 bit

 

++dst;

++src;

}

}

 

function enqueue_cmd()  \ bf5xx_ac97_read \ bf5xx_ac97_write are written too.

 

but when I insmod my driver snd-wm9707.ko file. I get the following error message.

 

dma rx:3 tx:4, err irq:11, regs:ffc00900

WM9707 SoC Audio Codec

Failed to allocate dma memory-Please increase uncached DMA memory region

asoc: platform pcm constructor failed

asoc: can't create pcm AC97 HiFi

soc-audio: probe of soc-audio failed with error -12

 

the error is caused by bf5xx_pcm_preallocate_dma_buffer function(locate in bf5xx-pcm.c). It seems the dma_alloc_coherent() failed!

 

my question is :

 

1.Is it necessary to modify the bf5xx-pcm.c file? How?

 

2.How dose the DMA tackle with the frame transfer?

 

3.Can ADI's guys add support to standrad AC'97 Codec?

TranslateQuoteReplyEditDelete

 

 

2009-07-17 06:15:58     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Barry Song (CHINA)

Message: 77531   

 

I guess you are misunderstanding the driver.

 

1.Is it necessary to modify the bf5xx-pcm.c file? How?

 

No. You don't need to make this kind of change:

 

void bf5xx_pcm_to_frame(struct audio_frame *dst, const __u32 *src, \

  size_t count)

{

...

}

 

bf5xx_pcm_to_ac97 will make right copy.

 

 

 

2.How dose the DMA tackle with the frame transfer?

 

In fact, the DMA word len is 32 not 16. We transfer to ac97 frame by software. And you don't need to change alloc codec too.

 

 

 

3.Can ADI's guys add support to standrad AC'97 Codec?

 

The drivers are supporting standard AC'97. We use it for AD1980, which is also a AC97 codec.

QuoteReplyEditDelete

 

 

2009-07-17 07:08:28     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Wang Mengyin (CHINA)

Message: 77536   

 

Thanks Barry Song!

 

But I sitll can not understand this structure:

 

in the file bf5xx-ac97.h, Roy Huang has defined the following audio frame:

 

struct audio_frame {

u16 ac97_tag;  /* slot 0 */

u16 ac97_addr;  /* slot 1 */

u16 ac97_data;  /* slot 2 */

u32 ac97_pcm;  /* slot 3 and 4: left and right pcm data */

} __attribute__ ((packed));

 

It's so-called Slot-16bit mode which has 16 bit time slot. Yes,it can work with ADI's Codec. But it conflict with Intel's Standard Ac'97 Specifiction. For my part WM9707 it only support AC'97 v2.1. The Audio frame  just like that:

 

slot 0 TAG 16bit

 

slot 1 CMD ADR 20bit

 

slot 2 CMD DATA 20bit

 

slot 3 PCM LEFT 20bit

 

slot 4 PCM RIGHT 20bit

 

you can see the differents between each other, they has the same TAG length. But the following CMD DATA solt is 20bit.

 

in your config file, it says

 

"Note:

   AC'97 codecs which do not implment the slot-16 mode will not function

   properly with this driver. This driver is known to work with the

   Analog Devices line of AC97 codecs."

 

which means it can not support 20bit data tansfer mode.

 

In order to support  standard specification , I have modify the sutrcture:

 

struct audio_frame {

u16 ac97_tag;  /* slot 0 FRAME TAG*/

u16 ac97_addr16; /* slot 1 CMD ADR HIGH 16 Bit 19 ~ 4*/

u16 ac97_addr4_data12; /* slot 1 ADR LOW 4 Bit 3 ~ 0 + slot 2 DATA HIGH 12 Bit */

u16 ac97_data8_pcmleft8; /* slot 2 DATA LOW 8 Bit + slot 3 left pcm data HIGH 8 bit*/

u16 ac97_pcmleft12_pcmright4; /* slot 3 left pcm data LOW 12 bit + slot 4 right pcm data HIGH 4 bit*/

u16 ac97_pcmright16; /* slot 4 right pcm data LOW 16 bit. pad to 16 words */

} __attribute__ ((packed));

 

The driver module compiled can load into kernel, the SPORT output signal seems right. But the CODEC can't output ANY analog signal.

 

I use  program "tone" to generate 1000Hz mono PCM stream. And I can see the stream output  from SPORT DT1PRI pin, the RFS1(SYNC) TSCLK1(SCLK) signal seems all right.

 

My question is :

 

1.Dose the ALSA SoC Driver did internal configuration to CODEC? How? Can you tell me the location of that Code?

 

by the way, beacuse of no WM9707 Codec file(in /sound/soc/codec), I write it by myself. Does the wrong configuration file affect the driver?

 

2.I can not get much infomation from ALSA offical site about ALSA SOC architecture? They discuess PCI driver? Can you give me some suggestion about How to find ASOC driver development reference?

 

3.In the file bf5xx-pcm.c(in /sound/soc/blackfin), I don't know why the following equation divide 4?

 

line 292 :"size_t size = bf5xx_pcm_hardware.buffer_bytes_max * sizeof(struct audio_frame)/4;"

 

size is used to allocate DMA buffer(dma_alloc_coherent)?

TranslateQuoteReplyEditDelete

 

 

2009-07-17 07:23:20     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Robin Getz (UNITED STATES)

Message: 77539   

 

Wang:

 

First - the Blackfin sport DOES NOT support AC'97

 

The SPORT supports a slot 16 mode that the ADI AC'97 codecs supported. Since this was not part of the AC'97 standard, no other codecs, except the ADI ones supported this.

 

Calling the driver AC97 was a poor choice in names - it should have been called slot-16.

 

-Robin

QuoteReplyEditDelete

 

 

2009-07-17 07:43:49     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Wang Mengyin (CHINA)

Message: 77548   

 

Wang:

 

First - the Blackfin sport DOES NOT support AC'97

 

The SPORT supports a slot 16 mode that the ADI AC'97 codecs supported. Since this was not part of the AC'97 standard, no other codecs, except the ADI ones supported this.

 

Calling the driver AC97 was a poor choice in names - it should have been called slot-16.

 

-Robin

 

---

 

Thanks Robin Getz, your comment is right. I know the driver does not support the Ac'97 standard. And it is just my work to add support for it. When I compare the two standrad ,I see they tackle data in a simliar way.

 

Is this possible to modify the ADI's driver to add its support? they just be different in frame structure.

 

Another important reason is I have made my own Blackfin PCB board, so I can not abandon it and made another one. It's so  expensive that I can't afford it.

 

If I have known that the driver can not support standrad AC'97 when I design the hardware, I would not use WM9707. Maybe I will choose PCM,I2S,DSP interface chip. It's  a stupid decision.

TranslateQuoteReplyEditDelete

 

 

2009-07-17 11:58:38     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Wang Mengyin (CHINA)

Message: 77568   

 

Hi Guys !

 

Hi Guys, my WM9707 Codec can works!!! Although there are some Bugs ! But, the ac97 pcm interface works normally!

 

I test on My Blackfin BF532 board which runs uClinux-2008R1.5 version. I use the mp3play to test the driver.

 

In order to get blackfin SPORT to support the AC'97 Specification. I modify the bf5xx-ac97.c file. The most important work is to modify the aduio_frame structure as i mentioned above. The related read and write fuctions should be rewrited to fit the change.

 

As the WM9707 has no Codecs has no related soc codec support file , I write it ,referenced the related WM9712 files.

 

 

TranslateQuoteReplyEditDelete

 

 

2009-07-17 23:47:19     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Mike Frysinger (UNITED STATES)

Message: 77590   

 

can you run `svn diff` and post the resulting output so we can see the changes required ?

QuoteReplyEditDelete

 

 

2009-07-18 00:14:44     Re: How to let Blackfin SPORT support Standard Ac'97 Device

Wang Mengyin (CHINA)

Message: 77596   

 

I have some extra work to do (including add Variable rate audio support ). After that, I will post my modification.

Attachments

    Outcomes