FreeCalypso > hg > freecalypso-sw
annotate target-utils/libcommon/spidrv.c @ 463:aad742029813
doc/Compiling: everything except gsm-fw
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 24 Jun 2014 00:16:04 +0000 |
parents | e60aecf23970 |
children |
rev | line source |
---|---|
389
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* Driver for SPI Master Controller inside TI Calypso */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 /* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 * All Rights Reserved |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 * (at your option) any later version. |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 * GNU General Public License for more details. |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 * with this program; if not, write to the Free Software Foundation, Inc., |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 * |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 #include "types.h" |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 #define ASIC_CONF_REG (*(volatile u16 *) 0xFFFEF008) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 struct spi_regs { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 u16 reg_set1; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 u16 reg_set2; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 u16 reg_ctrl; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 u16 reg_status; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 u16 reg_tx_lsb; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 u16 reg_tx_msb; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 u16 reg_rx_lsb; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 u16 reg_rx_msb; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 }; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 #define SPI_REGS (*(volatile struct spi_regs *) 0xFFFE3000) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 #define BASE_ADDR_SPI 0xfffe3000 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 #define SPI_REG(n) (BASE_ADDR_SPI+(n)) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 #define SPI_SET1_EN_CLK (1 << 0) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 #define SPI_SET1_WR_IRQ_DIS (1 << 4) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 #define SPI_SET1_RDWR_IRQ_DIS (1 << 5) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 #define SPI_CTRL_RDWR (1 << 0) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 #define SPI_CTRL_WR (1 << 1) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 #define SPI_CTRL_NB_SHIFT 2 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 #define SPI_CTRL_AD_SHIFT 7 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 #define SPI_STATUS_RE (1 << 0) /* Read End */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 #define SPI_STATUS_WE (1 << 1) /* Write End */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 spi_init() |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 static int initdone; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 if (initdone) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 return(0); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 ASIC_CONF_REG |= 0x6000; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 SPI_REGS.reg_set1 = SPI_SET1_EN_CLK | SPI_SET1_WR_IRQ_DIS | |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 SPI_SET1_RDWR_IRQ_DIS; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 SPI_REGS.reg_set2 = 0x0001; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 initdone = 1; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 return(1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 spi_xfer(dev_idx, bitlen, dout, din) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 void *dout, *din; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 int bytes_per_xfer; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 u16 reg_status, reg_ctrl = 0; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 u32 tmp; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 if (bitlen <= 0) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 return 0; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 if (bitlen > 32) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 return -1; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 if (dev_idx > 4) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 return -1; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 bytes_per_xfer = bitlen / 8; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 if (bitlen % 8) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 bytes_per_xfer ++; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 reg_ctrl |= (bitlen - 1) << SPI_CTRL_NB_SHIFT; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 reg_ctrl |= (dev_idx & 0x7) << SPI_CTRL_AD_SHIFT; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 if (bitlen <= 8) { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
94 tmp = *(u8 *)dout; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
95 tmp <<= 24 + (8-bitlen); /* align to MSB */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
96 } else if (bitlen <= 16) { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
97 tmp = *(u16 *)dout; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
98 tmp <<= 16 + (16-bitlen); /* align to MSB */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
99 } else { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
100 tmp = *(u32 *)dout; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
101 tmp <<= (32-bitlen); /* align to MSB */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
102 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
103 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
104 /* fill transmit registers */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
105 SPI_REGS.reg_tx_msb = tmp >> 16; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
106 SPI_REGS.reg_tx_lsb = tmp; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
107 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
108 /* initiate transfer */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
109 if (din) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
110 reg_ctrl |= SPI_CTRL_RDWR; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
111 else |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
112 reg_ctrl |= SPI_CTRL_WR; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
113 SPI_REGS.reg_ctrl = reg_ctrl; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
114 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
115 /* wait until the transfer is complete */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
116 while (1) { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
117 reg_status = SPI_REGS.reg_status; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
118 if (din && (reg_status & SPI_STATUS_RE)) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
119 break; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
120 else if (reg_status & SPI_STATUS_WE) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
121 break; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
122 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
123 /* FIXME: calibrate how much delay we really need (seven 13MHz cycles) */ |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
124 osmo_delay_ms(1); |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
125 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
126 if (din) { |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
127 tmp = SPI_REGS.reg_rx_msb << 16; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
128 tmp |= SPI_REGS.reg_rx_lsb; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
129 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
130 if (bitlen <= 8) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
131 *(u8 *)din = tmp & 0xff; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
132 else if (bitlen <= 16) |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
133 *(u16 *)din = tmp & 0xffff; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
134 else |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
135 *(u32 *)din = tmp; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
136 } |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
137 |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
138 return 0; |
e60aecf23970
target-utils: ABB operations implemented (ported from OsmocomBB),
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
139 } |