xref: /linux/drivers/pcmcia/sa11xx_base.h (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
11da177e4SLinus Torvalds /*======================================================================
21da177e4SLinus Torvalds 
31da177e4SLinus Torvalds     Device driver for the PCMCIA control functionality of StrongARM
41da177e4SLinus Torvalds     SA-1100 microprocessors.
51da177e4SLinus Torvalds 
61da177e4SLinus Torvalds     The contents of this file are subject to the Mozilla Public
71da177e4SLinus Torvalds     License Version 1.1 (the "License"); you may not use this file
81da177e4SLinus Torvalds     except in compliance with the License. You may obtain a copy of
91da177e4SLinus Torvalds     the License at http://www.mozilla.org/MPL/
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds     Software distributed under the License is distributed on an "AS
121da177e4SLinus Torvalds     IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
131da177e4SLinus Torvalds     implied. See the License for the specific language governing
141da177e4SLinus Torvalds     rights and limitations under the License.
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds     The initial developer of the original code is John G. Dorsey
171da177e4SLinus Torvalds     <john+@cs.cmu.edu>.  Portions created by John G. Dorsey are
181da177e4SLinus Torvalds     Copyright (C) 1999 John G. Dorsey.  All Rights Reserved.
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds     Alternatively, the contents of this file may be used under the
211da177e4SLinus Torvalds     terms of the GNU Public License version 2 (the "GPL"), in which
221da177e4SLinus Torvalds     case the provisions of the GPL are applicable instead of the
231da177e4SLinus Torvalds     above.  If you wish to allow the use of your version of this file
241da177e4SLinus Torvalds     only under the terms of the GPL and not to allow others to use
251da177e4SLinus Torvalds     your version of this file under the MPL, indicate your decision
261da177e4SLinus Torvalds     by deleting the provisions above and replace them with the notice
271da177e4SLinus Torvalds     and other provisions required by the GPL.  If you do not delete
281da177e4SLinus Torvalds     the provisions above, a recipient may use your version of this
291da177e4SLinus Torvalds     file under either the MPL or the GPL.
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds ======================================================================*/
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #if !defined(_PCMCIA_SA1100_H)
341da177e4SLinus Torvalds # define _PCMCIA_SA1100_H
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds /* SA-1100 PCMCIA Memory and I/O timing
371da177e4SLinus Torvalds  * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
381da177e4SLinus Torvalds  * The SA-1110 Developer's Manual, section 10.2.5, says the following:
391da177e4SLinus Torvalds  *
401da177e4SLinus Torvalds  *  "To calculate the recommended BS_xx value for each address space:
411da177e4SLinus Torvalds  *   divide the command width time (the greater of twIOWR and twIORD,
421da177e4SLinus Torvalds  *   or the greater of twWE and twOE) by processor cycle time; divide
431da177e4SLinus Torvalds  *   by 2; divide again by 3 (number of BCLK's per command assertion);
441da177e4SLinus Torvalds  *   round up to the next whole number; and subtract 1."
451da177e4SLinus Torvalds  */
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds /* MECR: Expansion Memory Configuration Register
481da177e4SLinus Torvalds  * (SA-1100 Developers Manual, p.10-13; SA-1110 Developers Manual, p.10-24)
491da177e4SLinus Torvalds  *
501da177e4SLinus Torvalds  * MECR layout is:
511da177e4SLinus Torvalds  *
521da177e4SLinus Torvalds  *   FAST1 BSM1<4:0> BSA1<4:0> BSIO1<4:0> FAST0 BSM0<4:0> BSA0<4:0> BSIO0<4:0>
531da177e4SLinus Torvalds  *
541da177e4SLinus Torvalds  * (This layout is actually true only for the SA-1110; the FASTn bits are
551da177e4SLinus Torvalds  * reserved on the SA-1100.)
561da177e4SLinus Torvalds  */
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds #define MECR_SOCKET_0_SHIFT (0)
591da177e4SLinus Torvalds #define MECR_SOCKET_1_SHIFT (16)
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds #define MECR_BS_MASK        (0x1f)
621da177e4SLinus Torvalds #define MECR_FAST_MODE_MASK (0x01)
631da177e4SLinus Torvalds 
641da177e4SLinus Torvalds #define MECR_BSIO_SHIFT (0)
651da177e4SLinus Torvalds #define MECR_BSA_SHIFT  (5)
661da177e4SLinus Torvalds #define MECR_BSM_SHIFT  (10)
671da177e4SLinus Torvalds #define MECR_FAST_SHIFT (15)
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds #define MECR_SET(mecr, sock, shift, mask, bs) \
701da177e4SLinus Torvalds ((mecr)=((mecr)&~(((mask)<<(shift))<<\
711da177e4SLinus Torvalds                   ((sock)==0?MECR_SOCKET_0_SHIFT:MECR_SOCKET_1_SHIFT)))|\
721da177e4SLinus Torvalds         (((bs)<<(shift))<<((sock)==0?MECR_SOCKET_0_SHIFT:MECR_SOCKET_1_SHIFT)))
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #define MECR_GET(mecr, sock, shift, mask) \
751da177e4SLinus Torvalds ((((mecr)>>(((sock)==0)?MECR_SOCKET_0_SHIFT:MECR_SOCKET_1_SHIFT))>>\
761da177e4SLinus Torvalds  (shift))&(mask))
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds #define MECR_BSIO_SET(mecr, sock, bs) \
791da177e4SLinus Torvalds MECR_SET((mecr), (sock), MECR_BSIO_SHIFT, MECR_BS_MASK, (bs))
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds #define MECR_BSIO_GET(mecr, sock) \
821da177e4SLinus Torvalds MECR_GET((mecr), (sock), MECR_BSIO_SHIFT, MECR_BS_MASK)
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds #define MECR_BSA_SET(mecr, sock, bs) \
851da177e4SLinus Torvalds MECR_SET((mecr), (sock), MECR_BSA_SHIFT, MECR_BS_MASK, (bs))
861da177e4SLinus Torvalds 
871da177e4SLinus Torvalds #define MECR_BSA_GET(mecr, sock) \
881da177e4SLinus Torvalds MECR_GET((mecr), (sock), MECR_BSA_SHIFT, MECR_BS_MASK)
891da177e4SLinus Torvalds 
901da177e4SLinus Torvalds #define MECR_BSM_SET(mecr, sock, bs) \
911da177e4SLinus Torvalds MECR_SET((mecr), (sock), MECR_BSM_SHIFT, MECR_BS_MASK, (bs))
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds #define MECR_BSM_GET(mecr, sock) \
941da177e4SLinus Torvalds MECR_GET((mecr), (sock), MECR_BSM_SHIFT, MECR_BS_MASK)
951da177e4SLinus Torvalds 
961da177e4SLinus Torvalds #define MECR_FAST_SET(mecr, sock, fast) \
971da177e4SLinus Torvalds MECR_SET((mecr), (sock), MECR_FAST_SHIFT, MECR_FAST_MODE_MASK, (fast))
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds #define MECR_FAST_GET(mecr, sock) \
1001da177e4SLinus Torvalds MECR_GET((mecr), (sock), MECR_FAST_SHIFT, MECR_FAST_MODE_MASK)
1011da177e4SLinus Torvalds 
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /* This function implements the BS value calculation for setting the MECR
1041da177e4SLinus Torvalds  * using integer arithmetic:
1051da177e4SLinus Torvalds  */
1061da177e4SLinus Torvalds static inline unsigned int sa1100_pcmcia_mecr_bs(unsigned int pcmcia_cycle_ns,
1071da177e4SLinus Torvalds 						 unsigned int cpu_clock_khz){
1081da177e4SLinus Torvalds   unsigned int t = ((pcmcia_cycle_ns * cpu_clock_khz) / 6) - 1000000;
1091da177e4SLinus Torvalds   return (t / 1000000) + (((t % 1000000) == 0) ? 0 : 1);
1101da177e4SLinus Torvalds }
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds /* This function returns the (approximate) command assertion period, in
1131da177e4SLinus Torvalds  * nanoseconds, for a given CPU clock frequency and MECR BS value:
1141da177e4SLinus Torvalds  */
1151da177e4SLinus Torvalds static inline unsigned int sa1100_pcmcia_cmd_time(unsigned int cpu_clock_khz,
1161da177e4SLinus Torvalds 						  unsigned int pcmcia_mecr_bs){
1171da177e4SLinus Torvalds   return (((10000000 * 2) / cpu_clock_khz) * (3 * (pcmcia_mecr_bs + 1))) / 10;
1181da177e4SLinus Torvalds }
1191da177e4SLinus Torvalds 
1201da177e4SLinus Torvalds 
121*701a5dc0SRussell King - ARM Linux int sa11xx_drv_pcmcia_add_one(struct soc_pcmcia_socket *skt);
122*701a5dc0SRussell King - ARM Linux void sa11xx_drv_pcmcia_ops(struct pcmcia_low_level *ops);
1231da177e4SLinus Torvalds extern int sa11xx_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr);
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds #endif  /* !defined(_PCMCIA_SA1100_H) */
126