omap3530/omap3530_drivers/spi/omap3530_spi.h
branchBeagle_BSP_dev
changeset 77 e5fd00cbb70a
child 82 65b40f262685
equal deleted inserted replaced
76:29b14275133a 77:e5fd00cbb70a
       
     1 // This component and the accompanying materials are made available
       
     2 // under the terms of the License "Eclipse Public License v1.0"
       
     3 // which accompanies this distribution, and is available
       
     4 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     5 //
       
     6 // Initial Contributors:
       
     7 // lukasz.forynski@gmail.com
       
     8 //
       
     9 // Contributors:
       
    10 //
       
    11 //
       
    12 // Description:
       
    13 // omap3530/omap3530_drivers/spi/omap3530_spi.h
       
    14 //
       
    15 // This file contains definitions to internal SPI implementation and register definitions
       
    16 // It is not intended to be exported - SPI registers must not be modified from outside of
       
    17 // the driver!
       
    18 //
       
    19 
       
    20 #ifndef __OMAP3530_SPI_H__
       
    21 #define __OMAP3530_SPI_H__
       
    22 
       
    23 #include <assp/omap3530_assp/omap3530_scm.h>
       
    24 
       
    25 
       
    26 #define BIT_MASK(shift,len)       (((1u << (len)) - 1) << (shift))
       
    27 #define GET_BITS(w,shift,len)     (((w) >> (shift)) & ((1 << (len)) - 1))
       
    28 #define SET_BITS(w,set,shift,len) ((w) &= ~BIT_MASK(shift, len), (w) |= ((set) << (shift)))
       
    29 
       
    30 
       
    31 // Device Instance Summary
       
    32 const TUint MCSPI1_phys = 0x48098000; // 4Kbytes
       
    33 const TUint MCSPI2_phys = 0x4809A000; // 4Kbytes
       
    34 const TUint MCSPI3_phys = 0x480B8000; // 4Kbytes
       
    35 const TUint MCSPI4_phys = 0x480BA000; // 4Kbytes
       
    36 
       
    37 const TUint MCSPI1 = Omap3530HwBase::TVirtual<MCSPI1_phys>::Value;
       
    38 const TUint MCSPI2 = Omap3530HwBase::TVirtual<MCSPI2_phys>::Value;
       
    39 const TUint MCSPI3 = Omap3530HwBase::TVirtual<MCSPI3_phys>::Value;
       
    40 const TUint MCSPI4 = Omap3530HwBase::TVirtual<MCSPI4_phys>::Value;
       
    41 
       
    42 // map of SPI base addresses..
       
    43 const TUint KMcSpiRegBase[] =
       
    44 	{
       
    45 	Omap3530HwBase::TVirtual<MCSPI1_phys>::Value, //McSPI module 1
       
    46 	Omap3530HwBase::TVirtual<MCSPI2_phys>::Value, //McSPI module 2
       
    47 	Omap3530HwBase::TVirtual<MCSPI3_phys>::Value, //McSPI module 3
       
    48 	Omap3530HwBase::TVirtual<MCSPI4_phys>::Value  //McSPI module 4
       
    49 	};
       
    50 
       
    51 
       
    52 //.. and IRQ lines for SPI channels
       
    53 const TUint KMcSpiIrqId[] =
       
    54 	{
       
    55 	EOmap3530_IRQ65_SPI1_IRQ, //McSPI module 1
       
    56 	EOmap3530_IRQ66_SPI2_IRQ, //McSPI module 2
       
    57 	EOmap3530_IRQ91_SPI3_IRQ, //McSPI module 3
       
    58 	EOmap3530_IRQ48_SPI4_IRQ  //McSPI module 4
       
    59 	};
       
    60 
       
    61 // available channels per module (i.e. number of 'slave select'  inputs/outpus per module)
       
    62 const TUint KMcSpiNumChannels[] =
       
    63 	{
       
    64 	4, // channels 0 - 3
       
    65 	2, // channels 0 - 1
       
    66 	2, // channels 0 - 1
       
    67 	1  // channel 0  only
       
    68 	};
       
    69 
       
    70 //---------------------------------------------------------------
       
    71 // MCSPI Registers offsets and bits definitions
       
    72 //----------------------------------
       
    73 // MCSPI_REVISION
       
    74 //----------------------------------
       
    75 const TUint MCSPI_REVISION = 0x00;
       
    76 
       
    77 
       
    78 //----------------------------------
       
    79 // MCSPI_SYSCONFIG
       
    80 //----------------------------------
       
    81 const TUint MCSPI_SYSCONFIG = 0x10;
       
    82 
       
    83 // 9:8 CLOCKACTIVITY Clocks activity during wake up mode period
       
    84 //0x0: Interface and Functional clocks may be switched off.
       
    85 //0x1: Interface clock is maintained. Functional clock may be switched off.
       
    86 //0x2: Functional clock is maintained. Interface clock may be switched off.
       
    87 //0x3: Interface and Functional clocks are maintained.
       
    88 const TUint MCSPI_SYSCONFIG_CLOCKACTIVITY_ALL_OFF        = 0 << 8;
       
    89 const TUint MCSPI_SYSCONFIG_CLOCKACTIVITY_INT_ON_FUN_OFF = 1 << 8;
       
    90 const TUint MCSPI_SYSCONFIG_CLOCKACTIVITY_INT_OFF_FUN_ON = 2 << 8;
       
    91 const TUint MCSPI_SYSCONFIG_CLOCKACTIVITY_ALL_ON         = 3 << 8;
       
    92 
       
    93 // 4:3 SIDLEMODE Power management
       
    94 const TUint MCSPI_SYSCONFIG_SIDLEMODE_ALWAYS = 0 << 3;
       
    95 const TUint MCSPI_SYSCONFIG_SIDLEMODE_IGNORE = 1 << 3;
       
    96 const TUint MCSPI_SYSCONFIG_SIDLEMODE_COND   = 2 << 3;
       
    97 const TUint MCSPI_SYSCONFIG_ENAWAKEUP = 1 << 2; // 0x1: Wake-up capability enabled
       
    98 const TUint MCSPI_SYSCONFIG_SOFTRESET = 1 << 1; // Software reset. Read always returns 0.
       
    99 const TUint MCSPI_SYSCONFIG_AUTOIDLE  = 1 << 0; // Internal interface Clock gating strategy
       
   100 
       
   101 
       
   102 //----------------------------------
       
   103 // MCSPI_SYSSTATUS
       
   104 //----------------------------------
       
   105 const TUint MCSPI_SYSSTATUS = 0x14;
       
   106 const TUint MCSPI_SYSSTATUS_RESETDONE = 1 << 0;
       
   107 
       
   108 
       
   109 //----------------------------------
       
   110 // MCSPI_IRQSTATUS
       
   111 //----------------------------------
       
   112 const TUint MCSPI_IRQSTATUS = 0x18; // for each bit- write 0x1: reset status, Read 0x1: Event is pending.
       
   113 const TUint MCSPI_IRQSTATUS_EOW           = 1 << 17; // End of word count event when a channel is enabled using
       
   114 const TUint MCSPI_IRQSTATUS_WKS           = 1 << 16; // Wake-up event in slave mode when an active control signal is detected
       
   115 const TUint MCSPI_IRQSTATUS_RX3_FULL      = 1 << 14; // MCSPI_RX3 register is full (only when channel 3 is enabled)
       
   116 const TUint MCSPI_IRQSTATUS_TX3_UDERFLOW  = 1 << 13; // MCSPI_TX3 register underflow (only when channel 3 is enabled)(1)
       
   117 const TUint MCSPI_IRQSTATUS_TX3_EMPTY     = 1 << 12; // MCSPI_TX3 register is empty (only when channel 3 is enabled)(2)
       
   118 const TUint MCSPI_IRQSTATUS_RX2_FULL      = 1 << 10; // MCSPI_RX2 register full (only when channel 2 is enabled)
       
   119 const TUint MCSPI_IRQSTATUS_TX2_UNDERFLOW = 1 <<  9; // MCSPI_TX2 register underflow (only when channel 2 is enabled)(1)
       
   120 const TUint MCSPI_IRQSTATUS_TX2_EMPTY     = 1 <<  8; // MCSPI_TX2 register empty (only when channel 2 is enabled)(2)
       
   121 const TUint MCSPI_IRQSTATUS_RX1_FULL      = 1 <<  6; // MCSPI_RX1 register full (only when channel 1 is enabled)
       
   122 const TUint MCSPI_IRQSTATUS_TX1_UNDERFLOW = 1 <<  5; // MCSPI_TX1 register underflow (only when channel 1 is enabled)(1)
       
   123 const TUint MCSPI_IRQSTATUS_TX1_EMPTY     = 1 <<  4; // MCSPI_TX1 register empty (only when channel 1 is enabled)(3)
       
   124 const TUint MCSPI_IRQSTATUS_RX0_OVERFLOW  = 1 <<  3; // MCSPI_RX0 register overflow (only in slave mode)
       
   125 const TUint MCSPI_IRQSTATUS_RX0_FULL      = 1 <<  2; // MCSPI_RX0 register full (only when channel 0 is enabled)
       
   126 const TUint MCSPI_IRQSTATUS_TX0_UNDERFLOW = 1 <<  1; // MCSPI_TX0 register underflow (only when channel 0 is
       
   127 const TUint MCSPI_IRQSTATUS_TX0_EMPTY     = 1 <<  0; // MCSPI_TX0 register empty (only when channel 0 is enabled)(3)
       
   128 
       
   129 //----------------------------------
       
   130 // MCSPI_IRQENABLE
       
   131 //----------------------------------
       
   132 //0x0: Interrupt disabled
       
   133 //0x1: Interrupt enabled
       
   134 const TUint MCSPI_IRQENABLE = 0x1C;
       
   135 const TUint MCSPI_IRQENABLE_EOWKE         = 1 << 17; // End of Word count Interrupt Enable.
       
   136 const TUint MCSPI_IRQENABLE_WKE           = 1 << 16; // Wake-up event interrupt enable in slave mode when an
       
   137 const TUint MCSPI_IRQENABLE_RX3_FULL      = 1 << 14; // MCSPI_RX3 register full interrupt enable (channel 3)
       
   138 const TUint MCSPI_IRQENABLE_TX3_UNDERFLOW = 1 << 13; // MCSPI_TX3 register underflow interrupt enable (channel 3)
       
   139 const TUint MCSPI_IRQENABLE_TX3_EMPTY     = 1 << 12; // MCSPI_TX3 register empty interrupt enable (channel 3)
       
   140 const TUint MCSPI_IRQENABLE_RX2_FULL      = 1 << 10; // MCSPI_RX2 register full interrupt enable (channel 2)
       
   141 const TUint MCSPI_IRQENABLE_TX2_UNDERFLOW = 1 << 9;  // MCSPI_TX2 register underflow interrupt enable (channel 2)
       
   142 const TUint MCSPI_IRQENABLE_TX2_EMPTY     = 1 << 8;  // MCSPI_TX2 register empty interrupt enable (channel 2)
       
   143 const TUint MCSPI_IRQENABLE_RX1_FULL      = 1 << 6;  // MCSPI_RX1 register full interrupt enable (channel 1)
       
   144 const TUint MCSPI_IRQENABLE_TX1_UNDERFLOW = 1 << 5;  // MCSPI_TX1 register underflow interrupt enable (channel 1)
       
   145 const TUint MCSPI_IRQENABLE_TX1_EMPTY     = 1 << 4;  // MCSPI_TX1 register empty interrupt enable (channel 1)
       
   146 const TUint MCSPI_IRQENABLE_RX0_OVERFLOW  = 1 << 3;  // MCSPI_RX0 register overflow interrupt enable (channel 0) (only Slave)
       
   147 const TUint MCSPI_IRQENABLE_RX0_FULL      = 1 << 2;  // MCSPI_RX0 register full interrupt enable (channel 0)
       
   148 const TUint MCSPI_IRQENABLE_TX0_UNDERFLOW = 1 << 1;  // MCSPI_TX0 register underflow interrupt enable (channel 0)
       
   149 const TUint MCSPI_IRQENABLE_TX0_EMPTY     = 1 << 0;  // MCSPI_TX0 register empty interrupt enable (channel 0)
       
   150 
       
   151 // macros to get these flags depending on the channel number..and ommited ENABLE
       
   152 // - as they are the same for MCSPI_IRQSTATUS register
       
   153 #define MCSPI_IRQ_RX_OVERFLOW         MCSPI_IRQENABLE_RX0_OVERFLOW  // Channel 0 only / slave mode only
       
   154 #define MCSPI_IRQ_RX_FULL(chan)      (MCSPI_IRQENABLE_RX0_FULL      << ((chan)*4))
       
   155 #define MCSPI_IRQ_TX_UNDERFLOW(chan) (MCSPI_IRQENABLE_TX0_UNDERFLOW << ((chan)*4))
       
   156 #define MCSPI_IRQ_TX_EMPTY(chan)     (MCSPI_IRQENABLE_TX0_EMPTY     << ((chan)*4))
       
   157 
       
   158 
       
   159 //----------------------------------
       
   160 // MCSPI_WAKEUPENABL
       
   161 //----------------------------------
       
   162 const TUint MCSPI_WAKEUPENABL = 0x20;
       
   163 const TUint MCSPI_WAKEUPENABL_WKEN = 1 << 0; //0x1: The event is allowed to wake-up the system
       
   164 
       
   165 
       
   166 //----------------------------------
       
   167 // MCSPI_SYST
       
   168 //----------------------------------
       
   169 const TUint MCSPI_SYST = 0x24;
       
   170 const TUint MCSPI_SYST_SSB        = 1 << 11; // Set status bit: 0x1: Force to 1 all status bits of MCSPI_ IRQSTATUS
       
   171 const TUint MCSPI_SYST_SPIENDIR   = 1 << 10; // spim_cs and spim_clk direction: 0x0: Output (as in master mode), 0x1: Input (as in slave mode)
       
   172 const TUint MCSPI_SYST_SPIDATDIR1 = 1 << 9;  // SPIDAT[1] (spim_simo) direction- 0x0: Output, 0x1: Input
       
   173 const TUint MCSPI_SYST_SPIDATDIR0 = 1 << 8;  // Set the direction of the SPIDAT[0] (spim_somi) RW 0
       
   174 const TUint MCSPI_SYST_WAKD       = 1 << 7;  // SWAKEUP output 0x0: The pin is driven low, 0x1: The pin is driven high.
       
   175 const TUint MCSPI_SYST_SPICLK     = 1 << 6;  // spim_clk line (signal data value) RW 0
       
   176 const TUint MCSPI_SYST_SPIDAT_1   = 1 << 5;  // spim_somi line (signal data value) RW 0
       
   177 const TUint MCSPI_SYST_SPIDAT_0   = 1 << 4;  // spim_simo line (signal data value)
       
   178 const TUint MCSPI_SYST_SPIEN_3    = 1 << 3;  // spim_cs3 line (signal data value) RW 0
       
   179 const TUint MCSPI_SYST_SPIEN_2    = 1 << 2;  // spim_cs2 line (signal data value) RW 0
       
   180 const TUint MCSPI_SYST_SPIEN_1    = 1 << 1;  // spim_cs1 line (signal data value) RW 0
       
   181 const TUint MCSPI_SYST_SPIEN_0    = 1 << 0;  // spim_cs0 line (signal data value) RW 0
       
   182 
       
   183 
       
   184 //----------------------------------
       
   185 // MCSPI_MODULCTRL
       
   186 //----------------------------------
       
   187 const TUint MCSPI_MODULCTRL = 0x28;
       
   188 const TUint MCSPI_MODULCTRL_SYSTEM_TEST = 1 << 3; // 0x0: Functional mode, 0x1: System test mode (SYSTEST)
       
   189 const TUint MCSPI_MODULCTRL_MS_SLAVE    = 1 << 2; // Master / Slave mode 0x0: Master, 0x1: Slave
       
   190 const TUint MCSPI_MODULCTRL_MS_MASTER   = 0;      // this is spurious definition -> not to write '0' magic number -defined this..
       
   191 const TUint MCSPI_MODULCTRL_SINGLE      = 1 << 0; // Single forced channel/multichannel (master mode only)
       
   192                                                   // MCSPI_CHxCONF_FORCE bit has to be set in this mode, TURBO cleared (recomended)
       
   193 
       
   194 
       
   195 //----------------------------------
       
   196 // MCSPI_CHxCONF - channel config
       
   197 //----------------------------------
       
   198 // x = 0 to 3 for MCSPI1.
       
   199 // x = 0 to 1 for MCSPI2 and MCSPI3.
       
   200 // x = 0 for MCSPI4.
       
   201 #define MCSPI_CHxCONF(x) (0x2C + 0x14 * (x))
       
   202 const TUint MCSPI_CHxCONF_CLKG = 1 << 29; //  Clock divider granularity.
       
   203 const TUint MCSPI_CHxCONF_FFER = 1 << 28; // FIFO enabled for Receive.
       
   204 const TUint MCSPI_CHxCONF_FFEW = 1 << 27; // FIFO enabled for Transmit. Only one channel can have this bit field set.
       
   205 
       
   206 // [26:25] TCS Chip select time control
       
   207 // Defines the number of interface clock cycles between CS toggling and first (or last) edge of SPI clock.
       
   208 const TUint MCSPI_CHxCONF_TCS_0_5 = 0 << 25; // 0x0: 0.5 clock cycle
       
   209 const TUint MCSPI_CHxCONF_TCS_1_5 = 1 << 25; // 0x1: 1.5 clock cycles
       
   210 const TUint MCSPI_CHxCONF_TCS_2_5 = 2 << 25; // 0x2: 2.5 clock cycles
       
   211 const TUint MCSPI_CHxCONF_TCS_3_5 = 3 << 25; // 0x3: 3.5 clock cycles
       
   212 
       
   213 const TUint MCSPI_CHxCONF_SBPOL = 1 << 24; // Start bit polarity (0: spi word is command, 1: spi word is data)
       
   214 const TUint MCSPI_CHxCONF_SBE   = 1 << 23; // Start bit enable - 0x1: Start bit D/CX added before transfer.
       
   215 const TUint MCSPI_CHxCONF_FORCE = 1 << 20; // Manual spim_csx assertion to keep spim_csx active between SPI words.
       
   216                                            // (single channel master mode only)- MCSPI_MODULCTRL_SINGLE has to be set
       
   217 const TUint MCSPI_CHxCONF_TURBO = 1 << 19; // Turbo mode
       
   218 const TUint MCSPI_CHxCONF_IS    = 1 << 18; // Input select- 0x0: (spim_somi), 0x1: (spim_simo) selected for reception
       
   219 const TUint MCSPI_CHxCONF_DPE1  = 1 << 17; // Transmission enable for data line 1 (spim_simo) RW 0x1
       
   220 const TUint MCSPI_CHxCONF_DPE0  = 1 << 16; // Transmission enable for data line 0 (spim_somi)
       
   221 const TUint MCSPI_CHxCONF_DMAR  = 1 << 15; // DMA Read request
       
   222 const TUint MCSPI_CHxCONF_DMAW  = 1 << 14; // DMA Write request.
       
   223 
       
   224 // 13:12 TRM Transmit/receive modes
       
   225 const TUint MCSPI_CHxCONF_TRM_TRANSMIT_RECEIVE = 0 << 12;
       
   226 const TUint MCSPI_CHxCONF_TRM_RECEIVE_ONLY     = 1 << 12;
       
   227 const TUint MCSPI_CHxCONF_TRM_TRANSMIT_ONLY    = 2 << 12;
       
   228 // these are to be cleared in the register
       
   229 const TUint MCSPI_CHxCONF_TRM_NO_TRANSMIT      = 1 << 12;
       
   230 const TUint MCSPI_CHxCONF_TRM_NO_RECEIVE       = 2 << 12;
       
   231 
       
   232 
       
   233 // 11:7 WL SPI word length0
       
   234 // values:<0-3> reserved, allowed:<4-31> => word_size = value + 1 (i.e. for 4: word size = 5)
       
   235 const TInt KMinSpiWordWidth = 5;
       
   236 const TUint MCSPI_CHxCONF_WL_OFFSET = 7;
       
   237 #define MCSPI_CHxCONF_WL(x) ( (((x) - 1) & BIT_MASK(0, 5)) << MCSPI_CHxCONF_WL_OFFSET )
       
   238 
       
   239 const TUint MCSPI_CHxCONF_EPOL_LOW = 1 << 6; // spim_csx polarity 0x0: active high, 0x1: active low
       
   240 
       
   241 // A programmable clock divider divides the SPI reference clock
       
   242 //5:2 CLKD Frequency divider for spim_clk (for master device only)
       
   243 const TUint MCSPI_CHxCONF_CLKD_48M   = 0x0 << 2; //0x0: 1    = 48 MHz
       
   244 const TUint MCSPI_CHxCONF_CLKD_24M   = 0x1 << 2; //0x1: 2    = 24 MHz
       
   245 const TUint MCSPI_CHxCONF_CLKD_12M   = 0x2 << 2; //0x2: 4    = 12 MHz
       
   246 const TUint MCSPI_CHxCONF_CLKD_6M    = 0x3 << 2; //0x3: 8    = 6 MHz
       
   247 const TUint MCSPI_CHxCONF_CLKD_3M    = 0x4 << 2; //0x4: 16   = 3 MHz
       
   248 const TUint MCSPI_CHxCONF_CLKD_1500k = 0x5 << 2; //0x5: 32   = 1.5 MHz
       
   249 const TUint MCSPI_CHxCONF_CLKD_750k  = 0x6 << 2; //0x6: 64   = 750 kHz
       
   250 const TUint MCSPI_CHxCONF_CLKD_375k  = 0x7 << 2; //0x7: 128  = 375 kHz
       
   251 const TUint MCSPI_CHxCONF_CLKD_187k  = 0x8 << 2; //0x8: 256  = 187.5 kHz
       
   252 const TUint MCSPI_CHxCONF_CLKD_93k   = 0x9 << 2; //0x9: 512  = 93.75 kHz
       
   253 const TUint MCSPI_CHxCONF_CLKD_46k   = 0xA << 2; //0xA: 1024 = 46.875 kHz
       
   254 const TUint MCSPI_CHxCONF_CLKD_23k   = 0xB << 2; //0xB: 2048 = 23.437,5 kHz
       
   255 const TUint MCSPI_CHxCONF_CLKD_11k   = 0xC << 2; //0xC: 4096 = 11.718,75 kHz
       
   256 const TUint MCSPI_K48MHz = 48000000;
       
   257 
       
   258 const TUint MCSPI_CHxCONF_POL = 1 << 1; // spim_clk polarity 0x0: active high, 0x1: active low
       
   259 const TUint MCSPI_CHxCONF_PHA = 1 << 0; // spim_clk phase
       
   260 // 0x0: Data are latched on odd-numbered edges of spim_clk.
       
   261 // 0x1: Data are latched on even-numbered edges of spim_clk.
       
   262 
       
   263 
       
   264 //----------------------------------
       
   265 // MCSPI_CHxSTAT
       
   266 //----------------------------------
       
   267 // x = 0 to 3 for MCSPI1.
       
   268 // x = 0 to 1 for MCSPI2 and MCSPI3.
       
   269 // x = 0 for MCSPI4.
       
   270 #define MCSPI_CHxSTAT(x) (0x30 + 0x14 * (x))
       
   271 const TUint MCSPI_CHxSTAT_RXFFF = 1 << 6; // Channel x FIFO Receive Buffer Full
       
   272 const TUint MCSPI_CHxSTAT_RXFFE = 1 << 5; // Channel x FIFO Receive Buffer Empty
       
   273 const TUint MCSPI_CHxSTAT_TXFFF = 1 << 4; // Channel x FIFO Transmit Buffer Full
       
   274 const TUint MCSPI_CHxSTAT_TXFFE = 1 << 3; // Channel x FIFO Transmit Buffer Empty
       
   275 const TUint MCSPI_CHxSTAT_EOT   = 1 << 2; // Channel x end-of-transfer status.
       
   276 const TUint MCSPI_CHxSTAT_TXS   = 1 << 1; // Channel x MCSPI_TXx register status R 0x0
       
   277 const TUint MCSPI_CHxSTAT_RXS   = 1 << 0; // Channel x MCSPI_RXx register status R 0x0
       
   278 
       
   279 
       
   280 //----------------------------------
       
   281 // MCSPI_CHxCTRL
       
   282 //----------------------------------
       
   283 // x = 0 to 3 for MCSPI1.
       
   284 // x = 0 to 1 for MCSPI2 and MCSPI3.
       
   285 // x = 0 for MCSPI4.
       
   286 #define MCSPI_CHxCTRL(x) (0x34 + 0x14 * (x))
       
   287 //15:8 EXTCLK Clock ratio extension: This register is used to concatenate with RW 0x00
       
   288 const TUint MCSPI_CHxCTRL_EXTCLK_1      = 0x00 << 8; //0x0: Clock ratio is CLKD + 1
       
   289 const TUint MCSPI_CHxCTRL_EXTCLK_1_16   = 0x01 << 8; //0x1: Clock ratio is CLKD + 1 + 16
       
   290 const TUint MCSPI_CHxCTRL_EXTCLK_1_4080 = 0xff << 8; //0xFF: Clock ratio is CLKD + 1 + 4080
       
   291 const TUint MCSPI_CHxCTRL_EN            = 0x01 << 0; // Channel enable
       
   292 
       
   293 
       
   294 //----------------------------------
       
   295 // MCSPI_TXx - Channel x Data to transmit
       
   296 //----------------------------------
       
   297 // x = 0 to 3 for MCSPI1.
       
   298 // x = 0 to 1 for MCSPI2 and MCSPI3.
       
   299 // x = 0 for MCSPI4.
       
   300 #define MCSPI_TXx(x)     (0x38 + 0x14 * (x)) // Channel x Data to transmit
       
   301 
       
   302 
       
   303 //----------------------------------
       
   304 // MCSPI_RXx - Channel x Received Data
       
   305 //----------------------------------
       
   306 // x = 0 to 3 for MCSPI1.
       
   307 // x = 0 to 1 for MCSPI2 and MCSPI3.
       
   308 // x = 0 for MCSPI4.
       
   309 #define MCSPI_RXx(x)     (0x3C + 0x14 * (x)) // Channel x Received Data
       
   310 
       
   311 
       
   312 //----------------------------------
       
   313 // MCSPI_XFERLEVEL
       
   314 //----------------------------------
       
   315 const TUint MCSPI_XFERLEVEL = 0x7C;
       
   316 const TUint MCSPI_XFERLEVEL_WCNT_OFFSET = 16; // [31:16] WCNT Spi word counter -> how many bytes are transfered to FIFO before tx is enabled
       
   317 const TUint MCSPI_XFERLEVEL_AFL_OFFSET  = 8;  // 13:8 AFL Buffer Almost Full. 0x0: One byte , 0x1: 2 bytes, x3E: 63 bytes.. etc
       
   318 const TUint MCSPI_XFERLEVEL_AEL_OFFSET  = 0;  // 5:0 AEL Buffer Almost Empty (threshold?) 0x0: One byte. 0x1: 2 bytes..
       
   319 
       
   320 #define MCSPI_XFERLEVEL_WCNT(x) ((x)  << MCSPI_XFERLEVEL_WCNT_OFFSET)
       
   321 #define MCSPI_XFERLEVEL_AFL(x)  (((x) << MCSPI_XFERLEVEL_AFL_OFFSET))
       
   322 #define MCSPI_XFERLEVEL_AEL(x)  (((x) << MCSPI_XFERLEVEL_AEL_OFFSET))
       
   323 
       
   324 
       
   325 //----------------------------------
       
   326 // PAD (PIN) configuration for SPI
       
   327 //----------------------------------
       
   328 
       
   329 //#define SPI_CHANNEL_3_PIN_OPTION_2 // TODO - move this to mmp file!
       
   330 //#define SPI_CHANNEL_3_PIN_OPTION_3
       
   331 
       
   332 // flags for CS signal pins - in order to keep them in certain state when SPI is inactive..
       
   333 const TUint KCsPinUp = SCM::EPullUdEnable | SCM::EPullTypeSelect; //
       
   334 const TUint KCsPinDown = SCM::EPullUdEnable; //
       
   335 
       
   336 const TUint KCsPinOffHi =  SCM::EOffOutEnable | SCM::EOffOutValue; //
       
   337 const TUint KCsPinOffLow = SCM::EOffOutEnable; //
       
   338 
       
   339 const TUint KCsPinModeUp   = /*KCsPinUp   |*//* KCsPinOffHi |*/ SCM::EInputEnable;
       
   340 const TUint KCsPinModeDown = KCsPinDown | KCsPinOffLow;
       
   341 
       
   342 const TUint KMaxSpiChannelsPerModule = 4; // there are max 4 channels (McSPI 1)
       
   343 
       
   344 struct TPinConfig
       
   345 	{
       
   346 	TLinAddr              iAddress;
       
   347 	SCM::TLowerHigherWord iMswLsw;
       
   348 	TUint16               iFlags;
       
   349 	};
       
   350 
       
   351 struct TSpiPinConfig
       
   352 	{
       
   353 	TPinConfig iClk;
       
   354 	TPinConfig iSimo;
       
   355 	TPinConfig iSomi;
       
   356 	TPinConfig iCs[KMaxSpiChannelsPerModule];
       
   357 	};
       
   358 
       
   359 const TSpiPinConfig TSpiPinConfigMcSpi1 =
       
   360 	{
       
   361 	{CONTROL_PADCONF_MCSPI1_CLK,  SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi1_clk
       
   362 	{CONTROL_PADCONF_MCSPI1_CLK,  SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi1_simo
       
   363 	{CONTROL_PADCONF_MCSPI1_SOMI, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi1_somi
       
   364 		{
       
   365 		{CONTROL_PADCONF_MCSPI1_SOMI, SCM::EMsw, SCM::EMode1}, // mcspi1_cs0
       
   366 		{CONTROL_PADCONF_MCSPI1_CS1,  SCM::ELsw, SCM::EMode1}, // mcspi1_cs1
       
   367 		{CONTROL_PADCONF_MCSPI1_CS1,  SCM::EMsw, SCM::EMode1}, // mcspi1_cs2
       
   368 		{CONTROL_PADCONF_MCSPI1_CS3,  SCM::ELsw, SCM::EMode1}, // mcspi1_cs3
       
   369 		}
       
   370 	};
       
   371 
       
   372 const TSpiPinConfig TSpiPinConfigMcSpi2 =
       
   373 	{
       
   374 	{CONTROL_PADCONF_MCSPI1_CS3,  SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi2_clk
       
   375 	{CONTROL_PADCONF_MCSPI2_SIMO, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi2_simo
       
   376 	{CONTROL_PADCONF_MCSPI2_SIMO, SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi2_somi
       
   377 		{
       
   378 		{CONTROL_PADCONF_MCSPI2_CS0,  SCM::ELsw, SCM::EMode1}, // mcspi2_cs0
       
   379 		{CONTROL_PADCONF_MCSPI2_CS0,  SCM::EMsw, SCM::EMode1}, // mcspi2_cs1
       
   380 		{0, SCM::ELsw, 0}, // not supported
       
   381 		{0, SCM::ELsw, 0}, // not supported
       
   382 		}
       
   383 	};
       
   384 
       
   385 
       
   386 #if defined(SPI_CHANNEL_3_PIN_OPTION_2)
       
   387 const TSpiPinConfig TSpiPinConfigMcSpi3 =
       
   388 	{
       
   389 	{CONTROL_PADCONF_DSS_DATA18, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_clk
       
   390 	{CONTROL_PADCONF_DSS_DATA18, SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_simo
       
   391 	{CONTROL_PADCONF_DSS_DATA20, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_somi
       
   392 		{
       
   393 		{CONTROL_PADCONF_DSS_DATA20, SCM::EMsw, SCM::EMode1}, // mcspi3_cs0
       
   394 		{CONTROL_PADCONF_DSS_DATA20, SCM::ELsw, SCM::EMode1}, // mcspi3_cs1
       
   395 		{0, SCM::ELsw, 0}, // not supported
       
   396 		{0, SCM::ELsw, 0}, // not supported
       
   397 		}
       
   398 	};
       
   399 #elif defined(SPI_CHANNEL_3_PIN_OPTION_3)
       
   400 const TSpiPinConfig TSpiPinConfigMcSpi3 =
       
   401 	{
       
   402 	{CONTROL_PADCONF_ETK_D2, SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_clk
       
   403 	{CONTROL_PADCONF_ETK_D0, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_simo
       
   404 	{CONTROL_PADCONF_ETK_D0, SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_somi
       
   405 		{
       
   406 		{CONTROL_PADCONF_ETK_D2, SCM::ELsw, SCM::EMode1}, // mcspi3_cs0
       
   407 		{CONTROL_PADCONF_ETK_D6, SCM::EMsw, SCM::EMode1}, // mcspi3_cs1
       
   408 		{0, SCM::ELsw, 0}, // not supported
       
   409 		{0, SCM::ELsw, 0}, // not supported
       
   410 		}
       
   411 	};
       
   412 #else // default option (for beagle- these are pins on the extension header)
       
   413 const TSpiPinConfig TSpiPinConfigMcSpi3 =
       
   414 	{
       
   415 	{CONTROL_PADCONF_MMC2_CLK,  SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_clk
       
   416 	{CONTROL_PADCONF_MMC2_CLK,  SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_simo
       
   417 	{CONTROL_PADCONF_MMC2_DAT0, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi3_somi
       
   418 		{
       
   419 		{CONTROL_PADCONF_MMC2_DAT2, SCM::EMsw, SCM::EMode1}, // mcspi3_cs0
       
   420 		{CONTROL_PADCONF_MMC2_DAT2, SCM::ELsw, SCM::EMode1}, // mcspi3_cs1
       
   421 		{0, SCM::ELsw, 0}, // not supported
       
   422 		{0, SCM::ELsw, 0}, // not supported
       
   423 		}
       
   424 	};
       
   425 #endif
       
   426 
       
   427 const TSpiPinConfig TSpiPinConfigMcSpi4 =
       
   428 	{
       
   429 	{CONTROL_PADCONF_MCBSP1_CLKR, SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi4_clk
       
   430 	{CONTROL_PADCONF_MCBSP1_DX,   SCM::ELsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi4_simo
       
   431 	{CONTROL_PADCONF_MCBSP1_DX,   SCM::EMsw, SCM::EMode1 | SCM::EInputEnable}, // mcspi4_somi
       
   432 		{
       
   433 		{CONTROL_PADCONF_MCBSP_CLKS, SCM::EMsw, SCM::EMode1}, // mcspi3_cs0
       
   434 		{0, SCM::ELsw, 0}, // not supported
       
   435 		{0, SCM::ELsw, 0}, // not supported
       
   436 		{0, SCM::ELsw, 0}, // not supported
       
   437 		}
       
   438 	};
       
   439 
       
   440 const TSpiPinConfig ModulePinConfig[] =
       
   441 	{
       
   442 	TSpiPinConfigMcSpi1,
       
   443 	TSpiPinConfigMcSpi2,
       
   444 	TSpiPinConfigMcSpi3,
       
   445 	TSpiPinConfigMcSpi4
       
   446 	};
       
   447 
       
   448 #include "omap3530_spi.inl"
       
   449 
       
   450 #endif /* __OMAP3530_SPI_H__ */