26 #include <linux/module.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
30 #include <linux/errno.h>
31 #include <linux/wait.h>
52 #define SPI_PPC4XX_MODE_SCP (0x80 >> 3)
55 #define SPI_PPC4XX_MODE_SPE (0x80 >> 4)
62 #define SPI_PPC4XX_MODE_RD (0x80 >> 5)
69 #define SPI_PPC4XX_MODE_CI (0x80 >> 6)
75 #define SPI_PPC4XX_MODE_IL (0x80 >> 7)
79 #define SPI_PPC4XX_CR_STR (0x80 >> 7)
83 #define SPI_PPC4XX_SR_BSY (0x80 >> 6)
85 #define SPI_PPC4XX_SR_RBR (0x80 >> 7)
88 #define SPI_CLK_MODE0 (SPI_PPC4XX_MODE_SCP | 0)
89 #define SPI_CLK_MODE1 (0 | 0)
90 #define SPI_CLK_MODE2 (SPI_PPC4XX_MODE_SCP | SPI_PPC4XX_MODE_CI)
91 #define SPI_CLK_MODE3 (0 | SPI_PPC4XX_MODE_CI)
93 #define DRIVER_NAME "spi_ppc4xx_of"
129 const unsigned char *
tx;
149 dev_dbg(&spi->
dev,
"txrx: tx %p, rx %p, len %d\n",
152 hw = spi_master_get_devdata(spi->
master);
160 data = hw->
tx ? hw->
tx[0] : 0;
193 if (bits_per_word != 8) {
194 dev_err(&spi->
dev,
"invalid bits-per-word (%d)\n",
200 dev_err(&spi->
dev,
"invalid speed_hz (%d)\n", speed);
211 cdm =
min(scr, 0xff);
213 dev_dbg(&spi->
dev,
"setting pre-scaler to %d (hz %d)\n", cdm, speed);
223 spin_unlock(&hw->
bitbang.lock);
228 static int spi_ppc4xx_setup(
struct spi_device *spi)
233 dev_err(&spi->
dev,
"invalid bits-per-word (%d)\n",
239 dev_err(&spi->
dev,
"invalid max_speed_hz (must be non-zero)\n");
321 dev_dbg(hw->
dev,
"got interrupt but spi still busy?\n");
325 }
while (++cnt < 100 && lstatus & SPI_PPC4XX_SR_BSY);
328 dev_err(hw->
dev,
"busywait: too many loops!\n");
334 dev_dbg(hw->
dev,
"loops %d status %x\n", cnt, status);
348 if (count < hw->
len) {
359 static void spi_ppc4xx_cleanup(
struct spi_device *spi)
364 static void spi_ppc4xx_enable(
struct ppc4xx_spi *hw)
373 dcri_clrset(SDR0,
SDR0_PFC1, 0x80000000 >> 14, 0);
378 if (hw->
master->num_chipselect) {
380 for (i = 0; i < hw->
master->num_chipselect; i++)
381 if (gpio_is_valid(hw->
gpios[i]))
403 const unsigned int *
clk;
408 master->
dev.of_node = np;
410 hw = spi_master_get_devdata(master);
411 hw->
master = spi_master_get(master);
414 init_completion(&hw->
done);
421 num_gpios = of_gpio_count(np);
431 for (i = 0; i < num_gpios; i++) {
435 gpio = of_get_gpio_flags(np, i, &flags);
438 if (gpio_is_valid(gpio)) {
442 dev_err(dev,
"can't request gpio "
443 "#%d: %d\n", i, ret);
449 }
else if (gpio == -
EEXIST) {
452 dev_err(dev,
"invalid gpio #%d: %d\n", i, gpio);
466 bbp->
master->setup = spi_ppc4xx_setup;
467 bbp->
master->cleanup = spi_ppc4xx_cleanup;
474 bbp->
master->num_chipselect = num_gpios;
479 dev_err(dev,
"OPB: cannot find node\n");
486 dev_err(dev,
"OPB: no clock-frequency property set\n");
497 dev_err(dev,
"error while parsing device node resource\n");
505 dev_err(dev,
"too small to map registers\n");
513 0,
"spi_ppc4xx_of", (
void *)hw);
515 dev_err(dev,
"unable to allocate interrupt\n");
520 dev_err(dev,
"resource unavailable\n");
522 goto request_mem_error;
528 dev_err(dev,
"unable to memory map registers\n");
533 spi_ppc4xx_enable(hw);
539 dev_err(dev,
"failed to register SPI master\n");
543 dev_info(dev,
"driver initialized\n");
557 spi_master_put(master);
559 dev_err(dev,
"initialization failed\n");
566 struct ppc4xx_spi *hw = spi_master_get_devdata(master);
577 static const struct of_device_id spi_ppc4xx_of_match[] = {
578 { .compatible =
"ibm,ppc4xx-spi", },
585 .probe = spi_ppc4xx_of_probe,
586 .remove =
__exit_p(spi_ppc4xx_of_remove),
590 .of_match_table = spi_ppc4xx_of_match,