Lines Matching refs:ssd130x

165 static int ssd130x_write_data(struct ssd130x_device *ssd130x, u8 *values, int count)  in ssd130x_write_data()  argument
167 return regmap_bulk_write(ssd130x->regmap, SSD130X_DATA, values, count); in ssd130x_write_data()
178 static int ssd130x_write_cmd(struct ssd130x_device *ssd130x, int count, in ssd130x_write_cmd() argument
189 ret = regmap_write(ssd130x->regmap, SSD130X_COMMAND, value); in ssd130x_write_cmd()
201 static int ssd130x_set_col_range(struct ssd130x_device *ssd130x, in ssd130x_set_col_range() argument
207 if (col_start == ssd130x->col_start && col_end == ssd130x->col_end) in ssd130x_set_col_range()
210 ret = ssd130x_write_cmd(ssd130x, 3, SSD130X_SET_COL_RANGE, col_start, col_end); in ssd130x_set_col_range()
214 ssd130x->col_start = col_start; in ssd130x_set_col_range()
215 ssd130x->col_end = col_end; in ssd130x_set_col_range()
219 static int ssd130x_set_page_range(struct ssd130x_device *ssd130x, in ssd130x_set_page_range() argument
225 if (page_start == ssd130x->page_start && page_end == ssd130x->page_end) in ssd130x_set_page_range()
228 ret = ssd130x_write_cmd(ssd130x, 3, SSD130X_SET_PAGE_RANGE, page_start, page_end); in ssd130x_set_page_range()
232 ssd130x->page_start = page_start; in ssd130x_set_page_range()
233 ssd130x->page_end = page_end; in ssd130x_set_page_range()
238 static int ssd130x_set_page_pos(struct ssd130x_device *ssd130x, in ssd130x_set_page_pos() argument
250 ret = ssd130x_write_cmd(ssd130x, 3, page, col_low, col_high); in ssd130x_set_page_pos()
257 static int ssd130x_pwm_enable(struct ssd130x_device *ssd130x) in ssd130x_pwm_enable() argument
259 struct device *dev = ssd130x->dev; in ssd130x_pwm_enable()
262 ssd130x->pwm = pwm_get(dev, NULL); in ssd130x_pwm_enable()
263 if (IS_ERR(ssd130x->pwm)) { in ssd130x_pwm_enable()
265 return PTR_ERR(ssd130x->pwm); in ssd130x_pwm_enable()
268 pwm_init_state(ssd130x->pwm, &pwmstate); in ssd130x_pwm_enable()
270 pwm_apply_might_sleep(ssd130x->pwm, &pwmstate); in ssd130x_pwm_enable()
273 pwm_enable(ssd130x->pwm); in ssd130x_pwm_enable()
276 ssd130x->pwm->pwm, pwm_get_period(ssd130x->pwm)); in ssd130x_pwm_enable()
281 static void ssd130x_reset(struct ssd130x_device *ssd130x) in ssd130x_reset() argument
283 if (!ssd130x->reset) in ssd130x_reset()
287 gpiod_set_value_cansleep(ssd130x->reset, 1); in ssd130x_reset()
289 gpiod_set_value_cansleep(ssd130x->reset, 0); in ssd130x_reset()
293 static int ssd130x_power_on(struct ssd130x_device *ssd130x) in ssd130x_power_on() argument
295 struct device *dev = ssd130x->dev; in ssd130x_power_on()
298 ssd130x_reset(ssd130x); in ssd130x_power_on()
300 ret = regulator_enable(ssd130x->vcc_reg); in ssd130x_power_on()
306 if (ssd130x->device_info->need_pwm) { in ssd130x_power_on()
307 ret = ssd130x_pwm_enable(ssd130x); in ssd130x_power_on()
310 regulator_disable(ssd130x->vcc_reg); in ssd130x_power_on()
318 static void ssd130x_power_off(struct ssd130x_device *ssd130x) in ssd130x_power_off() argument
320 pwm_disable(ssd130x->pwm); in ssd130x_power_off()
321 pwm_put(ssd130x->pwm); in ssd130x_power_off()
323 regulator_disable(ssd130x->vcc_reg); in ssd130x_power_off()
326 static int ssd130x_init(struct ssd130x_device *ssd130x) in ssd130x_init() argument
333 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_CONTRAST, ssd130x->contrast); in ssd130x_init()
339 SSD130X_SET_SEG_REMAP_SET(ssd130x->seg_remap)); in ssd130x_init()
340 ret = ssd130x_write_cmd(ssd130x, 1, seg_remap); in ssd130x_init()
346 SSD130X_SET_COM_SCAN_DIR_SET(ssd130x->com_invdir)); in ssd130x_init()
347 ret = ssd130x_write_cmd(ssd130x, 1, com_invdir); in ssd130x_init()
352 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_MULTIPLEX_RATIO, ssd130x->height - 1); in ssd130x_init()
357 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_DISPLAY_OFFSET, ssd130x->com_offset); in ssd130x_init()
362 dclk = (SSD130X_SET_CLOCK_DIV_SET(ssd130x->dclk_div - 1) | in ssd130x_init()
363 SSD130X_SET_CLOCK_FREQ_SET(ssd130x->dclk_frq)); in ssd130x_init()
364 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_CLOCK_FREQ, dclk); in ssd130x_init()
369 if (ssd130x->area_color_enable || ssd130x->low_power) { in ssd130x_init()
372 if (ssd130x->area_color_enable) in ssd130x_init()
375 if (ssd130x->low_power) in ssd130x_init()
378 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_AREA_COLOR_MODE, mode); in ssd130x_init()
384 precharge = (SSD130X_SET_PRECHARGE_PERIOD1_SET(ssd130x->prechargep1) | in ssd130x_init()
385 SSD130X_SET_PRECHARGE_PERIOD2_SET(ssd130x->prechargep2)); in ssd130x_init()
386 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_PRECHARGE_PERIOD, precharge); in ssd130x_init()
397 scan_mode = !ssd130x->com_seq; in ssd130x_init()
399 SSD130X_SET_COM_PINS_CONFIG2_SET(ssd130x->com_lrremap)); in ssd130x_init()
400 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_COM_PINS_CONFIG, compins); in ssd130x_init()
405 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_VCOMH, ssd130x->vcomh); in ssd130x_init()
412 if (ssd130x->device_info->need_chargepump) in ssd130x_init()
415 ret = ssd130x_write_cmd(ssd130x, 2, SSD130X_CHARGE_PUMP, chargepump); in ssd130x_init()
420 if (ssd130x->lookup_table_set) { in ssd130x_init()
423 ret = ssd130x_write_cmd(ssd130x, 1, SSD130X_SET_LOOKUP_TABLE); in ssd130x_init()
427 for (i = 0; i < ARRAY_SIZE(ssd130x->lookup_table); i++) { in ssd130x_init()
428 u8 val = ssd130x->lookup_table[i]; in ssd130x_init()
431 dev_warn(ssd130x->dev, in ssd130x_init()
434 ret = ssd130x_write_cmd(ssd130x, 1, val); in ssd130x_init()
441 if (ssd130x->page_address_mode) in ssd130x_init()
442 return ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_ADDRESS_MODE, in ssd130x_init()
446 return ssd130x_write_cmd(ssd130x, 2, SSD130X_SET_ADDRESS_MODE, in ssd130x_init()
450 static int ssd130x_update_rect(struct ssd130x_device *ssd130x, in ssd130x_update_rect() argument
461 unsigned int page_height = ssd130x->device_info->page_height; in ssd130x_update_rect()
463 struct drm_device *drm = &ssd130x->drm; in ssd130x_update_rect()
498 if (!ssd130x->page_address_mode) { in ssd130x_update_rect()
500 ret = ssd130x_set_col_range(ssd130x, ssd130x->col_offset + x, width); in ssd130x_update_rect()
504 ret = ssd130x_set_page_range(ssd130x, ssd130x->page_offset + y / 8, pages); in ssd130x_update_rect()
513 if (8 * (y / 8 + i + 1) > ssd130x->height) in ssd130x_update_rect()
514 m = ssd130x->height % 8; in ssd130x_update_rect()
531 if (ssd130x->page_address_mode) { in ssd130x_update_rect()
532 ret = ssd130x_set_page_pos(ssd130x, in ssd130x_update_rect()
533 ssd130x->page_offset + i, in ssd130x_update_rect()
534 ssd130x->col_offset + x); in ssd130x_update_rect()
538 ret = ssd130x_write_data(ssd130x, data_array, width); in ssd130x_update_rect()
547 if (!ssd130x->page_address_mode) in ssd130x_update_rect()
548 ret = ssd130x_write_data(ssd130x, data_array, width * pages); in ssd130x_update_rect()
553 static void ssd130x_clear_screen(struct ssd130x_device *ssd130x, in ssd130x_clear_screen() argument
556 unsigned int page_height = ssd130x->device_info->page_height; in ssd130x_clear_screen()
557 unsigned int pages = DIV_ROUND_UP(ssd130x->height, page_height); in ssd130x_clear_screen()
559 unsigned int width = ssd130x->width; in ssd130x_clear_screen()
562 if (!ssd130x->page_address_mode) { in ssd130x_clear_screen()
566 ret = ssd130x_set_col_range(ssd130x, ssd130x->col_offset, width); in ssd130x_clear_screen()
570 ret = ssd130x_set_page_range(ssd130x, ssd130x->page_offset, pages); in ssd130x_clear_screen()
575 ssd130x_write_data(ssd130x, data_array, width * pages); in ssd130x_clear_screen()
584 ret = ssd130x_set_page_pos(ssd130x, in ssd130x_clear_screen()
585 ssd130x->page_offset + i, in ssd130x_clear_screen()
586 ssd130x->col_offset); in ssd130x_clear_screen()
590 ret = ssd130x_write_data(ssd130x, data_array, width); in ssd130x_clear_screen()
602 struct ssd130x_device *ssd130x = drm_to_ssd130x(fb->dev); in ssd130x_fb_blit_rect() local
603 unsigned int page_height = ssd130x->device_info->page_height; in ssd130x_fb_blit_rect()
612 rect->y2 = min_t(unsigned int, round_up(rect->y2, page_height), ssd130x->height); in ssd130x_fb_blit_rect()
625 ssd130x_update_rect(ssd130x, ssd130x_state, rect); in ssd130x_fb_blit_rect()
634 struct ssd130x_device *ssd130x = drm_to_ssd130x(drm); in ssd130x_primary_plane_helper_atomic_check() local
637 unsigned int page_height = ssd130x->device_info->page_height; in ssd130x_primary_plane_helper_atomic_check()
638 unsigned int pages = DIV_ROUND_UP(ssd130x->height, page_height); in ssd130x_primary_plane_helper_atomic_check()
651 pitch = drm_format_info_min_pitch(fi, 0, ssd130x->width); in ssd130x_primary_plane_helper_atomic_check()
653 ssd130x_state->buffer = kcalloc(pitch, ssd130x->height, GFP_KERNEL); in ssd130x_primary_plane_helper_atomic_check()
657 ssd130x_state->data_array = kcalloc(ssd130x->width, pages, GFP_KERNEL); in ssd130x_primary_plane_helper_atomic_check()
700 struct ssd130x_device *ssd130x = drm_to_ssd130x(drm); in ssd130x_primary_plane_helper_atomic_disable() local
707 ssd130x_clear_screen(ssd130x, ssd130x_state); in ssd130x_primary_plane_helper_atomic_disable()
783 struct ssd130x_device *ssd130x = drm_to_ssd130x(crtc->dev); in ssd130x_crtc_helper_mode_valid() local
785 if (mode->hdisplay != ssd130x->mode.hdisplay && in ssd130x_crtc_helper_mode_valid()
786 mode->vdisplay != ssd130x->mode.vdisplay) in ssd130x_crtc_helper_mode_valid()
788 else if (mode->hdisplay != ssd130x->mode.hdisplay) in ssd130x_crtc_helper_mode_valid()
790 else if (mode->vdisplay != ssd130x->mode.vdisplay) in ssd130x_crtc_helper_mode_valid()
819 struct ssd130x_device *ssd130x = drm_to_ssd130x(drm); in ssd130x_encoder_helper_atomic_enable() local
822 ret = ssd130x_power_on(ssd130x); in ssd130x_encoder_helper_atomic_enable()
826 ret = ssd130x_init(ssd130x); in ssd130x_encoder_helper_atomic_enable()
830 ssd130x_write_cmd(ssd130x, 1, SSD130X_DISPLAY_ON); in ssd130x_encoder_helper_atomic_enable()
832 backlight_enable(ssd130x->bl_dev); in ssd130x_encoder_helper_atomic_enable()
837 ssd130x_power_off(ssd130x); in ssd130x_encoder_helper_atomic_enable()
845 struct ssd130x_device *ssd130x = drm_to_ssd130x(drm); in ssd130x_encoder_helper_atomic_disable() local
847 backlight_disable(ssd130x->bl_dev); in ssd130x_encoder_helper_atomic_disable()
849 ssd130x_write_cmd(ssd130x, 1, SSD130X_DISPLAY_OFF); in ssd130x_encoder_helper_atomic_disable()
851 ssd130x_power_off(ssd130x); in ssd130x_encoder_helper_atomic_disable()
865 struct ssd130x_device *ssd130x = drm_to_ssd130x(connector->dev); in ssd130x_connector_helper_get_modes() local
867 struct device *dev = ssd130x->dev; in ssd130x_connector_helper_get_modes()
869 mode = drm_mode_duplicate(connector->dev, &ssd130x->mode); in ssd130x_connector_helper_get_modes()
919 struct ssd130x_device *ssd130x = bl_get_data(bdev); in ssd130x_update_bl() local
923 ssd130x->contrast = brightness; in ssd130x_update_bl()
925 ret = ssd130x_write_cmd(ssd130x, 1, SSD130X_CONTRAST); in ssd130x_update_bl()
929 ret = ssd130x_write_cmd(ssd130x, 1, ssd130x->contrast); in ssd130x_update_bl()
940 static void ssd130x_parse_properties(struct ssd130x_device *ssd130x) in ssd130x_parse_properties() argument
942 struct device *dev = ssd130x->dev; in ssd130x_parse_properties()
944 if (device_property_read_u32(dev, "solomon,width", &ssd130x->width)) in ssd130x_parse_properties()
945 ssd130x->width = ssd130x->device_info->default_width; in ssd130x_parse_properties()
947 if (device_property_read_u32(dev, "solomon,height", &ssd130x->height)) in ssd130x_parse_properties()
948 ssd130x->height = ssd130x->device_info->default_height; in ssd130x_parse_properties()
950 if (device_property_read_u32(dev, "solomon,page-offset", &ssd130x->page_offset)) in ssd130x_parse_properties()
951 ssd130x->page_offset = 1; in ssd130x_parse_properties()
953 if (device_property_read_u32(dev, "solomon,col-offset", &ssd130x->col_offset)) in ssd130x_parse_properties()
954 ssd130x->col_offset = 0; in ssd130x_parse_properties()
956 if (device_property_read_u32(dev, "solomon,com-offset", &ssd130x->com_offset)) in ssd130x_parse_properties()
957 ssd130x->com_offset = 0; in ssd130x_parse_properties()
959 if (device_property_read_u32(dev, "solomon,prechargep1", &ssd130x->prechargep1)) in ssd130x_parse_properties()
960 ssd130x->prechargep1 = 2; in ssd130x_parse_properties()
962 if (device_property_read_u32(dev, "solomon,prechargep2", &ssd130x->prechargep2)) in ssd130x_parse_properties()
963 ssd130x->prechargep2 = 2; in ssd130x_parse_properties()
966 ssd130x->lookup_table, in ssd130x_parse_properties()
967 ARRAY_SIZE(ssd130x->lookup_table))) in ssd130x_parse_properties()
968 ssd130x->lookup_table_set = 1; in ssd130x_parse_properties()
970 ssd130x->seg_remap = !device_property_read_bool(dev, "solomon,segment-no-remap"); in ssd130x_parse_properties()
971 ssd130x->com_seq = device_property_read_bool(dev, "solomon,com-seq"); in ssd130x_parse_properties()
972 ssd130x->com_lrremap = device_property_read_bool(dev, "solomon,com-lrremap"); in ssd130x_parse_properties()
973 ssd130x->com_invdir = device_property_read_bool(dev, "solomon,com-invdir"); in ssd130x_parse_properties()
974 ssd130x->area_color_enable = in ssd130x_parse_properties()
976 ssd130x->low_power = device_property_read_bool(dev, "solomon,low-power"); in ssd130x_parse_properties()
978 ssd130x->contrast = 127; in ssd130x_parse_properties()
979 ssd130x->vcomh = ssd130x->device_info->default_vcomh; in ssd130x_parse_properties()
982 if (device_property_read_u32(dev, "solomon,dclk-div", &ssd130x->dclk_div)) in ssd130x_parse_properties()
983 ssd130x->dclk_div = ssd130x->device_info->default_dclk_div; in ssd130x_parse_properties()
984 if (device_property_read_u32(dev, "solomon,dclk-frq", &ssd130x->dclk_frq)) in ssd130x_parse_properties()
985 ssd130x->dclk_frq = ssd130x->device_info->default_dclk_frq; in ssd130x_parse_properties()
988 static int ssd130x_init_modeset(struct ssd130x_device *ssd130x) in ssd130x_init_modeset() argument
990 struct drm_display_mode *mode = &ssd130x->mode; in ssd130x_init_modeset()
991 struct device *dev = ssd130x->dev; in ssd130x_init_modeset()
992 struct drm_device *drm = &ssd130x->drm; in ssd130x_init_modeset()
1012 mode->hdisplay = mode->htotal = ssd130x->width; in ssd130x_init_modeset()
1013 mode->hsync_start = mode->hsync_end = ssd130x->width; in ssd130x_init_modeset()
1014 mode->vdisplay = mode->vtotal = ssd130x->height; in ssd130x_init_modeset()
1015 mode->vsync_start = mode->vsync_end = ssd130x->height; in ssd130x_init_modeset()
1031 primary_plane = &ssd130x->primary_plane; in ssd130x_init_modeset()
1046 crtc = &ssd130x->crtc; in ssd130x_init_modeset()
1058 encoder = &ssd130x->encoder; in ssd130x_init_modeset()
1072 connector = &ssd130x->connector; in ssd130x_init_modeset()
1093 static int ssd130x_get_resources(struct ssd130x_device *ssd130x) in ssd130x_get_resources() argument
1095 struct device *dev = ssd130x->dev; in ssd130x_get_resources()
1097 ssd130x->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); in ssd130x_get_resources()
1098 if (IS_ERR(ssd130x->reset)) in ssd130x_get_resources()
1099 return dev_err_probe(dev, PTR_ERR(ssd130x->reset), in ssd130x_get_resources()
1102 ssd130x->vcc_reg = devm_regulator_get(dev, "vcc"); in ssd130x_get_resources()
1103 if (IS_ERR(ssd130x->vcc_reg)) in ssd130x_get_resources()
1104 return dev_err_probe(dev, PTR_ERR(ssd130x->vcc_reg), in ssd130x_get_resources()
1112 struct ssd130x_device *ssd130x; in ssd130x_probe() local
1117 ssd130x = devm_drm_dev_alloc(dev, &ssd130x_drm_driver, in ssd130x_probe()
1119 if (IS_ERR(ssd130x)) in ssd130x_probe()
1120 return ERR_PTR(dev_err_probe(dev, PTR_ERR(ssd130x), in ssd130x_probe()
1123 drm = &ssd130x->drm; in ssd130x_probe()
1125 ssd130x->dev = dev; in ssd130x_probe()
1126 ssd130x->regmap = regmap; in ssd130x_probe()
1127 ssd130x->device_info = device_get_match_data(dev); in ssd130x_probe()
1129 if (ssd130x->device_info->page_mode_only) in ssd130x_probe()
1130 ssd130x->page_address_mode = 1; in ssd130x_probe()
1132 ssd130x_parse_properties(ssd130x); in ssd130x_probe()
1134 ret = ssd130x_get_resources(ssd130x); in ssd130x_probe()
1138 bl = devm_backlight_device_register(dev, dev_name(dev), dev, ssd130x, in ssd130x_probe()
1144 bl->props.brightness = ssd130x->contrast; in ssd130x_probe()
1146 ssd130x->bl_dev = bl; in ssd130x_probe()
1148 ret = ssd130x_init_modeset(ssd130x); in ssd130x_probe()
1158 return ssd130x; in ssd130x_probe()
1162 void ssd130x_remove(struct ssd130x_device *ssd130x) in ssd130x_remove() argument
1164 drm_dev_unplug(&ssd130x->drm); in ssd130x_remove()
1168 void ssd130x_shutdown(struct ssd130x_device *ssd130x) in ssd130x_shutdown() argument
1170 drm_atomic_helper_shutdown(&ssd130x->drm); in ssd130x_shutdown()