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