1384740dcSRalf Baechle /*
2384740dcSRalf Baechle * Author: MontaVista Software, Inc.
3384740dcSRalf Baechle * source@mvista.com
4384740dcSRalf Baechle *
5384740dcSRalf Baechle * Copyright 2001-2006 MontaVista Software Inc.
6384740dcSRalf Baechle *
7384740dcSRalf Baechle * This program is free software; you can redistribute it and/or modify it
8384740dcSRalf Baechle * under the terms of the GNU General Public License as published by the
9384740dcSRalf Baechle * Free Software Foundation; either version 2 of the License, or (at your
10384740dcSRalf Baechle * option) any later version.
11384740dcSRalf Baechle *
12384740dcSRalf Baechle * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13384740dcSRalf Baechle * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14384740dcSRalf Baechle * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15384740dcSRalf Baechle * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16384740dcSRalf Baechle * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17384740dcSRalf Baechle * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
18384740dcSRalf Baechle * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19384740dcSRalf Baechle * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
20384740dcSRalf Baechle * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21384740dcSRalf Baechle * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22384740dcSRalf Baechle *
23384740dcSRalf Baechle * You should have received a copy of the GNU General Public License along
24384740dcSRalf Baechle * with this program; if not, write to the Free Software Foundation, Inc.,
25384740dcSRalf Baechle * 675 Mass Ave, Cambridge, MA 02139, USA.
26384740dcSRalf Baechle */
27384740dcSRalf Baechle #ifndef __ASM_TXX9_TX4927_H
28384740dcSRalf Baechle #define __ASM_TXX9_TX4927_H
29384740dcSRalf Baechle
30384740dcSRalf Baechle #include <linux/types.h>
31384740dcSRalf Baechle #include <linux/io.h>
32384740dcSRalf Baechle #include <asm/txx9irq.h>
33384740dcSRalf Baechle #include <asm/txx9/tx4927pcic.h>
34384740dcSRalf Baechle
35384740dcSRalf Baechle #ifdef CONFIG_64BIT
36384740dcSRalf Baechle #define TX4927_REG_BASE 0xffffffffff1f0000UL
37384740dcSRalf Baechle #else
38384740dcSRalf Baechle #define TX4927_REG_BASE 0xff1f0000UL
39384740dcSRalf Baechle #endif
40384740dcSRalf Baechle #define TX4927_REG_SIZE 0x00010000
41384740dcSRalf Baechle
42384740dcSRalf Baechle #define TX4927_SDRAMC_REG (TX4927_REG_BASE + 0x8000)
43384740dcSRalf Baechle #define TX4927_EBUSC_REG (TX4927_REG_BASE + 0x9000)
44f48c8c95SAtsushi Nemoto #define TX4927_DMA_REG (TX4927_REG_BASE + 0xb000)
45384740dcSRalf Baechle #define TX4927_PCIC_REG (TX4927_REG_BASE + 0xd000)
46384740dcSRalf Baechle #define TX4927_CCFG_REG (TX4927_REG_BASE + 0xe000)
47384740dcSRalf Baechle #define TX4927_IRC_REG (TX4927_REG_BASE + 0xf600)
48384740dcSRalf Baechle #define TX4927_NR_TMR 3
49384740dcSRalf Baechle #define TX4927_TMR_REG(ch) (TX4927_REG_BASE + 0xf000 + (ch) * 0x100)
50384740dcSRalf Baechle #define TX4927_NR_SIO 2
51384740dcSRalf Baechle #define TX4927_SIO_REG(ch) (TX4927_REG_BASE + 0xf300 + (ch) * 0x100)
52384740dcSRalf Baechle #define TX4927_PIO_REG (TX4927_REG_BASE + 0xf500)
53*742cd586SAtsushi Nemoto #define TX4927_ACLC_REG (TX4927_REG_BASE + 0xf700)
54384740dcSRalf Baechle
55384740dcSRalf Baechle #define TX4927_IR_ECCERR 0
56384740dcSRalf Baechle #define TX4927_IR_WTOERR 1
57384740dcSRalf Baechle #define TX4927_NUM_IR_INT 6
58384740dcSRalf Baechle #define TX4927_IR_INT(n) (2 + (n))
59384740dcSRalf Baechle #define TX4927_NUM_IR_SIO 2
60384740dcSRalf Baechle #define TX4927_IR_SIO(n) (8 + (n))
61384740dcSRalf Baechle #define TX4927_NUM_IR_DMA 4
62384740dcSRalf Baechle #define TX4927_IR_DMA(n) (10 + (n))
63384740dcSRalf Baechle #define TX4927_IR_PIO 14
64384740dcSRalf Baechle #define TX4927_IR_PDMAC 15
65384740dcSRalf Baechle #define TX4927_IR_PCIC 16
66384740dcSRalf Baechle #define TX4927_NUM_IR_TMR 3
67384740dcSRalf Baechle #define TX4927_IR_TMR(n) (17 + (n))
68384740dcSRalf Baechle #define TX4927_IR_PCIERR 22
69384740dcSRalf Baechle #define TX4927_IR_PCIPME 23
70384740dcSRalf Baechle #define TX4927_IR_ACLC 24
71384740dcSRalf Baechle #define TX4927_IR_ACLCPME 25
72384740dcSRalf Baechle #define TX4927_NUM_IR 32
73384740dcSRalf Baechle
74384740dcSRalf Baechle #define TX4927_IRC_INT 2 /* IP[2] in Status register */
75384740dcSRalf Baechle
76384740dcSRalf Baechle #define TX4927_NUM_PIO 16
77384740dcSRalf Baechle
78384740dcSRalf Baechle struct tx4927_sdramc_reg {
79384740dcSRalf Baechle u64 cr[4];
80384740dcSRalf Baechle u64 unused0[4];
81384740dcSRalf Baechle u64 tr;
82384740dcSRalf Baechle u64 unused1[2];
83384740dcSRalf Baechle u64 cmd;
84384740dcSRalf Baechle };
85384740dcSRalf Baechle
86384740dcSRalf Baechle struct tx4927_ebusc_reg {
87384740dcSRalf Baechle u64 cr[8];
88384740dcSRalf Baechle };
89384740dcSRalf Baechle
90384740dcSRalf Baechle struct tx4927_ccfg_reg {
91384740dcSRalf Baechle u64 ccfg;
92384740dcSRalf Baechle u64 crir;
93384740dcSRalf Baechle u64 pcfg;
94384740dcSRalf Baechle u64 toea;
95384740dcSRalf Baechle u64 clkctr;
96384740dcSRalf Baechle u64 unused0;
97384740dcSRalf Baechle u64 garbc;
98384740dcSRalf Baechle u64 unused1;
99384740dcSRalf Baechle u64 unused2;
100384740dcSRalf Baechle u64 ramp;
101384740dcSRalf Baechle };
102384740dcSRalf Baechle
103384740dcSRalf Baechle /*
104384740dcSRalf Baechle * CCFG
105384740dcSRalf Baechle */
106384740dcSRalf Baechle /* CCFG : Chip Configuration */
107384740dcSRalf Baechle #define TX4927_CCFG_WDRST 0x0000020000000000ULL
108384740dcSRalf Baechle #define TX4927_CCFG_WDREXEN 0x0000010000000000ULL
109384740dcSRalf Baechle #define TX4927_CCFG_BCFG_MASK 0x000000ff00000000ULL
110384740dcSRalf Baechle #define TX4927_CCFG_TINTDIS 0x01000000
111384740dcSRalf Baechle #define TX4927_CCFG_PCI66 0x00800000
112384740dcSRalf Baechle #define TX4927_CCFG_PCIMODE 0x00400000
113384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_MASK 0x000e0000
114384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_8 (0x0 << 17)
115384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_12 (0x1 << 17)
116384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_16 (0x2 << 17)
117384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_10 (0x3 << 17)
118384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_2 (0x4 << 17)
119384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_3 (0x5 << 17)
120384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_4 (0x6 << 17)
121384740dcSRalf Baechle #define TX4927_CCFG_DIVMODE_2_5 (0x7 << 17)
122384740dcSRalf Baechle #define TX4927_CCFG_BEOW 0x00010000
123384740dcSRalf Baechle #define TX4927_CCFG_WR 0x00008000
124384740dcSRalf Baechle #define TX4927_CCFG_TOE 0x00004000
125384740dcSRalf Baechle #define TX4927_CCFG_PCIARB 0x00002000
126384740dcSRalf Baechle #define TX4927_CCFG_PCIDIVMODE_MASK 0x00001800
127384740dcSRalf Baechle #define TX4927_CCFG_PCIDIVMODE_2_5 0x00000000
128384740dcSRalf Baechle #define TX4927_CCFG_PCIDIVMODE_3 0x00000800
129384740dcSRalf Baechle #define TX4927_CCFG_PCIDIVMODE_5 0x00001000
130384740dcSRalf Baechle #define TX4927_CCFG_PCIDIVMODE_6 0x00001800
131384740dcSRalf Baechle #define TX4927_CCFG_SYSSP_MASK 0x000000c0
132384740dcSRalf Baechle #define TX4927_CCFG_ENDIAN 0x00000004
133384740dcSRalf Baechle #define TX4927_CCFG_HALT 0x00000002
134384740dcSRalf Baechle #define TX4927_CCFG_ACEHOLD 0x00000001
135384740dcSRalf Baechle #define TX4927_CCFG_W1CBITS (TX4927_CCFG_WDRST | TX4927_CCFG_BEOW)
136384740dcSRalf Baechle
137384740dcSRalf Baechle /* PCFG : Pin Configuration */
138384740dcSRalf Baechle #define TX4927_PCFG_SDCLKDLY_MASK 0x30000000
139384740dcSRalf Baechle #define TX4927_PCFG_SDCLKDLY(d) ((d)<<28)
140384740dcSRalf Baechle #define TX4927_PCFG_SYSCLKEN 0x08000000
141384740dcSRalf Baechle #define TX4927_PCFG_SDCLKEN_ALL 0x07800000
142384740dcSRalf Baechle #define TX4927_PCFG_SDCLKEN(ch) (0x00800000<<(ch))
143384740dcSRalf Baechle #define TX4927_PCFG_PCICLKEN_ALL 0x003f0000
144384740dcSRalf Baechle #define TX4927_PCFG_PCICLKEN(ch) (0x00010000<<(ch))
145384740dcSRalf Baechle #define TX4927_PCFG_SEL2 0x00000200
146384740dcSRalf Baechle #define TX4927_PCFG_SEL1 0x00000100
147384740dcSRalf Baechle #define TX4927_PCFG_DMASEL_ALL 0x000000ff
148384740dcSRalf Baechle #define TX4927_PCFG_DMASEL0_MASK 0x00000003
149384740dcSRalf Baechle #define TX4927_PCFG_DMASEL1_MASK 0x0000000c
150384740dcSRalf Baechle #define TX4927_PCFG_DMASEL2_MASK 0x00000030
151384740dcSRalf Baechle #define TX4927_PCFG_DMASEL3_MASK 0x000000c0
152384740dcSRalf Baechle #define TX4927_PCFG_DMASEL0_DRQ0 0x00000000
153384740dcSRalf Baechle #define TX4927_PCFG_DMASEL0_SIO1 0x00000001
154384740dcSRalf Baechle #define TX4927_PCFG_DMASEL0_ACL0 0x00000002
155384740dcSRalf Baechle #define TX4927_PCFG_DMASEL0_ACL2 0x00000003
156384740dcSRalf Baechle #define TX4927_PCFG_DMASEL1_DRQ1 0x00000000
157384740dcSRalf Baechle #define TX4927_PCFG_DMASEL1_SIO1 0x00000004
158384740dcSRalf Baechle #define TX4927_PCFG_DMASEL1_ACL1 0x00000008
159384740dcSRalf Baechle #define TX4927_PCFG_DMASEL1_ACL3 0x0000000c
160384740dcSRalf Baechle #define TX4927_PCFG_DMASEL2_DRQ2 0x00000000 /* SEL2=0 */
161384740dcSRalf Baechle #define TX4927_PCFG_DMASEL2_SIO0 0x00000010 /* SEL2=0 */
162384740dcSRalf Baechle #define TX4927_PCFG_DMASEL2_ACL1 0x00000000 /* SEL2=1 */
163384740dcSRalf Baechle #define TX4927_PCFG_DMASEL2_ACL2 0x00000020 /* SEL2=1 */
164384740dcSRalf Baechle #define TX4927_PCFG_DMASEL2_ACL0 0x00000030 /* SEL2=1 */
165384740dcSRalf Baechle #define TX4927_PCFG_DMASEL3_DRQ3 0x00000000
166384740dcSRalf Baechle #define TX4927_PCFG_DMASEL3_SIO0 0x00000040
167384740dcSRalf Baechle #define TX4927_PCFG_DMASEL3_ACL3 0x00000080
168384740dcSRalf Baechle #define TX4927_PCFG_DMASEL3_ACL1 0x000000c0
169384740dcSRalf Baechle
170384740dcSRalf Baechle /* CLKCTR : Clock Control */
171384740dcSRalf Baechle #define TX4927_CLKCTR_ACLCKD 0x02000000
172384740dcSRalf Baechle #define TX4927_CLKCTR_PIOCKD 0x01000000
173384740dcSRalf Baechle #define TX4927_CLKCTR_DMACKD 0x00800000
174384740dcSRalf Baechle #define TX4927_CLKCTR_PCICKD 0x00400000
175384740dcSRalf Baechle #define TX4927_CLKCTR_TM0CKD 0x00100000
176384740dcSRalf Baechle #define TX4927_CLKCTR_TM1CKD 0x00080000
177384740dcSRalf Baechle #define TX4927_CLKCTR_TM2CKD 0x00040000
178384740dcSRalf Baechle #define TX4927_CLKCTR_SIO0CKD 0x00020000
179384740dcSRalf Baechle #define TX4927_CLKCTR_SIO1CKD 0x00010000
180384740dcSRalf Baechle #define TX4927_CLKCTR_ACLRST 0x00000200
181384740dcSRalf Baechle #define TX4927_CLKCTR_PIORST 0x00000100
182384740dcSRalf Baechle #define TX4927_CLKCTR_DMARST 0x00000080
183384740dcSRalf Baechle #define TX4927_CLKCTR_PCIRST 0x00000040
184384740dcSRalf Baechle #define TX4927_CLKCTR_TM0RST 0x00000010
185384740dcSRalf Baechle #define TX4927_CLKCTR_TM1RST 0x00000008
186384740dcSRalf Baechle #define TX4927_CLKCTR_TM2RST 0x00000004
187384740dcSRalf Baechle #define TX4927_CLKCTR_SIO0RST 0x00000002
188384740dcSRalf Baechle #define TX4927_CLKCTR_SIO1RST 0x00000001
189384740dcSRalf Baechle
190384740dcSRalf Baechle #define tx4927_sdramcptr \
191384740dcSRalf Baechle ((struct tx4927_sdramc_reg __iomem *)TX4927_SDRAMC_REG)
192384740dcSRalf Baechle #define tx4927_pcicptr \
193384740dcSRalf Baechle ((struct tx4927_pcic_reg __iomem *)TX4927_PCIC_REG)
194384740dcSRalf Baechle #define tx4927_ccfgptr \
195384740dcSRalf Baechle ((struct tx4927_ccfg_reg __iomem *)TX4927_CCFG_REG)
196384740dcSRalf Baechle #define tx4927_ebuscptr \
197384740dcSRalf Baechle ((struct tx4927_ebusc_reg __iomem *)TX4927_EBUSC_REG)
198384740dcSRalf Baechle #define tx4927_pioptr ((struct txx9_pio_reg __iomem *)TX4927_PIO_REG)
199384740dcSRalf Baechle
200384740dcSRalf Baechle #define TX4927_REV_PCODE() \
201384740dcSRalf Baechle ((__u32)__raw_readq(&tx4927_ccfgptr->crir) >> 16)
202384740dcSRalf Baechle
203384740dcSRalf Baechle #define TX4927_SDRAMC_CR(ch) __raw_readq(&tx4927_sdramcptr->cr[(ch)])
204384740dcSRalf Baechle #define TX4927_SDRAMC_BA(ch) ((TX4927_SDRAMC_CR(ch) >> 49) << 21)
205384740dcSRalf Baechle #define TX4927_SDRAMC_SIZE(ch) \
206384740dcSRalf Baechle ((((TX4927_SDRAMC_CR(ch) >> 33) & 0x7fff) + 1) << 21)
207384740dcSRalf Baechle
208384740dcSRalf Baechle #define TX4927_EBUSC_CR(ch) __raw_readq(&tx4927_ebuscptr->cr[(ch)])
209384740dcSRalf Baechle #define TX4927_EBUSC_BA(ch) ((TX4927_EBUSC_CR(ch) >> 48) << 20)
210384740dcSRalf Baechle #define TX4927_EBUSC_SIZE(ch) \
211384740dcSRalf Baechle (0x00100000 << ((unsigned long)(TX4927_EBUSC_CR(ch) >> 8) & 0xf))
212384740dcSRalf Baechle #define TX4927_EBUSC_WIDTH(ch) \
213384740dcSRalf Baechle (64 >> ((__u32)(TX4927_EBUSC_CR(ch) >> 20) & 0x3))
214384740dcSRalf Baechle
215384740dcSRalf Baechle /* utilities */
txx9_clear64(__u64 __iomem * adr,__u64 bits)216384740dcSRalf Baechle static inline void txx9_clear64(__u64 __iomem *adr, __u64 bits)
217384740dcSRalf Baechle {
218384740dcSRalf Baechle #ifdef CONFIG_32BIT
219384740dcSRalf Baechle unsigned long flags;
220384740dcSRalf Baechle local_irq_save(flags);
221384740dcSRalf Baechle #endif
222384740dcSRalf Baechle ____raw_writeq(____raw_readq(adr) & ~bits, adr);
223384740dcSRalf Baechle #ifdef CONFIG_32BIT
224384740dcSRalf Baechle local_irq_restore(flags);
225384740dcSRalf Baechle #endif
226384740dcSRalf Baechle }
txx9_set64(__u64 __iomem * adr,__u64 bits)227384740dcSRalf Baechle static inline void txx9_set64(__u64 __iomem *adr, __u64 bits)
228384740dcSRalf Baechle {
229384740dcSRalf Baechle #ifdef CONFIG_32BIT
230384740dcSRalf Baechle unsigned long flags;
231384740dcSRalf Baechle local_irq_save(flags);
232384740dcSRalf Baechle #endif
233384740dcSRalf Baechle ____raw_writeq(____raw_readq(adr) | bits, adr);
234384740dcSRalf Baechle #ifdef CONFIG_32BIT
235384740dcSRalf Baechle local_irq_restore(flags);
236384740dcSRalf Baechle #endif
237384740dcSRalf Baechle }
238384740dcSRalf Baechle
239384740dcSRalf Baechle /* These functions are not interrupt safe. */
tx4927_ccfg_clear(__u64 bits)240384740dcSRalf Baechle static inline void tx4927_ccfg_clear(__u64 bits)
241384740dcSRalf Baechle {
242384740dcSRalf Baechle ____raw_writeq(____raw_readq(&tx4927_ccfgptr->ccfg)
243384740dcSRalf Baechle & ~(TX4927_CCFG_W1CBITS | bits),
244384740dcSRalf Baechle &tx4927_ccfgptr->ccfg);
245384740dcSRalf Baechle }
tx4927_ccfg_set(__u64 bits)246384740dcSRalf Baechle static inline void tx4927_ccfg_set(__u64 bits)
247384740dcSRalf Baechle {
248384740dcSRalf Baechle ____raw_writeq((____raw_readq(&tx4927_ccfgptr->ccfg)
249384740dcSRalf Baechle & ~TX4927_CCFG_W1CBITS) | bits,
250384740dcSRalf Baechle &tx4927_ccfgptr->ccfg);
251384740dcSRalf Baechle }
tx4927_ccfg_change(__u64 change,__u64 new)252384740dcSRalf Baechle static inline void tx4927_ccfg_change(__u64 change, __u64 new)
253384740dcSRalf Baechle {
254384740dcSRalf Baechle ____raw_writeq((____raw_readq(&tx4927_ccfgptr->ccfg)
255384740dcSRalf Baechle & ~(TX4927_CCFG_W1CBITS | change)) |
256384740dcSRalf Baechle new,
257384740dcSRalf Baechle &tx4927_ccfgptr->ccfg);
258384740dcSRalf Baechle }
259384740dcSRalf Baechle
260384740dcSRalf Baechle unsigned int tx4927_get_mem_size(void);
261384740dcSRalf Baechle void tx4927_wdt_init(void);
262384740dcSRalf Baechle void tx4927_setup(void);
263384740dcSRalf Baechle void tx4927_time_init(unsigned int tmrnr);
264384740dcSRalf Baechle void tx4927_sio_init(unsigned int sclk, unsigned int cts_mask);
265384740dcSRalf Baechle int tx4927_report_pciclk(void);
266384740dcSRalf Baechle int tx4927_pciclk66_setup(void);
267384740dcSRalf Baechle void tx4927_setup_pcierr_irq(void);
268384740dcSRalf Baechle void tx4927_irq_init(void);
269384740dcSRalf Baechle void tx4927_mtd_init(int ch);
270f48c8c95SAtsushi Nemoto void tx4927_dmac_init(int memcpy_chan);
271*742cd586SAtsushi Nemoto void tx4927_aclc_init(unsigned int dma_chan_out, unsigned int dma_chan_in);
272384740dcSRalf Baechle
273384740dcSRalf Baechle #endif /* __ASM_TXX9_TX4927_H */
274