Lines Matching +full:num +full:- +full:transfer +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0-or-later
61 * 1. 9-bit with the Data/Command signal as the ninth bit
62 * 2. Same as above except it's sent as 16 bits
63 * 3. 8-bit with the Data/Command signal as a separate D/CX pin
107 if (!dbi->read_commands) in mipi_dbi_command_is_read()
111 if (!dbi->read_commands[i]) in mipi_dbi_command_is_read()
113 if (cmd == dbi->read_commands[i]) in mipi_dbi_command_is_read()
121 * mipi_dbi_command_read - MIPI DCS read command
133 if (!dbi->read_commands) in mipi_dbi_command_read()
134 return -EACCES; in mipi_dbi_command_read()
137 return -EINVAL; in mipi_dbi_command_read()
144 * mipi_dbi_command_buf - MIPI DCS command with parameter(s) in an array
158 /* SPI requires dma-safe buffers */ in mipi_dbi_command_buf()
161 return -ENOMEM; in mipi_dbi_command_buf()
163 mutex_lock(&dbi->cmdlock); in mipi_dbi_command_buf()
164 ret = dbi->command(dbi, cmdbuf, data, len); in mipi_dbi_command_buf()
165 mutex_unlock(&dbi->cmdlock); in mipi_dbi_command_buf()
182 return -ENOMEM; in mipi_dbi_command_stackbuf()
193 * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
197 * @swap: When true, swap MSB/LSB of 16-bit values
219 switch (fb->format->format) { in mipi_dbi_buf_copy()
222 drm_fb_swab(&dst_map, NULL, data, fb, clip, !gem->import_attach); in mipi_dbi_buf_copy()
230 drm_err_once(fb->dev, "Format is not supported: %p4cc\n", in mipi_dbi_buf_copy()
231 &fb->format->format); in mipi_dbi_buf_copy()
232 ret = -EINVAL; in mipi_dbi_buf_copy()
247 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_set_window_address()
249 xs += dbidev->left_offset; in mipi_dbi_set_window_address()
250 xe += dbidev->left_offset; in mipi_dbi_set_window_address()
251 ys += dbidev->top_offset; in mipi_dbi_set_window_address()
252 ye += dbidev->top_offset; in mipi_dbi_set_window_address()
264 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); in mipi_dbi_fb_dirty()
265 unsigned int height = rect->y2 - rect->y1; in mipi_dbi_fb_dirty()
266 unsigned int width = rect->x2 - rect->x1; in mipi_dbi_fb_dirty()
267 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_fb_dirty()
268 bool swap = dbi->swap_bytes; in mipi_dbi_fb_dirty()
276 if (!drm_dev_enter(fb->dev, &idx)) in mipi_dbi_fb_dirty()
283 full = width == fb->width && height == fb->height; in mipi_dbi_fb_dirty()
285 DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect)); in mipi_dbi_fb_dirty()
287 if (!dbi->dc || !full || swap || in mipi_dbi_fb_dirty()
288 fb->format->format == DRM_FORMAT_XRGB8888) { in mipi_dbi_fb_dirty()
289 tr = dbidev->tx_buf; in mipi_dbi_fb_dirty()
290 ret = mipi_dbi_buf_copy(dbidev->tx_buf, fb, rect, swap); in mipi_dbi_fb_dirty()
297 mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1, in mipi_dbi_fb_dirty()
298 rect->y2 - 1); in mipi_dbi_fb_dirty()
304 drm_err_once(fb->dev, "Failed to update display %d\n", ret); in mipi_dbi_fb_dirty()
313 * mipi_dbi_pipe_mode_valid - MIPI DBI mode-valid helper
318 * display. Drivers can use this as their &drm_simple_display_pipe_funcs->mode_valid
324 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_mode_valid()
326 return drm_crtc_helper_mode_valid_fixed(&pipe->crtc, mode, &dbidev->mode); in mipi_dbi_pipe_mode_valid()
331 * mipi_dbi_pipe_update - Display pipe update helper
336 * this as their &drm_simple_display_pipe_funcs->update callback.
341 struct drm_plane_state *state = pipe->plane.state; in mipi_dbi_pipe_update()
344 if (!pipe->crtc.state->active) in mipi_dbi_pipe_update()
348 mipi_dbi_fb_dirty(state->fb, &rect); in mipi_dbi_pipe_update()
353 * mipi_dbi_enable_flush - MIPI DBI enable helper
359 * in their &drm_simple_display_pipe_funcs->enable callback.
369 struct drm_framebuffer *fb = plane_state->fb; in mipi_dbi_enable_flush()
372 .x2 = fb->width, in mipi_dbi_enable_flush()
374 .y2 = fb->height, in mipi_dbi_enable_flush()
378 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_enable_flush()
382 backlight_enable(dbidev->backlight); in mipi_dbi_enable_flush()
390 struct drm_device *drm = &dbidev->drm; in mipi_dbi_blank()
391 u16 height = drm->mode_config.min_height; in mipi_dbi_blank()
392 u16 width = drm->mode_config.min_width; in mipi_dbi_blank()
393 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_blank()
400 memset(dbidev->tx_buf, 0, len); in mipi_dbi_blank()
402 mipi_dbi_set_window_address(dbidev, 0, width - 1, 0, height - 1); in mipi_dbi_blank()
404 (u8 *)dbidev->tx_buf, len); in mipi_dbi_blank()
410 * mipi_dbi_pipe_disable - MIPI DBI pipe disable helper
415 * &drm_simple_display_pipe_funcs->disable callback.
419 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_disable()
423 if (dbidev->backlight) in mipi_dbi_pipe_disable()
424 backlight_disable(dbidev->backlight); in mipi_dbi_pipe_disable()
428 if (dbidev->regulator) in mipi_dbi_pipe_disable()
429 regulator_disable(dbidev->regulator); in mipi_dbi_pipe_disable()
435 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(connector->dev); in mipi_dbi_connector_get_modes()
437 return drm_connector_helper_get_modes_fixed(connector, &dbidev->mode); in mipi_dbi_connector_get_modes()
458 swap(mode->hdisplay, mode->vdisplay); in mipi_dbi_rotate_mode()
459 swap(mode->hsync_start, mode->vsync_start); in mipi_dbi_rotate_mode()
460 swap(mode->hsync_end, mode->vsync_end); in mipi_dbi_rotate_mode()
461 swap(mode->htotal, mode->vtotal); in mipi_dbi_rotate_mode()
462 swap(mode->width_mm, mode->height_mm); in mipi_dbi_rotate_mode()
465 return -EINVAL; in mipi_dbi_rotate_mode()
481 * mipi_dbi_dev_init_with_formats - MIPI DBI device initialization with custom formats
513 struct drm_device *drm = &dbidev->drm; in mipi_dbi_dev_init_with_formats()
516 if (!dbidev->dbi.command) in mipi_dbi_dev_init_with_formats()
517 return -EINVAL; in mipi_dbi_dev_init_with_formats()
523 dbidev->tx_buf = devm_kmalloc(drm->dev, tx_buf_size, GFP_KERNEL); in mipi_dbi_dev_init_with_formats()
524 if (!dbidev->tx_buf) in mipi_dbi_dev_init_with_formats()
525 return -ENOMEM; in mipi_dbi_dev_init_with_formats()
527 drm_mode_copy(&dbidev->mode, mode); in mipi_dbi_dev_init_with_formats()
528 ret = mipi_dbi_rotate_mode(&dbidev->mode, rotation); in mipi_dbi_dev_init_with_formats()
531 return -EINVAL; in mipi_dbi_dev_init_with_formats()
534 drm_connector_helper_add(&dbidev->connector, &mipi_dbi_connector_hfuncs); in mipi_dbi_dev_init_with_formats()
535 ret = drm_connector_init(drm, &dbidev->connector, &mipi_dbi_connector_funcs, in mipi_dbi_dev_init_with_formats()
540 ret = drm_simple_display_pipe_init(drm, &dbidev->pipe, funcs, formats, format_count, in mipi_dbi_dev_init_with_formats()
541 modifiers, &dbidev->connector); in mipi_dbi_dev_init_with_formats()
545 drm_plane_enable_fb_damage_clips(&dbidev->pipe.plane); in mipi_dbi_dev_init_with_formats()
547 drm->mode_config.funcs = &mipi_dbi_mode_config_funcs; in mipi_dbi_dev_init_with_formats()
548 drm->mode_config.min_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
549 drm->mode_config.max_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
550 drm->mode_config.min_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
551 drm->mode_config.max_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
552 dbidev->rotation = rotation; in mipi_dbi_dev_init_with_formats()
561 * mipi_dbi_dev_init - MIPI DBI device initialization
581 size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); in mipi_dbi_dev_init()
583 dbidev->drm.mode_config.preferred_depth = 16; in mipi_dbi_dev_init()
592 * mipi_dbi_hw_reset - Hardware reset of controller
595 * Reset controller if the &mipi_dbi->reset gpio is set.
599 if (!dbi->reset) in mipi_dbi_hw_reset()
602 gpiod_set_value_cansleep(dbi->reset, 0); in mipi_dbi_hw_reset()
604 gpiod_set_value_cansleep(dbi->reset, 1); in mipi_dbi_hw_reset()
610 * mipi_dbi_display_is_on - Check if display is on
643 struct device *dev = dbidev->drm.dev; in mipi_dbi_poweron_reset_conditional()
644 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_poweron_reset_conditional()
647 if (dbidev->regulator) { in mipi_dbi_poweron_reset_conditional()
648 ret = regulator_enable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
662 if (dbidev->regulator) in mipi_dbi_poweron_reset_conditional()
663 regulator_disable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
672 if (dbi->reset) in mipi_dbi_poweron_reset_conditional()
681 * mipi_dbi_poweron_reset - MIPI DBI poweron and reset
697 * mipi_dbi_poweron_conditional_reset - MIPI DBI poweron and conditional reset
717 * mipi_dbi_spi_cmd_max_speed - get the maximum SPI bus speed
719 * @len: The transfer buffer length.
723 * at 10MHz, preventing transfer glitches from messing up the init settings.
730 return min_t(u32, 10000000, spi->max_speed_hz); in mipi_dbi_spi_cmd_max_speed()
746 * If the SPI controller doesn't have 9 bits per word support,
747 * use blocks of 9 bytes to send 8x 9-bit words using a 8-bit SPI transfer.
766 size_t chunk, max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1e_transfer()
767 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1e_transfer()
769 .tx_buf = dbi->tx_buf9, in mipi_dbi_spi1e_transfer()
786 return -EINVAL; in mipi_dbi_spi1e_transfer()
788 /* Command: pad no-op's (zeroes) at beginning of block */ in mipi_dbi_spi1e_transfer()
789 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
808 len -= chunk; in mipi_dbi_spi1e_transfer()
809 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
814 /* Data: pad no-op's (zeroes) at end of block */ in mipi_dbi_spi1e_transfer()
820 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
821 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
824 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
825 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
832 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
833 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
883 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1_transfer()
898 max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1_transfer()
899 dst16 = dbi->tx_buf9; in mipi_dbi_spi1_transfer()
932 len -= chunk; in mipi_dbi_spi1_transfer()
945 struct spi_device *spi = dbi->spi; in mipi_dbi_typec1_command_read()
947 spi->max_speed_hz / 2); in mipi_dbi_typec1_command_read()
952 .tx_buf = dbi->tx_buf9, in mipi_dbi_typec1_command_read()
966 return -EINVAL; in mipi_dbi_typec1_command_read()
973 dev_err(&spi->dev, in mipi_dbi_typec1_command_read()
975 return -EOPNOTSUPP; in mipi_dbi_typec1_command_read()
980 * buffer. Only 9 bits of this will be used when executing the actual in mipi_dbi_typec1_command_read()
981 * transfer. in mipi_dbi_typec1_command_read()
983 dst16 = dbi->tx_buf9; in mipi_dbi_typec1_command_read()
996 u8 *parameters, size_t num) in mipi_dbi_typec1_command() argument
1002 return mipi_dbi_typec1_command_read(dbi, cmd, parameters, num); in mipi_dbi_typec1_command()
1004 MIPI_DBI_DEBUG_COMMAND(*cmd, parameters, num); in mipi_dbi_typec1_command()
1007 if (ret || !num) in mipi_dbi_typec1_command()
1010 return mipi_dbi_spi1_transfer(dbi, 1, parameters, num, bpw); in mipi_dbi_typec1_command()
1018 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command_read()
1020 spi->max_speed_hz / 2); in mipi_dbi_typec3_command_read()
1036 return -EINVAL; in mipi_dbi_typec3_command_read()
1039 * Support non-standard 24-bit and 32-bit Nokia read commands which in mipi_dbi_typec3_command_read()
1045 return -EINVAL; in mipi_dbi_typec3_command_read()
1052 return -ENOMEM; in mipi_dbi_typec3_command_read()
1055 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command_read()
1080 u8 *par, size_t num) in mipi_dbi_typec3_command() argument
1082 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command()
1088 return mipi_dbi_typec3_command_read(dbi, cmd, par, num); in mipi_dbi_typec3_command()
1090 MIPI_DBI_DEBUG_COMMAND(*cmd, par, num); in mipi_dbi_typec3_command()
1092 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command()
1095 if (ret || !num) in mipi_dbi_typec3_command()
1098 if (*cmd == MIPI_DCS_WRITE_MEMORY_START && !dbi->swap_bytes) in mipi_dbi_typec3_command()
1101 gpiod_set_value_cansleep(dbi->dc, 1); in mipi_dbi_typec3_command()
1102 speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num); in mipi_dbi_typec3_command()
1104 return mipi_dbi_spi_transfer(spi, speed_hz, bpw, par, num); in mipi_dbi_typec3_command()
1108 * mipi_dbi_spi_init - Initialize MIPI DBI SPI interface
1113 * This function sets &mipi_dbi->command, enables &mipi_dbi->read_commands for the
1115 * a driver-specific init.
1120 * If the SPI master driver doesn't support the necessary bits per word,
1123 * - 9-bit: reorder buffer as 9x 8-bit words, padded with no-op command.
1124 * - 16-bit: if big endian send as 8-bit, if little endian swap bytes
1132 struct device *dev = &spi->dev; in mipi_dbi_spi_init()
1141 * The virtual address is used in the transfer and the SPI core in mipi_dbi_spi_init()
1142 * re-maps it on the SPI master device using the DMA streaming API in mipi_dbi_spi_init()
1145 if (!dev->coherent_dma_mask) { in mipi_dbi_spi_init()
1153 dbi->spi = spi; in mipi_dbi_spi_init()
1154 dbi->read_commands = mipi_dbi_dcs_read_commands; in mipi_dbi_spi_init()
1157 dbi->command = mipi_dbi_typec3_command; in mipi_dbi_spi_init()
1158 dbi->dc = dc; in mipi_dbi_spi_init()
1160 dbi->swap_bytes = true; in mipi_dbi_spi_init()
1162 dbi->command = mipi_dbi_typec1_command; in mipi_dbi_spi_init()
1163 dbi->tx_buf9_len = SZ_16K; in mipi_dbi_spi_init()
1164 dbi->tx_buf9 = devm_kmalloc(dev, dbi->tx_buf9_len, GFP_KERNEL); in mipi_dbi_spi_init()
1165 if (!dbi->tx_buf9) in mipi_dbi_spi_init()
1166 return -ENOMEM; in mipi_dbi_spi_init()
1169 mutex_init(&dbi->cmdlock); in mipi_dbi_spi_init()
1171 DRM_DEBUG_DRIVER("SPI speed: %uMHz\n", spi->max_speed_hz / 1000000); in mipi_dbi_spi_init()
1178 * mipi_dbi_spi_transfer - SPI transfer helper
1181 * @bpw: Bits per word
1182 * @buf: Buffer to transfer
1185 * This SPI transfer helper breaks up the transfer of @buf into chunks which
1204 * are accepted (xfer->len % w_size must be zero). in mipi_dbi_spi_transfer()
1205 * Here we align max_chunk to multiple of 2 (16bits), in mipi_dbi_spi_transfer()
1218 len -= chunk; in mipi_dbi_spi_transfer()
1237 struct seq_file *m = file->private_data; in mipi_dbi_debugfs_command_write()
1238 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_write()
1243 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_write()
1244 return -ENODEV; in mipi_dbi_debugfs_command_write()
1253 for (i = count - 1; i > 0; i--) in mipi_dbi_debugfs_command_write()
1263 ret = -EINVAL; in mipi_dbi_debugfs_command_write()
1277 ret = -E2BIG; in mipi_dbi_debugfs_command_write()
1282 ret = mipi_dbi_command_buf(&dbidev->dbi, cmd, parameters, i); in mipi_dbi_debugfs_command_write()
1294 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_show()
1295 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_debugfs_command_show()
1300 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_show()
1301 return -ENODEV; in mipi_dbi_debugfs_command_show()
1341 inode->i_private); in mipi_dbi_debugfs_command_open()
1354 * mipi_dbi_debugfs_init - Create debugfs entries
1359 * Drivers can use this as their &drm_driver->debugfs_init callback.
1364 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(minor->dev); in mipi_dbi_debugfs_init()
1367 if (dbidev->dbi.read_commands) in mipi_dbi_debugfs_init()
1369 debugfs_create_file("command", mode, minor->debugfs_root, dbidev, in mipi_dbi_debugfs_init()