1 /*
2  * Copyright (c) 2022 Thomas Stranger
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #define DT_DRV_COMPAT vnd_w1
8 
9 /*
10  * This is not a real 1-Wire driver. It is only used to instantiate struct
11  * devices for the "vnd,w1" devicetree compatibe used in test code.
12  */
13 #include <zephyr/drivers/w1.h>
14 
15 struct w1_vnd_config {
16 	/** w1 master config, common to all drivers */
17 	struct w1_master_config master_config;
18 };
19 
20 struct w1_vnd_data {
21 	/** w1 master data, common to all drivers */
22 	struct w1_master_data master_data;
23 };
24 
w1_vnd_reset_bus(const struct device * dev)25 static int w1_vnd_reset_bus(const struct device *dev)
26 {
27 	return -ENOTSUP;
28 }
29 
w1_vnd_read_bit(const struct device * dev)30 static int w1_vnd_read_bit(const struct device *dev)
31 {
32 	return -ENOTSUP;
33 }
34 
w1_vnd_write_bit(const struct device * dev,const bool bit)35 static int w1_vnd_write_bit(const struct device *dev, const bool bit)
36 {
37 	return -ENOTSUP;
38 }
39 
w1_vnd_read_byte(const struct device * dev)40 static int w1_vnd_read_byte(const struct device *dev)
41 {
42 	return -ENOTSUP;
43 }
44 
w1_vnd_write_byte(const struct device * dev,const uint8_t byte)45 static int w1_vnd_write_byte(const struct device *dev, const uint8_t byte)
46 {
47 	return -ENOTSUP;
48 }
49 
w1_vnd_configure(const struct device * dev,enum w1_settings_type type,uint32_t value)50 static int w1_vnd_configure(const struct device *dev,
51 			    enum w1_settings_type type, uint32_t value)
52 {
53 	return -ENOTSUP;
54 }
55 
56 static DEVICE_API(w1, w1_vnd_api) = {
57 	.reset_bus = w1_vnd_reset_bus,
58 	.read_bit = w1_vnd_read_bit,
59 	.write_bit = w1_vnd_write_bit,
60 	.read_byte = w1_vnd_read_byte,
61 	.write_byte = w1_vnd_write_byte,
62 	.configure = w1_vnd_configure,
63 };
64 
65 #define W1_VND_INIT(n)							\
66 static const struct w1_vnd_config w1_vnd_cfg_##inst = {			\
67 	.master_config.slave_count = W1_INST_SLAVE_COUNT(inst)		\
68 };									\
69 static struct w1_vnd_data w1_vnd_data_##inst = {};			\
70 DEVICE_DT_INST_DEFINE(n, NULL, NULL, &w1_vnd_data_##inst,		\
71 		      &w1_vnd_cfg_##inst, POST_KERNEL,			\
72 		      CONFIG_W1_INIT_PRIORITY, &w1_vnd_api);
73 
74 DT_INST_FOREACH_STATUS_OKAY(W1_VND_INIT)
75