Lines Matching +full:ctx +full:- +full:gpios
5 * SPDX-License-Identifier: Apache-2.0
39 struct spi_context ctx; member
56 return -ENOMEM; in get_hw_block_num()
59 static uint8_t get_dfs_value(struct spi_context *ctx) in get_dfs_value() argument
61 switch (SPI_WORD_SIZE_GET(ctx->config->operation)) { in get_dfs_value()
75 struct ifx_cat1_spi_data *const data = dev->data; in transfer_chunk()
76 struct spi_context *ctx = &data->ctx; in transfer_chunk() local
78 size_t chunk_len = spi_context_max_continuous_chunk(ctx); in transfer_chunk()
84 data->chunk_len = chunk_len; in transfer_chunk()
87 &data->obj, ctx->tx_buf, spi_context_tx_buf_on(ctx) ? chunk_len : 0, ctx->rx_buf, in transfer_chunk()
88 spi_context_rx_buf_on(ctx) ? chunk_len : 0); in transfer_chunk()
93 ret = -EIO; in transfer_chunk()
96 spi_context_cs_control(ctx, false); in transfer_chunk()
97 spi_context_complete(ctx, dev, ret); in transfer_chunk()
103 struct ifx_cat1_spi_data *const data = dev->data; in spi_interrupt_callback()
104 struct spi_context *ctx = &data->ctx; in spi_interrupt_callback() local
108 cyhal_spi_abort_async(&data->obj); in spi_interrupt_callback()
110 spi_context_cs_control(ctx, false); in spi_interrupt_callback()
111 spi_context_complete(ctx, dev, -EIO); in spi_interrupt_callback()
115 spi_context_update_tx(ctx, data->dfs_value, data->chunk_len); in spi_interrupt_callback()
116 spi_context_update_rx(ctx, data->dfs_value, data->chunk_len); in spi_interrupt_callback()
125 struct ifx_cat1_spi_data *const data = dev->data; in spi_config()
126 const struct ifx_cat1_spi_config *const config = dev->config; in spi_config()
127 cy_stc_scb_spi_config_t scb_spi_config = config->scb_spi_config; in spi_config()
128 struct spi_context *ctx = &data->ctx; in spi_config() local
133 if (spi_context_configured(ctx, spi_cfg)) { in spi_config()
138 if (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_LOOP) { in spi_config()
139 return -ENOTSUP; in spi_config()
142 if (SPI_WORD_SIZE_GET(spi_cfg->operation) > IFX_CAT1_SPI_MAX_DATA_WIDTH) { in spi_config()
143 LOG_ERR("Word size %d is greater than %d", SPI_WORD_SIZE_GET(spi_cfg->operation), in spi_config()
145 return -EINVAL; in spi_config()
148 if (SPI_WORD_SIZE_GET(spi_cfg->operation) < IFX_CAT1_SPI_MIN_DATA_WIDTH) { in spi_config()
149 LOG_ERR("Word size %d is less than %d", SPI_WORD_SIZE_GET(spi_cfg->operation), in spi_config()
151 return -EINVAL; in spi_config()
154 if (SPI_OP_MODE_GET(spi_cfg->operation) == SPI_OP_MODE_SLAVE) { in spi_config()
162 if (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPOL) { in spi_config()
166 if (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPHA) { in spi_config()
170 if (SPI_WORD_SIZE_GET(spi_cfg->operation)) { in spi_config()
171 scb_spi_config.txDataWidth = SPI_WORD_SIZE_GET(spi_cfg->operation); in spi_config()
172 scb_spi_config.rxDataWidth = SPI_WORD_SIZE_GET(spi_cfg->operation); in spi_config()
183 scb_spi_config.enableMsbFirst = (spi_cfg->operation & SPI_TRANSFER_LSB) ? false : true; in spi_config()
186 if (data->obj.base != NULL) { in spi_config()
187 cyhal_spi_free(&data->obj); in spi_config()
191 cyhal_spi_configurator_t spi_init_cfg = {.resource = &data->hw_resource, in spi_config()
193 .gpios = {NC, {NC, NC, NC, NC}, NC, NC}}; in spi_config()
195 result = cyhal_spi_init_cfg(&data->obj, &spi_init_cfg); in spi_config()
197 return -ENOTSUP; in spi_config()
201 en_clk_dst_t clk_idx = _cyhal_scb_get_clock_index(spi_init_cfg.resource->block_num); in spi_config()
203 result = _cyhal_utils_peri_pclk_assign_divider(clk_idx, &data->obj.clock); in spi_config()
205 return -ENOTSUP; in spi_config()
209 if (SPI_OP_MODE_GET(spi_cfg->operation) == SPI_OP_MODE_SLAVE) { in spi_config()
210 Cy_SCB_SPI_SetActiveSlaveSelectPolarity(data->obj.base, CY_SCB_SPI_SLAVE_SELECT0, in spi_config()
215 result = cyhal_spi_set_frequency(&data->obj, spi_cfg->frequency); in spi_config()
217 return -EIO; in spi_config()
221 data->obj.write_fill = 0; in spi_config()
224 cyhal_spi_register_callback(&data->obj, spi_interrupt_callback, (void *)dev); in spi_config()
225 cyhal_spi_enable_event(&data->obj, CYHAL_SPI_IRQ_DONE, config->irq_priority, true); in spi_config()
228 ctx->config = spi_cfg; in spi_config()
230 data->dfs_value = get_dfs_value(ctx); in spi_config()
240 struct ifx_cat1_spi_data *const data = dev->data; in transceive()
241 struct spi_context *ctx = &data->ctx; in transceive() local
243 spi_context_lock(ctx, asynchronous, cb, userdata, spi_cfg); in transceive()
251 spi_context_buffers_setup(ctx, tx_bufs, rx_bufs, data->dfs_value); in transceive()
253 spi_context_cs_control(ctx, true); in transceive()
257 result = spi_context_wait_for_completion(&data->ctx); in transceive()
259 spi_context_release(ctx, result); in transceive()
283 struct ifx_cat1_spi_data *const data = dev->data; in ifx_cat1_spi_release()
285 cyhal_spi_free(&data->obj); in ifx_cat1_spi_release()
303 struct ifx_cat1_spi_data *const data = dev->data; in ifx_cat1_spi_init()
304 const struct ifx_cat1_spi_config *const config = dev->config; in ifx_cat1_spi_init()
308 data->hw_resource.type = CYHAL_RSC_SCB; in ifx_cat1_spi_init()
309 data->hw_resource.block_num = get_hw_block_num(config->reg_addr); in ifx_cat1_spi_init()
312 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in ifx_cat1_spi_init()
318 spi_context_cs_configure_all(&data->ctx); in ifx_cat1_spi_init()
320 spi_context_unlock_unconditionally(&data->ctx); in ifx_cat1_spi_init()
328 SPI_CONTEXT_INIT_LOCK(spi_cat1_data_##n, ctx), \
329 SPI_CONTEXT_INIT_SYNC(spi_cat1_data_##n, ctx), \
330 SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx)}; \