Lines Matching refs:ddata

93 #define ddata_to_dev(ddata)	(&(ddata->bitbang.master->dev))  argument
94 #define efm32_spi_vdbg(ddata, format, arg...) \ argument
95 dev_vdbg(ddata_to_dev(ddata), format, ##arg)
97 static void efm32_spi_write32(struct efm32_spi_ddata *ddata, in efm32_spi_write32() argument
100 writel_relaxed(value, ddata->base + offset); in efm32_spi_write32()
103 static u32 efm32_spi_read32(struct efm32_spi_ddata *ddata, unsigned offset) in efm32_spi_read32() argument
105 return readl_relaxed(ddata->base + offset); in efm32_spi_read32()
110 struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master); in efm32_spi_chipselect() local
113 gpio_set_value(ddata->csgpio[spi->chip_select], value); in efm32_spi_chipselect()
119 struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master); in efm32_spi_setup_transfer() local
123 unsigned long clkfreq = clk_get_rate(ddata->clk); in efm32_spi_setup_transfer()
126 efm32_spi_write32(ddata, REG_CTRL_SYNC | REG_CTRL_MSBF | in efm32_spi_setup_transfer()
130 efm32_spi_write32(ddata, in efm32_spi_setup_transfer()
141 efm32_spi_write32(ddata, clkdiv, REG_CLKDIV); in efm32_spi_setup_transfer()
142 efm32_spi_write32(ddata, REG_CMD_MASTEREN, REG_CMD); in efm32_spi_setup_transfer()
143 efm32_spi_write32(ddata, REG_CMD_RXEN | REG_CMD_TXEN, REG_CMD); in efm32_spi_setup_transfer()
148 static void efm32_spi_tx_u8(struct efm32_spi_ddata *ddata) in efm32_spi_tx_u8() argument
152 if (ddata->tx_buf) { in efm32_spi_tx_u8()
153 val = *ddata->tx_buf; in efm32_spi_tx_u8()
154 ddata->tx_buf++; in efm32_spi_tx_u8()
157 ddata->tx_len--; in efm32_spi_tx_u8()
158 efm32_spi_write32(ddata, val, REG_TXDATA); in efm32_spi_tx_u8()
159 efm32_spi_vdbg(ddata, "%s: tx 0x%x\n", __func__, val); in efm32_spi_tx_u8()
162 static void efm32_spi_rx_u8(struct efm32_spi_ddata *ddata) in efm32_spi_rx_u8() argument
164 u32 rxdata = efm32_spi_read32(ddata, REG_RXDATAX); in efm32_spi_rx_u8()
165 efm32_spi_vdbg(ddata, "%s: rx 0x%x\n", __func__, rxdata); in efm32_spi_rx_u8()
167 if (ddata->rx_buf) { in efm32_spi_rx_u8()
168 *ddata->rx_buf = rxdata; in efm32_spi_rx_u8()
169 ddata->rx_buf++; in efm32_spi_rx_u8()
172 ddata->rx_len--; in efm32_spi_rx_u8()
175 static void efm32_spi_filltx(struct efm32_spi_ddata *ddata) in efm32_spi_filltx() argument
177 while (ddata->tx_len && in efm32_spi_filltx()
178 ddata->tx_len + 2 > ddata->rx_len && in efm32_spi_filltx()
179 efm32_spi_read32(ddata, REG_STATUS) & REG_STATUS_TXBL) { in efm32_spi_filltx()
180 efm32_spi_tx_u8(ddata); in efm32_spi_filltx()
186 struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master); in efm32_spi_txrx_bufs() local
189 spin_lock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
191 if (ddata->tx_buf || ddata->rx_buf) in efm32_spi_txrx_bufs()
194 ddata->tx_buf = t->tx_buf; in efm32_spi_txrx_bufs()
195 ddata->rx_buf = t->rx_buf; in efm32_spi_txrx_bufs()
196 ddata->tx_len = ddata->rx_len = in efm32_spi_txrx_bufs()
199 efm32_spi_filltx(ddata); in efm32_spi_txrx_bufs()
201 reinit_completion(&ddata->done); in efm32_spi_txrx_bufs()
203 efm32_spi_write32(ddata, REG_IF_TXBL | REG_IF_RXDATAV, REG_IEN); in efm32_spi_txrx_bufs()
205 spin_unlock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
207 wait_for_completion(&ddata->done); in efm32_spi_txrx_bufs()
209 spin_lock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
211 ret = t->len - max(ddata->tx_len, ddata->rx_len); in efm32_spi_txrx_bufs()
213 efm32_spi_write32(ddata, 0, REG_IEN); in efm32_spi_txrx_bufs()
214 ddata->tx_buf = ddata->rx_buf = NULL; in efm32_spi_txrx_bufs()
217 spin_unlock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
224 struct efm32_spi_ddata *ddata = data; in efm32_spi_rxirq() local
227 spin_lock(&ddata->lock); in efm32_spi_rxirq()
229 while (ddata->rx_len > 0 && in efm32_spi_rxirq()
230 efm32_spi_read32(ddata, REG_STATUS) & in efm32_spi_rxirq()
232 efm32_spi_rx_u8(ddata); in efm32_spi_rxirq()
237 if (!ddata->rx_len) { in efm32_spi_rxirq()
238 u32 ien = efm32_spi_read32(ddata, REG_IEN); in efm32_spi_rxirq()
242 efm32_spi_write32(ddata, ien, REG_IEN); in efm32_spi_rxirq()
244 complete(&ddata->done); in efm32_spi_rxirq()
247 spin_unlock(&ddata->lock); in efm32_spi_rxirq()
254 struct efm32_spi_ddata *ddata = data; in efm32_spi_txirq() local
256 efm32_spi_vdbg(ddata, in efm32_spi_txirq()
258 __func__, ddata->tx_len, ddata->rx_len, in efm32_spi_txirq()
259 efm32_spi_read32(ddata, REG_IF), in efm32_spi_txirq()
260 efm32_spi_read32(ddata, REG_STATUS)); in efm32_spi_txirq()
262 spin_lock(&ddata->lock); in efm32_spi_txirq()
264 efm32_spi_filltx(ddata); in efm32_spi_txirq()
266 efm32_spi_vdbg(ddata, "%s: txlen = %u, rxlen = %u\n", in efm32_spi_txirq()
267 __func__, ddata->tx_len, ddata->rx_len); in efm32_spi_txirq()
269 if (!ddata->tx_len) { in efm32_spi_txirq()
270 u32 ien = efm32_spi_read32(ddata, REG_IEN); in efm32_spi_txirq()
274 efm32_spi_write32(ddata, ien, REG_IEN); in efm32_spi_txirq()
275 efm32_spi_vdbg(ddata, "disable TXBL\n"); in efm32_spi_txirq()
278 spin_unlock(&ddata->lock); in efm32_spi_txirq()
283 static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata) in efm32_spi_get_configured_location() argument
285 u32 reg = efm32_spi_read32(ddata, REG_ROUTE); in efm32_spi_get_configured_location()
291 struct spi_master *master, struct efm32_spi_ddata *ddata) in efm32_spi_probe_dt() argument
311 location = efm32_spi_get_configured_location(ddata); in efm32_spi_probe_dt()
316 ddata->pdata.location = location; in efm32_spi_probe_dt()
321 struct efm32_spi_ddata *ddata; in efm32_spi_probe() local
336 sizeof(*ddata) + num_cs * sizeof(unsigned)); in efm32_spi_probe()
350 ddata = spi_master_get_devdata(master); in efm32_spi_probe()
352 ddata->bitbang.master = master; in efm32_spi_probe()
353 ddata->bitbang.chipselect = efm32_spi_chipselect; in efm32_spi_probe()
354 ddata->bitbang.setup_transfer = efm32_spi_setup_transfer; in efm32_spi_probe()
355 ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs; in efm32_spi_probe()
357 spin_lock_init(&ddata->lock); in efm32_spi_probe()
358 init_completion(&ddata->done); in efm32_spi_probe()
360 ddata->clk = devm_clk_get(&pdev->dev, NULL); in efm32_spi_probe()
361 if (IS_ERR(ddata->clk)) { in efm32_spi_probe()
362 ret = PTR_ERR(ddata->clk); in efm32_spi_probe()
374 ddata->csgpio[i] = ret; in efm32_spi_probe()
375 dev_dbg(&pdev->dev, "csgpio#%u = %u\n", i, ddata->csgpio[i]); in efm32_spi_probe()
376 ret = devm_gpio_request_one(&pdev->dev, ddata->csgpio[i], in efm32_spi_probe()
399 ddata->base = devm_ioremap_resource(&pdev->dev, res); in efm32_spi_probe()
400 if (IS_ERR(ddata->base)) { in efm32_spi_probe()
401 ret = PTR_ERR(ddata->base); in efm32_spi_probe()
411 ddata->rxirq = ret; in efm32_spi_probe()
415 ret = ddata->rxirq + 1; in efm32_spi_probe()
417 ddata->txirq = ret; in efm32_spi_probe()
419 ret = clk_prepare_enable(ddata->clk); in efm32_spi_probe()
425 efm32_spi_probe_dt(pdev, master, ddata); in efm32_spi_probe()
427 efm32_spi_write32(ddata, 0, REG_IEN); in efm32_spi_probe()
428 efm32_spi_write32(ddata, REG_ROUTE_TXPEN | REG_ROUTE_RXPEN | in efm32_spi_probe()
430 REG_ROUTE_LOCATION(ddata->pdata.location), REG_ROUTE); in efm32_spi_probe()
432 ret = request_irq(ddata->rxirq, efm32_spi_rxirq, in efm32_spi_probe()
433 0, DRIVER_NAME " rx", ddata); in efm32_spi_probe()
439 ret = request_irq(ddata->txirq, efm32_spi_txirq, in efm32_spi_probe()
440 0, DRIVER_NAME " tx", ddata); in efm32_spi_probe()
446 ret = spi_bitbang_start(&ddata->bitbang); in efm32_spi_probe()
450 free_irq(ddata->txirq, ddata); in efm32_spi_probe()
452 free_irq(ddata->rxirq, ddata); in efm32_spi_probe()
454 clk_disable_unprepare(ddata->clk); in efm32_spi_probe()
465 struct efm32_spi_ddata *ddata = spi_master_get_devdata(master); in efm32_spi_remove() local
467 spi_bitbang_stop(&ddata->bitbang); in efm32_spi_remove()
469 efm32_spi_write32(ddata, 0, REG_IEN); in efm32_spi_remove()
471 free_irq(ddata->txirq, ddata); in efm32_spi_remove()
472 free_irq(ddata->rxirq, ddata); in efm32_spi_remove()
473 clk_disable_unprepare(ddata->clk); in efm32_spi_remove()