blob: c83f0bb6cf3cfc2cf1e6d6f0f84533c824c15228 [file] [log] [blame]
wdenk591dda52002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
3 * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/* stuff specific for the sc520,
25 * but idependent of implementation */
26
wdenkabda5ca2003-05-31 18:35:21 +000027#include <config.h>
28
29#ifdef CONFIG_SC520
wdenk591dda52002-11-18 00:14:45 +000030
31#include <common.h>
32#include <config.h>
33#include <pci.h>
wdenkabda5ca2003-05-31 18:35:21 +000034#include <ssi.h>
wdenk591dda52002-11-18 00:14:45 +000035#include <asm/io.h>
36#include <asm/pci.h>
37#include <asm/ic/sc520.h>
38
Wolfgang Denk6405a152006-03-31 18:32:53 +020039DECLARE_GLOBAL_DATA_PTR;
40
wdenk57b2d802003-06-27 21:31:46 +000041/*
42 * utility functions for boards based on the AMD sc520
43 *
wdenk591dda52002-11-18 00:14:45 +000044 * void write_mmcr_byte(u16 mmcr, u8 data)
45 * void write_mmcr_word(u16 mmcr, u16 data)
46 * void write_mmcr_long(u16 mmcr, u32 data)
wdenk57b2d802003-06-27 21:31:46 +000047 *
wdenk591dda52002-11-18 00:14:45 +000048 * u8 read_mmcr_byte(u16 mmcr)
49 * u16 read_mmcr_word(u16 mmcr)
50 * u32 read_mmcr_long(u16 mmcr)
wdenk57b2d802003-06-27 21:31:46 +000051 *
wdenk591dda52002-11-18 00:14:45 +000052 * void init_sc520(void)
53 * unsigned long init_sc520_dram(void)
54 * void pci_sc520_init(struct pci_controller *hose)
wdenk57b2d802003-06-27 21:31:46 +000055 *
wdenk591dda52002-11-18 00:14:45 +000056 * void reset_timer(void)
57 * ulong get_timer(ulong base)
58 * void set_timer(ulong t)
59 * void udelay(unsigned long usec)
wdenk57b2d802003-06-27 21:31:46 +000060 *
wdenk591dda52002-11-18 00:14:45 +000061 */
62
63static u32 mmcr_base= 0xfffef000;
64
65void write_mmcr_byte(u16 mmcr, u8 data)
66{
67 writeb(data, mmcr+mmcr_base);
68}
69
70void write_mmcr_word(u16 mmcr, u16 data)
71{
wdenk57b2d802003-06-27 21:31:46 +000072 writew(data, mmcr+mmcr_base);
wdenk591dda52002-11-18 00:14:45 +000073}
74
75void write_mmcr_long(u16 mmcr, u32 data)
76{
77 writel(data, mmcr+mmcr_base);
78}
79
80u8 read_mmcr_byte(u16 mmcr)
81{
82 return readb(mmcr+mmcr_base);
83}
84
85u16 read_mmcr_word(u16 mmcr)
86{
wdenk57b2d802003-06-27 21:31:46 +000087 return readw(mmcr+mmcr_base);
wdenk591dda52002-11-18 00:14:45 +000088}
89
90u32 read_mmcr_long(u16 mmcr)
91{
92 return readl(mmcr+mmcr_base);
93}
94
95
96void init_sc520(void)
97{
wdenk591dda52002-11-18 00:14:45 +000098 /* Set the UARTxCTL register at it's slower,
wdenk57b2d802003-06-27 21:31:46 +000099 * baud clock giving us a 1.8432 MHz reference
wdenk591dda52002-11-18 00:14:45 +0000100 */
101 write_mmcr_byte(SC520_UART1CTL, 7);
102 write_mmcr_byte(SC520_UART2CTL, 7);
wdenk57b2d802003-06-27 21:31:46 +0000103
wdenk591dda52002-11-18 00:14:45 +0000104 /* first set the timer pin mapping */
105 write_mmcr_byte(SC520_CLKSEL, 0x72); /* no clock frequency selected, use 1.1892MHz */
wdenk57b2d802003-06-27 21:31:46 +0000106
wdenk591dda52002-11-18 00:14:45 +0000107 /* enable PCI bus arbitrer */
108 write_mmcr_byte(SC520_SYSARBCTL,0x02); /* enable concurrent mode */
wdenk57b2d802003-06-27 21:31:46 +0000109
wdenk591dda52002-11-18 00:14:45 +0000110 write_mmcr_word(SC520_SYSARBMENB,0x1f); /* enable external grants */
111 write_mmcr_word(SC520_HBCTL,0x04); /* enable posted-writes */
112
113
114 if (CFG_SC520_HIGH_SPEED) {
115 write_mmcr_byte(SC520_CPUCTL, 0x2); /* set it to 133 MHz and write back */
116 gd->cpu_clk = 133000000;
117 printf("## CPU Speed set to 133MHz\n");
118 } else {
119 write_mmcr_byte(SC520_CPUCTL, 1); /* set CPU to 100 MHz and write back cache */
120 printf("## CPU Speed set to 100MHz\n");
121 gd->cpu_clk = 100000000;
122 }
wdenk57b2d802003-06-27 21:31:46 +0000123
wdenk591dda52002-11-18 00:14:45 +0000124
125 /* wait at least one millisecond */
wdenk57b2d802003-06-27 21:31:46 +0000126 asm("movl $0x2000,%%ecx\n"
wdenk591dda52002-11-18 00:14:45 +0000127 "wait_loop: pushl %%ecx\n"
128 "popl %%ecx\n"
129 "loop wait_loop\n": : : "ecx");
130
131 /* turn on the SDRAM write buffer */
132 write_mmcr_byte(SC520_DBCTL, 0x11);
133
134 /* turn on the cache and disable write through */
135 asm("movl %%cr0, %%eax\n"
136 "andl $0x9fffffff, %%eax\n"
137 "movl %%eax, %%cr0\n" : : : "eax");
138}
139
140unsigned long init_sc520_dram(void)
141{
wdenk591dda52002-11-18 00:14:45 +0000142 bd_t *bd = gd->bd;
wdenk57b2d802003-06-27 21:31:46 +0000143
wdenk591dda52002-11-18 00:14:45 +0000144 u32 dram_present=0;
145 u32 dram_ctrl;
146
147 int val;
wdenk57b2d802003-06-27 21:31:46 +0000148
149 int cas_precharge_delay = CFG_SDRAM_PRECHARGE_DELAY;
150 int refresh_rate = CFG_SDRAM_REFRESH_RATE;
wdenk591dda52002-11-18 00:14:45 +0000151 int ras_cas_delay = CFG_SDRAM_RAS_CAS_DELAY;
wdenk57b2d802003-06-27 21:31:46 +0000152
wdenk591dda52002-11-18 00:14:45 +0000153 /* set SDRAM speed here */
wdenk57b2d802003-06-27 21:31:46 +0000154
155 refresh_rate/=78;
wdenk591dda52002-11-18 00:14:45 +0000156 if (refresh_rate<=1) {
157 val = 0; /* 7.8us */
158 } else if (refresh_rate==2) {
159 val = 1; /* 15.6us */
160 } else if (refresh_rate==3 || refresh_rate==4) {
161 val = 2; /* 31.2us */
162 } else {
163 val = 3; /* 62.4us */
164 }
165 write_mmcr_byte(SC520_DRCCTL, (read_mmcr_byte(SC520_DRCCTL) & 0xcf) | (val<<4));
wdenk57b2d802003-06-27 21:31:46 +0000166
wdenk591dda52002-11-18 00:14:45 +0000167 val = read_mmcr_byte(SC520_DRCTMCTL);
168 val &= 0xf0;
wdenk57b2d802003-06-27 21:31:46 +0000169
170 if (cas_precharge_delay==3) {
wdenk591dda52002-11-18 00:14:45 +0000171 val |= 0x04; /* 3T */
wdenk57b2d802003-06-27 21:31:46 +0000172 } else if (cas_precharge_delay==4) {
wdenk591dda52002-11-18 00:14:45 +0000173 val |= 0x08; /* 4T */
wdenk57b2d802003-06-27 21:31:46 +0000174 } else if (cas_precharge_delay>4) {
wdenk591dda52002-11-18 00:14:45 +0000175 val |= 0x0c;
wdenk57b2d802003-06-27 21:31:46 +0000176 }
177
wdenk591dda52002-11-18 00:14:45 +0000178 if (ras_cas_delay > 3) {
wdenk57b2d802003-06-27 21:31:46 +0000179 val |= 2;
wdenk591dda52002-11-18 00:14:45 +0000180 } else {
wdenk57b2d802003-06-27 21:31:46 +0000181 val |= 1;
wdenk591dda52002-11-18 00:14:45 +0000182 }
183 write_mmcr_byte(SC520_DRCTMCTL, val);
184
185
186 /* We read-back the configuration of the dram
187 * controller that the assembly code wrote */
188 dram_ctrl = read_mmcr_long(SC520_DRCBENDADR);
wdenk57b2d802003-06-27 21:31:46 +0000189
wdenk591dda52002-11-18 00:14:45 +0000190
191 bd->bi_dram[0].start = 0;
192 if (dram_ctrl & 0x80) {
193 /* bank 0 enabled */
194 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
wdenk57b2d802003-06-27 21:31:46 +0000195 bd->bi_dram[0].size = bd->bi_dram[1].start;
wdenk591dda52002-11-18 00:14:45 +0000196
197 } else {
198 bd->bi_dram[0].size = 0;
199 bd->bi_dram[1].start = bd->bi_dram[0].start;
200 }
wdenk57b2d802003-06-27 21:31:46 +0000201
wdenk591dda52002-11-18 00:14:45 +0000202 if (dram_ctrl & 0x8000) {
203 /* bank 1 enabled */
204 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
wdenk57b2d802003-06-27 21:31:46 +0000205 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
wdenk591dda52002-11-18 00:14:45 +0000206 } else {
207 bd->bi_dram[1].size = 0;
208 bd->bi_dram[2].start = bd->bi_dram[1].start;
209 }
wdenk57b2d802003-06-27 21:31:46 +0000210
wdenk591dda52002-11-18 00:14:45 +0000211 if (dram_ctrl & 0x800000) {
212 /* bank 2 enabled */
213 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
wdenk57b2d802003-06-27 21:31:46 +0000214 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
wdenk591dda52002-11-18 00:14:45 +0000215 } else {
216 bd->bi_dram[2].size = 0;
217 bd->bi_dram[3].start = bd->bi_dram[2].start;
wdenk57b2d802003-06-27 21:31:46 +0000218 }
219
wdenk591dda52002-11-18 00:14:45 +0000220 if (dram_ctrl & 0x80000000) {
221 /* bank 3 enabled */
222 dram_present = (dram_ctrl & 0x7f000000) >> 2;
223 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
224 } else {
225 bd->bi_dram[3].size = 0;
226 }
227
wdenk57b2d802003-06-27 21:31:46 +0000228
229#if 0
wdenk591dda52002-11-18 00:14:45 +0000230 printf("Configured %d bytes of dram\n", dram_present);
wdenk57b2d802003-06-27 21:31:46 +0000231#endif
wdenk591dda52002-11-18 00:14:45 +0000232 gd->ram_size = dram_present;
wdenk57b2d802003-06-27 21:31:46 +0000233
wdenk591dda52002-11-18 00:14:45 +0000234 return dram_present;
235}
236
237
238#ifdef CONFIG_PCI
239
240
wdenkabda5ca2003-05-31 18:35:21 +0000241static struct {
242 u8 priority;
243 u16 level_reg;
244 u8 level_bit;
245} sc520_irq[] = {
246 { SC520_IRQ0, SC520_MPICMODE, 0x01 },
247 { SC520_IRQ1, SC520_MPICMODE, 0x02 },
248 { SC520_IRQ2, SC520_SL1PICMODE, 0x02 },
249 { SC520_IRQ3, SC520_MPICMODE, 0x08 },
250 { SC520_IRQ4, SC520_MPICMODE, 0x10 },
251 { SC520_IRQ5, SC520_MPICMODE, 0x20 },
252 { SC520_IRQ6, SC520_MPICMODE, 0x40 },
253 { SC520_IRQ7, SC520_MPICMODE, 0x80 },
254
255 { SC520_IRQ8, SC520_SL1PICMODE, 0x01 },
256 { SC520_IRQ9, SC520_SL1PICMODE, 0x02 },
257 { SC520_IRQ10, SC520_SL1PICMODE, 0x04 },
258 { SC520_IRQ11, SC520_SL1PICMODE, 0x08 },
259 { SC520_IRQ12, SC520_SL1PICMODE, 0x10 },
260 { SC520_IRQ13, SC520_SL1PICMODE, 0x20 },
261 { SC520_IRQ14, SC520_SL1PICMODE, 0x40 },
262 { SC520_IRQ15, SC520_SL1PICMODE, 0x80 }
263};
264
265
266/* The interrupt used for PCI INTA-INTD */
wdenk57b2d802003-06-27 21:31:46 +0000267int sc520_pci_ints[15] = {
wdenkabda5ca2003-05-31 18:35:21 +0000268 -1, -1, -1, -1, -1, -1, -1, -1,
269 -1, -1, -1, -1, -1, -1, -1
270};
271
272/* utility function to configure a pci interrupt */
wdenk57b2d802003-06-27 21:31:46 +0000273int pci_sc520_set_irq(int pci_pin, int irq)
wdenkabda5ca2003-05-31 18:35:21 +0000274{
275 int i;
wdenk57b2d802003-06-27 21:31:46 +0000276
wdenkabda5ca2003-05-31 18:35:21 +0000277# if 0
278 printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
wdenk57b2d802003-06-27 21:31:46 +0000279#endif
wdenkabda5ca2003-05-31 18:35:21 +0000280 if (irq < 0 || irq > 15) {
281 return -1; /* illegal irq */
282 }
283
284 if (pci_pin < 0 || pci_pin > 15) {
285 return -1; /* illegal pci int pin */
286 }
287
wdenk57b2d802003-06-27 21:31:46 +0000288 /* first disable any non-pci interrupt source that use
wdenkabda5ca2003-05-31 18:35:21 +0000289 * this level */
290 for (i=SC520_GPTMR0MAP;i<=SC520_GP10IMAP;i++) {
291 if (i>=SC520_PCIINTAMAP&&i<=SC520_PCIINTDMAP) {
292 continue;
293 }
294 if (read_mmcr_byte(i) == sc520_irq[irq].priority) {
295 write_mmcr_byte(i, SC520_IRQ_DISABLED);
296 }
297 }
wdenk57b2d802003-06-27 21:31:46 +0000298
wdenkabda5ca2003-05-31 18:35:21 +0000299 /* Set the trigger to level */
wdenk57b2d802003-06-27 21:31:46 +0000300 write_mmcr_byte(sc520_irq[irq].level_reg,
wdenkabda5ca2003-05-31 18:35:21 +0000301 read_mmcr_byte(sc520_irq[irq].level_reg) | sc520_irq[irq].level_bit);
wdenk57b2d802003-06-27 21:31:46 +0000302
303
wdenkabda5ca2003-05-31 18:35:21 +0000304 if (pci_pin < 4) {
305 /* PCI INTA-INTD */
306 /* route the interrupt */
307 write_mmcr_byte(SC520_PCIINTAMAP + pci_pin, sc520_irq[irq].priority);
wdenk57b2d802003-06-27 21:31:46 +0000308
309
wdenkabda5ca2003-05-31 18:35:21 +0000310 } else {
311 /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
312 write_mmcr_byte(SC520_GP0IMAP + pci_pin - 4, sc520_irq[irq].priority);
wdenk57b2d802003-06-27 21:31:46 +0000313
wdenkabda5ca2003-05-31 18:35:21 +0000314 /* also set the polarity in this case */
wdenk57b2d802003-06-27 21:31:46 +0000315 write_mmcr_word(SC520_INTPINPOL,
wdenkabda5ca2003-05-31 18:35:21 +0000316 read_mmcr_word(SC520_INTPINPOL) | (1 << (pci_pin-4)));
wdenk57b2d802003-06-27 21:31:46 +0000317
wdenkabda5ca2003-05-31 18:35:21 +0000318 }
wdenk57b2d802003-06-27 21:31:46 +0000319
320 /* register the pin */
wdenkabda5ca2003-05-31 18:35:21 +0000321 sc520_pci_ints[pci_pin] = irq;
wdenk57b2d802003-06-27 21:31:46 +0000322
wdenkabda5ca2003-05-31 18:35:21 +0000323
324 return 0; /* OK */
325}
wdenk591dda52002-11-18 00:14:45 +0000326
327void pci_sc520_init(struct pci_controller *hose)
328{
329 hose->first_busno = 0;
330 hose->last_busno = 0xff;
331
332 /* System memory space */
wdenk57b2d802003-06-27 21:31:46 +0000333 pci_set_region(hose->regions + 0,
wdenk591dda52002-11-18 00:14:45 +0000334 SC520_PCI_MEMORY_BUS,
335 SC520_PCI_MEMORY_PHYS,
336 SC520_PCI_MEMORY_SIZE,
337 PCI_REGION_MEM | PCI_REGION_MEMORY);
338
339 /* PCI memory space */
wdenk57b2d802003-06-27 21:31:46 +0000340 pci_set_region(hose->regions + 1,
wdenk591dda52002-11-18 00:14:45 +0000341 SC520_PCI_MEM_BUS,
342 SC520_PCI_MEM_PHYS,
343 SC520_PCI_MEM_SIZE,
344 PCI_REGION_MEM);
345
346 /* ISA/PCI memory space */
wdenk57b2d802003-06-27 21:31:46 +0000347 pci_set_region(hose->regions + 2,
wdenk591dda52002-11-18 00:14:45 +0000348 SC520_ISA_MEM_BUS,
349 SC520_ISA_MEM_PHYS,
350 SC520_ISA_MEM_SIZE,
351 PCI_REGION_MEM);
352
353 /* PCI I/O space */
wdenk57b2d802003-06-27 21:31:46 +0000354 pci_set_region(hose->regions + 3,
wdenk591dda52002-11-18 00:14:45 +0000355 SC520_PCI_IO_BUS,
356 SC520_PCI_IO_PHYS,
357 SC520_PCI_IO_SIZE,
358 PCI_REGION_IO);
359
360 /* ISA/PCI I/O space */
wdenk57b2d802003-06-27 21:31:46 +0000361 pci_set_region(hose->regions + 4,
wdenk591dda52002-11-18 00:14:45 +0000362 SC520_ISA_IO_BUS,
363 SC520_ISA_IO_PHYS,
364 SC520_ISA_IO_SIZE,
365 PCI_REGION_IO);
366
367 hose->region_count = 5;
368
369 pci_setup_type1(hose,
370 SC520_REG_ADDR,
371 SC520_REG_DATA);
372
373 pci_register_hose(hose);
374
375 hose->last_busno = pci_hose_scan(hose);
wdenk57b2d802003-06-27 21:31:46 +0000376
wdenk591dda52002-11-18 00:14:45 +0000377 /* enable target memory acceses on host brige */
wdenk57b2d802003-06-27 21:31:46 +0000378 pci_write_config_word(0, PCI_COMMAND,
wdenk591dda52002-11-18 00:14:45 +0000379 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
380
381}
382
383
384#endif
385
386#ifdef CFG_TIMER_SC520
387
388
389void reset_timer(void)
390{
391 write_mmcr_word(SC520_GPTMR0CNT, 0);
392 write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
wdenk57b2d802003-06-27 21:31:46 +0000393
wdenk591dda52002-11-18 00:14:45 +0000394}
395
396ulong get_timer(ulong base)
397{
398 /* fixme: 30 or 33 */
399 return read_mmcr_word(SC520_GPTMR0CNT) / 33;
400}
401
402void set_timer(ulong t)
403{
404 /* FixMe: use two cascade coupled timers */
405 write_mmcr_word(SC520_GPTMR0CTL, 0x4001);
406 write_mmcr_word(SC520_GPTMR0CNT, t*33);
407 write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
408}
409
410
411void udelay(unsigned long usec)
412{
413 int m=0;
414 long u;
wdenk57b2d802003-06-27 21:31:46 +0000415
wdenk591dda52002-11-18 00:14:45 +0000416 read_mmcr_word(SC520_SWTMRMILLI);
417 read_mmcr_word(SC520_SWTMRMICRO);
wdenk57b2d802003-06-27 21:31:46 +0000418
wdenk591dda52002-11-18 00:14:45 +0000419#if 0
420 /* do not enable this line, udelay is used in the serial driver -> recursion */
421 printf("udelay: %ld m.u %d.%d tm.tu %d.%d\n", usec, m, u, tm, tu);
wdenk57b2d802003-06-27 21:31:46 +0000422#endif
wdenk591dda52002-11-18 00:14:45 +0000423 while (1) {
wdenk57b2d802003-06-27 21:31:46 +0000424
wdenk591dda52002-11-18 00:14:45 +0000425 m += read_mmcr_word(SC520_SWTMRMILLI);
426 u = read_mmcr_word(SC520_SWTMRMICRO) + (m * 1000);
wdenk57b2d802003-06-27 21:31:46 +0000427
wdenk591dda52002-11-18 00:14:45 +0000428 if (usec <= u) {
429 break;
430 }
431 }
432}
433
434#endif
435
wdenkabda5ca2003-05-31 18:35:21 +0000436int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase)
437{
438 u8 temp=0;
439
440 if (freq >= 8192) {
wdenk57b2d802003-06-27 21:31:46 +0000441 temp |= CTL_CLK_SEL_4;
wdenkabda5ca2003-05-31 18:35:21 +0000442 } else if (freq >= 4096) {
wdenk57b2d802003-06-27 21:31:46 +0000443 temp |= CTL_CLK_SEL_8;
wdenkabda5ca2003-05-31 18:35:21 +0000444 } else if (freq >= 2048) {
wdenk57b2d802003-06-27 21:31:46 +0000445 temp |= CTL_CLK_SEL_16;
wdenkabda5ca2003-05-31 18:35:21 +0000446 } else if (freq >= 1024) {
wdenk57b2d802003-06-27 21:31:46 +0000447 temp |= CTL_CLK_SEL_32;
wdenkabda5ca2003-05-31 18:35:21 +0000448 } else if (freq >= 512) {
449 temp |= CTL_CLK_SEL_64;
450 } else if (freq >= 256) {
451 temp |= CTL_CLK_SEL_128;
452 } else if (freq >= 128) {
453 temp |= CTL_CLK_SEL_256;
454 } else {
455 temp |= CTL_CLK_SEL_512;
456 }
wdenk57b2d802003-06-27 21:31:46 +0000457
wdenkabda5ca2003-05-31 18:35:21 +0000458 if (!lsb_first) {
459 temp |= MSBF_ENB;
460 }
wdenk57b2d802003-06-27 21:31:46 +0000461
wdenkabda5ca2003-05-31 18:35:21 +0000462 if (inv_clock) {
463 temp |= CLK_INV_ENB;
464 }
wdenk57b2d802003-06-27 21:31:46 +0000465
wdenkabda5ca2003-05-31 18:35:21 +0000466 if (inv_phase) {
467 temp |= PHS_INV_ENB;
468 }
wdenk57b2d802003-06-27 21:31:46 +0000469
wdenkabda5ca2003-05-31 18:35:21 +0000470 write_mmcr_byte(SC520_SSICTL, temp);
wdenk57b2d802003-06-27 21:31:46 +0000471
wdenkabda5ca2003-05-31 18:35:21 +0000472 return 0;
473}
474
wdenk57b2d802003-06-27 21:31:46 +0000475u8 ssi_txrx_byte(u8 data)
wdenkabda5ca2003-05-31 18:35:21 +0000476{
477 write_mmcr_byte(SC520_SSIXMIT, data);
478 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
479 write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMITRCV);
480 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
wdenk57b2d802003-06-27 21:31:46 +0000481 return read_mmcr_byte(SC520_SSIRCV);
482}
wdenkabda5ca2003-05-31 18:35:21 +0000483
484
wdenk57b2d802003-06-27 21:31:46 +0000485void ssi_tx_byte(u8 data)
wdenkabda5ca2003-05-31 18:35:21 +0000486{
487 write_mmcr_byte(SC520_SSIXMIT, data);
wdenk57b2d802003-06-27 21:31:46 +0000488 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
wdenkabda5ca2003-05-31 18:35:21 +0000489 write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMIT);
490}
491
wdenk57b2d802003-06-27 21:31:46 +0000492u8 ssi_rx_byte(void)
wdenkabda5ca2003-05-31 18:35:21 +0000493{
494 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
495 write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_RCV);
496 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
497 return read_mmcr_byte(SC520_SSIRCV);
wdenk57b2d802003-06-27 21:31:46 +0000498}
wdenk591dda52002-11-18 00:14:45 +0000499
wdenkabda5ca2003-05-31 18:35:21 +0000500#endif /* CONFIG_SC520 */