Lines Matching +full:gpiote +full:- +full:instance
2 * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
4 * SPDX-License-Identifier: Apache-2.0
102 struct spi_nrfx_data *dev_data = dev->data; in request_clock()
103 const struct spi_nrfx_config *dev_config = dev->config; in request_clock()
106 if (!dev_config->clk_dev) { in request_clock()
111 dev_config->clk_dev, &dev_config->clk_spec, in request_clock()
118 dev_data->clock_requested = true; in request_clock()
129 struct spi_nrfx_data *dev_data = dev->data; in release_clock()
130 const struct spi_nrfx_config *dev_config = dev->config; in release_clock()
132 if (!dev_data->clock_requested) { in release_clock()
136 dev_data->clock_requested = false; in release_clock()
138 nrf_clock_control_release(dev_config->clk_dev, &dev_config->clk_spec); in release_clock()
146 struct spi_nrfx_data *dev_data = dev->data; in finalize_spi_transaction()
147 const struct spi_nrfx_config *dev_config = dev->config; in finalize_spi_transaction()
148 void *reg = dev_config->spim.p_reg; in finalize_spi_transaction()
151 spi_context_cs_control(&dev_data->ctx, false); in finalize_spi_transaction()
154 if (NRF_SPIM_IS_320MHZ_SPIM(reg) && !(dev_data->ctx.config->operation & SPI_HOLD_ON_CS)) { in finalize_spi_transaction()
219 struct spi_nrfx_data *dev_data = dev->data; in configure()
220 const struct spi_nrfx_config *dev_config = dev->config; in configure()
221 struct spi_context *ctx = &dev_data->ctx; in configure()
222 uint32_t max_freq = dev_config->max_freq; in configure()
227 if (dev_data->initialized && spi_context_configured(ctx, spi_cfg)) { in configure()
232 if (spi_cfg->operation & SPI_HALF_DUPLEX) { in configure()
233 LOG_ERR("Half-duplex not supported"); in configure()
234 return -ENOTSUP; in configure()
237 if (SPI_OP_MODE_GET(spi_cfg->operation) != SPI_OP_MODE_MASTER) { in configure()
238 LOG_ERR("Slave mode is not supported on %s", dev->name); in configure()
239 return -EINVAL; in configure()
242 if (spi_cfg->operation & SPI_MODE_LOOP) { in configure()
244 return -EINVAL; in configure()
248 (spi_cfg->operation & SPI_LINES_MASK) != SPI_LINES_SINGLE) { in configure()
250 return -EINVAL; in configure()
253 if (SPI_WORD_SIZE_GET(spi_cfg->operation) != 8) { in configure()
255 return -EINVAL; in configure()
258 if (spi_cfg->frequency < 125000) { in configure()
260 return -EINVAL; in configure()
274 config = dev_config->def_config; in configure()
276 /* Limit the frequency to that supported by the SPIM instance. */ in configure()
277 config.frequency = get_nrf_spim_frequency(MIN(spi_cfg->frequency, in configure()
279 config.mode = get_nrf_spim_mode(spi_cfg->operation); in configure()
280 config.bit_order = get_nrf_spim_bit_order(spi_cfg->operation); in configure()
282 sck_pin = nrfy_spim_sck_pin_get(dev_config->spim.p_reg); in configure()
285 nrfy_gpio_pin_write(sck_pin, spi_cfg->operation & SPI_MODE_CPOL ? 1 : 0); in configure()
288 if (dev_data->initialized) { in configure()
289 nrfx_spim_uninit(&dev_config->spim); in configure()
290 dev_data->initialized = false; in configure()
293 result = nrfx_spim_init(&dev_config->spim, &config, in configure()
297 return -EIO; in configure()
300 dev_data->initialized = true; in configure()
302 ctx->config = spi_cfg; in configure()
308 static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(0); variable
319 * channel and the GPIOTE channel before attempting to transmit multiple
324 struct spi_nrfx_data *dev_data = dev->data; in anomaly_58_workaround_setup()
325 const struct spi_nrfx_config *dev_config = dev->config; in anomaly_58_workaround_setup()
326 NRF_SPIM_Type *spim = dev_config->spim.p_reg; in anomaly_58_workaround_setup()
327 uint32_t ppi_ch = dev_data->ppi_ch; in anomaly_58_workaround_setup()
328 uint32_t gpiote_ch = dev_data->gpiote_ch; in anomaly_58_workaround_setup()
329 uint32_t eep = (uint32_t)&gpiote.p_reg->EVENTS_IN[gpiote_ch]; in anomaly_58_workaround_setup()
330 uint32_t tep = (uint32_t)&spim->TASKS_STOP; in anomaly_58_workaround_setup()
332 dev_data->anomaly_58_workaround_active = true; in anomaly_58_workaround_setup()
335 nrf_gpiote_event_configure(gpiote.p_reg, gpiote_ch, spim->PSEL.SCK, in anomaly_58_workaround_setup()
337 nrf_gpiote_event_enable(gpiote.p_reg, gpiote_ch); in anomaly_58_workaround_setup()
339 /* Stop the spim instance when SCK toggles */ in anomaly_58_workaround_setup()
343 /* The spim instance cannot be stopped mid-byte, so it will finish in anomaly_58_workaround_setup()
351 uint32_t ppi_ch = dev_data->ppi_ch; in anomaly_58_workaround_clear()
352 uint32_t gpiote_ch = dev_data->gpiote_ch; in anomaly_58_workaround_clear()
354 if (dev_data->anomaly_58_workaround_active) { in anomaly_58_workaround_clear()
356 nrf_gpiote_task_disable(gpiote.p_reg, gpiote_ch); in anomaly_58_workaround_clear()
358 dev_data->anomaly_58_workaround_active = false; in anomaly_58_workaround_clear()
364 struct spi_nrfx_data *dev_data = dev->data; in anomaly_58_workaround_init()
365 const struct spi_nrfx_config *dev_config = dev->config; in anomaly_58_workaround_init()
368 dev_data->anomaly_58_workaround_active = false; in anomaly_58_workaround_init()
370 if (dev_config->anomaly_58_workaround) { in anomaly_58_workaround_init()
371 err_code = nrfx_ppi_channel_alloc(&dev_data->ppi_ch); in anomaly_58_workaround_init()
374 return -ENODEV; in anomaly_58_workaround_init()
377 err_code = nrfx_gpiote_channel_alloc(&gpiote, &dev_data->gpiote_ch); in anomaly_58_workaround_init()
379 LOG_ERR("Failed to allocate GPIOTE channel"); in anomaly_58_workaround_init()
380 return -ENODEV; in anomaly_58_workaround_init()
382 LOG_DBG("PAN 58 workaround enabled for %s: ppi %u, gpiote %u", in anomaly_58_workaround_init()
383 dev->name, dev_data->ppi_ch, dev_data->gpiote_ch); in anomaly_58_workaround_init()
392 struct spi_nrfx_data *dev_data = dev->data; in finish_transaction()
393 struct spi_context *ctx = &dev_data->ctx; in finish_transaction()
398 dev_data->busy = false; in finish_transaction()
405 struct spi_nrfx_data *dev_data = dev->data; in transfer_next_chunk()
406 const struct spi_nrfx_config *dev_config = dev->config; in transfer_next_chunk()
407 struct spi_context *ctx = &dev_data->ctx; in transfer_next_chunk()
415 const uint8_t *tx_buf = ctx->tx_buf; in transfer_next_chunk()
416 uint8_t *rx_buf = ctx->rx_buf; in transfer_next_chunk()
418 if (chunk_len > dev_config->max_chunk_len) { in transfer_next_chunk()
419 chunk_len = dev_config->max_chunk_len; in transfer_next_chunk()
424 !nrf_dma_accessible_check(&dev_config->spim.p_reg, tx_buf)) { in transfer_next_chunk()
430 memcpy(dev_data->tx_buffer, tx_buf, chunk_len); in transfer_next_chunk()
432 if (dev_config->mem_attr & DT_MEM_CACHEABLE) { in transfer_next_chunk()
433 sys_cache_data_flush_range(dev_data->tx_buffer, chunk_len); in transfer_next_chunk()
436 tx_buf = dev_data->tx_buffer; in transfer_next_chunk()
440 !nrf_dma_accessible_check(&dev_config->spim.p_reg, rx_buf)) { in transfer_next_chunk()
446 rx_buf = dev_data->rx_buffer; in transfer_next_chunk()
450 dev_data->chunk_len = chunk_len; in transfer_next_chunk()
459 if (dev_config->anomaly_58_workaround) { in transfer_next_chunk()
464 error = -EIO; in transfer_next_chunk()
469 result = nrfx_spim_xfer(&dev_config->spim, &xfer, 0); in transfer_next_chunk()
473 error = -EIO; in transfer_next_chunk()
486 struct spi_nrfx_data *dev_data = dev->data; in event_handler()
488 const struct spi_nrfx_config *dev_config = dev->config; in event_handler()
491 if (p_event->type == NRFX_SPIM_EVENT_DONE) { in event_handler()
495 if (dev_data->chunk_len == 0) { in event_handler()
496 finish_transaction(dev_data->dev, -ETIMEDOUT); in event_handler()
504 if (spi_context_rx_buf_on(&dev_data->ctx) && in event_handler()
505 p_event->xfer_desc.p_rx_buffer != NULL && in event_handler()
506 p_event->xfer_desc.p_rx_buffer != dev_data->ctx.rx_buf) { in event_handler()
508 if (dev_config->mem_attr & DT_MEM_CACHEABLE) { in event_handler()
509 sys_cache_data_invd_range(dev_data->rx_buffer, dev_data->chunk_len); in event_handler()
512 (void)memcpy(dev_data->ctx.rx_buf, in event_handler()
513 dev_data->rx_buffer, in event_handler()
514 dev_data->chunk_len); in event_handler()
517 spi_context_update_tx(&dev_data->ctx, 1, dev_data->chunk_len); in event_handler()
518 spi_context_update_rx(&dev_data->ctx, 1, dev_data->chunk_len); in event_handler()
520 transfer_next_chunk(dev_data->dev); in event_handler()
532 struct spi_nrfx_data *dev_data = dev->data; in transceive()
533 const struct spi_nrfx_config *dev_config = dev->config; in transceive()
534 void *reg = dev_config->spim.p_reg; in transceive()
538 spi_context_lock(&dev_data->ctx, asynchronous, cb, userdata, spi_cfg); in transceive()
547 dev_data->busy = true; in transceive()
549 if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { in transceive()
550 error = spi_nrfx_wake_request(&dev_config->wake_gpiote, in transceive()
551 dev_config->wake_pin); in transceive()
552 if (error == -ETIMEDOUT) { in transceive()
562 spi_context_buffers_setup(&dev_data->ctx, tx_bufs, rx_bufs, 1); in transceive()
566 spi_context_cs_control(&dev_data->ctx, true); in transceive()
570 error = spi_context_wait_for_completion(&dev_data->ctx); in transceive()
571 if (error == -ETIMEDOUT) { in transceive()
576 dev_data->chunk_len = 0; in transceive()
580 nrfx_spim_uninit(&dev_config->spim); in transceive()
581 dev_data->initialized = false; in transceive()
587 finish_transaction(dev, -ETIMEDOUT); in transceive()
590 k_sem_reset(&dev_data->ctx.sync); in transceive()
601 spi_context_release(&dev_data->ctx, error); in transceive()
629 struct spi_nrfx_data *dev_data = dev->data; in spi_nrfx_release()
631 if (!spi_context_configured(&dev_data->ctx, spi_cfg)) { in spi_nrfx_release()
632 return -EINVAL; in spi_nrfx_release()
635 if (dev_data->busy) { in spi_nrfx_release()
636 return -EBUSY; in spi_nrfx_release()
639 spi_context_unlock_unconditionally(&dev_data->ctx); in spi_nrfx_release()
658 const struct spi_nrfx_config *dev_config = dev->config; in spim_resume()
660 (void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); in spim_resume()
666 nrf_gpd_retain_pins_set(dev_config->pcfg, false); in spim_resume()
674 const struct spi_nrfx_config *dev_config = dev->config; in spim_suspend()
675 struct spi_nrfx_data *dev_data = dev->data; in spim_suspend()
677 if (dev_data->initialized) { in spim_suspend()
678 nrfx_spim_uninit(&dev_config->spim); in spim_suspend()
679 dev_data->initialized = false; in spim_suspend()
687 nrf_gpd_retain_pins_set(dev_config->pcfg, true); in spim_suspend()
690 (void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); in spim_suspend()
700 return -ENOTSUP; in spim_nrfx_pm_action()
708 const struct spi_nrfx_config *dev_config = dev->config; in spi_nrfx_init()
709 struct spi_nrfx_data *dev_data = dev->data; in spi_nrfx_init()
712 err = pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_DEFAULT); in spi_nrfx_init()
717 if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { in spi_nrfx_init()
718 err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin); in spi_nrfx_init()
719 if (err == -ENODEV) { in spi_nrfx_init()
720 LOG_ERR("Failed to allocate GPIOTE channel for WAKE"); in spi_nrfx_init()
723 if (err == -EIO) { in spi_nrfx_init()
729 dev_config->irq_connect(); in spi_nrfx_init()
731 err = spi_context_cs_configure_all(&dev_data->ctx); in spi_nrfx_init()
736 spi_context_unlock_unconditionally(&dev_data->ctx); in spi_nrfx_init()
748 * functions which are named according to SoC peripheral instance