xref: /optee_os/core/drivers/i2c/i2c.c (revision 92d75aefed568a557dbd9152d749a4bc320fa9f2)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright 2023 Microchip
4  */
5 
6 #include <drivers/i2c.h>
7 #include <kernel/dt.h>
8 #include <kernel/dt_driver.h>
9 #include <libfdt.h>
10 #include <malloc.h>
11 #include <tee_api_defines_extensions.h>
12 #include <tee_api_types.h>
13 #include <trace.h>
14 #include <types_ext.h>
15 
16 struct i2c_dev *i2c_create_dev(struct i2c_ctrl *i2c_ctrl, const void *fdt,
17 			       int node)
18 {
19 	struct i2c_dev *i2c_dev = NULL;
20 	paddr_t addr = fdt_reg_base_address(fdt, node);
21 
22 	if (addr == DT_INFO_INVALID_REG)
23 		return NULL;
24 
25 	i2c_dev = calloc(1, sizeof(struct i2c_dev));
26 	if (!i2c_dev)
27 		return NULL;
28 
29 	i2c_dev->addr = addr;
30 	i2c_dev->ctrl = i2c_ctrl;
31 
32 	return i2c_dev;
33 }
34