6b5bc77c9b
Stefan thinks they don't add value. Command used: sed -i -e '/file is part of /d' $(git grep "file is part of " |egrep ":( */\*.*\*/\$|#|;#|-- | *\* )" | cut -d: -f1 |grep -v crossgcc |grep -v gcov | grep -v /elf.h |grep -v nvramtool) The exceptions are for: - crossgcc (patch file) - gcov (imported from gcc) - elf.h (imported from GNU's libc) - nvramtool (more complicated header) The removed lines are: - fmt.Fprintln(f, "/* This file is part of the coreboot project. */") -# This file is part of a set of unofficial pre-commit hooks available -/* This file is part of coreboot */ -# This file is part of msrtool. -/* This file is part of msrtool. */ - * This file is part of ncurses, designed to be appended after curses.h.in -/* This file is part of pgtblgen. */ - * This file is part of the coreboot project. - /* This file is part of the coreboot project. */ -# This file is part of the coreboot project. -# This file is part of the coreboot project. -## This file is part of the coreboot project. --- This file is part of the coreboot project. -/* This file is part of the coreboot project */ -/* This file is part of the coreboot project. */ -;## This file is part of the coreboot project. -# This file is part of the coreboot project. It originated in the - * This file is part of the coreinfo project. -## This file is part of the coreinfo project. - * This file is part of the depthcharge project. -/* This file is part of the depthcharge project. */ -/* This file is part of the ectool project. */ - * This file is part of the GNU C Library. - * This file is part of the libpayload project. -## This file is part of the libpayload project. -/* This file is part of the Linux kernel. */ -## This file is part of the superiotool project. -/* This file is part of the superiotool project */ -/* This file is part of uio_usbdebug */ Change-Id: I82d872b3b337388c93d5f5bf704e9ee9e53ab3a9 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/41194 Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
186 lines
4 KiB
C
186 lines
4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
#include <stdint.h>
|
|
#include <console/console.h>
|
|
#include <device/smbus.h>
|
|
#include <device/i2c_bus.h>
|
|
#include <commonlib/endian.h>
|
|
|
|
struct bus *i2c_link(struct device *const dev)
|
|
{
|
|
if (!dev || !dev->bus)
|
|
return NULL;
|
|
|
|
struct bus *link = dev->bus;
|
|
while (link) {
|
|
struct device *const parent = link->dev;
|
|
|
|
if (parent && parent->ops &&
|
|
(parent->ops->ops_i2c_bus || parent->ops->ops_smbus_bus))
|
|
break;
|
|
|
|
if (parent && parent->bus)
|
|
link = parent->bus;
|
|
else
|
|
link = NULL;
|
|
}
|
|
|
|
if (!link) {
|
|
printk(BIOS_ALERT, "%s Cannot find I2C or SMBus bus operations",
|
|
dev_path(dev));
|
|
}
|
|
|
|
return link;
|
|
}
|
|
|
|
int i2c_dev_readb(struct device *const dev)
|
|
{
|
|
struct device *const busdev = i2c_busdev(dev);
|
|
if (!busdev)
|
|
return -1;
|
|
|
|
if (busdev->ops->ops_i2c_bus) {
|
|
uint8_t val;
|
|
const struct i2c_msg msg = {
|
|
.flags = I2C_M_RD,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = &val,
|
|
.len = sizeof(val),
|
|
};
|
|
|
|
const int ret = busdev->ops->ops_i2c_bus->
|
|
transfer(busdev, &msg, 1);
|
|
if (ret)
|
|
return ret;
|
|
else
|
|
return val;
|
|
} else if (busdev->ops->ops_smbus_bus->recv_byte) {
|
|
return busdev->ops->ops_smbus_bus->recv_byte(dev);
|
|
} else {
|
|
printk(BIOS_ERR, "%s Missing ops_smbus_bus->recv_byte",
|
|
dev_path(busdev));
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int i2c_dev_writeb(struct device *const dev, uint8_t val)
|
|
{
|
|
struct device *const busdev = i2c_busdev(dev);
|
|
if (!busdev)
|
|
return -1;
|
|
|
|
if (busdev->ops->ops_i2c_bus) {
|
|
const struct i2c_msg msg = {
|
|
.flags = 0,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = &val,
|
|
.len = sizeof(val),
|
|
};
|
|
return busdev->ops->ops_i2c_bus->transfer(busdev, &msg, 1);
|
|
} else if (busdev->ops->ops_smbus_bus->send_byte) {
|
|
return busdev->ops->ops_smbus_bus->send_byte(dev, val);
|
|
} else {
|
|
printk(BIOS_ERR, "%s Missing ops_smbus_bus->send_byte",
|
|
dev_path(busdev));
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int i2c_dev_readb_at(struct device *const dev, uint8_t off)
|
|
{
|
|
struct device *const busdev = i2c_busdev(dev);
|
|
if (!busdev)
|
|
return -1;
|
|
|
|
if (busdev->ops->ops_i2c_bus) {
|
|
uint8_t val;
|
|
const struct i2c_msg msg[] = {
|
|
{
|
|
.flags = 0,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = &off,
|
|
.len = sizeof(off),
|
|
},
|
|
{
|
|
.flags = I2C_M_RD,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = &val,
|
|
.len = sizeof(val),
|
|
},
|
|
};
|
|
|
|
const int ret = busdev->ops->ops_i2c_bus->
|
|
transfer(busdev, msg, ARRAY_SIZE(msg));
|
|
if (ret)
|
|
return ret;
|
|
else
|
|
return val;
|
|
} else if (busdev->ops->ops_smbus_bus->read_byte) {
|
|
return busdev->ops->ops_smbus_bus->read_byte(dev, off);
|
|
} else {
|
|
printk(BIOS_ERR, "%s Missing ops_smbus_bus->read_byte",
|
|
dev_path(busdev));
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int i2c_dev_writeb_at(struct device *const dev,
|
|
const uint8_t off, const uint8_t val)
|
|
{
|
|
struct device *const busdev = i2c_busdev(dev);
|
|
if (!busdev)
|
|
return -1;
|
|
|
|
if (busdev->ops->ops_i2c_bus) {
|
|
uint8_t buf[] = { off, val };
|
|
const struct i2c_msg msg = {
|
|
.flags = 0,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = buf,
|
|
.len = sizeof(buf),
|
|
};
|
|
return busdev->ops->ops_i2c_bus->transfer(busdev, &msg, 1);
|
|
} else if (busdev->ops->ops_smbus_bus->write_byte) {
|
|
return busdev->ops->ops_smbus_bus->write_byte(dev, off, val);
|
|
} else {
|
|
printk(BIOS_ERR, "%s Missing ops_smbus_bus->write_byte",
|
|
dev_path(busdev));
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int i2c_dev_read_at16(struct device *const dev,
|
|
uint8_t *const buf, const size_t len, uint16_t off)
|
|
{
|
|
struct device *const busdev = i2c_busdev(dev);
|
|
if (!busdev)
|
|
return -1;
|
|
|
|
if (busdev->ops->ops_i2c_bus) {
|
|
const struct i2c_msg msg[] = {
|
|
{
|
|
.flags = 0,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = (uint8_t *)&off,
|
|
.len = sizeof(off),
|
|
},
|
|
{
|
|
.flags = I2C_M_RD,
|
|
.slave = dev->path.i2c.device,
|
|
.buf = buf,
|
|
.len = len,
|
|
},
|
|
};
|
|
|
|
write_be16(&off, off);
|
|
const int ret = busdev->ops->ops_i2c_bus->transfer(
|
|
busdev, msg, ARRAY_SIZE(msg));
|
|
if (ret)
|
|
return ret;
|
|
else
|
|
return len;
|
|
} else {
|
|
printk(BIOS_ERR, "%s Missing ops_i2c_bus->transfer", dev_path(busdev));
|
|
return -1;
|
|
}
|
|
}
|