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 19 #ifndef __HI_DRV_GPIO_I2C_H__ 20 #define __HI_DRV_GPIO_I2C_H__ 21 22 #include <linux/kernel.h> 23 #include "hi_type.h" 24 25 hi_u32 hi_drv_i2c_get_chip_version(hi_void); 26 hi_s32 hi_drv_gpioi2c_init(hi_void); 27 hi_void hi_drv_gpioi2c_de_init(hi_void); 28 29 hi_s32 hi_drv_gpioi2c_sccb_read(hi_u32 i2c_num, HI_U8 u8_devaddr, HI_U8 u8_reg_address, HI_U8 *pu8_data); 30 31 hi_s32 hi_drv_gpioi2c_read(hi_u32 i2c_num, HI_U8 u8_devaddr, HI_U8 u8_reg_address, HI_U8 *pu8_data); 32 hi_s32 hi_drv_gpioi2c_write(hi_u32 i2c_num, HI_U8 u8_devaddr, HI_U8 u8_reg_address, HI_U8 u8_data); 33 hi_s32 hi_drv_gpioi2c_create_gpio_i2c(hi_u32 *pu32_i2c_num, hi_u32 scl_gpio_no, hi_u32 sda_gpio_no); 34 hi_s32 hi_drv_gpioi2c_destroy_gpio_i2c(hi_u32 i2c_num); 35 36 hi_s32 hi_drv_gpioi2c_read_ext(hi_u32 i2c_num, HI_U8 devaddress, hi_u32 address, hi_u32 addresslen, 37 HI_U8 *p_data, hi_u32 data_len); 38 hi_s32 hi_drv_gpioi2c_read_ext_directly(hi_u32 i2c_num, HI_U8 devaddress, hi_u32 address, 39 hi_u32 addresslen, HI_U8 *p_data, hi_u32 data_len); 40 hi_s32 hi_drv_gpioi2c_write_ext(hi_u32 i2c_num, HI_U8 devaddress, hi_u32 address, 41 hi_u32 addresslen, HI_U8 *p_data, hi_u32 data_len); 42 hi_s32 hi_drv_gpioi2c_write_ext_no_stop(hi_u32 i2c_num, HI_U8 devaddress, 43 hi_u32 address, hi_u32 addresslen, HI_U8 *p_data, hi_u32 data_len); 44 45 int hi_drv_gpioi2c_cmd_read(unsigned int cmd, hi_void *arg, hi_void *private_data); 46 int hi_drv_gpioi2c_cmd_write(unsigned int cmd, hi_void *arg, hi_void *private_data); 47 int hi_drv_gpioi2c_cmd_config(unsigned int cmd, hi_void *arg, hi_void *private_data); 48 int hi_drv_gpioi2c_cmd_destroy(unsigned int cmd, hi_void *arg, hi_void *private_data); 49 50 typedef enum { 51 I2C_DRV_CHIP_V350 = 0x350, 52 53 I2C_DRV_CHIP_BUTT 54 } i2c_drv_chip; 55 56 57 typedef hi_s32 (*fn_gpio_i2c_write)(hi_u32 i2c_num, hi_u8 dev_addr, hi_u8 reg_address, hi_u8 data); 58 typedef hi_s32 (*fn_gpio_i2c_write_ext)(hi_u32, hi_u8, hi_u32, hi_u32, hi_u8 *, hi_u32); 59 60 typedef hi_s32 (*fn_gpio_i2c_read)(hi_u32 i2c_num, hi_u8 dev_addr, hi_u8 reg_address, hi_u8 *p_data); 61 typedef hi_s32 (*fn_gpio_i2c_read_ext)(hi_u32, hi_u8, hi_u32, hi_u32, hi_u8 *, hi_u32); 62 63 typedef hi_s32 (*fn_gpio_i2c_sccb_read)(hi_u32 i2c_num, hi_u8 dev_addr, hi_u8 reg_address, hi_u8 *p_data); 64 65 66 typedef hi_s32 (*fn_gpio_i2c_create_channel)(hi_u32 *, hi_u32, hi_u32); 67 typedef hi_s32 (*fn_gpio_i2c_destroy_channel)(hi_u32); 68 typedef hi_s32 (*fn_gpio_i2c_is_used)(hi_u32, HI_BOOL *); 69 70 typedef struct { 71 fn_gpio_i2c_write pfn_gpio_i2c_write; 72 fn_gpio_i2c_write_ext pfn_gpio_i2c_write_ext; 73 fn_gpio_i2c_write_ext pfn_gpio_i2c_write_ext_nostop; 74 fn_gpio_i2c_read pfn_gpio_i2c_read; 75 fn_gpio_i2c_read_ext pfn_gpio_i2c_read_ext; 76 fn_gpio_i2c_read_ext pfn_gpio_i2c_read_ext_di_rectly; 77 78 fn_gpio_i2c_sccb_read pfn_gpio_i2c_sccb_read; 79 fn_gpio_i2c_create_channel pfn_gpio_i2c_create_channel; 80 fn_gpio_i2c_destroy_channel pfn_gpio_i2c_destroy_channel; 81 fn_gpio_i2c_is_used pfn_gpio_i2c_is_used; 82 } gpio_i2c_ext_func; 83 84 #endif 85