162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * at91-pcm.h - ALSA PCM interface for the Atmel AT91 SoC.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci *  Copyright (C) 2005 SAN People
662306a36Sopenharmony_ci *  Copyright (C) 2008 Atmel
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Authors: Sedji Gaouaou <sedji.gaouaou@atmel.com>
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Based on at91-pcm. by:
1162306a36Sopenharmony_ci * Frank Mandarino <fmandarino@endrelia.com>
1262306a36Sopenharmony_ci * Copyright 2006 Endrelia Technologies Inc.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * Based on pxa2xx-pcm.c by:
1562306a36Sopenharmony_ci *
1662306a36Sopenharmony_ci * Author:	Nicolas Pitre
1762306a36Sopenharmony_ci * Created:	Nov 30, 2004
1862306a36Sopenharmony_ci * Copyright:	(C) 2004 MontaVista Software, Inc.
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#ifndef _ATMEL_PCM_H
2262306a36Sopenharmony_ci#define _ATMEL_PCM_H
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#include <linux/atmel-ssc.h>
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define ATMEL_SSC_DMABUF_SIZE	(64 * 1024)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * Registers and status bits that are required by the PCM driver.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_cistruct atmel_pdc_regs {
3262306a36Sopenharmony_ci	unsigned int	xpr;		/* PDC recv/trans pointer */
3362306a36Sopenharmony_ci	unsigned int	xcr;		/* PDC recv/trans counter */
3462306a36Sopenharmony_ci	unsigned int	xnpr;		/* PDC next recv/trans pointer */
3562306a36Sopenharmony_ci	unsigned int	xncr;		/* PDC next recv/trans counter */
3662306a36Sopenharmony_ci	unsigned int	ptcr;		/* PDC transfer control */
3762306a36Sopenharmony_ci};
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistruct atmel_ssc_mask {
4062306a36Sopenharmony_ci	u32	ssc_enable;		/* SSC recv/trans enable */
4162306a36Sopenharmony_ci	u32	ssc_disable;		/* SSC recv/trans disable */
4262306a36Sopenharmony_ci	u32	ssc_error;		/* SSC error conditions */
4362306a36Sopenharmony_ci	u32	ssc_endx;		/* SSC ENDTX or ENDRX */
4462306a36Sopenharmony_ci	u32	ssc_endbuf;		/* SSC TXBUFE or RXBUFF */
4562306a36Sopenharmony_ci	u32	pdc_enable;		/* PDC recv/trans enable */
4662306a36Sopenharmony_ci	u32	pdc_disable;		/* PDC recv/trans disable */
4762306a36Sopenharmony_ci};
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/*
5062306a36Sopenharmony_ci * This structure, shared between the PCM driver and the interface,
5162306a36Sopenharmony_ci * contains all information required by the PCM driver to perform the
5262306a36Sopenharmony_ci * PDC DMA operation.  All fields except dma_intr_handler() are initialized
5362306a36Sopenharmony_ci * by the interface.  The dma_intr_handler() pointer is set by the PCM
5462306a36Sopenharmony_ci * driver and called by the interface SSC interrupt handler if it is
5562306a36Sopenharmony_ci * non-NULL.
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_cistruct atmel_pcm_dma_params {
5862306a36Sopenharmony_ci	char *name;			/* stream identifier */
5962306a36Sopenharmony_ci	int pdc_xfer_size;		/* PDC counter increment in bytes */
6062306a36Sopenharmony_ci	struct ssc_device *ssc;		/* SSC device for stream */
6162306a36Sopenharmony_ci	struct atmel_pdc_regs *pdc;	/* PDC receive or transmit registers */
6262306a36Sopenharmony_ci	struct atmel_ssc_mask *mask;	/* SSC & PDC status bits */
6362306a36Sopenharmony_ci	struct snd_pcm_substream *substream;
6462306a36Sopenharmony_ci	void (*dma_intr_handler)(u32, struct snd_pcm_substream *);
6562306a36Sopenharmony_ci};
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/*
6862306a36Sopenharmony_ci * SSC register access (since ssc_writel() / ssc_readl() require literal name)
6962306a36Sopenharmony_ci */
7062306a36Sopenharmony_ci#define ssc_readx(base, reg)            (__raw_readl((base) + (reg)))
7162306a36Sopenharmony_ci#define ssc_writex(base, reg, value)    __raw_writel((value), (base) + (reg))
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_ATMEL_SOC_PDC)
7462306a36Sopenharmony_ciint atmel_pcm_pdc_platform_register(struct device *dev);
7562306a36Sopenharmony_ci#else
7662306a36Sopenharmony_cistatic inline int atmel_pcm_pdc_platform_register(struct device *dev)
7762306a36Sopenharmony_ci{
7862306a36Sopenharmony_ci	return 0;
7962306a36Sopenharmony_ci}
8062306a36Sopenharmony_ci#endif
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_ATMEL_SOC_DMA)
8362306a36Sopenharmony_ciint atmel_pcm_dma_platform_register(struct device *dev);
8462306a36Sopenharmony_ci#else
8562306a36Sopenharmony_cistatic inline int atmel_pcm_dma_platform_register(struct device *dev)
8662306a36Sopenharmony_ci{
8762306a36Sopenharmony_ci	return 0;
8862306a36Sopenharmony_ci}
8962306a36Sopenharmony_ci#endif
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#endif /* _ATMEL_PCM_H */
92