Lines Matching +full:even +full:- +full:numbered
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DRM driver for Pervasive Displays RePaper branded e-ink panels
5 * Copyright 2013-2017 Pervasive Displays, Inc.
51 enum repaper_stage { /* Image pixel -> Display pixel */
52 REPAPER_COMPENSATE, /* B -> W, W -> B (Current Image) */
53 REPAPER_WHITE, /* B -> N, W -> W (Current Image) */
54 REPAPER_INVERSE, /* B -> N, W -> B (New Image) */
55 REPAPER_NORMAL /* B -> B, W -> W (New Image) */
111 return -ENOMEM; in repaper_spi_transfer()
121 ret = -ENOMEM; in repaper_spi_transfer()
129 ret = -ENOMEM; in repaper_spi_transfer()
199 /* pixels on display are numbered from 1 so even is actually bits 1,3,5,... */
206 for (b = 0; b < (epd->width / 8); b++) { in repaper_even_pixels()
218 case REPAPER_COMPENSATE: /* B -> W, W -> B (Current) */ in repaper_even_pixels()
221 case REPAPER_WHITE: /* B -> N, W -> W (Current) */ in repaper_even_pixels()
224 case REPAPER_INVERSE: /* B -> N, W -> B (New) */ in repaper_even_pixels()
227 case REPAPER_NORMAL: /* B -> B, W -> W (New) */ in repaper_even_pixels()
245 /* pixels on display are numbered from 1 so odd is actually bits 0,2,4,... */
252 for (b = epd->width / 8; b > 0; b--) { in repaper_odd_pixels()
254 u8 pixels = data[b - 1] & 0x55; in repaper_odd_pixels()
258 pixel_mask = (mask[b - 1] ^ pixels) & 0x55; in repaper_odd_pixels()
263 case REPAPER_COMPENSATE: /* B -> W, W -> B (Current) */ in repaper_odd_pixels()
266 case REPAPER_WHITE: /* B -> N, W -> W (Current) */ in repaper_odd_pixels()
269 case REPAPER_INVERSE: /* B -> N, W -> B (New) */ in repaper_odd_pixels()
272 case REPAPER_NORMAL: /* B -> B, W -> W (New) */ in repaper_odd_pixels()
285 /* interleave bits: (byte)76543210 -> (16 bit).7.6.5.4.3.2.1 */
295 /* pixels on display are numbered from 1 */
302 for (b = epd->width / 8; b > 0; b--) { in repaper_all_pixels()
304 u16 pixels = repaper_interleave_bits(data[b - 1]); in repaper_all_pixels()
308 pixel_mask = repaper_interleave_bits(mask[b - 1]); in repaper_all_pixels()
315 case REPAPER_COMPENSATE: /* B -> W, W -> B (Current) */ in repaper_all_pixels()
318 case REPAPER_WHITE: /* B -> N, W -> W (Current) */ in repaper_all_pixels()
321 case REPAPER_INVERSE: /* B -> N, W -> B (New) */ in repaper_all_pixels()
324 case REPAPER_NORMAL: /* B -> B, W -> W (New) */ in repaper_all_pixels()
344 u8 *p = epd->line_buffer; in repaper_one_line()
347 repaper_spi_mosi_low(epd->spi); in repaper_one_line()
349 if (epd->pre_border_byte) in repaper_one_line()
352 if (epd->middle_scan) { in repaper_one_line()
357 for (b = epd->bytes_per_scan; b > 0; b--) { in repaper_one_line()
358 if (line / 4 == b - 1) in repaper_one_line()
368 * even scan line, but as lines on display are numbered from 1, in repaper_one_line()
371 for (b = 0; b < epd->bytes_per_scan; b++) { in repaper_one_line()
382 * odd scan line, but as lines on display are numbered from 1, in repaper_one_line()
385 for (b = epd->bytes_per_scan; b > 0; b--) { in repaper_one_line()
386 if (0 == (line & 0x01) && line / 8 == b - 1) in repaper_one_line()
393 switch (epd->border_byte) { in repaper_one_line()
415 repaper_write_buf(epd->spi, 0x0a, epd->line_buffer, in repaper_one_line()
416 p - epd->line_buffer); in repaper_one_line()
419 repaper_write_val(epd->spi, 0x02, 0x07); in repaper_one_line()
421 repaper_spi_mosi_low(epd->spi); in repaper_one_line()
429 for (line = 0; line < epd->height; line++) in repaper_frame_fixed()
439 for (line = 0; line < epd->height; line++) { in repaper_frame_data()
441 &image[line * (epd->width / 8)], in repaper_frame_data()
445 for (line = 0; line < epd->height; line++) { in repaper_frame_data()
446 size_t n = line * epd->width / 8; in repaper_frame_data()
458 u64 end = start + (epd->factored_stage_time * 1000 * 1000); in repaper_frame_fixed_repeat()
469 u64 end = start + (epd->factored_stage_time * 1000 * 1000); in repaper_frame_data_repeat()
481 if (!epd->thermal) in repaper_get_temperature()
484 ret = thermal_zone_get_temp(epd->thermal, &temperature); in repaper_get_temperature()
486 DRM_DEV_ERROR(&epd->spi->dev, "Failed to get temperature (%d)\n", ret); in repaper_get_temperature()
492 if (temperature <= -10) in repaper_get_temperature()
494 else if (temperature <= -5) in repaper_get_temperature()
509 epd->factored_stage_time = epd->stage_time * factor10x / 10; in repaper_get_temperature()
515 struct repaper_epd *epd = drm_to_epd(fb->dev); in repaper_fb_dirty()
522 if (!drm_dev_enter(fb->dev, &idx)) in repaper_fb_dirty()
523 return -ENODEV; in repaper_fb_dirty()
527 clip.x2 = fb->width; in repaper_fb_dirty()
529 clip.y2 = fb->height; in repaper_fb_dirty()
533 DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id, in repaper_fb_dirty()
534 epd->factored_stage_time); in repaper_fb_dirty()
536 buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL); in repaper_fb_dirty()
538 ret = -ENOMEM; in repaper_fb_dirty()
547 iosys_map_set_vaddr(&vmap, dma_obj->vaddr); in repaper_fb_dirty()
552 if (epd->partial) { in repaper_fb_dirty()
553 repaper_frame_data_repeat(epd, buf, epd->current_frame, in repaper_fb_dirty()
555 } else if (epd->cleared) { in repaper_fb_dirty()
556 repaper_frame_data_repeat(epd, epd->current_frame, NULL, in repaper_fb_dirty()
558 repaper_frame_data_repeat(epd, epd->current_frame, NULL, in repaper_fb_dirty()
563 epd->partial = true; in repaper_fb_dirty()
565 /* Clear display (anything -> white) */ in repaper_fb_dirty()
577 epd->cleared = true; in repaper_fb_dirty()
578 epd->partial = true; in repaper_fb_dirty()
581 memcpy(epd->current_frame, buf, fb->width * fb->height / 8); in repaper_fb_dirty()
587 if (epd->pre_border_byte) { in repaper_fb_dirty()
590 for (x = 0; x < (fb->width / 8); x++) in repaper_fb_dirty()
591 if (buf[x + (fb->width * (fb->height - 1) / 8)]) { in repaper_fb_dirty()
593 epd->current_frame, in repaper_fb_dirty()
610 gpiod_set_value_cansleep(epd->reset, 0); in power_off()
611 gpiod_set_value_cansleep(epd->panel_on, 0); in power_off()
612 if (epd->border) in power_off()
613 gpiod_set_value_cansleep(epd->border, 0); in power_off()
616 repaper_spi_mosi_low(epd->spi); in power_off()
619 gpiod_set_value_cansleep(epd->discharge, 1); in power_off()
621 gpiod_set_value_cansleep(epd->discharge, 0); in power_off()
627 struct drm_crtc *crtc = &pipe->crtc; in repaper_pipe_mode_valid()
628 struct repaper_epd *epd = drm_to_epd(crtc->dev); in repaper_pipe_mode_valid()
630 return drm_crtc_helper_mode_valid_fixed(crtc, mode, epd->mode); in repaper_pipe_mode_valid()
637 struct repaper_epd *epd = drm_to_epd(pipe->crtc.dev); in repaper_pipe_enable()
638 struct spi_device *spi = epd->spi; in repaper_pipe_enable()
639 struct device *dev = &spi->dev; in repaper_pipe_enable()
643 if (!drm_dev_enter(pipe->crtc.dev, &idx)) in repaper_pipe_enable()
649 gpiod_set_value_cansleep(epd->reset, 0); in repaper_pipe_enable()
650 gpiod_set_value_cansleep(epd->panel_on, 0); in repaper_pipe_enable()
651 gpiod_set_value_cansleep(epd->discharge, 0); in repaper_pipe_enable()
652 if (epd->border) in repaper_pipe_enable()
653 gpiod_set_value_cansleep(epd->border, 0); in repaper_pipe_enable()
657 gpiod_set_value_cansleep(epd->panel_on, 1); in repaper_pipe_enable()
663 gpiod_set_value_cansleep(epd->reset, 1); in repaper_pipe_enable()
664 if (epd->border) in repaper_pipe_enable()
665 gpiod_set_value_cansleep(epd->border, 1); in repaper_pipe_enable()
667 gpiod_set_value_cansleep(epd->reset, 0); in repaper_pipe_enable()
669 gpiod_set_value_cansleep(epd->reset, 1); in repaper_pipe_enable()
673 for (i = 100; i > 0; i--) { in repaper_pipe_enable()
674 if (!gpiod_get_value_cansleep(epd->busy)) in repaper_pipe_enable()
713 repaper_write_buf(spi, 0x01, epd->channel_select, 8); in repaper_pipe_enable()
730 /* Charge pump positive voltage on - VGH/VDL on */ in repaper_pipe_enable()
734 /* Charge pump negative voltage on - VGL/VDL on */ in repaper_pipe_enable()
738 /* Charge pump Vcom on - Vcom driver on */ in repaper_pipe_enable()
768 epd->partial = false; in repaper_pipe_enable()
775 struct repaper_epd *epd = drm_to_epd(pipe->crtc.dev); in repaper_pipe_disable()
776 struct spi_device *spi = epd->spi; in repaper_pipe_disable()
789 for (line = 0; line < epd->height; line++) in repaper_pipe_disable()
794 if (epd->border) { in repaper_pipe_disable()
799 gpiod_set_value_cansleep(epd->border, 0); in repaper_pipe_disable()
801 gpiod_set_value_cansleep(epd->border, 1); in repaper_pipe_disable()
832 struct drm_plane_state *state = pipe->plane.state; in repaper_pipe_update()
835 if (!pipe->crtc.state->active) in repaper_pipe_update()
839 repaper_fb_dirty(state->fb); in repaper_pipe_update()
851 struct repaper_epd *epd = drm_to_epd(connector->dev); in repaper_connector_get_modes()
853 return drm_connector_helper_get_modes_fixed(connector, epd->mode); in repaper_connector_get_modes()
913 .desc = "Pervasive Displays RePaper e-ink panels",
941 struct device *dev = &spi->dev; in repaper_probe()
955 model = (enum repaper_model)spi_id->driver_data; in repaper_probe()
959 if (!dev->coherent_dma_mask) { in repaper_probe()
972 drm = &epd->drm; in repaper_probe()
977 drm->mode_config.funcs = &repaper_mode_config_funcs; in repaper_probe()
979 epd->spi = spi; in repaper_probe()
981 epd->panel_on = devm_gpiod_get(dev, "panel-on", GPIOD_OUT_LOW); in repaper_probe()
982 if (IS_ERR(epd->panel_on)) { in repaper_probe()
983 ret = PTR_ERR(epd->panel_on); in repaper_probe()
984 if (ret != -EPROBE_DEFER) in repaper_probe()
985 DRM_DEV_ERROR(dev, "Failed to get gpio 'panel-on'\n"); in repaper_probe()
989 epd->discharge = devm_gpiod_get(dev, "discharge", GPIOD_OUT_LOW); in repaper_probe()
990 if (IS_ERR(epd->discharge)) { in repaper_probe()
991 ret = PTR_ERR(epd->discharge); in repaper_probe()
992 if (ret != -EPROBE_DEFER) in repaper_probe()
997 epd->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in repaper_probe()
998 if (IS_ERR(epd->reset)) { in repaper_probe()
999 ret = PTR_ERR(epd->reset); in repaper_probe()
1000 if (ret != -EPROBE_DEFER) in repaper_probe()
1005 epd->busy = devm_gpiod_get(dev, "busy", GPIOD_IN); in repaper_probe()
1006 if (IS_ERR(epd->busy)) { in repaper_probe()
1007 ret = PTR_ERR(epd->busy); in repaper_probe()
1008 if (ret != -EPROBE_DEFER) in repaper_probe()
1013 if (!device_property_read_string(dev, "pervasive,thermal-zone", in repaper_probe()
1015 epd->thermal = thermal_zone_get_zone_by_name(thermal_zone); in repaper_probe()
1016 if (IS_ERR(epd->thermal)) { in repaper_probe()
1018 return PTR_ERR(epd->thermal); in repaper_probe()
1025 epd->channel_select = repaper_e1144cs021_cs; in repaper_probe()
1026 epd->stage_time = 480; in repaper_probe()
1027 epd->bytes_per_scan = 96 / 4; in repaper_probe()
1028 epd->middle_scan = true; /* data-scan-data */ in repaper_probe()
1029 epd->pre_border_byte = false; in repaper_probe()
1030 epd->border_byte = REPAPER_BORDER_BYTE_ZERO; in repaper_probe()
1035 epd->channel_select = repaper_e1190cs021_cs; in repaper_probe()
1036 epd->stage_time = 480; in repaper_probe()
1037 epd->bytes_per_scan = 128 / 4 / 2; in repaper_probe()
1038 epd->middle_scan = false; /* scan-data-scan */ in repaper_probe()
1039 epd->pre_border_byte = false; in repaper_probe()
1040 epd->border_byte = REPAPER_BORDER_BYTE_SET; in repaper_probe()
1045 epd->channel_select = repaper_e2200cs021_cs; in repaper_probe()
1046 epd->stage_time = 480; in repaper_probe()
1047 epd->bytes_per_scan = 96 / 4; in repaper_probe()
1048 epd->middle_scan = true; /* data-scan-data */ in repaper_probe()
1049 epd->pre_border_byte = true; in repaper_probe()
1050 epd->border_byte = REPAPER_BORDER_BYTE_NONE; in repaper_probe()
1054 epd->border = devm_gpiod_get(dev, "border", GPIOD_OUT_LOW); in repaper_probe()
1055 if (IS_ERR(epd->border)) { in repaper_probe()
1056 ret = PTR_ERR(epd->border); in repaper_probe()
1057 if (ret != -EPROBE_DEFER) in repaper_probe()
1063 epd->channel_select = repaper_e2271cs021_cs; in repaper_probe()
1064 epd->stage_time = 630; in repaper_probe()
1065 epd->bytes_per_scan = 176 / 4; in repaper_probe()
1066 epd->middle_scan = true; /* data-scan-data */ in repaper_probe()
1067 epd->pre_border_byte = true; in repaper_probe()
1068 epd->border_byte = REPAPER_BORDER_BYTE_NONE; in repaper_probe()
1072 return -ENODEV; in repaper_probe()
1075 epd->mode = mode; in repaper_probe()
1076 epd->width = mode->hdisplay; in repaper_probe()
1077 epd->height = mode->vdisplay; in repaper_probe()
1078 epd->factored_stage_time = epd->stage_time; in repaper_probe()
1080 line_buffer_size = 2 * epd->width / 8 + epd->bytes_per_scan + 2; in repaper_probe()
1081 epd->line_buffer = devm_kzalloc(dev, line_buffer_size, GFP_KERNEL); in repaper_probe()
1082 if (!epd->line_buffer) in repaper_probe()
1083 return -ENOMEM; in repaper_probe()
1085 epd->current_frame = devm_kzalloc(dev, epd->width * epd->height / 8, in repaper_probe()
1087 if (!epd->current_frame) in repaper_probe()
1088 return -ENOMEM; in repaper_probe()
1090 drm->mode_config.min_width = mode->hdisplay; in repaper_probe()
1091 drm->mode_config.max_width = mode->hdisplay; in repaper_probe()
1092 drm->mode_config.min_height = mode->vdisplay; in repaper_probe()
1093 drm->mode_config.max_height = mode->vdisplay; in repaper_probe()
1095 drm_connector_helper_add(&epd->connector, &repaper_connector_hfuncs); in repaper_probe()
1096 ret = drm_connector_init(drm, &epd->connector, &repaper_connector_funcs, in repaper_probe()
1101 ret = drm_simple_display_pipe_init(drm, &epd->pipe, &repaper_pipe_funcs, in repaper_probe()
1103 NULL, &epd->connector); in repaper_probe()
1115 DRM_DEBUG_DRIVER("SPI speed: %uMHz\n", spi->max_speed_hz / 1000000); in repaper_probe()