/*************************************************************************** * * Copyright 2015-2019 BES. * All rights reserved. All unpublished rights reserved. * * No part of this work may be used or reproduced in any form or by any * means, or stored in a database or retrieval system, without prior written * permission of BES. * * Use of this work is governed by a license granted by BES. * This work contains confidential and proprietary information of * BES. which is protected by copyright, trade secret, * trademark and other intellectual property rights. * ****************************************************************************/ #ifndef __HAL_I2CIP_H__ #define __HAL_I2CIP_H__ #ifdef __cplusplus extern "C" { #endif #include "plat_types.h" #include "reg_i2cip.h" #define i2cip_read32(b,a) \ (*(volatile uint32_t *)(b+a)) #define i2cip_write32(v,b,a) \ ((*(volatile uint32_t *)(b+a)) = v) static inline uint8_t i2cip_w_enable(uint32_t reg_base, uint8_t enable) { uint32_t val = 0; val = i2cip_read32(reg_base, I2CIP_ENABLE_REG_OFFSET); if (enable) val |= I2CIP_ENABLE_MASK; else val &= ~I2CIP_ENABLE_MASK; i2cip_write32(val, reg_base, I2CIP_ENABLE_REG_OFFSET); return 0; } static inline uint8_t i2cip_w_clear_ctrl(uint32_t reg_base) { i2cip_write32(0, reg_base, I2CIP_CTRL_REG_OFFSET); return 0; } static inline uint8_t i2cip_w_10bit_master(uint32_t reg_base, uint8_t enable) { uint32_t val = 0; val = i2cip_read32(reg_base, I2CIP_CTRL_REG_OFFSET); if (enable) val |= I2CIP_10BITADDR_MASTER_MASK; else val &= ~I2CIP_10BITADDR_MASTER_MASK; i2cip_write32(val, reg_base, I2CIP_CTRL_REG_OFFSET); return 0; } static inline uint8_t i2cip_r_ctrl_reg(uint32_t reg_base) { return i2cip_read32(reg_base, I2CIP_CTRL_REG_OFFSET); } static inline uint8_t i2cip_w_10bit_slave(uint32_t reg_base, uint8_t enable) { uint32_t val = 0; val = i2cip_read32(reg_base, I2CIP_CTRL_REG_OFFSET); if (enable) val |= I2CIP_10BITADDR_SLAVE_MASK; else val &= ~I2CIP_10BITADDR_SLAVE_MASK; i2cip_write32(val, reg_base, I2CIP_CTRL_REG_OFFSET); return 0; } static inline uint8_t i2cip_w_restart(uint32_t reg_base, uint8_t restart) { uint32_t val = 0; val = i2cip_read32(reg_base, I2CIP_CTRL_REG_OFFSET); if (restart) val |= I2CIP_RESTART_ENABLE_MASK; else val &= ~I2CIP_RESTART_ENABLE_MASK; i2cip_write32(val, reg_base, I2CIP_CTRL_REG_OFFSET); return 0; } static inline uint8_t i2cip_w_speed(uint32_t reg_base, uint32_t speed) { uint32_t val = 0; val = i2cip_read32(reg_base, I2CIP_CTRL_REG_OFFSET); val &= ~I2CIP_SPEED_MASK; val |= speed; i2cip_write32(val, reg_base, I2CIP_CTRL_REG_OFFSET); return 0; } static inline uint8_t i2cip_w_standard_speed_hcnt(uint32_t reg_base, uint32_t hcnt) { uint32_t val = 0; val |= hcnt<