HiKey970. I2C Development Guide. Issue 01. Date

Similar documents
Introduction to Linux kernel driver programming + i2c drivers

SPMI: System Power Management Interface

Vinod Koul, Sanyog Kale Intel Corp. MIPI SoundWire Linux Subsystem: An introduction to Protocol and Linux Subsystem

esdk Storage Plugins 1.0.RC4 Compilation Guide 01(vRO) Issue 01 Date HUAWEI TECHNOLOGIES CO., LTD.

F28335 I2C MODULE v1.1

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

AD SSO Technical White Paper

S Series Switch. Cisco HSRP Replacement. Issue 01. Date HUAWEI TECHNOLOGIES CO., LTD.

The Shiny New I2C Slave Framework

Embedded Systems Programming

Hi3520D V200 H.264 CODEC Processor. Brief Data Sheet. Issue 01. Date

Hi3520D V300 H.264 CODEC Processor. Brief Data Sheet. Issue 04. Date

I + I2C = I3C, what s hiding in this additional I

RX Family APPLICATION NOTE. Simple I 2 C Module Using Firmware Integration Technology. Introduction. Target Device.

Live Streaming Accelerator. Quick Start. Issue 03 Date HUAWEI TECHNOLOGIES CO., LTD.

The Cubesat Internal bus: The I2C

SpiNNaker Application Programming Interface (API)

Application Note. Shared IRQ Line Considerations AN-PM-059

Global GPS NMEA over I²C Software Guide V 1.2

For reference only Refer to the latest documents for details

I 2 C Communication. Embedded Systems Interfacing. 25 October 2011

RX Family APPLICATION NOTE. I 2 C Bus Interface (RIIC) Module Using Firmware Integration Technology. Introduction. Target Device.

OceanStor 9000 InfiniBand Technical White Paper. Issue V1.01 Date HUAWEI TECHNOLOGIES CO., LTD.

The I2C BUS Interface

Anti-DDoS. User Guide (Paris) Issue 01 Date HUAWEI TECHNOLOGIES CO., LTD.

Energy Saving Technology White Paper HUAWEI TECHNOLOGIES CO., LTD. Issue 01. Date

Driving Me Nuts Device Classes

Huawei FusionCloud Desktop Solution 5.1 Resource Reuse Technical White Paper HUAWEI TECHNOLOGIES CO., LTD. Issue 01.

Interfacing Z8 Encore! XP MCUs with an I 2 C-Based Character LCD

DRH Hardware Maintenance Guide

esight V300R001C10 SLA Technical White Paper Issue 01 Date HUAWEI TECHNOLOGIES CO., LTD.

Hi3516C Professsional HD IP Camera SoC. Brief Data Sheet. Issue 01. Date Baseline Date

TPMC901-SW-95. QNX4 - Neutrino Device Driver. User Manual. The Embedded I/O Company. 6/4/2 Channel Extended CAN-Bus PMC

L76-L I2C Application Note

Huawei HiAI DDK User Manual

espace SoftConsole V200R001C02 Product Description HUAWEI TECHNOLOGIES CO., LTD. Issue 01 Date

N720 OpenLinux Source Code Developer Guide

Anti-DDoS. FAQs. Issue 11 Date HUAWEI TECHNOLOGIES CO., LTD.

Image Recognition. SDK Reference. Issue 09 Date HUAWEI TECHNOLOGIES CO., LTD.

HUAWEI AR Series SEP Technical White Paper HUAWEI TECHNOLOGIES CO., LTD. Issue 1.0. Date

Guide to Kernel Driver Integration in Android for Huawei Modules. Issue Date

AN-895 APPLICATION NOTE

17. I 2 C communication channel

CODE TIME TECHNOLOGIES. Abassi RTOS. I2C Support

The EFM32 I2C module allows simple, robust and cost effective communication between integrated circuits using only one data and one clock line.

I2C interface Tutorial

Introduction to I2C & SPI. Chapter 22

HWTACACS Technology White Paper

IIC Driver for the MC9S08GW64

CPSC 8220 FINAL EXAM, SPRING 2016

Guide to Kernel Driver Integration in Android for Huawei Modules. Issue Date

Embedded Systems Programming

Technical Specifications

Small Logger File System

Bridging of Control Interfaces over Multimedia Serial Links

Emulating I2C Bus Master by using FlexIO

Each I2C master has 8-deep transmit and receive FIFOs for efficient data handling. SPI to Dual I2C Masters. Registers

Product Description. HUAWEI TalkBand B2 V200R001 HUAWEI TECHNOLOGIES CO., LTD. Issue 03. Date

Huawei MZ110 NIC V100R001. White Paper. Issue 07 Date HUAWEI TECHNOLOGIES CO., LTD.

MPLS OAM Technology White Paper

Two Wire Interface (TWI) also commonly called I2C

I2C. I2C, sometimes IIC or I 2 C, stands for inter IC. 2-line bus, clock (SCL) and data (SDA) Devices individually addressable

White Paper Using the MAX II altufm Megafunction I 2 C Interface

Hi3518E V200 Economical HD IP Camera SoC. Brief Data Sheet. Issue 02. Date

Data Ingestion Service. SDK Development Guide. Issue 03 Date HUAWEI TECHNOLOGIES CO., LTD.

BGP/MPLS VPN Technical White Paper

Preliminary Data MOS IC. Type Ordering Code Package SDA Q67100-H5096 P-DIP-8-1

Janus-MM Basic CAN Driver For Linux 2.6.xx and Windows XP. User Manual Revision A

AN10428 UART-SPI Gateway for Philips SPI slave bridges

Preliminary Data MOS IC. Type Ordering Code Package SDA Q67100-H5092 P-DIP-8-1

MEAS TEMPERATURE SYSTEM SENSOR (TSYS01) XPLAINED PRO BOARD

CALIBRE. I2C Communications Adapter Windows 95 / 98 Driver Manual ICADLL/95 Issue /07/1999

Hi3536 H.265 Decoder Processor. Brief Data Sheet. Issue 03. Date

Embedding it better... µtasker Document. µtasker I 2 C Support, Demo and Simulation

A buffered receiver. receiver task FIFO ...

AN-1159 APPLICATION NOTE

Technical White Paper for NAT Traversal

AN3281 Application note

UM PCAL6524 demonstration board OM Document information

espace UMS V100R001C01SPC100 Product Description Issue 03 Date HUAWEI TECHNOLOGIES CO., LTD.

Implementation of MCU Invariant I2C Slave Driver Using Bit Banging

Bharat Bhushan, Stuart Yoder

Domain Name Service. FAQs. Issue 07 Date HUAWEI TECHNOLOGIES CO., LTD.

1.3inch OLED User Manual

The Serial Device Bus

USB-to-I2C. Ultra Hardware User s Manual.

Vulnerability Scan Service. User Guide. Issue 20 Date HUAWEI TECHNOLOGIES CO., LTD.

DYNAMIC ENGINEERING 435 Park Dr., Ben Lomond, Calif Fax Est

Coccinelle: Killing Driver Bugs Before They Hatch

CAN Module Documentation

regmap The power of subsystems and abstractions 2012 Wolfson Microelectronics plc

HUAWEI Secospace USG Series User Management and Control White Paper

CLD SC58x CDC Library v.1.00 Users Guide Users Guide Revision For Use With Analog Devices ADSP-SC58x Series Processors. Closed Loop Design, LLC

Development and research of different architectures of I 2 C bus controller. E. Vasiliev, MIET

Microcontroller basics

Product Description. MS2372h-153 LTE USB Stick V100R001 HUAWEI TECHNOLOGIES CO., LTD. Issue 01. Date

Audio core for Intel DE-Series Boards. 1 Core Overview. 2 Functional Description. For Quartus Prime 16.1

RL78 Serial interfaces

Quidway S5700 Series Ethernet Switches V100R006C01. Configuration Guide - Ethernet. Issue 02 Date HUAWEI TECHNOLOGIES CO., LTD.

AN Philips LPC2000 CAN driver. Document information

Transcription:

Issue 01 Date 2018-03-11

2018. All rights reserved. No part of this document may be reproduced or transmitted in any form or by any means without prior written consent of HiSilicon Technologies Co., Ltd. Trademarks and Permissions,, and other HiSilicon icons are trademarks of HiSilicon Technologies Co., Ltd. All other trademarks and trade names mentioned in this document are the property of their respective holders. Notice The purchased products, services and features are stipulated by the contract made between HiSilicon and the customer. All or part of the products, services and features described in this document may not be within the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements, information, and recommendations in this document are provided "AS IS" without warranties, guarantees or representations of any kind, either express or implied. The information in this document is subject to change without notice. Every effort has been made in the preparation of this document to ensure accuracy of the contents, but all statements, information, and recommendations in this document do not constitute a warranty of any kind, express or implied. HiSilicon Technologies Co., Ltd. Address: Website: Email: Huawei Industrial Base Bantian, Longgang Shenzhen 518129 People's Republic of China http://www.hisilicon.com support@hisilicon.com i

Change History Change History Changes between document issues are cumulative. The latest document issue contains all the changes made in earlier issues. The first version. i

Contents Contents Change History... i Contents... ii 1 Description... 1 1.1 I2C... 1 1.1.1 General description... 1 1.1.2 Features... 1 1.2 I2C Workflow... 2 1.2.1 I2C Adapter Initialization... 2 1.2.2 Data Transfer... 3 1.3 Development... 4 1.3.1 DTS Configuration... 4 1.3.2 Device Driver Configuration... 4 1.3.3 Data Structure... 5 1.3.4 Function... 6 1.3.5 Reference... 9 ii

1 Description 1.1 I2C 1.1.1 General description 1.1.2 Features The Inter-integrated Circuit (I2C) bus is a very powerful bus used for communication between master and slave devices. The physical I2C interface consists of the serial data (SDA) and serial clock (SCL) lines. Here the I2C module is a controller or master that communicates with the slave devices. The I2C has the following features: Supports the I2C-bus specification version 2.1. It can only be used as a Master on the I2C bus, and it cannot be used as a Slave. As a transmitter on the I2C bus, the master sends data to the slave. The slave address supported as the master device: standard address (7-bit) and extended address (10-bit). Supports standard mode 100kbit/s, fast mode 400kbit/s, and high-speed mode 3.4Mbit/s data rates. Provides transmit FIFO, receive FIFO, and DMA data transfer methods. Supports interrupt reporting and initial interrupt status and masked interrupt status query. Support Clock stretching function. During data transmission, when the transmit FIFO data is empty, pull down the SCL and wait for the FIFO to fill the data again. During data reception, when the receive FIFO data is empty, pull down the SCL and wait for the FIFO to fill the data again. Supports SDA data Restart transmission. The data bus is not released and transmission continues on the same channel. 1

1.2 I2C Workflow 1.2.1 I2C Adapter Initialization dw_i2c_plat_probe i2c_dw_probe i2c_dw_algo i2c_dw_isr i2c_add_numbered_adapter i2c_register_adapter of_i2c_register_devices of_i2c_register_device Parses the DTS file I2C adapter node, obtains relevant hardware information, initializes the I2C adapter, matches compatible attributes in DTS file, struct i2c_algorithm type initializes i2c_dw_algo, implements master_xfer() function and functionality() function, registers interrupt handling function i2c_dw_isr, adds I2C adapter, register I2C devices. 2

1.2.2 Data Transfer i2cdev_write / i2cdev_read i2c_transfer i2c_transfer adap->algo->master_xfer: i2c_dw_xfer i2c_dw_xfer_init i2c_dw_isr i2c_dw_xfer_msg / i2c_dw_read complete(&dev->cmd_complete) 1. I2C device to send and receive data, call the driver interface write or read; 2. Start the data transfer by calling the i2c_transfer function in the file drivers/i2c/i2c-core.c; 3. i2c_transfer calls i2c_transfer to execute the master_xfer function, which is a callback function i2c_dw_xfer registered when I2C adapter is started. The i2c_dw_xfer function is in the file drivers/i2c/busses/i2c-designware-core.c; 4. At this point, open the I2C controller via the i2c_dw_xfer_init function and enable the interrupt. 5. Receives an interrupt and executes the interrupt handler i2c_dw_isr; 6. Send and receive data through i2c_dw_xfer_msg or i2c_dw_read; 7. release complete to finish this transmission; ----End 3

1.3 Development 1.3.1 DTS Configuration The DTS configuration of the I2C adapter mainly involves the file kirin970.dtsi i2c0: i2c@ffd71000 { compatible = "snps,designware-i2c"; reg = <0x0 0xffd71000 0x0 0x1000>; interrupts = <GIC_SPI 118 IRQ_TYPE_LEVEL_HIGH>; #address-cells = <1>; #size-cells = <0>; clock-frequency = <400000>; clocks = <&iomcu KIRIN970_CLK_GATE_I2C0>; resets = <&iomcu_rst 0x20 3>; pinctrl-names = "default"; pinctrl-0 = <&i2c0_pmx_func &i2c0_cfg_func>; status = "disabled"; }; This I2C adapter configuration includes the base address, interrupt number, clock configuration, reset, and I2C adapter switches. For I2C device configuration can be placed in file kirin970-hikey970.dts. Here are some examples. &i2c0 { status = "okay"; myi2cdev@50 { compatible = "myi2cdev"; reg = <0x50>;... }; }; The above 2f is the device address and is modified as required. 1.3.2 Device Driver Configuration 1. Modify the file arch/arm64/configs/hikey970_defconfig and add: CONFIG_I2C_MYI2CDEV =y 2. Modify the file drivers/i2c/makefile and add: obj-$(config_i2c_myi2cdev) += myi2cdev.o 4

1.3.3 Data Structure 1.3.3.1 I2C Client 1.3.3.2 I2C driver struct i2c_client { unsigned short flags; /* div., see below */ unsigned short addr; /* chip address - NOTE: 7bit */ /* addresses are stored in the */ /* _LOWER_ 7 bits */ char name[i2c_name_size]; struct i2c_adapter *adapter; /* the adapter we sit on */ struct device dev; /* the device structure */ int irq; /* irq issued by device */ struct list_head detected; #if IS_ENABLED(CONFIG_I2C_SLAVE) i2c_slave_cb_t slave_cb; /* callback for slave mode */ #endif }; struct i2c_driver { unsigned int class; /* Notifies the driver that a new bus has appeared. You should avoid * using this, it will be removed in a near future. */ int (*attach_adapter)(struct i2c_adapter *) deprecated; /* Standard driver model interfaces */ int (*probe)(struct i2c_client *, const struct i2c_device_id *); int (*remove)(struct i2c_client *); /* driver model interfaces that don't relate to enumeration */ void (*shutdown)(struct i2c_client *); /* Alert callback, for example for the SMBus alert protocol. * The format and meaning of the data value depends on the protocol. * For the SMBus alert protocol, there is a single bit of data passed * as the alert response's low bit ("event flag"). * For the SMBus Host Notify protocol, the data corresponds to the * 16-bit payload data reported by the slave device acting as master. */ void (*alert)(struct i2c_client *, enum i2c_alert_protocol protocol, unsigned int data); 5

/* a ioctl like command that can be used to perform specific functions * with the device. */ int (*command)(struct i2c_client *client, unsigned int cmd, void *arg); struct device_driver driver; const struct i2c_device_id *id_table; }; /* Device detection callback for automatic device creation */ int (*detect)(struct i2c_client *, struct i2c_board_info *); const unsigned short *address_list; struct list_head clients; 1.3.4 Function 1.3.4.1 i2c_add_numbered_adapter prototype #include <linux/i2c.h> int i2c_add_numbered_adapter(struct i2c_adapter *adap); description declare i2c adapter, use static bus number parameter adap: the adapter to register (with adap->nr initialized) return 1.3.4.2 i2c_add_driver zero on success, else a negative error code. prototype #include <linux/i2c.h> #define i2c_add_driver(driver) i2c_register_driver(this_module, driver) int i2c_register_driver(struct module *owner, struct i2c_driver *driver) description register a I2C driver 6

parameter owner: owner module of the driver to register driver: the driver to register return 1.3.4.3 i2c_del_driver zero on success, else a negative error code. prototype void i2c_del_driver(struct i2c_driver *driver); description unregister I2C driver parameter driver: the driver being unregistered return none 1.3.4.4 i2c_new_device prototype #include <linux/i2c.h> struct i2c_client * i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info); description instantiate an i2c device parameter adap: the adapter managing the device info: describes one I2C device; bus_num is ignored return This returns the new i2c client, which may be saved for later use with i2c_unregister_device(); or NULL to indicate an error. 7

1.3.4.5 i2c_transfer prototype #include <linux/i2c.h> int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); description execute a single or combined I2C message parameter adap: Handle to I2C bus msgs: One or more messages to execute before STOP is issued to terminate the operation; each message begins with a START. num: Number of messages to be executed. return 1.3.4.6 i2c_master_send Returns negative errno, else the number of messages executed. prototype #include <linux/i2c.h> int i2c_master_send(const struct i2c_client *client, const char *buf, int count); description issue a single I2C message in master transmit mode parameter client: Handle to slave device buf: Data that will be written to the slave count: How many bytes to write, must be less than 64k since msg.len is u16 return 1.3.4.7 i2c_master_recv Returns negative errno, or else the number of bytes written. prototype #include <linux/i2c.h> int i2c_master_recv(const struct i2c_client *client, char *buf, int count); 8

description issue a single I2C message in master receive mode parameter client: Handle to slave device buf: Where to store data read from slave count: How many bytes to read, must be less than 64k since msg.len is u16 return 1.3.5 Reference Returns negative errno, or else the number of bytes read. Add your own device driver file drivers/i2c/myi2cdev.c. If the device in dts matches this driver, execute myi2cdev_probe() in the file myi2cdev.c. The myi2cdev_probe() function is implemented by the user according to the requirements static const struct of_device_id myi2cdev_of_match[] = { {.compatible = "myi2cdev",}, { } }; MODULE_DEVICE_TABLE(of, myi2cdev_of_match); static int myi2cdev_probe(struct i2c_client *client, const struct i2c_device_id *id) { } static int myi2cdev_remove(struct i2c_client *i2c) { } static struct i2c_driver myi2cdev_i2c_driver = {.driver = {.name = "myi2cdev",.of_match_table = myi2cdev_of_match, },.probe = myi2cdev_probe,.remove = myi2cdev_remove, }; 9

static int init myi2cdev_init(void) { return i2c_add_driver(&myi2cdev_i2c_driver); } subsys_initcall(myi2cdev_init); static void exit myi2cdev_exit(void) { i2c_del_driver(&myi2cdev_i2c_driver); } module_exit(myi2cdev_exit) 10