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