Lines Matching full:hw
74 static int altr_spi_writel(struct altera_spi *hw, unsigned int reg, in altr_spi_writel() argument
79 ret = regmap_write(hw->regmap, hw->regoff + reg, val); in altr_spi_writel()
81 dev_err(hw->dev, "fail to write reg 0x%x val 0x%x: %d\n", in altr_spi_writel()
87 static int altr_spi_readl(struct altera_spi *hw, unsigned int reg, in altr_spi_readl() argument
92 ret = regmap_read(hw->regmap, hw->regoff + reg, val); in altr_spi_readl()
94 dev_err(hw->dev, "fail to read reg 0x%x: %d\n", reg, ret); in altr_spi_readl()
106 struct altera_spi *hw = altera_spi_to_hw(spi); in altera_spi_set_cs() local
109 hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_set_cs()
110 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_set_cs()
111 altr_spi_writel(hw, ALTERA_SPI_SLAVE_SEL, 0); in altera_spi_set_cs()
113 altr_spi_writel(hw, ALTERA_SPI_SLAVE_SEL, in altera_spi_set_cs()
115 hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_set_cs()
116 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_set_cs()
120 static void altera_spi_tx_word(struct altera_spi *hw) in altera_spi_tx_word() argument
124 if (hw->tx) { in altera_spi_tx_word()
125 switch (hw->bytes_per_word) { in altera_spi_tx_word()
127 txd = hw->tx[hw->count]; in altera_spi_tx_word()
130 txd = (hw->tx[hw->count * 2] in altera_spi_tx_word()
131 | (hw->tx[hw->count * 2 + 1] << 8)); in altera_spi_tx_word()
134 txd = (hw->tx[hw->count * 4] in altera_spi_tx_word()
135 | (hw->tx[hw->count * 4 + 1] << 8) in altera_spi_tx_word()
136 | (hw->tx[hw->count * 4 + 2] << 16) in altera_spi_tx_word()
137 | (hw->tx[hw->count * 4 + 3] << 24)); in altera_spi_tx_word()
143 altr_spi_writel(hw, ALTERA_SPI_TXDATA, txd); in altera_spi_tx_word()
146 static void altera_spi_rx_word(struct altera_spi *hw) in altera_spi_rx_word() argument
150 altr_spi_readl(hw, ALTERA_SPI_RXDATA, &rxd); in altera_spi_rx_word()
151 if (hw->rx) { in altera_spi_rx_word()
152 switch (hw->bytes_per_word) { in altera_spi_rx_word()
154 hw->rx[hw->count] = rxd; in altera_spi_rx_word()
157 hw->rx[hw->count * 2] = rxd; in altera_spi_rx_word()
158 hw->rx[hw->count * 2 + 1] = rxd >> 8; in altera_spi_rx_word()
161 hw->rx[hw->count * 4] = rxd; in altera_spi_rx_word()
162 hw->rx[hw->count * 4 + 1] = rxd >> 8; in altera_spi_rx_word()
163 hw->rx[hw->count * 4 + 2] = rxd >> 16; in altera_spi_rx_word()
164 hw->rx[hw->count * 4 + 3] = rxd >> 24; in altera_spi_rx_word()
170 hw->count++; in altera_spi_rx_word()
176 struct altera_spi *hw = spi_master_get_devdata(master); in altera_spi_txrx() local
179 hw->tx = t->tx_buf; in altera_spi_txrx()
180 hw->rx = t->rx_buf; in altera_spi_txrx()
181 hw->count = 0; in altera_spi_txrx()
182 hw->bytes_per_word = DIV_ROUND_UP(t->bits_per_word, 8); in altera_spi_txrx()
183 hw->len = t->len / hw->bytes_per_word; in altera_spi_txrx()
185 if (hw->irq >= 0) { in altera_spi_txrx()
187 hw->imr |= ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_txrx()
188 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_txrx()
191 altera_spi_tx_word(hw); in altera_spi_txrx()
193 while (hw->count < hw->len) { in altera_spi_txrx()
194 altera_spi_tx_word(hw); in altera_spi_txrx()
197 altr_spi_readl(hw, ALTERA_SPI_STATUS, &val); in altera_spi_txrx()
204 altera_spi_rx_word(hw); in altera_spi_txrx()
215 struct altera_spi *hw = spi_master_get_devdata(master); in altera_spi_irq() local
217 altera_spi_rx_word(hw); in altera_spi_irq()
219 if (hw->count < hw->len) { in altera_spi_irq()
220 altera_spi_tx_word(hw); in altera_spi_irq()
223 hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_irq()
224 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_irq()
237 struct altera_spi *hw; in altera_spi_probe() local
271 hw = spi_master_get_devdata(master); in altera_spi_probe()
272 hw->dev = &pdev->dev; in altera_spi_probe()
281 hw->regmap = dev_get_regmap(pdev->dev.parent, NULL); in altera_spi_probe()
282 if (!hw->regmap) { in altera_spi_probe()
289 hw->regoff = regoff->start; in altera_spi_probe()
299 hw->regmap = devm_regmap_init_mmio(&pdev->dev, res, in altera_spi_probe()
301 if (IS_ERR(hw->regmap)) { in altera_spi_probe()
303 err = PTR_ERR(hw->regmap); in altera_spi_probe()
309 hw->imr = 0; /* disable spi interrupts */ in altera_spi_probe()
310 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_probe()
311 altr_spi_writel(hw, ALTERA_SPI_STATUS, 0); /* clear status reg */ in altera_spi_probe()
312 altr_spi_readl(hw, ALTERA_SPI_STATUS, &val); in altera_spi_probe()
314 altr_spi_readl(hw, ALTERA_SPI_RXDATA, &val); /* flush rxdata */ in altera_spi_probe()
316 hw->irq = platform_get_irq(pdev, 0); in altera_spi_probe()
317 if (hw->irq >= 0) { in altera_spi_probe()
318 err = devm_request_irq(&pdev->dev, hw->irq, altera_spi_irq, 0, in altera_spi_probe()
337 dev_info(&pdev->dev, "regoff %u, irq %d\n", hw->regoff, hw->irq); in altera_spi_probe()