Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 1 | /* |
| 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, but independent of implementation */ |
| 25 | |
| 26 | #include <common.h> |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 27 | #include <asm/io.h> |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 28 | #include <asm/ic/ssi.h> |
| 29 | #include <asm/ic/sc520.h> |
| 30 | |
| 31 | int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase) |
| 32 | { |
| 33 | u8 temp=0; |
| 34 | |
| 35 | if (freq >= 8192) { |
| 36 | temp |= CTL_CLK_SEL_4; |
| 37 | } else if (freq >= 4096) { |
| 38 | temp |= CTL_CLK_SEL_8; |
| 39 | } else if (freq >= 2048) { |
| 40 | temp |= CTL_CLK_SEL_16; |
| 41 | } else if (freq >= 1024) { |
| 42 | temp |= CTL_CLK_SEL_32; |
| 43 | } else if (freq >= 512) { |
| 44 | temp |= CTL_CLK_SEL_64; |
| 45 | } else if (freq >= 256) { |
| 46 | temp |= CTL_CLK_SEL_128; |
| 47 | } else if (freq >= 128) { |
| 48 | temp |= CTL_CLK_SEL_256; |
| 49 | } else { |
| 50 | temp |= CTL_CLK_SEL_512; |
| 51 | } |
| 52 | |
| 53 | if (!lsb_first) { |
| 54 | temp |= MSBF_ENB; |
| 55 | } |
| 56 | |
| 57 | if (inv_clock) { |
| 58 | temp |= CLK_INV_ENB; |
| 59 | } |
| 60 | |
| 61 | if (inv_phase) { |
| 62 | temp |= PHS_INV_ENB; |
| 63 | } |
| 64 | |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 65 | writeb(temp, &sc520_mmcr->ssictl); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | u8 ssi_txrx_byte(u8 data) |
| 71 | { |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 72 | writeb(data, &sc520_mmcr->ssixmit); |
| 73 | while (readb(&sc520_mmcr->ssista) & SSISTA_BSY); |
| 74 | writeb(SSICMD_CMD_SEL_XMITRCV, &sc520_mmcr->ssicmd); |
| 75 | while (readb(&sc520_mmcr->ssista) & SSISTA_BSY); |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 76 | |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 77 | return readb(&sc520_mmcr->ssircv); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | void ssi_tx_byte(u8 data) |
| 82 | { |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 83 | writeb(data, &sc520_mmcr->ssixmit); |
| 84 | while (readb(&sc520_mmcr->ssista) & SSISTA_BSY); |
| 85 | writeb(SSICMD_CMD_SEL_XMIT, &sc520_mmcr->ssicmd); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | u8 ssi_rx_byte(void) |
| 89 | { |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 90 | while (readb(&sc520_mmcr->ssista) & SSISTA_BSY); |
| 91 | writeb(SSICMD_CMD_SEL_RCV, &sc520_mmcr->ssicmd); |
| 92 | while (readb(&sc520_mmcr->ssista) & SSISTA_BSY); |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 93 | |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 94 | return readb(&sc520_mmcr->ssircv); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 95 | } |