FreeCalypso > hg > freecalypso-tools
view target-utils/libbase/spidrv.c @ 497:74610c4f10f7
target-utils: added 10 ms delay at the end of abb_power_off()
The deosmification of the ABB access code (replacement of osmo_delay_ms()
bogus delays with correctly-timed ones, which are significantly shorter)
had one annoying side effect: when executing the poweroff command from
any of the programs, one last '=' prompt character was being sent (and
received by the x86 host) as the Calypso board powers off. With delays
being shorter now, the abb_power_off() function was returning and the
standalone program's main loop was printing its prompt before the Iota chip
fully executed the switch-off sequence!
I thought about inserting an endless tight loop at the end of the
abb_power_off() function, but the implemented solution of a 10 ms delay
is a little nicer IMO because if the DEVOFF operation doesn't happen for
some reason in a manual hacking scenario, there won't be an artificial
blocker in the form of a tight loop keeping us from further poking around.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 25 May 2019 20:44:05 +0000 |
parents | 3d73d4d3527f |
children |
line wrap: on
line source
/* Driver for SPI Master Controller inside TI Calypso */ /* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */ /* (C) 2010 by Harald Welte <laforge@gnumonks.org> * * All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #include "types.h" #define ASIC_CONF_REG (*(volatile u16 *) 0xFFFEF008) struct spi_regs { u16 reg_set1; u16 reg_set2; u16 reg_ctrl; u16 reg_status; u16 reg_tx_lsb; u16 reg_tx_msb; u16 reg_rx_lsb; u16 reg_rx_msb; }; #define SPI_REGS (*(volatile struct spi_regs *) 0xFFFE3000) #define BASE_ADDR_SPI 0xfffe3000 #define SPI_REG(n) (BASE_ADDR_SPI+(n)) #define SPI_SET1_EN_CLK (1 << 0) #define SPI_SET1_WR_IRQ_DIS (1 << 4) #define SPI_SET1_RDWR_IRQ_DIS (1 << 5) #define SPI_CTRL_RDWR (1 << 0) #define SPI_CTRL_WR (1 << 1) #define SPI_CTRL_NB_SHIFT 2 #define SPI_CTRL_AD_SHIFT 7 #define SPI_STATUS_RE (1 << 0) /* Read End */ #define SPI_STATUS_WE (1 << 1) /* Write End */ spi_init() { static int initdone; if (initdone) return(0); ASIC_CONF_REG |= 0x6000; SPI_REGS.reg_set1 = SPI_SET1_EN_CLK | SPI_SET1_WR_IRQ_DIS | SPI_SET1_RDWR_IRQ_DIS; SPI_REGS.reg_set2 = 0x0001; initdone = 1; return(1); } spi_xfer(dev_idx, bitlen, dout, din) void *dout, *din; { int bytes_per_xfer; u16 reg_status, reg_ctrl = 0; u32 tmp; if (bitlen <= 0) return 0; if (bitlen > 32) return -1; if (dev_idx > 4) return -1; bytes_per_xfer = bitlen / 8; if (bitlen % 8) bytes_per_xfer ++; reg_ctrl |= (bitlen - 1) << SPI_CTRL_NB_SHIFT; reg_ctrl |= (dev_idx & 0x7) << SPI_CTRL_AD_SHIFT; if (bitlen <= 8) { tmp = *(u8 *)dout; tmp <<= 24 + (8-bitlen); /* align to MSB */ } else if (bitlen <= 16) { tmp = *(u16 *)dout; tmp <<= 16 + (16-bitlen); /* align to MSB */ } else { tmp = *(u32 *)dout; tmp <<= (32-bitlen); /* align to MSB */ } /* fill transmit registers */ SPI_REGS.reg_tx_msb = tmp >> 16; SPI_REGS.reg_tx_lsb = tmp; /* initiate transfer */ if (din) reg_ctrl |= SPI_CTRL_RDWR; else reg_ctrl |= SPI_CTRL_WR; SPI_REGS.reg_ctrl = reg_ctrl; /* wait until the transfer is complete */ while (1) { reg_status = SPI_REGS.reg_status; if (din && (reg_status & SPI_STATUS_RE)) break; else if (reg_status & SPI_STATUS_WE) break; } /* delay of seven 13MHz cycles */ wait_ARM_cycles(7); if (din) { tmp = SPI_REGS.reg_rx_msb << 16; tmp |= SPI_REGS.reg_rx_lsb; if (bitlen <= 8) *(u8 *)din = tmp & 0xff; else if (bitlen <= 16) *(u16 *)din = tmp & 0xffff; else *(u32 *)din = tmp; } return 0; }