1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */ 2938717ceSSteve Sakoman /* 3938717ceSSteve Sakoman * (C) Copyright 2004-2010 4938717ceSSteve Sakoman * Texas Instruments, <www.ti.com> 5938717ceSSteve Sakoman */ 607cf5e20SNishanth Menon #ifndef _OMAP2PLUS_I2C_H_ 707cf5e20SNishanth Menon #define _OMAP2PLUS_I2C_H_ 8938717ceSSteve Sakoman 9938717ceSSteve Sakoman /* I2C masks */ 10938717ceSSteve Sakoman 11938717ceSSteve Sakoman /* I2C Interrupt Enable Register (I2C_IE): */ 12938717ceSSteve Sakoman #define I2C_IE_GC_IE (1 << 5) 13938717ceSSteve Sakoman #define I2C_IE_XRDY_IE (1 << 4) /* Transmit data ready interrupt enable */ 14938717ceSSteve Sakoman #define I2C_IE_RRDY_IE (1 << 3) /* Receive data ready interrupt enable */ 15938717ceSSteve Sakoman #define I2C_IE_ARDY_IE (1 << 2) /* Register access ready interrupt enable */ 16938717ceSSteve Sakoman #define I2C_IE_NACK_IE (1 << 1) /* No acknowledgment interrupt enable */ 17938717ceSSteve Sakoman #define I2C_IE_AL_IE (1 << 0) /* Arbitration lost interrupt enable */ 18938717ceSSteve Sakoman 19938717ceSSteve Sakoman /* I2C Status Register (I2C_STAT): */ 20938717ceSSteve Sakoman 21938717ceSSteve Sakoman #define I2C_STAT_SBD (1 << 15) /* Single byte data */ 22938717ceSSteve Sakoman #define I2C_STAT_BB (1 << 12) /* Bus busy */ 23938717ceSSteve Sakoman #define I2C_STAT_ROVR (1 << 11) /* Receive overrun */ 24938717ceSSteve Sakoman #define I2C_STAT_XUDF (1 << 10) /* Transmit underflow */ 25938717ceSSteve Sakoman #define I2C_STAT_AAS (1 << 9) /* Address as slave */ 26938717ceSSteve Sakoman #define I2C_STAT_GC (1 << 5) 27938717ceSSteve Sakoman #define I2C_STAT_XRDY (1 << 4) /* Transmit data ready */ 28938717ceSSteve Sakoman #define I2C_STAT_RRDY (1 << 3) /* Receive data ready */ 29938717ceSSteve Sakoman #define I2C_STAT_ARDY (1 << 2) /* Register access ready */ 30938717ceSSteve Sakoman #define I2C_STAT_NACK (1 << 1) /* No acknowledgment interrupt enable */ 31938717ceSSteve Sakoman #define I2C_STAT_AL (1 << 0) /* Arbitration lost interrupt enable */ 32938717ceSSteve Sakoman 33938717ceSSteve Sakoman /* I2C Interrupt Code Register (I2C_INTCODE): */ 34938717ceSSteve Sakoman 35938717ceSSteve Sakoman #define I2C_INTCODE_MASK 7 36938717ceSSteve Sakoman #define I2C_INTCODE_NONE 0 37938717ceSSteve Sakoman #define I2C_INTCODE_AL 1 /* Arbitration lost */ 38938717ceSSteve Sakoman #define I2C_INTCODE_NAK 2 /* No acknowledgement/general call */ 39938717ceSSteve Sakoman #define I2C_INTCODE_ARDY 3 /* Register access ready */ 40938717ceSSteve Sakoman #define I2C_INTCODE_RRDY 4 /* Rcv data ready */ 41938717ceSSteve Sakoman #define I2C_INTCODE_XRDY 5 /* Xmit data ready */ 42938717ceSSteve Sakoman 43938717ceSSteve Sakoman /* I2C Buffer Configuration Register (I2C_BUF): */ 44938717ceSSteve Sakoman 45938717ceSSteve Sakoman #define I2C_BUF_RDMA_EN (1 << 15) /* Receive DMA channel enable */ 46938717ceSSteve Sakoman #define I2C_BUF_XDMA_EN (1 << 7) /* Transmit DMA channel enable */ 47938717ceSSteve Sakoman 48938717ceSSteve Sakoman /* I2C Configuration Register (I2C_CON): */ 49938717ceSSteve Sakoman 50938717ceSSteve Sakoman #define I2C_CON_EN (1 << 15) /* I2C module enable */ 51938717ceSSteve Sakoman #define I2C_CON_BE (1 << 14) /* Big endian mode */ 52938717ceSSteve Sakoman #define I2C_CON_STB (1 << 11) /* Start byte mode (master mode only) */ 53938717ceSSteve Sakoman #define I2C_CON_MST (1 << 10) /* Master/slave mode */ 54938717ceSSteve Sakoman #define I2C_CON_TRX (1 << 9) /* Transmitter/receiver mode */ 55938717ceSSteve Sakoman /* (master mode only) */ 56938717ceSSteve Sakoman #define I2C_CON_XA (1 << 8) /* Expand address */ 57938717ceSSteve Sakoman #define I2C_CON_STP (1 << 1) /* Stop condition (master mode only) */ 58938717ceSSteve Sakoman #define I2C_CON_STT (1 << 0) /* Start condition (master mode only) */ 59938717ceSSteve Sakoman 60938717ceSSteve Sakoman /* I2C System Test Register (I2C_SYSTEST): */ 61938717ceSSteve Sakoman 62938717ceSSteve Sakoman #define I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */ 63938717ceSSteve Sakoman #define I2C_SYSTEST_FREE (1 << 14) /* Free running mode, on brkpoint) */ 64938717ceSSteve Sakoman #define I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */ 65938717ceSSteve Sakoman #define I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */ 66938717ceSSteve Sakoman #define I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense input value */ 67938717ceSSteve Sakoman #define I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive output value */ 68938717ceSSteve Sakoman #define I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense input value */ 69938717ceSSteve Sakoman #define I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive output value */ 70938717ceSSteve Sakoman 71d708395dSSteve Sakoman /* I2C System Status Register (I2C_SYSS): */ 72d708395dSSteve Sakoman 73d708395dSSteve Sakoman #define I2C_SYSS_RDONE (1 << 0) /* Internel reset monitoring */ 74d708395dSSteve Sakoman 75938717ceSSteve Sakoman #define I2C_SCLL_SCLL 0 76938717ceSSteve Sakoman #define I2C_SCLL_SCLL_M 0xFF 77938717ceSSteve Sakoman #define I2C_SCLL_HSSCLL 8 78938717ceSSteve Sakoman #define I2C_SCLH_HSSCLL_M 0xFF 79938717ceSSteve Sakoman #define I2C_SCLH_SCLH 0 80938717ceSSteve Sakoman #define I2C_SCLH_SCLH_M 0xFF 81938717ceSSteve Sakoman #define I2C_SCLH_HSSCLH 8 82938717ceSSteve Sakoman #define I2C_SCLH_HSSCLH_M 0xFF 83938717ceSSteve Sakoman 84938717ceSSteve Sakoman #define OMAP_I2C_STANDARD 100000 85938717ceSSteve Sakoman #define OMAP_I2C_FAST_MODE 400000 86938717ceSSteve Sakoman #define OMAP_I2C_HIGH_SPEED 3400000 87938717ceSSteve Sakoman 88938717ceSSteve Sakoman #define SYSTEM_CLOCK_12 12000000 89938717ceSSteve Sakoman #define SYSTEM_CLOCK_13 13000000 90938717ceSSteve Sakoman #define SYSTEM_CLOCK_192 19200000 91938717ceSSteve Sakoman #define SYSTEM_CLOCK_96 96000000 92938717ceSSteve Sakoman 93938717ceSSteve Sakoman /* Use the reference value of 96MHz if not explicitly set by the board */ 94938717ceSSteve Sakoman #ifndef I2C_IP_CLK 95938717ceSSteve Sakoman #define I2C_IP_CLK SYSTEM_CLOCK_96 96938717ceSSteve Sakoman #endif 97938717ceSSteve Sakoman 98938717ceSSteve Sakoman /* 99938717ceSSteve Sakoman * The reference minimum clock for high speed is 19.2MHz. 100938717ceSSteve Sakoman * The linux 2.6.30 kernel uses this value. 101938717ceSSteve Sakoman * The reference minimum clock for fast mode is 9.6MHz 102938717ceSSteve Sakoman * The reference minimum clock for standard mode is 4MHz 103938717ceSSteve Sakoman * In TRM, the value of 12MHz is used. 104938717ceSSteve Sakoman */ 105938717ceSSteve Sakoman #ifndef I2C_INTERNAL_SAMPLING_CLK 106938717ceSSteve Sakoman #define I2C_INTERNAL_SAMPLING_CLK 19200000 107938717ceSSteve Sakoman #endif 108938717ceSSteve Sakoman 109938717ceSSteve Sakoman /* 110938717ceSSteve Sakoman * The equation for the low and high time is 111938717ceSSteve Sakoman * tlow = scll + scll_trim = (sampling clock * tlow_duty) / speed 112938717ceSSteve Sakoman * thigh = sclh + sclh_trim = (sampling clock * (1 - tlow_duty)) / speed 113938717ceSSteve Sakoman * 114938717ceSSteve Sakoman * If the duty cycle is 50% 115938717ceSSteve Sakoman * 116938717ceSSteve Sakoman * tlow = scll + scll_trim = sampling clock / (2 * speed) 117938717ceSSteve Sakoman * thigh = sclh + sclh_trim = sampling clock / (2 * speed) 118938717ceSSteve Sakoman * 119938717ceSSteve Sakoman * In TRM 120938717ceSSteve Sakoman * scll_trim = 7 121938717ceSSteve Sakoman * sclh_trim = 5 122938717ceSSteve Sakoman * 123e530d2e1SLukasz Majewski * The linux 4.9 kernel uses 124e530d2e1SLukasz Majewski * scll_trim = 7 125e530d2e1SLukasz Majewski * sclh_trim = 5 126938717ceSSteve Sakoman * 127938717ceSSteve Sakoman * These are the trim values for standard and fast speed 128938717ceSSteve Sakoman */ 129938717ceSSteve Sakoman #ifndef I2C_FASTSPEED_SCLL_TRIM 130e530d2e1SLukasz Majewski #define I2C_FASTSPEED_SCLL_TRIM 7 131938717ceSSteve Sakoman #endif 132938717ceSSteve Sakoman #ifndef I2C_FASTSPEED_SCLH_TRIM 133e530d2e1SLukasz Majewski #define I2C_FASTSPEED_SCLH_TRIM 5 134938717ceSSteve Sakoman #endif 135938717ceSSteve Sakoman 136938717ceSSteve Sakoman /* These are the trim values for high speed */ 137938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM 138938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_ONE_SCLL_TRIM I2C_FASTSPEED_SCLL_TRIM 139938717ceSSteve Sakoman #endif 140938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM 141938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_ONE_SCLH_TRIM I2C_FASTSPEED_SCLH_TRIM 142938717ceSSteve Sakoman #endif 143938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM 144938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_TWO_SCLL_TRIM I2C_FASTSPEED_SCLL_TRIM 145938717ceSSteve Sakoman #endif 146938717ceSSteve Sakoman #ifndef I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM 147938717ceSSteve Sakoman #define I2C_HIGHSPEED_PHASE_TWO_SCLH_TRIM I2C_FASTSPEED_SCLH_TRIM 148938717ceSSteve Sakoman #endif 149938717ceSSteve Sakoman 150938717ceSSteve Sakoman #define I2C_PSC_MAX 0x0f 151938717ceSSteve Sakoman #define I2C_PSC_MIN 0x00 152938717ceSSteve Sakoman 153938717ceSSteve Sakoman #endif /* _OMAP24XX_I2C_H_ */ 154