Lines Matching refs:spicc
178 static void meson_spicc_oen_enable(struct meson_spicc_device *spicc) in meson_spicc_oen_enable() argument
182 if (!spicc->data->has_oen) { in meson_spicc_oen_enable()
184 spicc->pins_idle_high = pinctrl_lookup_state(spicc->pinctrl, in meson_spicc_oen_enable()
186 if (IS_ERR(spicc->pins_idle_high)) { in meson_spicc_oen_enable()
187 dev_warn(&spicc->pdev->dev, "can't get idle-high pinctrl\n"); in meson_spicc_oen_enable()
188 spicc->pins_idle_high = NULL; in meson_spicc_oen_enable()
190 spicc->pins_idle_low = pinctrl_lookup_state(spicc->pinctrl, in meson_spicc_oen_enable()
192 if (IS_ERR(spicc->pins_idle_low)) { in meson_spicc_oen_enable()
193 dev_warn(&spicc->pdev->dev, "can't get idle-low pinctrl\n"); in meson_spicc_oen_enable()
194 spicc->pins_idle_low = NULL; in meson_spicc_oen_enable()
199 conf = readl_relaxed(spicc->base + SPICC_ENH_CTL0) | in meson_spicc_oen_enable()
202 writel_relaxed(conf, spicc->base + SPICC_ENH_CTL0); in meson_spicc_oen_enable()
205 static inline bool meson_spicc_txfull(struct meson_spicc_device *spicc) in meson_spicc_txfull() argument
208 readl_relaxed(spicc->base + SPICC_STATREG)); in meson_spicc_txfull()
211 static inline bool meson_spicc_rxready(struct meson_spicc_device *spicc) in meson_spicc_rxready() argument
214 readl_relaxed(spicc->base + SPICC_STATREG)); in meson_spicc_rxready()
217 static inline u32 meson_spicc_pull_data(struct meson_spicc_device *spicc) in meson_spicc_pull_data() argument
219 unsigned int bytes = spicc->bytes_per_word; in meson_spicc_pull_data()
225 byte = *spicc->tx_buf++; in meson_spicc_pull_data()
230 spicc->tx_remain--; in meson_spicc_pull_data()
234 static inline void meson_spicc_push_data(struct meson_spicc_device *spicc, in meson_spicc_push_data() argument
237 unsigned int bytes = spicc->bytes_per_word; in meson_spicc_push_data()
243 *spicc->rx_buf++ = byte; in meson_spicc_push_data()
247 spicc->rx_remain--; in meson_spicc_push_data()
250 static inline void meson_spicc_rx(struct meson_spicc_device *spicc) in meson_spicc_rx() argument
253 while (spicc->rx_remain && in meson_spicc_rx()
254 meson_spicc_rxready(spicc)) in meson_spicc_rx()
255 meson_spicc_push_data(spicc, in meson_spicc_rx()
256 readl_relaxed(spicc->base + SPICC_RXDATA)); in meson_spicc_rx()
259 static inline void meson_spicc_tx(struct meson_spicc_device *spicc) in meson_spicc_tx() argument
262 while (spicc->tx_remain && in meson_spicc_tx()
263 !meson_spicc_txfull(spicc)) in meson_spicc_tx()
264 writel_relaxed(meson_spicc_pull_data(spicc), in meson_spicc_tx()
265 spicc->base + SPICC_TXDATA); in meson_spicc_tx()
268 static inline void meson_spicc_setup_burst(struct meson_spicc_device *spicc) in meson_spicc_setup_burst() argument
272 spicc->xfer_remain / in meson_spicc_setup_burst()
273 spicc->bytes_per_word, in meson_spicc_setup_burst()
274 spicc->data->fifo_size); in meson_spicc_setup_burst()
276 spicc->tx_remain = burst_len; in meson_spicc_setup_burst()
277 spicc->rx_remain = burst_len; in meson_spicc_setup_burst()
278 spicc->xfer_remain -= burst_len * spicc->bytes_per_word; in meson_spicc_setup_burst()
284 spicc->base + SPICC_CONREG); in meson_spicc_setup_burst()
287 meson_spicc_tx(spicc); in meson_spicc_setup_burst()
292 struct meson_spicc_device *spicc = (void *) data; in meson_spicc_irq() local
294 writel_bits_relaxed(SPICC_TC, SPICC_TC, spicc->base + SPICC_STATREG); in meson_spicc_irq()
297 meson_spicc_rx(spicc); in meson_spicc_irq()
299 if (!spicc->xfer_remain) { in meson_spicc_irq()
301 writel(0, spicc->base + SPICC_INTREG); in meson_spicc_irq()
303 complete(&spicc->done); in meson_spicc_irq()
309 meson_spicc_setup_burst(spicc); in meson_spicc_irq()
312 writel_bits_relaxed(SPICC_XCH, SPICC_XCH, spicc->base + SPICC_CONREG); in meson_spicc_irq()
317 static void meson_spicc_auto_io_delay(struct meson_spicc_device *spicc) in meson_spicc_auto_io_delay() argument
323 if (spicc->data->has_enhance_clk_div) { in meson_spicc_auto_io_delay()
325 readl_relaxed(spicc->base + SPICC_ENH_CTL0)); in meson_spicc_auto_io_delay()
330 readl_relaxed(spicc->base + SPICC_CONREG)); in meson_spicc_auto_io_delay()
337 hz = clk_get_rate(spicc->clk); in meson_spicc_auto_io_delay()
352 conf = readl_relaxed(spicc->base + SPICC_TESTREG); in meson_spicc_auto_io_delay()
357 writel_relaxed(conf, spicc->base + SPICC_TESTREG); in meson_spicc_auto_io_delay()
360 static void meson_spicc_setup_xfer(struct meson_spicc_device *spicc, in meson_spicc_setup_xfer() argument
366 conf = conf_orig = readl_relaxed(spicc->base + SPICC_CONREG); in meson_spicc_setup_xfer()
371 (spicc->bytes_per_word << 3) - 1); in meson_spicc_setup_xfer()
375 writel_relaxed(conf, spicc->base + SPICC_CONREG); in meson_spicc_setup_xfer()
377 clk_set_rate(spicc->clk, xfer->speed_hz); in meson_spicc_setup_xfer()
379 meson_spicc_auto_io_delay(spicc); in meson_spicc_setup_xfer()
381 writel_relaxed(0, spicc->base + SPICC_DMAREG); in meson_spicc_setup_xfer()
384 static void meson_spicc_reset_fifo(struct meson_spicc_device *spicc) in meson_spicc_reset_fifo() argument
386 if (spicc->data->has_oen) in meson_spicc_reset_fifo()
389 spicc->base + SPICC_ENH_CTL0); in meson_spicc_reset_fifo()
392 spicc->base + SPICC_TESTREG); in meson_spicc_reset_fifo()
394 while (meson_spicc_rxready(spicc)) in meson_spicc_reset_fifo()
395 readl_relaxed(spicc->base + SPICC_RXDATA); in meson_spicc_reset_fifo()
397 if (spicc->data->has_oen) in meson_spicc_reset_fifo()
399 spicc->base + SPICC_ENH_CTL0); in meson_spicc_reset_fifo()
406 struct meson_spicc_device *spicc = spi_controller_get_devdata(host); in meson_spicc_transfer_one() local
410 spicc->xfer = xfer; in meson_spicc_transfer_one()
413 spicc->tx_buf = (u8 *)xfer->tx_buf; in meson_spicc_transfer_one()
414 spicc->rx_buf = (u8 *)xfer->rx_buf; in meson_spicc_transfer_one()
415 spicc->xfer_remain = xfer->len; in meson_spicc_transfer_one()
418 spicc->bytes_per_word = in meson_spicc_transfer_one()
419 DIV_ROUND_UP(spicc->xfer->bits_per_word, 8); in meson_spicc_transfer_one()
421 if (xfer->len % spicc->bytes_per_word) in meson_spicc_transfer_one()
425 meson_spicc_setup_xfer(spicc, xfer); in meson_spicc_transfer_one()
427 meson_spicc_reset_fifo(spicc); in meson_spicc_transfer_one()
430 meson_spicc_setup_burst(spicc); in meson_spicc_transfer_one()
433 reinit_completion(&spicc->done); in meson_spicc_transfer_one()
446 writel_bits_relaxed(SPICC_XCH, SPICC_XCH, spicc->base + SPICC_CONREG); in meson_spicc_transfer_one()
449 writel_relaxed(SPICC_TC_EN, spicc->base + SPICC_INTREG); in meson_spicc_transfer_one()
451 if (!wait_for_completion_timeout(&spicc->done, msecs_to_jiffies(timeout))) in meson_spicc_transfer_one()
460 struct meson_spicc_device *spicc = spi_controller_get_devdata(host); in meson_spicc_prepare_message() local
462 u32 conf = readl_relaxed(spicc->base + SPICC_CONREG) & SPICC_DATARATE_MASK; in meson_spicc_prepare_message()
465 spicc->message = message; in meson_spicc_prepare_message()
479 if (!spicc->data->has_oen) { in meson_spicc_prepare_message()
481 if (spicc->pins_idle_high) in meson_spicc_prepare_message()
482 pinctrl_select_state(spicc->pinctrl, spicc->pins_idle_high); in meson_spicc_prepare_message()
484 if (spicc->pins_idle_low) in meson_spicc_prepare_message()
485 pinctrl_select_state(spicc->pinctrl, spicc->pins_idle_low); in meson_spicc_prepare_message()
512 writel_relaxed(conf, spicc->base + SPICC_CONREG); in meson_spicc_prepare_message()
515 writel_relaxed(0, spicc->base + SPICC_PERIODREG); in meson_spicc_prepare_message()
519 spicc->base + SPICC_TESTREG); in meson_spicc_prepare_message()
526 struct meson_spicc_device *spicc = spi_controller_get_devdata(host); in meson_spicc_unprepare_transfer() local
527 u32 conf = readl_relaxed(spicc->base + SPICC_CONREG) & SPICC_DATARATE_MASK; in meson_spicc_unprepare_transfer()
530 writel(0, spicc->base + SPICC_INTREG); in meson_spicc_unprepare_transfer()
532 device_reset_optional(&spicc->pdev->dev); in meson_spicc_unprepare_transfer()
535 writel_relaxed(conf, spicc->base + SPICC_CONREG); in meson_spicc_unprepare_transfer()
537 if (!spicc->data->has_oen) in meson_spicc_unprepare_transfer()
538 pinctrl_select_default_state(&spicc->pdev->dev); in meson_spicc_unprepare_transfer()
588 struct meson_spicc_device *spicc = pow2_clk_to_spicc(divider); in meson_spicc_pow2_recalc_rate() local
590 if (!spicc->host->cur_msg) in meson_spicc_pow2_recalc_rate()
600 struct meson_spicc_device *spicc = pow2_clk_to_spicc(divider); in meson_spicc_pow2_determine_rate() local
602 if (!spicc->host->cur_msg) in meson_spicc_pow2_determine_rate()
612 struct meson_spicc_device *spicc = pow2_clk_to_spicc(divider); in meson_spicc_pow2_set_rate() local
614 if (!spicc->host->cur_msg) in meson_spicc_pow2_set_rate()
626 static int meson_spicc_pow2_clk_init(struct meson_spicc_device *spicc) in meson_spicc_pow2_clk_init() argument
628 struct device *dev = &spicc->pdev->dev; in meson_spicc_pow2_clk_init()
649 if (spicc->data->has_pclk) { in meson_spicc_pow2_clk_init()
651 parent_data[0].hw = __clk_get_hw(spicc->pclk); in meson_spicc_pow2_clk_init()
654 parent_data[0].hw = __clk_get_hw(spicc->core); in meson_spicc_pow2_clk_init()
677 spicc->pow2_div.shift = 16; in meson_spicc_pow2_clk_init()
678 spicc->pow2_div.width = 3; in meson_spicc_pow2_clk_init()
679 spicc->pow2_div.flags = CLK_DIVIDER_POWER_OF_TWO; in meson_spicc_pow2_clk_init()
680 spicc->pow2_div.reg = spicc->base + SPICC_CONREG; in meson_spicc_pow2_clk_init()
681 spicc->pow2_div.hw.init = &init; in meson_spicc_pow2_clk_init()
683 spicc->clk = devm_clk_register(dev, &spicc->pow2_div.hw); in meson_spicc_pow2_clk_init()
684 if (WARN_ON(IS_ERR(spicc->clk))) in meson_spicc_pow2_clk_init()
685 return PTR_ERR(spicc->clk); in meson_spicc_pow2_clk_init()
690 static int meson_spicc_enh_clk_init(struct meson_spicc_device *spicc) in meson_spicc_enh_clk_init() argument
692 struct device *dev = &spicc->pdev->dev; in meson_spicc_enh_clk_init()
715 if (spicc->data->has_pclk) { in meson_spicc_enh_clk_init()
717 parent_data[0].hw = __clk_get_hw(spicc->pclk); in meson_spicc_enh_clk_init()
720 parent_data[0].hw = __clk_get_hw(spicc->core); in meson_spicc_enh_clk_init()
745 enh_div->reg = spicc->base + SPICC_ENH_CTL0; in meson_spicc_enh_clk_init()
759 parent_data[0].hw = &spicc->pow2_div.hw; in meson_spicc_enh_clk_init()
766 mux->reg = spicc->base + SPICC_ENH_CTL0; in meson_spicc_enh_clk_init()
769 spicc->clk = devm_clk_register(dev, &mux->hw); in meson_spicc_enh_clk_init()
770 if (WARN_ON(IS_ERR(spicc->clk))) in meson_spicc_enh_clk_init()
771 return PTR_ERR(spicc->clk); in meson_spicc_enh_clk_init()
779 struct meson_spicc_device *spicc; in meson_spicc_probe() local
782 host = spi_alloc_host(&pdev->dev, sizeof(*spicc)); in meson_spicc_probe()
787 spicc = spi_controller_get_devdata(host); in meson_spicc_probe()
788 spicc->host = host; in meson_spicc_probe()
790 spicc->data = of_device_get_match_data(&pdev->dev); in meson_spicc_probe()
791 if (!spicc->data) { in meson_spicc_probe()
797 spicc->pdev = pdev; in meson_spicc_probe()
798 platform_set_drvdata(pdev, spicc); in meson_spicc_probe()
800 init_completion(&spicc->done); in meson_spicc_probe()
802 spicc->base = devm_platform_ioremap_resource(pdev, 0); in meson_spicc_probe()
803 if (IS_ERR(spicc->base)) { in meson_spicc_probe()
805 ret = PTR_ERR(spicc->base); in meson_spicc_probe()
811 spicc->base + SPICC_CONREG); in meson_spicc_probe()
814 writel_relaxed(0, spicc->base + SPICC_INTREG); in meson_spicc_probe()
823 0, NULL, spicc); in meson_spicc_probe()
829 spicc->core = devm_clk_get_enabled(&pdev->dev, "core"); in meson_spicc_probe()
830 if (IS_ERR(spicc->core)) { in meson_spicc_probe()
832 ret = PTR_ERR(spicc->core); in meson_spicc_probe()
836 if (spicc->data->has_pclk) { in meson_spicc_probe()
837 spicc->pclk = devm_clk_get_enabled(&pdev->dev, "pclk"); in meson_spicc_probe()
838 if (IS_ERR(spicc->pclk)) { in meson_spicc_probe()
840 ret = PTR_ERR(spicc->pclk); in meson_spicc_probe()
845 spicc->pinctrl = devm_pinctrl_get(&pdev->dev); in meson_spicc_probe()
846 if (IS_ERR(spicc->pinctrl)) { in meson_spicc_probe()
847 ret = PTR_ERR(spicc->pinctrl); in meson_spicc_probe()
861 host->min_speed_hz = spicc->data->min_speed_hz; in meson_spicc_probe()
862 host->max_speed_hz = spicc->data->max_speed_hz; in meson_spicc_probe()
870 meson_spicc_oen_enable(spicc); in meson_spicc_probe()
872 ret = meson_spicc_pow2_clk_init(spicc); in meson_spicc_probe()
878 if (spicc->data->has_enhance_clk_div) { in meson_spicc_probe()
879 ret = meson_spicc_enh_clk_init(spicc); in meson_spicc_probe()
902 struct meson_spicc_device *spicc = platform_get_drvdata(pdev); in meson_spicc_remove() local
905 writel(0, spicc->base + SPICC_CONREG); in meson_spicc_remove()
907 spi_controller_put(spicc->host); in meson_spicc_remove()