Lines Matching +full:odd +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()
516 struct repaper_epd *epd = drm_to_epd(fb->dev); in repaper_fb_dirty()
523 if (!drm_dev_enter(fb->dev, &idx)) in repaper_fb_dirty()
524 return -ENODEV; in repaper_fb_dirty()
528 clip.x2 = fb->width; in repaper_fb_dirty()
530 clip.y2 = fb->height; in repaper_fb_dirty()
534 DRM_DEBUG("Flushing [FB:%d] st=%ums\n", fb->base.id, in repaper_fb_dirty()
535 epd->factored_stage_time); in repaper_fb_dirty()
537 buf = kmalloc(fb->width * fb->height / 8, GFP_KERNEL); in repaper_fb_dirty()
539 ret = -ENOMEM; in repaper_fb_dirty()
548 iosys_map_set_vaddr(&vmap, dma_obj->vaddr); in repaper_fb_dirty()
553 if (epd->partial) { in repaper_fb_dirty()
554 repaper_frame_data_repeat(epd, buf, epd->current_frame, in repaper_fb_dirty()
556 } else if (epd->cleared) { in repaper_fb_dirty()
557 repaper_frame_data_repeat(epd, epd->current_frame, NULL, in repaper_fb_dirty()
559 repaper_frame_data_repeat(epd, epd->current_frame, NULL, in repaper_fb_dirty()
564 epd->partial = true; in repaper_fb_dirty()
566 /* Clear display (anything -> white) */ in repaper_fb_dirty()
578 epd->cleared = true; in repaper_fb_dirty()
579 epd->partial = true; in repaper_fb_dirty()
582 memcpy(epd->current_frame, buf, fb->width * fb->height / 8); in repaper_fb_dirty()
588 if (epd->pre_border_byte) { in repaper_fb_dirty()
591 for (x = 0; x < (fb->width / 8); x++) in repaper_fb_dirty()
592 if (buf[x + (fb->width * (fb->height - 1) / 8)]) { in repaper_fb_dirty()
594 epd->current_frame, in repaper_fb_dirty()
611 gpiod_set_value_cansleep(epd->reset, 0); in power_off()
612 gpiod_set_value_cansleep(epd->panel_on, 0); in power_off()
613 if (epd->border) in power_off()
614 gpiod_set_value_cansleep(epd->border, 0); in power_off()
617 repaper_spi_mosi_low(epd->spi); in power_off()
620 gpiod_set_value_cansleep(epd->discharge, 1); in power_off()
622 gpiod_set_value_cansleep(epd->discharge, 0); in power_off()
628 struct drm_crtc *crtc = &pipe->crtc; in repaper_pipe_mode_valid()
629 struct repaper_epd *epd = drm_to_epd(crtc->dev); in repaper_pipe_mode_valid()
631 return drm_crtc_helper_mode_valid_fixed(crtc, mode, epd->mode); in repaper_pipe_mode_valid()
638 struct repaper_epd *epd = drm_to_epd(pipe->crtc.dev); in repaper_pipe_enable()
639 struct spi_device *spi = epd->spi; in repaper_pipe_enable()
640 struct device *dev = &spi->dev; in repaper_pipe_enable()
644 if (!drm_dev_enter(pipe->crtc.dev, &idx)) in repaper_pipe_enable()
650 gpiod_set_value_cansleep(epd->reset, 0); in repaper_pipe_enable()
651 gpiod_set_value_cansleep(epd->panel_on, 0); in repaper_pipe_enable()
652 gpiod_set_value_cansleep(epd->discharge, 0); in repaper_pipe_enable()
653 if (epd->border) in repaper_pipe_enable()
654 gpiod_set_value_cansleep(epd->border, 0); in repaper_pipe_enable()
658 gpiod_set_value_cansleep(epd->panel_on, 1); in repaper_pipe_enable()
664 gpiod_set_value_cansleep(epd->reset, 1); in repaper_pipe_enable()
665 if (epd->border) in repaper_pipe_enable()
666 gpiod_set_value_cansleep(epd->border, 1); in repaper_pipe_enable()
668 gpiod_set_value_cansleep(epd->reset, 0); in repaper_pipe_enable()
670 gpiod_set_value_cansleep(epd->reset, 1); in repaper_pipe_enable()
674 for (i = 100; i > 0; i--) { in repaper_pipe_enable()
675 if (!gpiod_get_value_cansleep(epd->busy)) in repaper_pipe_enable()
714 repaper_write_buf(spi, 0x01, epd->channel_select, 8); in repaper_pipe_enable()
731 /* Charge pump positive voltage on - VGH/VDL on */ in repaper_pipe_enable()
735 /* Charge pump negative voltage on - VGL/VDL on */ in repaper_pipe_enable()
739 /* Charge pump Vcom on - Vcom driver on */ in repaper_pipe_enable()
769 epd->partial = false; in repaper_pipe_enable()
776 struct repaper_epd *epd = drm_to_epd(pipe->crtc.dev); in repaper_pipe_disable()
777 struct spi_device *spi = epd->spi; in repaper_pipe_disable()
790 for (line = 0; line < epd->height; line++) in repaper_pipe_disable()
795 if (epd->border) { in repaper_pipe_disable()
800 gpiod_set_value_cansleep(epd->border, 0); in repaper_pipe_disable()
802 gpiod_set_value_cansleep(epd->border, 1); in repaper_pipe_disable()
833 struct drm_plane_state *state = pipe->plane.state; in repaper_pipe_update()
837 if (!pipe->crtc.state->active) in repaper_pipe_update()
841 repaper_fb_dirty(state->fb, &fmtcnv_state); in repaper_pipe_update()
855 struct repaper_epd *epd = drm_to_epd(connector->dev); in repaper_connector_get_modes()
857 return drm_connector_helper_get_modes_fixed(connector, epd->mode); in repaper_connector_get_modes()
917 .desc = "Pervasive Displays RePaper e-ink panels",
945 struct device *dev = &spi->dev; in repaper_probe()
959 model = (enum repaper_model)spi_id->driver_data; in repaper_probe()
963 if (!dev->coherent_dma_mask) { in repaper_probe()
976 drm = &epd->drm; in repaper_probe()
981 drm->mode_config.funcs = &repaper_mode_config_funcs; in repaper_probe()
983 epd->spi = spi; in repaper_probe()
985 epd->panel_on = devm_gpiod_get(dev, "panel-on", GPIOD_OUT_LOW); in repaper_probe()
986 if (IS_ERR(epd->panel_on)) { in repaper_probe()
987 ret = PTR_ERR(epd->panel_on); in repaper_probe()
988 if (ret != -EPROBE_DEFER) in repaper_probe()
989 DRM_DEV_ERROR(dev, "Failed to get gpio 'panel-on'\n"); in repaper_probe()
993 epd->discharge = devm_gpiod_get(dev, "discharge", GPIOD_OUT_LOW); in repaper_probe()
994 if (IS_ERR(epd->discharge)) { in repaper_probe()
995 ret = PTR_ERR(epd->discharge); in repaper_probe()
996 if (ret != -EPROBE_DEFER) in repaper_probe()
1001 epd->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW); in repaper_probe()
1002 if (IS_ERR(epd->reset)) { in repaper_probe()
1003 ret = PTR_ERR(epd->reset); in repaper_probe()
1004 if (ret != -EPROBE_DEFER) in repaper_probe()
1009 epd->busy = devm_gpiod_get(dev, "busy", GPIOD_IN); in repaper_probe()
1010 if (IS_ERR(epd->busy)) { in repaper_probe()
1011 ret = PTR_ERR(epd->busy); in repaper_probe()
1012 if (ret != -EPROBE_DEFER) in repaper_probe()
1017 if (!device_property_read_string(dev, "pervasive,thermal-zone", in repaper_probe()
1019 epd->thermal = thermal_zone_get_zone_by_name(thermal_zone); in repaper_probe()
1020 if (IS_ERR(epd->thermal)) { in repaper_probe()
1022 return PTR_ERR(epd->thermal); in repaper_probe()
1029 epd->channel_select = repaper_e1144cs021_cs; in repaper_probe()
1030 epd->stage_time = 480; in repaper_probe()
1031 epd->bytes_per_scan = 96 / 4; in repaper_probe()
1032 epd->middle_scan = true; /* data-scan-data */ in repaper_probe()
1033 epd->pre_border_byte = false; in repaper_probe()
1034 epd->border_byte = REPAPER_BORDER_BYTE_ZERO; in repaper_probe()
1039 epd->channel_select = repaper_e1190cs021_cs; in repaper_probe()
1040 epd->stage_time = 480; in repaper_probe()
1041 epd->bytes_per_scan = 128 / 4 / 2; in repaper_probe()
1042 epd->middle_scan = false; /* scan-data-scan */ in repaper_probe()
1043 epd->pre_border_byte = false; in repaper_probe()
1044 epd->border_byte = REPAPER_BORDER_BYTE_SET; in repaper_probe()
1049 epd->channel_select = repaper_e2200cs021_cs; in repaper_probe()
1050 epd->stage_time = 480; in repaper_probe()
1051 epd->bytes_per_scan = 96 / 4; in repaper_probe()
1052 epd->middle_scan = true; /* data-scan-data */ in repaper_probe()
1053 epd->pre_border_byte = true; in repaper_probe()
1054 epd->border_byte = REPAPER_BORDER_BYTE_NONE; in repaper_probe()
1058 epd->border = devm_gpiod_get(dev, "border", GPIOD_OUT_LOW); in repaper_probe()
1059 if (IS_ERR(epd->border)) { in repaper_probe()
1060 ret = PTR_ERR(epd->border); in repaper_probe()
1061 if (ret != -EPROBE_DEFER) in repaper_probe()
1067 epd->channel_select = repaper_e2271cs021_cs; in repaper_probe()
1068 epd->stage_time = 630; in repaper_probe()
1069 epd->bytes_per_scan = 176 / 4; in repaper_probe()
1070 epd->middle_scan = true; /* data-scan-data */ in repaper_probe()
1071 epd->pre_border_byte = true; in repaper_probe()
1072 epd->border_byte = REPAPER_BORDER_BYTE_NONE; in repaper_probe()
1076 return -ENODEV; in repaper_probe()
1079 epd->mode = mode; in repaper_probe()
1080 epd->width = mode->hdisplay; in repaper_probe()
1081 epd->height = mode->vdisplay; in repaper_probe()
1082 epd->factored_stage_time = epd->stage_time; in repaper_probe()
1084 line_buffer_size = 2 * epd->width / 8 + epd->bytes_per_scan + 2; in repaper_probe()
1085 epd->line_buffer = devm_kzalloc(dev, line_buffer_size, GFP_KERNEL); in repaper_probe()
1086 if (!epd->line_buffer) in repaper_probe()
1087 return -ENOMEM; in repaper_probe()
1089 epd->current_frame = devm_kzalloc(dev, epd->width * epd->height / 8, in repaper_probe()
1091 if (!epd->current_frame) in repaper_probe()
1092 return -ENOMEM; in repaper_probe()
1094 drm->mode_config.min_width = mode->hdisplay; in repaper_probe()
1095 drm->mode_config.max_width = mode->hdisplay; in repaper_probe()
1096 drm->mode_config.min_height = mode->vdisplay; in repaper_probe()
1097 drm->mode_config.max_height = mode->vdisplay; in repaper_probe()
1099 drm_connector_helper_add(&epd->connector, &repaper_connector_hfuncs); in repaper_probe()
1100 ret = drm_connector_init(drm, &epd->connector, &repaper_connector_funcs, in repaper_probe()
1105 ret = drm_simple_display_pipe_init(drm, &epd->pipe, &repaper_pipe_funcs, in repaper_probe()
1107 NULL, &epd->connector); in repaper_probe()
1119 DRM_DEBUG_DRIVER("SPI speed: %uMHz\n", spi->max_speed_hz / 1000000); in repaper_probe()