Macpaul Lin | 65224c3 | 2011-04-24 22:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Register definitions for the Andes SPI Controller |
| 3 | * |
| 4 | * (C) Copyright 2011 Andes Technology |
| 5 | * Macpaul Lin <macpaul@andestech.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #ifndef __ANDES_SPI_H |
| 24 | #define __ANDES_SPI_H |
| 25 | |
| 26 | struct andes_spi_regs { |
| 27 | unsigned int apb; /* 0x00 - APB SPI interface setting */ |
| 28 | unsigned int pio; /* 0x04 - PIO reg */ |
| 29 | unsigned int cr; /* 0x08 - SPI Control reg */ |
| 30 | unsigned int st; /* 0x0c - SPI Status reg */ |
| 31 | unsigned int ie; /* 0x10 - Interrupt Enable reg */ |
| 32 | unsigned int ist; /* 0x14 - Interrupt Status reg */ |
| 33 | unsigned int dcr; /* 0x18 - data control reg */ |
| 34 | unsigned int data; /* 0x1c - data register */ |
| 35 | unsigned int ahb; /* 0x20 - AHB SPI interface setting */ |
| 36 | unsigned int ver; /* 0x3c - SPI version reg */ |
| 37 | }; |
| 38 | |
| 39 | #define BIT(x) (1 << (x)) |
| 40 | |
| 41 | /* 0x00 - APB SPI interface setting register */ |
| 42 | #define ANDES_SPI_APB_BAUD(x) (((x) & 0xff) < 0) |
| 43 | #define ANDES_SPI_APB_CSHT(x) (((x) & 0xf) < 16) |
| 44 | #define ANDES_SPI_APB_SPNTS BIT(20) /* 0: normal, 1: delay */ |
| 45 | #define ANDES_SPI_APB_CPHA BIT(24) /* 0: Sampling at odd edges */ |
| 46 | #define ANDES_SPI_APB_CPOL BIT(25) /* 0: SCK low, 1: SCK high */ |
| 47 | #define ANDES_SPI_APB_MSSL BIT(26) /* 0: SPI Master, 1: slave */ |
| 48 | |
| 49 | /* 0x04 - PIO register */ |
| 50 | #define ANDES_SPI_PIO_MISO BIT(0) /* input value of pin MISO */ |
| 51 | #define ANDES_SPI_PIO_MOSI BIT(1) /* I/O value of pin MOSI */ |
| 52 | #define ANDES_SPI_PIO_SCK BIT(2) /* I/O value of pin SCK */ |
| 53 | #define ANDES_SPI_PIO_CS BIT(3) /* I/O value of pin CS */ |
| 54 | #define ANDES_SPI_PIO_PIOE BIT(4) /* Programming IO Enable */ |
| 55 | |
| 56 | /* 0x08 - SPI Control register */ |
| 57 | #define ANDES_SPI_CR_SPIRST BIT(0) /* SPI mode reset */ |
| 58 | #define ANDES_SPI_CR_RXFRST BIT(1) /* RxFIFO reset */ |
| 59 | #define ANDES_SPI_CR_TXFRST BIT(2) /* TxFIFO reset */ |
| 60 | #define ANDES_SPI_CR_RXFTH(x) (((x) & 0x1f) << 10) /* RxFIFO Threshold */ |
| 61 | #define ANDES_SPI_CR_TXFTH(x) (((x) & 0x1f) << 18) /* TxFIFO Threshold */ |
| 62 | |
| 63 | /* 0x0c - SPI Status register */ |
| 64 | #define ANDES_SPI_ST_SPIBSY BIT(0) /* SPI Transfer is active */ |
| 65 | #define ANDES_SPI_ST_RXFEM BIT(8) /* RxFIFO Empty Flag */ |
| 66 | #define ANDES_SPI_ST_RXFEL BIT(9) /* RxFIFO Full Flag */ |
| 67 | #define ANDES_SPI_ST_RXFVE(x) (((x) >> 10) & 0x1f) |
| 68 | #define ANDES_SPI_ST_TXFEM BIT(16) /* TxFIFO Empty Flag */ |
| 69 | #define ANDES_SPI_ST_TXFEL BIT(7) /* TxFIFO Full Flag */ |
| 70 | #define ANDES_SPI_ST_TXFVE(x) (((x) >> 18) & 0x1f) |
| 71 | |
| 72 | /* 0x10 - Interrupt Enable register */ |
| 73 | #define ANDES_SPI_IE_RXFORIE BIT(0) /* RxFIFO overrun intr */ |
| 74 | #define ANDES_SPI_IE_TXFURIE BIT(1) /* TxFOFO underrun intr */ |
| 75 | #define ANDES_SPI_IE_RXFTHIE BIT(2) /* RxFIFO threshold intr */ |
| 76 | #define ANDES_SPI_IE_TXFTHIE BIT(3) /* TxFIFO threshold intr */ |
| 77 | #define ANDES_SPI_IE_SPIEIE BIT(4) /* SPI transmit END intr */ |
| 78 | #define ANDES_SPI_IE_SPCFIE BIT(5) /* AHB/APB TxReq conflict */ |
| 79 | |
| 80 | /* 0x14 - Interrupt Status Register */ |
| 81 | #define ANDES_SPI_IST_RXFORI BIT(0) /* has RxFIFO overrun */ |
| 82 | #define ANDES_SPI_IST_TXFURI BIT(1) /* has TxFOFO underrun */ |
| 83 | #define ANDES_SPI_IST_RXFTHI BIT(2) /* has RxFIFO threshold */ |
| 84 | #define ANDES_SPI_IST_TXFTHI BIT(3) /* has TxFIFO threshold */ |
| 85 | #define ANDES_SPI_IST_SPIEI BIT(4) /* has SPI transmit END */ |
| 86 | #define ANDES_SPI_IST_SPCFI BIT(5) /* has AHB/APB TxReq conflict */ |
| 87 | |
| 88 | /* 0x18 - Data Control Register */ |
| 89 | #define ANDES_SPI_DCR_RCNT(x) (((x) & 0x3ff) << 0) |
| 90 | #define ANDES_SPI_DCR_DYCNT(x) (((x) & 0x7) << 12) |
| 91 | #define ANDES_SPI_DCR_WCNT(x) (((x) & 0x3ff) << 16) |
| 92 | #define ANDES_SPI_DCR_TRAMODE(x) (((x) & 0x7) << 28) |
| 93 | #define ANDES_SPI_DCR_SPIT BIT(31) /* SPI bus trigger */ |
| 94 | |
| 95 | #define ANDES_SPI_DCR_MODE_WRCON ANDES_SPI_DCR_TRAMODE(0) /* w/r at the same time */ |
| 96 | #define ANDES_SPI_DCR_MODE_WO ANDES_SPI_DCR_TRAMODE(1) /* write only */ |
| 97 | #define ANDES_SPI_DCR_MODE_RO ANDES_SPI_DCR_TRAMODE(2) /* read only */ |
| 98 | #define ANDES_SPI_DCR_MODE_WR ANDES_SPI_DCR_TRAMODE(3) /* write, read */ |
| 99 | #define ANDES_SPI_DCR_MODE_RW ANDES_SPI_DCR_TRAMODE(4) /* read, write */ |
| 100 | #define ANDES_SPI_DCR_MODE_WDR ANDES_SPI_DCR_TRAMODE(5) /* write, dummy, read */ |
| 101 | #define ANDES_SPI_DCR_MODE_RDW ANDES_SPI_DCR_TRAMODE(6) /* read, dummy, write */ |
| 102 | #define ANDES_SPI_DCR_MODE_RECEIVE ANDES_SPI_DCR_TRAMODE(7) /* receive */ |
| 103 | |
| 104 | /* 0x20 - AHB SPI interface setting register */ |
| 105 | #define ANDES_SPI_AHB_BAUD(x) (((x) & 0xff) < 0) |
| 106 | #define ANDES_SPI_AHB_CSHT(x) (((x) & 0xf) < 16) |
| 107 | #define ANDES_SPI_AHB_SPNTS BIT(20) /* 0: normal, 1: delay */ |
| 108 | #define ANDES_SPI_AHB_CPHA BIT(24) /* 0: Sampling at odd edges */ |
| 109 | #define ANDES_SPI_AHB_CPOL BIT(25) /* 0: SCK low, 1: SCK high */ |
| 110 | #define ANDES_SPI_AHB_MSSL BIT(26) /* only Master mode */ |
| 111 | |
| 112 | /* 0x3c - Version Register - (Year V.MAJOR.MINOR) */ |
| 113 | #define ANDES_SPI_VER_MINOR(x) (((x) >> 0) & 0xf) |
| 114 | #define ANDES_SPI_VER_MAJOR(x) (((x) >> 8) & 0xf) |
| 115 | #define ANDES_SPI_VER_YEAR(x) (((x) >> 16) & 0xf) |
| 116 | |
| 117 | struct andes_spi_slave { |
| 118 | struct spi_slave slave; |
| 119 | struct andes_spi_regs *regs; |
| 120 | unsigned int freq; |
| 121 | }; |
| 122 | |
| 123 | static inline struct andes_spi_slave *to_andes_spi(struct spi_slave *slave) |
| 124 | { |
| 125 | return container_of(slave, struct andes_spi_slave, slave); |
| 126 | } |
| 127 | |
| 128 | #endif /* __ANDES_SPI_H */ |