Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 2 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 3 | #include <device/pci_ops.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 4 | #include <device/pci_def.h> |
Kyösti Mälkki | 1cae454 | 2020-01-06 12:31:34 +0200 | [diff] [blame] | 5 | #include <device/smbus_host.h> |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 6 | #include "i82801gx.h" |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 7 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 8 | uintptr_t smbus_base(void) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 9 | { |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 10 | return SMBUS_IO_BASE; |
| 11 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 12 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 13 | int smbus_enable_iobar(uintptr_t base) |
| 14 | { |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | /* Set the SMBus device statically. */ |
Elyes HAOUAS | eb00e87 | 2020-04-06 09:38:38 +0200 | [diff] [blame] | 16 | const pci_devfn_t dev = PCI_DEV(0x0, 0x1f, 0x3); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 17 | |
| 18 | /* Check to make sure we've got the right device. */ |
Elyes HAOUAS | ae22fe2 | 2020-05-21 09:04:16 +0200 | [diff] [blame] | 19 | if (pci_read_config16(dev, PCI_DEVICE_ID) != 0x27da) |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 20 | return -1; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 21 | |
| 22 | /* Set SMBus I/O base. */ |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 23 | pci_write_config32(dev, SMB_BASE, base | PCI_BASE_ADDRESS_SPACE_IO); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 24 | |
| 25 | /* Set SMBus enable. */ |
| 26 | pci_write_config8(dev, HOSTC, HST_EN); |
| 27 | |
| 28 | /* Set SMBus I/O space enable. */ |
| 29 | pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_IO); |
| 30 | |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 31 | return 0; |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame] | 34 | int smbus_read_byte(unsigned int device, unsigned int address) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 35 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 36 | return do_smbus_read_byte(SMBUS_IO_BASE, device, address); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 37 | } |
Arthur Heymans | 2a7c519 | 2017-03-20 22:32:02 +0100 | [diff] [blame] | 38 | |
Kyösti Mälkki | c01a505 | 2019-01-30 09:39:23 +0200 | [diff] [blame] | 39 | int i2c_eeprom_read(unsigned int device, unsigned int offset, u32 bytes, u8 *buf) |
Arthur Heymans | 2a7c519 | 2017-03-20 22:32:02 +0100 | [diff] [blame] | 40 | { |
Kyösti Mälkki | c01a505 | 2019-01-30 09:39:23 +0200 | [diff] [blame] | 41 | return do_i2c_eeprom_read(SMBUS_IO_BASE, device, offset, bytes, buf); |
Arthur Heymans | 2a7c519 | 2017-03-20 22:32:02 +0100 | [diff] [blame] | 42 | } |
Arthur Heymans | ad29ec3 | 2017-05-05 21:08:00 +0200 | [diff] [blame] | 43 | |
| 44 | int smbus_block_read(unsigned int device, unsigned int cmd, u8 bytes, u8 *buf) |
| 45 | { |
| 46 | return do_smbus_block_read(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 47 | } |
| 48 | |
Elyes HAOUAS | 92646ea | 2020-04-04 13:43:03 +0200 | [diff] [blame] | 49 | int smbus_block_write(unsigned int device, unsigned int cmd, u8 bytes, const u8 *buf) |
Arthur Heymans | ad29ec3 | 2017-05-05 21:08:00 +0200 | [diff] [blame] | 50 | { |
| 51 | return do_smbus_block_write(SMBUS_IO_BASE, device, cmd, bytes, buf); |
| 52 | } |