Lines Matching refs:hs
163 static int hisi_spi_debugfs_init(struct hisi_spi *hs) in hisi_spi_debugfs_init() argument
169 master = container_of(hs->dev, struct spi_controller, dev); in hisi_spi_debugfs_init()
171 hs->debugfs = debugfs_create_dir(name, NULL); in hisi_spi_debugfs_init()
172 if (!hs->debugfs) in hisi_spi_debugfs_init()
175 hs->regset.regs = hisi_spi_regs; in hisi_spi_debugfs_init()
176 hs->regset.nregs = ARRAY_SIZE(hisi_spi_regs); in hisi_spi_debugfs_init()
177 hs->regset.base = hs->regs; in hisi_spi_debugfs_init()
178 debugfs_create_regset32("registers", 0400, hs->debugfs, &hs->regset); in hisi_spi_debugfs_init()
183 static u32 hisi_spi_busy(struct hisi_spi *hs) in hisi_spi_busy() argument
185 return readl(hs->regs + HISI_SPI_SR) & SR_BUSY; in hisi_spi_busy()
188 static u32 hisi_spi_rx_not_empty(struct hisi_spi *hs) in hisi_spi_rx_not_empty() argument
190 return readl(hs->regs + HISI_SPI_SR) & SR_RXNE; in hisi_spi_rx_not_empty()
193 static u32 hisi_spi_tx_not_full(struct hisi_spi *hs) in hisi_spi_tx_not_full() argument
195 return readl(hs->regs + HISI_SPI_SR) & SR_TXNF; in hisi_spi_tx_not_full()
198 static void hisi_spi_flush_fifo(struct hisi_spi *hs) in hisi_spi_flush_fifo() argument
203 while (hisi_spi_rx_not_empty(hs)) in hisi_spi_flush_fifo()
204 readl(hs->regs + HISI_SPI_DOUT); in hisi_spi_flush_fifo()
205 } while (hisi_spi_busy(hs) && limit--); in hisi_spi_flush_fifo()
209 static void hisi_spi_disable(struct hisi_spi *hs) in hisi_spi_disable() argument
211 writel(0, hs->regs + HISI_SPI_ENR); in hisi_spi_disable()
212 writel(IMR_MASK, hs->regs + HISI_SPI_IMR); in hisi_spi_disable()
213 writel(ICR_MASK, hs->regs + HISI_SPI_ICR); in hisi_spi_disable()
226 static void hisi_spi_reader(struct hisi_spi *hs) in hisi_spi_reader() argument
228 u32 max = min_t(u32, hs->rx_len, hs->fifo_len); in hisi_spi_reader()
231 while (hisi_spi_rx_not_empty(hs) && max--) { in hisi_spi_reader()
232 rxw = readl(hs->regs + HISI_SPI_DOUT); in hisi_spi_reader()
234 if (hs->rx) { in hisi_spi_reader()
235 switch (hs->n_bytes) { in hisi_spi_reader()
237 *(u8 *)(hs->rx) = rxw; in hisi_spi_reader()
240 *(u16 *)(hs->rx) = rxw; in hisi_spi_reader()
243 *(u32 *)(hs->rx) = rxw; in hisi_spi_reader()
246 hs->rx += hs->n_bytes; in hisi_spi_reader()
248 --hs->rx_len; in hisi_spi_reader()
252 static void hisi_spi_writer(struct hisi_spi *hs) in hisi_spi_writer() argument
254 u32 max = min_t(u32, hs->tx_len, hs->fifo_len); in hisi_spi_writer()
257 while (hisi_spi_tx_not_full(hs) && max--) { in hisi_spi_writer()
259 if (hs->tx) { in hisi_spi_writer()
260 switch (hs->n_bytes) { in hisi_spi_writer()
262 txw = *(u8 *)(hs->tx); in hisi_spi_writer()
265 txw = *(u16 *)(hs->tx); in hisi_spi_writer()
268 txw = *(u32 *)(hs->tx); in hisi_spi_writer()
271 hs->tx += hs->n_bytes; in hisi_spi_writer()
273 writel(txw, hs->regs + HISI_SPI_DIN); in hisi_spi_writer()
274 --hs->tx_len; in hisi_spi_writer()
325 static void hisi_spi_hw_init(struct hisi_spi *hs) in hisi_spi_hw_init() argument
327 hisi_spi_disable(hs); in hisi_spi_hw_init()
332 hs->regs + HISI_SPI_FIFOC); in hisi_spi_hw_init()
334 hs->fifo_len = 256; in hisi_spi_hw_init()
340 struct hisi_spi *hs = spi_controller_get_devdata(master); in hisi_spi_irq() local
341 u32 irq_status = readl(hs->regs + HISI_SPI_ISR) & ISR_MASK; in hisi_spi_irq()
351 dev_err(hs->dev, "interrupt_transfer: fifo overflow\n"); in hisi_spi_irq()
360 hisi_spi_reader(hs); in hisi_spi_irq()
361 if (!hs->rx_len) in hisi_spi_irq()
366 hisi_spi_writer(hs); in hisi_spi_irq()
371 hisi_spi_disable(hs); in hisi_spi_irq()
379 struct hisi_spi *hs = spi_controller_get_devdata(master); in hisi_spi_transfer_one() local
389 writel(cr, hs->regs + HISI_SPI_CR); in hisi_spi_transfer_one()
391 hisi_spi_flush_fifo(hs); in hisi_spi_transfer_one()
393 hs->n_bytes = hisi_spi_n_bytes(transfer); in hisi_spi_transfer_one()
394 hs->tx = transfer->tx_buf; in hisi_spi_transfer_one()
395 hs->tx_len = transfer->len / hs->n_bytes; in hisi_spi_transfer_one()
396 hs->rx = transfer->rx_buf; in hisi_spi_transfer_one()
397 hs->rx_len = hs->tx_len; in hisi_spi_transfer_one()
406 writel(~(u32)IMR_MASK, hs->regs + HISI_SPI_IMR); in hisi_spi_transfer_one()
407 writel(1, hs->regs + HISI_SPI_ENR); in hisi_spi_transfer_one()
415 struct hisi_spi *hs = spi_controller_get_devdata(master); in hisi_spi_handle_err() local
417 hisi_spi_disable(hs); in hisi_spi_handle_err()
456 struct hisi_spi *hs; in hisi_spi_probe() local
463 master = devm_spi_alloc_master(dev, sizeof(*hs)); in hisi_spi_probe()
469 hs = spi_controller_get_devdata(master); in hisi_spi_probe()
470 hs->dev = dev; in hisi_spi_probe()
471 hs->irq = irq; in hisi_spi_probe()
473 hs->regs = devm_platform_ioremap_resource(pdev, 0); in hisi_spi_probe()
474 if (IS_ERR(hs->regs)) in hisi_spi_probe()
475 return PTR_ERR(hs->regs); in hisi_spi_probe()
501 hisi_spi_hw_init(hs); in hisi_spi_probe()
503 ret = devm_request_irq(dev, hs->irq, hisi_spi_irq, 0, dev_name(dev), in hisi_spi_probe()
506 dev_err(dev, "failed to get IRQ=%d, ret=%d\n", hs->irq, ret); in hisi_spi_probe()
516 if (hisi_spi_debugfs_init(hs)) in hisi_spi_probe()
520 readl(hs->regs + HISI_SPI_VERSION), in hisi_spi_probe()
529 struct hisi_spi *hs = spi_controller_get_devdata(master); in hisi_spi_remove() local
531 debugfs_remove_recursive(hs->debugfs); in hisi_spi_remove()