b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Marvell Inc, <www.marvell.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #ifndef _MV_I2C_H_ |
| 9 | #define _MV_I2C_H_ |
| 10 | extern void i2c_clk_enable(void); |
| 11 | #ifdef CONFIG_ASR1901 |
| 12 | /* Shall the current transfer have a start/stop condition? */ |
| 13 | #define I2C_COND_NORMAL 0 |
| 14 | #define I2C_COND_START 1 |
| 15 | #define I2C_COND_STOP 2 |
| 16 | |
| 17 | /* Shall the current transfer be ack/nacked or being waited for it? */ |
| 18 | #define I2C_ACKNAK_WAITACK 1 |
| 19 | #define I2C_ACKNAK_SENDACK 2 |
| 20 | #define I2C_ACKNAK_SENDNAK 4 |
| 21 | |
| 22 | /* Specify who shall transfer the data (master or slave) */ |
| 23 | #define I2C_READ 0 |
| 24 | #define I2C_WRITE 1 |
| 25 | |
| 26 | #if (CONFIG_SYS_I2C_SPEED == 400000) |
| 27 | #define I2C_ICR_INIT (ICR_FM | ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD \ |
| 28 | | ICR_SCLE) |
| 29 | #else |
| 30 | #define I2C_ICR_INIT (ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD | ICR_SCLE) |
| 31 | #endif |
| 32 | |
| 33 | #define I2C_ISR_INIT 0xFFFFFFFF |
| 34 | /* ----- Control register bits ---------------------------------------- */ |
| 35 | |
| 36 | #define ICR_START (0x1 << 0) /* start bit */ |
| 37 | #define ICR_STOP (0x1 << 1) /* stop bit */ |
| 38 | #define ICR_ACKNAK (0x1 << 2) /* send ACK(0) or NAK(1) */ |
| 39 | #define ICR_TB (0x1 << 3) /* transfer byte bit */ |
| 40 | #define ICR_MA (0x1 << 12) /* master abort */ |
| 41 | #define ICR_SCLE (0x1 << 13) /* master clock enable, mona SCLEA */ |
| 42 | #define ICR_IUE (0x1 << 14) /* unit enable */ |
| 43 | #define ICR_GCD (0x1 << 21) /* general call disable */ |
| 44 | #define ICR_ITEIE (0x1 << 19) /* enable tx interrupts */ |
| 45 | #define ICR_IRFIE (0x1 << 20) /* enable rx interrupts, mona: DRFIE */ |
| 46 | #define ICR_BEIE (0x1 << 22) /* enable bus error ints */ |
| 47 | #define ICR_SSDIE (0x1 << 24) /* slave STOP detected int enable */ |
| 48 | #define ICR_ALDIE (0x1 << 18) /* enable arbitration interrupt */ |
| 49 | #define ICR_SADIE (0x1 << 23) /* slave address detected int enable */ |
| 50 | #define ICR_UR (0x1 << 10) /* unit reset */ |
| 51 | #define ICR_FM (0x1 << 8) /* Fast Mode */ |
| 52 | #define ICR_BUS_RESET (0x1 << 11) /* Bus Reset */ |
| 53 | |
| 54 | /* ----- Status register bits ----------------------------------------- */ |
| 55 | |
| 56 | #define ISR_RWM (0x1 << 13) /* read/write mode */ |
| 57 | #define ISR_ACKNAK (0x1 << 14) /* ack/nak status */ |
| 58 | #define ISR_UB (0x1 << 15) /* unit busy */ |
| 59 | #define ISR_IBB (0x1 << 16) /* bus busy */ |
| 60 | #define ISR_SSD (0x1 << 24) /* slave stop detected */ |
| 61 | #define ISR_ALD (0x1 << 18) /* arbitration loss detected */ |
| 62 | #define ISR_ITE (0x1 << 19) /* tx buffer empty */ |
| 63 | #define ISR_IRF (0x1 << 20) /* rx buffer full */ |
| 64 | #define ISR_GCAD (0x1 << 21) /* general call address detected */ |
| 65 | #define ISR_SAD (0x1 << 23) /* slave address detected */ |
| 66 | #define ISR_BED (0x1 << 22) /* bus error no ACK/NAK */ |
| 67 | #else |
| 68 | /* Shall the current transfer have a start/stop condition? */ |
| 69 | #define I2C_COND_NORMAL 0 |
| 70 | #define I2C_COND_START 1 |
| 71 | #define I2C_COND_STOP 2 |
| 72 | |
| 73 | /* Shall the current transfer be ack/nacked or being waited for it? */ |
| 74 | #define I2C_ACKNAK_WAITACK 1 |
| 75 | #define I2C_ACKNAK_SENDACK 2 |
| 76 | #define I2C_ACKNAK_SENDNAK 4 |
| 77 | |
| 78 | /* Specify who shall transfer the data (master or slave) */ |
| 79 | #define I2C_READ 0 |
| 80 | #define I2C_WRITE 1 |
| 81 | |
| 82 | #if (CONFIG_SYS_I2C_SPEED == 400000) |
| 83 | #define I2C_ICR_INIT (ICR_FM | ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD \ |
| 84 | | ICR_SCLE) |
| 85 | #else |
| 86 | #define I2C_ICR_INIT (ICR_BEIE | ICR_IRFIE | ICR_ITEIE | ICR_GCD | ICR_SCLE) |
| 87 | #endif |
| 88 | |
| 89 | #define I2C_ISR_INIT 0x7FF |
| 90 | /* ----- Control register bits ---------------------------------------- */ |
| 91 | |
| 92 | #define ICR_START 0x1 /* start bit */ |
| 93 | #define ICR_STOP 0x2 /* stop bit */ |
| 94 | #define ICR_ACKNAK 0x4 /* send ACK(0) or NAK(1) */ |
| 95 | #define ICR_TB 0x8 /* transfer byte bit */ |
| 96 | #define ICR_MA 0x10 /* master abort */ |
| 97 | #define ICR_SCLE 0x20 /* master clock enable, mona SCLEA */ |
| 98 | #define ICR_IUE 0x40 /* unit enable */ |
| 99 | #define ICR_GCD 0x80 /* general call disable */ |
| 100 | #define ICR_ITEIE 0x100 /* enable tx interrupts */ |
| 101 | #define ICR_IRFIE 0x200 /* enable rx interrupts, mona: DRFIE */ |
| 102 | #define ICR_BEIE 0x400 /* enable bus error ints */ |
| 103 | #define ICR_SSDIE 0x800 /* slave STOP detected int enable */ |
| 104 | #define ICR_ALDIE 0x1000 /* enable arbitration interrupt */ |
| 105 | #define ICR_SADIE 0x2000 /* slave address detected int enable */ |
| 106 | #define ICR_UR 0x4000 /* unit reset */ |
| 107 | #define ICR_FM 0x8000 /* Fast Mode */ |
| 108 | #define ICR_BUS_RESET 0x10000000 /* Bus Reset */ |
| 109 | |
| 110 | /* ----- Status register bits ----------------------------------------- */ |
| 111 | |
| 112 | #define ISR_RWM 0x1 /* read/write mode */ |
| 113 | #define ISR_ACKNAK 0x2 /* ack/nak status */ |
| 114 | #define ISR_UB 0x4 /* unit busy */ |
| 115 | #define ISR_IBB 0x8 /* bus busy */ |
| 116 | #define ISR_SSD 0x10 /* slave stop detected */ |
| 117 | #define ISR_ALD 0x20 /* arbitration loss detected */ |
| 118 | #define ISR_ITE 0x40 /* tx buffer empty */ |
| 119 | #define ISR_IRF 0x80 /* rx buffer full */ |
| 120 | #define ISR_GCAD 0x100 /* general call address detected */ |
| 121 | #define ISR_SAD 0x200 /* slave address detected */ |
| 122 | #define ISR_BED 0x400 /* bus error no ACK/NAK */ |
| 123 | #endif |
| 124 | #endif |