Azure Sphere MT3620 M4 API Reference Manual
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
mhal_i2c.h
1 /*
2  * (C) 2005-2020 MediaTek Inc. All rights reserved.
3  *
4  * Copyright Statement:
5  *
6  * This MT3620 driver software/firmware and related documentation
7  * ("MediaTek Software") are protected under relevant copyright laws.
8  * The information contained herein is confidential and proprietary to
9  * MediaTek Inc. ("MediaTek"). You may only use, reproduce, modify, or
10  * distribute (as applicable) MediaTek Software if you have agreed to and been
11  * bound by this Statement and the applicable license agreement with MediaTek
12  * ("License Agreement") and been granted explicit permission to do so within
13  * the License Agreement ("Permitted User"). If you are not a Permitted User,
14  * please cease any access or use of MediaTek Software immediately.
15  *
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
18  * PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS
19  * ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
21  * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH
22  * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
23  * INCORPORATED IN, OR SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO
24  * LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
25  * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
26  * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK
27  * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE
28  * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
29  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S
30  * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED
31  * HEREUNDER WILL BE ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
32  * RECEIVER TO MEDIATEK DURING THE PRECEDING TWELVE (12) MONTHS FOR SUCH
33  * MEDIATEK SOFTWARE AT ISSUE.
34  */
35 
36 #ifndef __MHAL_I2C__H__
37 #define __MHAL_I2C__H__
38 
39 #include "mhal_osai.h"
40 
110 #define I2C_OK 0
111 
112 #define I2C_EPTR 1
113 
114 #define I2C_EFIFO 2
115 
116 #define I2C_ENXIO 6
117 
118 #define I2C_EBUSY 16
119 
120 #define I2C_EINVAL 22
121 
122 #define I2C_ETIMEDOUT 110
123 
125 #define I2C_TRANS_DONE 0
126 
129 #define I2C_WAIT_DMA 1
130 
157 };
158 
173 };
174 
175 /*@brief I2C controller role definition
176  * Before performing transfer, users should indicate the
177  * controller as the master role or slave role.
178 */
184 };
185 
211 typedef int (*i2c_dma_done_callback) (void *user_data);
212 
228 struct i2c_msg {
232  u8 addr;
241  u16 len;
243  u8 *buf;
244 };
245 
252  u8 *tx_buff;
254  u8 *rx_buff;
256  dma_addr_t tx_dma_addr;
258  dma_addr_t rx_dma_addr;
260  u32 tx_len;
262  u32 rx_len;
266  void *user_data;
267 
272 };
273 
280  void __iomem *base;
281 
283  void __iomem *cg_base;
284 
289 
291  struct i2c_msg *msg;
292 
295 
297  bool dma_en;
298 
303  u32 irq_stat;
304 
306  u32 timeout;
307 
310 
313 
315  u8 op;
316 
319 
322 };
323 
334 #ifdef __cplusplus
335 extern "C" {
336 #endif
337 
351 
369 
384 
400 
415 
428 
441 
458  enum i2c_speed_kHz);
459 
476 int mtk_mhal_i2c_init_slv_addr(struct mtk_i2c_controller *i2c, u8 slv_addr);
477 
499  struct mtk_i2c_controller *i2c,
500  i2c_dma_done_callback callback,
501  void *user_data);
502 
514 
525 
526 #ifdef __cplusplus
527 }
528 #endif
529 
538 #endif
Transmit data with 1000 kbps.
Definition: mhal_i2c.h:156
int mtk_mhal_i2c_disable_clk(struct mtk_i2c_controller *i2c)
This function is used to disable I2C clock after transfer.
int mtk_mhal_i2c_dump_register(struct mtk_i2c_controller *i2c)
This function is used to dump I2C register value for debugging.
u8 msg_num
The number of message.
Definition: mhal_i2c.h:294
i2c_speed_kHz
I2C master's clock frequency definition.
Definition: mhal_i2c.h:146
int mtk_mhal_i2c_irq_handle(struct mtk_i2c_controller *i2c)
Get I2C irq status and clear irq status reg.
Set I2C controller to master role.
Definition: mhal_i2c.h:181
void __iomem * base
I2C controller base address.
Definition: mhal_i2c.h:280
u32 rx_len
Temp transfer length to DMA.
Definition: mhal_i2c.h:262
Transmit data with 100 kbps.
Definition: mhal_i2c.h:150
I2C master reads data from slave.
Definition: mhal_i2c.h:168
void __iomem * cg_base
Clock gate base address of I2C controller.
Definition: mhal_i2c.h:283
u32 irq_stat
Interrupt flag, this parameter will be set in mtk_mhal_i2c_irq_handle().
Definition: mhal_i2c.h:303
int mtk_mhal_i2c_trigger_transfer(struct mtk_i2c_controller *i2c)
This function is used to trigger I2C controller transfer.
Interface to messages.
Definition: mhal_i2c.h:228
u32 tx_len
Temp transfer length to DMA.
Definition: mhal_i2c.h:260
u8 * buf
Pointer to read or write data buffer.
Definition: mhal_i2c.h:243
bool dma_en
I2C supports FIFO mode and DMA mode, 0: FIFO mode, 1: DMA mode.
Definition: mhal_i2c.h:297
int mtk_mhal_i2c_enable_clk(struct mtk_i2c_controller *i2c)
Enable I2C clock before transfer.
enum i2c_trans_op flags
I2C transfer operation mode.
Definition: mhal_i2c.h:239
int(* i2c_dma_done_callback)(void *user_data)
This defines the callback function prototype.
Definition: mhal_i2c.h:211
struct mtk_i2c_private * mdata
M-HAL private structure is used by M-HAL only.
Definition: mhal_i2c.h:321
u16 len
Read or write data length, unit: byte.
Definition: mhal_i2c.h:241
u32 timeout
Set the transmission timeout period.
Definition: mhal_i2c.h:306
enum i2c_trans_mode i2c_mode
0: Set I2C controller as a master or slave role
Definition: mhal_i2c.h:312
u8 addr
The address of slave device which the master access.
Definition: mhal_i2c.h:232
u8 * tx_buff
used for tx temp buf
Definition: mhal_i2c.h:252
Transmit data with 200 kbps.
Definition: mhal_i2c.h:152
int mtk_mhal_i2c_init_slv_addr(struct mtk_i2c_controller *i2c, u8 slv_addr)
This function is used to set I2C salve address.
M-HAL private structure.
Definition: mhal_i2c.h:250
i2c_dma_done_callback dma_done_callback
This function is used to register user's DMA done callback to OS-HAL layer.
Definition: mhal_i2c.h:271
int mtk_mhal_i2c_result_handle(struct mtk_i2c_controller *i2c)
This fuction is used to analyze the type of i2c interrupt.
void * user_data
User_data is an OS-HAL defined parameter provided by mtk_mhal_i2c_dma_done_callback_register().
Definition: mhal_i2c.h:266
int mtk_mhal_i2c_init_hw(struct mtk_i2c_controller *i2c)
This function is used to initialize I2C and DMA hardware.
u8 slave_addr
Set i2c slave address, default by 0x20.
Definition: mhal_i2c.h:318
i2c_trans_mode
Definition: mhal_i2c.h:179
dma_addr_t rx_dma_addr
temp rx DMA physical addr
Definition: mhal_i2c.h:258
The mtk_i2c_controller contains hardware information( such as base address) of i2c controller...
Definition: mhal_i2c.h:278
int mtk_mhal_i2c_release_dma(struct mtk_i2c_controller *i2c)
This function is used to release I2C DMA channel.
enum i2c_speed_kHz i2c_speed
I2C master transfer speed.
Definition: mhal_i2c.h:309
u8 op
I2C master transfer mode, it is used to HDL driver.
Definition: mhal_i2c.h:315
struct i2c_msg * msg
Configure I2C transfer message.
Definition: mhal_i2c.h:291
I2C slave sends data to master.
Definition: mhal_i2c.h:172
Transmit data with 50 kbps.
Definition: mhal_i2c.h:148
I2C slave receives data from master.
Definition: mhal_i2c.h:170
i2c_trans_op
I2C controller operation mode definition.
Definition: mhal_i2c.h:164
I2C master writes data to slave.
Definition: mhal_i2c.h:166
u8 * rx_buff
used for rx temp buf
Definition: mhal_i2c.h:254
int mtk_mhal_i2c_dma_done_callback_register(struct mtk_i2c_controller *i2c, i2c_dma_done_callback callback, void *user_data)
This defines the callback function prototype.
int dma_rx_chan
RX DMA channel.
Definition: mhal_i2c.h:288
Transmit data with 400 kbps.
Definition: mhal_i2c.h:154
int dma_tx_chan
TX DMA channel.
Definition: mhal_i2c.h:286
int mtk_mhal_i2c_init_speed(struct mtk_i2c_controller *i2c, enum i2c_speed_kHz)
This function is used to initialize transfer speed.
Set I2C controller to slave role.
Definition: mhal_i2c.h:183
dma_addr_t tx_dma_addr
temp tx DMA physical addr
Definition: mhal_i2c.h:256
int mtk_mhal_i2c_request_dma(struct mtk_i2c_controller *i2c)
This function is used to allocate I2C DMA channel.