1*580d00f4SEmmanuel Vadot /*- 2*580d00f4SEmmanuel Vadot * Copyright (C) 2008 MARVELL INTERNATIONAL LTD. 3*580d00f4SEmmanuel Vadot * All rights reserved. 4*580d00f4SEmmanuel Vadot * 5*580d00f4SEmmanuel Vadot * Developed by Semihalf. 6*580d00f4SEmmanuel Vadot * 7*580d00f4SEmmanuel Vadot * Redistribution and use in source and binary forms, with or without 8*580d00f4SEmmanuel Vadot * modification, are permitted provided that the following conditions 9*580d00f4SEmmanuel Vadot * are met: 10*580d00f4SEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright 11*580d00f4SEmmanuel Vadot * notice, this list of conditions and the following disclaimer. 12*580d00f4SEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright 13*580d00f4SEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the 14*580d00f4SEmmanuel Vadot * documentation and/or other materials provided with the distribution. 15*580d00f4SEmmanuel Vadot * 3. Neither the name of MARVELL nor the names of contributors 16*580d00f4SEmmanuel Vadot * may be used to endorse or promote products derived from this software 17*580d00f4SEmmanuel Vadot * without specific prior written permission. 18*580d00f4SEmmanuel Vadot * 19*580d00f4SEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20*580d00f4SEmmanuel Vadot * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*580d00f4SEmmanuel Vadot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*580d00f4SEmmanuel Vadot * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 23*580d00f4SEmmanuel Vadot * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24*580d00f4SEmmanuel Vadot * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25*580d00f4SEmmanuel Vadot * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26*580d00f4SEmmanuel Vadot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27*580d00f4SEmmanuel Vadot * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28*580d00f4SEmmanuel Vadot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29*580d00f4SEmmanuel Vadot * SUCH DAMAGE. 30*580d00f4SEmmanuel Vadot */ 31*580d00f4SEmmanuel Vadot 32*580d00f4SEmmanuel Vadot #ifndef _TWSI_H_ 33*580d00f4SEmmanuel Vadot #define _TWSI_H_ 34*580d00f4SEmmanuel Vadot 35*580d00f4SEmmanuel Vadot #include <dev/extres/clk/clk.h> 36*580d00f4SEmmanuel Vadot 37*580d00f4SEmmanuel Vadot struct twsi_baud_rate { 38*580d00f4SEmmanuel Vadot uint32_t raw; 39*580d00f4SEmmanuel Vadot int param; 40*580d00f4SEmmanuel Vadot int m; 41*580d00f4SEmmanuel Vadot int n; 42*580d00f4SEmmanuel Vadot }; 43*580d00f4SEmmanuel Vadot 44*580d00f4SEmmanuel Vadot struct twsi_softc { 45*580d00f4SEmmanuel Vadot device_t dev; 46*580d00f4SEmmanuel Vadot struct resource *res[2]; 47*580d00f4SEmmanuel Vadot struct mtx mutex; 48*580d00f4SEmmanuel Vadot device_t iicbus; 49*580d00f4SEmmanuel Vadot clk_t clk_core; 50*580d00f4SEmmanuel Vadot clk_t clk_reg; 51*580d00f4SEmmanuel Vadot void * intrhand; 52*580d00f4SEmmanuel Vadot bool have_intr; 53*580d00f4SEmmanuel Vadot 54*580d00f4SEmmanuel Vadot struct iic_msg *msgs; 55*580d00f4SEmmanuel Vadot uint32_t nmsgs; 56*580d00f4SEmmanuel Vadot uint32_t msg_idx; 57*580d00f4SEmmanuel Vadot uint16_t sent_bytes; 58*580d00f4SEmmanuel Vadot uint16_t recv_bytes; 59*580d00f4SEmmanuel Vadot int transfer; 60*580d00f4SEmmanuel Vadot int error; 61*580d00f4SEmmanuel Vadot int debug; 62*580d00f4SEmmanuel Vadot uint32_t control_val; 63*580d00f4SEmmanuel Vadot bool iflag_w1c; 64*580d00f4SEmmanuel Vadot 65*580d00f4SEmmanuel Vadot bus_size_t reg_data; 66*580d00f4SEmmanuel Vadot bus_size_t reg_slave_addr; 67*580d00f4SEmmanuel Vadot bus_size_t reg_slave_ext_addr; 68*580d00f4SEmmanuel Vadot bus_size_t reg_control; 69*580d00f4SEmmanuel Vadot bus_size_t reg_status; 70*580d00f4SEmmanuel Vadot bus_size_t reg_baud_rate; 71*580d00f4SEmmanuel Vadot bus_size_t reg_soft_reset; 72*580d00f4SEmmanuel Vadot struct twsi_baud_rate baud_rate[IIC_FASTEST + 1]; 73*580d00f4SEmmanuel Vadot }; 74*580d00f4SEmmanuel Vadot 75*580d00f4SEmmanuel Vadot DECLARE_CLASS(twsi_driver); 76*580d00f4SEmmanuel Vadot 77*580d00f4SEmmanuel Vadot #define TWSI_BAUD_RATE_PARAM(M,N) ((((M) << 3) | ((N) & 0x7)) & 0x7f) 78*580d00f4SEmmanuel Vadot 79*580d00f4SEmmanuel Vadot int twsi_attach(device_t); 80*580d00f4SEmmanuel Vadot int twsi_detach(device_t); 81*580d00f4SEmmanuel Vadot 82*580d00f4SEmmanuel Vadot #endif /* _TWSI_H_ */ 83