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