Lines Matching +full:enable +full:- +full:cdm +full:- +full:check

1 // SPDX-License-Identifier: GPL-2.0-only
41 #include <asm/dcr-regs.h>
43 /* bits in mode register - bit 0 is MSb */
56 * SPI_PPC4XX_MODE_RD = 0 means "MSB first" - this is the normal mode
57 * SPI_PPC4XX_MODE_RD = 1 means "LSB first" - this is bit-reversed mode
71 * SPI_PPC4XX_MODE_IL = 1 means "loopback enable"
103 * SCPClkOut = OPBCLK/(4(CDM + 1))
105 * CDM = (OPBCLK/4*SCPClkOut) - 1
108 u8 cdm; member
145 dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n", in spi_ppc4xx_txrx()
146 t->tx_buf, t->rx_buf, t->len); in spi_ppc4xx_txrx()
148 hw = spi_controller_get_devdata(spi->controller); in spi_ppc4xx_txrx()
150 hw->tx = t->tx_buf; in spi_ppc4xx_txrx()
151 hw->rx = t->rx_buf; in spi_ppc4xx_txrx()
152 hw->len = t->len; in spi_ppc4xx_txrx()
153 hw->count = 0; in spi_ppc4xx_txrx()
156 data = hw->tx ? hw->tx[0] : 0; in spi_ppc4xx_txrx()
157 out_8(&hw->regs->txd, data); in spi_ppc4xx_txrx()
158 out_8(&hw->regs->cr, SPI_PPC4XX_CR_STR); in spi_ppc4xx_txrx()
159 wait_for_completion(&hw->done); in spi_ppc4xx_txrx()
161 return hw->count; in spi_ppc4xx_txrx()
166 struct ppc4xx_spi *hw = spi_controller_get_devdata(spi->controller); in spi_ppc4xx_setupxfer()
167 struct spi_ppc4xx_cs *cs = spi->controller_state; in spi_ppc4xx_setupxfer()
169 u8 cdm = 0; in spi_ppc4xx_setupxfer() local
173 speed = spi->max_speed_hz; in spi_ppc4xx_setupxfer()
180 if (t->speed_hz) in spi_ppc4xx_setupxfer()
181 speed = min(t->speed_hz, spi->max_speed_hz); in spi_ppc4xx_setupxfer()
184 if (!speed || (speed > spi->max_speed_hz)) { in spi_ppc4xx_setupxfer()
185 dev_err(&spi->dev, "invalid speed_hz (%d)\n", speed); in spi_ppc4xx_setupxfer()
186 return -EINVAL; in spi_ppc4xx_setupxfer()
190 out_8(&hw->regs->mode, cs->mode); in spi_ppc4xx_setupxfer()
194 scr = (hw->opb_freq / speed) - 1; in spi_ppc4xx_setupxfer()
196 cdm = min(scr, 0xff); in spi_ppc4xx_setupxfer()
198 dev_dbg(&spi->dev, "setting pre-scaler to %d (hz %d)\n", cdm, speed); in spi_ppc4xx_setupxfer()
200 if (in_8(&hw->regs->cdm) != cdm) in spi_ppc4xx_setupxfer()
201 out_8(&hw->regs->cdm, cdm); in spi_ppc4xx_setupxfer()
203 mutex_lock(&hw->bitbang.lock); in spi_ppc4xx_setupxfer()
204 if (!hw->bitbang.busy) { in spi_ppc4xx_setupxfer()
205 hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE); in spi_ppc4xx_setupxfer()
208 mutex_unlock(&hw->bitbang.lock); in spi_ppc4xx_setupxfer()
215 struct spi_ppc4xx_cs *cs = spi->controller_state; in spi_ppc4xx_setup()
217 if (!spi->max_speed_hz) { in spi_ppc4xx_setup()
218 dev_err(&spi->dev, "invalid max_speed_hz (must be non-zero)\n"); in spi_ppc4xx_setup()
219 return -EINVAL; in spi_ppc4xx_setup()
225 return -ENOMEM; in spi_ppc4xx_setup()
226 spi->controller_state = cs; in spi_ppc4xx_setup()
231 * no need to read-modify-write in spi_ppc4xx_setup()
233 cs->mode = SPI_PPC4XX_MODE_SPE; in spi_ppc4xx_setup()
235 switch (spi->mode & SPI_MODE_X_MASK) { in spi_ppc4xx_setup()
237 cs->mode |= SPI_CLK_MODE0; in spi_ppc4xx_setup()
240 cs->mode |= SPI_CLK_MODE1; in spi_ppc4xx_setup()
243 cs->mode |= SPI_CLK_MODE2; in spi_ppc4xx_setup()
246 cs->mode |= SPI_CLK_MODE3; in spi_ppc4xx_setup()
250 if (spi->mode & SPI_LSB_FIRST) in spi_ppc4xx_setup()
251 cs->mode |= SPI_PPC4XX_MODE_RD; in spi_ppc4xx_setup()
265 status = in_8(&hw->regs->sr); in spi_ppc4xx_int()
270 * BSY de-asserts one cycle after the transfer is complete. The in spi_ppc4xx_int()
279 dev_dbg(hw->dev, "got interrupt but spi still busy?\n"); in spi_ppc4xx_int()
282 lstatus = in_8(&hw->regs->sr); in spi_ppc4xx_int()
286 dev_err(hw->dev, "busywait: too many loops!\n"); in spi_ppc4xx_int()
287 complete(&hw->done); in spi_ppc4xx_int()
291 status = in_8(&hw->regs->sr); in spi_ppc4xx_int()
292 dev_dbg(hw->dev, "loops %d status %x\n", cnt, status); in spi_ppc4xx_int()
296 count = hw->count; in spi_ppc4xx_int()
297 hw->count++; in spi_ppc4xx_int()
300 data = in_8(&hw->regs->rxd); in spi_ppc4xx_int()
301 if (hw->rx) in spi_ppc4xx_int()
302 hw->rx[count] = data; in spi_ppc4xx_int()
306 if (count < hw->len) { in spi_ppc4xx_int()
307 data = hw->tx ? hw->tx[count] : 0; in spi_ppc4xx_int()
308 out_8(&hw->regs->txd, data); in spi_ppc4xx_int()
309 out_8(&hw->regs->cr, SPI_PPC4XX_CR_STR); in spi_ppc4xx_int()
311 complete(&hw->done); in spi_ppc4xx_int()
319 kfree(spi->controller_state); in spi_ppc4xx_cleanup()
326 * the 2nd I2C bus. We need to enable the SPI bus before in spi_ppc4xx_enable()
330 /* need to clear bit 14 to enable SPC */ in spi_ppc4xx_enable()
343 struct device_node *np = op->dev.of_node; in spi_ppc4xx_of_probe()
344 struct device *dev = &op->dev; in spi_ppc4xx_of_probe()
351 return -ENOMEM; in spi_ppc4xx_of_probe()
352 host->dev.of_node = np; in spi_ppc4xx_of_probe()
355 hw->host = host; in spi_ppc4xx_of_probe()
356 hw->dev = dev; in spi_ppc4xx_of_probe()
358 init_completion(&hw->done); in spi_ppc4xx_of_probe()
361 bbp = &hw->bitbang; in spi_ppc4xx_of_probe()
362 bbp->master = hw->host; in spi_ppc4xx_of_probe()
363 bbp->setup_transfer = spi_ppc4xx_setupxfer; in spi_ppc4xx_of_probe()
364 bbp->txrx_bufs = spi_ppc4xx_txrx; in spi_ppc4xx_of_probe()
365 bbp->use_dma = 0; in spi_ppc4xx_of_probe()
366 bbp->master->setup = spi_ppc4xx_setup; in spi_ppc4xx_of_probe()
367 bbp->master->cleanup = spi_ppc4xx_cleanup; in spi_ppc4xx_of_probe()
368 bbp->master->bits_per_word_mask = SPI_BPW_MASK(8); in spi_ppc4xx_of_probe()
369 bbp->master->use_gpio_descriptors = true; in spi_ppc4xx_of_probe()
374 bbp->master->num_chipselect = 0; in spi_ppc4xx_of_probe()
376 /* the spi->mode bits understood by this driver: */ in spi_ppc4xx_of_probe()
377 bbp->master->mode_bits = in spi_ppc4xx_of_probe()
384 ret = -ENODEV; in spi_ppc4xx_of_probe()
388 clk = of_get_property(opbnp, "clock-frequency", NULL); in spi_ppc4xx_of_probe()
390 dev_err(dev, "OPB: no clock-frequency property set\n"); in spi_ppc4xx_of_probe()
392 ret = -ENODEV; in spi_ppc4xx_of_probe()
395 hw->opb_freq = *clk; in spi_ppc4xx_of_probe()
396 hw->opb_freq >>= 2; in spi_ppc4xx_of_probe()
404 hw->mapbase = resource.start; in spi_ppc4xx_of_probe()
405 hw->mapsize = resource_size(&resource); in spi_ppc4xx_of_probe()
407 /* Sanity check */ in spi_ppc4xx_of_probe()
408 if (hw->mapsize < sizeof(struct spi_ppc4xx_regs)) { in spi_ppc4xx_of_probe()
410 ret = -EINVAL; in spi_ppc4xx_of_probe()
415 hw->irqnum = irq_of_parse_and_map(np, 0); in spi_ppc4xx_of_probe()
416 ret = request_irq(hw->irqnum, spi_ppc4xx_int, in spi_ppc4xx_of_probe()
423 if (!request_mem_region(hw->mapbase, hw->mapsize, DRIVER_NAME)) { in spi_ppc4xx_of_probe()
425 ret = -EBUSY; in spi_ppc4xx_of_probe()
429 hw->regs = ioremap(hw->mapbase, sizeof(struct spi_ppc4xx_regs)); in spi_ppc4xx_of_probe()
431 if (!hw->regs) { in spi_ppc4xx_of_probe()
433 ret = -ENXIO; in spi_ppc4xx_of_probe()
440 dev->dma_mask = 0; in spi_ppc4xx_of_probe()
452 iounmap(hw->regs); in spi_ppc4xx_of_probe()
454 release_mem_region(hw->mapbase, hw->mapsize); in spi_ppc4xx_of_probe()
456 free_irq(hw->irqnum, hw); in spi_ppc4xx_of_probe()
469 spi_bitbang_stop(&hw->bitbang); in spi_ppc4xx_of_remove()
470 release_mem_region(hw->mapbase, hw->mapsize); in spi_ppc4xx_of_remove()
471 free_irq(hw->irqnum, hw); in spi_ppc4xx_of_remove()
472 iounmap(hw->regs); in spi_ppc4xx_of_remove()
477 { .compatible = "ibm,ppc4xx-spi", },