Lines Matching +full:num +full:- +full:transfer +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0-or-later
62 * 1. 9-bit with the Data/Command signal as the ninth bit
63 * 2. Same as above except it's sent as 16 bits
64 * 3. 8-bit with the Data/Command signal as a separate D/CX pin
108 if (!dbi->read_commands) in mipi_dbi_command_is_read()
112 if (!dbi->read_commands[i]) in mipi_dbi_command_is_read()
114 if (cmd == dbi->read_commands[i]) in mipi_dbi_command_is_read()
122 * mipi_dbi_command_read - MIPI DCS read command
134 if (!dbi->read_commands) in mipi_dbi_command_read()
135 return -EACCES; in mipi_dbi_command_read()
138 return -EINVAL; in mipi_dbi_command_read()
145 * mipi_dbi_command_buf - MIPI DCS command with parameter(s) in an array
159 /* SPI requires dma-safe buffers */ in mipi_dbi_command_buf()
162 return -ENOMEM; in mipi_dbi_command_buf()
164 mutex_lock(&dbi->cmdlock); in mipi_dbi_command_buf()
165 ret = dbi->command(dbi, cmdbuf, data, len); in mipi_dbi_command_buf()
166 mutex_unlock(&dbi->cmdlock); in mipi_dbi_command_buf()
183 return -ENOMEM; in mipi_dbi_command_stackbuf()
194 * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
199 * @swap: When true, swap MSB/LSB of 16-bit values
200 * @fmtcnv_state: Format-conversion state
217 switch (fb->format->format) { in mipi_dbi_buf_copy()
220 drm_fb_swab(&dst_map, NULL, src, fb, clip, !gem->import_attach, in mipi_dbi_buf_copy()
229 drm_err_once(fb->dev, "Format is not supported: %p4cc\n", in mipi_dbi_buf_copy()
230 &fb->format->format); in mipi_dbi_buf_copy()
231 ret = -EINVAL; in mipi_dbi_buf_copy()
244 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_set_window_address()
246 xs += dbidev->left_offset; in mipi_dbi_set_window_address()
247 xe += dbidev->left_offset; in mipi_dbi_set_window_address()
248 ys += dbidev->top_offset; in mipi_dbi_set_window_address()
249 ye += dbidev->top_offset; in mipi_dbi_set_window_address()
260 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); in mipi_dbi_fb_dirty()
261 unsigned int height = rect->y2 - rect->y1; in mipi_dbi_fb_dirty()
262 unsigned int width = rect->x2 - rect->x1; in mipi_dbi_fb_dirty()
263 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_fb_dirty()
264 bool swap = dbi->swap_bytes; in mipi_dbi_fb_dirty()
269 full = width == fb->width && height == fb->height; in mipi_dbi_fb_dirty()
271 DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect)); in mipi_dbi_fb_dirty()
273 if (!dbi->dc || !full || swap || in mipi_dbi_fb_dirty()
274 fb->format->format == DRM_FORMAT_XRGB8888) { in mipi_dbi_fb_dirty()
275 tr = dbidev->tx_buf; in mipi_dbi_fb_dirty()
280 tr = src->vaddr; /* TODO: Use mapping abstraction properly */ in mipi_dbi_fb_dirty()
283 mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1, in mipi_dbi_fb_dirty()
284 rect->y2 - 1); in mipi_dbi_fb_dirty()
290 drm_err_once(fb->dev, "Failed to update display %d\n", ret); in mipi_dbi_fb_dirty()
294 * mipi_dbi_pipe_mode_valid - MIPI DBI mode-valid helper
299 * display. Drivers can use this as their &drm_simple_display_pipe_funcs->mode_valid
305 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_mode_valid()
307 return drm_crtc_helper_mode_valid_fixed(&pipe->crtc, mode, &dbidev->mode); in mipi_dbi_pipe_mode_valid()
312 * mipi_dbi_pipe_update - Display pipe update helper
317 * this as their &drm_simple_display_pipe_funcs->update callback.
322 struct drm_plane_state *state = pipe->plane.state; in mipi_dbi_pipe_update()
324 struct drm_framebuffer *fb = state->fb; in mipi_dbi_pipe_update()
328 if (!pipe->crtc.state->active) in mipi_dbi_pipe_update()
334 if (!drm_dev_enter(fb->dev, &idx)) in mipi_dbi_pipe_update()
338 mipi_dbi_fb_dirty(&shadow_plane_state->data[0], fb, &rect, in mipi_dbi_pipe_update()
339 &shadow_plane_state->fmtcnv_state); in mipi_dbi_pipe_update()
346 * mipi_dbi_enable_flush - MIPI DBI enable helper
352 * in their &drm_simple_display_pipe_funcs->enable callback.
363 struct drm_framebuffer *fb = plane_state->fb; in mipi_dbi_enable_flush()
366 .x2 = fb->width, in mipi_dbi_enable_flush()
368 .y2 = fb->height, in mipi_dbi_enable_flush()
372 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_enable_flush()
375 mipi_dbi_fb_dirty(&shadow_plane_state->data[0], fb, &rect, in mipi_dbi_enable_flush()
376 &shadow_plane_state->fmtcnv_state); in mipi_dbi_enable_flush()
377 backlight_enable(dbidev->backlight); in mipi_dbi_enable_flush()
385 struct drm_device *drm = &dbidev->drm; in mipi_dbi_blank()
386 u16 height = drm->mode_config.min_height; in mipi_dbi_blank()
387 u16 width = drm->mode_config.min_width; in mipi_dbi_blank()
388 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_blank()
395 memset(dbidev->tx_buf, 0, len); in mipi_dbi_blank()
397 mipi_dbi_set_window_address(dbidev, 0, width - 1, 0, height - 1); in mipi_dbi_blank()
399 (u8 *)dbidev->tx_buf, len); in mipi_dbi_blank()
405 * mipi_dbi_pipe_disable - MIPI DBI pipe disable helper
410 * &drm_simple_display_pipe_funcs->disable callback.
414 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_disable()
418 if (dbidev->backlight) in mipi_dbi_pipe_disable()
419 backlight_disable(dbidev->backlight); in mipi_dbi_pipe_disable()
423 if (dbidev->regulator) in mipi_dbi_pipe_disable()
424 regulator_disable(dbidev->regulator); in mipi_dbi_pipe_disable()
425 if (dbidev->io_regulator) in mipi_dbi_pipe_disable()
426 regulator_disable(dbidev->io_regulator); in mipi_dbi_pipe_disable()
431 * mipi_dbi_pipe_begin_fb_access - MIPI DBI pipe begin-access helper
446 return drm_gem_begin_shadow_fb_access(&pipe->plane, plane_state); in mipi_dbi_pipe_begin_fb_access()
451 * mipi_dbi_pipe_end_fb_access - MIPI DBI pipe end-access helper
462 drm_gem_end_shadow_fb_access(&pipe->plane, plane_state); in mipi_dbi_pipe_end_fb_access()
467 * mipi_dbi_pipe_reset_plane - MIPI DBI plane-reset helper
475 drm_gem_reset_shadow_plane(&pipe->plane); in mipi_dbi_pipe_reset_plane()
480 * mipi_dbi_pipe_duplicate_plane_state - duplicates MIPI DBI plane state
493 return drm_gem_duplicate_shadow_plane_state(&pipe->plane); in mipi_dbi_pipe_duplicate_plane_state()
498 * mipi_dbi_pipe_destroy_plane_state - cleans up MIPI DBI plane state
510 drm_gem_destroy_shadow_plane_state(&pipe->plane, plane_state); in mipi_dbi_pipe_destroy_plane_state()
516 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(connector->dev); in mipi_dbi_connector_get_modes()
518 return drm_connector_helper_get_modes_fixed(connector, &dbidev->mode); in mipi_dbi_connector_get_modes()
539 swap(mode->hdisplay, mode->vdisplay); in mipi_dbi_rotate_mode()
540 swap(mode->hsync_start, mode->vsync_start); in mipi_dbi_rotate_mode()
541 swap(mode->hsync_end, mode->vsync_end); in mipi_dbi_rotate_mode()
542 swap(mode->htotal, mode->vtotal); in mipi_dbi_rotate_mode()
543 swap(mode->width_mm, mode->height_mm); in mipi_dbi_rotate_mode()
546 return -EINVAL; in mipi_dbi_rotate_mode()
562 * mipi_dbi_dev_init_with_formats - MIPI DBI device initialization with custom formats
594 struct drm_device *drm = &dbidev->drm; in mipi_dbi_dev_init_with_formats()
597 if (!dbidev->dbi.command) in mipi_dbi_dev_init_with_formats()
598 return -EINVAL; in mipi_dbi_dev_init_with_formats()
604 dbidev->tx_buf = devm_kmalloc(drm->dev, tx_buf_size, GFP_KERNEL); in mipi_dbi_dev_init_with_formats()
605 if (!dbidev->tx_buf) in mipi_dbi_dev_init_with_formats()
606 return -ENOMEM; in mipi_dbi_dev_init_with_formats()
608 drm_mode_copy(&dbidev->mode, mode); in mipi_dbi_dev_init_with_formats()
609 ret = mipi_dbi_rotate_mode(&dbidev->mode, rotation); in mipi_dbi_dev_init_with_formats()
612 return -EINVAL; in mipi_dbi_dev_init_with_formats()
615 drm_connector_helper_add(&dbidev->connector, &mipi_dbi_connector_hfuncs); in mipi_dbi_dev_init_with_formats()
616 ret = drm_connector_init(drm, &dbidev->connector, &mipi_dbi_connector_funcs, in mipi_dbi_dev_init_with_formats()
621 ret = drm_simple_display_pipe_init(drm, &dbidev->pipe, funcs, formats, format_count, in mipi_dbi_dev_init_with_formats()
622 modifiers, &dbidev->connector); in mipi_dbi_dev_init_with_formats()
626 drm_plane_enable_fb_damage_clips(&dbidev->pipe.plane); in mipi_dbi_dev_init_with_formats()
628 drm->mode_config.funcs = &mipi_dbi_mode_config_funcs; in mipi_dbi_dev_init_with_formats()
629 drm->mode_config.min_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
630 drm->mode_config.max_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
631 drm->mode_config.min_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
632 drm->mode_config.max_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
633 dbidev->rotation = rotation; in mipi_dbi_dev_init_with_formats()
642 * mipi_dbi_dev_init - MIPI DBI device initialization
662 size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); in mipi_dbi_dev_init()
664 dbidev->drm.mode_config.preferred_depth = 16; in mipi_dbi_dev_init()
673 * mipi_dbi_hw_reset - Hardware reset of controller
676 * Reset controller if the &mipi_dbi->reset gpio is set.
680 if (!dbi->reset) in mipi_dbi_hw_reset()
683 gpiod_set_value_cansleep(dbi->reset, 0); in mipi_dbi_hw_reset()
685 gpiod_set_value_cansleep(dbi->reset, 1); in mipi_dbi_hw_reset()
691 * mipi_dbi_display_is_on - Check if display is on
724 struct device *dev = dbidev->drm.dev; in mipi_dbi_poweron_reset_conditional()
725 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_poweron_reset_conditional()
728 if (dbidev->regulator) { in mipi_dbi_poweron_reset_conditional()
729 ret = regulator_enable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
736 if (dbidev->io_regulator) { in mipi_dbi_poweron_reset_conditional()
737 ret = regulator_enable(dbidev->io_regulator); in mipi_dbi_poweron_reset_conditional()
740 if (dbidev->regulator) in mipi_dbi_poweron_reset_conditional()
741 regulator_disable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
753 if (dbidev->regulator) in mipi_dbi_poweron_reset_conditional()
754 regulator_disable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
755 if (dbidev->io_regulator) in mipi_dbi_poweron_reset_conditional()
756 regulator_disable(dbidev->io_regulator); in mipi_dbi_poweron_reset_conditional()
765 if (dbi->reset) in mipi_dbi_poweron_reset_conditional()
774 * mipi_dbi_poweron_reset - MIPI DBI poweron and reset
790 * mipi_dbi_poweron_conditional_reset - MIPI DBI poweron and conditional reset
810 * mipi_dbi_spi_cmd_max_speed - get the maximum SPI bus speed
812 * @len: The transfer buffer length.
816 * at 10MHz, preventing transfer glitches from messing up the init settings.
823 return min_t(u32, 10000000, spi->max_speed_hz); in mipi_dbi_spi_cmd_max_speed()
839 * If the SPI controller doesn't have 9 bits per word support,
840 * use blocks of 9 bytes to send 8x 9-bit words using a 8-bit SPI transfer.
859 size_t chunk, max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1e_transfer()
860 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1e_transfer()
862 .tx_buf = dbi->tx_buf9, in mipi_dbi_spi1e_transfer()
879 return -EINVAL; in mipi_dbi_spi1e_transfer()
881 /* Command: pad no-op's (zeroes) at beginning of block */ in mipi_dbi_spi1e_transfer()
882 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
901 len -= chunk; in mipi_dbi_spi1e_transfer()
902 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
907 /* Data: pad no-op's (zeroes) at end of block */ in mipi_dbi_spi1e_transfer()
913 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
914 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
917 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
918 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
925 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
926 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
976 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1_transfer()
991 max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1_transfer()
992 dst16 = dbi->tx_buf9; in mipi_dbi_spi1_transfer()
1025 len -= chunk; in mipi_dbi_spi1_transfer()
1038 struct spi_device *spi = dbi->spi; in mipi_dbi_typec1_command_read()
1040 spi->max_speed_hz / 2); in mipi_dbi_typec1_command_read()
1045 .tx_buf = dbi->tx_buf9, in mipi_dbi_typec1_command_read()
1059 return -EINVAL; in mipi_dbi_typec1_command_read()
1066 dev_err(&spi->dev, in mipi_dbi_typec1_command_read()
1068 return -EOPNOTSUPP; in mipi_dbi_typec1_command_read()
1073 * buffer. Only 9 bits of this will be used when executing the actual in mipi_dbi_typec1_command_read()
1074 * transfer. in mipi_dbi_typec1_command_read()
1076 dst16 = dbi->tx_buf9; in mipi_dbi_typec1_command_read()
1089 u8 *parameters, size_t num) in mipi_dbi_typec1_command() argument
1095 return mipi_dbi_typec1_command_read(dbi, cmd, parameters, num); in mipi_dbi_typec1_command()
1097 MIPI_DBI_DEBUG_COMMAND(*cmd, parameters, num); in mipi_dbi_typec1_command()
1100 if (ret || !num) in mipi_dbi_typec1_command()
1103 return mipi_dbi_spi1_transfer(dbi, 1, parameters, num, bpw); in mipi_dbi_typec1_command()
1111 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command_read()
1113 spi->max_speed_hz / 2); in mipi_dbi_typec3_command_read()
1129 return -EINVAL; in mipi_dbi_typec3_command_read()
1132 * Support non-standard 24-bit and 32-bit Nokia read commands which in mipi_dbi_typec3_command_read()
1138 return -EINVAL; in mipi_dbi_typec3_command_read()
1145 return -ENOMEM; in mipi_dbi_typec3_command_read()
1149 spi_bus_lock(spi->controller); in mipi_dbi_typec3_command_read()
1150 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command_read()
1154 spi_bus_unlock(spi->controller); in mipi_dbi_typec3_command_read()
1176 u8 *par, size_t num) in mipi_dbi_typec3_command() argument
1178 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command()
1184 return mipi_dbi_typec3_command_read(dbi, cmd, par, num); in mipi_dbi_typec3_command()
1186 MIPI_DBI_DEBUG_COMMAND(*cmd, par, num); in mipi_dbi_typec3_command()
1188 spi_bus_lock(spi->controller); in mipi_dbi_typec3_command()
1189 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command()
1192 spi_bus_unlock(spi->controller); in mipi_dbi_typec3_command()
1193 if (ret || !num) in mipi_dbi_typec3_command()
1196 if (*cmd == MIPI_DCS_WRITE_MEMORY_START && !dbi->swap_bytes) in mipi_dbi_typec3_command()
1199 spi_bus_lock(spi->controller); in mipi_dbi_typec3_command()
1200 gpiod_set_value_cansleep(dbi->dc, 1); in mipi_dbi_typec3_command()
1201 speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num); in mipi_dbi_typec3_command()
1202 ret = mipi_dbi_spi_transfer(spi, speed_hz, bpw, par, num); in mipi_dbi_typec3_command()
1203 spi_bus_unlock(spi->controller); in mipi_dbi_typec3_command()
1209 * mipi_dbi_spi_init - Initialize MIPI DBI SPI interface
1214 * This function sets &mipi_dbi->command, enables &mipi_dbi->read_commands for the
1216 * a driver-specific init.
1221 * If the SPI master driver doesn't support the necessary bits per word,
1224 * - 9-bit: reorder buffer as 9x 8-bit words, padded with no-op command.
1225 * - 16-bit: if big endian send as 8-bit, if little endian swap bytes
1233 struct device *dev = &spi->dev; in mipi_dbi_spi_init()
1242 * The virtual address is used in the transfer and the SPI core in mipi_dbi_spi_init()
1243 * re-maps it on the SPI master device using the DMA streaming API in mipi_dbi_spi_init()
1246 if (!dev->coherent_dma_mask) { in mipi_dbi_spi_init()
1254 dbi->spi = spi; in mipi_dbi_spi_init()
1255 dbi->read_commands = mipi_dbi_dcs_read_commands; in mipi_dbi_spi_init()
1258 dbi->command = mipi_dbi_typec3_command; in mipi_dbi_spi_init()
1259 dbi->dc = dc; in mipi_dbi_spi_init()
1261 dbi->swap_bytes = true; in mipi_dbi_spi_init()
1263 dbi->command = mipi_dbi_typec1_command; in mipi_dbi_spi_init()
1264 dbi->tx_buf9_len = SZ_16K; in mipi_dbi_spi_init()
1265 dbi->tx_buf9 = devm_kmalloc(dev, dbi->tx_buf9_len, GFP_KERNEL); in mipi_dbi_spi_init()
1266 if (!dbi->tx_buf9) in mipi_dbi_spi_init()
1267 return -ENOMEM; in mipi_dbi_spi_init()
1270 mutex_init(&dbi->cmdlock); in mipi_dbi_spi_init()
1272 DRM_DEBUG_DRIVER("SPI speed: %uMHz\n", spi->max_speed_hz / 1000000); in mipi_dbi_spi_init()
1279 * mipi_dbi_spi_transfer - SPI transfer helper
1282 * @bpw: Bits per word
1283 * @buf: Buffer to transfer
1286 * This SPI transfer helper breaks up the transfer of @buf into chunks which
1306 * are accepted (xfer->len % w_size must be zero). in mipi_dbi_spi_transfer()
1307 * Here we align max_chunk to multiple of 2 (16bits), in mipi_dbi_spi_transfer()
1320 len -= chunk; in mipi_dbi_spi_transfer()
1339 struct seq_file *m = file->private_data; in mipi_dbi_debugfs_command_write()
1340 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_write()
1345 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_write()
1346 return -ENODEV; in mipi_dbi_debugfs_command_write()
1355 for (i = count - 1; i > 0; i--) in mipi_dbi_debugfs_command_write()
1365 ret = -EINVAL; in mipi_dbi_debugfs_command_write()
1379 ret = -E2BIG; in mipi_dbi_debugfs_command_write()
1384 ret = mipi_dbi_command_buf(&dbidev->dbi, cmd, parameters, i); in mipi_dbi_debugfs_command_write()
1396 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_show()
1397 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_debugfs_command_show()
1402 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_show()
1403 return -ENODEV; in mipi_dbi_debugfs_command_show()
1443 inode->i_private); in mipi_dbi_debugfs_command_open()
1456 * mipi_dbi_debugfs_init - Create debugfs entries
1461 * Drivers can use this as their &drm_driver->debugfs_init callback.
1466 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(minor->dev); in mipi_dbi_debugfs_init()
1469 if (dbidev->dbi.read_commands) in mipi_dbi_debugfs_init()
1471 debugfs_create_file("command", mode, minor->debugfs_root, dbidev, in mipi_dbi_debugfs_init()