s3c2440_i2s.h revision 1.1.6.2 1 /*-
2 * Copyright (c) 2012 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Paul Fleischer <paul (at) xpg.dk>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29 #ifndef _S3C2440_I2S_H_
30 #define _S3C2440_I2S_H_
31
32 struct s3c2440_i2s_attach_args {
33 void *i2sa_handle; /* Handle of the S3C2440 I2S Controller */
34 };
35
36 /* It should be possible to allocate most buffer sizes within
37 2 segments.
38 However, worst case actually is PHYSMEM / PAGE_SIZE, which seems to
39 be 65535/4096 = 16 as default for most architectures.
40 This does seem like a too pesimistic number.
41 */
42 #define S3C2440_I2S_BUF_MAX_SEGS 2
43
44 struct s3c2440_i2s_buf {
45 void *i2b_parent; /* I2S handle */
46
47 /* Size of the buffer */
48 int i2b_size;
49
50 /* Kernelspace virtual address of the buffer */
51 void *i2b_addr;
52
53 /* Physical segments holding the buffer */
54 bus_dma_segment_t i2b_segs[S3C2440_I2S_BUF_MAX_SEGS];
55
56 /* Number of segments in use */
57 int i2b_nsegs;
58
59 /* Map used for transfers DMA transfers */
60 bus_dmamap_t i2b_dmamap;
61
62 /* DMA transfer structure */
63 dmac_xfer_t i2b_xfer;
64
65 /* Callback */
66 void (*i2b_cb)(void*);
67 void *i2b_cb_cookie;
68 };
69
70 typedef struct s3c2440_i2s_buf* s3c2440_i2s_buf_t;
71
72
73 void s3c2440_i2s_set_intr_lock(void *handle, kmutex_t *sc_intr_lock);
74
75 #define S3C2440_I2S_NONE (0)
76 #define S3C2440_I2S_TRANSMIT (1<<0)
77 #define S3C2440_I2S_RECEIVE (1<<1)
78 #define S3C2440_I2S_BOTH (S3C2440_I2S_TRANSMIT | S3C2440_I2S_RECEIVE)
79 /* Set transfer direction of the I2S bus */
80 void s3c2440_i2s_set_direction(void *handle, int direction);
81
82 /* Set the I2S clocks (master and serial) from the given sample rate */
83 void s3c2440_i2s_set_sample_rate(void *handle, int sample_rate);
84 void s3c2440_i2s_set_sample_width(void *handle, int width);
85
86 #define S3C2440_I2S_BUS_MSB 1
87 #define S3C2440_I2S_BUS_I2S 2
88 void s3c2440_i2s_set_bus_format(void *handle, int format);
89
90 /* Enable the I2S bus */
91 int s3c2440_i2s_commit(void *handle);
92
93 /* Disable the I2S bus */
94 int s3c2440_i2s_disable(void *handle);
95
96 int s3c2440_i2s_get_master_clock(void *handle);
97 int s3c2440_i2s_get_serial_clock(void *handle);
98
99 /* Allocate a I2S buffer. */
100 int s3c2440_i2s_alloc(void *, int, size_t, int, s3c2440_i2s_buf_t *);
101
102 /* Free an I2S buffer. */
103 void s3c2440_i2s_free(s3c2440_i2s_buf_t);
104
105 /* Write data (from the I2S buffer) onto the I2S bus */
106 int s3c2440_i2s_output(s3c2440_i2s_buf_t, void *, int, void (*)(void*), void*);
107 int s3c2440_i2s_input(s3c2440_i2s_buf_t, void *, int, void (*)(void*), void*);
108
109 int s3c2440_i2s_halt_output(s3c2440_i2s_buf_t);
110
111 #endif
112
113