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