-
Notifications
You must be signed in to change notification settings - Fork 5.5k
drm/panel: waveshare: Add automatic panel recognition for DSI panels #7553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EngineerWill
wants to merge
3
commits into
raspberrypi:rpi-6.18.y
Choose a base branch
from
waveshareteam:waveshare-dsi
base: rpi-6.18.y
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+146
−6
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ struct ws_panel { | |
| struct i2c_client *i2c; | ||
| const struct drm_display_mode *mode; | ||
| enum drm_panel_orientation orientation; | ||
| int lanes; | ||
| }; | ||
|
|
||
| struct ws_panel_data { | ||
|
|
@@ -345,6 +346,63 @@ static const struct ws_panel_data ws_panel_7_0_h_data = { | |
| .mode_flags = MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS, | ||
| }; | ||
|
|
||
| /* 10.1inch DSI LCD (E) | ||
| * https://www.waveshare.com/10.1inch-dsi-lcd-e.htm | ||
| */ | ||
| static const struct drm_display_mode ws_panel_1200x1920_60fps_mode = { | ||
| .clock = 166666, | ||
| .hdisplay = 1200, | ||
| .hsync_start = 1200 + 28, | ||
| .hsync_end = 1200 + 28 + 10, | ||
| .htotal = 1200 + 28 + 10 + 30, | ||
| .vdisplay = 1920, | ||
| .vsync_start = 1920 + 238, | ||
| .vsync_end = 1920 + 238 + 4, | ||
| .vtotal = 1920 + 238 + 4 + 28, | ||
| }; | ||
|
|
||
| static const struct drm_display_mode ws_panel_1200x1920_30fps_mode = { | ||
| .clock = 83333, | ||
| .hdisplay = 1200, | ||
| .hsync_start = 1200 + 28, | ||
| .hsync_end = 1200 + 28 + 10, | ||
| .htotal = 1200 + 28 + 10 + 30, | ||
| .vdisplay = 1920, | ||
| .vsync_start = 1920 + 238, | ||
| .vsync_end = 1920 + 238 + 4, | ||
| .vtotal = 1920 + 238 + 4 + 28, | ||
| }; | ||
|
|
||
| static const struct drm_display_mode ws_panel_1920x1200_60fps_mode = { | ||
| .clock = 166666, | ||
| .hdisplay = 1920, | ||
| .hsync_start = 1920 + 238, | ||
| .hsync_end = 1920 + 238 + 4, | ||
| .htotal = 1920 + 238 + 4 + 28, | ||
| .vdisplay = 1200, | ||
| .vsync_start = 1200 + 28, | ||
| .vsync_end = 1200 + 28 + 10, | ||
| .vtotal = 1200 + 28 + 10 + 30, | ||
| }; | ||
|
|
||
| static const struct drm_display_mode ws_panel_1920x1200_30fps_mode = { | ||
| .clock = 83333, | ||
| .hdisplay = 1920, | ||
| .hsync_start = 1920 + 238, | ||
| .hsync_end = 1920 + 238 + 4, | ||
| .htotal = 1920 + 238 + 4 + 28, | ||
| .vdisplay = 1200, | ||
| .vsync_start = 1200 + 28, | ||
| .vsync_end = 1200 + 28 + 10, | ||
| .vtotal = 1200 + 28 + 10 + 30, | ||
| }; | ||
|
|
||
| static const struct ws_panel_data ws_panel_automatic_data = { | ||
| .mode = NULL, | ||
| .lanes = 0, | ||
| .mode_flags = MIPI_DSI_MODE_VIDEO_HSE | MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS, | ||
| }; | ||
|
|
||
| static struct ws_panel *panel_to_ts(struct drm_panel *panel) | ||
| { | ||
| return container_of(panel, struct ws_panel, base); | ||
|
|
@@ -359,6 +417,68 @@ static void ws_panel_i2c_write(struct ws_panel *ts, u8 reg, u8 val) | |
| dev_err(&ts->i2c->dev, "I2C write failed: %d\n", ret); | ||
| } | ||
|
|
||
| static int ws_panel_i2c_read(struct ws_panel *ts, u8 reg) | ||
| { | ||
| int ret; | ||
|
|
||
| ret = i2c_smbus_read_byte_data(ts->i2c, reg); | ||
| if (ret < 0) | ||
| dev_err(&ts->i2c->dev, "read reg 0x%02x failed %d\n", reg, ret); | ||
| return ret; | ||
| } | ||
|
|
||
| static int ws_panel_auto_detect(struct ws_panel *ts) | ||
| { | ||
| int screen_type; | ||
| int rotate; | ||
| int fps; | ||
|
|
||
| fps = ws_panel_i2c_read(ts, 0xd0); | ||
| if (fps < 0) | ||
| return fps; | ||
|
|
||
| rotate = ws_panel_i2c_read(ts, 0xd1); | ||
| if (rotate < 0) | ||
| return rotate; | ||
|
|
||
| screen_type = ws_panel_i2c_read(ts, 0xd3); | ||
| if (screen_type < 0) | ||
| return screen_type; | ||
|
|
||
| dev_info(&ts->i2c->dev, | ||
| "automatic panel detect screen_type=0x%x rotate=0x%x fps=0x%x\n", | ||
| screen_type, rotate, fps); | ||
|
|
||
| if (screen_type == 0x01) { | ||
| switch (rotate) { | ||
| case 0: | ||
| case 2: | ||
| dev_info(&ts->i2c->dev, "select 1200x1920 panel\n"); | ||
| ts->mode = fps == 60 ? | ||
| &ws_panel_1200x1920_60fps_mode : | ||
| &ws_panel_1200x1920_30fps_mode; | ||
| break; | ||
| case 1: | ||
| case 3: | ||
| dev_info(&ts->i2c->dev, "select 1920x1200 panel\n"); | ||
| ts->mode = fps == 60 ? | ||
| &ws_panel_1920x1200_60fps_mode : | ||
| &ws_panel_1920x1200_30fps_mode; | ||
| break; | ||
| default: | ||
| dev_err(&ts->i2c->dev, "unknown rotate value %d\n", rotate); | ||
| return -EINVAL; | ||
| } | ||
| if (fps == 60) | ||
| ts->lanes = 4; | ||
| else | ||
| ts->lanes = 2; | ||
| return 0; | ||
| } | ||
| dev_err(&ts->i2c->dev, "unsupported panel D3=0x%x\n", screen_type); | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| static int ws_panel_disable(struct drm_panel *panel) | ||
| { | ||
| struct ws_panel *ts = panel_to_ts(panel); | ||
|
|
@@ -492,13 +612,24 @@ static int ws_panel_probe(struct i2c_client *i2c) | |
| if (!_ws_panel_data) | ||
| return -EINVAL; | ||
|
|
||
| ts->mode = _ws_panel_data->mode; | ||
| if (!ts->mode) | ||
| return -EINVAL; | ||
|
|
||
| ts->i2c = i2c; | ||
| i2c_set_clientdata(i2c, ts); | ||
| ts->lanes = _ws_panel_data->lanes; | ||
| /* | ||
| * automatic recognition panel | ||
| */ | ||
| if (of_device_is_compatible(dev->of_node, "waveshare,automatic-recognition-panel")) { | ||
| ret = ws_panel_auto_detect(ts); | ||
| if (ret) { | ||
| dev_err(dev, "panel auto detect failed\n"); | ||
| return ret; | ||
| } | ||
| } else { | ||
| ts->mode = _ws_panel_data->mode; | ||
| } | ||
|
|
||
| ts->i2c = i2c; | ||
| if (!ts->mode) | ||
| return -EINVAL; | ||
|
|
||
| ws_panel_i2c_write(ts, 0xc0, 0x01); | ||
| ws_panel_i2c_write(ts, 0xc2, 0x01); | ||
|
|
@@ -556,7 +687,7 @@ static int ws_panel_probe(struct i2c_client *i2c) | |
|
|
||
| ts->dsi->mode_flags = _ws_panel_data->mode_flags; | ||
| ts->dsi->format = MIPI_DSI_FMT_RGB888; | ||
| ts->dsi->lanes = _ws_panel_data->lanes; | ||
| ts->dsi->lanes = ts->lanes; | ||
|
|
||
| ret = devm_mipi_dsi_attach(dev, ts->dsi); | ||
|
|
||
|
|
@@ -583,6 +714,7 @@ static void ws_panel_shutdown(struct i2c_client *i2c) | |
| { | ||
| struct ws_panel *ts = i2c_get_clientdata(i2c); | ||
|
|
||
| ws_panel_i2c_write(ts, 0xd2, 0x5a); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems odd as nothing else ever writes register 0xd2. Note that |
||
| ws_panel_disable(&ts->base); | ||
| } | ||
|
|
||
|
|
@@ -635,6 +767,9 @@ static const struct of_device_id ws_panel_of_ids[] = { | |
| }, { | ||
| .compatible = "waveshare,7.0inch-h-panel", | ||
| .data = &ws_panel_7_0_h_data, | ||
| }, { | ||
| .compatible = "waveshare,automatic-recognition-panel", | ||
| .data = &ws_panel_automatic_data, | ||
| }, { | ||
| /* sentinel */ | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify this to
if (!_ws_panel_data->mode)