1 /* Bosch BMA4xx 3-axis accelerometer driver
2  *
3  * Copyright (c) 2023 Google LLC
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #define DT_DRV_COMPAT bosch_bma4xx
9 
10 #include <zephyr/drivers/spi.h>
11 #include <zephyr/logging/log.h>
12 
13 #include "bma4xx.h"
14 
15 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
16 
17 LOG_MODULE_DECLARE(bma4xx, CONFIG_SENSOR_LOG_LEVEL);
18 
bma4xx_spi_read_data(const struct device * dev,uint8_t reg_addr,uint8_t * value,uint8_t len)19 static int bma4xx_spi_read_data(const struct device *dev, uint8_t reg_addr,
20 				 uint8_t *value, uint8_t len)
21 {
22 	return -ENOTSUP;
23 }
24 
bma4xx_spi_write_data(const struct device * dev,uint8_t reg_addr,uint8_t * value,uint8_t len)25 static int bma4xx_spi_write_data(const struct device *dev, uint8_t reg_addr,
26 				  uint8_t *value, uint8_t len)
27 {
28 	return -ENOTSUP;
29 }
30 
bma4xx_spi_read_reg(const struct device * dev,uint8_t reg_addr,uint8_t * value)31 static int bma4xx_spi_read_reg(const struct device *dev, uint8_t reg_addr,
32 				uint8_t *value)
33 {
34 	return -ENOTSUP;
35 }
36 
bma4xx_spi_write_reg(const struct device * dev,uint8_t reg_addr,uint8_t value)37 static int bma4xx_spi_write_reg(const struct device *dev, uint8_t reg_addr,
38 				uint8_t value)
39 {
40 	return -ENOTSUP;
41 }
42 
bma4xx_spi_update_reg(const struct device * dev,uint8_t reg_addr,uint8_t mask,uint8_t value)43 static int bma4xx_spi_update_reg(const struct device *dev, uint8_t reg_addr,
44 				  uint8_t mask, uint8_t value)
45 {
46 	return -ENOTSUP;
47 }
48 
49 static const struct bma4xx_hw_operations spi_ops = {
50 	.read_data = bma4xx_spi_read_data,
51 	.write_data = bma4xx_spi_write_data,
52 	.read_reg  = bma4xx_spi_read_reg,
53 	.write_reg  = bma4xx_spi_write_reg,
54 	.update_reg = bma4xx_spi_update_reg,
55 };
56 
bma4xx_spi_init(const struct device * dev)57 int bma4xx_spi_init(const struct device *dev)
58 {
59 	struct bma4xx_data *data = dev->data;
60 	const struct bma4xx_config *cfg = dev->config;
61 
62 	if (!device_is_ready(cfg->bus_cfg.spi.bus)) {
63 		LOG_ERR("SPI bus device is not ready");
64 		return -ENODEV;
65 	}
66 
67 	data->hw_ops = &spi_ops;
68 
69 	return 0;
70 }
71 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
72