blob: 689e775c938160a7747d2b51f3d1adb37275ad33 [file] [log] [blame]
wdenk2262cfe2002-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
wdenk7a8e9bed2003-05-31 18:35:21 +000027#include <config.h>
28
29#ifdef CONFIG_SC520
wdenk2262cfe2002-11-18 00:14:45 +000030
31#include <common.h>
32#include <config.h>
33#include <pci.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000034#include <ssi.h>
wdenk2262cfe2002-11-18 00:14:45 +000035#include <asm/io.h>
36#include <asm/pci.h>
37#include <asm/ic/sc520.h>
38
wdenk8bde7f72003-06-27 21:31:46 +000039/*
40 * utility functions for boards based on the AMD sc520
41 *
wdenk2262cfe2002-11-18 00:14:45 +000042 * void write_mmcr_byte(u16 mmcr, u8 data)
43 * void write_mmcr_word(u16 mmcr, u16 data)
44 * void write_mmcr_long(u16 mmcr, u32 data)
wdenk8bde7f72003-06-27 21:31:46 +000045 *
wdenk2262cfe2002-11-18 00:14:45 +000046 * u8 read_mmcr_byte(u16 mmcr)
47 * u16 read_mmcr_word(u16 mmcr)
48 * u32 read_mmcr_long(u16 mmcr)
wdenk8bde7f72003-06-27 21:31:46 +000049 *
wdenk2262cfe2002-11-18 00:14:45 +000050 * void init_sc520(void)
51 * unsigned long init_sc520_dram(void)
52 * void pci_sc520_init(struct pci_controller *hose)
wdenk8bde7f72003-06-27 21:31:46 +000053 *
wdenk2262cfe2002-11-18 00:14:45 +000054 * void reset_timer(void)
55 * ulong get_timer(ulong base)
56 * void set_timer(ulong t)
57 * void udelay(unsigned long usec)
wdenk8bde7f72003-06-27 21:31:46 +000058 *
wdenk2262cfe2002-11-18 00:14:45 +000059 */
60
61static u32 mmcr_base= 0xfffef000;
62
63void write_mmcr_byte(u16 mmcr, u8 data)
64{
65 writeb(data, mmcr+mmcr_base);
66}
67
68void write_mmcr_word(u16 mmcr, u16 data)
69{
wdenk8bde7f72003-06-27 21:31:46 +000070 writew(data, mmcr+mmcr_base);
wdenk2262cfe2002-11-18 00:14:45 +000071}
72
73void write_mmcr_long(u16 mmcr, u32 data)
74{
75 writel(data, mmcr+mmcr_base);
76}
77
78u8 read_mmcr_byte(u16 mmcr)
79{
80 return readb(mmcr+mmcr_base);
81}
82
83u16 read_mmcr_word(u16 mmcr)
84{
wdenk8bde7f72003-06-27 21:31:46 +000085 return readw(mmcr+mmcr_base);
wdenk2262cfe2002-11-18 00:14:45 +000086}
87
88u32 read_mmcr_long(u16 mmcr)
89{
90 return readl(mmcr+mmcr_base);
91}
92
93
94void init_sc520(void)
95{
96 DECLARE_GLOBAL_DATA_PTR;
wdenk8bde7f72003-06-27 21:31:46 +000097
wdenk2262cfe2002-11-18 00:14:45 +000098 /* Set the UARTxCTL register at it's slower,
wdenk8bde7f72003-06-27 21:31:46 +000099 * baud clock giving us a 1.8432 MHz reference
wdenk2262cfe2002-11-18 00:14:45 +0000100 */
101 write_mmcr_byte(SC520_UART1CTL, 7);
102 write_mmcr_byte(SC520_UART2CTL, 7);
wdenk8bde7f72003-06-27 21:31:46 +0000103
wdenk2262cfe2002-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 */
wdenk8bde7f72003-06-27 21:31:46 +0000106
wdenk2262cfe2002-11-18 00:14:45 +0000107 /* enable PCI bus arbitrer */
108 write_mmcr_byte(SC520_SYSARBCTL,0x02); /* enable concurrent mode */
wdenk8bde7f72003-06-27 21:31:46 +0000109
wdenk2262cfe2002-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 }
wdenk8bde7f72003-06-27 21:31:46 +0000123
wdenk2262cfe2002-11-18 00:14:45 +0000124
125 /* wait at least one millisecond */
wdenk8bde7f72003-06-27 21:31:46 +0000126 asm("movl $0x2000,%%ecx\n"
wdenk2262cfe2002-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{
142 DECLARE_GLOBAL_DATA_PTR;
143 bd_t *bd = gd->bd;
wdenk8bde7f72003-06-27 21:31:46 +0000144
wdenk2262cfe2002-11-18 00:14:45 +0000145 u32 dram_present=0;
146 u32 dram_ctrl;
147
148 int val;
wdenk8bde7f72003-06-27 21:31:46 +0000149
150 int cas_precharge_delay = CFG_SDRAM_PRECHARGE_DELAY;
151 int refresh_rate = CFG_SDRAM_REFRESH_RATE;
wdenk2262cfe2002-11-18 00:14:45 +0000152 int ras_cas_delay = CFG_SDRAM_RAS_CAS_DELAY;
wdenk8bde7f72003-06-27 21:31:46 +0000153
wdenk2262cfe2002-11-18 00:14:45 +0000154 /* set SDRAM speed here */
wdenk8bde7f72003-06-27 21:31:46 +0000155
156 refresh_rate/=78;
wdenk2262cfe2002-11-18 00:14:45 +0000157 if (refresh_rate<=1) {
158 val = 0; /* 7.8us */
159 } else if (refresh_rate==2) {
160 val = 1; /* 15.6us */
161 } else if (refresh_rate==3 || refresh_rate==4) {
162 val = 2; /* 31.2us */
163 } else {
164 val = 3; /* 62.4us */
165 }
166 write_mmcr_byte(SC520_DRCCTL, (read_mmcr_byte(SC520_DRCCTL) & 0xcf) | (val<<4));
wdenk8bde7f72003-06-27 21:31:46 +0000167
wdenk2262cfe2002-11-18 00:14:45 +0000168 val = read_mmcr_byte(SC520_DRCTMCTL);
169 val &= 0xf0;
wdenk8bde7f72003-06-27 21:31:46 +0000170
171 if (cas_precharge_delay==3) {
wdenk2262cfe2002-11-18 00:14:45 +0000172 val |= 0x04; /* 3T */
wdenk8bde7f72003-06-27 21:31:46 +0000173 } else if (cas_precharge_delay==4) {
wdenk2262cfe2002-11-18 00:14:45 +0000174 val |= 0x08; /* 4T */
wdenk8bde7f72003-06-27 21:31:46 +0000175 } else if (cas_precharge_delay>4) {
wdenk2262cfe2002-11-18 00:14:45 +0000176 val |= 0x0c;
wdenk8bde7f72003-06-27 21:31:46 +0000177 }
178
wdenk2262cfe2002-11-18 00:14:45 +0000179 if (ras_cas_delay > 3) {
wdenk8bde7f72003-06-27 21:31:46 +0000180 val |= 2;
wdenk2262cfe2002-11-18 00:14:45 +0000181 } else {
wdenk8bde7f72003-06-27 21:31:46 +0000182 val |= 1;
wdenk2262cfe2002-11-18 00:14:45 +0000183 }
184 write_mmcr_byte(SC520_DRCTMCTL, val);
185
186
187 /* We read-back the configuration of the dram
188 * controller that the assembly code wrote */
189 dram_ctrl = read_mmcr_long(SC520_DRCBENDADR);
wdenk8bde7f72003-06-27 21:31:46 +0000190
wdenk2262cfe2002-11-18 00:14:45 +0000191
192 bd->bi_dram[0].start = 0;
193 if (dram_ctrl & 0x80) {
194 /* bank 0 enabled */
195 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
wdenk8bde7f72003-06-27 21:31:46 +0000196 bd->bi_dram[0].size = bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000197
198 } else {
199 bd->bi_dram[0].size = 0;
200 bd->bi_dram[1].start = bd->bi_dram[0].start;
201 }
wdenk8bde7f72003-06-27 21:31:46 +0000202
wdenk2262cfe2002-11-18 00:14:45 +0000203 if (dram_ctrl & 0x8000) {
204 /* bank 1 enabled */
205 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
wdenk8bde7f72003-06-27 21:31:46 +0000206 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000207 } else {
208 bd->bi_dram[1].size = 0;
209 bd->bi_dram[2].start = bd->bi_dram[1].start;
210 }
wdenk8bde7f72003-06-27 21:31:46 +0000211
wdenk2262cfe2002-11-18 00:14:45 +0000212 if (dram_ctrl & 0x800000) {
213 /* bank 2 enabled */
214 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
wdenk8bde7f72003-06-27 21:31:46 +0000215 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
wdenk2262cfe2002-11-18 00:14:45 +0000216 } else {
217 bd->bi_dram[2].size = 0;
218 bd->bi_dram[3].start = bd->bi_dram[2].start;
wdenk8bde7f72003-06-27 21:31:46 +0000219 }
220
wdenk2262cfe2002-11-18 00:14:45 +0000221 if (dram_ctrl & 0x80000000) {
222 /* bank 3 enabled */
223 dram_present = (dram_ctrl & 0x7f000000) >> 2;
224 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
225 } else {
226 bd->bi_dram[3].size = 0;
227 }
228
wdenk8bde7f72003-06-27 21:31:46 +0000229
230#if 0
wdenk2262cfe2002-11-18 00:14:45 +0000231 printf("Configured %d bytes of dram\n", dram_present);
wdenk8bde7f72003-06-27 21:31:46 +0000232#endif
wdenk2262cfe2002-11-18 00:14:45 +0000233 gd->ram_size = dram_present;
wdenk8bde7f72003-06-27 21:31:46 +0000234
wdenk2262cfe2002-11-18 00:14:45 +0000235 return dram_present;
236}
237
238
239#ifdef CONFIG_PCI
240
241
wdenk7a8e9bed2003-05-31 18:35:21 +0000242static struct {
243 u8 priority;
244 u16 level_reg;
245 u8 level_bit;
246} sc520_irq[] = {
247 { SC520_IRQ0, SC520_MPICMODE, 0x01 },
248 { SC520_IRQ1, SC520_MPICMODE, 0x02 },
249 { SC520_IRQ2, SC520_SL1PICMODE, 0x02 },
250 { SC520_IRQ3, SC520_MPICMODE, 0x08 },
251 { SC520_IRQ4, SC520_MPICMODE, 0x10 },
252 { SC520_IRQ5, SC520_MPICMODE, 0x20 },
253 { SC520_IRQ6, SC520_MPICMODE, 0x40 },
254 { SC520_IRQ7, SC520_MPICMODE, 0x80 },
255
256 { SC520_IRQ8, SC520_SL1PICMODE, 0x01 },
257 { SC520_IRQ9, SC520_SL1PICMODE, 0x02 },
258 { SC520_IRQ10, SC520_SL1PICMODE, 0x04 },
259 { SC520_IRQ11, SC520_SL1PICMODE, 0x08 },
260 { SC520_IRQ12, SC520_SL1PICMODE, 0x10 },
261 { SC520_IRQ13, SC520_SL1PICMODE, 0x20 },
262 { SC520_IRQ14, SC520_SL1PICMODE, 0x40 },
263 { SC520_IRQ15, SC520_SL1PICMODE, 0x80 }
264};
265
266
267/* The interrupt used for PCI INTA-INTD */
wdenk8bde7f72003-06-27 21:31:46 +0000268int sc520_pci_ints[15] = {
wdenk7a8e9bed2003-05-31 18:35:21 +0000269 -1, -1, -1, -1, -1, -1, -1, -1,
270 -1, -1, -1, -1, -1, -1, -1
271};
272
273/* utility function to configure a pci interrupt */
wdenk8bde7f72003-06-27 21:31:46 +0000274int pci_sc520_set_irq(int pci_pin, int irq)
wdenk7a8e9bed2003-05-31 18:35:21 +0000275{
276 int i;
wdenk8bde7f72003-06-27 21:31:46 +0000277
wdenk7a8e9bed2003-05-31 18:35:21 +0000278# if 0
279 printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
wdenk8bde7f72003-06-27 21:31:46 +0000280#endif
wdenk7a8e9bed2003-05-31 18:35:21 +0000281 if (irq < 0 || irq > 15) {
282 return -1; /* illegal irq */
283 }
284
285 if (pci_pin < 0 || pci_pin > 15) {
286 return -1; /* illegal pci int pin */
287 }
288
wdenk8bde7f72003-06-27 21:31:46 +0000289 /* first disable any non-pci interrupt source that use
wdenk7a8e9bed2003-05-31 18:35:21 +0000290 * this level */
291 for (i=SC520_GPTMR0MAP;i<=SC520_GP10IMAP;i++) {
292 if (i>=SC520_PCIINTAMAP&&i<=SC520_PCIINTDMAP) {
293 continue;
294 }
295 if (read_mmcr_byte(i) == sc520_irq[irq].priority) {
296 write_mmcr_byte(i, SC520_IRQ_DISABLED);
297 }
298 }
wdenk8bde7f72003-06-27 21:31:46 +0000299
wdenk7a8e9bed2003-05-31 18:35:21 +0000300 /* Set the trigger to level */
wdenk8bde7f72003-06-27 21:31:46 +0000301 write_mmcr_byte(sc520_irq[irq].level_reg,
wdenk7a8e9bed2003-05-31 18:35:21 +0000302 read_mmcr_byte(sc520_irq[irq].level_reg) | sc520_irq[irq].level_bit);
wdenk8bde7f72003-06-27 21:31:46 +0000303
304
wdenk7a8e9bed2003-05-31 18:35:21 +0000305 if (pci_pin < 4) {
306 /* PCI INTA-INTD */
307 /* route the interrupt */
308 write_mmcr_byte(SC520_PCIINTAMAP + pci_pin, sc520_irq[irq].priority);
wdenk8bde7f72003-06-27 21:31:46 +0000309
310
wdenk7a8e9bed2003-05-31 18:35:21 +0000311 } else {
312 /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
313 write_mmcr_byte(SC520_GP0IMAP + pci_pin - 4, sc520_irq[irq].priority);
wdenk8bde7f72003-06-27 21:31:46 +0000314
wdenk7a8e9bed2003-05-31 18:35:21 +0000315 /* also set the polarity in this case */
wdenk8bde7f72003-06-27 21:31:46 +0000316 write_mmcr_word(SC520_INTPINPOL,
wdenk7a8e9bed2003-05-31 18:35:21 +0000317 read_mmcr_word(SC520_INTPINPOL) | (1 << (pci_pin-4)));
wdenk8bde7f72003-06-27 21:31:46 +0000318
wdenk7a8e9bed2003-05-31 18:35:21 +0000319 }
wdenk8bde7f72003-06-27 21:31:46 +0000320
321 /* register the pin */
wdenk7a8e9bed2003-05-31 18:35:21 +0000322 sc520_pci_ints[pci_pin] = irq;
wdenk8bde7f72003-06-27 21:31:46 +0000323
wdenk7a8e9bed2003-05-31 18:35:21 +0000324
325 return 0; /* OK */
326}
wdenk2262cfe2002-11-18 00:14:45 +0000327
328void pci_sc520_init(struct pci_controller *hose)
329{
330 hose->first_busno = 0;
331 hose->last_busno = 0xff;
332
333 /* System memory space */
wdenk8bde7f72003-06-27 21:31:46 +0000334 pci_set_region(hose->regions + 0,
wdenk2262cfe2002-11-18 00:14:45 +0000335 SC520_PCI_MEMORY_BUS,
336 SC520_PCI_MEMORY_PHYS,
337 SC520_PCI_MEMORY_SIZE,
338 PCI_REGION_MEM | PCI_REGION_MEMORY);
339
340 /* PCI memory space */
wdenk8bde7f72003-06-27 21:31:46 +0000341 pci_set_region(hose->regions + 1,
wdenk2262cfe2002-11-18 00:14:45 +0000342 SC520_PCI_MEM_BUS,
343 SC520_PCI_MEM_PHYS,
344 SC520_PCI_MEM_SIZE,
345 PCI_REGION_MEM);
346
347 /* ISA/PCI memory space */
wdenk8bde7f72003-06-27 21:31:46 +0000348 pci_set_region(hose->regions + 2,
wdenk2262cfe2002-11-18 00:14:45 +0000349 SC520_ISA_MEM_BUS,
350 SC520_ISA_MEM_PHYS,
351 SC520_ISA_MEM_SIZE,
352 PCI_REGION_MEM);
353
354 /* PCI I/O space */
wdenk8bde7f72003-06-27 21:31:46 +0000355 pci_set_region(hose->regions + 3,
wdenk2262cfe2002-11-18 00:14:45 +0000356 SC520_PCI_IO_BUS,
357 SC520_PCI_IO_PHYS,
358 SC520_PCI_IO_SIZE,
359 PCI_REGION_IO);
360
361 /* ISA/PCI I/O space */
wdenk8bde7f72003-06-27 21:31:46 +0000362 pci_set_region(hose->regions + 4,
wdenk2262cfe2002-11-18 00:14:45 +0000363 SC520_ISA_IO_BUS,
364 SC520_ISA_IO_PHYS,
365 SC520_ISA_IO_SIZE,
366 PCI_REGION_IO);
367
368 hose->region_count = 5;
369
370 pci_setup_type1(hose,
371 SC520_REG_ADDR,
372 SC520_REG_DATA);
373
374 pci_register_hose(hose);
375
376 hose->last_busno = pci_hose_scan(hose);
wdenk8bde7f72003-06-27 21:31:46 +0000377
wdenk2262cfe2002-11-18 00:14:45 +0000378 /* enable target memory acceses on host brige */
wdenk8bde7f72003-06-27 21:31:46 +0000379 pci_write_config_word(0, PCI_COMMAND,
wdenk2262cfe2002-11-18 00:14:45 +0000380 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
381
382}
383
384
385#endif
386
387#ifdef CFG_TIMER_SC520
388
389
390void reset_timer(void)
391{
392 write_mmcr_word(SC520_GPTMR0CNT, 0);
393 write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
wdenk8bde7f72003-06-27 21:31:46 +0000394
wdenk2262cfe2002-11-18 00:14:45 +0000395}
396
397ulong get_timer(ulong base)
398{
399 /* fixme: 30 or 33 */
400 return read_mmcr_word(SC520_GPTMR0CNT) / 33;
401}
402
403void set_timer(ulong t)
404{
405 /* FixMe: use two cascade coupled timers */
406 write_mmcr_word(SC520_GPTMR0CTL, 0x4001);
407 write_mmcr_word(SC520_GPTMR0CNT, t*33);
408 write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
409}
410
411
412void udelay(unsigned long usec)
413{
414 int m=0;
415 long u;
wdenk8bde7f72003-06-27 21:31:46 +0000416
wdenk2262cfe2002-11-18 00:14:45 +0000417 read_mmcr_word(SC520_SWTMRMILLI);
418 read_mmcr_word(SC520_SWTMRMICRO);
wdenk8bde7f72003-06-27 21:31:46 +0000419
wdenk2262cfe2002-11-18 00:14:45 +0000420#if 0
421 /* do not enable this line, udelay is used in the serial driver -> recursion */
422 printf("udelay: %ld m.u %d.%d tm.tu %d.%d\n", usec, m, u, tm, tu);
wdenk8bde7f72003-06-27 21:31:46 +0000423#endif
wdenk2262cfe2002-11-18 00:14:45 +0000424 while (1) {
wdenk8bde7f72003-06-27 21:31:46 +0000425
wdenk2262cfe2002-11-18 00:14:45 +0000426 m += read_mmcr_word(SC520_SWTMRMILLI);
427 u = read_mmcr_word(SC520_SWTMRMICRO) + (m * 1000);
wdenk8bde7f72003-06-27 21:31:46 +0000428
wdenk2262cfe2002-11-18 00:14:45 +0000429 if (usec <= u) {
430 break;
431 }
432 }
433}
434
435#endif
436
wdenk7a8e9bed2003-05-31 18:35:21 +0000437int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase)
438{
439 u8 temp=0;
wdenk2262cfe2002-11-18 00:14:45 +0000440
wdenk7a8e9bed2003-05-31 18:35:21 +0000441 if (freq >= 8192) {
wdenk8bde7f72003-06-27 21:31:46 +0000442 temp |= CTL_CLK_SEL_4;
wdenk7a8e9bed2003-05-31 18:35:21 +0000443 } else if (freq >= 4096) {
wdenk8bde7f72003-06-27 21:31:46 +0000444 temp |= CTL_CLK_SEL_8;
wdenk7a8e9bed2003-05-31 18:35:21 +0000445 } else if (freq >= 2048) {
wdenk8bde7f72003-06-27 21:31:46 +0000446 temp |= CTL_CLK_SEL_16;
wdenk7a8e9bed2003-05-31 18:35:21 +0000447 } else if (freq >= 1024) {
wdenk8bde7f72003-06-27 21:31:46 +0000448 temp |= CTL_CLK_SEL_32;
wdenk7a8e9bed2003-05-31 18:35:21 +0000449 } else if (freq >= 512) {
450 temp |= CTL_CLK_SEL_64;
451 } else if (freq >= 256) {
452 temp |= CTL_CLK_SEL_128;
453 } else if (freq >= 128) {
454 temp |= CTL_CLK_SEL_256;
455 } else {
456 temp |= CTL_CLK_SEL_512;
457 }
wdenk8bde7f72003-06-27 21:31:46 +0000458
wdenk7a8e9bed2003-05-31 18:35:21 +0000459 if (!lsb_first) {
460 temp |= MSBF_ENB;
461 }
wdenk8bde7f72003-06-27 21:31:46 +0000462
wdenk7a8e9bed2003-05-31 18:35:21 +0000463 if (inv_clock) {
464 temp |= CLK_INV_ENB;
465 }
wdenk8bde7f72003-06-27 21:31:46 +0000466
wdenk7a8e9bed2003-05-31 18:35:21 +0000467 if (inv_phase) {
468 temp |= PHS_INV_ENB;
469 }
wdenk8bde7f72003-06-27 21:31:46 +0000470
wdenk7a8e9bed2003-05-31 18:35:21 +0000471 write_mmcr_byte(SC520_SSICTL, temp);
wdenk8bde7f72003-06-27 21:31:46 +0000472
wdenk7a8e9bed2003-05-31 18:35:21 +0000473 return 0;
474}
475
wdenk8bde7f72003-06-27 21:31:46 +0000476u8 ssi_txrx_byte(u8 data)
wdenk7a8e9bed2003-05-31 18:35:21 +0000477{
478 write_mmcr_byte(SC520_SSIXMIT, data);
479 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
480 write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMITRCV);
481 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
wdenk8bde7f72003-06-27 21:31:46 +0000482 return read_mmcr_byte(SC520_SSIRCV);
483}
wdenk7a8e9bed2003-05-31 18:35:21 +0000484
485
wdenk8bde7f72003-06-27 21:31:46 +0000486void ssi_tx_byte(u8 data)
wdenk7a8e9bed2003-05-31 18:35:21 +0000487{
488 write_mmcr_byte(SC520_SSIXMIT, data);
wdenk8bde7f72003-06-27 21:31:46 +0000489 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
wdenk7a8e9bed2003-05-31 18:35:21 +0000490 write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_XMIT);
491}
492
wdenk8bde7f72003-06-27 21:31:46 +0000493u8 ssi_rx_byte(void)
wdenk7a8e9bed2003-05-31 18:35:21 +0000494{
495 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
496 write_mmcr_byte(SC520_SSICMD, SSICMD_CMD_SEL_RCV);
497 while ((read_mmcr_byte(SC520_SSISTA)) & SSISTA_BSY);
498 return read_mmcr_byte(SC520_SSIRCV);
wdenk8bde7f72003-06-27 21:31:46 +0000499}
wdenk7a8e9bed2003-05-31 18:35:21 +0000500
501#endif /* CONFIG_SC520 */