Lines Matching refs:ddata
86 #define ddata_to_dev(ddata) (&(ddata->bitbang.master->dev)) argument
87 #define efm32_spi_vdbg(ddata, format, arg...) \ argument
88 dev_vdbg(ddata_to_dev(ddata), format, ##arg)
90 static void efm32_spi_write32(struct efm32_spi_ddata *ddata, in efm32_spi_write32() argument
93 writel_relaxed(value, ddata->base + offset); in efm32_spi_write32()
96 static u32 efm32_spi_read32(struct efm32_spi_ddata *ddata, unsigned offset) in efm32_spi_read32() argument
98 return readl_relaxed(ddata->base + offset); in efm32_spi_read32()
104 struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master); in efm32_spi_setup_transfer() local
108 unsigned long clkfreq = clk_get_rate(ddata->clk); in efm32_spi_setup_transfer()
111 efm32_spi_write32(ddata, REG_CTRL_SYNC | REG_CTRL_MSBF | in efm32_spi_setup_transfer()
115 efm32_spi_write32(ddata, in efm32_spi_setup_transfer()
126 efm32_spi_write32(ddata, clkdiv, REG_CLKDIV); in efm32_spi_setup_transfer()
127 efm32_spi_write32(ddata, REG_CMD_MASTEREN, REG_CMD); in efm32_spi_setup_transfer()
128 efm32_spi_write32(ddata, REG_CMD_RXEN | REG_CMD_TXEN, REG_CMD); in efm32_spi_setup_transfer()
133 static void efm32_spi_tx_u8(struct efm32_spi_ddata *ddata) in efm32_spi_tx_u8() argument
137 if (ddata->tx_buf) { in efm32_spi_tx_u8()
138 val = *ddata->tx_buf; in efm32_spi_tx_u8()
139 ddata->tx_buf++; in efm32_spi_tx_u8()
142 ddata->tx_len--; in efm32_spi_tx_u8()
143 efm32_spi_write32(ddata, val, REG_TXDATA); in efm32_spi_tx_u8()
144 efm32_spi_vdbg(ddata, "%s: tx 0x%x\n", __func__, val); in efm32_spi_tx_u8()
147 static void efm32_spi_rx_u8(struct efm32_spi_ddata *ddata) in efm32_spi_rx_u8() argument
149 u32 rxdata = efm32_spi_read32(ddata, REG_RXDATAX); in efm32_spi_rx_u8()
150 efm32_spi_vdbg(ddata, "%s: rx 0x%x\n", __func__, rxdata); in efm32_spi_rx_u8()
152 if (ddata->rx_buf) { in efm32_spi_rx_u8()
153 *ddata->rx_buf = rxdata; in efm32_spi_rx_u8()
154 ddata->rx_buf++; in efm32_spi_rx_u8()
157 ddata->rx_len--; in efm32_spi_rx_u8()
160 static void efm32_spi_filltx(struct efm32_spi_ddata *ddata) in efm32_spi_filltx() argument
162 while (ddata->tx_len && in efm32_spi_filltx()
163 ddata->tx_len + 2 > ddata->rx_len && in efm32_spi_filltx()
164 efm32_spi_read32(ddata, REG_STATUS) & REG_STATUS_TXBL) { in efm32_spi_filltx()
165 efm32_spi_tx_u8(ddata); in efm32_spi_filltx()
171 struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master); in efm32_spi_txrx_bufs() local
174 spin_lock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
176 if (ddata->tx_buf || ddata->rx_buf) in efm32_spi_txrx_bufs()
179 ddata->tx_buf = t->tx_buf; in efm32_spi_txrx_bufs()
180 ddata->rx_buf = t->rx_buf; in efm32_spi_txrx_bufs()
181 ddata->tx_len = ddata->rx_len = in efm32_spi_txrx_bufs()
184 efm32_spi_filltx(ddata); in efm32_spi_txrx_bufs()
186 reinit_completion(&ddata->done); in efm32_spi_txrx_bufs()
188 efm32_spi_write32(ddata, REG_IF_TXBL | REG_IF_RXDATAV, REG_IEN); in efm32_spi_txrx_bufs()
190 spin_unlock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
192 wait_for_completion(&ddata->done); in efm32_spi_txrx_bufs()
194 spin_lock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
196 ret = t->len - max(ddata->tx_len, ddata->rx_len); in efm32_spi_txrx_bufs()
198 efm32_spi_write32(ddata, 0, REG_IEN); in efm32_spi_txrx_bufs()
199 ddata->tx_buf = ddata->rx_buf = NULL; in efm32_spi_txrx_bufs()
202 spin_unlock_irq(&ddata->lock); in efm32_spi_txrx_bufs()
209 struct efm32_spi_ddata *ddata = data; in efm32_spi_rxirq() local
212 spin_lock(&ddata->lock); in efm32_spi_rxirq()
214 while (ddata->rx_len > 0 && in efm32_spi_rxirq()
215 efm32_spi_read32(ddata, REG_STATUS) & in efm32_spi_rxirq()
217 efm32_spi_rx_u8(ddata); in efm32_spi_rxirq()
222 if (!ddata->rx_len) { in efm32_spi_rxirq()
223 u32 ien = efm32_spi_read32(ddata, REG_IEN); in efm32_spi_rxirq()
227 efm32_spi_write32(ddata, ien, REG_IEN); in efm32_spi_rxirq()
229 complete(&ddata->done); in efm32_spi_rxirq()
232 spin_unlock(&ddata->lock); in efm32_spi_rxirq()
239 struct efm32_spi_ddata *ddata = data; in efm32_spi_txirq() local
241 efm32_spi_vdbg(ddata, in efm32_spi_txirq()
243 __func__, ddata->tx_len, ddata->rx_len, in efm32_spi_txirq()
244 efm32_spi_read32(ddata, REG_IF), in efm32_spi_txirq()
245 efm32_spi_read32(ddata, REG_STATUS)); in efm32_spi_txirq()
247 spin_lock(&ddata->lock); in efm32_spi_txirq()
249 efm32_spi_filltx(ddata); in efm32_spi_txirq()
251 efm32_spi_vdbg(ddata, "%s: txlen = %u, rxlen = %u\n", in efm32_spi_txirq()
252 __func__, ddata->tx_len, ddata->rx_len); in efm32_spi_txirq()
254 if (!ddata->tx_len) { in efm32_spi_txirq()
255 u32 ien = efm32_spi_read32(ddata, REG_IEN); in efm32_spi_txirq()
259 efm32_spi_write32(ddata, ien, REG_IEN); in efm32_spi_txirq()
260 efm32_spi_vdbg(ddata, "disable TXBL\n"); in efm32_spi_txirq()
263 spin_unlock(&ddata->lock); in efm32_spi_txirq()
268 static u32 efm32_spi_get_configured_location(struct efm32_spi_ddata *ddata) in efm32_spi_get_configured_location() argument
270 u32 reg = efm32_spi_read32(ddata, REG_ROUTE); in efm32_spi_get_configured_location()
276 struct spi_master *master, struct efm32_spi_ddata *ddata) in efm32_spi_probe_dt() argument
296 location = efm32_spi_get_configured_location(ddata); in efm32_spi_probe_dt()
301 ddata->pdata.location = location; in efm32_spi_probe_dt()
306 struct efm32_spi_ddata *ddata; in efm32_spi_probe() local
315 master = spi_alloc_master(&pdev->dev, sizeof(*ddata)); in efm32_spi_probe()
329 ddata = spi_master_get_devdata(master); in efm32_spi_probe()
331 ddata->bitbang.master = master; in efm32_spi_probe()
332 ddata->bitbang.setup_transfer = efm32_spi_setup_transfer; in efm32_spi_probe()
333 ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs; in efm32_spi_probe()
335 spin_lock_init(&ddata->lock); in efm32_spi_probe()
336 init_completion(&ddata->done); in efm32_spi_probe()
338 ddata->clk = devm_clk_get(&pdev->dev, NULL); in efm32_spi_probe()
339 if (IS_ERR(ddata->clk)) { in efm32_spi_probe()
340 ret = PTR_ERR(ddata->clk); in efm32_spi_probe()
358 ddata->base = devm_ioremap_resource(&pdev->dev, res); in efm32_spi_probe()
359 if (IS_ERR(ddata->base)) { in efm32_spi_probe()
360 ret = PTR_ERR(ddata->base); in efm32_spi_probe()
368 ddata->rxirq = ret; in efm32_spi_probe()
372 ret = ddata->rxirq + 1; in efm32_spi_probe()
374 ddata->txirq = ret; in efm32_spi_probe()
376 ret = clk_prepare_enable(ddata->clk); in efm32_spi_probe()
382 efm32_spi_probe_dt(pdev, master, ddata); in efm32_spi_probe()
384 efm32_spi_write32(ddata, 0, REG_IEN); in efm32_spi_probe()
385 efm32_spi_write32(ddata, REG_ROUTE_TXPEN | REG_ROUTE_RXPEN | in efm32_spi_probe()
387 REG_ROUTE_LOCATION(ddata->pdata.location), REG_ROUTE); in efm32_spi_probe()
389 ret = request_irq(ddata->rxirq, efm32_spi_rxirq, in efm32_spi_probe()
390 0, DRIVER_NAME " rx", ddata); in efm32_spi_probe()
396 ret = request_irq(ddata->txirq, efm32_spi_txirq, in efm32_spi_probe()
397 0, DRIVER_NAME " tx", ddata); in efm32_spi_probe()
403 ret = spi_bitbang_start(&ddata->bitbang); in efm32_spi_probe()
407 free_irq(ddata->txirq, ddata); in efm32_spi_probe()
409 free_irq(ddata->rxirq, ddata); in efm32_spi_probe()
411 clk_disable_unprepare(ddata->clk); in efm32_spi_probe()
422 struct efm32_spi_ddata *ddata = spi_master_get_devdata(master); in efm32_spi_remove() local
424 spi_bitbang_stop(&ddata->bitbang); in efm32_spi_remove()
426 efm32_spi_write32(ddata, 0, REG_IEN); in efm32_spi_remove()
428 free_irq(ddata->txirq, ddata); in efm32_spi_remove()
429 free_irq(ddata->rxirq, ddata); in efm32_spi_remove()
430 clk_disable_unprepare(ddata->clk); in efm32_spi_remove()