xref: /optee_os/core/drivers/i2c/i2c.c (revision 9f34db38245c9b3a4e6e7e63eb78a75e23ab2da3)
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 <libfdt.h>
9 #include <malloc.h>
10 #include <tee_api_defines_extensions.h>
11 #include <tee_api_types.h>
12 #include <trace.h>
13 #include <types_ext.h>
14 
15 struct i2c_dev *i2c_create_dev(struct i2c_ctrl *i2c_ctrl, const void *fdt,
16 			       int node)
17 {
18 	struct i2c_dev *i2c_dev = NULL;
19 	paddr_t addr = fdt_reg_base_address(fdt, node);
20 
21 	if (addr == DT_INFO_INVALID_REG)
22 		return NULL;
23 
24 	i2c_dev = calloc(1, sizeof(struct i2c_dev));
25 	if (!i2c_dev)
26 		return NULL;
27 
28 	i2c_dev->addr = addr;
29 	i2c_dev->ctrl = i2c_ctrl;
30 
31 	return i2c_dev;
32 }
33