1 /*
2  * Copyright (c) 2024 Intel Corporation
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 /*
7  * Bus-specific functionality for MMC56X3s accessed via I2C.
8  */
9 
10 #include "mmc56x3.h"
11 
mmc56x3_bus_check_i2c(const union mmc56x3_bus * bus)12 static int mmc56x3_bus_check_i2c(const union mmc56x3_bus *bus)
13 {
14 	return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV;
15 }
16 
mmc56x3_reg_read_i2c(const union mmc56x3_bus * bus,uint8_t reg,uint8_t * buf,int size)17 static int mmc56x3_reg_read_i2c(const union mmc56x3_bus *bus, uint8_t reg, uint8_t *buf, int size)
18 {
19 	return i2c_burst_read_dt(&bus->i2c, reg, buf, size);
20 }
21 
mmc56x3_reg_write_i2c(const union mmc56x3_bus * bus,uint8_t reg,uint8_t val)22 static int mmc56x3_reg_write_i2c(const union mmc56x3_bus *bus, uint8_t reg, uint8_t val)
23 {
24 	return i2c_reg_write_byte_dt(&bus->i2c, reg, val);
25 }
26 
mmc56x3_raw_read_i2c(const union mmc56x3_bus * bus,uint8_t * buf,size_t size)27 static int mmc56x3_raw_read_i2c(const union mmc56x3_bus *bus, uint8_t *buf, size_t size)
28 {
29 	return i2c_read_dt(&bus->i2c, buf, size);
30 }
31 
mmc56x3_raw_write_i2c(const union mmc56x3_bus * bus,uint8_t * buf,size_t size)32 static int mmc56x3_raw_write_i2c(const union mmc56x3_bus *bus, uint8_t *buf, size_t size)
33 {
34 	return i2c_write_dt(&bus->i2c, buf, size);
35 }
36 
37 const struct mmc56x3_bus_io mmc56x3_bus_io_i2c = {
38 	.check = mmc56x3_bus_check_i2c,
39 	.read = mmc56x3_reg_read_i2c,
40 	.write = mmc56x3_reg_write_i2c,
41 	.raw_read = mmc56x3_raw_read_i2c,
42 	.raw_write = mmc56x3_raw_write_i2c,
43 };
44