- jeprintk(jme->pdev, "phy(%d) write timeout : %d\n", phy, reg);
-
- return;
-}
-
-static void
-jme_spi_start(struct pci_dev *pdev, struct jme_spi_op *spiop)
-{
- spiop->sr |= SPI_EN;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
- ndelay(spiop->halfclk << 2);
- if (spiop->mode & SPI_MODE_CPOL) {
- spiop->sr |= SPI_SCLK;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
- ndelay(spiop->halfclk << 2);
- }
- spiop->sr &= ~SPI_CS;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
- ndelay(spiop->halfclk);
-}
-
-static void
-jme_spi_write(struct pci_dev *pdev, struct jme_spi_op *spiop, u8 byte)
-{
- int bit;
-
- for (bit = 0 ; bit < 8 ; ++bit) {
- if (byte & 0x80)
- spiop->sr |= SPI_MOSI;
- else
- spiop->sr &= ~SPI_MOSI;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
-
- byte <<= 1;
- ndelay(spiop->halfclk);
- spiop->sr ^= SPI_SCLK;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
-
- ndelay(spiop->halfclk);
- spiop->sr ^= SPI_SCLK;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
- }
-}
-
-static void
-jme_spi_read(struct pci_dev *pdev, struct jme_spi_op *spiop, u8 *byte)
-{
- int bit;
- u8 b;
-
- spiop->sr &= ~SPI_MOSI;
- for (bit = 0 ; bit < 8 ; ++bit) {
- *byte <<= 1;
- ndelay(spiop->halfclk);
- spiop->sr ^= SPI_SCLK;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
-
- ndelay(spiop->halfclk);
- pci_read_config_byte(pdev, PCI_SPI, &b);
- *byte |= !!(b & SPI_MISO);
- spiop->sr ^= SPI_SCLK;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
- }
-}
-
-static void
-jme_spi_stop(struct pci_dev *pdev, struct jme_spi_op *spiop)
-{
- spiop->sr &= ~SPI_EN;
- spiop->sr |= SPI_CS;
- pci_write_config_byte(pdev, PCI_SPI, spiop->sr);
-}
-
-/**
- * jme_spi_io - SPI Access helper function.
- * @jme: Adapter informations
- * @spiop: SPI operation.
- *
- * We have a SPI SW Access register in PCI configuration space,
- * which directly connect to flash controller with SPI interface.
- * This function is used to communicate with it in SPI protocol.
- */
-static int
-jme_spi_op(struct jme_adapter *jme, struct jme_spi_op *spiop)
-{
- int i;
-
- /*
- * Only support 8 bits for now
- */
- if (spiop->bitn != 8)
- return -EINVAL;
-
- /*
- * Only support half-duplex for now
- */
- if (spiop->mode & SPI_MODE_DUP)
- return -EINVAL;
-
- spiop->halfclk = HALF_US / spiop->spd;
- spiop->sr = SPI_CS;
- jme_spi_start(jme->pdev, spiop);
-
- for (i = 0 ; i < spiop->wn ; ++i)
- jme_spi_write(jme->pdev, spiop, spiop->kwbuf[i]);
-
- for (i = 0 ; i < spiop->rn ; ++i)
- jme_spi_read(jme->pdev, spiop, spiop->krbuf + i);
-
- jme_spi_stop(jme->pdev, spiop);
-
- return 0;