Angel Pons | c74dae9 | 2020-04-02 23:48:16 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 2 | |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 3 | #include <stdint.h> |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 5 | #include <device/device.h> |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 6 | #include <device/smbus.h> |
| 7 | |
Elyes HAOUAS | 2f119a3 | 2018-05-02 21:26:01 +0200 | [diff] [blame] | 8 | struct bus *get_pbus_smbus(struct device *dev) |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 9 | { |
Nico Huber | 632d6ab | 2017-08-02 16:57:17 +0200 | [diff] [blame] | 10 | struct bus *const pbus = i2c_link(dev); |
| 11 | if (!pbus->dev->ops->ops_smbus_bus) { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 12 | printk(BIOS_ALERT, "%s Cannot find SMBus bus operations", |
| 13 | dev_path(dev)); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 14 | die(""); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 15 | } |
| 16 | return pbus; |
| 17 | } |
| 18 | |
Vladimir Serbinenko | dec9198 | 2014-01-27 23:46:46 +0100 | [diff] [blame] | 19 | #define CHECK_PRESENCE(x) \ |
| 20 | if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \ |
| 21 | printk(BIOS_ERR, "%s missing " #x "\n", \ |
| 22 | dev_path(dev)); \ |
| 23 | return -1; \ |
| 24 | } |
| 25 | |
Elyes HAOUAS | 2f119a3 | 2018-05-02 21:26:01 +0200 | [diff] [blame] | 26 | int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer) |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 27 | { |
Vladimir Serbinenko | dec9198 | 2014-01-27 23:46:46 +0100 | [diff] [blame] | 28 | CHECK_PRESENCE(block_read); |
| 29 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 30 | return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd, |
| 31 | bytes, buffer); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 32 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 33 | |
Elyes HAOUAS | 2f119a3 | 2018-05-02 21:26:01 +0200 | [diff] [blame] | 34 | int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer) |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 35 | { |
Vladimir Serbinenko | dec9198 | 2014-01-27 23:46:46 +0100 | [diff] [blame] | 36 | CHECK_PRESENCE(block_write); |
| 37 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 38 | return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd, |
| 39 | bytes, buffer); |
Yinghai Lu | 7213d0f | 2004-12-03 03:39:04 +0000 | [diff] [blame] | 40 | } |