Lines Matching refs:hw
95 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_chipsel() local
102 hw->set_cs(hw->pdata, spi->chip_select, cspol^1); in s3c24xx_spi_chipsel()
103 writeb(cs->spcon, hw->regs + S3C2410_SPCON); in s3c24xx_spi_chipsel()
108 hw->regs + S3C2410_SPCON); in s3c24xx_spi_chipsel()
109 hw->set_cs(hw->pdata, spi->chip_select, cspol); in s3c24xx_spi_chipsel()
117 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_update_state() local
142 clk = clk_get_rate(hw->clk); in s3c24xx_spi_update_state()
162 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_setupxfer() local
167 writeb(cs->sppre, hw->regs + S3C2410_SPPRE); in s3c24xx_spi_setupxfer()
175 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_setup() local
196 mutex_lock(&hw->bitbang.lock); in s3c24xx_spi_setup()
197 if (!hw->bitbang.busy) { in s3c24xx_spi_setup()
198 hw->bitbang.chipselect(spi, BITBANG_CS_INACTIVE); in s3c24xx_spi_setup()
201 mutex_unlock(&hw->bitbang.lock); in s3c24xx_spi_setup()
206 static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count) in hw_txbyte() argument
208 return hw->tx ? hw->tx[count] : 0; in hw_txbyte()
243 static void s3c24xx_spi_tryfiq(struct s3c24xx_spi *hw) in s3c24xx_spi_tryfiq() argument
251 if (!hw->fiq_claimed) { in s3c24xx_spi_tryfiq()
255 ret = claim_fiq(&hw->fiq_handler); in s3c24xx_spi_tryfiq()
260 if (hw->tx && !hw->rx) in s3c24xx_spi_tryfiq()
262 else if (hw->rx && !hw->tx) in s3c24xx_spi_tryfiq()
267 regs.uregs[fiq_rspi] = (long)hw->regs; in s3c24xx_spi_tryfiq()
268 regs.uregs[fiq_rrx] = (long)hw->rx; in s3c24xx_spi_tryfiq()
269 regs.uregs[fiq_rtx] = (long)hw->tx + 1; in s3c24xx_spi_tryfiq()
270 regs.uregs[fiq_rcount] = hw->len - 1; in s3c24xx_spi_tryfiq()
274 if (hw->fiq_mode != mode) { in s3c24xx_spi_tryfiq()
275 hw->fiq_mode = mode; in s3c24xx_spi_tryfiq()
297 s3c24xx_set_fiq(hw->irq, ack_ptr, true); in s3c24xx_spi_tryfiq()
299 hw->fiq_mode = mode; in s3c24xx_spi_tryfiq()
300 hw->fiq_inuse = 1; in s3c24xx_spi_tryfiq()
314 struct s3c24xx_spi *hw = pw; in s3c24xx_spi_fiqop() local
318 if (hw->fiq_inuse) in s3c24xx_spi_fiqop()
324 hw->fiq_mode = FIQ_MODE_NONE; in s3c24xx_spi_fiqop()
325 hw->fiq_claimed = 0; in s3c24xx_spi_fiqop()
327 hw->fiq_claimed = 1; in s3c24xx_spi_fiqop()
339 static inline void s3c24xx_spi_initfiq(struct s3c24xx_spi *hw) in s3c24xx_spi_initfiq() argument
341 hw->fiq_handler.dev_id = hw; in s3c24xx_spi_initfiq()
342 hw->fiq_handler.name = dev_name(hw->dev); in s3c24xx_spi_initfiq()
343 hw->fiq_handler.fiq_op = s3c24xx_spi_fiqop; in s3c24xx_spi_initfiq()
353 static inline bool s3c24xx_spi_usefiq(struct s3c24xx_spi *hw) in s3c24xx_spi_usefiq() argument
355 return hw->pdata->use_fiq; in s3c24xx_spi_usefiq()
380 struct s3c24xx_spi *hw = to_hw(spi); in s3c24xx_spi_txrx() local
382 hw->tx = t->tx_buf; in s3c24xx_spi_txrx()
383 hw->rx = t->rx_buf; in s3c24xx_spi_txrx()
384 hw->len = t->len; in s3c24xx_spi_txrx()
385 hw->count = 0; in s3c24xx_spi_txrx()
387 init_completion(&hw->done); in s3c24xx_spi_txrx()
389 hw->fiq_inuse = 0; in s3c24xx_spi_txrx()
390 if (s3c24xx_spi_usefiq(hw) && t->len >= 3) in s3c24xx_spi_txrx()
391 s3c24xx_spi_tryfiq(hw); in s3c24xx_spi_txrx()
394 writeb(hw_txbyte(hw, 0), hw->regs + S3C2410_SPTDAT); in s3c24xx_spi_txrx()
396 wait_for_completion(&hw->done); in s3c24xx_spi_txrx()
397 return hw->count; in s3c24xx_spi_txrx()
402 struct s3c24xx_spi *hw = dev; in s3c24xx_spi_irq() local
403 unsigned int spsta = readb(hw->regs + S3C2410_SPSTA); in s3c24xx_spi_irq()
404 unsigned int count = hw->count; in s3c24xx_spi_irq()
407 dev_dbg(hw->dev, "data-collision\n"); in s3c24xx_spi_irq()
408 complete(&hw->done); in s3c24xx_spi_irq()
413 dev_dbg(hw->dev, "spi not ready for tx?\n"); in s3c24xx_spi_irq()
414 complete(&hw->done); in s3c24xx_spi_irq()
418 if (!s3c24xx_spi_usingfiq(hw)) { in s3c24xx_spi_irq()
419 hw->count++; in s3c24xx_spi_irq()
421 if (hw->rx) in s3c24xx_spi_irq()
422 hw->rx[count] = readb(hw->regs + S3C2410_SPRDAT); in s3c24xx_spi_irq()
426 if (count < hw->len) in s3c24xx_spi_irq()
427 writeb(hw_txbyte(hw, count), hw->regs + S3C2410_SPTDAT); in s3c24xx_spi_irq()
429 complete(&hw->done); in s3c24xx_spi_irq()
431 hw->count = hw->len; in s3c24xx_spi_irq()
432 hw->fiq_inuse = 0; in s3c24xx_spi_irq()
434 if (hw->rx) in s3c24xx_spi_irq()
435 hw->rx[hw->len-1] = readb(hw->regs + S3C2410_SPRDAT); in s3c24xx_spi_irq()
437 complete(&hw->done); in s3c24xx_spi_irq()
444 static void s3c24xx_spi_initialsetup(struct s3c24xx_spi *hw) in s3c24xx_spi_initialsetup() argument
448 clk_enable(hw->clk); in s3c24xx_spi_initialsetup()
452 writeb(0xff, hw->regs + S3C2410_SPPRE); in s3c24xx_spi_initialsetup()
453 writeb(SPPIN_DEFAULT, hw->regs + S3C2410_SPPIN); in s3c24xx_spi_initialsetup()
454 writeb(SPCON_DEFAULT, hw->regs + S3C2410_SPCON); in s3c24xx_spi_initialsetup()
456 if (hw->pdata) { in s3c24xx_spi_initialsetup()
457 if (hw->set_cs == s3c24xx_spi_gpiocs) in s3c24xx_spi_initialsetup()
458 gpio_direction_output(hw->pdata->pin_cs, 1); in s3c24xx_spi_initialsetup()
460 if (hw->pdata->gpio_setup) in s3c24xx_spi_initialsetup()
461 hw->pdata->gpio_setup(hw->pdata, 1); in s3c24xx_spi_initialsetup()
468 struct s3c24xx_spi *hw; in s3c24xx_spi_probe() local
478 hw = spi_master_get_devdata(master); in s3c24xx_spi_probe()
480 hw->master = master; in s3c24xx_spi_probe()
481 hw->pdata = pdata = dev_get_platdata(&pdev->dev); in s3c24xx_spi_probe()
482 hw->dev = &pdev->dev; in s3c24xx_spi_probe()
490 platform_set_drvdata(pdev, hw); in s3c24xx_spi_probe()
491 init_completion(&hw->done); in s3c24xx_spi_probe()
495 s3c24xx_spi_initfiq(hw); in s3c24xx_spi_probe()
502 master->num_chipselect = hw->pdata->num_cs; in s3c24xx_spi_probe()
508 hw->bitbang.master = hw->master; in s3c24xx_spi_probe()
509 hw->bitbang.setup_transfer = s3c24xx_spi_setupxfer; in s3c24xx_spi_probe()
510 hw->bitbang.chipselect = s3c24xx_spi_chipsel; in s3c24xx_spi_probe()
511 hw->bitbang.txrx_bufs = s3c24xx_spi_txrx; in s3c24xx_spi_probe()
513 hw->master->setup = s3c24xx_spi_setup; in s3c24xx_spi_probe()
515 dev_dbg(hw->dev, "bitbang at %p\n", &hw->bitbang); in s3c24xx_spi_probe()
518 hw->regs = devm_platform_ioremap_resource(pdev, 0); in s3c24xx_spi_probe()
519 if (IS_ERR(hw->regs)) { in s3c24xx_spi_probe()
520 err = PTR_ERR(hw->regs); in s3c24xx_spi_probe()
524 hw->irq = platform_get_irq(pdev, 0); in s3c24xx_spi_probe()
525 if (hw->irq < 0) { in s3c24xx_spi_probe()
530 err = devm_request_irq(&pdev->dev, hw->irq, s3c24xx_spi_irq, 0, in s3c24xx_spi_probe()
531 pdev->name, hw); in s3c24xx_spi_probe()
537 hw->clk = devm_clk_get(&pdev->dev, "spi"); in s3c24xx_spi_probe()
538 if (IS_ERR(hw->clk)) { in s3c24xx_spi_probe()
540 err = PTR_ERR(hw->clk); in s3c24xx_spi_probe()
560 hw->set_cs = s3c24xx_spi_gpiocs; in s3c24xx_spi_probe()
563 hw->set_cs = pdata->set_cs; in s3c24xx_spi_probe()
565 s3c24xx_spi_initialsetup(hw); in s3c24xx_spi_probe()
569 err = spi_bitbang_start(&hw->bitbang); in s3c24xx_spi_probe()
578 clk_disable(hw->clk); in s3c24xx_spi_probe()
581 spi_master_put(hw->master); in s3c24xx_spi_probe()
587 struct s3c24xx_spi *hw = platform_get_drvdata(dev); in s3c24xx_spi_remove() local
589 spi_bitbang_stop(&hw->bitbang); in s3c24xx_spi_remove()
590 clk_disable(hw->clk); in s3c24xx_spi_remove()
591 spi_master_put(hw->master); in s3c24xx_spi_remove()
600 struct s3c24xx_spi *hw = dev_get_drvdata(dev); in s3c24xx_spi_suspend() local
603 ret = spi_master_suspend(hw->master); in s3c24xx_spi_suspend()
607 if (hw->pdata && hw->pdata->gpio_setup) in s3c24xx_spi_suspend()
608 hw->pdata->gpio_setup(hw->pdata, 0); in s3c24xx_spi_suspend()
610 clk_disable(hw->clk); in s3c24xx_spi_suspend()
616 struct s3c24xx_spi *hw = dev_get_drvdata(dev); in s3c24xx_spi_resume() local
618 s3c24xx_spi_initialsetup(hw); in s3c24xx_spi_resume()
619 return spi_master_resume(hw->master); in s3c24xx_spi_resume()