1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2019 Ian Lepore <ian@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 AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #ifndef __IICMUX_H 31 #define __IICMUX_H 32 33 #define IICMUX_MAX_BUSES 16 /* More than any available mux chip. */ 34 35 /* 36 * IICMUX_SELECT_IDLE instructs the mux hardware driver to do whatever it is 37 * configured to do when the downstream buses are idle. Hardware has varying 38 * capabilities; it may disconnect all downstream buses, or connect a specific 39 * bus, or just leave whatever bus was last used connected. Hardware which is 40 * capable of various choices will have some mechanism to configure the choice 41 * which is handled outside of the iicmux framework. 42 */ 43 #define IICMUX_SELECT_IDLE (-1) 44 45 /* 46 * The iicmux softc; chip drivers should embed one of these as the first member 47 * variable of their own softc struct, and must call iicmux_attach() to 48 * initialize it before calling any other iicmux functions. 49 */ 50 struct iicmux_softc { 51 device_t busdev; /* Upstream i2c bus (may not be our parent). */ 52 device_t dev; /* Ourself. */ 53 int maxbus; /* Index of highest populated busdevs slot. */ 54 int numbuses; /* Number of buses supported by the chip. */ 55 int debugmux; /* Write debug messages when > 0. */ 56 device_t childdevs[IICMUX_MAX_BUSES]; /* Child bus instances. */ 57 #ifdef FDT 58 phandle_t childnodes[IICMUX_MAX_BUSES]; /* Child bus fdt nodes. */ 59 #endif 60 }; 61 62 DECLARE_CLASS(iicmux_driver); 63 64 /* 65 * Helpers to call from attach/detach functions of chip-specific drivers. 66 * 67 * The iicmux_attach() function initializes the core driver's portion of the 68 * softc, and creates child iicbus instances for any children it can identify 69 * using hints and FDT data. If a chip driver does its own device_add_child() 70 * calls to add other downstream buses that participate in the mux switching, it 71 * must call iicmux_add_child() to inform the core driver of the downstream 72 * busidx<->device_t relationship. 73 */ 74 int iicmux_add_child(device_t dev, device_t child, int busidx); 75 int iicmux_attach(device_t dev, device_t busdev, int numbuses); 76 int iicmux_detach(device_t dev); 77 78 #endif 79