• Home
  • Raw
  • Download

Lines Matching +full:cs +full:- +full:gpios

44 #include <asm/dcr-regs.h>
46 /* bits in mode register - bit 0 is MSb */
59 * SPI_PPC4XX_MODE_RD = 0 means "MSB first" - this is the normal mode
60 * SPI_PPC4XX_MODE_RD = 1 means "LSB first" - this is bit-reversed mode
108 * CDM = (OPBCLK/4*SCPClkOut) - 1
133 int *gpios; member
150 dev_dbg(&spi->dev, "txrx: tx %p, rx %p, len %d\n", in spi_ppc4xx_txrx()
151 t->tx_buf, t->rx_buf, t->len); in spi_ppc4xx_txrx()
153 hw = spi_master_get_devdata(spi->master); in spi_ppc4xx_txrx()
155 hw->tx = t->tx_buf; in spi_ppc4xx_txrx()
156 hw->rx = t->rx_buf; in spi_ppc4xx_txrx()
157 hw->len = t->len; in spi_ppc4xx_txrx()
158 hw->count = 0; in spi_ppc4xx_txrx()
161 data = hw->tx ? hw->tx[0] : 0; in spi_ppc4xx_txrx()
162 out_8(&hw->regs->txd, data); in spi_ppc4xx_txrx()
163 out_8(&hw->regs->cr, SPI_PPC4XX_CR_STR); in spi_ppc4xx_txrx()
164 wait_for_completion(&hw->done); in spi_ppc4xx_txrx()
166 return hw->count; in spi_ppc4xx_txrx()
171 struct ppc4xx_spi *hw = spi_master_get_devdata(spi->master); in spi_ppc4xx_setupxfer()
172 struct spi_ppc4xx_cs *cs = spi->controller_state; in spi_ppc4xx_setupxfer() local
179 bits_per_word = spi->bits_per_word; in spi_ppc4xx_setupxfer()
180 speed = spi->max_speed_hz; in spi_ppc4xx_setupxfer()
187 if (t->bits_per_word) in spi_ppc4xx_setupxfer()
188 bits_per_word = t->bits_per_word; in spi_ppc4xx_setupxfer()
190 if (t->speed_hz) in spi_ppc4xx_setupxfer()
191 speed = min(t->speed_hz, spi->max_speed_hz); in spi_ppc4xx_setupxfer()
194 if (!speed || (speed > spi->max_speed_hz)) { in spi_ppc4xx_setupxfer()
195 dev_err(&spi->dev, "invalid speed_hz (%d)\n", speed); in spi_ppc4xx_setupxfer()
196 return -EINVAL; in spi_ppc4xx_setupxfer()
200 out_8(&hw->regs->mode, cs->mode); in spi_ppc4xx_setupxfer()
204 scr = (hw->opb_freq / speed) - 1; in spi_ppc4xx_setupxfer()
208 dev_dbg(&spi->dev, "setting pre-scaler to %d (hz %d)\n", cdm, speed); in spi_ppc4xx_setupxfer()
210 if (in_8(&hw->regs->cdm) != cdm) in spi_ppc4xx_setupxfer()
211 out_8(&hw->regs->cdm, cdm); in spi_ppc4xx_setupxfer()
213 mutex_lock(&hw->bitbang.lock); in spi_ppc4xx_setupxfer()
214 if (!hw->bitbang.busy) { in spi_ppc4xx_setupxfer()
215 hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE); in spi_ppc4xx_setupxfer()
218 mutex_unlock(&hw->bitbang.lock); in spi_ppc4xx_setupxfer()
225 struct spi_ppc4xx_cs *cs = spi->controller_state; in spi_ppc4xx_setup() local
227 if (!spi->max_speed_hz) { in spi_ppc4xx_setup()
228 dev_err(&spi->dev, "invalid max_speed_hz (must be non-zero)\n"); in spi_ppc4xx_setup()
229 return -EINVAL; in spi_ppc4xx_setup()
232 if (cs == NULL) { in spi_ppc4xx_setup()
233 cs = kzalloc(sizeof *cs, GFP_KERNEL); in spi_ppc4xx_setup()
234 if (!cs) in spi_ppc4xx_setup()
235 return -ENOMEM; in spi_ppc4xx_setup()
236 spi->controller_state = cs; in spi_ppc4xx_setup()
241 * no need to read-modify-write in spi_ppc4xx_setup()
243 cs->mode = SPI_PPC4XX_MODE_SPE; in spi_ppc4xx_setup()
245 switch (spi->mode & (SPI_CPHA | SPI_CPOL)) { in spi_ppc4xx_setup()
247 cs->mode |= SPI_CLK_MODE0; in spi_ppc4xx_setup()
250 cs->mode |= SPI_CLK_MODE1; in spi_ppc4xx_setup()
253 cs->mode |= SPI_CLK_MODE2; in spi_ppc4xx_setup()
256 cs->mode |= SPI_CLK_MODE3; in spi_ppc4xx_setup()
260 if (spi->mode & SPI_LSB_FIRST) in spi_ppc4xx_setup()
261 cs->mode |= SPI_PPC4XX_MODE_RD; in spi_ppc4xx_setup()
268 struct ppc4xx_spi *hw = spi_master_get_devdata(spi->master); in spi_ppc4xx_chipsel()
269 unsigned int cs = spi->chip_select; in spi_ppc4xx_chipsel() local
274 * case of a non-existent (dummy) chip select, do nothing. in spi_ppc4xx_chipsel()
277 if (!hw->master->num_chipselect || hw->gpios[cs] == -EEXIST) in spi_ppc4xx_chipsel()
280 cspol = spi->mode & SPI_CS_HIGH ? 1 : 0; in spi_ppc4xx_chipsel()
284 gpio_set_value(hw->gpios[cs], cspol); in spi_ppc4xx_chipsel()
296 status = in_8(&hw->regs->sr); in spi_ppc4xx_int()
301 * BSY de-asserts one cycle after the transfer is complete. The in spi_ppc4xx_int()
310 dev_dbg(hw->dev, "got interrupt but spi still busy?\n"); in spi_ppc4xx_int()
313 lstatus = in_8(&hw->regs->sr); in spi_ppc4xx_int()
317 dev_err(hw->dev, "busywait: too many loops!\n"); in spi_ppc4xx_int()
318 complete(&hw->done); in spi_ppc4xx_int()
322 status = in_8(&hw->regs->sr); in spi_ppc4xx_int()
323 dev_dbg(hw->dev, "loops %d status %x\n", cnt, status); in spi_ppc4xx_int()
327 count = hw->count; in spi_ppc4xx_int()
328 hw->count++; in spi_ppc4xx_int()
331 data = in_8(&hw->regs->rxd); in spi_ppc4xx_int()
332 if (hw->rx) in spi_ppc4xx_int()
333 hw->rx[count] = data; in spi_ppc4xx_int()
337 if (count < hw->len) { in spi_ppc4xx_int()
338 data = hw->tx ? hw->tx[count] : 0; in spi_ppc4xx_int()
339 out_8(&hw->regs->txd, data); in spi_ppc4xx_int()
340 out_8(&hw->regs->cr, SPI_PPC4XX_CR_STR); in spi_ppc4xx_int()
342 complete(&hw->done); in spi_ppc4xx_int()
350 kfree(spi->controller_state); in spi_ppc4xx_cleanup()
367 if (hw->master->num_chipselect) { in free_gpios()
369 for (i = 0; i < hw->master->num_chipselect; i++) in free_gpios()
370 if (gpio_is_valid(hw->gpios[i])) in free_gpios()
371 gpio_free(hw->gpios[i]); in free_gpios()
373 kfree(hw->gpios); in free_gpios()
374 hw->gpios = NULL; in free_gpios()
387 struct device_node *np = op->dev.of_node; in spi_ppc4xx_of_probe()
388 struct device *dev = &op->dev; in spi_ppc4xx_of_probe()
396 return -ENOMEM; in spi_ppc4xx_of_probe()
397 master->dev.of_node = np; in spi_ppc4xx_of_probe()
400 hw->master = master; in spi_ppc4xx_of_probe()
401 hw->dev = dev; in spi_ppc4xx_of_probe()
403 init_completion(&hw->done); in spi_ppc4xx_of_probe()
406 * A count of zero implies a single SPI device without any chip-select. in spi_ppc4xx_of_probe()
407 * Note that of_gpio_count counts all gpios assigned to this spi master. in spi_ppc4xx_of_probe()
414 hw->gpios = kcalloc(num_gpios, sizeof(*hw->gpios), GFP_KERNEL); in spi_ppc4xx_of_probe()
415 if (!hw->gpios) { in spi_ppc4xx_of_probe()
416 ret = -ENOMEM; in spi_ppc4xx_of_probe()
425 hw->gpios[i] = gpio; in spi_ppc4xx_of_probe()
428 /* Real CS - set the initial state. */ in spi_ppc4xx_of_probe()
429 ret = gpio_request(gpio, np->name); in spi_ppc4xx_of_probe()
439 } else if (gpio == -EEXIST) { in spi_ppc4xx_of_probe()
440 ; /* No CS, but that's OK. */ in spi_ppc4xx_of_probe()
443 ret = -EINVAL; in spi_ppc4xx_of_probe()
450 bbp = &hw->bitbang; in spi_ppc4xx_of_probe()
451 bbp->master = hw->master; in spi_ppc4xx_of_probe()
452 bbp->setup_transfer = spi_ppc4xx_setupxfer; in spi_ppc4xx_of_probe()
453 bbp->chipselect = spi_ppc4xx_chipsel; in spi_ppc4xx_of_probe()
454 bbp->txrx_bufs = spi_ppc4xx_txrx; in spi_ppc4xx_of_probe()
455 bbp->use_dma = 0; in spi_ppc4xx_of_probe()
456 bbp->master->setup = spi_ppc4xx_setup; in spi_ppc4xx_of_probe()
457 bbp->master->cleanup = spi_ppc4xx_cleanup; in spi_ppc4xx_of_probe()
458 bbp->master->bits_per_word_mask = SPI_BPW_MASK(8); in spi_ppc4xx_of_probe()
460 /* the spi->mode bits understood by this driver: */ in spi_ppc4xx_of_probe()
461 bbp->master->mode_bits = in spi_ppc4xx_of_probe()
465 bbp->master->num_chipselect = num_gpios > 0 ? num_gpios : 0; in spi_ppc4xx_of_probe()
471 ret = -ENODEV; in spi_ppc4xx_of_probe()
475 clk = of_get_property(opbnp, "clock-frequency", NULL); in spi_ppc4xx_of_probe()
477 dev_err(dev, "OPB: no clock-frequency property set\n"); in spi_ppc4xx_of_probe()
479 ret = -ENODEV; in spi_ppc4xx_of_probe()
482 hw->opb_freq = *clk; in spi_ppc4xx_of_probe()
483 hw->opb_freq >>= 2; in spi_ppc4xx_of_probe()
491 hw->mapbase = resource.start; in spi_ppc4xx_of_probe()
492 hw->mapsize = resource_size(&resource); in spi_ppc4xx_of_probe()
495 if (hw->mapsize < sizeof(struct spi_ppc4xx_regs)) { in spi_ppc4xx_of_probe()
497 ret = -EINVAL; in spi_ppc4xx_of_probe()
502 hw->irqnum = irq_of_parse_and_map(np, 0); in spi_ppc4xx_of_probe()
503 ret = request_irq(hw->irqnum, spi_ppc4xx_int, in spi_ppc4xx_of_probe()
510 if (!request_mem_region(hw->mapbase, hw->mapsize, DRIVER_NAME)) { in spi_ppc4xx_of_probe()
512 ret = -EBUSY; in spi_ppc4xx_of_probe()
516 hw->regs = ioremap(hw->mapbase, sizeof(struct spi_ppc4xx_regs)); in spi_ppc4xx_of_probe()
518 if (!hw->regs) { in spi_ppc4xx_of_probe()
520 ret = -ENXIO; in spi_ppc4xx_of_probe()
527 dev->dma_mask = 0; in spi_ppc4xx_of_probe()
539 iounmap(hw->regs); in spi_ppc4xx_of_probe()
541 release_mem_region(hw->mapbase, hw->mapsize); in spi_ppc4xx_of_probe()
543 free_irq(hw->irqnum, hw); in spi_ppc4xx_of_probe()
558 spi_bitbang_stop(&hw->bitbang); in spi_ppc4xx_of_remove()
559 release_mem_region(hw->mapbase, hw->mapsize); in spi_ppc4xx_of_remove()
560 free_irq(hw->irqnum, hw); in spi_ppc4xx_of_remove()
561 iounmap(hw->regs); in spi_ppc4xx_of_remove()
568 { .compatible = "ibm,ppc4xx-spi", },