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