Lines Matching refs:hw
66 struct altera_spi *hw = altera_spi_to_hw(spi); in altera_spi_set_cs() local
69 hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_set_cs()
70 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_set_cs()
71 writel(0, hw->base + ALTERA_SPI_SLAVE_SEL); in altera_spi_set_cs()
73 writel(BIT(spi->chip_select), hw->base + ALTERA_SPI_SLAVE_SEL); in altera_spi_set_cs()
74 hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_set_cs()
75 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_set_cs()
79 static void altera_spi_tx_word(struct altera_spi *hw) in altera_spi_tx_word() argument
83 if (hw->tx) { in altera_spi_tx_word()
84 switch (hw->bytes_per_word) { in altera_spi_tx_word()
86 txd = hw->tx[hw->count]; in altera_spi_tx_word()
89 txd = (hw->tx[hw->count * 2] in altera_spi_tx_word()
90 | (hw->tx[hw->count * 2 + 1] << 8)); in altera_spi_tx_word()
95 writel(txd, hw->base + ALTERA_SPI_TXDATA); in altera_spi_tx_word()
98 static void altera_spi_rx_word(struct altera_spi *hw) in altera_spi_rx_word() argument
102 rxd = readl(hw->base + ALTERA_SPI_RXDATA); in altera_spi_rx_word()
103 if (hw->rx) { in altera_spi_rx_word()
104 switch (hw->bytes_per_word) { in altera_spi_rx_word()
106 hw->rx[hw->count] = rxd; in altera_spi_rx_word()
109 hw->rx[hw->count * 2] = rxd; in altera_spi_rx_word()
110 hw->rx[hw->count * 2 + 1] = rxd >> 8; in altera_spi_rx_word()
115 hw->count++; in altera_spi_rx_word()
121 struct altera_spi *hw = spi_master_get_devdata(master); in altera_spi_txrx() local
123 hw->tx = t->tx_buf; in altera_spi_txrx()
124 hw->rx = t->rx_buf; in altera_spi_txrx()
125 hw->count = 0; in altera_spi_txrx()
126 hw->bytes_per_word = DIV_ROUND_UP(t->bits_per_word, 8); in altera_spi_txrx()
127 hw->len = t->len / hw->bytes_per_word; in altera_spi_txrx()
129 if (hw->irq >= 0) { in altera_spi_txrx()
131 hw->imr |= ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_txrx()
132 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_txrx()
135 altera_spi_tx_word(hw); in altera_spi_txrx()
137 while (hw->count < hw->len) { in altera_spi_txrx()
138 altera_spi_tx_word(hw); in altera_spi_txrx()
140 while (!(readl(hw->base + ALTERA_SPI_STATUS) & in altera_spi_txrx()
144 altera_spi_rx_word(hw); in altera_spi_txrx()
155 struct altera_spi *hw = spi_master_get_devdata(master); in altera_spi_irq() local
157 altera_spi_rx_word(hw); in altera_spi_irq()
159 if (hw->count < hw->len) { in altera_spi_irq()
160 altera_spi_tx_word(hw); in altera_spi_irq()
163 hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_irq()
164 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_irq()
174 struct altera_spi *hw; in altera_spi_probe() local
192 hw = spi_master_get_devdata(master); in altera_spi_probe()
196 hw->base = devm_ioremap_resource(&pdev->dev, res); in altera_spi_probe()
197 if (IS_ERR(hw->base)) { in altera_spi_probe()
198 err = PTR_ERR(hw->base); in altera_spi_probe()
202 hw->imr = 0; /* disable spi interrupts */ in altera_spi_probe()
203 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_probe()
204 writel(0, hw->base + ALTERA_SPI_STATUS); /* clear status reg */ in altera_spi_probe()
205 if (readl(hw->base + ALTERA_SPI_STATUS) & ALTERA_SPI_STATUS_RRDY_MSK) in altera_spi_probe()
206 readl(hw->base + ALTERA_SPI_RXDATA); /* flush rxdata */ in altera_spi_probe()
208 hw->irq = platform_get_irq(pdev, 0); in altera_spi_probe()
209 if (hw->irq >= 0) { in altera_spi_probe()
210 err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0, in altera_spi_probe()
219 dev_info(&pdev->dev, "base %p, irq %d\n", hw->base, hw->irq); in altera_spi_probe()