Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 115 additions & 24 deletions drivers/gpu/drm/sysfb/simpledrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ static int simplefb_get_panel_height_mm_of(struct drm_device *dev,
* Simple Framebuffer device
*/

#define H9G_NUM_EXTRA_MODES 4

struct simpledrm_device {
struct drm_sysfb_device sysfb;
void __iomem *h9g;
struct drm_display_mode h9g_fast_mode;
struct drm_display_mode h9g_modes[H9G_NUM_EXTRA_MODES];
u16 h9g_boot_subframes;

/* clocks */
Expand Down Expand Up @@ -582,6 +584,32 @@ static int simpledrm_device_attach_genpd(struct simpledrm_device *sdev)
#define H9G_SUBFRAME_LINES 0x18708
#define H9G_ACTIVE_SUBFRAMES 0x1870c
#define H9G_EXTRA_SUBFRAMES_WRITE 0x98050
#define H9G_ACTIVE_SUBFRAME_COUNT 2
#define H9G_BOOT_SUBFRAMES 2

struct simpledrm_h9g_panel {
u16 hdisplay;
u16 vdisplay;
u16 htotal;
u16 subframe_lines;
u32 clock;
};

static const struct simpledrm_h9g_panel simpledrm_h9g_panels[] = {
/* 12.9-inch iPad Pro 2 (J120/J121) */
{ 2048, 2732, 2088, 1497, 750001 },
/* 10.5-inch iPad Pro 2 (J207/J208) */
{ 1668, 2224, 1756, 1227, 517107 },
};

/*
* Extra blank subframes inserted after the 2 active scanout subframes on a
* fixed 240 Hz subframe clock: 0 -> 120 Hz, 2 (boot) -> 60 Hz, 3 -> 48 Hz,
* 6 -> 30 Hz, 8 -> 24 Hz.
*/
static const u16 simpledrm_h9g_extra_subframes[H9G_NUM_EXTRA_MODES] = {
0, 3, 6, 8,
};

static bool simpledrm_h9g_write(struct simpledrm_device *sdev, u16 subframes)
{
Expand All @@ -600,18 +628,53 @@ static void simpledrm_h9g_restore(void *data)
drm_err(&sdev->sysfb.dev, "failed to restore H9G boot cadence\n");
}

static const struct simpledrm_h9g_panel *
simpledrm_h9g_find_panel(const struct drm_display_mode *mode)
{
unsigned int i;

for (i = 0; i < ARRAY_SIZE(simpledrm_h9g_panels); i++) {
if (mode->hdisplay == simpledrm_h9g_panels[i].hdisplay &&
mode->vdisplay == simpledrm_h9g_panels[i].vdisplay)
return &simpledrm_h9g_panels[i];
}
return NULL;
}

static bool simpledrm_h9g_mode_subframes(const struct simpledrm_device *sdev,
const struct drm_display_mode *mode,
u16 *subframes)
{
unsigned int i;

if (drm_mode_equal(mode, &sdev->sysfb.fb_mode)) {
*subframes = sdev->h9g_boot_subframes;
return true;
}
for (i = 0; i < ARRAY_SIZE(sdev->h9g_modes); i++) {
if (drm_mode_equal(mode, &sdev->h9g_modes[i])) {
*subframes = simpledrm_h9g_extra_subframes[i];
return true;
}
}
return false;
}

static void simpledrm_h9g_init(struct simpledrm_device *sdev)
{
struct drm_sysfb_device *sysfb = &sdev->sysfb;
struct device *dev = sysfb->dev.dev;
const struct simpledrm_h9g_panel *panel;
struct device_node *display;
struct resource res;
void __iomem *regs;
unsigned int i;
u16 subframes;
int ret = -ENODEV;

/* The 12.9-inch iPad Pro 2 panel behind an A10X H9G display pipe */
if (sysfb->fb_mode.hdisplay != 2048 || sysfb->fb_mode.vdisplay != 2732)
/* iPad Pro 2 (12.9-inch or 10.5-inch) panel behind an A10X H9G pipe */
panel = simpledrm_h9g_find_panel(&sysfb->fb_mode);
if (!panel)
return;
display = of_parse_phandle(dev->of_node, "display", 0);
if (!display)
Expand All @@ -628,9 +691,9 @@ static void simpledrm_h9g_init(struct simpledrm_device *sdev)
/* Adopt only the boot scanout with the firmware processor stopped. */
if (readl(regs + H9G_M3_CONTROL) != 3 || readl(regs + H9G_MODE) != 1 ||
readl(regs + H9G_IRQ_ENABLE) || readl(regs + H9G_OUTPUT_ENABLE) ||
readl(regs + H9G_SUBFRAME_LINES) != 1497 ||
readl(regs + H9G_SUBFRAME_LINES) != panel->subframe_lines ||
readl(regs + H9G_ACTIVE_SUBFRAMES) != 0x200 ||
subframes != 2)
subframes != H9G_BOOT_SUBFRAMES)
return;

sdev->h9g = regs;
Expand All @@ -640,21 +703,27 @@ static void simpledrm_h9g_init(struct simpledrm_device *sdev)
return;
}

/* The boot link runs at the same pixel clock for both cadences. */
sysfb->fb_mode.clock = 750001;
sysfb->fb_mode.htotal = 2088;
sysfb->fb_mode.vtotal = 5988;
sdev->h9g_fast_mode = sysfb->fb_mode;
sdev->h9g_fast_mode.vtotal = 2994;
/* The boot link runs at the same pixel clock for every cadence. */
sysfb->fb_mode.clock = panel->clock;
sysfb->fb_mode.htotal = panel->htotal;
sysfb->fb_mode.vtotal = (H9G_ACTIVE_SUBFRAME_COUNT + subframes) *
panel->subframe_lines;
for (i = 0; i < ARRAY_SIZE(sdev->h9g_modes); i++) {
sdev->h9g_modes[i] = sysfb->fb_mode;
sdev->h9g_modes[i].vtotal = (H9G_ACTIVE_SUBFRAME_COUNT +
simpledrm_h9g_extra_subframes[i]) *
panel->subframe_lines;
}
}

static enum drm_mode_status simpledrm_mode_valid(struct drm_crtc *crtc,
const struct drm_display_mode *mode)
{
struct drm_sysfb_device *sysfb = to_drm_sysfb_device(crtc->dev);
struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb);
u16 subframes;

if (drm_mode_equal(mode, &sysfb->fb_mode) || drm_mode_equal(mode, &sdev->h9g_fast_mode))
if (simpledrm_h9g_mode_subframes(sdev, mode, &subframes))
return MODE_OK;
return MODE_BAD;
}
Expand All @@ -664,28 +733,37 @@ static void simpledrm_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_com
struct drm_sysfb_device *sysfb = to_drm_sysfb_device(crtc->dev);
struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb);
const struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc);
u16 subframes;
u16 subframes = sdev->h9g_boot_subframes;
int idx;

subframes = drm_mode_equal(&new_state->mode, &sdev->h9g_fast_mode) ?
0 : sdev->h9g_boot_subframes;
if (!drm_dev_enter(crtc->dev, &idx))
return;

simpledrm_h9g_mode_subframes(sdev, &new_state->mode, &subframes);
if (!simpledrm_h9g_write(sdev, subframes))
drm_err(crtc->dev, "failed to set H9G extra subframes to %u\n", subframes);

drm_dev_exit(idx);
}

static int simpledrm_get_modes(struct drm_connector *connector)
{
struct drm_sysfb_device *sysfb = to_drm_sysfb_device(connector->dev);
struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb);
struct drm_display_mode *fast;
struct drm_display_mode *mode;
unsigned int i;
int count = drm_sysfb_connector_helper_get_modes(connector);

fast = drm_mode_duplicate(connector->dev, &sdev->h9g_fast_mode);
if (!fast)
return count;
fast->type = DRM_MODE_TYPE_DRIVER;
drm_mode_set_name(fast);
drm_mode_probed_add(connector, fast);
return count + 1;
for (i = 0; i < ARRAY_SIZE(sdev->h9g_modes); i++) {
mode = drm_mode_duplicate(connector->dev, &sdev->h9g_modes[i]);
if (!mode)
continue;
mode->type = DRM_MODE_TYPE_DRIVER;
drm_mode_set_name(mode);
drm_mode_probed_add(connector, mode);
count++;
}
return count;
}

static const u64 simpledrm_primary_plane_format_modifiers[] = {
Expand All @@ -705,7 +783,7 @@ static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = {
DRM_SYSFB_CRTC_HELPER_FUNCS,
};

/* Only a display with an adopted H9G boot scanout offers its 120 Hz mode. */
/* Only a display with an adopted H9G boot scanout offers alternate cadences. */
static const struct drm_crtc_helper_funcs simpledrm_h9g_crtc_helper_funcs = {
.mode_valid = simpledrm_mode_valid,
.atomic_check = drm_sysfb_crtc_helper_atomic_check,
Expand Down Expand Up @@ -1096,6 +1174,18 @@ static void simpledrm_remove(struct platform_device *pdev)
drm_dev_unplug(dev);
}

static void simpledrm_shutdown(struct platform_device *pdev)
{
struct simpledrm_device *sdev = platform_get_drvdata(pdev);
struct drm_device *dev = &sdev->sysfb.dev;

if (!sdev->h9g)
return;

drm_dev_unplug(dev);
simpledrm_h9g_restore(sdev);
}

static const struct of_device_id simpledrm_of_match_table[] = {
{ .compatible = "simple-framebuffer", },
{ },
Expand All @@ -1110,6 +1200,7 @@ static struct platform_driver simpledrm_platform_driver = {
},
.probe = simpledrm_probe,
.remove = simpledrm_remove,
.shutdown = simpledrm_shutdown,
};

module_platform_driver(simpledrm_platform_driver);
Expand Down
Loading