This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335x kernel panic



Hi All,

I am working on a prototype board based on Beagle Bone Black running TI SDK 8.00.

I am experiencing kernel panic occasionally while running our application.

Given below are the console logs of the kernel panic.


[72738.801274] net eth0: initializing cpsw version 1.12 (0)
[72738.907779] davinci_mdio 4a101000.mdio: timed out waiting for user access
[72739.087801] davinci_mdio 4a101000.mdio: timed out waiting for user access
[72739.095003] net eth0: phy 4a101000.mdio:01 not found on slave 0
[72739.217800] davinci_mdio 4a101000.mdio: timed out waiting for user access
[72739.377801] davinci_mdio 4a101000.mdio: timed out waiting for user access
[72739.385002] net eth0: phy 4a101000.mdio:01 not found on slave 1
[72739.395310] Unable to handle kernel NULL pointer dereference at virtual addre ss 000000c4
[72739.403928] pgd = c0004000
[72739.406808] [000000c4] *pgd=00000000
[72739.410617] Internal error: Oops - BUG: 17 [#1] ARM
[72739.415752] Modules linked in: musb_dsps musb_hdrc musb_am335x btwilink bluet ooth 6lowpan_iphc
[72739.424883] CPU: 0 PID: 3 Comm: ksoftirqd/0 Not tainted 3.14.26-3.0.18b #1
[72739.432123] task: dd86d400 ti: dd882000 task.ti: dd882000
[72739.437814] pc : [<c02fc0a8>] lr : [<c01e97fc>] psr: a0000013
[72739.437814] sp : dd883e78 ip : dd883e88 fp : dd883e84
[72739.449891] r10: 04208040 r9 : c04f8b40 r8 : c04f8b98
[72739.455392] r7 : 00000100 r6 : 00000000 r5 : 00000000 r4 : dd904800
[72739.462263] r3 : c02fc098 r2 : 00000000 r1 : dd904854 r0 : dda03600
[72739.469136] Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment kern el
[72739.476829] Control: 10c5387d Table: 9dd1c019 DAC: 00000015
[72739.482877] Process ksoftirqd/0 (pid: 3, stack limit = 0xdd882238)
[72739.489381] Stack: (0xdd883e78 to 0xdd884000)
[72739.493974] 3e60: dd883 eb4 dd883e88
[72739.502594] 3e80: c01e97fc c02fc0a4 dd883e88 dd883e88 ffffffff c04cad00 00000 000 00000000
[72739.511214] 3ea0: 00000100 c04f8b98 dd883ed4 dd883eb8 c0036f74 c01e9788 00000 006 00000240
[72739.519835] 3ec0: dd882000 c04f8b80 dd883f24 dd883ed8 c00368f0 c0036f14 dd882 000 c04cad14
[72739.528451] 3ee0: dd882000 00000006 00000006 00000007 006e88a3 0000000a 00000 001 00000000
[72739.537069] 3f00: c04cad14 dd882000 00000001 00000000 00000000 00000000 dd883 f3c dd883f28
[72739.545688] 3f20: c0036a4c c003683c c0036a24 dd81a100 dd883f64 dd883f40 c0050 7cc c0036a30
[72739.554308] 3f40: dd86d400 dd875fc0 00000000 dd81a100 c00506b4 00000000 dd883 fac dd883f68
[72739.562928] 3f60: c004ab6c c00506c0 01001880 00000001 00000000 dd81a100 00000 000 dd883f7c
[72739.571547] 3f80: dd883f7c 00000000 dd883f88 dd883f88 dd875fc0 c004aa98 00000 000 00000000
[72739.580164] 3fa0: 00000000 dd883fb0 c000e978 c004aaa4 00000000 00000000 00000 000 00000000
[72739.588777] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000 000 00000000
[72739.597393] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 10308 085 00009000
[72739.605987] Backtrace:
[72739.608572] Function entered at [<c02fc098>] from [<c01e97fc>]
[72739.614710] Function entered at [<c01e977c>] from [<c0036f74>]
[72739.620844] r8:c04f8b98 r7:00000100 r6:00000000 r5:00000000 r4:c04cad00
[72739.627938] Function entered at [<c0036f08>] from [<c00368f0>]
[72739.634072] r6:c04f8b80 r5:dd882000 r4:00000240 r3:00000006
[72739.640061] Function entered at [<c0036830>] from [<c0036a4c>]
[72739.646195] r10:00000000 r9:00000000 r8:00000000 r7:00000001 r6:dd882000 r5: c04cad14
[72739.654476] r4:00000000
[72739.657151] Function entered at [<c0036a24>] from [<c00507cc>]
[72739.663284] r4:dd81a100 r3:c0036a24
[72739.667063] Function entered at [<c00506b4>] from [<c004ab6c>]
[72739.673196] r8:00000000 r7:c00506b4 r6:dd81a100 r5:00000000 r4:dd875fc0 r3:d d86d400
[72739.681391] Function entered at [<c004aa98>] from [<c000e978>]
[72739.687524] r7:00000000 r6:00000000 r5:c004aa98 r4:dd875fc0
[72739.693527] Code: e1a0c00d e92dd800 e24cb004 e59020a4 (e59230c4)
[72739.700003] ---[ end trace 1aeaa120fca98bd7 ]---
[72739.704872] Kernel panic - not syncing: Fatal exception in interrupt
[72739.711558] Rebooting in 3 seconds..

Please let me know if you can provide any information regarding the above kernel panic.

Also let me know if you need any further information.

Thanks,
Sridhar CR

  • This has been forwarded to the software team.
  • Hi Sridhar,

    can you go to the directory where your kernel is build and run following command:

    arm-linux-gnueabihf-addr2line -f -e vmlinux c02fc0a8

    to find the place in the source where the panic originated.

    Regards,
    Yordan
  • Hi Yordan,

    Thanks for the reply. I executed the above command, but got the response as given below

    ??
    ??:0
  • Hi Yordan,

    I am sorry, I had executed it on compressed vmlinux. On executing it on uncompressed vmlinux, I got the following:

    substream_to_prtd
    /home/sridharcr/P032-Source/P032-Source/Platform/board-support/linux-3.14.26-g2489c02/sound/core/pcm_dmaengine.c:41

    Thanks,
    Sridhar CR
  • Hi

    Is there any update on the issue?

    I was going through the literature in internet, I found some links where they have got very similar kernel panic. Given below is the link

    Is there any information regarding to this? Is the issue resolved in TI releases?

  • Hi Sridhar,

    I suspect your kernel panic issue is caused by the previous "Unable to handle kernel NULL pointer dereference at virtual addre ss" message. It seems to me you have issues with your USB:

    "Modules linked in: musb_dsps musb_hdrc musb_am335x btwilink bluet ooth 6lowpan_iphc"

    Do you use USB in your application?

    See also if the below e2e threads will be in help:

    e2e.ti.com/.../466646
    e2e.ti.com/.../1407724
    e2e.ti.com/.../357716

    Regards,
    Pavel
  • Hi Pavel,

    Thanks for the information. But the decoded backtrace point to the code in pcm_dmaengine. This is common in all the kernel panics that we have observed.

    As per the logs the last decoded backtrace points to the function substream_to_prtd in pcm_dmaengine.c while deferencing substream pointer. The function substream_to_prtd is invoked from function dmaengine_pcm_dma_complete as seen from the decoded backtrace.

    We have USB in our application, but the kernel panics backtrace mentioned in the links above point to USB, which is different from our case.

    I am attaching the complete decoded backtrace as excel sheet Kernel_Panic_Decoded.xlsx

  • Sridhar,

    Can you provide more details why you think that the issue come from the pcm_dmaengine.c file? From what I see this file is related to ALSA audio. Do you have audio processing in your application? You can also compare your pcm_dmaengine.c files with the one from the latest AM335x SDK (based on linux kernel 4.4.12) and/or mainline linux v4.7.4

    Regards,

    Pavel

  • Hi Pavel,

    We have an audio application that uses the ALSA library (snd_pcm) for playing of audio messages. This application has been written based on the aplay code.

    I compared the pcm_dmaengine,c of our SDK (8.00) to mainline kernel 4.4.12 as well as mainline kernel 4.7.4.

    From the comparison, I could observe that SDK 8 file does not have many changes wrt  mainline kernel 4.4.12. However, it has many changes compared to mainline kernel 4.7.4 file.

    Also I doubt if we can directly backport the changes in 4.7.4 to SDK 8 for this file.

    I am attaching the pcm_dmaengine.c from all the three kernel versions.

    /*
     *  Copyright (C) 2012, Analog Devices Inc.
     *	Author: Lars-Peter Clausen <lars@metafoo.de>
     *
     *  Based on:
     *	imx-pcm-dma-mx2.c, Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
     *	mxs-pcm.c, Copyright (C) 2011 Freescale Semiconductor, Inc.
     *	ep93xx-pcm.c, Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
     *		      Copyright (C) 2006 Applied Data Systems
     *
     *  This program is free software; you can redistribute it and/or modify it
     *  under  the terms of the GNU General  Public License as published by the
     *  Free Software Foundation;  either version 2 of the License, or (at your
     *  option) any later version.
     *
     *  You should have received a copy of the GNU General Public License along
     *  with this program; if not, write to the Free Software Foundation, Inc.,
     *  675 Mass Ave, Cambridge, MA 02139, USA.
     *
     */
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/dmaengine.h>
    #include <linux/slab.h>
    #include <sound/pcm.h>
    #include <sound/pcm_params.h>
    #include <sound/soc.h>
    
    #include <sound/dmaengine_pcm.h>
    
    struct dmaengine_pcm_runtime_data {
    	struct dma_chan *dma_chan;
    	dma_cookie_t cookie;
    
    	unsigned int pos;
    };
    
    static inline struct dmaengine_pcm_runtime_data *substream_to_prtd(
    	const struct snd_pcm_substream *substream)
    {
    	return substream->runtime->private_data;
    }
    
    struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	return prtd->dma_chan;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_get_chan);
    
    /**
     * snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config
     * @substream: PCM substream
     * @params: hw_params
     * @slave_config: DMA slave config
     *
     * This function can be used to initialize a dma_slave_config from a substream
     * and hw_params in a dmaengine based PCM driver implementation.
     */
    int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
    	const struct snd_pcm_hw_params *params,
    	struct dma_slave_config *slave_config)
    {
    	enum dma_slave_buswidth buswidth;
    	int bits;
    
    	bits = params_physical_width(params);
    	if (bits < 8 || bits > 64)
    		return -EINVAL;
    	else if (bits == 8)
    		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
    	else if (bits == 16)
    		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
    	else if (bits == 24)
    		buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES;
    	else if (bits <= 32)
    		buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
    	else
    		buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES;
    
    	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    		slave_config->direction = DMA_MEM_TO_DEV;
    		slave_config->dst_addr_width = buswidth;
    	} else {
    		slave_config->direction = DMA_DEV_TO_MEM;
    		slave_config->src_addr_width = buswidth;
    	}
    
    	slave_config->device_fc = false;
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_hwparams_to_dma_slave_config);
    
    /**
     * snd_dmaengine_pcm_set_config_from_dai_data() - Initializes a dma slave config
     *  using DAI DMA data.
     * @substream: PCM substream
     * @dma_data: DAI DMA data
     * @slave_config: DMA slave configuration
     *
     * Initializes the {dst,src}_addr, {dst,src}_maxburst, {dst,src}_addr_width and
     * slave_id fields of the DMA slave config from the same fields of the DAI DMA
     * data struct. The src and dst fields will be initialized depending on the
     * direction of the substream. If the substream is a playback stream the dst
     * fields will be initialized, if it is a capture stream the src fields will be
     * initialized. The {dst,src}_addr_width field will only be initialized if the
     * addr_width field of the DAI DMA data struct is not equal to
     * DMA_SLAVE_BUSWIDTH_UNDEFINED.
     */
    void snd_dmaengine_pcm_set_config_from_dai_data(
    	const struct snd_pcm_substream *substream,
    	const struct snd_dmaengine_dai_dma_data *dma_data,
    	struct dma_slave_config *slave_config)
    {
    	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    		slave_config->dst_addr = dma_data->addr;
    		slave_config->dst_maxburst = dma_data->maxburst;
    		if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED)
    			slave_config->dst_addr_width = dma_data->addr_width;
    	} else {
    		slave_config->src_addr = dma_data->addr;
    		slave_config->src_maxburst = dma_data->maxburst;
    		if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED)
    			slave_config->src_addr_width = dma_data->addr_width;
    	}
    
    	slave_config->slave_id = dma_data->slave_id;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);
    
    static void dmaengine_pcm_dma_complete(void *arg)
    {
    	struct snd_pcm_substream *substream = arg;
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	prtd->pos += snd_pcm_lib_period_bytes(substream);
    	if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))
    		prtd->pos = 0;
    
    	snd_pcm_period_elapsed(substream);
    }
    
    static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct dma_chan *chan = prtd->dma_chan;
    	struct dma_async_tx_descriptor *desc;
    	enum dma_transfer_direction direction;
    	unsigned long flags = DMA_CTRL_ACK;
    
    	direction = snd_pcm_substream_to_dma_direction(substream);
    
    	if (!substream->runtime->no_period_wakeup)
    		flags |= DMA_PREP_INTERRUPT;
    
    	prtd->pos = 0;
    	desc = dmaengine_prep_dma_cyclic(chan,
    		substream->runtime->dma_addr,
    		snd_pcm_lib_buffer_bytes(substream),
    		snd_pcm_lib_period_bytes(substream), direction, flags);
    
    	if (!desc)
    		return -ENOMEM;
    
    	desc->callback = dmaengine_pcm_dma_complete;
    	desc->callback_param = substream;
    	prtd->cookie = dmaengine_submit(desc);
    
    	return 0;
    }
    
    /**
     * snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation
     * @substream: PCM substream
     * @cmd: Trigger command
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * This function can be used as the PCM trigger callback for dmaengine based PCM
     * driver implementations.
     */
    int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	int ret;
    
    	switch (cmd) {
    	case SNDRV_PCM_TRIGGER_START:
    		ret = dmaengine_pcm_prepare_and_submit(substream);
    		if (ret)
    			return ret;
    		dma_async_issue_pending(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_RESUME:
    	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    		dmaengine_resume(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_SUSPEND:
    	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    		dmaengine_pause(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_STOP:
    		dmaengine_terminate_all(prtd->dma_chan);
    		break;
    	default:
    		return -EINVAL;
    	}
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger);
    
    /**
     * snd_dmaengine_pcm_pointer_no_residue - dmaengine based PCM pointer implementation
     * @substream: PCM substream
     *
     * This function is deprecated and should not be used by new drivers, as its
     * results may be unreliable.
     */
    snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	return bytes_to_frames(substream->runtime, prtd->pos);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue);
    
    /**
     * snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation
     * @substream: PCM substream
     *
     * This function can be used as the PCM pointer callback for dmaengine based PCM
     * driver implementations.
     */
    snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct dma_tx_state state;
    	enum dma_status status;
    	unsigned int buf_size;
    	unsigned int pos = 0;
    
    	status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
    	if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) {
    		buf_size = snd_pcm_lib_buffer_bytes(substream);
    		if (state.residue > 0 && state.residue <= buf_size)
    			pos = buf_size - state.residue;
    	}
    
    	return bytes_to_frames(substream->runtime, pos);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer);
    
    /**
     * snd_dmaengine_pcm_request_channel - Request channel for the dmaengine PCM
     * @filter_fn: Filter function used to request the DMA channel
     * @filter_data: Data passed to the DMA filter function
     *
     * Returns NULL or the requested DMA channel.
     *
     * This function request a DMA channel for usage with dmaengine PCM.
     */
    struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn,
    	void *filter_data)
    {
    	dma_cap_mask_t mask;
    
    	dma_cap_zero(mask);
    	dma_cap_set(DMA_SLAVE, mask);
    	dma_cap_set(DMA_CYCLIC, mask);
    
    	return dma_request_channel(mask, filter_fn, filter_data);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel);
    
    /**
     * snd_dmaengine_pcm_open - Open a dmaengine based PCM substream
     * @substream: PCM substream
     * @chan: DMA channel to use for data transfers
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * The function should usually be called from the pcm open callback. Note that
     * this function will use private_data field of the substream's runtime. So it
     * is not availabe to your pcm driver implementation.
     */
    int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
    	struct dma_chan *chan)
    {
    	struct dmaengine_pcm_runtime_data *prtd;
    	int ret;
    
    	if (!chan)
    		return -ENXIO;
    
    	ret = snd_pcm_hw_constraint_integer(substream->runtime,
    					    SNDRV_PCM_HW_PARAM_PERIODS);
    	if (ret < 0)
    		return ret;
    
    	prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
    	if (!prtd)
    		return -ENOMEM;
    
    	prtd->dma_chan = chan;
    
    	substream->runtime->private_data = prtd;
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
    
    /**
     * snd_dmaengine_pcm_open_request_chan - Open a dmaengine based PCM substream and request channel
     * @substream: PCM substream
     * @filter_fn: Filter function used to request the DMA channel
     * @filter_data: Data passed to the DMA filter function
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * This function will request a DMA channel using the passed filter function and
     * data. The function should usually be called from the pcm open callback. Note
     * that this function will use private_data field of the substream's runtime. So
     * it is not availabe to your pcm driver implementation.
     */
    int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
    	dma_filter_fn filter_fn, void *filter_data)
    {
    	return snd_dmaengine_pcm_open(substream,
    		    snd_dmaengine_pcm_request_channel(filter_fn, filter_data));
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan);
    
    /**
     * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
     * @substream: PCM substream
     */
    int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	kfree(prtd);
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
    
    /**
     * snd_dmaengine_pcm_release_chan_close - Close a dmaengine based PCM substream and release channel
     * @substream: PCM substream
     *
     * Releases the DMA channel associated with the PCM substream.
     */
    int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	dma_release_channel(prtd->dma_chan);
    
    	return snd_dmaengine_pcm_close(substream);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan);
    
    MODULE_LICENSE("GPL");
    
    /*
     *  Copyright (C) 2012, Analog Devices Inc.
     *	Author: Lars-Peter Clausen <lars@metafoo.de>
     *
     *  Based on:
     *	imx-pcm-dma-mx2.c, Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
     *	mxs-pcm.c, Copyright (C) 2011 Freescale Semiconductor, Inc.
     *	ep93xx-pcm.c, Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
     *		      Copyright (C) 2006 Applied Data Systems
     *
     *  This program is free software; you can redistribute it and/or modify it
     *  under  the terms of the GNU General  Public License as published by the
     *  Free Software Foundation;  either version 2 of the License, or (at your
     *  option) any later version.
     *
     *  You should have received a copy of the GNU General Public License along
     *  with this program; if not, write to the Free Software Foundation, Inc.,
     *  675 Mass Ave, Cambridge, MA 02139, USA.
     *
     */
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/dmaengine.h>
    #include <linux/slab.h>
    #include <sound/pcm.h>
    #include <sound/pcm_params.h>
    #include <sound/soc.h>
    
    #include <sound/dmaengine_pcm.h>
    
    struct dmaengine_pcm_runtime_data {
    	struct dma_chan *dma_chan;
    	dma_cookie_t cookie;
    
    	unsigned int pos;
    };
    
    static inline struct dmaengine_pcm_runtime_data *substream_to_prtd(
    	const struct snd_pcm_substream *substream)
    {
    	return substream->runtime->private_data;
    }
    
    struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	return prtd->dma_chan;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_get_chan);
    
    /**
     * snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config
     * @substream: PCM substream
     * @params: hw_params
     * @slave_config: DMA slave config
     *
     * This function can be used to initialize a dma_slave_config from a substream
     * and hw_params in a dmaengine based PCM driver implementation.
     */
    int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
    	const struct snd_pcm_hw_params *params,
    	struct dma_slave_config *slave_config)
    {
    	enum dma_slave_buswidth buswidth;
    	int bits;
    
    	bits = params_physical_width(params);
    	if (bits < 8 || bits > 64)
    		return -EINVAL;
    	else if (bits == 8)
    		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
    	else if (bits == 16)
    		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
    	else if (bits == 24)
    		buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES;
    	else if (bits <= 32)
    		buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
    	else
    		buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES;
    
    	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    		slave_config->direction = DMA_MEM_TO_DEV;
    		slave_config->dst_addr_width = buswidth;
    	} else {
    		slave_config->direction = DMA_DEV_TO_MEM;
    		slave_config->src_addr_width = buswidth;
    	}
    
    	slave_config->device_fc = false;
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_hwparams_to_dma_slave_config);
    
    /**
     * snd_dmaengine_pcm_set_config_from_dai_data() - Initializes a dma slave config
     *  using DAI DMA data.
     * @substream: PCM substream
     * @dma_data: DAI DMA data
     * @slave_config: DMA slave configuration
     *
     * Initializes the {dst,src}_addr, {dst,src}_maxburst, {dst,src}_addr_width and
     * slave_id fields of the DMA slave config from the same fields of the DAI DMA
     * data struct. The src and dst fields will be initialized depending on the
     * direction of the substream. If the substream is a playback stream the dst
     * fields will be initialized, if it is a capture stream the src fields will be
     * initialized. The {dst,src}_addr_width field will only be initialized if the
     * addr_width field of the DAI DMA data struct is not equal to
     * DMA_SLAVE_BUSWIDTH_UNDEFINED.
     */
    void snd_dmaengine_pcm_set_config_from_dai_data(
    	const struct snd_pcm_substream *substream,
    	const struct snd_dmaengine_dai_dma_data *dma_data,
    	struct dma_slave_config *slave_config)
    {
    	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    		slave_config->dst_addr = dma_data->addr;
    		slave_config->dst_maxburst = dma_data->maxburst;
    		if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED)
    			slave_config->dst_addr_width = dma_data->addr_width;
    	} else {
    		slave_config->src_addr = dma_data->addr;
    		slave_config->src_maxburst = dma_data->maxburst;
    		if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED)
    			slave_config->src_addr_width = dma_data->addr_width;
    	}
    
    	slave_config->slave_id = dma_data->slave_id;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);
    
    static void dmaengine_pcm_dma_complete(void *arg)
    {
    	struct snd_pcm_substream *substream = arg;
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	prtd->pos += snd_pcm_lib_period_bytes(substream);
    	if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))
    		prtd->pos = 0;
    
    	snd_pcm_period_elapsed(substream);
    }
    
    static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct dma_chan *chan = prtd->dma_chan;
    	struct dma_async_tx_descriptor *desc;
    	enum dma_transfer_direction direction;
    	unsigned long flags = DMA_CTRL_ACK;
    
    	direction = snd_pcm_substream_to_dma_direction(substream);
    
    	if (!substream->runtime->no_period_wakeup)
    		flags |= DMA_PREP_INTERRUPT;
    
    	prtd->pos = 0;
    	desc = dmaengine_prep_dma_cyclic(chan,
    		substream->runtime->dma_addr,
    		snd_pcm_lib_buffer_bytes(substream),
    		snd_pcm_lib_period_bytes(substream), direction, flags);
    
    	if (!desc)
    		return -ENOMEM;
    
    	desc->callback = dmaengine_pcm_dma_complete;
    	desc->callback_param = substream;
    	prtd->cookie = dmaengine_submit(desc);
    
    	return 0;
    }
    
    /**
     * snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation
     * @substream: PCM substream
     * @cmd: Trigger command
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * This function can be used as the PCM trigger callback for dmaengine based PCM
     * driver implementations.
     */
    int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct snd_pcm_runtime *runtime = substream->runtime;
    	int ret;
    
    	switch (cmd) {
    	case SNDRV_PCM_TRIGGER_START:
    		ret = dmaengine_pcm_prepare_and_submit(substream);
    		if (ret)
    			return ret;
    		dma_async_issue_pending(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_RESUME:
    	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    		dmaengine_resume(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_SUSPEND:
    		if (runtime->info & SNDRV_PCM_INFO_PAUSE)
    			dmaengine_pause(prtd->dma_chan);
    		else
    			dmaengine_terminate_all(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    		dmaengine_pause(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_STOP:
    		dmaengine_terminate_all(prtd->dma_chan);
    		break;
    	default:
    		return -EINVAL;
    	}
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger);
    
    /**
     * snd_dmaengine_pcm_pointer_no_residue - dmaengine based PCM pointer implementation
     * @substream: PCM substream
     *
     * This function is deprecated and should not be used by new drivers, as its
     * results may be unreliable.
     */
    snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	return bytes_to_frames(substream->runtime, prtd->pos);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue);
    
    /**
     * snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation
     * @substream: PCM substream
     *
     * This function can be used as the PCM pointer callback for dmaengine based PCM
     * driver implementations.
     */
    snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct dma_tx_state state;
    	enum dma_status status;
    	unsigned int buf_size;
    	unsigned int pos = 0;
    
    	status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
    	if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) {
    		buf_size = snd_pcm_lib_buffer_bytes(substream);
    		if (state.residue > 0 && state.residue <= buf_size)
    			pos = buf_size - state.residue;
    	}
    
    	return bytes_to_frames(substream->runtime, pos);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer);
    
    /**
     * snd_dmaengine_pcm_request_channel - Request channel for the dmaengine PCM
     * @filter_fn: Filter function used to request the DMA channel
     * @filter_data: Data passed to the DMA filter function
     *
     * Returns NULL or the requested DMA channel.
     *
     * This function request a DMA channel for usage with dmaengine PCM.
     */
    struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn,
    	void *filter_data)
    {
    	dma_cap_mask_t mask;
    
    	dma_cap_zero(mask);
    	dma_cap_set(DMA_SLAVE, mask);
    	dma_cap_set(DMA_CYCLIC, mask);
    
    	return dma_request_channel(mask, filter_fn, filter_data);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel);
    
    /**
     * snd_dmaengine_pcm_open - Open a dmaengine based PCM substream
     * @substream: PCM substream
     * @chan: DMA channel to use for data transfers
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * The function should usually be called from the pcm open callback. Note that
     * this function will use private_data field of the substream's runtime. So it
     * is not available to your pcm driver implementation.
     */
    int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
    	struct dma_chan *chan)
    {
    	struct dmaengine_pcm_runtime_data *prtd;
    	int ret;
    
    	if (!chan)
    		return -ENXIO;
    
    	ret = snd_pcm_hw_constraint_integer(substream->runtime,
    					    SNDRV_PCM_HW_PARAM_PERIODS);
    	if (ret < 0)
    		return ret;
    
    	prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
    	if (!prtd)
    		return -ENOMEM;
    
    	prtd->dma_chan = chan;
    
    	substream->runtime->private_data = prtd;
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
    
    /**
     * snd_dmaengine_pcm_open_request_chan - Open a dmaengine based PCM substream and request channel
     * @substream: PCM substream
     * @filter_fn: Filter function used to request the DMA channel
     * @filter_data: Data passed to the DMA filter function
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * This function will request a DMA channel using the passed filter function and
     * data. The function should usually be called from the pcm open callback. Note
     * that this function will use private_data field of the substream's runtime. So
     * it is not available to your pcm driver implementation.
     */
    int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
    	dma_filter_fn filter_fn, void *filter_data)
    {
    	return snd_dmaengine_pcm_open(substream,
    		    snd_dmaengine_pcm_request_channel(filter_fn, filter_data));
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan);
    
    /**
     * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
     * @substream: PCM substream
     */
    int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	kfree(prtd);
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
    
    /**
     * snd_dmaengine_pcm_release_chan_close - Close a dmaengine based PCM substream and release channel
     * @substream: PCM substream
     *
     * Releases the DMA channel associated with the PCM substream.
     */
    int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	dma_release_channel(prtd->dma_chan);
    
    	return snd_dmaengine_pcm_close(substream);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan);
    
    MODULE_LICENSE("GPL");
    
    /*
     *  Copyright (C) 2012, Analog Devices Inc.
     *	Author: Lars-Peter Clausen <lars@metafoo.de>
     *
     *  Based on:
     *	imx-pcm-dma-mx2.c, Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
     *	mxs-pcm.c, Copyright (C) 2011 Freescale Semiconductor, Inc.
     *	ep93xx-pcm.c, Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
     *		      Copyright (C) 2006 Applied Data Systems
     *
     *  This program is free software; you can redistribute it and/or modify it
     *  under  the terms of the GNU General  Public License as published by the
     *  Free Software Foundation;  either version 2 of the License, or (at your
     *  option) any later version.
     *
     *  You should have received a copy of the GNU General Public License along
     *  with this program; if not, write to the Free Software Foundation, Inc.,
     *  675 Mass Ave, Cambridge, MA 02139, USA.
     *
     */
    #include <linux/module.h>
    #include <linux/init.h>
    #include <linux/dmaengine.h>
    #include <linux/slab.h>
    #include <sound/pcm.h>
    #include <sound/pcm_params.h>
    #include <sound/soc.h>
    
    #include <sound/dmaengine_pcm.h>
    
    struct dmaengine_pcm_runtime_data {
    	struct dma_chan *dma_chan;
    	dma_cookie_t cookie;
    
    	unsigned int pos;
    };
    
    static inline struct dmaengine_pcm_runtime_data *substream_to_prtd(
    	const struct snd_pcm_substream *substream)
    {
    	return substream->runtime->private_data;
    }
    
    struct dma_chan *snd_dmaengine_pcm_get_chan(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	return prtd->dma_chan;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_get_chan);
    
    /**
     * snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config
     * @substream: PCM substream
     * @params: hw_params
     * @slave_config: DMA slave config
     *
     * This function can be used to initialize a dma_slave_config from a substream
     * and hw_params in a dmaengine based PCM driver implementation.
     */
    int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream,
    	const struct snd_pcm_hw_params *params,
    	struct dma_slave_config *slave_config)
    {
    	enum dma_slave_buswidth buswidth;
    	int bits;
    
    	bits = params_physical_width(params);
    	if (bits < 8 || bits > 64)
    		return -EINVAL;
    	else if (bits == 8)
    		buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
    	else if (bits == 16)
    		buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
    	else if (bits == 24)
    		buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES;
    	else if (bits <= 32)
    		buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
    	else
    		buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES;
    
    	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    		slave_config->direction = DMA_MEM_TO_DEV;
    		slave_config->dst_addr_width = buswidth;
    	} else {
    		slave_config->direction = DMA_DEV_TO_MEM;
    		slave_config->src_addr_width = buswidth;
    	}
    
    	slave_config->device_fc = false;
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_hwparams_to_dma_slave_config);
    
    /**
     * snd_dmaengine_pcm_set_config_from_dai_data() - Initializes a dma slave config
     *  using DAI DMA data.
     * @substream: PCM substream
     * @dma_data: DAI DMA data
     * @slave_config: DMA slave configuration
     *
     * Initializes the {dst,src}_addr, {dst,src}_maxburst, {dst,src}_addr_width and
     * slave_id fields of the DMA slave config from the same fields of the DAI DMA
     * data struct. The src and dst fields will be initialized depending on the
     * direction of the substream. If the substream is a playback stream the dst
     * fields will be initialized, if it is a capture stream the src fields will be
     * initialized. The {dst,src}_addr_width field will only be initialized if the
     * SND_DMAENGINE_PCM_DAI_FLAG_PACK flag is set or if the addr_width field of
     * the DAI DMA data struct is not equal to DMA_SLAVE_BUSWIDTH_UNDEFINED. If
     * both conditions are met the latter takes priority.
     */
    void snd_dmaengine_pcm_set_config_from_dai_data(
    	const struct snd_pcm_substream *substream,
    	const struct snd_dmaengine_dai_dma_data *dma_data,
    	struct dma_slave_config *slave_config)
    {
    	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
    		slave_config->dst_addr = dma_data->addr;
    		slave_config->dst_maxburst = dma_data->maxburst;
    		if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK)
    			slave_config->dst_addr_width =
    				DMA_SLAVE_BUSWIDTH_UNDEFINED;
    		if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED)
    			slave_config->dst_addr_width = dma_data->addr_width;
    	} else {
    		slave_config->src_addr = dma_data->addr;
    		slave_config->src_maxburst = dma_data->maxburst;
    		if (dma_data->flags & SND_DMAENGINE_PCM_DAI_FLAG_PACK)
    			slave_config->src_addr_width =
    				DMA_SLAVE_BUSWIDTH_UNDEFINED;
    		if (dma_data->addr_width != DMA_SLAVE_BUSWIDTH_UNDEFINED)
    			slave_config->src_addr_width = dma_data->addr_width;
    	}
    
    	slave_config->slave_id = dma_data->slave_id;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);
    
    static void dmaengine_pcm_dma_complete(void *arg)
    {
    	struct snd_pcm_substream *substream = arg;
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	prtd->pos += snd_pcm_lib_period_bytes(substream);
    	if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))
    		prtd->pos = 0;
    
    	snd_pcm_period_elapsed(substream);
    }
    
    static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct dma_chan *chan = prtd->dma_chan;
    	struct dma_async_tx_descriptor *desc;
    	enum dma_transfer_direction direction;
    	unsigned long flags = DMA_CTRL_ACK;
    
    	direction = snd_pcm_substream_to_dma_direction(substream);
    
    	if (!substream->runtime->no_period_wakeup)
    		flags |= DMA_PREP_INTERRUPT;
    
    	prtd->pos = 0;
    	desc = dmaengine_prep_dma_cyclic(chan,
    		substream->runtime->dma_addr,
    		snd_pcm_lib_buffer_bytes(substream),
    		snd_pcm_lib_period_bytes(substream), direction, flags);
    
    	if (!desc)
    		return -ENOMEM;
    
    	desc->callback = dmaengine_pcm_dma_complete;
    	desc->callback_param = substream;
    	prtd->cookie = dmaengine_submit(desc);
    
    	return 0;
    }
    
    /**
     * snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation
     * @substream: PCM substream
     * @cmd: Trigger command
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * This function can be used as the PCM trigger callback for dmaengine based PCM
     * driver implementations.
     */
    int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct snd_pcm_runtime *runtime = substream->runtime;
    	int ret;
    
    	switch (cmd) {
    	case SNDRV_PCM_TRIGGER_START:
    		ret = dmaengine_pcm_prepare_and_submit(substream);
    		if (ret)
    			return ret;
    		dma_async_issue_pending(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_RESUME:
    	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
    		dmaengine_resume(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_SUSPEND:
    		if (runtime->info & SNDRV_PCM_INFO_PAUSE)
    			dmaengine_pause(prtd->dma_chan);
    		else
    			dmaengine_terminate_async(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
    		dmaengine_pause(prtd->dma_chan);
    		break;
    	case SNDRV_PCM_TRIGGER_STOP:
    		dmaengine_terminate_async(prtd->dma_chan);
    		break;
    	default:
    		return -EINVAL;
    	}
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_trigger);
    
    /**
     * snd_dmaengine_pcm_pointer_no_residue - dmaengine based PCM pointer implementation
     * @substream: PCM substream
     *
     * This function is deprecated and should not be used by new drivers, as its
     * results may be unreliable.
     */
    snd_pcm_uframes_t snd_dmaengine_pcm_pointer_no_residue(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	return bytes_to_frames(substream->runtime, prtd->pos);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer_no_residue);
    
    /**
     * snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation
     * @substream: PCM substream
     *
     * This function can be used as the PCM pointer callback for dmaengine based PCM
     * driver implementations.
     */
    snd_pcm_uframes_t snd_dmaengine_pcm_pointer(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    	struct dma_tx_state state;
    	enum dma_status status;
    	unsigned int buf_size;
    	unsigned int pos = 0;
    
    	status = dmaengine_tx_status(prtd->dma_chan, prtd->cookie, &state);
    	if (status == DMA_IN_PROGRESS || status == DMA_PAUSED) {
    		buf_size = snd_pcm_lib_buffer_bytes(substream);
    		if (state.residue > 0 && state.residue <= buf_size)
    			pos = buf_size - state.residue;
    	}
    
    	return bytes_to_frames(substream->runtime, pos);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_pointer);
    
    /**
     * snd_dmaengine_pcm_request_channel - Request channel for the dmaengine PCM
     * @filter_fn: Filter function used to request the DMA channel
     * @filter_data: Data passed to the DMA filter function
     *
     * Returns NULL or the requested DMA channel.
     *
     * This function request a DMA channel for usage with dmaengine PCM.
     */
    struct dma_chan *snd_dmaengine_pcm_request_channel(dma_filter_fn filter_fn,
    	void *filter_data)
    {
    	dma_cap_mask_t mask;
    
    	dma_cap_zero(mask);
    	dma_cap_set(DMA_SLAVE, mask);
    	dma_cap_set(DMA_CYCLIC, mask);
    
    	return dma_request_channel(mask, filter_fn, filter_data);
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_request_channel);
    
    /**
     * snd_dmaengine_pcm_open - Open a dmaengine based PCM substream
     * @substream: PCM substream
     * @chan: DMA channel to use for data transfers
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * The function should usually be called from the pcm open callback. Note that
     * this function will use private_data field of the substream's runtime. So it
     * is not available to your pcm driver implementation.
     */
    int snd_dmaengine_pcm_open(struct snd_pcm_substream *substream,
    	struct dma_chan *chan)
    {
    	struct dmaengine_pcm_runtime_data *prtd;
    	int ret;
    
    	if (!chan)
    		return -ENXIO;
    
    	ret = snd_pcm_hw_constraint_integer(substream->runtime,
    					    SNDRV_PCM_HW_PARAM_PERIODS);
    	if (ret < 0)
    		return ret;
    
    	prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
    	if (!prtd)
    		return -ENOMEM;
    
    	prtd->dma_chan = chan;
    
    	substream->runtime->private_data = prtd;
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open);
    
    /**
     * snd_dmaengine_pcm_open_request_chan - Open a dmaengine based PCM substream and request channel
     * @substream: PCM substream
     * @filter_fn: Filter function used to request the DMA channel
     * @filter_data: Data passed to the DMA filter function
     *
     * Returns 0 on success, a negative error code otherwise.
     *
     * This function will request a DMA channel using the passed filter function and
     * data. The function should usually be called from the pcm open callback. Note
     * that this function will use private_data field of the substream's runtime. So
     * it is not available to your pcm driver implementation.
     */
    int snd_dmaengine_pcm_open_request_chan(struct snd_pcm_substream *substream,
    	dma_filter_fn filter_fn, void *filter_data)
    {
    	return snd_dmaengine_pcm_open(substream,
    		    snd_dmaengine_pcm_request_channel(filter_fn, filter_data));
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_open_request_chan);
    
    /**
     * snd_dmaengine_pcm_close - Close a dmaengine based PCM substream
     * @substream: PCM substream
     */
    int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	dmaengine_synchronize(prtd->dma_chan);
    	kfree(prtd);
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close);
    
    /**
     * snd_dmaengine_pcm_release_chan_close - Close a dmaengine based PCM substream and release channel
     * @substream: PCM substream
     *
     * Releases the DMA channel associated with the PCM substream.
     */
    int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream)
    {
    	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
    
    	dmaengine_synchronize(prtd->dma_chan);
    	dma_release_channel(prtd->dma_chan);
    	kfree(prtd);
    
    	return 0;
    }
    EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan);
    
    MODULE_LICENSE("GPL");
    

    Thanks,

    Sridhar CR

  • Sridhar,

    I would suggest the below debug steps:

    1. Check which line of code in your application is causing the below message:
    "Unable to handle kernel NULL pointer dereference at virtual address 000000c4"

    2. Check if your application can run successful on Beagle Bone Black board

    3. Check if your application can run successful on your custom board but with latest AM335x TI SDK 03.00.00.04

    4. Check if the minimal playback application will run fine on your custom board with SDK8:

    processors.wiki.ti.com/.../AM335x_Audio_Driver's_Guide
    processors.wiki.ti.com/.../Sitara_Linux_Audio_Sample_Application_Overview

    processors.wiki.ti.com/.../Sitara_SDK_Linux_Audio_ALSA_User_Space
    processors.wiki.ti.com/.../Linux_Core_Audio_User's_Guide

    5. Check if the aplay tool will run fine on your custom board with SDK8

    Regards,
    Pavel