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

1 // SPDX-License-Identifier: GPL-2.0-or-later
58 * 1. 9-bit with the Data/Command signal as the ninth bit
59 * 2. Same as above except it's sent as 16 bits
60 * 3. 8-bit with the Data/Command signal as a separate D/CX pin
104 if (!dbi->read_commands) in mipi_dbi_command_is_read()
108 if (!dbi->read_commands[i]) in mipi_dbi_command_is_read()
110 if (cmd == dbi->read_commands[i]) in mipi_dbi_command_is_read()
118 * mipi_dbi_command_read - MIPI DCS read command
130 if (!dbi->read_commands) in mipi_dbi_command_read()
131 return -EACCES; in mipi_dbi_command_read()
134 return -EINVAL; in mipi_dbi_command_read()
141 * mipi_dbi_command_buf - MIPI DCS command with parameter(s) in an array
155 /* SPI requires dma-safe buffers */ in mipi_dbi_command_buf()
158 return -ENOMEM; in mipi_dbi_command_buf()
160 mutex_lock(&dbi->cmdlock); in mipi_dbi_command_buf()
161 ret = dbi->command(dbi, cmdbuf, data, len); in mipi_dbi_command_buf()
162 mutex_unlock(&dbi->cmdlock); in mipi_dbi_command_buf()
179 return -ENOMEM; in mipi_dbi_command_stackbuf()
190 * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
194 * @swap: When true, swap MSB/LSB of 16-bit values
204 void *src = cma_obj->vaddr; in mipi_dbi_buf_copy()
211 switch (fb->format->format) { in mipi_dbi_buf_copy()
214 drm_fb_swab(dst, src, fb, clip, !gem->import_attach); in mipi_dbi_buf_copy()
222 drm_err_once(fb->dev, "Format is not supported: %p4cc\n", in mipi_dbi_buf_copy()
223 &fb->format->format); in mipi_dbi_buf_copy()
224 return -EINVAL; in mipi_dbi_buf_copy()
237 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_set_window_address()
239 xs += dbidev->left_offset; in mipi_dbi_set_window_address()
240 xe += dbidev->left_offset; in mipi_dbi_set_window_address()
241 ys += dbidev->top_offset; in mipi_dbi_set_window_address()
242 ye += dbidev->top_offset; in mipi_dbi_set_window_address()
254 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); in mipi_dbi_fb_dirty()
255 unsigned int height = rect->y2 - rect->y1; in mipi_dbi_fb_dirty()
256 unsigned int width = rect->x2 - rect->x1; in mipi_dbi_fb_dirty()
257 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_fb_dirty()
258 bool swap = dbi->swap_bytes; in mipi_dbi_fb_dirty()
266 if (!drm_dev_enter(fb->dev, &idx)) 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()
276 ret = mipi_dbi_buf_copy(dbidev->tx_buf, fb, rect, swap); in mipi_dbi_fb_dirty()
280 tr = cma_obj->vaddr; 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()
296 * mipi_dbi_pipe_update - Display pipe update helper
301 * this as their &drm_simple_display_pipe_funcs->update callback.
306 struct drm_plane_state *state = pipe->plane.state; in mipi_dbi_pipe_update()
309 if (!pipe->crtc.state->active) in mipi_dbi_pipe_update()
313 mipi_dbi_fb_dirty(state->fb, &rect); in mipi_dbi_pipe_update()
318 * mipi_dbi_enable_flush - MIPI DBI enable helper
324 * in their &drm_simple_display_pipe_funcs->enable callback.
334 struct drm_framebuffer *fb = plane_state->fb; in mipi_dbi_enable_flush()
337 .x2 = fb->width, in mipi_dbi_enable_flush()
339 .y2 = fb->height, in mipi_dbi_enable_flush()
343 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_enable_flush()
347 backlight_enable(dbidev->backlight); in mipi_dbi_enable_flush()
355 struct drm_device *drm = &dbidev->drm; in mipi_dbi_blank()
356 u16 height = drm->mode_config.min_height; in mipi_dbi_blank()
357 u16 width = drm->mode_config.min_width; in mipi_dbi_blank()
358 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_blank()
365 memset(dbidev->tx_buf, 0, len); in mipi_dbi_blank()
367 mipi_dbi_set_window_address(dbidev, 0, width - 1, 0, height - 1); in mipi_dbi_blank()
369 (u8 *)dbidev->tx_buf, len); in mipi_dbi_blank()
375 * mipi_dbi_pipe_disable - MIPI DBI pipe disable helper
380 * &drm_simple_display_pipe_funcs->disable callback.
384 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_disable()
388 if (dbidev->backlight) in mipi_dbi_pipe_disable()
389 backlight_disable(dbidev->backlight); in mipi_dbi_pipe_disable()
393 if (dbidev->regulator) in mipi_dbi_pipe_disable()
394 regulator_disable(dbidev->regulator); in mipi_dbi_pipe_disable()
400 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(connector->dev); in mipi_dbi_connector_get_modes()
403 mode = drm_mode_duplicate(connector->dev, &dbidev->mode); in mipi_dbi_connector_get_modes()
409 if (mode->name[0] == '\0') in mipi_dbi_connector_get_modes()
412 mode->type |= DRM_MODE_TYPE_PREFERRED; in mipi_dbi_connector_get_modes()
415 if (mode->width_mm) { in mipi_dbi_connector_get_modes()
416 connector->display_info.width_mm = mode->width_mm; in mipi_dbi_connector_get_modes()
417 connector->display_info.height_mm = mode->height_mm; in mipi_dbi_connector_get_modes()
441 swap(mode->hdisplay, mode->vdisplay); in mipi_dbi_rotate_mode()
442 swap(mode->hsync_start, mode->vsync_start); in mipi_dbi_rotate_mode()
443 swap(mode->hsync_end, mode->vsync_end); in mipi_dbi_rotate_mode()
444 swap(mode->htotal, mode->vtotal); in mipi_dbi_rotate_mode()
445 swap(mode->width_mm, mode->height_mm); in mipi_dbi_rotate_mode()
448 return -EINVAL; in mipi_dbi_rotate_mode()
464 * mipi_dbi_dev_init_with_formats - MIPI DBI device initialization with custom formats
496 struct drm_device *drm = &dbidev->drm; in mipi_dbi_dev_init_with_formats()
499 if (!dbidev->dbi.command) in mipi_dbi_dev_init_with_formats()
500 return -EINVAL; in mipi_dbi_dev_init_with_formats()
506 dbidev->tx_buf = devm_kmalloc(drm->dev, tx_buf_size, GFP_KERNEL); in mipi_dbi_dev_init_with_formats()
507 if (!dbidev->tx_buf) in mipi_dbi_dev_init_with_formats()
508 return -ENOMEM; in mipi_dbi_dev_init_with_formats()
510 drm_mode_copy(&dbidev->mode, mode); in mipi_dbi_dev_init_with_formats()
511 ret = mipi_dbi_rotate_mode(&dbidev->mode, rotation); in mipi_dbi_dev_init_with_formats()
514 return -EINVAL; in mipi_dbi_dev_init_with_formats()
517 drm_connector_helper_add(&dbidev->connector, &mipi_dbi_connector_hfuncs); in mipi_dbi_dev_init_with_formats()
518 ret = drm_connector_init(drm, &dbidev->connector, &mipi_dbi_connector_funcs, in mipi_dbi_dev_init_with_formats()
523 ret = drm_simple_display_pipe_init(drm, &dbidev->pipe, funcs, formats, format_count, in mipi_dbi_dev_init_with_formats()
524 modifiers, &dbidev->connector); in mipi_dbi_dev_init_with_formats()
528 drm_plane_enable_fb_damage_clips(&dbidev->pipe.plane); in mipi_dbi_dev_init_with_formats()
530 drm->mode_config.funcs = &mipi_dbi_mode_config_funcs; in mipi_dbi_dev_init_with_formats()
531 drm->mode_config.min_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
532 drm->mode_config.max_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
533 drm->mode_config.min_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
534 drm->mode_config.max_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
535 dbidev->rotation = rotation; in mipi_dbi_dev_init_with_formats()
544 * mipi_dbi_dev_init - MIPI DBI device initialization
564 size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); in mipi_dbi_dev_init()
566 dbidev->drm.mode_config.preferred_depth = 16; in mipi_dbi_dev_init()
575 * mipi_dbi_hw_reset - Hardware reset of controller
578 * Reset controller if the &mipi_dbi->reset gpio is set.
582 if (!dbi->reset) in mipi_dbi_hw_reset()
585 gpiod_set_value_cansleep(dbi->reset, 0); in mipi_dbi_hw_reset()
587 gpiod_set_value_cansleep(dbi->reset, 1); in mipi_dbi_hw_reset()
593 * mipi_dbi_display_is_on - Check if display is on
626 struct device *dev = dbidev->drm.dev; in mipi_dbi_poweron_reset_conditional()
627 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_poweron_reset_conditional()
630 if (dbidev->regulator) { in mipi_dbi_poweron_reset_conditional()
631 ret = regulator_enable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
645 if (dbidev->regulator) in mipi_dbi_poweron_reset_conditional()
646 regulator_disable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
655 if (dbi->reset) in mipi_dbi_poweron_reset_conditional()
664 * mipi_dbi_poweron_reset - MIPI DBI poweron and reset
680 * mipi_dbi_poweron_conditional_reset - MIPI DBI poweron and conditional reset
700 * mipi_dbi_spi_cmd_max_speed - get the maximum SPI bus speed
702 * @len: The transfer buffer length.
706 * at 10MHz, preventing transfer glitches from messing up the init settings.
713 return min_t(u32, 10000000, spi->max_speed_hz); in mipi_dbi_spi_cmd_max_speed()
729 * If the SPI controller doesn't have 9 bits per word support,
730 * use blocks of 9 bytes to send 8x 9-bit words using a 8-bit SPI transfer.
749 size_t chunk, max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1e_transfer()
750 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1e_transfer()
752 .tx_buf = dbi->tx_buf9, in mipi_dbi_spi1e_transfer()
769 return -EINVAL; in mipi_dbi_spi1e_transfer()
771 /* Command: pad no-op's (zeroes) at beginning of block */ in mipi_dbi_spi1e_transfer()
772 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
791 len -= chunk; in mipi_dbi_spi1e_transfer()
792 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
797 /* Data: pad no-op's (zeroes) at end of block */ in mipi_dbi_spi1e_transfer()
803 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
804 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
807 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
808 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
815 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
816 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
866 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1_transfer()
881 max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1_transfer()
882 dst16 = dbi->tx_buf9; in mipi_dbi_spi1_transfer()
915 len -= chunk; in mipi_dbi_spi1_transfer()
928 struct spi_device *spi = dbi->spi; in mipi_dbi_typec1_command_read()
930 spi->max_speed_hz / 2); in mipi_dbi_typec1_command_read()
935 .tx_buf = dbi->tx_buf9, in mipi_dbi_typec1_command_read()
949 return -EINVAL; in mipi_dbi_typec1_command_read()
956 dev_err(&spi->dev, in mipi_dbi_typec1_command_read()
958 return -EOPNOTSUPP; in mipi_dbi_typec1_command_read()
963 * buffer. Only 9 bits of this will be used when executing the actual in mipi_dbi_typec1_command_read()
964 * transfer. in mipi_dbi_typec1_command_read()
966 dst16 = dbi->tx_buf9; in mipi_dbi_typec1_command_read()
979 u8 *parameters, size_t num) in mipi_dbi_typec1_command() argument
985 return mipi_dbi_typec1_command_read(dbi, cmd, parameters, num); in mipi_dbi_typec1_command()
987 MIPI_DBI_DEBUG_COMMAND(*cmd, parameters, num); in mipi_dbi_typec1_command()
990 if (ret || !num) in mipi_dbi_typec1_command()
993 return mipi_dbi_spi1_transfer(dbi, 1, parameters, num, bpw); in mipi_dbi_typec1_command()
1001 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command_read()
1003 spi->max_speed_hz / 2); in mipi_dbi_typec3_command_read()
1019 return -EINVAL; in mipi_dbi_typec3_command_read()
1022 * Support non-standard 24-bit and 32-bit Nokia read commands which in mipi_dbi_typec3_command_read()
1028 return -EINVAL; in mipi_dbi_typec3_command_read()
1035 return -ENOMEM; in mipi_dbi_typec3_command_read()
1038 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command_read()
1063 u8 *par, size_t num) in mipi_dbi_typec3_command() argument
1065 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command()
1071 return mipi_dbi_typec3_command_read(dbi, cmd, par, num); in mipi_dbi_typec3_command()
1073 MIPI_DBI_DEBUG_COMMAND(*cmd, par, num); in mipi_dbi_typec3_command()
1075 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command()
1078 if (ret || !num) in mipi_dbi_typec3_command()
1081 if (*cmd == MIPI_DCS_WRITE_MEMORY_START && !dbi->swap_bytes) in mipi_dbi_typec3_command()
1084 gpiod_set_value_cansleep(dbi->dc, 1); in mipi_dbi_typec3_command()
1085 speed_hz = mipi_dbi_spi_cmd_max_speed(spi, num); in mipi_dbi_typec3_command()
1087 return mipi_dbi_spi_transfer(spi, speed_hz, bpw, par, num); in mipi_dbi_typec3_command()
1091 * mipi_dbi_spi_init - Initialize MIPI DBI SPI interface
1096 * This function sets &mipi_dbi->command, enables &mipi_dbi->read_commands for the
1098 * a driver-specific init.
1103 * If the SPI master driver doesn't support the necessary bits per word,
1106 * - 9-bit: reorder buffer as 9x 8-bit words, padded with no-op command.
1107 * - 16-bit: if big endian send as 8-bit, if little endian swap bytes
1115 struct device *dev = &spi->dev; in mipi_dbi_spi_init()
1124 * The virtual address is used in the transfer and the SPI core in mipi_dbi_spi_init()
1125 * re-maps it on the SPI master device using the DMA streaming API in mipi_dbi_spi_init()
1128 if (!dev->coherent_dma_mask) { in mipi_dbi_spi_init()
1136 dbi->spi = spi; in mipi_dbi_spi_init()
1137 dbi->read_commands = mipi_dbi_dcs_read_commands; in mipi_dbi_spi_init()
1140 dbi->command = mipi_dbi_typec3_command; in mipi_dbi_spi_init()
1141 dbi->dc = dc; in mipi_dbi_spi_init()
1143 dbi->swap_bytes = true; in mipi_dbi_spi_init()
1145 dbi->command = mipi_dbi_typec1_command; in mipi_dbi_spi_init()
1146 dbi->tx_buf9_len = SZ_16K; in mipi_dbi_spi_init()
1147 dbi->tx_buf9 = devm_kmalloc(dev, dbi->tx_buf9_len, GFP_KERNEL); in mipi_dbi_spi_init()
1148 if (!dbi->tx_buf9) in mipi_dbi_spi_init()
1149 return -ENOMEM; in mipi_dbi_spi_init()
1152 mutex_init(&dbi->cmdlock); in mipi_dbi_spi_init()
1154 DRM_DEBUG_DRIVER("SPI speed: %uMHz\n", spi->max_speed_hz / 1000000); in mipi_dbi_spi_init()
1161 * mipi_dbi_spi_transfer - SPI transfer helper
1164 * @bpw: Bits per word
1165 * @buf: Buffer to transfer
1168 * This SPI transfer helper breaks up the transfer of @buf into chunks which
1194 len -= chunk; in mipi_dbi_spi_transfer()
1213 struct seq_file *m = file->private_data; in mipi_dbi_debugfs_command_write()
1214 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_write()
1219 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_write()
1220 return -ENODEV; in mipi_dbi_debugfs_command_write()
1229 for (i = count - 1; i > 0; i--) in mipi_dbi_debugfs_command_write()
1239 ret = -EINVAL; in mipi_dbi_debugfs_command_write()
1253 ret = -E2BIG; in mipi_dbi_debugfs_command_write()
1258 ret = mipi_dbi_command_buf(&dbidev->dbi, cmd, parameters, i); in mipi_dbi_debugfs_command_write()
1270 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_show()
1271 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_debugfs_command_show()
1276 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_show()
1277 return -ENODEV; in mipi_dbi_debugfs_command_show()
1317 inode->i_private); in mipi_dbi_debugfs_command_open()
1330 * mipi_dbi_debugfs_init - Create debugfs entries
1335 * Drivers can use this as their &drm_driver->debugfs_init callback.
1340 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(minor->dev); in mipi_dbi_debugfs_init()
1343 if (dbidev->dbi.read_commands) in mipi_dbi_debugfs_init()
1345 debugfs_create_file("command", mode, minor->debugfs_root, dbidev, in mipi_dbi_debugfs_init()