xref: /netbsd-src/sys/dev/ic/dwiic_var.h (revision 91893f3cc32a3d4d6f9251c3dde077210502e8cf)
1 /* $NetBSD: dwiic_var.h,v 1.3 2022/10/19 22:34:10 riastradh Exp $ */
2 
3 /*-
4  * Copyright (c) 2017 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Manuel Bouyer.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <dev/i2c/i2cvar.h>
33 
34 enum dwiic_type {
35 	dwiic_type_generic,
36 	dwiic_type_sunrisepoint
37 };
38 
39 struct dwiic_softc {
40 	device_t		sc_dev;
41 
42 	bus_space_tag_t		sc_iot;
43 	bus_space_handle_t	sc_ioh;
44 	void			*sc_ih;
45 
46 	enum dwiic_type		sc_type;
47 
48 	bool			(*sc_power)(struct dwiic_softc *, bool);
49 
50 	struct i2cbus_attach_args sc_iba;
51 	device_t		sc_iic;
52 
53 	int			sc_poll;
54 	kmutex_t		sc_int_lock;
55 	kcondvar_t		sc_int_readwait;
56 	kcondvar_t		sc_int_writewait;
57 	kcondvar_t		sc_int_stopwait;
58 
59 	uint32_t		master_cfg;
60 	uint16_t		ss_hcnt, ss_lcnt, fs_hcnt, fs_lcnt;
61 	uint32_t		sda_hold_time;
62 	int			tx_fifo_depth;
63 	int			rx_fifo_depth;
64 
65 	struct i2c_controller	sc_i2c_tag;
66 	kmutex_t		sc_i2c_lock;
67 	struct {
68 		i2c_op_t	op;
69 		void		*buf;
70 		size_t		len;
71 		int		flags;
72 		volatile int	error;
73 	} sc_i2c_xfer;
74 
75 	volatile bool		sc_attached;
76 };
77 
78 bool		dwiic_attach(struct dwiic_softc *);
79 int		dwiic_detach(device_t, int);
80 bool		dwiic_suspend(device_t, const pmf_qual_t *);
81 bool		dwiic_resume(device_t, const pmf_qual_t *);
82 
83 int		dwiic_intr(void *);
84