Lines Matching refs:hw
71 struct altera_spi *hw = altera_spi_to_hw(spi); in altera_spi_chipsel() local
77 hw->base + ALTERA_SPI_SLAVE_SEL); in altera_spi_chipsel()
78 hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_chipsel()
79 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_chipsel()
83 hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_chipsel()
84 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_chipsel()
85 writel(0, hw->base + ALTERA_SPI_SLAVE_SEL); in altera_spi_chipsel()
91 hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_chipsel()
92 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_chipsel()
97 hw->base + ALTERA_SPI_SLAVE_SEL); in altera_spi_chipsel()
98 hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_chipsel()
99 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_chipsel()
105 static inline unsigned int hw_txbyte(struct altera_spi *hw, int count) in hw_txbyte() argument
107 if (hw->tx) { in hw_txbyte()
108 switch (hw->bytes_per_word) { in hw_txbyte()
110 return hw->tx[count]; in hw_txbyte()
112 return (hw->tx[count * 2] in hw_txbyte()
113 | (hw->tx[count * 2 + 1] << 8)); in hw_txbyte()
121 struct altera_spi *hw = altera_spi_to_hw(spi); 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 writel(hw_txbyte(hw, 0), hw->base + ALTERA_SPI_TXDATA); in altera_spi_txrx()
137 wait_for_completion(&hw->done); in altera_spi_txrx()
139 hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_txrx()
140 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_txrx()
142 while (hw->count < hw->len) { in altera_spi_txrx()
145 writel(hw_txbyte(hw, hw->count), in altera_spi_txrx()
146 hw->base + ALTERA_SPI_TXDATA); in altera_spi_txrx()
148 while (!(readl(hw->base + ALTERA_SPI_STATUS) & in altera_spi_txrx()
152 rxd = readl(hw->base + ALTERA_SPI_RXDATA); in altera_spi_txrx()
153 if (hw->rx) { in altera_spi_txrx()
154 switch (hw->bytes_per_word) { in altera_spi_txrx()
156 hw->rx[hw->count] = rxd; in altera_spi_txrx()
159 hw->rx[hw->count * 2] = rxd; in altera_spi_txrx()
160 hw->rx[hw->count * 2 + 1] = rxd >> 8; in altera_spi_txrx()
165 hw->count++; in altera_spi_txrx()
169 return hw->count * hw->bytes_per_word; in altera_spi_txrx()
174 struct altera_spi *hw = dev; in altera_spi_irq() local
177 rxd = readl(hw->base + ALTERA_SPI_RXDATA); in altera_spi_irq()
178 if (hw->rx) { in altera_spi_irq()
179 switch (hw->bytes_per_word) { in altera_spi_irq()
181 hw->rx[hw->count] = rxd; in altera_spi_irq()
184 hw->rx[hw->count * 2] = rxd; in altera_spi_irq()
185 hw->rx[hw->count * 2 + 1] = rxd >> 8; in altera_spi_irq()
190 hw->count++; in altera_spi_irq()
192 if (hw->count < hw->len) in altera_spi_irq()
193 writel(hw_txbyte(hw, hw->count), hw->base + ALTERA_SPI_TXDATA); in altera_spi_irq()
195 complete(&hw->done); in altera_spi_irq()
202 struct altera_spi *hw; in altera_spi_probe() local
218 hw = spi_master_get_devdata(master); in altera_spi_probe()
219 platform_set_drvdata(pdev, hw); in altera_spi_probe()
222 hw->bitbang.master = master; in altera_spi_probe()
223 hw->bitbang.chipselect = altera_spi_chipsel; in altera_spi_probe()
224 hw->bitbang.txrx_bufs = altera_spi_txrx; in altera_spi_probe()
228 hw->base = devm_ioremap_resource(&pdev->dev, res); in altera_spi_probe()
229 if (IS_ERR(hw->base)) { in altera_spi_probe()
230 err = PTR_ERR(hw->base); in altera_spi_probe()
234 hw->imr = 0; /* disable spi interrupts */ in altera_spi_probe()
235 writel(hw->imr, hw->base + ALTERA_SPI_CONTROL); in altera_spi_probe()
236 writel(0, hw->base + ALTERA_SPI_STATUS); /* clear status reg */ in altera_spi_probe()
237 if (readl(hw->base + ALTERA_SPI_STATUS) & ALTERA_SPI_STATUS_RRDY_MSK) in altera_spi_probe()
238 readl(hw->base + ALTERA_SPI_RXDATA); /* flush rxdata */ in altera_spi_probe()
240 hw->irq = platform_get_irq(pdev, 0); in altera_spi_probe()
241 if (hw->irq >= 0) { in altera_spi_probe()
242 init_completion(&hw->done); in altera_spi_probe()
243 err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0, in altera_spi_probe()
244 pdev->name, hw); in altera_spi_probe()
250 err = spi_bitbang_start(&hw->bitbang); in altera_spi_probe()
253 dev_info(&pdev->dev, "base %p, irq %d\n", hw->base, hw->irq); in altera_spi_probe()
263 struct altera_spi *hw = platform_get_drvdata(dev); in altera_spi_remove() local
264 struct spi_master *master = hw->bitbang.master; in altera_spi_remove()
266 spi_bitbang_stop(&hw->bitbang); in altera_spi_remove()