Lines Matching +full:hardware +full:- +full:wise
1 // SPDX-License-Identifier: GPL-2.0-or-later
62 * 1. 9-bit with the Data/Command signal as the ninth bit
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
209 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); in mipi_dbi_buf_copy()
218 switch (fb->format->format) { in mipi_dbi_buf_copy()
221 drm_fb_swab(&dst_map, NULL, src, fb, clip, !gem->import_attach, in mipi_dbi_buf_copy()
230 switch (dbidev->pixel_format) { in mipi_dbi_buf_copy()
240 drm_err_once(fb->dev, "Format is not supported: %p4cc\n", in mipi_dbi_buf_copy()
241 &fb->format->format); in mipi_dbi_buf_copy()
242 ret = -EINVAL; in mipi_dbi_buf_copy()
255 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_set_window_address()
257 xs += dbidev->left_offset; in mipi_dbi_set_window_address()
258 xe += dbidev->left_offset; in mipi_dbi_set_window_address()
259 ys += dbidev->top_offset; in mipi_dbi_set_window_address()
260 ye += dbidev->top_offset; in mipi_dbi_set_window_address()
271 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); in mipi_dbi_fb_dirty()
272 unsigned int height = rect->y2 - rect->y1; in mipi_dbi_fb_dirty()
273 unsigned int width = rect->x2 - rect->x1; in mipi_dbi_fb_dirty()
275 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_fb_dirty()
276 bool swap = dbi->swap_bytes; in mipi_dbi_fb_dirty()
282 full = width == fb->width && height == fb->height; in mipi_dbi_fb_dirty()
284 DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect)); in mipi_dbi_fb_dirty()
286 if (!dbi->dc || !full || swap || in mipi_dbi_fb_dirty()
287 fb->format->format == DRM_FORMAT_XRGB8888) { in mipi_dbi_fb_dirty()
288 tr = dbidev->tx_buf; in mipi_dbi_fb_dirty()
293 tr = src->vaddr; /* TODO: Use mapping abstraction properly */ in mipi_dbi_fb_dirty()
296 mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1, in mipi_dbi_fb_dirty()
297 rect->y2 - 1); in mipi_dbi_fb_dirty()
299 if (fb->format->format == DRM_FORMAT_XRGB8888) in mipi_dbi_fb_dirty()
300 dst_format = drm_format_info(dbidev->pixel_format); in mipi_dbi_fb_dirty()
302 dst_format = fb->format; in mipi_dbi_fb_dirty()
308 drm_err_once(fb->dev, "Failed to update display %d\n", ret); in mipi_dbi_fb_dirty()
312 * mipi_dbi_pipe_mode_valid - MIPI DBI mode-valid helper
316 * This function validates a given display mode against the MIPI DBI's hardware
317 * display. Drivers can use this as their &drm_simple_display_pipe_funcs->mode_valid
323 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_mode_valid()
325 return drm_crtc_helper_mode_valid_fixed(&pipe->crtc, mode, &dbidev->mode); in mipi_dbi_pipe_mode_valid()
330 * mipi_dbi_pipe_update - Display pipe update helper
335 * this as their &drm_simple_display_pipe_funcs->update callback.
340 struct drm_plane_state *state = pipe->plane.state; in mipi_dbi_pipe_update()
342 struct drm_framebuffer *fb = state->fb; in mipi_dbi_pipe_update()
346 if (!pipe->crtc.state->active) in mipi_dbi_pipe_update()
352 if (!drm_dev_enter(fb->dev, &idx)) in mipi_dbi_pipe_update()
356 mipi_dbi_fb_dirty(&shadow_plane_state->data[0], fb, &rect, in mipi_dbi_pipe_update()
357 &shadow_plane_state->fmtcnv_state); in mipi_dbi_pipe_update()
364 * mipi_dbi_enable_flush - MIPI DBI enable helper
370 * in their &drm_simple_display_pipe_funcs->enable callback.
381 struct drm_framebuffer *fb = plane_state->fb; in mipi_dbi_enable_flush()
384 .x2 = fb->width, in mipi_dbi_enable_flush()
386 .y2 = fb->height, in mipi_dbi_enable_flush()
390 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_enable_flush()
393 mipi_dbi_fb_dirty(&shadow_plane_state->data[0], fb, &rect, in mipi_dbi_enable_flush()
394 &shadow_plane_state->fmtcnv_state); in mipi_dbi_enable_flush()
395 backlight_enable(dbidev->backlight); in mipi_dbi_enable_flush()
403 struct drm_device *drm = &dbidev->drm; in mipi_dbi_blank()
404 u16 height = drm->mode_config.min_height; in mipi_dbi_blank()
405 u16 width = drm->mode_config.min_width; in mipi_dbi_blank()
406 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_blank()
413 memset(dbidev->tx_buf, 0, len); in mipi_dbi_blank()
415 mipi_dbi_set_window_address(dbidev, 0, width - 1, 0, height - 1); in mipi_dbi_blank()
417 (u8 *)dbidev->tx_buf, len); in mipi_dbi_blank()
423 * mipi_dbi_pipe_disable - MIPI DBI pipe disable helper
428 * &drm_simple_display_pipe_funcs->disable callback.
432 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); in mipi_dbi_pipe_disable()
436 if (dbidev->backlight) in mipi_dbi_pipe_disable()
437 backlight_disable(dbidev->backlight); in mipi_dbi_pipe_disable()
441 if (dbidev->regulator) in mipi_dbi_pipe_disable()
442 regulator_disable(dbidev->regulator); in mipi_dbi_pipe_disable()
443 if (dbidev->io_regulator) in mipi_dbi_pipe_disable()
444 regulator_disable(dbidev->io_regulator); in mipi_dbi_pipe_disable()
449 * mipi_dbi_pipe_begin_fb_access - MIPI DBI pipe begin-access helper
464 return drm_gem_begin_shadow_fb_access(&pipe->plane, plane_state); in mipi_dbi_pipe_begin_fb_access()
469 * mipi_dbi_pipe_end_fb_access - MIPI DBI pipe end-access helper
480 drm_gem_end_shadow_fb_access(&pipe->plane, plane_state); in mipi_dbi_pipe_end_fb_access()
485 * mipi_dbi_pipe_reset_plane - MIPI DBI plane-reset helper
493 drm_gem_reset_shadow_plane(&pipe->plane); in mipi_dbi_pipe_reset_plane()
498 * mipi_dbi_pipe_duplicate_plane_state - duplicates MIPI DBI plane state
511 return drm_gem_duplicate_shadow_plane_state(&pipe->plane); in mipi_dbi_pipe_duplicate_plane_state()
516 * mipi_dbi_pipe_destroy_plane_state - cleans up MIPI DBI plane state
528 drm_gem_destroy_shadow_plane_state(&pipe->plane, plane_state); in mipi_dbi_pipe_destroy_plane_state()
534 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(connector->dev); in mipi_dbi_connector_get_modes()
536 return drm_connector_helper_get_modes_fixed(connector, &dbidev->mode); in mipi_dbi_connector_get_modes()
557 swap(mode->hdisplay, mode->vdisplay); in mipi_dbi_rotate_mode()
558 swap(mode->hsync_start, mode->vsync_start); in mipi_dbi_rotate_mode()
559 swap(mode->hsync_end, mode->vsync_end); in mipi_dbi_rotate_mode()
560 swap(mode->htotal, mode->vtotal); in mipi_dbi_rotate_mode()
561 swap(mode->width_mm, mode->height_mm); in mipi_dbi_rotate_mode()
564 return -EINVAL; in mipi_dbi_rotate_mode()
580 * mipi_dbi_dev_init_with_formats - MIPI DBI device initialization with custom formats
586 * @rotation: Initial rotation in degrees Counter Clock Wise
612 struct drm_device *drm = &dbidev->drm; in mipi_dbi_dev_init_with_formats()
615 if (!dbidev->dbi.command) in mipi_dbi_dev_init_with_formats()
616 return -EINVAL; in mipi_dbi_dev_init_with_formats()
622 dbidev->tx_buf = devm_kmalloc(drm->dev, tx_buf_size, GFP_KERNEL); in mipi_dbi_dev_init_with_formats()
623 if (!dbidev->tx_buf) in mipi_dbi_dev_init_with_formats()
624 return -ENOMEM; in mipi_dbi_dev_init_with_formats()
626 drm_mode_copy(&dbidev->mode, mode); in mipi_dbi_dev_init_with_formats()
627 ret = mipi_dbi_rotate_mode(&dbidev->mode, rotation); in mipi_dbi_dev_init_with_formats()
630 return -EINVAL; in mipi_dbi_dev_init_with_formats()
633 drm_connector_helper_add(&dbidev->connector, &mipi_dbi_connector_hfuncs); in mipi_dbi_dev_init_with_formats()
634 ret = drm_connector_init(drm, &dbidev->connector, &mipi_dbi_connector_funcs, in mipi_dbi_dev_init_with_formats()
639 ret = drm_simple_display_pipe_init(drm, &dbidev->pipe, funcs, formats, format_count, in mipi_dbi_dev_init_with_formats()
640 modifiers, &dbidev->connector); in mipi_dbi_dev_init_with_formats()
644 drm_plane_enable_fb_damage_clips(&dbidev->pipe.plane); in mipi_dbi_dev_init_with_formats()
646 drm->mode_config.funcs = &mipi_dbi_mode_config_funcs; in mipi_dbi_dev_init_with_formats()
647 drm->mode_config.min_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
648 drm->mode_config.max_width = dbidev->mode.hdisplay; in mipi_dbi_dev_init_with_formats()
649 drm->mode_config.min_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
650 drm->mode_config.max_height = dbidev->mode.vdisplay; in mipi_dbi_dev_init_with_formats()
651 dbidev->rotation = rotation; in mipi_dbi_dev_init_with_formats()
652 dbidev->pixel_format = formats[0]; in mipi_dbi_dev_init_with_formats()
654 dbidev->dbi.write_memory_bpw = 8; in mipi_dbi_dev_init_with_formats()
663 * mipi_dbi_dev_init - MIPI DBI device initialization
667 * @rotation: Initial rotation in degrees Counter Clock Wise
683 size_t bufsize = mode->vdisplay * mode->hdisplay * sizeof(u16); in mipi_dbi_dev_init()
685 dbidev->drm.mode_config.preferred_depth = 16; in mipi_dbi_dev_init()
694 * mipi_dbi_hw_reset - Hardware reset of controller
697 * Reset controller if the &mipi_dbi->reset gpio is set.
701 if (!dbi->reset) in mipi_dbi_hw_reset()
704 gpiod_set_value_cansleep(dbi->reset, 0); in mipi_dbi_hw_reset()
706 gpiod_set_value_cansleep(dbi->reset, 1); in mipi_dbi_hw_reset()
712 * mipi_dbi_display_is_on - Check if display is on
745 struct device *dev = dbidev->drm.dev; in mipi_dbi_poweron_reset_conditional()
746 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_poweron_reset_conditional()
749 if (dbidev->regulator) { in mipi_dbi_poweron_reset_conditional()
750 ret = regulator_enable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
757 if (dbidev->io_regulator) { in mipi_dbi_poweron_reset_conditional()
758 ret = regulator_enable(dbidev->io_regulator); in mipi_dbi_poweron_reset_conditional()
761 if (dbidev->regulator) in mipi_dbi_poweron_reset_conditional()
762 regulator_disable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
774 if (dbidev->regulator) in mipi_dbi_poweron_reset_conditional()
775 regulator_disable(dbidev->regulator); in mipi_dbi_poweron_reset_conditional()
776 if (dbidev->io_regulator) in mipi_dbi_poweron_reset_conditional()
777 regulator_disable(dbidev->io_regulator); in mipi_dbi_poweron_reset_conditional()
786 if (dbi->reset) in mipi_dbi_poweron_reset_conditional()
795 * mipi_dbi_poweron_reset - MIPI DBI poweron and reset
798 * This function enables the regulator if used and does a hardware and software
811 * mipi_dbi_poweron_conditional_reset - MIPI DBI poweron and conditional reset
815 * does a hardware and software reset. If mipi_dbi_display_is_on() determines
831 * mipi_dbi_spi_cmd_max_speed - get the maximum SPI bus speed
844 return min_t(u32, 10000000, spi->max_speed_hz); in mipi_dbi_spi_cmd_max_speed()
852 * use blocks of 9 bytes to send 8x 9-bit words using a 8-bit SPI transfer.
871 size_t chunk, max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1e_transfer()
872 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1e_transfer()
874 .tx_buf = dbi->tx_buf9, in mipi_dbi_spi1e_transfer()
891 return -EINVAL; in mipi_dbi_spi1e_transfer()
893 /* Command: pad no-op's (zeroes) at beginning of block */ in mipi_dbi_spi1e_transfer()
894 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
913 len -= chunk; in mipi_dbi_spi1e_transfer()
914 dst = dbi->tx_buf9; in mipi_dbi_spi1e_transfer()
919 /* Data: pad no-op's (zeroes) at end of block */ 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()
929 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
930 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
937 *dst++ = carry | BIT(8 - i) | (val >> i); in mipi_dbi_spi1e_transfer()
938 carry = val << (8 - i); in mipi_dbi_spi1e_transfer()
988 struct spi_device *spi = dbi->spi; in mipi_dbi_spi1_transfer()
1003 max_chunk = dbi->tx_buf9_len; in mipi_dbi_spi1_transfer()
1004 dst16 = dbi->tx_buf9; in mipi_dbi_spi1_transfer()
1037 len -= chunk; in mipi_dbi_spi1_transfer()
1050 struct spi_device *spi = dbi->spi; in mipi_dbi_typec1_command_read()
1052 spi->max_speed_hz / 2); in mipi_dbi_typec1_command_read()
1057 .tx_buf = dbi->tx_buf9, in mipi_dbi_typec1_command_read()
1071 return -EINVAL; in mipi_dbi_typec1_command_read()
1078 dev_err(&spi->dev, in mipi_dbi_typec1_command_read()
1080 return -EOPNOTSUPP; in mipi_dbi_typec1_command_read()
1088 dst16 = dbi->tx_buf9; in mipi_dbi_typec1_command_read()
1116 bpw = dbi->write_memory_bpw; in mipi_dbi_typec1_command()
1126 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command_read()
1128 spi->max_speed_hz / 2); in mipi_dbi_typec3_command_read()
1144 return -EINVAL; in mipi_dbi_typec3_command_read()
1147 * Support non-standard 24-bit and 32-bit Nokia read commands which in mipi_dbi_typec3_command_read()
1153 return -EINVAL; in mipi_dbi_typec3_command_read()
1160 return -ENOMEM; in mipi_dbi_typec3_command_read()
1164 spi_bus_lock(spi->controller); in mipi_dbi_typec3_command_read()
1165 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command_read()
1169 spi_bus_unlock(spi->controller); in mipi_dbi_typec3_command_read()
1193 struct spi_device *spi = dbi->spi; in mipi_dbi_typec3_command()
1203 spi_bus_lock(spi->controller); in mipi_dbi_typec3_command()
1204 gpiod_set_value_cansleep(dbi->dc, 0); in mipi_dbi_typec3_command()
1207 spi_bus_unlock(spi->controller); in mipi_dbi_typec3_command()
1212 bpw = dbi->write_memory_bpw; in mipi_dbi_typec3_command()
1214 spi_bus_lock(spi->controller); in mipi_dbi_typec3_command()
1215 gpiod_set_value_cansleep(dbi->dc, 1); in mipi_dbi_typec3_command()
1218 spi_bus_unlock(spi->controller); in mipi_dbi_typec3_command()
1224 * mipi_dbi_spi_init - Initialize MIPI DBI SPI interface
1229 * This function sets &mipi_dbi->command, enables &mipi_dbi->read_commands for the
1231 * a driver-specific init.
1242 * Option 1 (D/C as a bit): The buffer is sent on the wire byte by byte so the 16-bit buffer is
1246 * sent as-is. If not the caller is responsible for swapping the bytes
1252 * the buffer is sent as 9x 8-bit words, padded with MIPI DCS no-op commands if necessary.
1260 struct device *dev = &spi->dev; in mipi_dbi_spi_init()
1270 * re-maps it on the SPI master device using the DMA streaming API in mipi_dbi_spi_init()
1273 if (!dev->coherent_dma_mask) { in mipi_dbi_spi_init()
1281 dbi->spi = spi; in mipi_dbi_spi_init()
1282 dbi->read_commands = mipi_dbi_dcs_read_commands; in mipi_dbi_spi_init()
1283 dbi->write_memory_bpw = 16; in mipi_dbi_spi_init()
1286 dbi->command = mipi_dbi_typec3_command; in mipi_dbi_spi_init()
1287 dbi->dc = dc; in mipi_dbi_spi_init()
1289 dbi->write_memory_bpw = 8; in mipi_dbi_spi_init()
1290 dbi->swap_bytes = true; in mipi_dbi_spi_init()
1293 dbi->command = mipi_dbi_typec1_command; in mipi_dbi_spi_init()
1294 dbi->tx_buf9_len = SZ_16K; in mipi_dbi_spi_init()
1295 dbi->tx_buf9 = devm_kmalloc(dev, dbi->tx_buf9_len, GFP_KERNEL); in mipi_dbi_spi_init()
1296 if (!dbi->tx_buf9) in mipi_dbi_spi_init()
1297 return -ENOMEM; in mipi_dbi_spi_init()
1300 mutex_init(&dbi->cmdlock); in mipi_dbi_spi_init()
1302 DRM_DEBUG_DRIVER("SPI speed: %uMHz\n", spi->max_speed_hz / 1000000); in mipi_dbi_spi_init()
1309 * mipi_dbi_spi_transfer - SPI transfer helper
1336 * are accepted (xfer->len % w_size must be zero). in mipi_dbi_spi_transfer()
1350 len -= chunk; in mipi_dbi_spi_transfer()
1369 struct seq_file *m = file->private_data; in mipi_dbi_debugfs_command_write()
1370 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_write()
1375 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_write()
1376 return -ENODEV; in mipi_dbi_debugfs_command_write()
1385 for (i = count - 1; i > 0; i--) in mipi_dbi_debugfs_command_write()
1395 ret = -EINVAL; in mipi_dbi_debugfs_command_write()
1409 ret = -E2BIG; in mipi_dbi_debugfs_command_write()
1414 ret = mipi_dbi_command_buf(&dbidev->dbi, cmd, parameters, i); in mipi_dbi_debugfs_command_write()
1426 struct mipi_dbi_dev *dbidev = m->private; in mipi_dbi_debugfs_command_show()
1427 struct mipi_dbi *dbi = &dbidev->dbi; in mipi_dbi_debugfs_command_show()
1432 if (!drm_dev_enter(&dbidev->drm, &idx)) in mipi_dbi_debugfs_command_show()
1433 return -ENODEV; in mipi_dbi_debugfs_command_show()
1473 inode->i_private); in mipi_dbi_debugfs_command_open()
1486 * mipi_dbi_debugfs_init - Create debugfs entries
1491 * Drivers can use this as their &drm_driver->debugfs_init callback.
1496 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(minor->dev); in mipi_dbi_debugfs_init()
1499 if (dbidev->dbi.read_commands) in mipi_dbi_debugfs_init()
1501 debugfs_create_file("command", mode, minor->debugfs_root, dbidev, in mipi_dbi_debugfs_init()