1 /*
2  * Copyright (c) 2016, 2017 Intel Corporation
3  * Copyright (c) 2017 IpTronix S.r.l.
4  * Copyright (c) 2021 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 /*
10  * Bus-specific functionality for BMM150s accessed via I2C.
11  */
12 
13 #include "bmm150.h"
14 
15 #if BMM150_BUS_I2C
16 
bmm150_bus_check_i2c(const union bmm150_bus * bus)17 static int bmm150_bus_check_i2c(const union bmm150_bus *bus)
18 {
19 	return i2c_is_ready_dt(&bus->i2c) ? 0 : -ENODEV;
20 }
21 
bmm150_reg_read_i2c(const union bmm150_bus * bus,uint8_t start,uint8_t * buf,int size)22 static int bmm150_reg_read_i2c(const union bmm150_bus *bus,
23 			       uint8_t start, uint8_t *buf, int size)
24 {
25 	return i2c_burst_read_dt(&bus->i2c, start, buf, size);
26 }
27 
bmm150_reg_write_i2c(const union bmm150_bus * bus,uint8_t reg,uint8_t val)28 static int bmm150_reg_write_i2c(const union bmm150_bus *bus,
29 				uint8_t reg, uint8_t val)
30 {
31 	return i2c_reg_write_byte_dt(&bus->i2c, reg, val);
32 }
33 
34 const struct bmm150_bus_io bmm150_bus_io_i2c = {
35 	.check = bmm150_bus_check_i2c,
36 	.read = bmm150_reg_read_i2c,
37 	.write = bmm150_reg_write_i2c,
38 };
39 
40 #endif /* BMM150_BUS_I2C */
41