1 /* SPDX-License-Identifier: GPL-2.0-only */
7 #include <device/device.h>
8 #include <device/i2c_bus.h>
10 /* Common SMBus bus operations */
11 struct smbus_bus_operations
{
12 int (*recv_byte
)(struct device
*dev
);
13 int (*send_byte
)(struct device
*dev
, u8 value
);
14 int (*read_byte
)(struct device
*dev
, u8 addr
);
15 int (*write_byte
)(struct device
*dev
, u8 addr
, u8 value
);
16 int (*block_read
)(struct device
*dev
, u8 cmd
, u8 bytes
, u8
*buffer
);
17 int (*block_write
)(struct device
*dev
, u8 cmd
, u8 bytes
,
21 static inline const struct smbus_bus_operations
*ops_smbus_bus(struct bus
*bus
)
23 const struct smbus_bus_operations
*bops
;
26 if (bus
&& bus
->dev
&& bus
->dev
->ops
)
27 bops
= bus
->dev
->ops
->ops_smbus_bus
;
32 struct bus
*get_pbus_smbus(struct device
*dev
);
35 static inline int smbus_recv_byte(struct device
*const dev
)
37 return i2c_dev_readb(dev
);
40 static inline int smbus_send_byte(struct device
*const dev
, u8 byte
)
42 return i2c_dev_writeb(dev
, byte
);
45 static inline int smbus_read_byte(struct device
*const dev
, u8 addr
)
47 return i2c_dev_readb_at(dev
, addr
);
50 static inline int smbus_write_byte(struct device
*const dev
, u8 addr
, u8 val
)
52 return i2c_dev_writeb_at(dev
, addr
, val
);
55 int smbus_block_read(struct device
*dev
, u8 cmd
, u8 bytes
, u8
*buffer
);
56 int smbus_block_write(struct device
*dev
, u8 cmd
, u8 bytes
, const u8
*buffer
);
59 #endif /* DEVICE_SMBUS_H */