1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Common SMBus definitions			File: cfe_smbus.h
5    *
6    *  Driver common data structures for SMBus devices.   The
7    *  higher-level (device-specific) SMBus drivers talk to this, and
8    *  via these structures we end up at platofrm-specific SMbus
9    *  handlers.
10    *
11    *  Author:  Mitch Lichtenberg
12    *
13    *********************************************************************
14    *
15    *  Copyright 2000,2001,2002,2003
16    *  Broadcom Corporation. All rights reserved.
17    *
18    *  This software is furnished under license and may be used and
19    *  copied only in accordance with the following terms and
20    *  conditions.  Subject to these conditions, you may download,
21    *  copy, install, use, modify and distribute modified or unmodified
22    *  copies of this software in source and/or binary form.  No title
23    *  or ownership is transferred hereby.
24    *
25    *  1) Any source code used, modified or distributed must reproduce
26    *     and retain this copyright notice and list of conditions
27    *     as they appear in the source file.
28    *
29    *  2) No right is granted to use any trade name, trademark, or
30    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
31    *     name may not be used to endorse or promote products derived
32    *     from this software without the prior written permission of
33    *     Broadcom Corporation.
34    *
35    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
36    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
37    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
38    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
39    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
40    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
41    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
43    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
46    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
47    *     THE POSSIBILITY OF SUCH DAMAGE.
48    ********************************************************************* */
49
50
51typedef struct cfe_smbus_channel_s cfe_smbus_channel_t;
52typedef struct cfe_smbus_s cfe_smbus_t;
53
54struct cfe_smbus_s {
55    /* Attach channel */
56    cfe_smbus_channel_t * (*attach)(cfe_smbus_t *,uint64_t probe_a,uint64_t probe_b);
57    /* initialize channel */
58    int (*init)(cfe_smbus_channel_t *chan);
59    /* Write 'n' bytes to device (stop condition after write) */
60    int (*write)(cfe_smbus_channel_t *chan,uint8_t slave,uint8_t *buf,int len);
61    /* Read 'n' bytes from device (stop condition after each read) */
62    int (*read)(cfe_smbus_channel_t *chan,uint8_t slave,uint8_t *buf,int len);
63    /* Transaction: Write 1 byte and read 'n' bytes (no stop between write and read) */
64    int (*xact)(cfe_smbus_channel_t *chan,uint8_t slave,uint8_t cmd,uint8_t *buf,int len);
65    /* Quick command */
66    int (*qcmd)(cfe_smbus_channel_t *chan,uint8_t slave,int rw);
67    /* Extended mode Read command */
68    int (*xread)(cfe_smbus_channel_t *chan,uint8_t slave,uint8_t cmd,uint8_t numcmd,uint8_t numdat, int *buf);
69    /* Extended mode Write command */
70    int (*xwrite)(cfe_smbus_channel_t *chan,uint8_t slave,uint8_t cmd,uint8_t numcmd,uint8_t numdat, int *buf);
71};
72
73#define SMBUS_QCMD_R	0
74#define SMBUS_QCMD_W	1
75
76struct cfe_smbus_channel_s {
77    cfe_smbus_t *ops;
78    void *softc;
79};
80
81#define SMBUS_CHANNELS_MAX	4
82
83extern cfe_smbus_channel_t *cfe_smbus_channels[SMBUS_CHANNELS_MAX];
84
85#define SMBUS_CHANNEL(chanidx) cfe_smbus_channels[chanidx]
86#define SMBUS_INIT(chan) (chan)->ops->init(chan)
87#define SMBUS_READ(chan,slave,buf,len) (chan)->ops->read(chan,slave,buf,len)
88#define SMBUS_WRITE(chan,slave,buf,len) (chan)->ops->write(chan,slave,buf,len)
89#define SMBUS_XACT(chan,slave,cmd,buf,len) (chan)->ops->xact(chan,slave,cmd,buf,len)
90#define SMBUS_QCMD(chan,slave,rw) (chan)->ops->qcmd(chan,slave,rw);
91#define SMBUS_XREAD(chan,slave,cmd,ncmd,ndat,buf) (chan)->ops->xread(chan,slave,cmd,ncmd,ndat,buf)
92#define SMBUS_XWRITE(chan,slave,cmd,ncmd,ndat,buf) (chan)->ops->xwrite(chan,slave,cmd,ncmd,ndat,buf)
93
94int cfe_add_smbus(cfe_smbus_t *ops,uint64_t probe_a,uint64_t probe_b);
95
96
97