2 * PC SMBus implementation
5 * Copyright (c) 2006 Fabrice Bellard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License version 2 as published by the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
24 #include "qemu-timer.h"
32 #define SMBHSTSTS 0x00
33 #define SMBHSTCNT 0x02
34 #define SMBHSTCMD 0x03
35 #define SMBHSTADD 0x04
36 #define SMBHSTDAT0 0x05
37 #define SMBHSTDAT1 0x06
38 #define SMBBLKDAT 0x07
43 # define SMBUS_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
45 # define SMBUS_DPRINTF(format, ...) do { } while (0)
49 static void smb_transaction(PMSMBus
*s
)
51 uint8_t prot
= (s
->smb_ctl
>> 2) & 0x07;
52 uint8_t read
= s
->smb_addr
& 0x01;
53 uint8_t cmd
= s
->smb_cmd
;
54 uint8_t addr
= s
->smb_addr
>> 1;
55 i2c_bus
*bus
= s
->smbus
;
57 SMBUS_DPRINTF("SMBus trans addr=0x%02x prot=0x%02x\n", addr
, prot
);
60 smbus_quick_command(bus
, addr
, read
);
64 s
->smb_data0
= smbus_receive_byte(bus
, addr
);
66 smbus_send_byte(bus
, addr
, cmd
);
71 s
->smb_data0
= smbus_read_byte(bus
, addr
, cmd
);
73 smbus_write_byte(bus
, addr
, cmd
, s
->smb_data0
);
79 val
= smbus_read_word(bus
, addr
, cmd
);
81 s
->smb_data1
= val
>> 8;
83 smbus_write_word(bus
, addr
, cmd
, (s
->smb_data1
<< 8) | s
->smb_data0
);
88 s
->smb_data0
= smbus_read_block(bus
, addr
, cmd
, s
->smb_data
);
90 smbus_write_block(bus
, addr
, cmd
, s
->smb_data
, s
->smb_data0
);
102 void smb_ioport_writeb(void *opaque
, uint32_t addr
, uint32_t val
)
106 SMBUS_DPRINTF("SMB writeb port=0x%04x val=0x%02x\n", addr
, val
);
130 s
->smb_data
[s
->smb_index
++] = val
;
131 if (s
->smb_index
> 31)
139 uint32_t smb_ioport_readb(void *opaque
, uint32_t addr
)
151 val
= s
->smb_ctl
& 0x1f;
166 val
= s
->smb_data
[s
->smb_index
++];
167 if (s
->smb_index
> 31)
174 SMBUS_DPRINTF("SMB readb port=0x%04x val=0x%02x\n", addr
, val
);
178 void pm_smbus_init(DeviceState
*parent
, PMSMBus
*smb
)
180 smb
->smbus
= i2c_init_bus(parent
, "i2c");