Lines Matching full:hw

96 	struct s3c24xx_spi *hw = to_hw(spi);  in s3c24xx_spi_chipsel()  local
103 hw->set_cs(hw->pdata, spi->chip_select, cspol^1); in s3c24xx_spi_chipsel()
104 writeb(cs->spcon, hw->regs + S3C2410_SPCON); in s3c24xx_spi_chipsel()
109 hw->regs + S3C2410_SPCON); in s3c24xx_spi_chipsel()
110 hw->set_cs(hw->pdata, spi->chip_select, cspol); in s3c24xx_spi_chipsel()
118 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_update_state() local
143 clk = clk_get_rate(hw->clk); in s3c24xx_spi_update_state()
163 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_setupxfer() local
168 writeb(cs->sppre, hw->regs + S3C2410_SPPRE); in s3c24xx_spi_setupxfer()
176 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_setup() local
197 mutex_lock(&hw->bitbang.lock); in s3c24xx_spi_setup()
198 if (!hw->bitbang.busy) { in s3c24xx_spi_setup()
199 hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE); in s3c24xx_spi_setup()
202 mutex_unlock(&hw->bitbang.lock); in s3c24xx_spi_setup()
207 static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count) in hw_txbyte() argument
209 return hw->tx ? hw->tx[count] : 0; in hw_txbyte()
250 * @hw: The hardware state.
259 static void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw) in s3c24xx_spi_tryfiq() argument
266 if (!hw->fiq_claimed) { in s3c24xx_spi_tryfiq()
270 ret = claim_fiq(&hw->fiq_handler); in s3c24xx_spi_tryfiq()
275 if (hw->tx && !hw->rx) in s3c24xx_spi_tryfiq()
277 else if (hw->rx && !hw->tx) in s3c24xx_spi_tryfiq()
282 regs.uregs[fiq_rspi] = (long)hw->regs; in s3c24xx_spi_tryfiq()
283 regs.uregs[fiq_rrx] = (long)hw->rx; in s3c24xx_spi_tryfiq()
284 regs.uregs[fiq_rtx] = (long)hw->tx + 1; in s3c24xx_spi_tryfiq()
285 regs.uregs[fiq_rcount] = hw->len - 1; in s3c24xx_spi_tryfiq()
290 if (hw->fiq_mode != mode) { in s3c24xx_spi_tryfiq()
293 hw->fiq_mode = mode; in s3c24xx_spi_tryfiq()
312 *ack_ptr = ack_bit(hw->irq); in s3c24xx_spi_tryfiq()
317 s3c24xx_set_fiq(hw->irq, true); in s3c24xx_spi_tryfiq()
319 hw->fiq_mode = mode; in s3c24xx_spi_tryfiq()
320 hw->fiq_inuse = 1; in s3c24xx_spi_tryfiq()
334 struct s3c24xx_spi *hw = pw; in s3c24xx_spi_fiqop() local
338 if (hw->fiq_inuse) in s3c24xx_spi_fiqop()
344 hw->fiq_mode = FIQ_MODE_NONE; in s3c24xx_spi_fiqop()
345 hw->fiq_claimed = 0; in s3c24xx_spi_fiqop()
347 hw->fiq_claimed = 1; in s3c24xx_spi_fiqop()
355 * @hw: The hardware state.
359 static inline void s3c24xx_spi_initfiq(struct s3c24xx_spi *hw) in s3c24xx_spi_initfiq() argument
361 hw->fiq_handler.dev_id = hw; in s3c24xx_spi_initfiq()
362 hw->fiq_handler.name = dev_name(hw->dev); in s3c24xx_spi_initfiq()
363 hw->fiq_handler.fiq_op = s3c24xx_spi_fiqop; in s3c24xx_spi_initfiq()
368 * @hw: The hardware state.
373 static inline bool s3c24xx_spi_usefiq(struct s3c24xx_spi *hw) in s3c24xx_spi_usefiq() argument
375 return hw->pdata->use_fiq; in s3c24xx_spi_usefiq()
400 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_txrx() local
402 hw->tx = t->tx_buf; in s3c24xx_spi_txrx()
403 hw->rx = t->rx_buf; in s3c24xx_spi_txrx()
404 hw->len = t->len; in s3c24xx_spi_txrx()
405 hw->count = 0; in s3c24xx_spi_txrx()
407 init_completion(&hw->done); in s3c24xx_spi_txrx()
409 hw->fiq_inuse = 0; in s3c24xx_spi_txrx()
410 if (s3c24xx_spi_usefiq(hw) && t->len >= 3) in s3c24xx_spi_txrx()
411 s3c24xx_spi_tryfiq(hw); in s3c24xx_spi_txrx()
414 writeb(hw_txbyte(hw, 0), hw->regs + S3C2410_SPTDAT); in s3c24xx_spi_txrx()
416 wait_for_completion(&hw->done); in s3c24xx_spi_txrx()
417 return hw->count; in s3c24xx_spi_txrx()
422 struct s3c24xx_spi *hw = dev; in s3c24xx_spi_irq() local
423 unsigned int spsta = readb(hw->regs + S3C2410_SPSTA); in s3c24xx_spi_irq()
424 unsigned int count = hw->count; in s3c24xx_spi_irq()
427 dev_dbg(hw->dev, "data-collision\n"); in s3c24xx_spi_irq()
428 complete(&hw->done); in s3c24xx_spi_irq()
433 dev_dbg(hw->dev, "spi not ready for tx?\n"); in s3c24xx_spi_irq()
434 complete(&hw->done); in s3c24xx_spi_irq()
438 if (!s3c24xx_spi_usingfiq(hw)) { in s3c24xx_spi_irq()
439 hw->count++; in s3c24xx_spi_irq()
441 if (hw->rx) in s3c24xx_spi_irq()
442 hw->rx[count] = readb(hw->regs + S3C2410_SPRDAT); in s3c24xx_spi_irq()
446 if (count < hw->len) in s3c24xx_spi_irq()
447 writeb(hw_txbyte(hw, count), hw->regs + S3C2410_SPTDAT); in s3c24xx_spi_irq()
449 complete(&hw->done); in s3c24xx_spi_irq()
451 hw->count = hw->len; in s3c24xx_spi_irq()
452 hw->fiq_inuse = 0; in s3c24xx_spi_irq()
454 if (hw->rx) in s3c24xx_spi_irq()
455 hw->rx[hw->len-1] = readb(hw->regs + S3C2410_SPRDAT); in s3c24xx_spi_irq()
457 complete(&hw->done); in s3c24xx_spi_irq()
464 static void s3c24xx_spi_initialsetup(struct s3c24xx_spi *hw) in s3c24xx_spi_initialsetup() argument
468 clk_enable(hw->clk); in s3c24xx_spi_initialsetup()
472 writeb(0xff, hw->regs + S3C2410_SPPRE); in s3c24xx_spi_initialsetup()
473 writeb(SPPIN_DEFAULT, hw->regs + S3C2410_SPPIN); in s3c24xx_spi_initialsetup()
474 writeb(SPCON_DEFAULT, hw->regs + S3C2410_SPCON); in s3c24xx_spi_initialsetup()
476 if (hw->pdata) { in s3c24xx_spi_initialsetup()
477 if (hw->set_cs == s3c24xx_spi_gpiocs) in s3c24xx_spi_initialsetup()
478 gpio_direction_output(hw->pdata->pin_cs, 1); in s3c24xx_spi_initialsetup()
480 if (hw->pdata->gpio_setup) in s3c24xx_spi_initialsetup()
481 hw->pdata->gpio_setup(hw->pdata, 1); in s3c24xx_spi_initialsetup()
488 struct s3c24xx_spi *hw; in s3c24xx_spi_probe() local
498 hw = spi_master_get_devdata(master); in s3c24xx_spi_probe()
500 hw->master = master; in s3c24xx_spi_probe()
501 hw->pdata = pdata = dev_get_platdata(&pdev->dev); in s3c24xx_spi_probe()
502 hw->dev = &pdev->dev; in s3c24xx_spi_probe()
510 platform_set_drvdata(pdev, hw); in s3c24xx_spi_probe()
511 init_completion(&hw->done); in s3c24xx_spi_probe()
515 s3c24xx_spi_initfiq(hw); in s3c24xx_spi_probe()
522 master->num_chipselect = hw->pdata->num_cs; in s3c24xx_spi_probe()
528 hw->bitbang.master = hw->master; in s3c24xx_spi_probe()
529 hw->bitbang.setup_transfer = s3c24xx_spi_setupxfer; in s3c24xx_spi_probe()
530 hw->bitbang.chipselect = s3c24xx_spi_chipsel; in s3c24xx_spi_probe()
531 hw->bitbang.txrx_bufs = s3c24xx_spi_txrx; in s3c24xx_spi_probe()
533 hw->master->setup = s3c24xx_spi_setup; in s3c24xx_spi_probe()
535 dev_dbg(hw->dev, "bitbang at %p\n", &hw->bitbang); in s3c24xx_spi_probe()
538 hw->regs = devm_platform_ioremap_resource(pdev, 0); in s3c24xx_spi_probe()
539 if (IS_ERR(hw->regs)) { in s3c24xx_spi_probe()
540 err = PTR_ERR(hw->regs); in s3c24xx_spi_probe()
544 hw->irq = platform_get_irq(pdev, 0); in s3c24xx_spi_probe()
545 if (hw->irq < 0) { in s3c24xx_spi_probe()
550 err = devm_request_irq(&pdev->dev, hw->irq, s3c24xx_spi_irq, 0, in s3c24xx_spi_probe()
551 pdev->name, hw); in s3c24xx_spi_probe()
557 hw->clk = devm_clk_get(&pdev->dev, "spi"); in s3c24xx_spi_probe()
558 if (IS_ERR(hw->clk)) { in s3c24xx_spi_probe()
560 err = PTR_ERR(hw->clk); in s3c24xx_spi_probe()
580 hw->set_cs = s3c24xx_spi_gpiocs; in s3c24xx_spi_probe()
583 hw->set_cs = pdata->set_cs; in s3c24xx_spi_probe()
585 s3c24xx_spi_initialsetup(hw); in s3c24xx_spi_probe()
589 err = spi_bitbang_start(&hw->bitbang); in s3c24xx_spi_probe()
598 clk_disable(hw->clk); in s3c24xx_spi_probe()
601 spi_master_put(hw->master); in s3c24xx_spi_probe()
607 struct s3c24xx_spi *hw = platform_get_drvdata(dev); in s3c24xx_spi_remove() local
609 spi_bitbang_stop(&hw->bitbang); in s3c24xx_spi_remove()
610 clk_disable(hw->clk); in s3c24xx_spi_remove()
611 spi_master_put(hw->master); in s3c24xx_spi_remove()
620 struct s3c24xx_spi *hw = dev_get_drvdata(dev); in s3c24xx_spi_suspend() local
623 ret = spi_master_suspend(hw->master); in s3c24xx_spi_suspend()
627 if (hw->pdata && hw->pdata->gpio_setup) in s3c24xx_spi_suspend()
628 hw->pdata->gpio_setup(hw->pdata, 0); in s3c24xx_spi_suspend()
630 clk_disable(hw->clk); in s3c24xx_spi_suspend()
636 struct s3c24xx_spi *hw = dev_get_drvdata(dev); in s3c24xx_spi_resume() local
638 s3c24xx_spi_initialsetup(hw); in s3c24xx_spi_resume()
639 return spi_master_resume(hw->master); in s3c24xx_spi_resume()