1d70424edSNicolas Souchu /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3718cf2ccSPedro F. Giffuni * 4d70424edSNicolas Souchu * Copyright (c) 1998 Nicolas Souchu 5d70424edSNicolas Souchu * All rights reserved. 6d70424edSNicolas Souchu * 7d70424edSNicolas Souchu * Redistribution and use in source and binary forms, with or without 8d70424edSNicolas Souchu * modification, are permitted provided that the following conditions 9d70424edSNicolas Souchu * are met: 10d70424edSNicolas Souchu * 1. Redistributions of source code must retain the above copyright 11d70424edSNicolas Souchu * notice, this list of conditions and the following disclaimer. 12d70424edSNicolas Souchu * 2. Redistributions in binary form must reproduce the above copyright 13d70424edSNicolas Souchu * notice, this list of conditions and the following disclaimer in the 14d70424edSNicolas Souchu * documentation and/or other materials provided with the distribution. 15d70424edSNicolas Souchu * 16d70424edSNicolas Souchu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17d70424edSNicolas Souchu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18d70424edSNicolas Souchu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19d70424edSNicolas Souchu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20d70424edSNicolas Souchu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21d70424edSNicolas Souchu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22d70424edSNicolas Souchu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23d70424edSNicolas Souchu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24d70424edSNicolas Souchu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25d70424edSNicolas Souchu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26d70424edSNicolas Souchu * SUCH DAMAGE. 27d70424edSNicolas Souchu * 28c3aac50fSPeter Wemm * $FreeBSD$ 29d70424edSNicolas Souchu */ 3048a225d4SKonstantin Belousov #ifndef __DEV_SMBUS_SMBCONF_H 3148a225d4SKonstantin Belousov #define __DEV_SMBUS_SMBCONF_H 32d70424edSNicolas Souchu 33d70424edSNicolas Souchu #include <sys/queue.h> 34d70424edSNicolas Souchu 35d7bcbf63SMatthew Dillon #define SMBPRI (PZERO+8) /* XXX sleep/wakeup queue priority */ 36d70424edSNicolas Souchu 37d70424edSNicolas Souchu #define n(flags) (~(flags) & (flags)) 38d70424edSNicolas Souchu 3994dce599SAndriy Gapon /* Order constants for smbus children. */ 4094dce599SAndriy Gapon #define SMBUS_ORDER_HINTED 20 4194dce599SAndriy Gapon #define SMBUS_ORDER_PNP 40 4294dce599SAndriy Gapon 43d70424edSNicolas Souchu /* 44d70424edSNicolas Souchu * How tsleep() is called in smb_request_bus(). 45d70424edSNicolas Souchu */ 46d70424edSNicolas Souchu #define SMB_DONTWAIT 0 47d70424edSNicolas Souchu #define SMB_NOINTR 0 48d70424edSNicolas Souchu #define SMB_WAIT 0x1 49d70424edSNicolas Souchu #define SMB_INTR 0x2 50d70424edSNicolas Souchu 51d70424edSNicolas Souchu /* 523ab1f056SNicolas Souchu * callback index 533ab1f056SNicolas Souchu */ 543ab1f056SNicolas Souchu #define SMB_REQUEST_BUS 0x1 553ab1f056SNicolas Souchu #define SMB_RELEASE_BUS 0x2 563ab1f056SNicolas Souchu 573ab1f056SNicolas Souchu /* 58d70424edSNicolas Souchu * SMB bus errors 59d70424edSNicolas Souchu */ 60d70424edSNicolas Souchu #define SMB_ENOERR 0x0 61d70424edSNicolas Souchu #define SMB_EBUSERR 0x1 623ab1f056SNicolas Souchu #define SMB_ENOTSUPP 0x2 63ba81c311SNicolas Souchu #define SMB_ENOACK 0x4 64ba81c311SNicolas Souchu #define SMB_ECOLLI 0x8 65ba81c311SNicolas Souchu #define SMB_EABORT 0x10 66ba81c311SNicolas Souchu #define SMB_ETIMEOUT 0x20 67ba81c311SNicolas Souchu #define SMB_EBUSY 0x40 687048a99cSJohn Baldwin #define SMB_EINVAL 0x100 69d70424edSNicolas Souchu 70d70424edSNicolas Souchu /* 71d70424edSNicolas Souchu * How Quick command is executed 72d70424edSNicolas Souchu */ 73d70424edSNicolas Souchu #define SMB_QWRITE 0x0 74d70424edSNicolas Souchu #define SMB_QREAD 0x1 75d70424edSNicolas Souchu 76d70424edSNicolas Souchu /* 77d70424edSNicolas Souchu * ivars codes 78d70424edSNicolas Souchu */ 79202379afSMichael Gmelin enum smbus_ivars { 80202379afSMichael Gmelin SMBUS_IVAR_ADDR, /* slave address of the device */ 81202379afSMichael Gmelin }; 82d70424edSNicolas Souchu 837048a99cSJohn Baldwin int smbus_request_bus(device_t, device_t, int); 847048a99cSJohn Baldwin int smbus_release_bus(device_t, device_t); 857048a99cSJohn Baldwin device_t smbus_alloc_bus(device_t); 867048a99cSJohn Baldwin int smbus_error(int error); 87d70424edSNicolas Souchu 887048a99cSJohn Baldwin void smbus_intr(device_t, u_char, char low, char high, int error); 89d70424edSNicolas Souchu 90202379afSMichael Gmelin #define SMBUS_ACCESSOR(var, ivar, type) \ 91202379afSMichael Gmelin __BUS_ACCESSOR(smbus, var, SMBUS, ivar, type) 92202379afSMichael Gmelin 93202379afSMichael Gmelin SMBUS_ACCESSOR(addr, ADDR, int) 94202379afSMichael Gmelin 95202379afSMichael Gmelin #undef SMBUS_ACCESSOR 967048a99cSJohn Baldwin 977048a99cSJohn Baldwin extern driver_t smbus_driver; 98d70424edSNicolas Souchu 99d70424edSNicolas Souchu #define smbus_quick(bus,slave,how) \ 100d70424edSNicolas Souchu (SMBUS_QUICK(device_get_parent(bus), slave, how)) 101d70424edSNicolas Souchu #define smbus_sendb(bus,slave,byte) \ 102d70424edSNicolas Souchu (SMBUS_SENDB(device_get_parent(bus), slave, byte)) 103d70424edSNicolas Souchu #define smbus_recvb(bus,slave,byte) \ 104d70424edSNicolas Souchu (SMBUS_RECVB(device_get_parent(bus), slave, byte)) 105d70424edSNicolas Souchu #define smbus_writeb(bus,slave,cmd,byte) \ 106d70424edSNicolas Souchu (SMBUS_WRITEB(device_get_parent(bus), slave, cmd, byte)) 107d70424edSNicolas Souchu #define smbus_writew(bus,slave,cmd,word) \ 108d70424edSNicolas Souchu (SMBUS_WRITEW(device_get_parent(bus), slave, cmd, word)) 109d70424edSNicolas Souchu #define smbus_readb(bus,slave,cmd,byte) \ 110d70424edSNicolas Souchu (SMBUS_READB(device_get_parent(bus), slave, cmd, byte)) 111d70424edSNicolas Souchu #define smbus_readw(bus,slave,cmd,word) \ 112d70424edSNicolas Souchu (SMBUS_READW(device_get_parent(bus), slave, cmd, word)) 113d70424edSNicolas Souchu #define smbus_pcall(bus,slave,cmd,sdata,rdata) \ 114d70424edSNicolas Souchu (SMBUS_PCALL(device_get_parent(bus), slave, cmd, sdata, rdata)) 115d70424edSNicolas Souchu #define smbus_bwrite(bus,slave,cmd,count,buf) \ 116d70424edSNicolas Souchu (SMBUS_BWRITE(device_get_parent(bus), slave, cmd, count, buf)) 117d70424edSNicolas Souchu #define smbus_bread(bus,slave,cmd,count,buf) \ 118d70424edSNicolas Souchu (SMBUS_BREAD(device_get_parent(bus), slave, cmd, count, buf)) 119202379afSMichael Gmelin #define smbus_trans(bus,slave,cmd,op,wbuf,wcount,rbuf,rcount,actualp) \ 120202379afSMichael Gmelin (SMBUS_TRANS(device_get_parent(bus), slave, cmd, op, \ 121202379afSMichael Gmelin wbuf, wcount, rbuf, rcount, actualp)) 122d70424edSNicolas Souchu 123c17d4340SNicolas Souchu #define SMBUS_MODVER 1 124c17d4340SNicolas Souchu #define SMBUS_MINVER 1 125c17d4340SNicolas Souchu #define SMBUS_MAXVER 1 126c17d4340SNicolas Souchu #define SMBUS_PREFVER SMBUS_MODVER 127c17d4340SNicolas Souchu 12848a225d4SKonstantin Belousov #endif /* __DEV_SMBUS_SMBCONF_H */ 129