• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 #ifndef __HI_DRV_I2C_H__
19 #define __HI_DRV_I2C_H__
20 
21 #include "hi_type.h"
22 #include "drv_i2c_struct.h"
23 
24 #define HI_I2C_SPACE_SIZE 0x1000
25 
26 #define HI_I2C_REG_REMAP(pvAddr, u32RegAddr) \
27     do { \
28         (pvAddr) = osal_ioremap_nocache((u32RegAddr), HI_I2C_SPACE_SIZE); \
29         if (NULL == (pvAddr)) { \
30             HI_LOG_ERR("ioremap REG_ADDR[0x%x] failure!\n", (u32RegAddr)); \
31             return HI_FAILURE; \
32         } \
33     } while (0)
34 
35 #define HI_I2C_ERR_PRINT(exp, ret, fmt...) \
36     do {                                   \
37         if ((exp)) {                       \
38             HI_LOG_ERR(fmt);               \
39             return (ret);                  \
40         }                                  \
41     } while (0)
42 
43 #define HI_I2C_INFO_PRINT(exp, ret, fmt...) \
44     do {                                    \
45         if ((exp)) {                        \
46             HI_LOG_INFO(fmt);               \
47             return (ret);                   \
48         }                                   \
49     } while (0)
50 
51 #define HI_I2C_REG_UNMAP(pvAddr) osal_iounmap(pvAddr)
52 
53 
54 hi_s32 hi_drv_i2c_init(hi_void);
55 hi_void hi_drv_i2c_de_init(hi_void);
56 
57 hi_s32 hi_drv_i2c_write_config(hi_u32 i2c_num, hi_u8 i2c_dev_addr);
58 hi_s32 hi_drv_i2c_write(hi_u32 i2c_num, hi_u8 i2c_dev_addr, hi_u32 i2c_reg_addr,
59     hi_u32 i2c_reg_addr_byte_num, hi_u8 *p_data, hi_u32 data_len);
60 hi_s32 hi_drv_i2c_read(hi_u32 i2c_num, hi_u8 i2c_dev_addr, hi_u32 i2c_reg_addr,
61     hi_u32 i2c_reg_addr_byte_num, hi_u8 *p_data, hi_u32 data_len);
62 hi_s32 hi_drv_i2c_read_si_labs(hi_u32 i2c_num, hi_u8 i2c_dev_addr,
63     hi_u32 i2c_reg_addr, hi_u32 i2c_reg_addr_byte_num, hi_u8 *p_data, hi_u32 data_len);
64 hi_s32 hi_i2c_write_sony(hi_u32 i2c_num, hi_u8 i2c_dev_addr, hi_u32 i2c_reg_addr, hi_u32 i2c_reg_addr_byte_num,
65                          hi_u8 *p_data, hi_u32 data_len, hi_u8 u8_mode);
66 hi_s32 hi_i2c_read_sony(hi_u32 i2c_num, hi_u8 i2c_dev_addr, hi_u32 i2c_reg_addr, hi_u32 i2c_reg_addr_byte_num,
67     hi_u8 *p_data, hi_u32 data_len, hi_u8 u8_mode);
68 hi_s32 hi_drv_i2c_read_directly(hi_u32 i2c_num, hi_u8 i2c_dev_addr,
69     hi_u32 i2c_reg_addr, hi_u32 i2c_reg_addr_byte_num, hi_u8 *p_data, hi_u32 data_len);
70 hi_s32 hi_drv_i2c_write_no_stop(HI_U32 i2c_num, HI_U8 i2c_dev_addr,
71     HI_U32 i2c_reg_addr, HI_U32 i2c_reg_addr_byte_num, HI_U8 *p_data, HI_U32 data_len);
72 
73 typedef hi_s32 (*fn_i2c_writeconfig)(hi_u32, hi_u8);
74 typedef hi_s32 (*fn_i2c_write)(hi_u32, hi_u8, hi_u32, hi_u32, hi_u8 *, hi_u32);
75 typedef hi_s32 (*fn_i2c_read)(hi_u32, hi_u8, hi_u32, hi_u32, hi_u8 *, hi_u32);
76 
77 typedef struct {
78     fn_i2c_writeconfig pfn_i2c_write_config;
79     fn_i2c_write pfn_i2c_write;
80     fn_i2c_read pfn_i2c_read;
81     fn_i2c_write pfn_i2c_write_nostop;
82     fn_i2c_read pfn_i2c_read_directly;
83     fn_i2c_read pfn_i2c_read_si_labs;
84 } i2c_ext_func;
85 
86 hi_void i2c_drv_get_i2c_ext_func(i2c_ext_func **st_i2c_export_funcs);
87 
88 #endif