bcm2835_bscvar.h revision 1.1.2.2 1 1.1.2.2 martin /* $NetBSD: bcm2835_bscvar.h,v 1.1.2.2 2020/04/08 14:07:28 martin Exp $ */
2 1.1.2.2 martin
3 1.1.2.2 martin /*
4 1.1.2.2 martin * Copyright (c) 2019 Jason R. Thorpe
5 1.1.2.2 martin * Copyright (c) 2012 Jonathan A. Kollasch
6 1.1.2.2 martin * All rights reserved.
7 1.1.2.2 martin *
8 1.1.2.2 martin * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 martin * modification, are permitted provided that the following conditions
10 1.1.2.2 martin * are met:
11 1.1.2.2 martin * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 martin * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 martin * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 martin * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 martin * documentation and/or other materials provided with the distribution.
16 1.1.2.2 martin *
17 1.1.2.2 martin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 1.1.2.2 martin * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 1.1.2.2 martin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1.1.2.2 martin * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21 1.1.2.2 martin * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 1.1.2.2 martin * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 1.1.2.2 martin * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 1.1.2.2 martin * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 1.1.2.2 martin * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 1.1.2.2 martin * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 1.1.2.2 martin * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 martin */
29 1.1.2.2 martin
30 1.1.2.2 martin #ifndef _BCM2835_BSCVAR_H
31 1.1.2.2 martin #define _BCM2835_BSCVAR_H
32 1.1.2.2 martin
33 1.1.2.2 martin #include <dev/i2c/i2cvar.h>
34 1.1.2.2 martin
35 1.1.2.2 martin typedef enum {
36 1.1.2.2 martin BSC_EXEC_STATE_IDLE = 0,
37 1.1.2.2 martin BSC_EXEC_STATE_SEND_ADDR = 1,
38 1.1.2.2 martin BSC_EXEC_STATE_SEND_CMD = 2,
39 1.1.2.2 martin BSC_EXEC_STATE_SEND_DATA = 3,
40 1.1.2.2 martin BSC_EXEC_STATE_RECV_DATA = 4,
41 1.1.2.2 martin BSC_EXEC_STATE_DONE = 5,
42 1.1.2.2 martin BSC_EXEC_STATE_ERROR = 6,
43 1.1.2.2 martin } bsc_exec_state_t;
44 1.1.2.2 martin
45 1.1.2.2 martin #define BSC_EXEC_STATE_SENDING(sc) \
46 1.1.2.2 martin ((sc)->sc_exec_state >= BSC_EXEC_STATE_SEND_ADDR && \
47 1.1.2.2 martin (sc)->sc_exec_state <= BSC_EXEC_STATE_SEND_DATA)
48 1.1.2.2 martin
49 1.1.2.2 martin #define BSC_EXEC_STATE_RECEIVING(sc) \
50 1.1.2.2 martin ((sc)->sc_exec_state == BSC_EXEC_STATE_RECV_DATA)
51 1.1.2.2 martin
52 1.1.2.2 martin struct bsciic_softc {
53 1.1.2.2 martin device_t sc_dev;
54 1.1.2.2 martin bus_space_tag_t sc_iot;
55 1.1.2.2 martin bus_space_handle_t sc_ioh;
56 1.1.2.2 martin struct i2c_controller sc_i2c;
57 1.1.2.2 martin void *sc_inth;
58 1.1.2.2 martin
59 1.1.2.2 martin struct clk *sc_clk;
60 1.1.2.2 martin u_int sc_frequency;
61 1.1.2.2 martin u_int sc_clkrate;
62 1.1.2.2 martin
63 1.1.2.2 martin kmutex_t sc_intr_lock;
64 1.1.2.2 martin kcondvar_t sc_intr_wait;
65 1.1.2.2 martin
66 1.1.2.2 martin struct {
67 1.1.2.2 martin i2c_op_t op;
68 1.1.2.2 martin i2c_addr_t addr;
69 1.1.2.2 martin const void *cmdbuf;
70 1.1.2.2 martin size_t cmdlen;
71 1.1.2.2 martin void *databuf;
72 1.1.2.2 martin size_t datalen;
73 1.1.2.2 martin int flags;
74 1.1.2.2 martin } sc_exec;
75 1.1.2.2 martin
76 1.1.2.2 martin /*
77 1.1.2.2 martin * Everything below here protected by the i2c controller lock
78 1.1.2.2 martin * /and/ sc_intr_lock (if we're using interrupts).
79 1.1.2.2 martin */
80 1.1.2.2 martin
81 1.1.2.2 martin bsc_exec_state_t sc_exec_state;
82 1.1.2.2 martin
83 1.1.2.2 martin uint8_t *sc_buf;
84 1.1.2.2 martin size_t sc_bufpos;
85 1.1.2.2 martin size_t sc_buflen;
86 1.1.2.2 martin
87 1.1.2.2 martin uint32_t sc_c_bits;
88 1.1.2.2 martin bool sc_expecting_interrupt;
89 1.1.2.2 martin };
90 1.1.2.2 martin
91 1.1.2.2 martin void bsciic_attach(struct bsciic_softc *);
92 1.1.2.2 martin
93 1.1.2.2 martin int bsciic_acquire_bus(void *, int);
94 1.1.2.2 martin void bsciic_release_bus(void *, int);
95 1.1.2.2 martin int bsciic_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
96 1.1.2.2 martin void *, size_t, int);
97 1.1.2.2 martin
98 1.1.2.2 martin int bsciic_intr(void *);
99 1.1.2.2 martin
100 1.1.2.2 martin #endif /* !_BCM2835_BSCVAR_H */
101