1 --- a/sound/soc/Kconfig
2 +++ b/sound/soc/Kconfig
3 @@ -46,6 +46,7 @@ source "sound/soc/cirrus/Kconfig"
4 source "sound/soc/davinci/Kconfig"
5 source "sound/soc/dwc/Kconfig"
6 source "sound/soc/fsl/Kconfig"
7 +source "sound/soc/gw-avila/Kconfig"
8 source "sound/soc/jz4740/Kconfig"
9 source "sound/soc/nuc900/Kconfig"
10 source "sound/soc/omap/Kconfig"
11 --- a/sound/soc/Makefile
12 +++ b/sound/soc/Makefile
13 @@ -26,6 +26,7 @@ obj-$(CONFIG_SND_SOC) += cirrus/
14 obj-$(CONFIG_SND_SOC) += davinci/
15 obj-$(CONFIG_SND_SOC) += dwc/
16 obj-$(CONFIG_SND_SOC) += fsl/
17 +obj-$(CONFIG_SND_SOC) += gw-avila/
18 obj-$(CONFIG_SND_SOC) += jz4740/
19 obj-$(CONFIG_SND_SOC) += intel/
20 obj-$(CONFIG_SND_SOC) += mediatek/
22 +++ b/sound/soc/gw-avila/Kconfig
24 +config SND_GW_AVILA_SOC_PCM
27 +config SND_GW_AVILA_SOC_HSS
30 +config SND_GW_AVILA_SOC
31 + tristate "SoC Audio for the Gateworks AVILA Family"
32 + depends on ARCH_IXP4XX && SND_SOC
33 + select SND_GW_AVILA_SOC_PCM
34 + select SND_GW_AVILA_SOC_HSS
35 + select SND_SOC_TLV320AIC3X
37 + Say Y or M if you want to add support for codecs attached to
38 + the Gateworks HSS interface. You will also need
39 + to select the audio interfaces to support below.
42 +++ b/sound/soc/gw-avila/Makefile
44 +# Gateworks Avila HSS Platform Support
45 +snd-soc-gw-avila-objs := gw-avila.o ixp4xx_hss.o
46 +snd-soc-gw-avila-pcm-objs := gw-avila-pcm.o
47 +snd-soc-gw-avila-hss-objs := gw-avila-hss.o
49 +obj-$(CONFIG_SND_GW_AVILA_SOC) += snd-soc-gw-avila.o
50 +obj-$(CONFIG_SND_GW_AVILA_SOC_PCM) += snd-soc-gw-avila-pcm.o
51 +obj-$(CONFIG_SND_GW_AVILA_SOC_HSS) += snd-soc-gw-avila-hss.o
53 +++ b/sound/soc/gw-avila/gw-avila-hss.c
56 + * gw-avila-hss.c -- HSS Audio Support for Gateworks Avila
58 + * Author: Chris Lang <clang@gateworks.com>
60 + * This program is free software; you can redistribute it and/or modify
61 + * it under the terms of the GNU General Public License version 2 as
62 + * published by the Free Software Foundation.
65 +#include <linux/init.h>
66 +#include <linux/module.h>
67 +#include <linux/platform_device.h>
68 +#include <linux/interrupt.h>
69 +#include <linux/wait.h>
70 +#include <linux/delay.h>
72 +#include <sound/core.h>
73 +#include <sound/pcm.h>
74 +#include <sound/ac97_codec.h>
75 +#include <sound/initval.h>
76 +#include <sound/soc.h>
79 +#include <linux/mutex.h>
80 +#include <linux/gpio.h>
82 +#include "ixp4xx_hss.h"
83 +#include "gw-avila-hss.h"
85 +#define gw_avila_hss_suspend NULL
86 +#define gw_avila_hss_resume NULL
88 +struct snd_soc_dai_driver gw_avila_hss_dai = {
92 + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
93 + SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
94 + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
95 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
96 + SNDRV_PCM_RATE_KNOT),
97 + .formats = SNDRV_PCM_FMTBIT_S16_LE, },
101 + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
102 + SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
103 + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
104 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
105 + SNDRV_PCM_RATE_KNOT),
106 + .formats = SNDRV_PCM_FMTBIT_S16_LE, },
109 +static const struct snd_soc_component_driver gw_avila_hss_component = {
110 + .name = "gw_avila_hss",
113 +static int gw_avila_hss_probe(struct platform_device *pdev)
115 + int port = (pdev->id < 2) ? 0 : 1;
116 + int channel = (pdev->id % 2);
118 + hss_handle[pdev->id] = hss_init(port, channel);
119 + if (!hss_handle[pdev->id]) {
123 + return snd_soc_register_component(&pdev->dev, &gw_avila_hss_component,
124 + &gw_avila_hss_dai, 1);
127 +static int gw_avila_hss_remove(struct platform_device *pdev)
129 + snd_soc_unregister_component(&pdev->dev);
134 +static struct platform_driver gw_avila_hss_driver = {
135 + .probe = gw_avila_hss_probe,
136 + .remove = gw_avila_hss_remove,
138 + .name = "gw_avila_hss",
139 + .owner = THIS_MODULE,
143 +static int __init gw_avila_hss_init(void)
145 + return platform_driver_register(&gw_avila_hss_driver);
147 +module_init(gw_avila_hss_init);
149 +static void __exit gw_avila_hss_exit(void)
151 + platform_driver_unregister(&gw_avila_hss_driver);
153 +module_exit(gw_avila_hss_exit);
155 +MODULE_AUTHOR("Chris Lang");
156 +MODULE_DESCRIPTION("HSS Audio Driver for Gateworks Avila");
157 +MODULE_LICENSE("GPL");
159 +++ b/sound/soc/gw-avila/gw-avila-hss.h
162 + * Author: Chris Lang <clang@gateworks.com>
164 + * This program is free software; you can redistribute it and/or modify
165 + * it under the terms of the GNU General Public License version 2 as
166 + * published by the Free Software Foundation.
169 +#ifndef _GW_AVILA_HSS_H
170 +#define _GW_AVILA_HSS_H
174 +++ b/sound/soc/gw-avila/gw-avila-pcm.c
177 + * ALSA PCM interface for the TI DAVINCI processor
179 + * Author: Chris Lang, <clang@gateworks.com>
180 + * Copyright: (C) 2009 Gateworks Corporation
182 + * Based On: davinci-evm.c, Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
184 + * This program is free software; you can redistribute it and/or modify
185 + * it under the terms of the GNU General Public License version 2 as
186 + * published by the Free Software Foundation.
189 +#include <linux/module.h>
190 +#include <linux/init.h>
191 +#include <linux/platform_device.h>
192 +#include <linux/slab.h>
193 +#include <linux/dma-mapping.h>
195 +#include <sound/core.h>
196 +#include <sound/pcm.h>
197 +#include <sound/pcm_params.h>
198 +#include <sound/soc.h>
200 +#include <asm/dma.h>
202 +#include "gw-avila-pcm.h"
203 +#include "gw-avila-hss.h"
204 +#include "ixp4xx_hss.h"
206 +#define GW_AVILA_PCM_DEBUG 0
207 +#if GW_AVILA_PCM_DEBUG
208 +#define DPRINTK(x...) printk(KERN_DEBUG x)
210 +#define DPRINTK(x...)
213 +static struct snd_pcm_hardware gw_avila_pcm_hardware = {
214 + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
215 + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
216 +/* SNDRV_PCM_INFO_PAUSE),*/
217 + .formats = (SNDRV_PCM_FMTBIT_S16_LE),
218 + .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
219 + SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
220 + SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
221 + SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
222 + SNDRV_PCM_RATE_KNOT),
227 + .buffer_bytes_max = 64 * 1024, // All of the lines below may need to be changed
228 + .period_bytes_min = 128,
229 + .period_bytes_max = 4 * 1024,
235 +struct gw_avila_runtime_data {
237 + int period; /* current DMA period */
238 + int master_lch; /* Master DMA channel */
239 + int slave_lch; /* Slave DMA channel */
240 + struct gw_avila_pcm_dma_params *params; /* DMA params */
243 +static void gw_avila_dma_irq(void *data)
245 + struct snd_pcm_substream *substream = data;
246 + snd_pcm_period_elapsed(substream);
249 +static int gw_avila_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
251 + struct snd_pcm_runtime *runtime = substream->runtime;
252 + struct hss_device *hdev = runtime->private_data;
256 + case SNDRV_PCM_TRIGGER_START:
257 + case SNDRV_PCM_TRIGGER_RESUME:
258 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
259 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
260 + hss_tx_start(hdev);
262 + hss_rx_start(hdev);
264 + case SNDRV_PCM_TRIGGER_STOP:
265 + case SNDRV_PCM_TRIGGER_SUSPEND:
266 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
267 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
279 +static int gw_avila_pcm_prepare(struct snd_pcm_substream *substream)
281 + struct snd_pcm_runtime *runtime = substream->runtime;
282 + struct hss_device *hdev = runtime->private_data;
284 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
285 + hss_set_tx_callback(hdev, gw_avila_dma_irq, substream);
286 + hss_config_tx_dma(hdev, runtime->dma_area, runtime->buffer_size, runtime->period_size);
288 + hss_set_rx_callback(hdev, gw_avila_dma_irq, substream);
289 + hss_config_rx_dma(hdev, runtime->dma_area, runtime->buffer_size, runtime->period_size);
295 +static snd_pcm_uframes_t
296 +gw_avila_pcm_pointer(struct snd_pcm_substream *substream)
298 + struct snd_pcm_runtime *runtime = substream->runtime;
299 + struct hss_device *hdev = runtime->private_data;
301 + unsigned int curr = 0;
302 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
303 + curr = hss_curr_offset_tx(hdev);
305 + curr = hss_curr_offset_rx(hdev);
309 +static int gw_avila_pcm_open(struct snd_pcm_substream *substream)
311 + struct snd_pcm_runtime *runtime = substream->runtime;
312 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
313 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
315 + snd_soc_set_runtime_hwparams(substream, &gw_avila_pcm_hardware);
317 + if (hss_handle[cpu_dai->id] != NULL)
318 + runtime->private_data = hss_handle[cpu_dai->id];
320 + pr_err("hss_handle is NULL\n");
324 + hss_chan_open(hss_handle[cpu_dai->id]);
329 +static int gw_avila_pcm_close(struct snd_pcm_substream *substream)
331 + struct snd_pcm_runtime *runtime = substream->runtime;
332 + struct hss_device *hdev = runtime->private_data;
334 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
335 + memset(hdev->tx_buf, 0, runtime->buffer_size);
337 + memset(hdev->rx_buf, 0, runtime->buffer_size);
339 + hss_chan_close(hdev);
344 +static int gw_avila_pcm_hw_params(struct snd_pcm_substream *substream,
345 + struct snd_pcm_hw_params *hw_params)
347 + return snd_pcm_lib_malloc_pages(substream,
348 + params_buffer_bytes(hw_params));
351 +static int gw_avila_pcm_hw_free(struct snd_pcm_substream *substream)
353 + struct snd_pcm_runtime *runtime = substream->runtime;
355 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
356 + memset(runtime->dma_area, 0, runtime->buffer_size);
358 + return snd_pcm_lib_free_pages(substream);
361 +static int gw_avila_pcm_mmap(struct snd_pcm_substream *substream,
362 + struct vm_area_struct *vma)
364 + struct snd_pcm_runtime *runtime = substream->runtime;
366 + return dma_mmap_writecombine(substream->pcm->card->dev, vma,
369 + runtime->dma_bytes);
372 +struct snd_pcm_ops gw_avila_pcm_ops = {
373 + .open = gw_avila_pcm_open,
374 + .close = gw_avila_pcm_close,
375 + .ioctl = snd_pcm_lib_ioctl,
376 + .hw_params = gw_avila_pcm_hw_params,
377 + .hw_free = gw_avila_pcm_hw_free,
378 + .prepare = gw_avila_pcm_prepare,
379 + .trigger = gw_avila_pcm_trigger,
380 + .pointer = gw_avila_pcm_pointer,
381 + .mmap = gw_avila_pcm_mmap,
384 +static int gw_avila_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
386 + struct snd_pcm_substream *substream = pcm->streams[stream].substream;
387 + struct snd_dma_buffer *buf = &substream->dma_buffer;
388 + size_t size = gw_avila_pcm_hardware.buffer_bytes_max;
390 + buf->dev.type = SNDRV_DMA_TYPE_DEV;
391 + buf->dev.dev = pcm->card->dev;
392 + buf->private_data = NULL;
394 + buf->area = dma_alloc_coherent(pcm->card->dev, size,
395 + &buf->addr, GFP_KERNEL);
401 + memset(buf->area, 0xff, size);
403 + DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n",
404 + (void *) buf->area, (void *) buf->addr, size);
411 +static void gw_avila_pcm_free(struct snd_pcm *pcm)
413 + struct snd_pcm_substream *substream;
414 + struct snd_dma_buffer *buf;
417 + for (stream = 0; stream < 2; stream++) {
418 + substream = pcm->streams[stream].substream;
422 + buf = &substream->dma_buffer;
426 + dma_free_coherent(NULL, buf->bytes, buf->area, 0);
431 +static u64 gw_avila_pcm_dmamask = 0xFFFFFFFF;
433 +static int gw_avila_pcm_new(struct snd_soc_pcm_runtime *rtd)
435 + struct snd_card *card = rtd->card->snd_card;
436 + struct snd_pcm *pcm = rtd->pcm;
437 + struct snd_soc_dai *dai = rtd->codec_dai;
440 + if (!card->dev->dma_mask)
441 + card->dev->dma_mask = &gw_avila_pcm_dmamask;
442 + if (!card->dev->coherent_dma_mask)
443 + card->dev->coherent_dma_mask = 0xFFFFFFFF;
445 + if (dai->driver->playback.channels_min) {
446 + ret = gw_avila_pcm_preallocate_dma_buffer(pcm,
447 + SNDRV_PCM_STREAM_PLAYBACK);
452 + if (dai->driver->capture.channels_min) {
453 + ret = gw_avila_pcm_preallocate_dma_buffer(pcm,
454 + SNDRV_PCM_STREAM_CAPTURE);
462 +struct snd_soc_platform_driver gw_avila_soc_platform = {
463 + .ops = &gw_avila_pcm_ops,
464 + .pcm_new = gw_avila_pcm_new,
465 + .pcm_free = gw_avila_pcm_free,
468 +static int gw_avila_pcm_platform_probe(struct platform_device *pdev)
470 + return snd_soc_register_platform(&pdev->dev, &gw_avila_soc_platform);
473 +static int gw_avila_pcm_platform_remove(struct platform_device *pdev)
475 + snd_soc_unregister_platform(&pdev->dev);
479 +static struct platform_driver gw_avila_pcm_driver = {
481 + .name = "gw_avila-audio",
482 + .owner = THIS_MODULE,
484 + .probe = gw_avila_pcm_platform_probe,
485 + .remove = gw_avila_pcm_platform_remove,
488 +static int __init gw_avila_soc_platform_init(void)
490 + return platform_driver_register(&gw_avila_pcm_driver);
492 +module_init(gw_avila_soc_platform_init);
494 +static void __exit gw_avila_soc_platform_exit(void)
496 + platform_driver_unregister(&gw_avila_pcm_driver);
498 +module_exit(gw_avila_soc_platform_exit);
500 +MODULE_AUTHOR("Chris Lang");
501 +MODULE_DESCRIPTION("Gateworks Avila PCM DMA module");
502 +MODULE_LICENSE("GPL");
504 +++ b/sound/soc/gw-avila/gw-avila-pcm.h
507 + * ALSA PCM interface for the Gateworks Avila platform
509 + * Author: Chris Lang, <clang@gateworks.com>
510 + * Copyright: (C) 2009 Gateworks Corporation
512 + * Based On: davinci-evm.c, Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
514 + * This program is free software; you can redistribute it and/or modify
515 + * it under the terms of the GNU General Public License version 2 as
516 + * published by the Free Software Foundation.
519 +#ifndef _GW_AVILA_PCM_H
520 +#define _GW_AVILA_PCM_H
523 +struct gw_avila_pcm_dma_params {
524 + char *name; /* stream identifier */
525 + int channel; /* sync dma channel ID */
526 + dma_addr_t dma_addr; /* device physical address for DMA */
527 + unsigned int data_type; /* xfer data type */
530 +struct gw_avila_snd_platform_data {
531 + int tx_dma_ch; // XXX Do we need this?
532 + int rx_dma_ch; // XXX Do we need this
534 +extern struct snd_soc_platform gw_avila_soc_platform[];
539 +++ b/sound/soc/gw-avila/gw-avila.c
542 + * File: sound/soc/gw-avila/gw_avila.c
543 + * Author: Chris Lang <clang@gateworks.com>
545 + * Created: Tue June 06 2008
546 + * Description: Board driver for Gateworks Avila
549 + * Copyright 2009 Gateworks Corporation
553 + * This program is free software; you can redistribute it and/or modify
554 + * it under the terms of the GNU General Public License as published by
555 + * the Free Software Foundation; either version 2 of the License, or
556 + * (at your option) any later version.
558 + * This program is distributed in the hope that it will be useful,
559 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
560 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
561 + * GNU General Public License for more details.
563 + * You should have received a copy of the GNU General Public License
564 + * along with this program; if not, see the file COPYING, or write
565 + * to the Free Software Foundation, Inc.,
566 + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
569 +#include <linux/module.h>
570 +#include <linux/moduleparam.h>
571 +#include <linux/device.h>
572 +#include <asm/dma.h>
573 +#include <linux/platform_device.h>
574 +#include <sound/core.h>
575 +#include <sound/pcm.h>
576 +#include <sound/soc.h>
577 +#include <linux/slab.h>
578 +#include <linux/gpio.h>
580 +#include "ixp4xx_hss.h"
581 +#include "gw-avila-hss.h"
582 +#include "gw-avila-pcm.h"
584 +#define CODEC_FREQ 33333000
586 +static int gw_avila_board_startup(struct snd_pcm_substream *substream)
588 + pr_debug("%s enter\n", __func__);
592 +static int gw_avila_hw_params(struct snd_pcm_substream *substream,
593 + struct snd_pcm_hw_params *params)
595 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
596 + struct snd_soc_dai *codec_dai = rtd->codec_dai;
597 + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
601 + /* set codec DAI configuration */
602 + if (cpu_dai->id % 2) {
603 + ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBS_CFS);
604 + snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 1, 32);
606 + ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | SND_SOC_DAIFMT_CBM_CFM);
607 + snd_soc_dai_set_tdm_slot(codec_dai, 0, 0, 0, 32);
613 + /* set the codec system clock */
614 + ret = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_FREQ, SND_SOC_CLOCK_OUT);
621 +static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
622 + SND_SOC_DAPM_HP("Headphone Jack", NULL),
623 + SND_SOC_DAPM_LINE("Line Out", NULL),
624 + SND_SOC_DAPM_LINE("Line In", NULL),
627 +static const struct snd_soc_dapm_route audio_map[] = {
628 + {"Headphone Jack", NULL, "HPLOUT"},
629 + {"Headphone Jack", NULL, "HPROUT"},
631 + /* Line Out connected to LLOUT, RLOUT */
632 + {"Line Out", NULL, "LLOUT"},
633 + {"Line Out", NULL, "RLOUT"},
635 + /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
636 + {"LINE1L", NULL, "Line In"},
637 + {"LINE1R", NULL, "Line In"},
640 +/* Logic for a aic3x as connected on a davinci-evm */
641 +static int avila_aic3x_init(struct snd_soc_pcm_runtime *rtd)
643 + struct snd_soc_codec *codec = rtd->codec;
644 + struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
646 + /* Add davinci-evm specific widgets */
647 + snd_soc_dapm_new_controls(dapm, aic3x_dapm_widgets,
648 + ARRAY_SIZE(aic3x_dapm_widgets));
650 + /* Set up davinci-evm specific audio path audio_map */
651 + snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
653 + /* not connected */
654 + snd_soc_dapm_disable_pin(dapm, "MONO_LOUT");
655 + //snd_soc_dapm_disable_pin(dapm, "HPLCOM");
656 + //snd_soc_dapm_disable_pin(dapm, "HPRCOM");
657 + snd_soc_dapm_disable_pin(dapm, "MIC3L");
658 + snd_soc_dapm_disable_pin(dapm, "MIC3R");
659 + snd_soc_dapm_disable_pin(dapm, "LINE2L");
660 + snd_soc_dapm_disable_pin(dapm, "LINE2R");
662 + /* always connected */
663 + snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
664 + snd_soc_dapm_enable_pin(dapm, "Line Out");
665 + snd_soc_dapm_enable_pin(dapm, "Line In");
667 + snd_soc_dapm_sync(dapm);
672 +static struct snd_soc_ops gw_avila_board_ops = {
673 + .startup = gw_avila_board_startup,
674 + .hw_params = gw_avila_hw_params,
677 +static struct snd_soc_dai_link gw_avila_board_dai[] = {
680 + .stream_name = "HSS-0",
681 + .cpu_dai_name = "gw_avila_hss.0",
682 + .codec_dai_name = "tlv320aic3x-hifi",
683 + .codec_name = "tlv320aic3x-codec.0-001b",
684 + .platform_name = "gw_avila-audio.0",
685 + .init = avila_aic3x_init,
686 + .ops = &gw_avila_board_ops,
689 + .stream_name = "HSS-1",
690 + .cpu_dai_name = "gw_avila_hss.1",
691 + .codec_dai_name = "tlv320aic3x-hifi",
692 + .codec_name = "tlv320aic3x-codec.0-001a",
693 + .platform_name = "gw_avila-audio.1",
694 + .init = avila_aic3x_init,
695 + .ops = &gw_avila_board_ops,
698 + .stream_name = "HSS-2",
699 + .cpu_dai_name = "gw_avila_hss.2",
700 + .codec_dai_name = "tlv320aic3x-hifi",
701 + .codec_name = "tlv320aic3x-codec.0-0019",
702 + .platform_name = "gw_avila-audio.2",
703 + .init = avila_aic3x_init,
704 + .ops = &gw_avila_board_ops,
707 + .stream_name = "HSS-3",
708 + .cpu_dai_name = "gw_avila_hss.3",
709 + .codec_dai_name = "tlv320aic3x-hifi",
710 + .codec_name = "tlv320aic3x-codec.0-0018",
711 + .platform_name = "gw_avila-audio.3",
712 + .init = avila_aic3x_init,
713 + .ops = &gw_avila_board_ops,
717 +static struct snd_soc_card gw_avila_board[] = {
719 + .name = "gw_avila-board.0",
720 + .owner = THIS_MODULE,
721 + .dai_link = &gw_avila_board_dai[0],
724 + .name = "gw_avila-board.1",
725 + .owner = THIS_MODULE,
726 + .dai_link = &gw_avila_board_dai[1],
729 + .name = "gw_avila-board.2",
730 + .owner = THIS_MODULE,
731 + .dai_link = &gw_avila_board_dai[2],
734 + .name = "gw_avila-board.3",
735 + .owner = THIS_MODULE,
736 + .dai_link = &gw_avila_board_dai[3],
741 +static struct platform_device *gw_avila_board_snd_device[4];
743 +static int __init gw_avila_board_init(void)
749 + if ((hss_port[0] = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
752 + if ((hss_port[1] = kzalloc(sizeof(*port), GFP_KERNEL)) == NULL)
755 + for (i = 0; i < 4; i++) {
756 + gw_avila_board_snd_device[i] = platform_device_alloc("soc-audio", i);
757 + if (!gw_avila_board_snd_device[i]) {
761 + platform_set_drvdata(gw_avila_board_snd_device[i], &gw_avila_board[i]);
762 + ret = platform_device_add(gw_avila_board_snd_device[i]);
765 + platform_device_put(gw_avila_board_snd_device[i]);
771 +static void __exit gw_avila_board_exit(void)
774 + for (i = 0; i < 4; i++)
775 + platform_device_unregister(gw_avila_board_snd_device[i]);
778 +module_init(gw_avila_board_init);
779 +module_exit(gw_avila_board_exit);
781 +/* Module information */
782 +MODULE_AUTHOR("Chris Lang");
783 +MODULE_DESCRIPTION("ALSA SoC HSS Audio gw_avila board");
784 +MODULE_LICENSE("GPL");
786 +++ b/sound/soc/gw-avila/ixp4xx_hss.c
789 + * Intel IXP4xx HSS (synchronous serial port) driver for Linux
791 + * Copyright (C) 2009 Chris Lang <clang@gateworks.com>
793 + * This program is free software; you can redistribute it and/or modify it
794 + * under the terms of version 2 of the GNU General Public License
795 + * as published by the Free Software Foundation.
798 +#include <linux/module.h>
799 +#include <linux/bitops.h>
800 +#include <linux/cdev.h>
801 +#include <linux/dma-mapping.h>
802 +#include <linux/dmapool.h>
803 +#include <linux/fs.h>
804 +#include <linux/io.h>
805 +#include <linux/kernel.h>
806 +#include <linux/platform_device.h>
807 +#include <linux/poll.h>
808 +#include <linux/slab.h>
809 +#include <linux/delay.h>
811 +#include <mach/npe.h>
812 +#include <mach/qmgr.h>
814 +#include "ixp4xx_hss.h"
816 +/*****************************************************************************
818 + ****************************************************************************/
820 +void hss_chan_read(unsigned long data);
821 +static char lock_init = 0;
822 +static spinlock_t npe_lock;
823 +static struct npe *npe;
825 +static const struct {
826 + int tx, txdone, rx, rxfree, chan;
827 +}queue_ids[2] = {{HSS0_PKT_TX0_QUEUE, HSS0_PKT_TXDONE_QUEUE, HSS0_PKT_RX_QUEUE,
828 + HSS0_PKT_RXFREE0_QUEUE, HSS0_CHL_RXTRIG_QUEUE},
829 + {HSS1_PKT_TX0_QUEUE, HSS1_PKT_TXDONE_QUEUE, HSS1_PKT_RX_QUEUE,
830 + HSS1_PKT_RXFREE0_QUEUE, HSS1_CHL_RXTRIG_QUEUE},
833 +struct port *hss_port[2];
834 +struct hss_device *hss_handle[32];
835 +EXPORT_SYMBOL(hss_handle);
837 +/*****************************************************************************
838 + * utility functions
839 + ****************************************************************************/
842 +static inline void memcpy_swab32(u32 *dest, u32 *src, int cnt)
845 + for (i = 0; i < cnt; i++)
846 + dest[i] = swab32(src[i]);
850 +static inline unsigned int sub_offset(unsigned int a, unsigned int b,
851 + unsigned int modulo)
853 + return (modulo /* make sure the result >= 0 */ + a - b) % modulo;
856 +/*****************************************************************************
858 + ****************************************************************************/
860 +static void hss_config_load(struct port *port)
865 + memset(&msg, 0, sizeof(msg));
866 + msg.cmd = PORT_CONFIG_LOAD;
867 + msg.hss_port = port->id;
868 + if (npe_send_message(npe, &msg, "HSS_LOAD_CONFIG"))
870 + if (npe_recv_message(npe, &msg, "HSS_LOAD_CONFIG"))
873 + /* HSS_LOAD_CONFIG for port #1 returns port_id = #4 */
874 + if (msg.cmd != PORT_CONFIG_LOAD || msg.data32)
877 + /* HDLC may stop working without this */
878 + npe_recv_message(npe, &msg, "FLUSH_IT");
882 + printk(KERN_CRIT "HSS-%i: unable to reload HSS configuration\n",
887 +static void hss_config_set_pcr(struct port *port)
892 + memset(&msg, 0, sizeof(msg));
893 + msg.cmd = PORT_CONFIG_WRITE;
894 + msg.hss_port = port->id;
895 + msg.index = HSS_CONFIG_TX_PCR;
897 + msg.data32 = PCR_FRM_SYNC_RISINGEDGE | PCR_MSB_ENDIAN |
898 + PCR_TX_DATA_ENABLE | PCR_TX_UNASS_HIGH_IMP | PCR_TX_V56K_HIGH_IMP | PCR_TX_FB_HIGH_IMP;
900 + msg.data32 = PCR_FRM_SYNC_RISINGEDGE | PCR_MSB_ENDIAN |
901 + PCR_TX_DATA_ENABLE | PCR_TX_FB_HIGH_IMP | PCR_DCLK_EDGE_RISING;
903 + if (port->frame_size % 8 == 0)
904 + msg.data32 |= PCR_SOF_NO_FBIT;
906 + if (npe_send_message(npe, &msg, "HSS_SET_TX_PCR"))
909 + msg.index = HSS_CONFIG_RX_PCR;
910 + msg.data32 &= ~ (PCR_DCLK_EDGE_RISING | PCR_FCLK_EDGE_RISING | PCR_TX_DATA_ENABLE);
912 + if (npe_send_message(npe, &msg, "HSS_SET_RX_PCR"))
917 + printk(KERN_CRIT "HSS-%i: unable to set HSS PCR registers\n", port->id);
921 +static void hss_config_set_core(struct port *port)
925 + memset(&msg, 0, sizeof(msg));
926 + msg.cmd = PORT_CONFIG_WRITE;
927 + msg.hss_port = port->id;
928 + msg.index = HSS_CONFIG_CORE_CR;
930 + msg.data32 = 0 | CCR_LOOPBACK |
931 + (port->id ? CCR_SECOND_HSS : 0);
934 + (port->id ? CCR_SECOND_HSS : 0);
936 + if (npe_send_message(npe, &msg, "HSS_SET_CORE_CR")) {
937 + printk(KERN_CRIT "HSS-%i: unable to set HSS core control"
938 + " register\n", port->id);
943 +static void hss_config_set_line(struct port *port)
947 + hss_config_set_pcr(port);
948 + hss_config_set_core(port);
950 + memset(&msg, 0, sizeof(msg));
951 + msg.cmd = PORT_CONFIG_WRITE;
952 + msg.hss_port = port->id;
953 + msg.index = HSS_CONFIG_CLOCK_CR;
954 + msg.data32 = CLK42X_SPEED_8192KHZ /* FIXME */;
955 + if (npe_send_message(npe, &msg, "HSS_SET_CLOCK_CR")) {
956 + printk(KERN_CRIT "HSS-%i: unable to set HSS clock control"
957 + " register\n", port->id);
962 +static void hss_config_set_rx_frame(struct port *port)
966 + memset(&msg, 0, sizeof(msg));
967 + msg.cmd = PORT_CONFIG_WRITE;
968 + msg.hss_port = port->id;
969 + msg.index = HSS_CONFIG_RX_FCR;
970 + msg.data16a = port->frame_sync_offset;
971 + msg.data16b = port->frame_size - 1;
972 + if (npe_send_message(npe, &msg, "HSS_SET_RX_FCR")) {
973 + printk(KERN_CRIT "HSS-%i: unable to set HSS RX frame size"
974 + " and offset\n", port->id);
979 +static void hss_config_set_frame(struct port *port)
983 + memset(&msg, 0, sizeof(msg));
984 + msg.cmd = PORT_CONFIG_WRITE;
985 + msg.hss_port = port->id;
986 + msg.index = HSS_CONFIG_TX_FCR;
987 + msg.data16a = TX_FRAME_SYNC_OFFSET;
988 + msg.data16b = port->frame_size - 1;
989 + if (npe_send_message(npe, &msg, "HSS_SET_TX_FCR")) {
990 + printk(KERN_CRIT "HSS-%i: unable to set HSS TX frame size"
991 + " and offset\n", port->id);
994 + hss_config_set_rx_frame(port);
997 +static void hss_config_set_lut(struct port *port)
1000 + int chan_count = 32;
1002 + memset(&msg, 0, sizeof(msg));
1003 + msg.cmd = PORT_CONFIG_WRITE;
1004 + msg.hss_port = port->id;
1006 + msg.index = HSS_CONFIG_TX_LUT;
1007 + msg.data32 = 0xffffffff;
1008 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1010 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1013 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1015 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1017 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1019 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1021 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1023 + npe_send_message(npe, &msg, "HSS_SET_TX_LUT");
1025 + msg.index = HSS_CONFIG_RX_LUT;
1026 + msg.data32 = 0xffffffff;
1027 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1029 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1032 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1034 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1036 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1038 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1040 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1042 + npe_send_message(npe, &msg, "HSS_SET_RX_LUT");
1044 + hss_config_set_frame(port);
1046 + memset(&msg, 0, sizeof(msg));
1047 + msg.cmd = CHAN_NUM_CHANS_WRITE;
1048 + msg.hss_port = port->id;
1049 + msg.data8a = chan_count;
1050 + if (npe_send_message(npe, &msg, "CHAN_NUM_CHANS_WRITE")) {
1051 + printk(KERN_CRIT "HSS-%i: unable to set HSS channel count\n",
1057 +static u32 hss_config_get_status(struct port *port)
1062 + memset(&msg, 0, sizeof(msg));
1063 + msg.cmd = PORT_ERROR_READ;
1064 + msg.hss_port = port->id;
1065 + if (npe_send_message(npe, &msg, "PORT_ERROR_READ"))
1067 + if (npe_recv_message(npe, &msg, "PORT_ERROR_READ"))
1070 + return msg.data32;
1073 + printk(KERN_CRIT "HSS-%i: unable to read HSS status\n", port->id);
1077 +static void hss_config_start_chan(struct port *port)
1081 + port->chan_last_tx = 0;
1082 + port->chan_last_rx = 0;
1085 + memset(&msg, 0, sizeof(msg));
1086 + msg.cmd = CHAN_RX_BUF_ADDR_WRITE;
1087 + msg.hss_port = port->id;
1088 + msg.data32 = port->chan_rx_buf_phys;
1089 + if (npe_send_message(npe, &msg, "CHAN_RX_BUF_ADDR_WRITE"))
1092 + memset(&msg, 0, sizeof(msg));
1093 + msg.cmd = CHAN_TX_BUF_ADDR_WRITE;
1094 + msg.hss_port = port->id;
1095 + msg.data32 = port->chan_tx_pointers_phys;
1096 + if (npe_send_message(npe, &msg, "CHAN_TX_BUF_ADDR_WRITE"))
1099 + memset(&msg, 0, sizeof(msg));
1100 + msg.cmd = CHAN_FLOW_ENABLE;
1101 + msg.hss_port = port->id;
1102 + if (npe_send_message(npe, &msg, "CHAN_FLOW_ENABLE"))
1104 + port->chan_started = 1;
1108 + printk(KERN_CRIT "HSS-%i: unable to start channelized flow\n",
1113 +static void hss_config_stop_chan(struct port *port)
1117 + if (!port->chan_started)
1120 + memset(&msg, 0, sizeof(msg));
1121 + msg.cmd = CHAN_FLOW_DISABLE;
1122 + msg.hss_port = port->id;
1123 + if (npe_send_message(npe, &msg, "CHAN_FLOW_DISABLE")) {
1124 + printk(KERN_CRIT "HSS-%i: unable to stop channelized flow\n",
1128 + hss_config_get_status(port); /* make sure it's halted */
1129 + port->chan_started = 0;
1132 +static int hss_config_load_firmware(struct port *port)
1136 + if (port->initialized)
1139 + if (!npe_running(npe)) {
1141 + if ((err = npe_load_firmware(npe, "NPE-A-HSS",
1147 + /* HSS main configuration */
1148 + hss_config_set_line(port);
1150 + hss_config_set_frame(port);
1152 + /* Channelized operation settings */
1153 + memset(&msg, 0, sizeof(msg));
1154 + msg.cmd = CHAN_TX_BLK_CFG_WRITE;
1155 + msg.hss_port = port->id;
1156 + msg.data8b = (CHAN_TX_LIST_FRAMES & ~7) / 2;
1157 + msg.data8a = msg.data8b / 4;
1158 + msg.data8d = CHAN_TX_LIST_FRAMES - msg.data8b;
1159 + msg.data8c = msg.data8d / 4;
1160 + if (npe_send_message(npe, &msg, "CHAN_TX_BLK_CFG_WRITE"))
1163 + memset(&msg, 0, sizeof(msg));
1164 + msg.cmd = CHAN_RX_BUF_CFG_WRITE;
1165 + msg.hss_port = port->id;
1166 + msg.data8a = CHAN_RX_TRIGGER / 8;
1167 + msg.data8b = CHAN_RX_FRAMES;
1168 + if (npe_send_message(npe, &msg, "CHAN_RX_BUF_CFG_WRITE"))
1171 + memset(&msg, 0, sizeof(msg));
1172 + msg.cmd = CHAN_TX_BUF_SIZE_WRITE;
1173 + msg.hss_port = port->id;
1174 + msg.data8a = CHAN_TX_LISTS;
1175 + if (npe_send_message(npe, &msg, "CHAN_TX_BUF_SIZE_WRITE"))
1178 + port->initialized = 1;
1182 + printk(KERN_CRIT "HSS-%i: unable to start HSS operation\n", port->id);
1186 +void hss_chan_irq(void *pdev)
1188 + struct port *port = pdev;
1190 + qmgr_disable_irq(queue_ids[port->id].chan);
1192 + tasklet_hi_schedule(&port->task);
1196 +int hss_prepare_chan(struct port *port)
1203 + if (port->initialized)
1206 + if ((err = hss_config_load_firmware(port)))
1209 + if ((err = qmgr_request_queue(queue_ids[port->id].chan,
1210 + CHAN_QUEUE_LEN, 0, 0, "%s:hss", "hss")))
1213 + port->chan_tx_buf = dma_alloc_coherent(port->dev, chan_tx_buf_len(port), &port->chan_tx_buf_phys, GFP_DMA);
1214 + memset(port->chan_tx_buf, 0, chan_tx_buf_len(port));
1216 + 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);
1218 + temp3 = port->chan_tx_buf;
1219 + for (i = 0; i < CHAN_TX_LISTS; i++) {
1220 + for (j = 0; j < 8; j++) {
1221 + port->tx_lists[i][j] = temp3;
1222 + temp3 += CHAN_TX_LIST_FRAMES * 4;
1226 + temp = port->chan_tx_pointers;
1227 + temp2 = port->chan_tx_buf_phys;
1228 + for (i = 0; i < CHAN_TX_LISTS; i++)
1230 + for (j = 0; j < 32; j++)
1233 + temp2 += CHAN_TX_LIST_FRAMES;
1238 + port->chan_rx_buf = dma_alloc_coherent(port->dev, chan_rx_buf_len(port), &port->chan_rx_buf_phys, GFP_DMA);
1240 + for (i = 0; i < 8; i++) {
1241 + temp3 = port->chan_rx_buf + (i * 4 * 128);
1242 + for (j = 0; j < 8; j++) {
1243 + port->rx_frames[i][j] = temp3;
1244 + temp3 += CHAN_RX_TRIGGER;
1248 + qmgr_set_irq(queue_ids[port->id].chan, QUEUE_IRQ_SRC_NOT_EMPTY,
1249 + hss_chan_irq, port);
1255 +int hss_tx_start(struct hss_device *hdev)
1257 + unsigned long flags;
1258 + struct port *port = hdev->port;
1261 + hdev->tx_frame = 0;
1263 + set_bit((1 << hdev->id), &port->chan_tx_bitmap);
1265 + if (!port->chan_started)
1267 + qmgr_enable_irq(queue_ids[port->id].chan);
1268 + spin_lock_irqsave(&npe_lock, flags);
1269 + hss_config_start_chan(port);
1270 + spin_unlock_irqrestore(&npe_lock, flags);
1271 + hss_chan_irq(port);
1276 +EXPORT_SYMBOL(hss_tx_start);
1278 +int hss_rx_start(struct hss_device *hdev)
1280 + unsigned long flags;
1281 + struct port *port = hdev->port;
1284 + hdev->rx_frame = 0;
1286 + set_bit((1 << hdev->id), &port->chan_rx_bitmap);
1288 + if (!port->chan_started)
1290 + qmgr_enable_irq(queue_ids[port->id].chan);
1291 + spin_lock_irqsave(&npe_lock, flags);
1292 + hss_config_start_chan(port);
1293 + spin_unlock_irqrestore(&npe_lock, flags);
1294 + hss_chan_irq(port);
1299 +EXPORT_SYMBOL(hss_rx_start);
1301 +int hss_tx_stop(struct hss_device *hdev)
1303 + struct port *port = hdev->port;
1305 + clear_bit((1 << hdev->id), &port->chan_tx_bitmap);
1309 +EXPORT_SYMBOL(hss_tx_stop);
1311 +int hss_rx_stop(struct hss_device *hdev)
1313 + struct port *port = hdev->port;
1315 + clear_bit((1 << hdev->id), &port->chan_rx_bitmap);
1319 +EXPORT_SYMBOL(hss_rx_stop);
1321 +int hss_chan_open(struct hss_device *hdev)
1323 + struct port *port = hdev->port;
1326 + if (port->chan_open)
1329 + if (port->mode == MODE_HDLC) {
1334 + if (port->mode == MODE_G704 && port->channels[0] == hdev->id) {
1335 + err = -EBUSY; /* channel #0 is used for G.704 signaling */
1339 + for (i = MAX_CHANNELS; i > port->frame_size / 8; i--)
1340 + if (port->channels[i - 1] == hdev->id) {
1341 + err = -ECHRNG; /* frame too short */
1345 + hdev->rx_loc = hdev->tx_loc = 0;
1346 + hdev->rx_frame = hdev->tx_frame = 0;
1348 + //clear_bit((1 << hdev->id), &port->chan_rx_bitmap);
1349 + //clear_bit((1 << hdev->id), &port->chan_tx_bitmap);
1351 + if (!port->initialized) {
1352 + hss_prepare_chan(port);
1354 + hss_config_stop_chan(port);
1355 + hdev->open_count++;
1356 + port->chan_open_count++;
1358 + hss_config_set_lut(port);
1359 + hss_config_load(port);
1362 + port->chan_open = 1;
1367 +EXPORT_SYMBOL(hss_chan_open);
1369 +int hss_chan_close(struct hss_device *hdev)
1373 +EXPORT_SYMBOL(hss_chan_close);
1375 +void hss_chan_read(unsigned long data)
1377 + struct port *port = (void *)data;
1378 + struct hss_device *hdev;
1379 + u8 *hw_buf, *save_buf;
1382 + unsigned int tx_list, rx_frame;
1383 + int i, j, channel;
1387 + My Data in the hardware buffer is scattered by channels into 4 trunks
1390 + channel 0 channel 1 channel 2 channel 3
1391 +Trunk 1 = 0 -> 127 128 -> 255 256 -> 383 384 -> 512
1392 +Trunk 2 = 513 -> 639 640 -> 768 769 -> 895 896 -> 1023
1393 +Trunk 3 = 1024 -> 1151 1152 -> 1207 1208 -> 1407 1408 -> 1535
1394 +Trunk 4 = 1535 -> 1663 1664 -> 1791 1792 -> 1920 1921 -> 2047
1396 + I will get CHAN_RX_TRIGGER worth of bytes out of each channel on each trunk
1399 + For TX Data, it is split into 8 lists with each list containing 16 bytes per
1402 +Trunk 1 = 0 -> 16 17 -> 32 33 -> 48 49 -> 64
1403 +Trunk 2 = 65 -> 80 81 -> 96 97 -> 112 113 -> 128
1404 +Trunk 3 = 129 -> 144 145 -> 160 161 -> 176 177 -> 192
1405 +Trunk 4 = 193 -> 208 209 -> 224 225 -> 240 241 -> 256
1410 + while ((v = qmgr_get_entry(queue_ids[port->id].chan)))
1412 + tx_list = (v >> 8) & 0xFF;
1413 + rx_frame = v & 0xFF;
1419 + for (channel = 0; channel < 8; channel++) {
1421 + hdev = port->chan_devices[channel];
1425 + if (test_bit(1 << channel, &port->chan_tx_bitmap)) {
1426 + buf = (u8 *)hdev->tx_buf + hdev->tx_loc;
1428 + hw_buf = (u8 *)port->chan_tx_buf;
1429 + hw_buf += (tx_list * CHAN_TX_LIST_FRAMES * 32);
1430 + hw_buf += (4 * CHAN_TX_LIST_FRAMES * channel);
1431 + save_buf = hw_buf;
1433 + save_buf = port->tx_lists[tx_list][channel];
1435 + for (i = 0; i < CHAN_TX_LIST_FRAMES; i++) {
1436 + hw_buf = save_buf + i;
1437 + for (j = 0; j < 4; j++) {
1438 + *hw_buf = *(buf++);
1439 + hw_buf += CHAN_TX_LIST_FRAMES;
1442 + hdev->tx_loc += 4;
1444 + if (hdev->tx_loc >= hdev->tx_buffer_size) {
1446 + buf = (u8 *)hdev->tx_buf;
1451 + hw_buf = (u8 *)port->chan_tx_buf;
1452 + hw_buf += (tx_list * CHAN_TX_LIST_FRAMES * 32);
1453 + hw_buf += (4 * CHAN_TX_LIST_FRAMES * channel);
1455 + hw_buf = port->tx_lists[tx_list][channel];
1457 + memset(hw_buf, 0, 64);
1460 + if (hdev->tx_frame >= hdev->tx_period_size && test_bit(1 << channel, &port->chan_tx_bitmap))
1462 + hdev->tx_frame %= hdev->tx_period_size;
1463 + if (hdev->tx_callback)
1464 + hdev->tx_callback(hdev->tx_data);
1468 + if (test_bit(1 << channel, &port->chan_rx_bitmap)) {
1469 + buf = (u8 *)hdev->rx_buf + hdev->rx_loc;
1471 + hw_buf = (u8 *)port->chan_rx_buf;
1472 + hw_buf += (4 * CHAN_RX_FRAMES * channel);
1473 + hw_buf += rx_frame;
1474 + save_buf = hw_buf;
1476 + save_buf = port->rx_frames[channel][rx_frame >> 4];
1478 + for (i = 0; i < CHAN_RX_TRIGGER; i++) {
1479 + hw_buf = save_buf + i;
1480 + for (j = 0; j < 4; j++) {
1481 + *(buf++) = *hw_buf;
1482 + hw_buf += CHAN_RX_FRAMES;
1484 + hdev->rx_loc += 4;
1486 + if (hdev->rx_loc >= hdev->rx_buffer_size) {
1488 + buf = (u8 *)hdev->rx_buf;
1493 + if (hdev->rx_frame >= hdev->rx_period_size && test_bit(1 << channel, &port->chan_rx_bitmap))
1495 + hdev->rx_frame %= hdev->rx_period_size;
1496 + if (hdev->rx_callback)
1497 + hdev->rx_callback(hdev->rx_data);
1504 + tasklet_hi_schedule(&port->task);
1510 + qmgr_enable_irq(queue_ids[port->id].chan);
1516 +struct hss_device *hss_chan_create(struct port *port, unsigned int channel)
1518 + struct hss_device *chan_dev;
1519 + unsigned long flags;
1521 + chan_dev = kzalloc(sizeof(struct hss_device), GFP_KERNEL);
1523 + spin_lock_irqsave(&npe_lock, flags);
1525 + chan_dev->id = channel;
1526 + chan_dev->port = port;
1528 + port->channels[channel] = channel;
1530 + port->chan_devices[channel] = chan_dev;
1532 + spin_unlock_irqrestore(&npe_lock, flags);
1537 +/*****************************************************************************
1539 + ****************************************************************************/
1541 +static struct platform_device gw_avila_hss_device_0 = {
1542 + .name = "ixp4xx_hss",
1546 +static struct platform_device gw_avila_hss_device_1 = {
1547 + .name = "ixp4xx_hss",
1551 +static struct platform_device *gw_avila_hss_port_0;
1552 +static struct platform_device *gw_avila_hss_port_1;
1553 +static u64 hss_dmamask = 0xFFFFFFFF;
1555 +struct hss_device *hss_init(int id, int channel)
1557 + struct port *port = hss_port[id];
1558 + struct hss_device *hdev;
1563 + spin_lock_init(&npe_lock);
1565 + npe = npe_request(0);
1568 + if (!port->init) {
1570 + gw_avila_hss_port_0 = platform_device_alloc("hss-port", 0);
1572 + platform_set_drvdata(gw_avila_hss_port_0, &gw_avila_hss_device_0);
1573 + port->dev = &gw_avila_hss_port_0->dev;
1575 + if (!port->dev->dma_mask)
1576 + port->dev->dma_mask = &hss_dmamask;
1577 + if (!port->dev->coherent_dma_mask)
1578 + port->dev->coherent_dma_mask = 0xFFFFFFFF;
1580 + ret = platform_device_add(gw_avila_hss_port_0);
1583 + platform_device_put(gw_avila_hss_port_0);
1585 + tasklet_init(&port->task, hss_chan_read, (unsigned long) port);
1589 + gw_avila_hss_port_1 = platform_device_alloc("hss-port", 1);
1591 + platform_set_drvdata(gw_avila_hss_port_1, &gw_avila_hss_device_1);
1592 + port->dev = &gw_avila_hss_port_1->dev;
1594 + if (!port->dev->dma_mask)
1595 + port->dev->dma_mask = &hss_dmamask;
1596 + if (!port->dev->coherent_dma_mask)
1597 + port->dev->coherent_dma_mask = 0xFFFFFFFF;
1599 + ret = platform_device_add(gw_avila_hss_port_1);
1602 + platform_device_put(gw_avila_hss_port_1);
1604 + tasklet_init(&port->task, hss_chan_read, (unsigned long) port);
1609 + port->clock_type = CLOCK_EXT;
1610 + port->clock_rate = 8192000;
1611 + port->frame_size = 256; /* E1 */
1612 + port->mode = MODE_RAW;
1613 + port->next_rx_frame = 0;
1614 + memset(port->channels, CHANNEL_UNUSED, sizeof(port->channels));
1617 + hdev = hss_chan_create(port, channel);
1621 +EXPORT_SYMBOL(hss_init);
1623 +int hss_set_tx_callback(struct hss_device *hdev, void (*tx_callback)(void *), void *tx_data)
1625 + BUG_ON(tx_callback == NULL);
1626 + hdev->tx_callback = tx_callback;
1627 + hdev->tx_data = tx_data;
1631 +EXPORT_SYMBOL(hss_set_tx_callback);
1633 +int hss_set_rx_callback(struct hss_device *hdev, void (*rx_callback)(void *), void *rx_data)
1635 + BUG_ON(rx_callback == NULL);
1636 + hdev->rx_callback = rx_callback;
1637 + hdev->rx_data = rx_data;
1641 +EXPORT_SYMBOL(hss_set_rx_callback);
1643 +int hss_config_rx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size)
1646 + * Period Size and Buffer Size are in Frames which are u32
1647 + * We convert the u32 *buf to u8 in order to make channel reads
1648 + * and rx_loc easier
1651 + hdev->rx_buf = (u8 *)buf;
1652 + hdev->rx_buffer_size = buffer_size << 2;
1653 + hdev->rx_period_size = period_size;
1657 +EXPORT_SYMBOL(hss_config_rx_dma);
1659 +int hss_config_tx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size)
1662 + * Period Size and Buffer Size are in Frames which are u32
1663 + * We convert the u32 *buf to u8 in order to make channel reads
1664 + * and rx_loc easier
1667 + hdev->tx_buf = (u8 *)buf;
1668 + hdev->tx_buffer_size = buffer_size << 2;
1669 + hdev->tx_period_size = period_size;
1673 +EXPORT_SYMBOL(hss_config_tx_dma);
1675 +unsigned long hss_curr_offset_rx(struct hss_device *hdev)
1677 + return hdev->rx_loc >> 2;
1679 +EXPORT_SYMBOL(hss_curr_offset_rx);
1681 +unsigned long hss_curr_offset_tx(struct hss_device *hdev)
1683 + return hdev->tx_loc >> 2;
1685 +EXPORT_SYMBOL(hss_curr_offset_tx);
1687 +MODULE_AUTHOR("Chris Lang");
1688 +MODULE_DESCRIPTION("Intel IXP4xx HSS Audio driver");
1689 +MODULE_LICENSE("GPL v2");
1691 +++ b/sound/soc/gw-avila/ixp4xx_hss.h
1696 + * Copyright (C) 2009 Gateworks Corporation
1698 + * This program is free software; you can redistribute it and/or modify it
1699 + * under the terms of version 2 of the GNU General Public License
1700 + * as published by the Free Software Foundation.
1703 +#include <linux/types.h>
1704 +#include <linux/bitops.h>
1705 +#include <linux/dma-mapping.h>
1706 +#include <linux/dmapool.h>
1707 +#include <linux/fs.h>
1708 +#include <linux/io.h>
1709 +#include <linux/kernel.h>
1710 +#include <linux/platform_device.h>
1711 +#include <linux/poll.h>
1712 +#include <mach/npe.h>
1713 +#include <mach/qmgr.h>
1714 +#include <linux/interrupt.h>
1716 +//#include <linux/hdlc.h> XXX We aren't HDLC
1718 +#define DEBUG_QUEUES 0
1719 +#define DEBUG_DESC 0
1722 +#define DEBUG_PKT_BYTES 0
1723 +#define DEBUG_CLOSE 0
1724 +#define DEBUG_FRAMER 0
1726 +#define DRV_NAME "ixp4xx_hss"
1728 +#define PKT_EXTRA_FLAGS 0 /* orig 1 */
1729 +#define TX_FRAME_SYNC_OFFSET 0 /* channelized */
1730 +#define PKT_NUM_PIPES 1 /* 1, 2 or 4 */
1731 +#define PKT_PIPE_FIFO_SIZEW 4 /* total 4 dwords per HSS */
1733 +#define RX_DESCS 512 /* also length of all RX queues */
1734 +#define TX_DESCS 512 /* also length of all TX queues */
1736 +//#define POOL_ALLOC_SIZE (sizeof(struct desc) * (RX_DESCS + TX_DESCS))
1737 +#define RX_SIZE (HDLC_MAX_MRU + 4) /* NPE needs more space */
1738 +#define MAX_CLOSE_WAIT 1000 /* microseconds */
1739 +#define HSS_COUNT 2
1740 +#define MIN_FRAME_SIZE 16 /* bits */
1741 +#define MAX_FRAME_SIZE 257 /* 256 bits + framing bit */
1742 +#define MAX_CHANNELS (MAX_FRAME_SIZE / 8)
1743 +#define MAX_CHAN_DEVICES 32
1744 +#define CHANNEL_HDLC 0xFE
1745 +#define CHANNEL_UNUSED 0xFF
1747 +#define NAPI_WEIGHT 16
1748 +#define CHAN_RX_TRIGGER 16 /* 8 RX frames = 1 ms @ E1 */
1749 +#define CHAN_RX_FRAMES 128
1750 +#define CHAN_RX_TRUNKS 1
1751 +#define MAX_CHAN_RX_BAD_SYNC (CHAN_RX_TRIGGER / 2 /* pairs */ - 3)
1753 +#define CHAN_TX_LIST_FRAMES CHAN_RX_TRIGGER /* bytes/channel per list, 16 - 48 */
1754 +#define CHAN_TX_LISTS 8
1755 +#define CHAN_TX_TRUNKS CHAN_RX_TRUNKS
1756 +#define CHAN_TX_FRAMES (CHAN_TX_LIST_FRAMES * CHAN_TX_LISTS)
1758 +#define CHAN_QUEUE_LEN 32 /* minimum possible */
1760 +#define chan_rx_buf_len(port) (port->frame_size / 8 * CHAN_RX_FRAMES * CHAN_RX_TRUNKS)
1761 +#define chan_tx_buf_len(port) (port->frame_size / 8 * CHAN_TX_FRAMES * CHAN_TX_TRUNKS)
1764 +#define HSS0_CHL_RXTRIG_QUEUE 12 /* orig size = 32 dwords */
1765 +#define HSS0_PKT_RX_QUEUE 13 /* orig size = 32 dwords */
1766 +#define HSS0_PKT_TX0_QUEUE 14 /* orig size = 16 dwords */
1767 +#define HSS0_PKT_TX1_QUEUE 15
1768 +#define HSS0_PKT_TX2_QUEUE 16
1769 +#define HSS0_PKT_TX3_QUEUE 17
1770 +#define HSS0_PKT_RXFREE0_QUEUE 18 /* orig size = 16 dwords */
1771 +#define HSS0_PKT_RXFREE1_QUEUE 19
1772 +#define HSS0_PKT_RXFREE2_QUEUE 20
1773 +#define HSS0_PKT_RXFREE3_QUEUE 21
1774 +#define HSS0_PKT_TXDONE_QUEUE 22 /* orig size = 64 dwords */
1776 +#define HSS1_CHL_RXTRIG_QUEUE 10
1777 +#define HSS1_PKT_RX_QUEUE 0
1778 +#define HSS1_PKT_TX0_QUEUE 5
1779 +#define HSS1_PKT_TX1_QUEUE 6
1780 +#define HSS1_PKT_TX2_QUEUE 7
1781 +#define HSS1_PKT_TX3_QUEUE 8
1782 +#define HSS1_PKT_RXFREE0_QUEUE 1
1783 +#define HSS1_PKT_RXFREE1_QUEUE 2
1784 +#define HSS1_PKT_RXFREE2_QUEUE 3
1785 +#define HSS1_PKT_RXFREE3_QUEUE 4
1786 +#define HSS1_PKT_TXDONE_QUEUE 9
1788 +#define NPE_PKT_MODE_HDLC 0
1789 +#define NPE_PKT_MODE_RAW 1
1790 +#define NPE_PKT_MODE_56KMODE 2
1791 +#define NPE_PKT_MODE_56KENDIAN_MSB 4
1793 +/* PKT_PIPE_HDLC_CFG_WRITE flags */
1794 +#define PKT_HDLC_IDLE_ONES 0x1 /* default = flags */
1795 +#define PKT_HDLC_CRC_32 0x2 /* default = CRC-16 */
1796 +#define PKT_HDLC_MSB_ENDIAN 0x4 /* default = LE */
1799 +/* hss_config, PCRs */
1800 +/* Frame sync sampling, default = active low */
1801 +#define PCR_FRM_SYNC_ACTIVE_HIGH 0x40000000
1802 +#define PCR_FRM_SYNC_FALLINGEDGE 0x80000000
1803 +#define PCR_FRM_SYNC_RISINGEDGE 0xC0000000
1805 +/* Frame sync pin: input (default) or output generated off a given clk edge */
1806 +#define PCR_FRM_SYNC_OUTPUT_FALLING 0x20000000
1807 +#define PCR_FRM_SYNC_OUTPUT_RISING 0x30000000
1809 +/* Frame and data clock sampling on edge, default = falling */
1810 +#define PCR_FCLK_EDGE_RISING 0x08000000
1811 +#define PCR_DCLK_EDGE_RISING 0x04000000
1813 +/* Clock direction, default = input */
1814 +#define PCR_SYNC_CLK_DIR_OUTPUT 0x02000000
1816 +/* Generate/Receive frame pulses, default = enabled */
1817 +#define PCR_FRM_PULSE_DISABLED 0x01000000
1819 + /* Data rate is full (default) or half the configured clk speed */
1820 +#define PCR_HALF_CLK_RATE 0x00200000
1822 +/* Invert data between NPE and HSS FIFOs? (default = no) */
1823 +#define PCR_DATA_POLARITY_INVERT 0x00100000
1825 +/* TX/RX endianness, default = LSB */
1826 +#define PCR_MSB_ENDIAN 0x00080000
1828 +/* Normal (default) / open drain mode (TX only) */
1829 +#define PCR_TX_PINS_OPEN_DRAIN 0x00040000
1831 +/* No framing bit transmitted and expected on RX? (default = framing bit) */
1832 +#define PCR_SOF_NO_FBIT 0x00020000
1834 +/* Drive data pins? */
1835 +#define PCR_TX_DATA_ENABLE 0x00010000
1837 +/* Voice 56k type: drive the data pins low (default), high, high Z */
1838 +#define PCR_TX_V56K_HIGH 0x00002000
1839 +#define PCR_TX_V56K_HIGH_IMP 0x00004000
1841 +/* Unassigned type: drive the data pins low (default), high, high Z */
1842 +#define PCR_TX_UNASS_HIGH 0x00000800
1843 +#define PCR_TX_UNASS_HIGH_IMP 0x00001000
1845 +/* T1 @ 1.544MHz only: Fbit dictated in FIFO (default) or high Z */
1846 +#define PCR_TX_FB_HIGH_IMP 0x00000400
1848 +/* 56k data endiannes - which bit unused: high (default) or low */
1849 +#define PCR_TX_56KE_BIT_0_UNUSED 0x00000200
1851 +/* 56k data transmission type: 32/8 bit data (default) or 56K data */
1852 +#define PCR_TX_56KS_56K_DATA 0x00000100
1854 +/* hss_config, cCR */
1855 +/* Number of packetized clients, default = 1 */
1856 +#define CCR_NPE_HFIFO_2_HDLC 0x04000000
1857 +#define CCR_NPE_HFIFO_3_OR_4HDLC 0x08000000
1859 +/* default = no loopback */
1860 +#define CCR_LOOPBACK 0x02000000
1862 +/* HSS number, default = 0 (first) */
1863 +#define CCR_SECOND_HSS 0x01000000
1866 +/* hss_config, clkCR: main:10, num:10, denom:12 */
1867 +#define CLK42X_SPEED_EXP ((0x3FF << 22) | ( 2 << 12) | 15) /*65 KHz*/
1869 +#define CLK42X_SPEED_512KHZ (( 130 << 22) | ( 2 << 12) | 15)
1870 +#define CLK42X_SPEED_1536KHZ (( 43 << 22) | ( 18 << 12) | 47)
1871 +#define CLK42X_SPEED_1544KHZ (( 43 << 22) | ( 33 << 12) | 192)
1872 +#define CLK42X_SPEED_2048KHZ (( 32 << 22) | ( 34 << 12) | 63)
1873 +#define CLK42X_SPEED_4096KHZ (( 16 << 22) | ( 34 << 12) | 127)
1874 +#define CLK42X_SPEED_8192KHZ (( 8 << 22) | ( 34 << 12) | 255)
1876 +#define CLK46X_SPEED_512KHZ (( 130 << 22) | ( 24 << 12) | 127)
1877 +#define CLK46X_SPEED_1536KHZ (( 43 << 22) | (152 << 12) | 383)
1878 +#define CLK46X_SPEED_1544KHZ (( 43 << 22) | ( 66 << 12) | 385)
1879 +#define CLK46X_SPEED_2048KHZ (( 32 << 22) | (280 << 12) | 511)
1880 +#define CLK46X_SPEED_4096KHZ (( 16 << 22) | (280 << 12) | 1023)
1881 +#define CLK46X_SPEED_8192KHZ (( 8 << 22) | (280 << 12) | 2047)
1884 +/* hss_config, LUT entries */
1885 +#define TDMMAP_UNASSIGNED 0
1886 +#define TDMMAP_HDLC 1 /* HDLC - packetized */
1887 +#define TDMMAP_VOICE56K 2 /* Voice56K - 7-bit channelized */
1888 +#define TDMMAP_VOICE64K 3 /* Voice64K - 8-bit channelized */
1890 +/* offsets into HSS config */
1891 +#define HSS_CONFIG_TX_PCR 0x00 /* port configuration registers */
1892 +#define HSS_CONFIG_RX_PCR 0x04
1893 +#define HSS_CONFIG_CORE_CR 0x08 /* loopback control, HSS# */
1894 +#define HSS_CONFIG_CLOCK_CR 0x0C /* clock generator control */
1895 +#define HSS_CONFIG_TX_FCR 0x10 /* frame configuration registers */
1896 +#define HSS_CONFIG_RX_FCR 0x14
1897 +#define HSS_CONFIG_TX_LUT 0x18 /* channel look-up tables */
1898 +#define HSS_CONFIG_RX_LUT 0x38
1901 +/* NPE command codes */
1902 +/* writes the ConfigWord value to the location specified by offset */
1903 +#define PORT_CONFIG_WRITE 0x40
1905 +/* triggers the NPE to load the contents of the configuration table */
1906 +#define PORT_CONFIG_LOAD 0x41
1908 +/* triggers the NPE to return an HssErrorReadResponse message */
1909 +#define PORT_ERROR_READ 0x42
1911 +/* reset NPE internal status and enable the HssChannelized operation */
1912 +#define CHAN_FLOW_ENABLE 0x43
1913 +#define CHAN_FLOW_DISABLE 0x44
1914 +#define CHAN_IDLE_PATTERN_WRITE 0x45
1915 +#define CHAN_NUM_CHANS_WRITE 0x46
1916 +#define CHAN_RX_BUF_ADDR_WRITE 0x47
1917 +#define CHAN_RX_BUF_CFG_WRITE 0x48
1918 +#define CHAN_TX_BLK_CFG_WRITE 0x49
1919 +#define CHAN_TX_BUF_ADDR_WRITE 0x4A
1920 +#define CHAN_TX_BUF_SIZE_WRITE 0x4B
1921 +#define CHAN_TSLOTSWITCH_ENABLE 0x4C
1922 +#define CHAN_TSLOTSWITCH_DISABLE 0x4D
1924 +/* downloads the gainWord value for a timeslot switching channel associated
1926 +#define CHAN_TSLOTSWITCH_GCT_DOWNLOAD 0x4E
1928 +/* triggers the NPE to reset internal status and enable the HssPacketized
1929 + operation for the flow specified by pPipe */
1930 +#define PKT_PIPE_FLOW_ENABLE 0x50
1931 +#define PKT_PIPE_FLOW_DISABLE 0x51
1932 +#define PKT_NUM_PIPES_WRITE 0x52
1933 +#define PKT_PIPE_FIFO_SIZEW_WRITE 0x53
1934 +#define PKT_PIPE_HDLC_CFG_WRITE 0x54
1935 +#define PKT_PIPE_IDLE_PATTERN_WRITE 0x55
1936 +#define PKT_PIPE_RX_SIZE_WRITE 0x56
1937 +#define PKT_PIPE_MODE_WRITE 0x57
1939 +/* HDLC packet status values - desc->status */
1940 +#define ERR_SHUTDOWN 1 /* stop or shutdown occurrance */
1941 +#define ERR_HDLC_ALIGN 2 /* HDLC alignment error */
1942 +#define ERR_HDLC_FCS 3 /* HDLC Frame Check Sum error */
1943 +#define ERR_RXFREE_Q_EMPTY 4 /* RX-free queue became empty while receiving
1944 + this packet (if buf_len < pkt_len) */
1945 +#define ERR_HDLC_TOO_LONG 5 /* HDLC frame size too long */
1946 +#define ERR_HDLC_ABORT 6 /* abort sequence received */
1947 +#define ERR_DISCONNECTING 7 /* disconnect is in progress */
1949 +#define CLOCK_EXT 0
1950 +#define CLOCK_INT 1
1952 +enum mode {MODE_HDLC = 0, MODE_RAW, MODE_G704};
1958 + CHAN_0 = (1 << 0),
1959 + CHAN_1 = (1 << 1),
1960 + CHAN_2 = (1 << 2),
1961 + CHAN_3 = (1 << 3),
1962 + CHAN_4 = (1 << 4),
1963 + CHAN_5 = (1 << 5),
1964 + CHAN_6 = (1 << 6),
1965 + CHAN_7 = (1 << 7),
1966 + CHAN_8 = (1 << 8),
1967 + CHAN_9 = (1 << 9),
1968 + CHAN_10 = (1 << 10),
1969 + CHAN_11 = (1 << 11),
1970 + CHAN_12 = (1 << 12),
1971 + CHAN_13 = (1 << 13),
1972 + CHAN_14 = (1 << 14),
1973 + CHAN_15 = (1 << 15)
1976 +enum alignment { NOT_ALIGNED = 0, EVEN_FIRST, ODD_FIRST };
1979 +typedef struct sk_buff buffer_t;
1980 +#define free_buffer dev_kfree_skb
1981 +#define free_buffer_irq dev_kfree_skb_irq
1983 +typedef void buffer_t;
1984 +#define free_buffer kfree
1985 +#define free_buffer_irq kfree
1988 +struct hss_device {
1989 + struct port *port;
1990 + unsigned int open_count, excl_open;
1991 + unsigned long tx_loc, rx_loc; /* bytes */
1992 + unsigned long tx_frame, rx_frame; /* Frames */
1993 + u8 id, chan_count;
1994 + u8 log_channels[MAX_CHANNELS];
1999 + size_t rx_buffer_size;
2000 + size_t rx_period_size;
2001 + size_t tx_buffer_size;
2002 + size_t tx_period_size;
2004 + void (*rx_callback)(void *data);
2006 + void (*tx_callback)(void *data);
2008 + void *private_data;
2011 +extern struct hss_device *hss_handle[32];
2012 +extern struct port *hss_port[2];
2015 + unsigned char init;
2017 + struct device *dev;
2019 + struct tasklet_struct task;
2021 + unsigned long chan_rx_bitmap;
2022 + unsigned long chan_tx_bitmap;
2023 + unsigned char chan_open;
2025 + /* the following fields must be protected by npe_lock */
2027 + unsigned int clock_type, clock_rate, loopback;
2028 + unsigned int frame_size, frame_sync_offset;
2029 + unsigned int next_rx_frame;
2031 + struct hss_device *chan_devices[MAX_CHAN_DEVICES];
2032 + u32 chan_tx_buf_phys, chan_rx_buf_phys;
2033 + u32 chan_tx_pointers_phys;
2034 + u32 *chan_tx_pointers;
2037 + u8 *tx_lists[CHAN_TX_LISTS][8];
2038 + u8 *rx_frames[8][CHAN_TX_LISTS];
2039 + unsigned int chan_open_count, hdlc_open;
2040 + unsigned int chan_started, initialized, just_set_offset;
2041 + unsigned int chan_last_rx, chan_last_tx;
2043 + /* assigned channels, may be invalid with given frame length or mode */
2044 + u8 channels[MAX_CHANNELS];
2048 +/* NPE message structure */
2051 + u8 cmd, unused, hss_port, index;
2053 + struct { u8 data8a, data8b, data8c, data8d; };
2054 + struct { u16 data16a, data16b; };
2055 + struct { u32 data32; };
2058 + u8 index, hss_port, unused, cmd;
2060 + struct { u8 data8d, data8c, data8b, data8a; };
2061 + struct { u16 data16b, data16a; };
2062 + struct { u32 data32; };
2067 +#define rx_desc_phys(port, n) ((port)->desc_tab_phys + \
2068 + (n) * sizeof(struct desc))
2069 +#define rx_desc_ptr(port, n) (&(port)->desc_tab[n])
2071 +#define tx_desc_phys(port, n) ((port)->desc_tab_phys + \
2072 + ((n) + RX_DESCS) * sizeof(struct desc))
2073 +#define tx_desc_ptr(port, n) (&(port)->desc_tab[(n) + RX_DESCS])
2075 +int hss_prepare_chan(struct port *port);
2076 +void hss_chan_stop(struct port *port);
2078 +struct hss_device *hss_init(int id, int channel);
2079 +int hss_chan_open(struct hss_device *hdev);
2080 +int hss_chan_close(struct hss_device *hdev);
2082 +int hss_set_tx_callback(struct hss_device *hdev, void (*tx_callback)(void *), void *tx_data);
2083 +int hss_set_rx_callback(struct hss_device *hdev, void (*rx_callback)(void *), void *rx_data);
2084 +int hss_tx_start(struct hss_device *hdev);
2085 +int hss_tx_stop(struct hss_device *hdev);
2086 +int hss_rx_start(struct hss_device *hdev);
2087 +int hss_rx_stop(struct hss_device *hdev);
2089 +int hss_config_rx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size);
2090 +int hss_config_tx_dma(struct hss_device *hdev, void *buf, size_t buffer_size, size_t period_size);
2091 +unsigned long hss_curr_offset_rx(struct hss_device *hdev);
2092 +unsigned long hss_curr_offset_tx(struct hss_device *hdev);