xref: /freebsd/sys/dev/iicbus/controller/qcom/geni_iic_var.h (revision 76113680635ea0c5972cbe8624a7d0d86270f569)
1 /*
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2025 Poul-Henning Kamp <phk@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef _GENIIIC_GENI_VAR_H_
30 #define _GENIIIC_GENI_VAR_H_
31 
32 #include "bus_if.h"
33 #include "device_if.h"
34 #include "iicbus_if.h"
35 
36 struct geniiic_softc {
37 	device_t	dev;
38 	device_t	iicbus;
39 	struct resource	*regs_res;
40 	int		regs_rid;
41 	struct resource	*intr_res;
42 	int		intr_rid;
43 	void		*intr_handle;
44 	int		intr_type;
45 	uint32_t	intr_mask;
46 
47 	bool		bus_locked;
48 
49 	bool		platform_attached;
50 
51 	int		nfail;
52 	unsigned	worst;
53 
54 	unsigned	rx_fifo_size;
55 	bool		rx_complete;
56 	bool		rx_fifo;
57 	uint8_t		*rx_buf;
58 	unsigned	rx_len;
59 	uint32_t	cmd_status;
60 
61 	// Protect access to the bus
62 	struct sx	bus_lock;
63 	struct sx	real_bus_lock;
64 
65 	// Coordinate with interrupt routine
66 	struct mtx	intr_lock;
67 };
68 
69 typedef struct geniiic_softc geniiic_softc_t;
70 
71 int geniiic_attach(geniiic_softc_t *sc);
72 int geniiic_detach(geniiic_softc_t *sc);
73 int geniiic_suspend(geniiic_softc_t *sc);
74 int geniiic_resume(geniiic_softc_t *sc);
75 
76 extern iicbus_transfer_t geniiic_transfer;
77 extern iicbus_reset_t   geniiic_reset;
78 extern iicbus_callback_t geniiic_callback;
79 
80 #endif /* _GENIIIC_GENI_VAR_H_ */
81