2007-04-22 21:08:13 +02:00
|
|
|
/*
|
2008-01-18 11:35:56 +01:00
|
|
|
* This file is part of the coreboot project.
|
2007-04-22 21:08:13 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2004-12-03 04:39:04 +01:00
|
|
|
#include <stdint.h>
|
2017-08-02 16:57:17 +02:00
|
|
|
#include <console/console.h>
|
2004-12-03 04:39:04 +01:00
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/smbus.h>
|
|
|
|
|
2018-05-02 21:26:01 +02:00
|
|
|
struct bus *get_pbus_smbus(struct device *dev)
|
2004-12-03 04:39:04 +01:00
|
|
|
{
|
2017-08-02 16:57:17 +02:00
|
|
|
struct bus *const pbus = i2c_link(dev);
|
|
|
|
if (!pbus->dev->ops->ops_smbus_bus) {
|
2010-10-18 02:00:57 +02:00
|
|
|
printk(BIOS_ALERT, "%s Cannot find SMBus bus operations",
|
|
|
|
dev_path(dev));
|
2004-12-03 04:39:04 +01:00
|
|
|
die("");
|
|
|
|
}
|
|
|
|
return pbus;
|
|
|
|
}
|
|
|
|
|
2014-01-27 23:46:46 +01:00
|
|
|
#define CHECK_PRESENCE(x) \
|
|
|
|
if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \
|
|
|
|
printk(BIOS_ERR, "%s missing " #x "\n", \
|
|
|
|
dev_path(dev)); \
|
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
2018-05-02 21:26:01 +02:00
|
|
|
int smbus_block_read(struct device *dev, u8 cmd, u8 bytes, u8 *buffer)
|
2004-12-03 04:39:04 +01:00
|
|
|
{
|
2014-01-27 23:46:46 +01:00
|
|
|
CHECK_PRESENCE(block_read);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
return ops_smbus_bus(get_pbus_smbus(dev))->block_read(dev, cmd,
|
|
|
|
bytes, buffer);
|
2004-12-03 04:39:04 +01:00
|
|
|
}
|
2010-10-18 02:00:57 +02:00
|
|
|
|
2018-05-02 21:26:01 +02:00
|
|
|
int smbus_block_write(struct device *dev, u8 cmd, u8 bytes, const u8 *buffer)
|
2004-12-03 04:39:04 +01:00
|
|
|
{
|
2014-01-27 23:46:46 +01:00
|
|
|
CHECK_PRESENCE(block_write);
|
|
|
|
|
2010-10-18 02:00:57 +02:00
|
|
|
return ops_smbus_bus(get_pbus_smbus(dev))->block_write(dev, cmd,
|
|
|
|
bytes, buffer);
|
2004-12-03 04:39:04 +01:00
|
|
|
}
|