xref: /freebsd/sys/dev/iicbus/controller/twsi/twsi.h (revision be82b3a0bf72ed3b5f01ac9fcd8dcd3802e3c742)
1580d00f4SEmmanuel Vadot /*-
2580d00f4SEmmanuel Vadot  * Copyright (C) 2008 MARVELL INTERNATIONAL LTD.
3580d00f4SEmmanuel Vadot  * All rights reserved.
4580d00f4SEmmanuel Vadot  *
5580d00f4SEmmanuel Vadot  * Developed by Semihalf.
6580d00f4SEmmanuel Vadot  *
7580d00f4SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
8580d00f4SEmmanuel Vadot  * modification, are permitted provided that the following conditions
9580d00f4SEmmanuel Vadot  * are met:
10580d00f4SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
11580d00f4SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
12580d00f4SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
13580d00f4SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
14580d00f4SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
15580d00f4SEmmanuel Vadot  * 3. Neither the name of MARVELL nor the names of contributors
16580d00f4SEmmanuel Vadot  *    may be used to endorse or promote products derived from this software
17580d00f4SEmmanuel Vadot  *    without specific prior written permission.
18580d00f4SEmmanuel Vadot  *
19580d00f4SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20580d00f4SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21580d00f4SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22580d00f4SEmmanuel Vadot  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
23580d00f4SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24580d00f4SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25580d00f4SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26580d00f4SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27580d00f4SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28580d00f4SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29580d00f4SEmmanuel Vadot  * SUCH DAMAGE.
30580d00f4SEmmanuel Vadot  */
31580d00f4SEmmanuel Vadot 
32580d00f4SEmmanuel Vadot #ifndef _TWSI_H_
33580d00f4SEmmanuel Vadot #define	_TWSI_H_
34580d00f4SEmmanuel Vadot 
35*be82b3a0SEmmanuel Vadot #include <dev/clk/clk.h>
36580d00f4SEmmanuel Vadot 
37580d00f4SEmmanuel Vadot struct twsi_baud_rate {
38580d00f4SEmmanuel Vadot 	uint32_t	raw;
39580d00f4SEmmanuel Vadot 	int		param;
40580d00f4SEmmanuel Vadot 	int		m;
41580d00f4SEmmanuel Vadot 	int		n;
42580d00f4SEmmanuel Vadot };
43580d00f4SEmmanuel Vadot 
44580d00f4SEmmanuel Vadot struct twsi_softc {
45580d00f4SEmmanuel Vadot 	device_t	dev;
46580d00f4SEmmanuel Vadot 	struct resource	*res[2];
47580d00f4SEmmanuel Vadot 	struct mtx	mutex;
48580d00f4SEmmanuel Vadot 	device_t	iicbus;
49580d00f4SEmmanuel Vadot 	clk_t		clk_core;
50580d00f4SEmmanuel Vadot 	clk_t		clk_reg;
51580d00f4SEmmanuel Vadot 	void *			intrhand;
52580d00f4SEmmanuel Vadot 	bool			have_intr;
53580d00f4SEmmanuel Vadot 
54580d00f4SEmmanuel Vadot 	struct iic_msg		*msgs;
55580d00f4SEmmanuel Vadot 	uint32_t		nmsgs;
56580d00f4SEmmanuel Vadot 	uint32_t		msg_idx;
57580d00f4SEmmanuel Vadot 	uint16_t		sent_bytes;
58580d00f4SEmmanuel Vadot 	uint16_t		recv_bytes;
59580d00f4SEmmanuel Vadot 	int			transfer;
60580d00f4SEmmanuel Vadot 	int			error;
61580d00f4SEmmanuel Vadot 	int			debug;
62580d00f4SEmmanuel Vadot 	uint32_t		control_val;
63580d00f4SEmmanuel Vadot 	bool			iflag_w1c;
64580d00f4SEmmanuel Vadot 
65580d00f4SEmmanuel Vadot 	bus_size_t	reg_data;
66580d00f4SEmmanuel Vadot 	bus_size_t	reg_slave_addr;
67580d00f4SEmmanuel Vadot 	bus_size_t	reg_slave_ext_addr;
68580d00f4SEmmanuel Vadot 	bus_size_t	reg_control;
69580d00f4SEmmanuel Vadot 	bus_size_t	reg_status;
70580d00f4SEmmanuel Vadot 	bus_size_t	reg_baud_rate;
71580d00f4SEmmanuel Vadot 	bus_size_t	reg_soft_reset;
72580d00f4SEmmanuel Vadot 	struct twsi_baud_rate  baud_rate[IIC_FASTEST + 1];
73580d00f4SEmmanuel Vadot };
74580d00f4SEmmanuel Vadot 
75580d00f4SEmmanuel Vadot DECLARE_CLASS(twsi_driver);
76580d00f4SEmmanuel Vadot 
77580d00f4SEmmanuel Vadot #define	TWSI_BAUD_RATE_PARAM(M,N)	((((M) << 3) | ((N) & 0x7)) & 0x7f)
78580d00f4SEmmanuel Vadot 
79580d00f4SEmmanuel Vadot int twsi_attach(device_t);
80580d00f4SEmmanuel Vadot int twsi_detach(device_t);
81580d00f4SEmmanuel Vadot 
82580d00f4SEmmanuel Vadot #endif /* _TWSI_H_ */
83