Lines Matching refs:hw

43 static int altr_spi_writel(struct altera_spi *hw, unsigned int reg,  in altr_spi_writel()  argument
48 ret = regmap_write(hw->regmap, hw->regoff + reg, val); in altr_spi_writel()
50 dev_err(hw->dev, "fail to write reg 0x%x val 0x%x: %d\n", in altr_spi_writel()
56 static int altr_spi_readl(struct altera_spi *hw, unsigned int reg, in altr_spi_readl() argument
61 ret = regmap_read(hw->regmap, hw->regoff + reg, val); in altr_spi_readl()
63 dev_err(hw->dev, "fail to read reg 0x%x: %d\n", reg, ret); in altr_spi_readl()
75 struct altera_spi *hw = altera_spi_to_hw(spi); in altera_spi_set_cs() local
78 hw->imr &= ~ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_set_cs()
79 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_set_cs()
80 altr_spi_writel(hw, ALTERA_SPI_TARGET_SEL, 0); in altera_spi_set_cs()
82 altr_spi_writel(hw, ALTERA_SPI_TARGET_SEL, in altera_spi_set_cs()
84 hw->imr |= ALTERA_SPI_CONTROL_SSO_MSK; in altera_spi_set_cs()
85 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_set_cs()
89 static void altera_spi_tx_word(struct altera_spi *hw) in altera_spi_tx_word() argument
93 if (hw->tx) { in altera_spi_tx_word()
94 switch (hw->bytes_per_word) { in altera_spi_tx_word()
96 txd = hw->tx[hw->count]; in altera_spi_tx_word()
99 txd = (hw->tx[hw->count * 2] in altera_spi_tx_word()
100 | (hw->tx[hw->count * 2 + 1] << 8)); in altera_spi_tx_word()
103 txd = (hw->tx[hw->count * 4] in altera_spi_tx_word()
104 | (hw->tx[hw->count * 4 + 1] << 8) in altera_spi_tx_word()
105 | (hw->tx[hw->count * 4 + 2] << 16) in altera_spi_tx_word()
106 | (hw->tx[hw->count * 4 + 3] << 24)); in altera_spi_tx_word()
112 altr_spi_writel(hw, ALTERA_SPI_TXDATA, txd); in altera_spi_tx_word()
115 static void altera_spi_rx_word(struct altera_spi *hw) in altera_spi_rx_word() argument
119 altr_spi_readl(hw, ALTERA_SPI_RXDATA, &rxd); in altera_spi_rx_word()
120 if (hw->rx) { in altera_spi_rx_word()
121 switch (hw->bytes_per_word) { in altera_spi_rx_word()
123 hw->rx[hw->count] = rxd; in altera_spi_rx_word()
126 hw->rx[hw->count * 2] = rxd; in altera_spi_rx_word()
127 hw->rx[hw->count * 2 + 1] = rxd >> 8; in altera_spi_rx_word()
130 hw->rx[hw->count * 4] = rxd; in altera_spi_rx_word()
131 hw->rx[hw->count * 4 + 1] = rxd >> 8; in altera_spi_rx_word()
132 hw->rx[hw->count * 4 + 2] = rxd >> 16; in altera_spi_rx_word()
133 hw->rx[hw->count * 4 + 3] = rxd >> 24; in altera_spi_rx_word()
139 hw->count++; in altera_spi_rx_word()
145 struct altera_spi *hw = spi_controller_get_devdata(host); in altera_spi_txrx() local
148 hw->tx = t->tx_buf; in altera_spi_txrx()
149 hw->rx = t->rx_buf; in altera_spi_txrx()
150 hw->count = 0; in altera_spi_txrx()
151 hw->bytes_per_word = DIV_ROUND_UP(t->bits_per_word, 8); in altera_spi_txrx()
152 hw->len = t->len / hw->bytes_per_word; in altera_spi_txrx()
154 if (hw->irq >= 0) { in altera_spi_txrx()
156 hw->imr |= ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_txrx()
157 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_txrx()
160 altera_spi_tx_word(hw); in altera_spi_txrx()
165 while (hw->count < hw->len) { in altera_spi_txrx()
166 altera_spi_tx_word(hw); in altera_spi_txrx()
169 altr_spi_readl(hw, ALTERA_SPI_STATUS, &val); in altera_spi_txrx()
176 altera_spi_rx_word(hw); in altera_spi_txrx()
186 struct altera_spi *hw = spi_controller_get_devdata(host); in altera_spi_irq() local
188 altera_spi_rx_word(hw); in altera_spi_irq()
190 if (hw->count < hw->len) { in altera_spi_irq()
191 altera_spi_tx_word(hw); in altera_spi_irq()
194 hw->imr &= ~ALTERA_SPI_CONTROL_IRRDY_MSK; in altera_spi_irq()
195 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_irq()
206 struct altera_spi *hw = spi_controller_get_devdata(host); in altera_spi_init_host() local
213 hw->imr = 0; /* disable spi interrupts */ in altera_spi_init_host()
214 altr_spi_writel(hw, ALTERA_SPI_CONTROL, hw->imr); in altera_spi_init_host()
215 altr_spi_writel(hw, ALTERA_SPI_STATUS, 0); /* clear status reg */ in altera_spi_init_host()
216 altr_spi_readl(hw, ALTERA_SPI_STATUS, &val); in altera_spi_init_host()
218 altr_spi_readl(hw, ALTERA_SPI_RXDATA, &val); /* flush rxdata */ in altera_spi_init_host()