Home | History | Annotate | Line # | Download | only in broadcom
      1 /*	$NetBSD: bcm2835_bscvar.h,v 1.1 2020/03/31 14:39:44 jmcneill Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2019 Jason R. Thorpe
      5  * Copyright (c) 2012 Jonathan A. Kollasch
      6  * All rights reserved.
      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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER OR
     21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     27  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef _BCM2835_BSCVAR_H
     31 #define _BCM2835_BSCVAR_H
     32 
     33 #include <dev/i2c/i2cvar.h>
     34 
     35 typedef enum {
     36 	BSC_EXEC_STATE_IDLE		= 0,
     37 	BSC_EXEC_STATE_SEND_ADDR	= 1,
     38 	BSC_EXEC_STATE_SEND_CMD		= 2,
     39 	BSC_EXEC_STATE_SEND_DATA	= 3,
     40 	BSC_EXEC_STATE_RECV_DATA	= 4,
     41 	BSC_EXEC_STATE_DONE		= 5,
     42 	BSC_EXEC_STATE_ERROR		= 6,
     43 } bsc_exec_state_t;
     44 
     45 #define	BSC_EXEC_STATE_SENDING(sc)	\
     46 	((sc)->sc_exec_state >= BSC_EXEC_STATE_SEND_ADDR && \
     47 	(sc)->sc_exec_state <= BSC_EXEC_STATE_SEND_DATA)
     48 
     49 #define	BSC_EXEC_STATE_RECEIVING(sc)	\
     50 	((sc)->sc_exec_state == BSC_EXEC_STATE_RECV_DATA)
     51 
     52 struct bsciic_softc {
     53 	device_t sc_dev;
     54 	bus_space_tag_t sc_iot;
     55 	bus_space_handle_t sc_ioh;
     56 	struct i2c_controller sc_i2c;
     57 	void *sc_inth;
     58 
     59 	struct clk *sc_clk;
     60 	u_int sc_frequency;
     61 	u_int sc_clkrate;
     62 
     63 	kmutex_t sc_intr_lock;
     64 	kcondvar_t sc_intr_wait;
     65 
     66 	struct {
     67 		i2c_op_t op;
     68 		i2c_addr_t addr;
     69 		const void *cmdbuf;
     70 		size_t cmdlen;
     71 		void *databuf;
     72 		size_t datalen;
     73 		int flags;
     74 	} sc_exec;
     75 
     76 	/*
     77 	 * Everything below here protected by the i2c controller lock
     78 	 * /and/ sc_intr_lock (if we're using interrupts).
     79 	 */
     80 
     81 	bsc_exec_state_t sc_exec_state;
     82 
     83 	uint8_t *sc_buf;
     84 	size_t sc_bufpos;
     85 	size_t sc_buflen;
     86 
     87 	uint32_t sc_c_bits;
     88 	bool sc_expecting_interrupt;
     89 };
     90 
     91 void bsciic_attach(struct bsciic_softc *);
     92 
     93 int  bsciic_acquire_bus(void *, int);
     94 void bsciic_release_bus(void *, int);
     95 int  bsciic_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
     96 		 void *, size_t, int);
     97 
     98 int bsciic_intr(void *);
     99 
    100 #endif /* !_BCM2835_BSCVAR_H */
    101