Lines Matching +full:out +full:- +full:gpio
5 * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/drivers/gpio.h>
21 /* Command/Data gpio */
23 /* Reset GPIO */
35 /* Expands to 1 if the node does not have the `write-only` property */
38 /* This macro will evaluate to 1 if any of the nodes with zephyr,mipi-dbi-spi
39 * lack a `write-only` property. The intention here is to allow the entire
40 * command_read function to be optimized out when it is not needed.
45 /* Expands to 1 if the node does reflect the enum in `xfr-min-bits` property */
49 /* This macros will evaluate to 1 if any of the nodes with zephyr,mipi-dbi-spi
50 * have the `xfr-min-bits` property to corresponding enum value. The intention
51 * here is to allow the write helper functions to be optimized out when not all
71 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_write_helper_3wire()
72 struct mipi_dbi_spi_data *data = dev->data; in mipi_dbi_spi_write_helper_3wire()
85 if ((dbi_config->config.operation & SPI_WORD_SIZE_MASK) in mipi_dbi_spi_write_helper_3wire()
87 return -ENOTSUP; in mipi_dbi_spi_write_helper_3wire()
89 buffer.buf = &data->spi_byte; in mipi_dbi_spi_write_helper_3wire()
94 data->spi_byte = cmd; in mipi_dbi_spi_write_helper_3wire()
95 ret = spi_write(config->spi_dev, &dbi_config->config, &buf_set); in mipi_dbi_spi_write_helper_3wire()
97 goto out; in mipi_dbi_spi_write_helper_3wire()
102 data->spi_byte = MIPI_DBI_DC_BIT | data_buf[i]; in mipi_dbi_spi_write_helper_3wire()
103 ret = spi_write(config->spi_dev, &dbi_config->config, &buf_set); in mipi_dbi_spi_write_helper_3wire()
105 goto out; in mipi_dbi_spi_write_helper_3wire()
108 out: in mipi_dbi_spi_write_helper_3wire()
120 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_write_helper_4wire_8bit()
130 * command/data GPIO to indicate if we are sending in mipi_dbi_spi_write_helper_4wire_8bit()
139 gpio_pin_set_dt(&config->cmd_data, 0); in mipi_dbi_spi_write_helper_4wire_8bit()
140 ret = spi_write(config->spi_dev, &dbi_config->config, &buf_set); in mipi_dbi_spi_write_helper_4wire_8bit()
142 goto out; in mipi_dbi_spi_write_helper_4wire_8bit()
151 gpio_pin_set_dt(&config->cmd_data, 1); in mipi_dbi_spi_write_helper_4wire_8bit()
152 ret = spi_write(config->spi_dev, &dbi_config->config, &buf_set); in mipi_dbi_spi_write_helper_4wire_8bit()
154 goto out; in mipi_dbi_spi_write_helper_4wire_8bit()
157 out: in mipi_dbi_spi_write_helper_4wire_8bit()
171 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_write_helper_4wire_16bit()
181 * 4 wire mode with toggle the command/data GPIO in mipi_dbi_spi_write_helper_4wire_16bit()
183 * but send 16-bit blocks (with bit stuffing). in mipi_dbi_spi_write_helper_4wire_16bit()
192 gpio_pin_set_dt(&config->cmd_data, 0); in mipi_dbi_spi_write_helper_4wire_16bit()
193 ret = spi_write(config->spi_dev, &dbi_config->config, in mipi_dbi_spi_write_helper_4wire_16bit()
196 goto out; in mipi_dbi_spi_write_helper_4wire_16bit()
201 gpio_pin_set_dt(&config->cmd_data, 1); in mipi_dbi_spi_write_helper_4wire_16bit()
208 ret = spi_write(config->spi_dev, &dbi_config->config, in mipi_dbi_spi_write_helper_4wire_16bit()
211 goto out; in mipi_dbi_spi_write_helper_4wire_16bit()
219 gpio_pin_set_dt(&config->cmd_data, 1); in mipi_dbi_spi_write_helper_4wire_16bit()
223 if (len - stuffing > 0) { in mipi_dbi_spi_write_helper_4wire_16bit()
225 buffer.len = len - stuffing; in mipi_dbi_spi_write_helper_4wire_16bit()
227 ret = spi_write(config->spi_dev, &dbi_config->config, in mipi_dbi_spi_write_helper_4wire_16bit()
230 goto out; in mipi_dbi_spi_write_helper_4wire_16bit()
235 for (int i = len - stuffing; i < len; i++) { in mipi_dbi_spi_write_helper_4wire_16bit()
240 ret = spi_write(config->spi_dev, &dbi_config->config, in mipi_dbi_spi_write_helper_4wire_16bit()
243 goto out; in mipi_dbi_spi_write_helper_4wire_16bit()
247 out: in mipi_dbi_spi_write_helper_4wire_16bit()
258 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_write_helper()
259 struct mipi_dbi_spi_data *data = dev->data; in mipi_dbi_spi_write_helper()
262 ret = k_mutex_lock(&data->lock, K_FOREVER); in mipi_dbi_spi_write_helper()
267 if (dbi_config->mode == MIPI_DBI_MODE_SPI_3WIRE && in mipi_dbi_spi_write_helper()
272 goto out; in mipi_dbi_spi_write_helper()
275 if (dbi_config->mode == MIPI_DBI_MODE_SPI_4WIRE) { in mipi_dbi_spi_write_helper()
278 if (config->xfr_min_bits == MIPI_DBI_SPI_XFR_8BIT) { in mipi_dbi_spi_write_helper()
283 goto out; in mipi_dbi_spi_write_helper()
288 if (config->xfr_min_bits == MIPI_DBI_SPI_XFR_16BIT) { in mipi_dbi_spi_write_helper()
293 goto out; in mipi_dbi_spi_write_helper()
300 ret = -ENOTSUP; in mipi_dbi_spi_write_helper()
302 out: in mipi_dbi_spi_write_helper()
303 k_mutex_unlock(&data->lock); in mipi_dbi_spi_write_helper()
325 framebuf, desc->buf_size); in mipi_dbi_spi_write_display()
336 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_read_helper_3wire()
337 struct mipi_dbi_spi_data *data = dev->data; in mipi_dbi_spi_read_helper_3wire()
352 if ((dbi_config->config.operation & SPI_WORD_SIZE_MASK) in mipi_dbi_spi_read_helper_3wire()
354 return -ENOTSUP; in mipi_dbi_spi_read_helper_3wire()
357 memcpy(&tmp_config, &dbi_config->config, sizeof(tmp_config)); in mipi_dbi_spi_read_helper_3wire()
361 buffer.buf = &data->spi_byte; in mipi_dbi_spi_read_helper_3wire()
366 data->spi_byte = cmds[i]; in mipi_dbi_spi_read_helper_3wire()
367 ret = spi_write(config->spi_dev, &tmp_config, &buf_set); in mipi_dbi_spi_read_helper_3wire()
369 goto out; in mipi_dbi_spi_read_helper_3wire()
376 ret = spi_read(config->spi_dev, &dbi_config->config, &buf_set); in mipi_dbi_spi_read_helper_3wire()
378 out: in mipi_dbi_spi_read_helper_3wire()
379 spi_release(config->spi_dev, &tmp_config); /* Really necessary here? */ in mipi_dbi_spi_read_helper_3wire()
389 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_read_helper_4wire()
400 * command/data GPIO to indicate if we are sending in mipi_dbi_spi_read_helper_4wire()
406 memcpy(&tmp_config, &dbi_config->config, sizeof(tmp_config)); in mipi_dbi_spi_read_helper_4wire()
414 gpio_pin_set_dt(&config->cmd_data, 0); in mipi_dbi_spi_read_helper_4wire()
416 ret = spi_write(config->spi_dev, &tmp_config, &buf_set); in mipi_dbi_spi_read_helper_4wire()
418 goto out; in mipi_dbi_spi_read_helper_4wire()
427 gpio_pin_set_dt(&config->cmd_data, 1); in mipi_dbi_spi_read_helper_4wire()
429 ret = spi_read(config->spi_dev, &tmp_config, &buf_set); in mipi_dbi_spi_read_helper_4wire()
431 goto out; in mipi_dbi_spi_read_helper_4wire()
435 out: in mipi_dbi_spi_read_helper_4wire()
436 spi_release(config->spi_dev, &tmp_config); in mipi_dbi_spi_read_helper_4wire()
445 struct mipi_dbi_spi_data *data = dev->data; in mipi_dbi_spi_command_read()
448 ret = k_mutex_lock(&data->lock, K_FOREVER); in mipi_dbi_spi_command_read()
452 if (dbi_config->mode == MIPI_DBI_MODE_SPI_3WIRE && in mipi_dbi_spi_command_read()
458 goto out; in mipi_dbi_spi_command_read()
460 } else if (dbi_config->mode == MIPI_DBI_MODE_SPI_4WIRE) { in mipi_dbi_spi_command_read()
465 goto out; in mipi_dbi_spi_command_read()
469 ret = -ENOTSUP; in mipi_dbi_spi_command_read()
471 out: in mipi_dbi_spi_command_read()
472 k_mutex_unlock(&data->lock); in mipi_dbi_spi_command_read()
480 return spec->port != NULL; in mipi_dbi_has_pin()
485 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_reset()
488 if (!mipi_dbi_has_pin(&config->reset)) { in mipi_dbi_spi_reset()
489 return -ENOTSUP; in mipi_dbi_spi_reset()
492 ret = gpio_pin_set_dt(&config->reset, 1); in mipi_dbi_spi_reset()
497 return gpio_pin_set_dt(&config->reset, 0); in mipi_dbi_spi_reset()
503 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_release()
505 return spi_release(config->spi_dev, &dbi_config->config); in mipi_dbi_spi_release()
510 const struct mipi_dbi_spi_config *config = dev->config; in mipi_dbi_spi_init()
511 struct mipi_dbi_spi_data *data = dev->data; in mipi_dbi_spi_init()
514 if (!device_is_ready(config->spi_dev)) { in mipi_dbi_spi_init()
516 return -ENODEV; in mipi_dbi_spi_init()
519 if (mipi_dbi_has_pin(&config->cmd_data)) { in mipi_dbi_spi_init()
520 if (!gpio_is_ready_dt(&config->cmd_data)) { in mipi_dbi_spi_init()
521 return -ENODEV; in mipi_dbi_spi_init()
523 ret = gpio_pin_configure_dt(&config->cmd_data, GPIO_OUTPUT); in mipi_dbi_spi_init()
525 LOG_ERR("Could not configure command/data GPIO (%d)", ret); in mipi_dbi_spi_init()
530 if (mipi_dbi_has_pin(&config->reset)) { in mipi_dbi_spi_init()
531 if (!gpio_is_ready_dt(&config->reset)) { in mipi_dbi_spi_init()
532 return -ENODEV; in mipi_dbi_spi_init()
534 ret = gpio_pin_configure_dt(&config->reset, GPIO_OUTPUT_INACTIVE); in mipi_dbi_spi_init()
536 LOG_ERR("Could not configure reset GPIO (%d)", ret); in mipi_dbi_spi_init()
541 k_mutex_init(&data->lock); in mipi_dbi_spi_init()