1930b3123SIan Lepore /*- 2*dbb77490SIan Lepore * SPDX-License-Identifier: BSD-2-Clause 3*dbb77490SIan Lepore * 4930b3123SIan Lepore * Copyright (c) 2017 Ian Lepore <ian@freebsd.org> 5930b3123SIan Lepore * 6930b3123SIan Lepore * Development sponsored by Microsemi, Inc. 7930b3123SIan Lepore * 8930b3123SIan Lepore * Redistribution and use in source and binary forms, with or without 9930b3123SIan Lepore * modification, are permitted provided that the following conditions 10930b3123SIan Lepore * are met: 11930b3123SIan Lepore * 1. Redistributions of source code must retain the above copyright 12930b3123SIan Lepore * notice, this list of conditions and the following disclaimer. 13930b3123SIan Lepore * 2. Redistributions in binary form must reproduce the above copyright 14930b3123SIan Lepore * notice, this list of conditions and the following disclaimer in the 15930b3123SIan Lepore * documentation and/or other materials provided with the distribution. 16930b3123SIan Lepore * 17930b3123SIan Lepore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18930b3123SIan Lepore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19930b3123SIan Lepore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20930b3123SIan Lepore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21930b3123SIan Lepore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22930b3123SIan Lepore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23930b3123SIan Lepore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24930b3123SIan Lepore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25930b3123SIan Lepore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26930b3123SIan Lepore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27930b3123SIan Lepore * SUCH DAMAGE. 28930b3123SIan Lepore */ 29930b3123SIan Lepore 30930b3123SIan Lepore /* 31930b3123SIan Lepore * Helper code to recover a hung i2c bus by bit-banging a recovery sequence. 32930b3123SIan Lepore */ 33930b3123SIan Lepore 34930b3123SIan Lepore #ifndef _IICBUS_IIC_RECOVER_BUS_H_ 35930b3123SIan Lepore #define _IICBUS_IIC_RECOVER_BUS_H_ 36930b3123SIan Lepore 37930b3123SIan Lepore struct iicrb_pin_access { 38930b3123SIan Lepore void *ctx; 39930b3123SIan Lepore int (*getsda)(void *ctx); 40930b3123SIan Lepore void (*setsda)(void *ctx, int value); 41930b3123SIan Lepore int (*getscl)(void *ctx); 42930b3123SIan Lepore void (*setscl)(void *ctx, int value); 43930b3123SIan Lepore }; 44930b3123SIan Lepore 45930b3123SIan Lepore /* 46930b3123SIan Lepore * Drive the bus-recovery logic by manipulating the line states using the 47930b3123SIan Lepore * caller-provided functions. This does not block or sleep or acquire any locks 48930b3123SIan Lepore * (unless the provided pin access functions do so). It uses DELAY() to pace 49930b3123SIan Lepore * bits on the bus. 50930b3123SIan Lepore * 51930b3123SIan Lepore * Returns 0 if the bus is functioning properly or IIC_EBUSERR if the recovery 52930b3123SIan Lepore * attempt failed and some slave device is still driving the bus. 53930b3123SIan Lepore */ 54930b3123SIan Lepore int iic_recover_bus(struct iicrb_pin_access *pins); 55930b3123SIan Lepore 56930b3123SIan Lepore #endif 57