blob: cc601e56e48328e8998c3e47b4beb229f7779a39 [file] [log] [blame]
Graeme Russ85cc39f2009-02-24 21:14:32 +11001/*
2 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02003 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
Graeme Russ85cc39f2009-02-24 21:14:32 +11004 *
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
Graeme Russ85cc39f2009-02-24 21:14:32 +110024#include <common.h>
Graeme Russ0c5ced72010-04-24 00:05:37 +100025#include <asm/io.h>
Graeme Russ0d992d02011-08-04 22:05:09 +100026#include <asm/arch/ssi.h>
27#include <asm/arch/sc520.h>
Graeme Russ85cc39f2009-02-24 21:14:32 +110028
29int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase)
30{
Graeme Russ55bed242011-11-08 02:33:14 +000031 u8 temp = 0;
Graeme Russ85cc39f2009-02-24 21:14:32 +110032
Graeme Russ55bed242011-11-08 02:33:14 +000033 if (freq >= 8192)
Graeme Russ85cc39f2009-02-24 21:14:32 +110034 temp |= CTL_CLK_SEL_4;
Graeme Russ55bed242011-11-08 02:33:14 +000035 else if (freq >= 4096)
Graeme Russ85cc39f2009-02-24 21:14:32 +110036 temp |= CTL_CLK_SEL_8;
Graeme Russ55bed242011-11-08 02:33:14 +000037 else if (freq >= 2048)
Graeme Russ85cc39f2009-02-24 21:14:32 +110038 temp |= CTL_CLK_SEL_16;
Graeme Russ55bed242011-11-08 02:33:14 +000039 else if (freq >= 1024)
Graeme Russ85cc39f2009-02-24 21:14:32 +110040 temp |= CTL_CLK_SEL_32;
Graeme Russ55bed242011-11-08 02:33:14 +000041 else if (freq >= 512)
Graeme Russ85cc39f2009-02-24 21:14:32 +110042 temp |= CTL_CLK_SEL_64;
Graeme Russ55bed242011-11-08 02:33:14 +000043 else if (freq >= 256)
Graeme Russ85cc39f2009-02-24 21:14:32 +110044 temp |= CTL_CLK_SEL_128;
Graeme Russ55bed242011-11-08 02:33:14 +000045 else if (freq >= 128)
Graeme Russ85cc39f2009-02-24 21:14:32 +110046 temp |= CTL_CLK_SEL_256;
Graeme Russ55bed242011-11-08 02:33:14 +000047 else
Graeme Russ85cc39f2009-02-24 21:14:32 +110048 temp |= CTL_CLK_SEL_512;
Graeme Russ85cc39f2009-02-24 21:14:32 +110049
Graeme Russ55bed242011-11-08 02:33:14 +000050 if (!lsb_first)
Graeme Russ85cc39f2009-02-24 21:14:32 +110051 temp |= MSBF_ENB;
Graeme Russ85cc39f2009-02-24 21:14:32 +110052
Graeme Russ55bed242011-11-08 02:33:14 +000053 if (inv_clock)
Graeme Russ85cc39f2009-02-24 21:14:32 +110054 temp |= CLK_INV_ENB;
Graeme Russ85cc39f2009-02-24 21:14:32 +110055
Graeme Russ55bed242011-11-08 02:33:14 +000056 if (inv_phase)
Graeme Russ85cc39f2009-02-24 21:14:32 +110057 temp |= PHS_INV_ENB;
Graeme Russ85cc39f2009-02-24 21:14:32 +110058
Graeme Russ0c5ced72010-04-24 00:05:37 +100059 writeb(temp, &sc520_mmcr->ssictl);
Graeme Russ85cc39f2009-02-24 21:14:32 +110060
61 return 0;
62}
63
64u8 ssi_txrx_byte(u8 data)
65{
Graeme Russ0c5ced72010-04-24 00:05:37 +100066 writeb(data, &sc520_mmcr->ssixmit);
Graeme Russ55bed242011-11-08 02:33:14 +000067 while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
68 ;
Graeme Russ0c5ced72010-04-24 00:05:37 +100069 writeb(SSICMD_CMD_SEL_XMITRCV, &sc520_mmcr->ssicmd);
Graeme Russ55bed242011-11-08 02:33:14 +000070 while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
71 ;
Graeme Russ1d977dc2009-08-23 12:59:56 +100072
Graeme Russ0c5ced72010-04-24 00:05:37 +100073 return readb(&sc520_mmcr->ssircv);
Graeme Russ85cc39f2009-02-24 21:14:32 +110074}
75
Graeme Russ85cc39f2009-02-24 21:14:32 +110076void ssi_tx_byte(u8 data)
77{
Graeme Russ0c5ced72010-04-24 00:05:37 +100078 writeb(data, &sc520_mmcr->ssixmit);
Graeme Russ55bed242011-11-08 02:33:14 +000079 while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
80 ;
Graeme Russ0c5ced72010-04-24 00:05:37 +100081 writeb(SSICMD_CMD_SEL_XMIT, &sc520_mmcr->ssicmd);
Graeme Russ85cc39f2009-02-24 21:14:32 +110082}
83
84u8 ssi_rx_byte(void)
85{
Graeme Russ55bed242011-11-08 02:33:14 +000086 while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
87 ;
Graeme Russ0c5ced72010-04-24 00:05:37 +100088 writeb(SSICMD_CMD_SEL_RCV, &sc520_mmcr->ssicmd);
Graeme Russ55bed242011-11-08 02:33:14 +000089 while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
90 ;
Graeme Russ1d977dc2009-08-23 12:59:56 +100091
Graeme Russ0c5ced72010-04-24 00:05:37 +100092 return readb(&sc520_mmcr->ssircv);
Graeme Russ85cc39f2009-02-24 21:14:32 +110093}