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
40 static void smb_transaction(PMSMBus
*s
)
42 uint8_t prot
= (s
->smb_ctl
>> 2) & 0x07;
43 uint8_t read
= s
->smb_addr
& 0x01;
44 uint8_t cmd
= s
->smb_cmd
;
45 uint8_t addr
= s
->smb_addr
>> 1;
46 i2c_bus
*bus
= s
->smbus
;
49 printf("SMBus trans addr=0x%02x prot=0x%02x\n", addr
, prot
);
53 smbus_quick_command(bus
, addr
, read
);
57 s
->smb_data0
= smbus_receive_byte(bus
, addr
);
59 smbus_send_byte(bus
, addr
, cmd
);
64 s
->smb_data0
= smbus_read_byte(bus
, addr
, cmd
);
66 smbus_write_byte(bus
, addr
, cmd
, s
->smb_data0
);
72 val
= smbus_read_word(bus
, addr
, cmd
);
74 s
->smb_data1
= val
>> 8;
76 smbus_write_word(bus
, addr
, cmd
, (s
->smb_data1
<< 8) | s
->smb_data0
);
81 s
->smb_data0
= smbus_read_block(bus
, addr
, cmd
, s
->smb_data
);
83 smbus_write_block(bus
, addr
, cmd
, s
->smb_data
, s
->smb_data0
);
95 void smb_ioport_writeb(void *opaque
, uint32_t addr
, uint32_t val
)
100 printf("SMB writeb port=0x%04x val=0x%02x\n", addr
, val
);
125 s
->smb_data
[s
->smb_index
++] = val
;
126 if (s
->smb_index
> 31)
134 uint32_t smb_ioport_readb(void *opaque
, uint32_t addr
)
146 val
= s
->smb_ctl
& 0x1f;
161 val
= s
->smb_data
[s
->smb_index
++];
162 if (s
->smb_index
> 31)
170 printf("SMB readb port=0x%04x val=0x%02x\n", addr
, val
);
175 void pm_smbus_init(DeviceState
*parent
, PMSMBus
*smb
)
177 smb
->smbus
= i2c_init_bus(parent
, "i2c");