1 /* $NetBSD: dwiic_var.h,v 1.4 2025/09/15 15:18:42 thorpej 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 int sc_poll; 51 kmutex_t sc_int_lock; 52 kcondvar_t sc_int_readwait; 53 kcondvar_t sc_int_writewait; 54 kcondvar_t sc_int_stopwait; 55 56 uint32_t master_cfg; 57 uint16_t ss_hcnt, ss_lcnt, fs_hcnt, fs_lcnt; 58 uint32_t sda_hold_time; 59 int tx_fifo_depth; 60 int rx_fifo_depth; 61 62 struct i2c_controller sc_i2c_tag; 63 kmutex_t sc_i2c_lock; 64 struct { 65 i2c_op_t op; 66 void *buf; 67 size_t len; 68 int flags; 69 volatile int error; 70 } sc_i2c_xfer; 71 72 volatile bool sc_attached; 73 }; 74 75 bool dwiic_attach(struct dwiic_softc *); 76 int dwiic_detach(device_t, int); 77 bool dwiic_suspend(device_t, const pmf_qual_t *); 78 bool dwiic_resume(device_t, const pmf_qual_t *); 79 80 int dwiic_intr(void *); 81