1 --- a/sound/soc/Kconfig
2 +++ b/sound/soc/Kconfig
3 @@ -54,6 +54,7 @@ source "sound/soc/spear/Kconfig"
4 source "sound/soc/tegra/Kconfig"
5 source "sound/soc/txx9/Kconfig"
6 source "sound/soc/ux500/Kconfig"
7 +source "sound/soc/gw-avila/Kconfig"
10 source "sound/soc/codecs/Kconfig"
11 --- a/sound/soc/Makefile
12 +++ b/sound/soc/Makefile
13 @@ -31,3 +31,4 @@ obj-$(CONFIG_SND_SOC) += spear/
14 obj-$(CONFIG_SND_SOC) += tegra/
15 obj-$(CONFIG_SND_SOC) += txx9/
16 obj-$(CONFIG_SND_SOC) += ux500/
17 +obj-$(CONFIG_SND_SOC) += gw-avila/
19 +++ b/sound/soc/gw-avila/Kconfig
21 +config SND_GW_AVILA_SOC_PCM
24 +config SND_GW_AVILA_SOC_HSS
27 +config SND_GW_AVILA_SOC
28 + tristate "SoC Audio for the Gateworks AVILA Family"
29 + depends on ARCH_IXP4XX && SND_SOC
30 + select SND_GW_AVILA_SOC_PCM
31 + select SND_GW_AVILA_SOC_HSS
32 + select SND_SOC_TLV320AIC3X
34 + Say Y or M if you want to add support for codecs attached to
35 + the Gateworks HSS interface. You will also need
36 + to select the audio interfaces to support below.
39 +++ b/sound/soc/gw-avila/Makefile
41 +# Gateworks Avila HSS Platform Support
42 +snd-soc-gw-avila-objs := gw-avila.o ixp4xx_hss.o
43 +snd-soc-gw-avila-pcm-objs := gw-avila-pcm.o
44 +snd-soc-gw-avila-hss-objs := gw-avila-hss.o
46 +obj-$(CONFIG_SND_GW_AVILA_SOC) += snd-soc-gw-avila.o
47 +obj-$(CONFIG_SND_GW_AVILA_SOC_PCM) += snd-soc-gw-avila-pcm.o
48 +obj-$(CONFIG_SND_GW_AVILA_SOC_HSS) += snd-soc-gw-avila-hss.o
50 +++ b/sound/soc/gw-avila/gw-avila-hss.c
53 + * gw-avila-hss.c -- HSS Audio Support for Gateworks Avila
55 + * Author: Chris Lang <clang@gateworks.com>
57 + * This program is free software; you can redistribute it and/or modify
58 + * it under the terms of the GNU General Public License version 2 as
59 + * published by the Free Software Foundation.
62 +#include <linux/init.h>
63 +#include <linux/module.h>
64 +#include <linux/platform_device.h>
65 +#include <linux/interrupt.h>
66 +#include <linux/wait.h>
67 +#include <linux/delay.h>
69 +#include <sound/core.h>
70 +#include <sound/pcm.h>
71 +#include <sound/ac97_codec.h>
72 +#include <sound/initval.h>
73 +#include <sound/soc.h>
76 +#include <linux/mutex.h>
77 +#include <linux/gpio.h>
79 +#include "ixp4xx_hss.h"
80 +#include "gw-avila-hss.h"
82 +#define gw_avila_hss_suspend NULL
83 +#define gw_avila_hss_resume NULL
85 +struct snd_soc_dai_driver gw_avila_hss_dai = {
89 + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
90 + SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
91 + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
92 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
93 + SNDRV_PCM_RATE_KNOT),
94 + .formats = SNDRV_PCM_FMTBIT_S16_LE, },
98 + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
99 + SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
100 + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
101 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
102 + SNDRV_PCM_RATE_KNOT),
103 + .formats = SNDRV_PCM_FMTBIT_S16_LE, },
106 +static const struct snd_soc_component_driver gw_avila_hss_component = {
107 + .name = "gw_avila_hss",
110 +static int gw_avila_hss_probe(struct platform_device *pdev)
112 + int port = (pdev->id < 2) ? 0 : 1;
113 + int channel = (pdev->id % 2);
115 + hss_handle[pdev->id] = hss_init(port, channel);
116 + if (!hss_handle[pdev->id]) {
120 + return snd_soc_register_component(&pdev->dev, &gw_avila_hss_component,
121 + &gw_avila_hss_dai, 1);
124 +static int gw_avila_hss_remove(struct platform_device *pdev)
126 + snd_soc_unregister_component(&pdev->dev);
131 +static struct platform_driver gw_avila_hss_driver = {
132 + .probe = gw_avila_hss_probe,
133 + .remove = gw_avila_hss_remove,
135 + .name = "gw_avila_hss",
136 + .owner = THIS_MODULE,
140 +static int __init gw_avila_hss_init(void)
142 + return platform_driver_register(&gw_avila_hss_driver);
144 +module_init(gw_avila_hss_init);
146 +static void __exit gw_avila_hss_exit(void)
148 + platform_driver_unregister(&gw_avila_hss_driver);
150 +module_exit(gw_avila_hss_exit);
152 +MODULE_AUTHOR("Chris Lang");
153 +MODULE_DESCRIPTION("HSS Audio Driver for Gateworks Avila");
154 +MODULE_LICENSE("GPL");
156 +++ b/sound/soc/gw-avila/gw-avila-hss.h
159 + * Author: Chris Lang <clang@gateworks.com>
161 + * This program is free software; you can redistribute it and/or modify
162 + * it under the terms of the GNU General Public License version 2 as
163 + * published by the Free Software Foundation.
166 +#ifndef _GW_AVILA_HSS_H
167 +#define _GW_AVILA_HSS_H
171 +++ b/sound/soc/gw-avila/gw-avila-pcm.c
174 + * ALSA PCM interface for the TI DAVINCI processor
176 + * Author: Chris Lang, <clang@gateworks.com>
177 + * Copyright: (C) 2009 Gateworks Corporation
179 + * Based On: davinci-evm.c, Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
181 + * This program is free software; you can redistribute it and/or modify
182 + * it under the terms of the GNU General Public License version 2 as
183 + * published by the Free Software Foundation.
186 +#include <linux/module.h>
187 +#include <linux/init.h>
188 +#include <linux/platform_device.h>
189 +#include <linux/slab.h>
190 +#include <linux/dma-mapping.h>
192 +#include <sound/core.h>
193 +#include <sound/pcm.h>
194 +#include <sound/pcm_params.h>
195 +#include <sound/soc.h>
197 +#include <asm/dma.h>
199 +#include "gw-avila-pcm.h"
200 +#include "gw-avila-hss.h"
201 +#include "ixp4xx_hss.h"
203 +#define GW_AVILA_PCM_DEBUG 0
204 +#if GW_AVILA_PCM_DEBUG
205 +#define DPRINTK(x...) printk(KERN_DEBUG x)
207 +#define DPRINTK(x...)
210 +static struct snd_pcm_hardware gw_avila_pcm_hardware = {
211 + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
212 + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
213 +/* SNDRV_PCM_INFO_PAUSE),*/
214 + .formats = (SNDRV_PCM_FMTBIT_S16_LE),
215 + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
216 + SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
217 + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
218 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
219 + SNDRV_PCM_RATE_KNOT),
224 + .buffer_bytes_max = 64 * 1024, // All of the lines below may need to be changed
225 + .period_bytes_min = 128,
226 + .period_bytes_max = 4 * 1024,
232 +struct gw_avila_runtime_data {
234 + int period; /* current DMA period */
235 + int master_lch; /* Master DMA channel */
236 + int slave_lch; /* Slave DMA channel */
237 + struct gw_avila_pcm_dma_params *params; /* DMA params */
240 +static void gw_avila_dma_irq(void *data)
242 + struct snd_pcm_substream *substream = data;
243 + snd_pcm_period_elapsed(substream);
246 +static int gw_avila_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
248 + struct snd_pcm_runtime *runtime = substream->runtime;
249 + struct hss_device *hdev = runtime->private_data;
253 + case SNDRV_PCM_TRIGGER_START:
254 + case SNDRV_PCM_TRIGGER_RESUME:
255 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
256 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
257 + hss_tx_start(hdev);
259 + hss_rx_start(hdev);
261 + case SNDRV_PCM_TRIGGER_STOP:
262 + case SNDRV_PCM_TRIGGER_SUSPEND:
263 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
264 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
276 +static int gw_avila_pcm_prepare(struct snd_pcm_substream *substream)
278 + struct snd_pcm_runtime *runtime = substream->runtime;
279 + struct hss_device *hdev = runtime->private_data;
281 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
282 + hss_set_tx_callback(hdev, gw_avila_dma_irq, substream);
283 + hss_config_tx_dma(hdev, runtime->dma_area, runtime->buffer_size, runtime->period_size);
285 + hss_set_rx_callback(hdev, gw_avila_dma_irq, substream);
286 + hss_config_rx_dma(hdev, runtime->dma_area, runtime->buffer_size, runtime->period_size);
292 +static snd_pcm_uframes_t
293 +gw_avila_pcm_pointer(struct snd_pcm_substream *substream)
295 + struct snd_pcm_runtime *runtime = substream->runtime;
296 + struct hss_device *hdev = runtime->private_data;
298 + unsigned int curr = 0;
299 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
300 + curr = hss_curr_offset_tx(hdev);
302 + curr = hss_curr_offset_rx(hdev);
306 +static int gw_avila_pcm_open(struct snd_pcm_substream *substream)
308 + struct snd_pcm_runtime *runtime = substream->runtime;
309 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
310 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
312 + snd_soc_set_runtime_hwparams(substream, &gw_avila_pcm_hardware);
314 + if (hss_handle[cpu_dai->id] != NULL)
315 + runtime->private_data = hss_handle[cpu_dai->id];
317 + pr_err("hss_handle is NULL\n");
321 + hss_chan_open(hss_handle[cpu_dai->id]);
326 +static int gw_avila_pcm_close(struct snd_pcm_substream *substream)
328 + struct snd_pcm_runtime *runtime = substream->runtime;
329 + struct hss_device *hdev = runtime->private_data;
331 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
332 + memset(hdev->tx_buf, 0, runtime->buffer_size);
334 + memset(hdev->rx_buf, 0, runtime->buffer_size);
336 + hss_chan_close(hdev);
341 +static int gw_avila_pcm_hw_params(struct snd_pcm_substream *substream,
342 + struct snd_pcm_hw_params *hw_params)
344 + return snd_pcm_lib_malloc_pages(substream,
345 + params_buffer_bytes(hw_params));
348 +static int gw_avila_pcm_hw_free(struct snd_pcm_substream *substream)
350 + struct snd_pcm_runtime *runtime = substream->runtime;
352 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
353 + memset(runtime->dma_area, 0, runtime->buffer_size);
355 + return snd_pcm_lib_free_pages(substream);
358 +static int gw_avila_pcm_mmap(struct snd_pcm_substream *substream,
359 + struct vm_area_struct *vma)
361 + struct snd_pcm_runtime *runtime = substream->runtime;
363 + return dma_mmap_writecombine(substream->pcm->card->dev, vma,
366 + runtime->dma_bytes);
369 +struct snd_pcm_ops gw_avila_pcm_ops = {
370 + .open = gw_avila_pcm_open,
371 + .close = gw_avila_pcm_close,
372 + .ioctl = snd_pcm_lib_ioctl,
373 + .hw_params = gw_avila_pcm_hw_params,
374 + .hw_free = gw_avila_pcm_hw_free,
375 + .prepare = gw_avila_pcm_prepare,
376 + .trigger = gw_avila_pcm_trigger,
377 + .pointer = gw_avila_pcm_pointer,
378 + .mmap = gw_avila_pcm_mmap,
381 +static int gw_avila_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
383 + struct snd_pcm_substream *substream = pcm->streams[stream].substream;
384 + struct snd_dma_buffer *buf = &substream->dma_buffer;
385 + size_t size = gw_avila_pcm_hardware.buffer_bytes_max;
387 + buf->dev.type = SNDRV_DMA_TYPE_DEV;
388 + buf->dev.dev = pcm->card->dev;
389 + buf->private_data = NULL;
391 + buf->area = dma_alloc_coherent(pcm->card->dev, size,
392 + &buf->addr, GFP_KERNEL);
398 + memset(buf->area, 0xff, size);
400 + DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n",
401 + (void *) buf->area, (void *) buf->addr, size);
408 +static void gw_avila_pcm_free(struct snd_pcm *pcm)
410 + struct snd_pcm_substream *substream;
411 + struct snd_dma_buffer *buf;
414 + for (stream = 0; stream < 2; stream++) {
415 + substream = pcm->streams[stream].substream;
419 + buf = &substream->dma_buffer;
423 + dma_free_coherent(NULL, buf->bytes, buf->area, 0);
428 +static u64 gw_avila_pcm_dmamask = 0xFFFFFFFF;
430 +static int gw_avila_pcm_new(struct snd_soc_pcm_runtime *rtd)
432 + struct snd_card *card = rtd->card->snd_card;
433 + struct snd_pcm *pcm = rtd->pcm;
434 + struct snd_soc_dai *dai = rtd->codec_dai;
437 + if (!card->dev->dma_mask)
438 + card->dev->dma_mask = &gw_avila_pcm_dmamask;
439 + if (!card->dev->coherent_dma_mask)
440 + card->dev->coherent_dma_mask = 0xFFFFFFFF;
442 + if (dai->driver->playback.channels_min) {
443 + ret = gw_avila_pcm_preallocate_dma_buffer(pcm,
444 + SNDRV_PCM_STREAM_PLAYBACK);
449 + if (dai->driver->capture.channels_min) {
450 + ret = gw_avila_pcm_preallocate_dma_buffer(pcm,
451 + SNDRV_PCM_STREAM_CAPTURE);
459 +struct snd_soc_platform_driver gw_avila_soc_platform = {
460 + .ops = &gw_avila_pcm_ops,
461 + .pcm_new = gw_avila_pcm_new,
462 + .pcm_free = gw_avila_pcm_free,
465 +static int gw_avila_pcm_platform_probe(struct platform_device *pdev)
467 + return snd_soc_register_platform(&pdev->dev, &gw_avila_soc_platform);
470 +static int gw_avila_pcm_platform_remove(struct platform_device *pdev)
472 + snd_soc_unregister_platform(&pdev->dev);
476 +static struct platform_driver gw_avila_pcm_driver = {
478 + .name = "gw_avila-audio",
479 + .owner = THIS_MODULE,
481 + .probe = gw_avila_pcm_platform_probe,
482 + .remove = gw_avila_pcm_platform_remove,
485 +static int __init gw_avila_soc_platform_init(void)
487 + return platform_driver_register(&gw_avila_pcm_driver);
489 +module_init(gw_avila_soc_platform_init);
491 +static void __exit gw_avila_soc_platform_exit(void)
493 + platform_driver_unregister(&gw_avila_pcm_driver);
495 +module_exit(gw_avila_soc_platform_exit);
497 +MODULE_AUTHOR("Chris Lang");
498 +MODULE_DESCRIPTION("Gateworks Avila PCM DMA module");
499 +MODULE_LICENSE("GPL");
501 +++ b/sound/soc/gw-avila/gw-avila-pcm.h
504 + * ALSA PCM interface for the Gateworks Avila platform
506 + * Author: Chris Lang, <clang@gateworks.com>
507 + * Copyright: (C) 2009 Gateworks Corporation
509 + * Based On: davinci-evm.c, Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
511 + * This program is free software; you can redistribute it and/or modify
512 + * it under the terms of the GNU General Public License version 2 as
513 + * published by the Free Software Foundation.
516 +#ifndef _GW_AVILA_PCM_H
517 +#define _GW_AVILA_PCM_H
520 +struct gw_avila_pcm_dma_params {
521 + char *name; /* stream identifier */
522 + int channel; /* sync dma channel ID */
523 + dma_addr_t dma_addr; /* device physical address for DMA */
524 + unsigned int data_type; /* xfer data type */
527 +struct gw_avila_snd_platform_data {
528 + int tx_dma_ch; // XXX Do we need this?
529 + int rx_dma_ch; // XXX Do we need this
531 +extern struct snd_soc_platform gw_avila_soc_platform[];
536 +++ b/sound/soc/gw-avila/gw-avila.c
539 + * File: sound/soc/gw-avila/gw_avila.c
540 + * Author: Chris Lang <clang@gateworks.com>
542 + * Created: Tue June 06 2008
543 + * Description: Board driver for Gateworks Avila
546 + * Copyright 2009 Gateworks Corporation
550 + * This program is free software; you can redistribute it and/or modify
551 + * it under the terms of the GNU General Public License as published by
552 + * the Free Software Foundation; either version 2 of the License, or
553 + * (at your option) any later version.
555 + * This program is distributed in the hope that it will be useful,
556 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
557 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
558 + * GNU General Public License for more details.
560 + * You should have received a copy of the GNU General Public License
561 + * along with this program; if not, see the file COPYING, or write
562 + * to the Free Software Foundation, Inc.,
563 + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
566 +#include <linux/module.h>
567 +#include <linux/moduleparam.h>
568 +#include <linux/device.h>
569 +#include <asm/dma.h>
570 +#include <linux/platform_device.h>
571 +#include <sound/core.h>
572 +#include <sound/pcm.h>
573 +#include <sound/soc.h>
574 +#include <linux/slab.h>
575 +#include <linux/gpio.h>
577 +#include "ixp4xx_hss.h"
578 +#include "gw-avila-hss.h"
579 +#include "gw-avila-pcm.h"
581 +#define CODEC_FREQ 33333000
583 +static int gw_avila_board_startup(struct snd_pcm_substream *substream)
585 + pr_debug("%s enter\n", __func__);
589 +static int gw_avila_hw_params(struct snd_pcm_substream *substream,
590 + struct snd_pcm_hw_params *params)
592 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
593 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
594 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
598 + /* set codec DAI configuration */
599 + if (cpu_dai->id % 2) {
600 + ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS);
601 + snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 1, 32);
603 + ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBM_CFM);
604 + snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 32);
610 + /* set the codec system clock */
611 + ret = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_FREQ, SND_SOC_CLOCK_OUT);
618 +static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
619 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
620 + SND_SOC_DAPM_LINE("Line Out", NULL),
621 + SND_SOC_DAPM_LINE("Line In", NULL),
624 +static const struct snd_soc_dapm_route audio_map[] = {
625 + {"Headphone Jack", NULL, "HPLOUT"},
626 + {"Headphone Jack", NULL, "HPROUT"},
628 + /* Line Out connected to LLOUT, RLOUT */
629 + {"Line Out", NULL, "LLOUT"},
630 + {"Line Out", NULL, "RLOUT"},
632 + /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
633 + {"LINE1L", NULL, "Line In"},
634 + {"LINE1R", NULL, "Line In"},
637 +/* Logic for a aic3x as connected on a davinci-evm */
638 +static int avila_aic3x_init(struct snd_soc_pcm_runtime *rtd)
640 + struct snd_soc_codec *codec = rtd->codec;
641 + struct snd_soc_dapm_context *dapm = &codec->dapm;
643 + /* Add davinci-evm specific widgets */
644 + snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
645 + ARRAY_SIZE(aic3x_dapm_widgets));
647 + /* Set up davinci-evm specific audio path audio_map */
648 + snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
650 + /* not connected */
651 + snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
652 + //snd_soc_dapm_disable_pin(dapm, "HPLCOM");
653 + //snd_soc_dapm_disable_pin(dapm, "HPRCOM");
654 + snd_soc_dapm_disable_pin(dapm, "MIC3L");
655 + snd_soc_dapm_disable_pin(dapm, "MIC3R");
656 + snd_soc_dapm_disable_pin(dapm, "LINE2L");
657 + snd_soc_dapm_disable_pin(dapm, "LINE2R");
659 + /* always connected */
660 + snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
661 + snd_soc_dapm_enable_pin(dapm, "Line Out");
662 + snd_soc_dapm_enable_pin(dapm, "Line In");
664 + snd_soc_dapm_sync(dapm);
669 +static struct snd_soc_ops gw_avila_board_ops = {
670 + .startup = gw_avila_board_startup,
671 + .hw_params = gw_avila_hw_params,
674 +static struct snd_soc_dai_link gw_avila_board_dai[] = {
677 + .stream_name = "HSS-0",
678 + .cpu_dai_name = "gw_avila_hss.0",
679 + .codec_dai_name = "tlv320aic3x-hifi",
680 + .codec_name = "tlv320aic3x-codec.0-001b",
681 + .platform_name = "gw_avila-audio.0",
682 + .init = avila_aic3x_init,
683 + .ops = &gw_avila_board_ops,
686 + .stream_name = "HSS-1",
687 + .cpu_dai_name = "gw_avila_hss.1",
688 + .codec_dai_name = "tlv320aic3x-hifi",
689 + .codec_name = "tlv320aic3x-codec.0-001a",
690 + .platform_name = "gw_avila-audio.1",
691 + .init = avila_aic3x_init,
692 + .ops = &gw_avila_board_ops,
695 + .stream_name = "HSS-2",
696 + .cpu_dai_name = "gw_avila_hss.2",
697 + .codec_dai_name = "tlv320aic3x-hifi",
698 + .codec_name = "tlv320aic3x-codec.0-0019",
699 + .platform_name = "gw_avila-audio.2",
700 + .init = avila_aic3x_init,
701 + .ops = &gw_avila_board_ops,
704 + .stream_name = "HSS-3",
705 + .cpu_dai_name = "gw_avila_hss.3",
706 + .codec_dai_name = "tlv320aic3x-hifi",
707 + .codec_name = "tlv320aic3x-codec.0-0018",
708 + .platform_name = "gw_avila-audio.3",
709 + .init = avila_aic3x_init,
710 + .ops = &gw_avila_board_ops,
714 +static struct snd_soc_card gw_avila_board[] = {
716 + .name = "gw_avila-board.0",
717 + .owner = THIS_MODULE,
718 + .dai_link = &gw_avila_board_dai[0],
721 + .name = "gw_avila-board.1",
722 + .owner = THIS_MODULE,
723 + .dai_link = &gw_avila_board_dai[1],
726 + .name = "gw_avila-board.2",
727 + .owner = THIS_MODULE,
728 + .dai_link = &gw_avila_board_dai[2],
731 + .name = "gw_avila-board.3",
732 + .owner = THIS_MODULE,
733 + .dai_link = &gw_avila_board_dai[3],
738 +static struct platform_device *gw_avila_board_snd_device[4];
740 +static int __init gw_avila_board_init(void)
746 + if ((hss_port[0] = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
749 + if ((hss_port[1] = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
752 + for (i = 0; i < 4; i++) {
753 + gw_avila_board_snd_device[i] = platform_device_alloc("soc-audio", i);
754 + if (!gw_avila_board_snd_device[i]) {
758 + platform_set_drvdata(gw_avila_board_snd_device[i], &gw_avila_board[i]);
759 + ret = platform_device_add(gw_avila_board_snd_device[i]);
762 + platform_device_put(gw_avila_board_snd_device[i]);
768 +static void __exit gw_avila_board_exit(void)
771 + for (i = 0; i < 4; i++)
772 + platform_device_unregister(gw_avila_board_snd_device[i]);
775 +module_init(gw_avila_board_init);
776 +module_exit(gw_avila_board_exit);
778 +/* Module information */
779 +MODULE_AUTHOR("Chris Lang");
780 +MODULE_DESCRIPTION("ALSA SoC HSS Audio gw_avila board");
781 +MODULE_LICENSE("GPL");
783 +++ b/sound/soc/gw-avila/ixp4xx_hss.c
786 + * Intel IXP4xx HSS (synchronous serial port) driver for Linux
788 + * Copyright (C) 2009 Chris Lang <clang@gateworks.com>
790 + * This program is free software; you can redistribute it and/or modify it
791 + * under the terms of version 2 of the GNU General Public License
792 + * as published by the Free Software Foundation.
795 +#include <linux/module.h>
796 +#include <linux/bitops.h>
797 +#include <linux/cdev.h>
798 +#include <linux/dma-mapping.h>
799 +#include <linux/dmapool.h>
800 +#include <linux/fs.h>
801 +#include <linux/io.h>
802 +#include <linux/kernel.h>
803 +#include <linux/platform_device.h>
804 +#include <linux/poll.h>
805 +#include <linux/slab.h>
806 +#include <linux/delay.h>
808 +#include <mach/npe.h>
809 +#include <mach/qmgr.h>
811 +#include "ixp4xx_hss.h"
813 +/*****************************************************************************
815 + ****************************************************************************/
817 +void hss_chan_read(unsigned long data);
818 +static char lock_init = 0;
819 +static spinlock_t npe_lock;
820 +static struct npe *npe;
822 +static const struct {
823 + int tx, txdone, rx, rxfree, chan;
824 +}queue_ids[2] = {{HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE, HSS0_PKT_RX_QUEUE,
825 + HSS0_PKT_RXFREE0_QUEUE, HSS0_CHL_RXTRIG_QUEUE},
826 + {HSS1_PKT_TX0_QUEUE, HSS1_PKT_TXDONE_QUEUE, HSS1_PKT_RX_QUEUE,
827 + HSS1_PKT_RXFREE0_QUEUE, HSS1_CHL_RXTRIG_QUEUE},
830 +struct port *hss_port[2];
831 +struct hss_device *hss_handle[32];
832 +EXPORT_SYMBOL(hss_handle);
834 +/*****************************************************************************
835 + * utility functions
836 + ****************************************************************************/
839 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
842 + for (i = 0; i < cnt; i++)
843 + dest[i] = swab32(src[i]);
847 +static inline unsigned int sub_offset(unsigned int a, unsigned int b,
848 + unsigned int modulo)
850 + return (modulo /* make sure the result >= 0 */ + a - b) % modulo;
853 +/*****************************************************************************
855 + ****************************************************************************/
857 +static void hss_config_load(struct port *port)
862 + memset(&msg, 0, sizeof(msg));
863 + msg.cmd = PORT_CONFIG_LOAD;
864 + msg.hss_port = port->id;
865 + if (npe_send_message(npe, &msg, "HSS_LOAD_CONFIG"))
867 + if (npe_recv_message(npe, &msg, "HSS_LOAD_CONFIG"))
870 + /* HSS_LOAD_CONFIG for port #1 returns port_id = #4 */
871 + if (msg.cmd != PORT_CONFIG_LOAD || msg.data32)
874 + /* HDLC may stop working without this */
875 + npe_recv_message(npe, &msg, "FLUSH_IT");
879 + printk(KERN_CRIT "HSS-%i: unable to reload HSS configuration\n",
884 +static void hss_config_set_pcr(struct port *port)
889 + memset(&msg, 0, sizeof(msg));
890 + msg.cmd = PORT_CONFIG_WRITE;
891 + msg.hss_port = port->id;
892 + msg.index = HSS_CONFIG_TX_PCR;
894 + msg.data32 = PCR_FRM_SYNC_RISINGEDGE | PCR_MSB_ENDIAN |
895 + PCR_TX_DATA_ENABLE | PCR_TX_UNASS_HIGH_IMP | PCR_TX_V56K_HIGH_IMP | PCR_TX_FB_HIGH_IMP;
897 + msg.data32 = PCR_FRM_SYNC_RISINGEDGE | PCR_MSB_ENDIAN |
898 + PCR_TX_DATA_ENABLE | PCR_TX_FB_HIGH_IMP | PCR_DCLK_EDGE_RISING;
900 + if (port->frame_size % 8 == 0)
901 + msg.data32 |= PCR_SOF_NO_FBIT;
903 + if (npe_send_message(npe, &msg, "HSS_SET_TX_PCR"))
906 + msg.index = HSS_CONFIG_RX_PCR;
907 + msg.data32 &= ~ (PCR_DCLK_EDGE_RISING | PCR_FCLK_EDGE_RISING | PCR_TX_DATA_ENABLE);
909 + if (npe_send_message(npe, &msg, "HSS_SET_RX_PCR"))
914 + printk(KERN_CRIT "HSS-%i: unable to set HSS PCR registers\n", port->id);
918 +static void hss_config_set_core(struct port *port)
922 + memset(&msg, 0, sizeof(msg));
923 + msg.cmd = PORT_CONFIG_WRITE;
924 + msg.hss_port = port->id;
925 + msg.index = HSS_CONFIG_CORE_CR;
927 + msg.data32 = 0 | CCR_LOOPBACK |
928 + (port->id ? CCR_SECOND_HSS : 0);
931 + (port->id ? CCR_SECOND_HSS : 0);
933 + if (npe_send_message(npe, &msg, "HSS_SET_CORE_CR")) {
934 + printk(KERN_CRIT "HSS-%i: unable to set HSS core control"
935 + " register\n", port->id);
940 +static void hss_config_set_line(struct port *port)
944 + hss_config_set_pcr(port);
945 + hss_config_set_core(port);
947 + memset(&msg, 0, sizeof(msg));
948 + msg.cmd = PORT_CONFIG_WRITE;
949 + msg.hss_port = port->id;
950 + msg.index = HSS_CONFIG_CLOCK_CR;
951 + msg.data32 = CLK42X_SPEED_8192KHZ /* FIXME */;
952 + if (npe_send_message(npe, &msg, "HSS_SET_CLOCK_CR")) {
953 + printk(KERN_CRIT "HSS-%i: unable to set HSS clock control"
954 + " register\n", port->id);
959 +static void hss_config_set_rx_frame(struct port *port)
963 + memset(&msg, 0, sizeof(msg));
964 + msg.cmd = PORT_CONFIG_WRITE;
965 + msg.hss_port = port->id;
966 + msg.index = HSS_CONFIG_RX_FCR;
967 + msg.data16a = port->frame_sync_offset;
968 + msg.data16b = port->frame_size - 1;
969 + if (npe_send_message(npe, &msg, "HSS_SET_RX_FCR")) {
970 + printk(KERN_CRIT "HSS-%i: unable to set HSS RX frame size"
971 + " and offset\n", port->id);
976 +static void hss_config_set_frame(struct port *port)
980 + memset(&msg, 0, sizeof(msg));
981 + msg.cmd = PORT_CONFIG_WRITE;
982 + msg.hss_port = port->id;
983 + msg.index = HSS_CONFIG_TX_FCR;
984 + msg.data16a = TX_FRAME_SYNC_OFFSET;
985 + msg.data16b = port->frame_size - 1;
986 + if (npe_send_message(npe, &msg, "HSS_SET_TX_FCR")) {
987 + printk(KERN_CRIT "HSS-%i: unable to set HSS TX frame size"
988 + " and offset\n", port->id);
991 + hss_config_set_rx_frame(port);
994 +static void hss_config_set_lut(struct port *port)
997 + int chan_count = 32;
999 + memset(&msg, 0, sizeof(msg));
1000 + msg.cmd = PORT_CONFIG_WRITE;
1001 + msg.hss_port = port->id;
1003 + msg.index = HSS_CONFIG_TX_LUT;
1004 + msg.data32 = 0xffffffff;
1005 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1007 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1010 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1012 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1014 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1016 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1018 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1020 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1022 + msg.index = HSS_CONFIG_RX_LUT;
1023 + msg.data32 = 0xffffffff;
1024 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1026 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1029 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1031 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1033 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1035 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1037 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1039 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1041 + hss_config_set_frame(port);
1043 + memset(&msg, 0, sizeof(msg));
1044 + msg.cmd = CHAN_NUM_CHANS_WRITE;
1045 + msg.hss_port = port->id;
1046 + msg.data8a = chan_count;
1047 + if (npe_send_message(npe, &msg, "CHAN_NUM_CHANS_WRITE")) {
1048 + printk(KERN_CRIT "HSS-%i: unable to set HSS channel count\n",
1054 +static u32 hss_config_get_status(struct port *port)
1059 + memset(&msg, 0, sizeof(msg));
1060 + msg.cmd = PORT_ERROR_READ;
1061 + msg.hss_port = port->id;
1062 + if (npe_send_message(npe, &msg, "PORT_ERROR_READ"))
1064 + if (npe_recv_message(npe, &msg, "PORT_ERROR_READ"))
1067 + return msg.data32;
1070 + printk(KERN_CRIT "HSS-%i: unable to read HSS status\n", port->id);
1074 +static void hss_config_start_chan(struct port *port)
1078 + port->chan_last_tx = 0;
1079 + port->chan_last_rx = 0;
1082 + memset(&msg, 0, sizeof(msg));
1083 + msg.cmd = CHAN_RX_BUF_ADDR_WRITE;
1084 + msg.hss_port = port->id;
1085 + msg.data32 = port->chan_rx_buf_phys;
1086 + if (npe_send_message(npe, &msg, "CHAN_RX_BUF_ADDR_WRITE"))
1089 + memset(&msg, 0, sizeof(msg));
1090 + msg.cmd = CHAN_TX_BUF_ADDR_WRITE;
1091 + msg.hss_port = port->id;
1092 + msg.data32 = port->chan_tx_pointers_phys;
1093 + if (npe_send_message(npe, &msg, "CHAN_TX_BUF_ADDR_WRITE"))
1096 + memset(&msg, 0, sizeof(msg));
1097 + msg.cmd = CHAN_FLOW_ENABLE;
1098 + msg.hss_port = port->id;
1099 + if (npe_send_message(npe, &msg, "CHAN_FLOW_ENABLE"))
1101 + port->chan_started = 1;
1105 + printk(KERN_CRIT "HSS-%i: unable to start channelized flow\n",
1110 +static void hss_config_stop_chan(struct port *port)
1114 + if (!port->chan_started)
1117 + memset(&msg, 0, sizeof(msg));
1118 + msg.cmd = CHAN_FLOW_DISABLE;
1119 + msg.hss_port = port->id;
1120 + if (npe_send_message(npe, &msg, "CHAN_FLOW_DISABLE")) {
1121 + printk(KERN_CRIT "HSS-%i: unable to stop channelized flow\n",
1125 + hss_config_get_status(port); /* make sure it's halted */
1126 + port->chan_started = 0;
1129 +static int hss_config_load_firmware(struct port *port)
1133 + if (port->initialized)
1136 + if (!npe_running(npe)) {
1138 + if ((err = npe_load_firmware(npe, "NPE-A-HSS",
1144 + /* HSS main configuration */
1145 + hss_config_set_line(port);
1147 + hss_config_set_frame(port);
1149 + /* Channelized operation settings */
1150 + memset(&msg, 0, sizeof(msg));
1151 + msg.cmd = CHAN_TX_BLK_CFG_WRITE;
1152 + msg.hss_port = port->id;
1153 + msg.data8b = (CHAN_TX_LIST_FRAMES & ~7) / 2;
1154 + msg.data8a = msg.data8b / 4;
1155 + msg.data8d = CHAN_TX_LIST_FRAMES - msg.data8b;
1156 + msg.data8c = msg.data8d / 4;
1157 + if (npe_send_message(npe, &msg, "CHAN_TX_BLK_CFG_WRITE"))
1160 + memset(&msg, 0, sizeof(msg));
1161 + msg.cmd = CHAN_RX_BUF_CFG_WRITE;
1162 + msg.hss_port = port->id;
1163 + msg.data8a = CHAN_RX_TRIGGER / 8;
1164 + msg.data8b = CHAN_RX_FRAMES;
1165 + if (npe_send_message(npe, &msg, "CHAN_RX_BUF_CFG_WRITE"))
1168 + memset(&msg, 0, sizeof(msg));
1169 + msg.cmd = CHAN_TX_BUF_SIZE_WRITE;
1170 + msg.hss_port = port->id;
1171 + msg.data8a = CHAN_TX_LISTS;
1172 + if (npe_send_message(npe, &msg, "CHAN_TX_BUF_SIZE_WRITE"))
1175 + port->initialized = 1;
1179 + printk(KERN_CRIT "HSS-%i: unable to start HSS operation\n", port->id);
1183 +void hss_chan_irq(void *pdev)
1185 + struct port *port = pdev;
1187 + qmgr_disable_irq(queue_ids[port->id].chan);
1189 + tasklet_hi_schedule(&port->task);
1193 +int hss_prepare_chan(struct port *port)
1200 + if (port->initialized)
1203 + if ((err = hss_config_load_firmware(port)))
1206 + if ((err = qmgr_request_queue(queue_ids[port->id].chan,
1207 + CHAN_QUEUE_LEN, 0, 0, "%s:hss", "hss")))
1210 + port->chan_tx_buf = dma_alloc_coherent(port->dev, chan_tx_buf_len(port), &port->chan_tx_buf_phys, GFP_DMA);
1211 + memset(port->chan_tx_buf, 0, chan_tx_buf_len(port));
1213 + port->chan_tx_pointers = dma_alloc_coherent(port->dev, chan_tx_buf_len(port) / CHAN_TX_LIST_FRAMES * 4, &port->chan_tx_pointers_phys, GFP_DMA);
1215 + temp3 = port->chan_tx_buf;
1216 + for (i = 0; i < CHAN_TX_LISTS; i++) {
1217 + for (j = 0; j < 8; j++) {
1218 + port->tx_lists[i][j] = temp3;
1219 + temp3 += CHAN_TX_LIST_FRAMES * 4;
1223 + temp = port->chan_tx_pointers;
1224 + temp2 = port->chan_tx_buf_phys;
1225 + for (i = 0; i < CHAN_TX_LISTS; i++)
1227 + for (j = 0; j < 32; j++)
1230 + temp2 += CHAN_TX_LIST_FRAMES;
1235 + port->chan_rx_buf = dma_alloc_coherent(port->dev, chan_rx_buf_len(port), &port->chan_rx_buf_phys, GFP_DMA);
1237 + for (i = 0; i < 8; i++) {
1238 + temp3 = port->chan_rx_buf + (i * 4 * 128);
1239 + for (j = 0; j < 8; j++) {
1240 + port->rx_frames[i][j] = temp3;
1241 + temp3 += CHAN_RX_TRIGGER;
1245 + qmgr_set_irq(queue_ids[port->id].chan, QUEUE_IRQ_SRC_NOT_EMPTY,
1246 + hss_chan_irq, port);
1252 +int hss_tx_start(struct hss_device *hdev)
1254 + unsigned long flags;
1255 + struct port *port = hdev->port;
1258 + hdev->tx_frame = 0;
1260 + set_bit((1 << hdev->id), &port->chan_tx_bitmap);
1262 + if (!port->chan_started)
1264 + qmgr_enable_irq(queue_ids[port->id].chan);
1265 + spin_lock_irqsave(&npe_lock, flags);
1266 + hss_config_start_chan(port);
1267 + spin_unlock_irqrestore(&npe_lock, flags);
1268 + hss_chan_irq(port);
1273 +EXPORT_SYMBOL(hss_tx_start);
1275 +int hss_rx_start(struct hss_device *hdev)
1277 + unsigned long flags;
1278 + struct port *port = hdev->port;
1281 + hdev->rx_frame = 0;
1283 + set_bit((1 << hdev->id), &port->chan_rx_bitmap);
1285 + if (!port->chan_started)
1287 + qmgr_enable_irq(queue_ids[port->id].chan);
1288 + spin_lock_irqsave(&npe_lock, flags);
1289 + hss_config_start_chan(port);
1290 + spin_unlock_irqrestore(&npe_lock, flags);
1291 + hss_chan_irq(port);
1296 +EXPORT_SYMBOL(hss_rx_start);
1298 +int hss_tx_stop(struct hss_device *hdev)
1300 + struct port *port = hdev->port;
1302 + clear_bit((1 << hdev->id), &port->chan_tx_bitmap);
1306 +EXPORT_SYMBOL(hss_tx_stop);
1308 +int hss_rx_stop(struct hss_device *hdev)
1310 + struct port *port = hdev->port;
1312 + clear_bit((1 << hdev->id), &port->chan_rx_bitmap);
1316 +EXPORT_SYMBOL(hss_rx_stop);
1318 +int hss_chan_open(struct hss_device *hdev)
1320 + struct port *port = hdev->port;
1323 + if (port->chan_open)
1326 + if (port->mode == MODE_HDLC) {
1331 + if (port->mode == MODE_G704 && port->channels[0] == hdev->id) {
1332 + err = -EBUSY; /* channel #0 is used for G.704 signaling */
1336 + for (i = MAX_CHANNELS; i > port->frame_size / 8; i--)
1337 + if (port->channels[i - 1] == hdev->id) {
1338 + err = -ECHRNG; /* frame too short */
1342 + hdev->rx_loc = hdev->tx_loc = 0;
1343 + hdev->rx_frame = hdev->tx_frame = 0;
1345 + //clear_bit((1 << hdev->id), &port->chan_rx_bitmap);
1346 + //clear_bit((1 << hdev->id), &port->chan_tx_bitmap);
1348 + if (!port->initialized) {
1349 + hss_prepare_chan(port);
1351 + hss_config_stop_chan(port);
1352 + hdev->open_count++;
1353 + port->chan_open_count++;
1355 + hss_config_set_lut(port);
1356 + hss_config_load(port);
1359 + port->chan_open = 1;
1364 +EXPORT_SYMBOL(hss_chan_open);
1366 +int hss_chan_close(struct hss_device *hdev)
1370 +EXPORT_SYMBOL(hss_chan_close);
1372 +void hss_chan_read(unsigned long data)
1374 + struct port *port = (void *)data;
1375 + struct hss_device *hdev;
1376 + u8 *hw_buf, *save_buf;
1379 + unsigned int tx_list, rx_frame;
1380 + int i, j, channel;
1384 + My Data in the hardware buffer is scattered by channels into 4 trunks
1387 + channel 0 channel 1 channel 2 channel 3
1388 +Trunk 1 = 0 -> 127 128 -> 255 256 -> 383 384 -> 512
1389 +Trunk 2 = 513 -> 639 640 -> 768 769 -> 895 896 -> 1023
1390 +Trunk 3 = 1024 -> 1151 1152 -> 1207 1208 -> 1407 1408 -> 1535
1391 +Trunk 4 = 1535 -> 1663 1664 -> 1791 1792 -> 1920 1921 -> 2047
1393 + I will get CHAN_RX_TRIGGER worth of bytes out of each channel on each trunk
1396 + For TX Data, it is split into 8 lists with each list containing 16 bytes per
1399 +Trunk 1 = 0 -> 16 17 -> 32 33 -> 48 49 -> 64
1400 +Trunk 2 = 65 -> 80 81 -> 96 97 -> 112 113 -> 128
1401 +Trunk 3 = 129 -> 144 145 -> 160 161 -> 176 177 -> 192
1402 +Trunk 4 = 193 -> 208 209 -> 224 225 -> 240 241 -> 256
1407 + while ((v = qmgr_get_entry(queue_ids[port->id].chan)))
1409 + tx_list = (v >> 8) & 0xFF;
1410 + rx_frame = v & 0xFF;
1416 + for (channel = 0; channel < 8; channel++) {
1418 + hdev = port->chan_devices[channel];
1422 + if (test_bit(1 << channel, &port->chan_tx_bitmap)) {
1423 + buf = (u8 *)hdev->tx_buf + hdev->tx_loc;
1425 + hw_buf = (u8 *)port->chan_tx_buf;
1426 + hw_buf += (tx_list * CHAN_TX_LIST_FRAMES * 32);
1427 + hw_buf += (4 * CHAN_TX_LIST_FRAMES * channel);
1428 + save_buf = hw_buf;
1430 + save_buf = port->tx_lists[tx_list][channel];
1432 + for (i = 0; i < CHAN_TX_LIST_FRAMES; i++) {
1433 + hw_buf = save_buf + i;
1434 + for (j = 0; j < 4; j++) {
1435 + *hw_buf = *(buf++);
1436 + hw_buf += CHAN_TX_LIST_FRAMES;
1439 + hdev->tx_loc += 4;
1441 + if (hdev->tx_loc >= hdev->tx_buffer_size) {
1443 + buf = (u8 *)hdev->tx_buf;
1448 + hw_buf = (u8 *)port->chan_tx_buf;
1449 + hw_buf += (tx_list * CHAN_TX_LIST_FRAMES * 32);
1450 + hw_buf += (4 * CHAN_TX_LIST_FRAMES * channel);
1452 + hw_buf = port->tx_lists[tx_list][channel];
1454 + memset(hw_buf, 0, 64);
1457 + if (hdev->tx_frame >= hdev->tx_period_size && test_bit(1 << channel, &port->chan_tx_bitmap))
1459 + hdev->tx_frame %= hdev->tx_period_size;
1460 + if (hdev->tx_callback)
1461 + hdev->tx_callback(hdev->tx_data);
1465 + if (test_bit(1 << channel, &port->chan_rx_bitmap)) {
1466 + buf = (u8 *)hdev->rx_buf + hdev->rx_loc;
1468 + hw_buf = (u8 *)port->chan_rx_buf;
1469 + hw_buf += (4 * CHAN_RX_FRAMES * channel);
1470 + hw_buf += rx_frame;
1471 + save_buf = hw_buf;
1473 + save_buf = port->rx_frames[channel][rx_frame >> 4];
1475 + for (i = 0; i < CHAN_RX_TRIGGER; i++) {
1476 + hw_buf = save_buf + i;
1477 + for (j = 0; j < 4; j++) {
1478 + *(buf++) = *hw_buf;
1479 + hw_buf += CHAN_RX_FRAMES;
1481 + hdev->rx_loc += 4;
1483 + if (hdev->rx_loc >= hdev->rx_buffer_size) {
1485 + buf = (u8 *)hdev->rx_buf;
1490 + if (hdev->rx_frame >= hdev->rx_period_size && test_bit(1 << channel, &port->chan_rx_bitmap))
1492 + hdev->rx_frame %= hdev->rx_period_size;
1493 + if (hdev->rx_callback)
1494 + hdev->rx_callback(hdev->rx_data);
1501 + tasklet_hi_schedule(&port->task);
1507 + qmgr_enable_irq(queue_ids[port->id].chan);
1513 +struct hss_device *hss_chan_create(struct port *port, unsigned int channel)
1515 + struct hss_device *chan_dev;
1516 + unsigned long flags;
1518 + chan_dev = kzalloc(sizeof(struct hss_device), GFP_KERNEL);
1520 + spin_lock_irqsave(&npe_lock, flags);
1522 + chan_dev->id = channel;
1523 + chan_dev->port = port;
1525 + port->channels[channel] = channel;
1527 + port->chan_devices[channel] = chan_dev;
1529 + spin_unlock_irqrestore(&npe_lock, flags);
1534 +/*****************************************************************************
1536 + ****************************************************************************/
1538 +static struct platform_device gw_avila_hss_device_0 = {
1539 + .name = "ixp4xx_hss",
1543 +static struct platform_device gw_avila_hss_device_1 = {
1544 + .name = "ixp4xx_hss",
1548 +static struct platform_device *gw_avila_hss_port_0;
1549 +static struct platform_device *gw_avila_hss_port_1;
1550 +static u64 hss_dmamask = 0xFFFFFFFF;
1552 +struct hss_device *hss_init(int id, int channel)
1554 + struct port *port = hss_port[id];
1555 + struct hss_device *hdev;
1560 + spin_lock_init(&npe_lock);
1562 + npe = npe_request(0);
1565 + if (!port->init) {
1567 + gw_avila_hss_port_0 = platform_device_alloc("hss-port", 0);
1569 + platform_set_drvdata(gw_avila_hss_port_0, &gw_avila_hss_device_0);
1570 + port->dev = &gw_avila_hss_port_0->dev;
1572 + if (!port->dev->dma_mask)
1573 + port->dev->dma_mask = &hss_dmamask;
1574 + if (!port->dev->coherent_dma_mask)
1575 + port->dev->coherent_dma_mask = 0xFFFFFFFF;
1577 + ret = platform_device_add(gw_avila_hss_port_0);
1580 + platform_device_put(gw_avila_hss_port_0);
1582 + tasklet_init(&port->task, hss_chan_read, (unsigned long) port);
1586 + gw_avila_hss_port_1 = platform_device_alloc("hss-port", 1);
1588 + platform_set_drvdata(gw_avila_hss_port_1, &gw_avila_hss_device_1);
1589 + port->dev = &gw_avila_hss_port_1->dev;
1591 + if (!port->dev->dma_mask)
1592 + port->dev->dma_mask = &hss_dmamask;
1593 + if (!port->dev->coherent_dma_mask)
1594 + port->dev->coherent_dma_mask = 0xFFFFFFFF;
1596 + ret = platform_device_add(gw_avila_hss_port_1);
1599 + platform_device_put(gw_avila_hss_port_1);
1601 + tasklet_init(&port->task, hss_chan_read, (unsigned long) port);
1606 + port->clock_type = CLOCK_EXT;
1607 + port->clock_rate = 8192000;
1608 + port->frame_size = 256; /* E1 */
1609 + port->mode = MODE_RAW;
1610 + port->next_rx_frame = 0;
1611 + memset(port->channels, CHANNEL_UNUSED, sizeof(port->channels));
1614 + hdev = hss_chan_create(port, channel);
1618 +EXPORT_SYMBOL(hss_init);
1620 +int hss_set_tx_callback(struct hss_device *hdev, void (*tx_callback)(void *), void *tx_data)
1622 + BUG_ON(tx_callback == NULL);
1623 + hdev->tx_callback = tx_callback;
1624 + hdev->tx_data = tx_data;
1628 +EXPORT_SYMBOL(hss_set_tx_callback);
1630 +int hss_set_rx_callback(struct hss_device *hdev, void (*rx_callback)(void *), void *rx_data)
1632 + BUG_ON(rx_callback == NULL);
1633 + hdev->rx_callback = rx_callback;
1634 + hdev->rx_data = rx_data;
1638 +EXPORT_SYMBOL(hss_set_rx_callback);
1640 +int hss_config_rx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size)
1643 + * Period Size and Buffer Size are in Frames which are u32
1644 + * We convert the u32 *buf to u8 in order to make channel reads
1645 + * and rx_loc easier
1648 + hdev->rx_buf = (u8 *)buf;
1649 + hdev->rx_buffer_size = buffer_size << 2;
1650 + hdev->rx_period_size = period_size;
1654 +EXPORT_SYMBOL(hss_config_rx_dma);
1656 +int hss_config_tx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size)
1659 + * Period Size and Buffer Size are in Frames which are u32
1660 + * We convert the u32 *buf to u8 in order to make channel reads
1661 + * and rx_loc easier
1664 + hdev->tx_buf = (u8 *)buf;
1665 + hdev->tx_buffer_size = buffer_size << 2;
1666 + hdev->tx_period_size = period_size;
1670 +EXPORT_SYMBOL(hss_config_tx_dma);
1672 +unsigned long hss_curr_offset_rx(struct hss_device *hdev)
1674 + return hdev->rx_loc >> 2;
1676 +EXPORT_SYMBOL(hss_curr_offset_rx);
1678 +unsigned long hss_curr_offset_tx(struct hss_device *hdev)
1680 + return hdev->tx_loc >> 2;
1682 +EXPORT_SYMBOL(hss_curr_offset_tx);
1684 +MODULE_AUTHOR("Chris Lang");
1685 +MODULE_DESCRIPTION("Intel IXP4xx HSS Audio driver");
1686 +MODULE_LICENSE("GPL v2");
1688 +++ b/sound/soc/gw-avila/ixp4xx_hss.h
1693 + * Copyright (C) 2009 Gateworks Corporation
1695 + * This program is free software; you can redistribute it and/or modify it
1696 + * under the terms of version 2 of the GNU General Public License
1697 + * as published by the Free Software Foundation.
1700 +#include <linux/types.h>
1701 +#include <linux/bitops.h>
1702 +#include <linux/dma-mapping.h>
1703 +#include <linux/dmapool.h>
1704 +#include <linux/fs.h>
1705 +#include <linux/io.h>
1706 +#include <linux/kernel.h>
1707 +#include <linux/platform_device.h>
1708 +#include <linux/poll.h>
1709 +#include <mach/npe.h>
1710 +#include <mach/qmgr.h>
1711 +#include <linux/interrupt.h>
1713 +//#include <linux/hdlc.h> XXX We aren't HDLC
1715 +#define DEBUG_QUEUES 0
1716 +#define DEBUG_DESC 0
1719 +#define DEBUG_PKT_BYTES 0
1720 +#define DEBUG_CLOSE 0
1721 +#define DEBUG_FRAMER 0
1723 +#define DRV_NAME "ixp4xx_hss"
1725 +#define PKT_EXTRA_FLAGS 0 /* orig 1 */
1726 +#define TX_FRAME_SYNC_OFFSET 0 /* channelized */
1727 +#define PKT_NUM_PIPES 1 /* 1, 2 or 4 */
1728 +#define PKT_PIPE_FIFO_SIZEW 4 /* total 4 dwords per HSS */
1730 +#define RX_DESCS 512 /* also length of all RX queues */
1731 +#define TX_DESCS 512 /* also length of all TX queues */
1733 +//#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
1734 +#define RX_SIZE (HDLC_MAX_MRU + 4) /* NPE needs more space */
1735 +#define MAX_CLOSE_WAIT 1000 /* microseconds */
1736 +#define HSS_COUNT 2
1737 +#define MIN_FRAME_SIZE 16 /* bits */
1738 +#define MAX_FRAME_SIZE 257 /* 256 bits + framing bit */
1739 +#define MAX_CHANNELS (MAX_FRAME_SIZE / 8)
1740 +#define MAX_CHAN_DEVICES 32
1741 +#define CHANNEL_HDLC 0xFE
1742 +#define CHANNEL_UNUSED 0xFF
1744 +#define NAPI_WEIGHT 16
1745 +#define CHAN_RX_TRIGGER 16 /* 8 RX frames = 1 ms @ E1 */
1746 +#define CHAN_RX_FRAMES 128
1747 +#define CHAN_RX_TRUNKS 1
1748 +#define MAX_CHAN_RX_BAD_SYNC (CHAN_RX_TRIGGER / 2 /* pairs */ - 3)
1750 +#define CHAN_TX_LIST_FRAMES CHAN_RX_TRIGGER /* bytes/channel per list, 16 - 48 */
1751 +#define CHAN_TX_LISTS 8
1752 +#define CHAN_TX_TRUNKS CHAN_RX_TRUNKS
1753 +#define CHAN_TX_FRAMES (CHAN_TX_LIST_FRAMES * CHAN_TX_LISTS)
1755 +#define CHAN_QUEUE_LEN 32 /* minimum possible */
1757 +#define chan_rx_buf_len(port) (port->frame_size / 8 * CHAN_RX_FRAMES * CHAN_RX_TRUNKS)
1758 +#define chan_tx_buf_len(port) (port->frame_size / 8 * CHAN_TX_FRAMES * CHAN_TX_TRUNKS)
1761 +#define HSS0_CHL_RXTRIG_QUEUE 12 /* orig size = 32 dwords */
1762 +#define HSS0_PKT_RX_QUEUE 13 /* orig size = 32 dwords */
1763 +#define HSS0_PKT_TX0_QUEUE 14 /* orig size = 16 dwords */
1764 +#define HSS0_PKT_TX1_QUEUE 15
1765 +#define HSS0_PKT_TX2_QUEUE 16
1766 +#define HSS0_PKT_TX3_QUEUE 17
1767 +#define HSS0_PKT_RXFREE0_QUEUE 18 /* orig size = 16 dwords */
1768 +#define HSS0_PKT_RXFREE1_QUEUE 19
1769 +#define HSS0_PKT_RXFREE2_QUEUE 20
1770 +#define HSS0_PKT_RXFREE3_QUEUE 21
1771 +#define HSS0_PKT_TXDONE_QUEUE 22 /* orig size = 64 dwords */
1773 +#define HSS1_CHL_RXTRIG_QUEUE 10
1774 +#define HSS1_PKT_RX_QUEUE 0
1775 +#define HSS1_PKT_TX0_QUEUE 5
1776 +#define HSS1_PKT_TX1_QUEUE 6
1777 +#define HSS1_PKT_TX2_QUEUE 7
1778 +#define HSS1_PKT_TX3_QUEUE 8
1779 +#define HSS1_PKT_RXFREE0_QUEUE 1
1780 +#define HSS1_PKT_RXFREE1_QUEUE 2
1781 +#define HSS1_PKT_RXFREE2_QUEUE 3
1782 +#define HSS1_PKT_RXFREE3_QUEUE 4
1783 +#define HSS1_PKT_TXDONE_QUEUE 9
1785 +#define NPE_PKT_MODE_HDLC 0
1786 +#define NPE_PKT_MODE_RAW 1
1787 +#define NPE_PKT_MODE_56KMODE 2
1788 +#define NPE_PKT_MODE_56KENDIAN_MSB 4
1790 +/* PKT_PIPE_HDLC_CFG_WRITE flags */
1791 +#define PKT_HDLC_IDLE_ONES 0x1 /* default = flags */
1792 +#define PKT_HDLC_CRC_32 0x2 /* default = CRC-16 */
1793 +#define PKT_HDLC_MSB_ENDIAN 0x4 /* default = LE */
1796 +/* hss_config, PCRs */
1797 +/* Frame sync sampling, default = active low */
1798 +#define PCR_FRM_SYNC_ACTIVE_HIGH 0x40000000
1799 +#define PCR_FRM_SYNC_FALLINGEDGE 0x80000000
1800 +#define PCR_FRM_SYNC_RISINGEDGE 0xC0000000
1802 +/* Frame sync pin: input (default) or output generated off a given clk edge */
1803 +#define PCR_FRM_SYNC_OUTPUT_FALLING 0x20000000
1804 +#define PCR_FRM_SYNC_OUTPUT_RISING 0x30000000
1806 +/* Frame and data clock sampling on edge, default = falling */
1807 +#define PCR_FCLK_EDGE_RISING 0x08000000
1808 +#define PCR_DCLK_EDGE_RISING 0x04000000
1810 +/* Clock direction, default = input */
1811 +#define PCR_SYNC_CLK_DIR_OUTPUT 0x02000000
1813 +/* Generate/Receive frame pulses, default = enabled */
1814 +#define PCR_FRM_PULSE_DISABLED 0x01000000
1816 + /* Data rate is full (default) or half the configured clk speed */
1817 +#define PCR_HALF_CLK_RATE 0x00200000
1819 +/* Invert data between NPE and HSS FIFOs? (default = no) */
1820 +#define PCR_DATA_POLARITY_INVERT 0x00100000
1822 +/* TX/RX endianness, default = LSB */
1823 +#define PCR_MSB_ENDIAN 0x00080000
1825 +/* Normal (default) / open drain mode (TX only) */
1826 +#define PCR_TX_PINS_OPEN_DRAIN 0x00040000
1828 +/* No framing bit transmitted and expected on RX? (default = framing bit) */
1829 +#define PCR_SOF_NO_FBIT 0x00020000
1831 +/* Drive data pins? */
1832 +#define PCR_TX_DATA_ENABLE 0x00010000
1834 +/* Voice 56k type: drive the data pins low (default), high, high Z */
1835 +#define PCR_TX_V56K_HIGH 0x00002000
1836 +#define PCR_TX_V56K_HIGH_IMP 0x00004000
1838 +/* Unassigned type: drive the data pins low (default), high, high Z */
1839 +#define PCR_TX_UNASS_HIGH 0x00000800
1840 +#define PCR_TX_UNASS_HIGH_IMP 0x00001000
1842 +/* T1 @ 1.544MHz only: Fbit dictated in FIFO (default) or high Z */
1843 +#define PCR_TX_FB_HIGH_IMP 0x00000400
1845 +/* 56k data endiannes - which bit unused: high (default) or low */
1846 +#define PCR_TX_56KE_BIT_0_UNUSED 0x00000200
1848 +/* 56k data transmission type: 32/8 bit data (default) or 56K data */
1849 +#define PCR_TX_56KS_56K_DATA 0x00000100
1851 +/* hss_config, cCR */
1852 +/* Number of packetized clients, default = 1 */
1853 +#define CCR_NPE_HFIFO_2_HDLC 0x04000000
1854 +#define CCR_NPE_HFIFO_3_OR_4HDLC 0x08000000
1856 +/* default = no loopback */
1857 +#define CCR_LOOPBACK 0x02000000
1859 +/* HSS number, default = 0 (first) */
1860 +#define CCR_SECOND_HSS 0x01000000
1863 +/* hss_config, clkCR: main:10, num:10, denom:12 */
1864 +#define CLK42X_SPEED_EXP ((0x3FF << 22) | ( 2 << 12) | 15) /*65 KHz*/
1866 +#define CLK42X_SPEED_512KHZ (( 130 << 22) | ( 2 << 12) | 15)
1867 +#define CLK42X_SPEED_1536KHZ (( 43 << 22) | ( 18 << 12) | 47)
1868 +#define CLK42X_SPEED_1544KHZ (( 43 << 22) | ( 33 << 12) | 192)
1869 +#define CLK42X_SPEED_2048KHZ (( 32 << 22) | ( 34 << 12) | 63)
1870 +#define CLK42X_SPEED_4096KHZ (( 16 << 22) | ( 34 << 12) | 127)
1871 +#define CLK42X_SPEED_8192KHZ (( 8 << 22) | ( 34 << 12) | 255)
1873 +#define CLK46X_SPEED_512KHZ (( 130 << 22) | ( 24 << 12) | 127)
1874 +#define CLK46X_SPEED_1536KHZ (( 43 << 22) | (152 << 12) | 383)
1875 +#define CLK46X_SPEED_1544KHZ (( 43 << 22) | ( 66 << 12) | 385)
1876 +#define CLK46X_SPEED_2048KHZ (( 32 << 22) | (280 << 12) | 511)
1877 +#define CLK46X_SPEED_4096KHZ (( 16 << 22) | (280 << 12) | 1023)
1878 +#define CLK46X_SPEED_8192KHZ (( 8 << 22) | (280 << 12) | 2047)
1881 +/* hss_config, LUT entries */
1882 +#define TDMMAP_UNASSIGNED 0
1883 +#define TDMMAP_HDLC 1 /* HDLC - packetized */
1884 +#define TDMMAP_VOICE56K 2 /* Voice56K - 7-bit channelized */
1885 +#define TDMMAP_VOICE64K 3 /* Voice64K - 8-bit channelized */
1887 +/* offsets into HSS config */
1888 +#define HSS_CONFIG_TX_PCR 0x00 /* port configuration registers */
1889 +#define HSS_CONFIG_RX_PCR 0x04
1890 +#define HSS_CONFIG_CORE_CR 0x08 /* loopback control, HSS# */
1891 +#define HSS_CONFIG_CLOCK_CR 0x0C /* clock generator control */
1892 +#define HSS_CONFIG_TX_FCR 0x10 /* frame configuration registers */
1893 +#define HSS_CONFIG_RX_FCR 0x14
1894 +#define HSS_CONFIG_TX_LUT 0x18 /* channel look-up tables */
1895 +#define HSS_CONFIG_RX_LUT 0x38
1898 +/* NPE command codes */
1899 +/* writes the ConfigWord value to the location specified by offset */
1900 +#define PORT_CONFIG_WRITE 0x40
1902 +/* triggers the NPE to load the contents of the configuration table */
1903 +#define PORT_CONFIG_LOAD 0x41
1905 +/* triggers the NPE to return an HssErrorReadResponse message */
1906 +#define PORT_ERROR_READ 0x42
1908 +/* reset NPE internal status and enable the HssChannelized operation */
1909 +#define CHAN_FLOW_ENABLE 0x43
1910 +#define CHAN_FLOW_DISABLE 0x44
1911 +#define CHAN_IDLE_PATTERN_WRITE 0x45
1912 +#define CHAN_NUM_CHANS_WRITE 0x46
1913 +#define CHAN_RX_BUF_ADDR_WRITE 0x47
1914 +#define CHAN_RX_BUF_CFG_WRITE 0x48
1915 +#define CHAN_TX_BLK_CFG_WRITE 0x49
1916 +#define CHAN_TX_BUF_ADDR_WRITE 0x4A
1917 +#define CHAN_TX_BUF_SIZE_WRITE 0x4B
1918 +#define CHAN_TSLOTSWITCH_ENABLE 0x4C
1919 +#define CHAN_TSLOTSWITCH_DISABLE 0x4D
1921 +/* downloads the gainWord value for a timeslot switching channel associated
1923 +#define CHAN_TSLOTSWITCH_GCT_DOWNLOAD 0x4E
1925 +/* triggers the NPE to reset internal status and enable the HssPacketized
1926 + operation for the flow specified by pPipe */
1927 +#define PKT_PIPE_FLOW_ENABLE 0x50
1928 +#define PKT_PIPE_FLOW_DISABLE 0x51
1929 +#define PKT_NUM_PIPES_WRITE 0x52
1930 +#define PKT_PIPE_FIFO_SIZEW_WRITE 0x53
1931 +#define PKT_PIPE_HDLC_CFG_WRITE 0x54
1932 +#define PKT_PIPE_IDLE_PATTERN_WRITE 0x55
1933 +#define PKT_PIPE_RX_SIZE_WRITE 0x56
1934 +#define PKT_PIPE_MODE_WRITE 0x57
1936 +/* HDLC packet status values - desc->status */
1937 +#define ERR_SHUTDOWN 1 /* stop or shutdown occurrance */
1938 +#define ERR_HDLC_ALIGN 2 /* HDLC alignment error */
1939 +#define ERR_HDLC_FCS 3 /* HDLC Frame Check Sum error */
1940 +#define ERR_RXFREE_Q_EMPTY 4 /* RX-free queue became empty while receiving
1941 + this packet (if buf_len < pkt_len) */
1942 +#define ERR_HDLC_TOO_LONG 5 /* HDLC frame size too long */
1943 +#define ERR_HDLC_ABORT 6 /* abort sequence received */
1944 +#define ERR_DISCONNECTING 7 /* disconnect is in progress */
1946 +#define CLOCK_EXT 0
1947 +#define CLOCK_INT 1
1949 +enum mode {MODE_HDLC = 0, MODE_RAW, MODE_G704};
1955 + CHAN_0 = (1 << 0),
1956 + CHAN_1 = (1 << 1),
1957 + CHAN_2 = (1 << 2),
1958 + CHAN_3 = (1 << 3),
1959 + CHAN_4 = (1 << 4),
1960 + CHAN_5 = (1 << 5),
1961 + CHAN_6 = (1 << 6),
1962 + CHAN_7 = (1 << 7),
1963 + CHAN_8 = (1 << 8),
1964 + CHAN_9 = (1 << 9),
1965 + CHAN_10 = (1 << 10),
1966 + CHAN_11 = (1 << 11),
1967 + CHAN_12 = (1 << 12),
1968 + CHAN_13 = (1 << 13),
1969 + CHAN_14 = (1 << 14),
1970 + CHAN_15 = (1 << 15)
1973 +enum alignment { NOT_ALIGNED = 0, EVEN_FIRST, ODD_FIRST };
1976 +typedef struct sk_buff buffer_t;
1977 +#define free_buffer dev_kfree_skb
1978 +#define free_buffer_irq dev_kfree_skb_irq
1980 +typedef void buffer_t;
1981 +#define free_buffer kfree
1982 +#define free_buffer_irq kfree
1985 +struct hss_device {
1986 + struct port *port;
1987 + unsigned int open_count, excl_open;
1988 + unsigned long tx_loc, rx_loc; /* bytes */
1989 + unsigned long tx_frame, rx_frame; /* Frames */
1990 + u8 id, chan_count;
1991 + u8 log_channels[MAX_CHANNELS];
1996 + size_t rx_buffer_size;
1997 + size_t rx_period_size;
1998 + size_t tx_buffer_size;
1999 + size_t tx_period_size;
2001 + void (*rx_callback)(void *data);
2003 + void (*tx_callback)(void *data);
2005 + void *private_data;
2008 +extern struct hss_device *hss_handle[32];
2009 +extern struct port *hss_port[2];
2012 + unsigned char init;
2014 + struct device *dev;
2016 + struct tasklet_struct task;
2018 + unsigned long chan_rx_bitmap;
2019 + unsigned long chan_tx_bitmap;
2020 + unsigned char chan_open;
2022 + /* the following fields must be protected by npe_lock */
2024 + unsigned int clock_type, clock_rate, loopback;
2025 + unsigned int frame_size, frame_sync_offset;
2026 + unsigned int next_rx_frame;
2028 + struct hss_device *chan_devices[MAX_CHAN_DEVICES];
2029 + u32 chan_tx_buf_phys, chan_rx_buf_phys;
2030 + u32 chan_tx_pointers_phys;
2031 + u32 *chan_tx_pointers;
2034 + u8 *tx_lists[CHAN_TX_LISTS][8];
2035 + u8 *rx_frames[8][CHAN_TX_LISTS];
2036 + unsigned int chan_open_count, hdlc_open;
2037 + unsigned int chan_started, initialized, just_set_offset;
2038 + unsigned int chan_last_rx, chan_last_tx;
2040 + /* assigned channels, may be invalid with given frame length or mode */
2041 + u8 channels[MAX_CHANNELS];
2045 +/* NPE message structure */
2048 + u8 cmd, unused, hss_port, index;
2050 + struct { u8 data8a, data8b, data8c, data8d; };
2051 + struct { u16 data16a, data16b; };
2052 + struct { u32 data32; };
2055 + u8 index, hss_port, unused, cmd;
2057 + struct { u8 data8d, data8c, data8b, data8a; };
2058 + struct { u16 data16b, data16a; };
2059 + struct { u32 data32; };
2064 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
2065 + (n) * sizeof(struct desc))
2066 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
2068 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
2069 + ((n) + RX_DESCS) * sizeof(struct desc))
2070 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
2072 +int hss_prepare_chan(struct port *port);
2073 +void hss_chan_stop(struct port *port);
2075 +struct hss_device *hss_init(int id, int channel);
2076 +int hss_chan_open(struct hss_device *hdev);
2077 +int hss_chan_close(struct hss_device *hdev);
2079 +int hss_set_tx_callback(struct hss_device *hdev, void (*tx_callback)(void *), void *tx_data);
2080 +int hss_set_rx_callback(struct hss_device *hdev, void (*rx_callback)(void *), void *rx_data);
2081 +int hss_tx_start(struct hss_device *hdev);
2082 +int hss_tx_stop(struct hss_device *hdev);
2083 +int hss_rx_start(struct hss_device *hdev);
2084 +int hss_rx_stop(struct hss_device *hdev);
2086 +int hss_config_rx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size);
2087 +int hss_config_tx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size);
2088 +unsigned long hss_curr_offset_rx(struct hss_device *hdev);
2089 +unsigned long hss_curr_offset_tx(struct hss_device *hdev);