xref: /linux/sound/aoa/soundbus/i2sbus/i2sbus.h (revision 0ea5c948cb64bab5bc7a5516774eb8536f05aa0d)
1*d6869352SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2f3d9478bSJohannes Berg /*
3f3d9478bSJohannes Berg  * i2sbus driver -- private definitions
4f3d9478bSJohannes Berg  *
5f3d9478bSJohannes Berg  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6f3d9478bSJohannes Berg  */
7f3d9478bSJohannes Berg #ifndef __I2SBUS_H
8f3d9478bSJohannes Berg #define __I2SBUS_H
9f3d9478bSJohannes Berg #include <linux/interrupt.h>
10f3d9478bSJohannes Berg #include <linux/spinlock.h>
11f3d9478bSJohannes Berg #include <linux/mutex.h>
12547ac2aeSPaul Mackerras #include <linux/completion.h>
13977c6023SBenjamin Herrenschmidt 
14977c6023SBenjamin Herrenschmidt #include <sound/pcm.h>
15977c6023SBenjamin Herrenschmidt 
16977c6023SBenjamin Herrenschmidt #include <asm/pmac_feature.h>
17977c6023SBenjamin Herrenschmidt #include <asm/dbdma.h>
18977c6023SBenjamin Herrenschmidt 
19888dcb7cSJohannes Berg #include "interface.h"
20f3d9478bSJohannes Berg #include "../soundbus.h"
21f3d9478bSJohannes Berg 
22f3d9478bSJohannes Berg struct i2sbus_control {
23f3d9478bSJohannes Berg 	struct list_head list;
24977c6023SBenjamin Herrenschmidt 	struct macio_chip *macio;
25f3d9478bSJohannes Berg };
26f3d9478bSJohannes Berg 
27f3d9478bSJohannes Berg #define MAX_DBDMA_COMMANDS	32
28f3d9478bSJohannes Berg 
29f3d9478bSJohannes Berg struct dbdma_command_mem {
30f3d9478bSJohannes Berg 	dma_addr_t bus_addr;
31f3d9478bSJohannes Berg 	dma_addr_t bus_cmd_start;
32f3d9478bSJohannes Berg 	struct dbdma_cmd *cmds;
33f3d9478bSJohannes Berg 	void *space;
34f3d9478bSJohannes Berg 	int size;
35f3d9478bSJohannes Berg 	u32 running:1;
36547ac2aeSPaul Mackerras 	u32 stopping:1;
37f3d9478bSJohannes Berg };
38f3d9478bSJohannes Berg 
39f3d9478bSJohannes Berg struct pcm_info {
40f3d9478bSJohannes Berg 	u32 created:1, /* has this direction been created with alsa? */
41f3d9478bSJohannes Berg 	    active:1;  /* is this stream active? */
42f3d9478bSJohannes Berg 	/* runtime information */
43f3d9478bSJohannes Berg 	struct snd_pcm_substream *substream;
44f3d9478bSJohannes Berg 	int current_period;
45f3d9478bSJohannes Berg 	u32 frame_count;
46f3d9478bSJohannes Berg 	struct dbdma_command_mem dbdma_ring;
47f3d9478bSJohannes Berg 	volatile struct dbdma_regs __iomem *dbdma;
48547ac2aeSPaul Mackerras 	struct completion *stop_completion;
49f3d9478bSJohannes Berg };
50f3d9478bSJohannes Berg 
51389ba795SBenjamin Herrenschmidt enum {
52389ba795SBenjamin Herrenschmidt 	aoa_resource_i2smmio = 0,
53389ba795SBenjamin Herrenschmidt 	aoa_resource_txdbdma,
54389ba795SBenjamin Herrenschmidt 	aoa_resource_rxdbdma,
55389ba795SBenjamin Herrenschmidt };
56389ba795SBenjamin Herrenschmidt 
57f3d9478bSJohannes Berg struct i2sbus_dev {
58f3d9478bSJohannes Berg 	struct soundbus_dev sound;
59f3d9478bSJohannes Berg 	struct macio_dev *macio;
60f3d9478bSJohannes Berg 	struct i2sbus_control *control;
61f3d9478bSJohannes Berg 	volatile struct i2s_interface_regs __iomem *intfregs;
62f3d9478bSJohannes Berg 
63f3d9478bSJohannes Berg 	struct resource resources[3];
64f3d9478bSJohannes Berg 	struct resource *allocated_resource[3];
65f3d9478bSJohannes Berg 	int interrupts[3];
66f3d9478bSJohannes Berg 	char rnames[3][32];
67f3d9478bSJohannes Berg 
68f3d9478bSJohannes Berg 	/* info about currently active substreams */
69f3d9478bSJohannes Berg 	struct pcm_info out, in;
70f3d9478bSJohannes Berg 	snd_pcm_format_t format;
71f3d9478bSJohannes Berg 	unsigned int rate;
72f3d9478bSJohannes Berg 
73f3d9478bSJohannes Berg 	/* list for a single controller */
74f3d9478bSJohannes Berg 	struct list_head item;
75f3d9478bSJohannes Berg 	/* number of bus on controller */
76f3d9478bSJohannes Berg 	int bus_number;
77f3d9478bSJohannes Berg 	/* for use by control layer */
78f3d9478bSJohannes Berg 	struct pmf_function *enable,
79f3d9478bSJohannes Berg 			    *cell_enable,
80f3d9478bSJohannes Berg 			    *cell_disable,
81f3d9478bSJohannes Berg 			    *clock_enable,
82f3d9478bSJohannes Berg 			    *clock_disable;
83f3d9478bSJohannes Berg 
84f3d9478bSJohannes Berg 	/* locks */
85f3d9478bSJohannes Berg 	/* spinlock for low-level interrupt locking */
86f3d9478bSJohannes Berg 	spinlock_t low_lock;
87f3d9478bSJohannes Berg 	/* mutex for high-level consistency */
88f3d9478bSJohannes Berg 	struct mutex lock;
89f3d9478bSJohannes Berg };
90f3d9478bSJohannes Berg 
91f3d9478bSJohannes Berg #define soundbus_dev_to_i2sbus_dev(sdev) \
92f3d9478bSJohannes Berg 		container_of(sdev, struct i2sbus_dev, sound)
93f3d9478bSJohannes Berg 
94f3d9478bSJohannes Berg /* pcm specific functions */
95f3d9478bSJohannes Berg extern int
96f3d9478bSJohannes Berg i2sbus_attach_codec(struct soundbus_dev *dev, struct snd_card *card,
97f3d9478bSJohannes Berg 		    struct codec_info *ci, void *data);
98f3d9478bSJohannes Berg extern void
99f3d9478bSJohannes Berg i2sbus_detach_codec(struct soundbus_dev *dev, void *data);
100f3d9478bSJohannes Berg extern irqreturn_t
1017d12e780SDavid Howells i2sbus_tx_intr(int irq, void *devid);
102f3d9478bSJohannes Berg extern irqreturn_t
1037d12e780SDavid Howells i2sbus_rx_intr(int irq, void *devid);
104f3d9478bSJohannes Berg 
105547ac2aeSPaul Mackerras extern void i2sbus_wait_for_stop_both(struct i2sbus_dev *i2sdev);
106547ac2aeSPaul Mackerras extern void i2sbus_pcm_prepare_both(struct i2sbus_dev *i2sdev);
107547ac2aeSPaul Mackerras 
108f3d9478bSJohannes Berg /* control specific functions */
109f3d9478bSJohannes Berg extern int i2sbus_control_init(struct macio_dev* dev,
110f3d9478bSJohannes Berg 			       struct i2sbus_control **c);
111f3d9478bSJohannes Berg extern void i2sbus_control_destroy(struct i2sbus_control *c);
112f3d9478bSJohannes Berg extern int i2sbus_control_add_dev(struct i2sbus_control *c,
113f3d9478bSJohannes Berg 				  struct i2sbus_dev *i2sdev);
114f3d9478bSJohannes Berg extern void i2sbus_control_remove_dev(struct i2sbus_control *c,
115f3d9478bSJohannes Berg 				      struct i2sbus_dev *i2sdev);
116f3d9478bSJohannes Berg extern int i2sbus_control_enable(struct i2sbus_control *c,
117f3d9478bSJohannes Berg 				 struct i2sbus_dev *i2sdev);
118f3d9478bSJohannes Berg extern int i2sbus_control_cell(struct i2sbus_control *c,
119f3d9478bSJohannes Berg 			       struct i2sbus_dev *i2sdev,
120f3d9478bSJohannes Berg 			       int enable);
121f3d9478bSJohannes Berg extern int i2sbus_control_clock(struct i2sbus_control *c,
122f3d9478bSJohannes Berg 				struct i2sbus_dev *i2sdev,
123f3d9478bSJohannes Berg 				int enable);
124f3d9478bSJohannes Berg #endif /* __I2SBUS_H */
125