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 */ 2848a225d4SKonstantin Belousov #ifndef __DEV_SMBUS_SMBCONF_H 2948a225d4SKonstantin Belousov #define __DEV_SMBUS_SMBCONF_H 30d70424edSNicolas Souchu 31d70424edSNicolas Souchu #include <sys/queue.h> 32d70424edSNicolas Souchu 33d7bcbf63SMatthew Dillon #define SMBPRI (PZERO+8) /* XXX sleep/wakeup queue priority */ 34d70424edSNicolas Souchu 35d70424edSNicolas Souchu #define n(flags) (~(flags) & (flags)) 36d70424edSNicolas Souchu 3794dce599SAndriy Gapon /* Order constants for smbus children. */ 3894dce599SAndriy Gapon #define SMBUS_ORDER_HINTED 20 3994dce599SAndriy Gapon #define SMBUS_ORDER_PNP 40 4094dce599SAndriy Gapon 41d70424edSNicolas Souchu /* 42d70424edSNicolas Souchu * How tsleep() is called in smb_request_bus(). 43d70424edSNicolas Souchu */ 44d70424edSNicolas Souchu #define SMB_DONTWAIT 0 45d70424edSNicolas Souchu #define SMB_NOINTR 0 46d70424edSNicolas Souchu #define SMB_WAIT 0x1 47d70424edSNicolas Souchu #define SMB_INTR 0x2 48d70424edSNicolas Souchu 49d70424edSNicolas Souchu /* 503ab1f056SNicolas Souchu * callback index 513ab1f056SNicolas Souchu */ 523ab1f056SNicolas Souchu #define SMB_REQUEST_BUS 0x1 533ab1f056SNicolas Souchu #define SMB_RELEASE_BUS 0x2 543ab1f056SNicolas Souchu 553ab1f056SNicolas Souchu /* 56d70424edSNicolas Souchu * SMB bus errors 57d70424edSNicolas Souchu */ 58d70424edSNicolas Souchu #define SMB_ENOERR 0x0 59d70424edSNicolas Souchu #define SMB_EBUSERR 0x1 603ab1f056SNicolas Souchu #define SMB_ENOTSUPP 0x2 61ba81c311SNicolas Souchu #define SMB_ENOACK 0x4 62ba81c311SNicolas Souchu #define SMB_ECOLLI 0x8 63ba81c311SNicolas Souchu #define SMB_EABORT 0x10 64ba81c311SNicolas Souchu #define SMB_ETIMEOUT 0x20 65ba81c311SNicolas Souchu #define SMB_EBUSY 0x40 667048a99cSJohn Baldwin #define SMB_EINVAL 0x100 67d70424edSNicolas Souchu 68d70424edSNicolas Souchu /* 69d70424edSNicolas Souchu * How Quick command is executed 70d70424edSNicolas Souchu */ 71d70424edSNicolas Souchu #define SMB_QWRITE 0x0 72d70424edSNicolas Souchu #define SMB_QREAD 0x1 73d70424edSNicolas Souchu 74d70424edSNicolas Souchu /* 75d70424edSNicolas Souchu * ivars codes 76d70424edSNicolas Souchu */ 77202379afSMichael Gmelin enum smbus_ivars { 78202379afSMichael Gmelin SMBUS_IVAR_ADDR, /* slave address of the device */ 79202379afSMichael Gmelin }; 80d70424edSNicolas Souchu 817048a99cSJohn Baldwin int smbus_request_bus(device_t, device_t, int); 827048a99cSJohn Baldwin int smbus_release_bus(device_t, device_t); 837048a99cSJohn Baldwin device_t smbus_alloc_bus(device_t); 847048a99cSJohn Baldwin int smbus_error(int error); 85d70424edSNicolas Souchu 867048a99cSJohn Baldwin void smbus_intr(device_t, u_char, char low, char high, int error); 87d70424edSNicolas Souchu 88202379afSMichael Gmelin #define SMBUS_ACCESSOR(var, ivar, type) \ 89202379afSMichael Gmelin __BUS_ACCESSOR(smbus, var, SMBUS, ivar, type) 90202379afSMichael Gmelin 91202379afSMichael Gmelin SMBUS_ACCESSOR(addr, ADDR, int) 92202379afSMichael Gmelin 93202379afSMichael Gmelin #undef SMBUS_ACCESSOR 947048a99cSJohn Baldwin 957048a99cSJohn Baldwin extern driver_t smbus_driver; 96d70424edSNicolas Souchu 97d70424edSNicolas Souchu #define smbus_quick(bus,slave,how) \ 98d70424edSNicolas Souchu (SMBUS_QUICK(device_get_parent(bus), slave, how)) 99d70424edSNicolas Souchu #define smbus_sendb(bus,slave,byte) \ 100d70424edSNicolas Souchu (SMBUS_SENDB(device_get_parent(bus), slave, byte)) 101d70424edSNicolas Souchu #define smbus_recvb(bus,slave,byte) \ 102d70424edSNicolas Souchu (SMBUS_RECVB(device_get_parent(bus), slave, byte)) 103d70424edSNicolas Souchu #define smbus_writeb(bus,slave,cmd,byte) \ 104d70424edSNicolas Souchu (SMBUS_WRITEB(device_get_parent(bus), slave, cmd, byte)) 105d70424edSNicolas Souchu #define smbus_writew(bus,slave,cmd,word) \ 106d70424edSNicolas Souchu (SMBUS_WRITEW(device_get_parent(bus), slave, cmd, word)) 107d70424edSNicolas Souchu #define smbus_readb(bus,slave,cmd,byte) \ 108d70424edSNicolas Souchu (SMBUS_READB(device_get_parent(bus), slave, cmd, byte)) 109d70424edSNicolas Souchu #define smbus_readw(bus,slave,cmd,word) \ 110d70424edSNicolas Souchu (SMBUS_READW(device_get_parent(bus), slave, cmd, word)) 111d70424edSNicolas Souchu #define smbus_pcall(bus,slave,cmd,sdata,rdata) \ 112d70424edSNicolas Souchu (SMBUS_PCALL(device_get_parent(bus), slave, cmd, sdata, rdata)) 113d70424edSNicolas Souchu #define smbus_bwrite(bus,slave,cmd,count,buf) \ 114d70424edSNicolas Souchu (SMBUS_BWRITE(device_get_parent(bus), slave, cmd, count, buf)) 115d70424edSNicolas Souchu #define smbus_bread(bus,slave,cmd,count,buf) \ 116d70424edSNicolas Souchu (SMBUS_BREAD(device_get_parent(bus), slave, cmd, count, buf)) 117202379afSMichael Gmelin #define smbus_trans(bus,slave,cmd,op,wbuf,wcount,rbuf,rcount,actualp) \ 118202379afSMichael Gmelin (SMBUS_TRANS(device_get_parent(bus), slave, cmd, op, \ 119202379afSMichael Gmelin wbuf, wcount, rbuf, rcount, actualp)) 120d70424edSNicolas Souchu 121c17d4340SNicolas Souchu #define SMBUS_MODVER 1 122c17d4340SNicolas Souchu #define SMBUS_MINVER 1 123c17d4340SNicolas Souchu #define SMBUS_MAXVER 1 124c17d4340SNicolas Souchu #define SMBUS_PREFVER SMBUS_MODVER 125c17d4340SNicolas Souchu 12648a225d4SKonstantin Belousov #endif /* __DEV_SMBUS_SMBCONF_H */ 127