Use the spibus accessor when applicable.

MFC after:	3 days
This commit is contained in:
manu 2016-12-12 20:04:31 +00:00
parent 7a906cbddf
commit 03c8e93972
6 changed files with 29 additions and 18 deletions

View File

@ -141,12 +141,14 @@ static int
lpc_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct lpc_spi_softc *sc = device_get_softc(dev);
struct spibus_ivar *devi = SPIBUS_IVAR(child);
uint32_t cs;
uint8_t *in_buf, *out_buf;
int i;
spibus_get_cs(child, &cs);
/* Set CS active */
lpc_gpio_set_state(child, devi->cs, 0);
lpc_gpio_set_state(child, cs, 0);
/* Wait for FIFO to be ready */
while ((lpc_spi_read_4(sc, LPC_SSP_SR) & LPC_SSP_SR_TNF) == 0);
@ -168,7 +170,7 @@ lpc_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
}
/* Set CS inactive */
lpc_gpio_set_state(child, devi->cs, 1);
lpc_gpio_set_state(child, cs, 1);
return (0);
}

View File

@ -155,9 +155,8 @@ ar5315_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct ar5315_spi_softc *sc;
uint8_t *buf_in, *buf_out;
struct spibus_ivar *devi = SPIBUS_IVAR(child);
int lin, lout;
uint32_t ctl, cnt, op, rdat;
uint32_t ctl, cnt, op, rdat, cs;
int i, j;
sc = device_get_softc(dev);
@ -165,8 +164,10 @@ ar5315_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
if (sc->sc_debug & 0x8000)
printf("ar5315_spi_transfer: CMD ");
spibus_get_cs(child, &cs);
/* Open SPI controller interface */
ar5315_spi_chip_activate(sc, devi->cs);
ar5315_spi_chip_activate(sc, cs);
do {
ctl = SPI_READ(sc, ARSPI_REG_CTL);
@ -243,7 +244,7 @@ ar5315_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
}
}
ar5315_spi_chip_deactivate(sc, devi->cs);
ar5315_spi_chip_deactivate(sc, cs);
/*
* Close SPI controller interface, restore flash memory mapped access.
*/

View File

@ -204,13 +204,15 @@ static int
ar71xx_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct ar71xx_spi_softc *sc;
uint32_t cs;
uint8_t *buf_in, *buf_out;
struct spibus_ivar *devi = SPIBUS_IVAR(child);
int i;
sc = device_get_softc(dev);
ar71xx_spi_chip_activate(sc, devi->cs);
spibus_get_cs(child, &cs);
ar71xx_spi_chip_activate(sc, cs);
KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz,
("TX/RX command sizes should be equal"));
@ -223,7 +225,7 @@ ar71xx_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
buf_out = (uint8_t *)cmd->tx_cmd;
buf_in = (uint8_t *)cmd->rx_cmd;
for (i = 0; i < cmd->tx_cmd_sz; i++)
buf_in[i] = ar71xx_spi_txrx(sc, devi->cs, buf_out[i]);
buf_in[i] = ar71xx_spi_txrx(sc, cs, buf_out[i]);
/*
* Receive/transmit data (depends on command)
@ -231,9 +233,9 @@ ar71xx_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
buf_out = (uint8_t *)cmd->tx_data;
buf_in = (uint8_t *)cmd->rx_data;
for (i = 0; i < cmd->tx_data_sz; i++)
buf_in[i] = ar71xx_spi_txrx(sc, devi->cs, buf_out[i]);
buf_in[i] = ar71xx_spi_txrx(sc, cs, buf_out[i]);
ar71xx_spi_chip_deactivate(sc, devi->cs);
ar71xx_spi_chip_deactivate(sc, cs);
return (0);
}

View File

@ -224,12 +224,14 @@ mtk_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct mtk_spi_softc *sc;
uint8_t *buf, byte, *tx_buf;
struct spibus_ivar *devi = SPIBUS_IVAR(child);
uint32_t cs;
int i, sz, error = 0, write = 0;
sc = device_get_softc(dev);
if (devi->cs != 0)
spibus_get_cs(child, &cs);
if (cs != 0)
/* Only 1 CS */
return (ENXIO);

View File

@ -229,12 +229,14 @@ mtk_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct mtk_spi_softc *sc;
uint8_t *buf, byte, *tx_buf;
struct spibus_ivar *devi = SPIBUS_IVAR(child);
uint32_t cs;
int i, sz, error, write = 0;
sc = device_get_softc(dev);
if (devi->cs != 0)
spibus_get_cs(child, &cs);
if (cs != 0)
/* Only 1 CS */
return (ENXIO);

View File

@ -218,13 +218,15 @@ static int
rt305x_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct rt305x_spi_softc *sc;
uint32_t cs;
uint8_t *buf, byte, *tx_buf;
struct spibus_ivar *devi = SPIBUS_IVAR(child);
int i, sz, error = 0, write = 0;
sc = device_get_softc(dev);
if (devi->cs != 0)
spibus_get_cs(child, &cs);
if (cs != 0)
/* Only 1 CS */
return (ENXIO);