Path: blob/master/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
26494 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2014 Traphandler3* Copyright (C) 2014 Free Electrons4* Copyright (C) 2014 Atmel5*6* Author: Jean-Jacques Hiblot <[email protected]>7* Author: Boris BREZILLON <[email protected]>8*/910#include <linux/clk.h>11#include <linux/irq.h>12#include <linux/irqchip.h>13#include <linux/mfd/atmel-hlcdc.h>14#include <linux/module.h>15#include <linux/pm_runtime.h>16#include <linux/platform_device.h>1718#include <drm/clients/drm_client_setup.h>19#include <drm/drm_atomic.h>20#include <drm/drm_atomic_helper.h>21#include <drm/drm_drv.h>22#include <drm/drm_fbdev_dma.h>23#include <drm/drm_fourcc.h>24#include <drm/drm_gem_dma_helper.h>25#include <drm/drm_gem_framebuffer_helper.h>26#include <drm/drm_module.h>27#include <drm/drm_probe_helper.h>28#include <drm/drm_vblank.h>2930#include "atmel_hlcdc_dc.h"3132#define ATMEL_HLCDC_LAYER_IRQS_OFFSET 83334static const struct atmel_hlcdc_layer_desc atmel_hlcdc_at91sam9n12_layers[] = {35{36.name = "base",37.formats = &atmel_hlcdc_plane_rgb_formats,38.regs_offset = 0x40,39.id = 0,40.type = ATMEL_HLCDC_BASE_LAYER,41.cfgs_offset = 0x2c,42.layout = {43.xstride = { 2 },44.default_color = 3,45.general_config = 4,46},47.clut_offset = 0x400,48},49};5051static const struct atmel_hlcdc_dc_desc atmel_hlcdc_dc_at91sam9n12 = {52.min_width = 0,53.min_height = 0,54.max_width = 1280,55.max_height = 860,56.max_spw = 0x3f,57.max_vpw = 0x3f,58.max_hpw = 0xff,59.conflicting_output_formats = true,60.nlayers = ARRAY_SIZE(atmel_hlcdc_at91sam9n12_layers),61.layers = atmel_hlcdc_at91sam9n12_layers,62.ops = &atmel_hlcdc_ops,63};6465static const struct atmel_hlcdc_layer_desc atmel_hlcdc_at91sam9x5_layers[] = {66{67.name = "base",68.formats = &atmel_hlcdc_plane_rgb_formats,69.regs_offset = 0x40,70.id = 0,71.type = ATMEL_HLCDC_BASE_LAYER,72.cfgs_offset = 0x2c,73.layout = {74.xstride = { 2 },75.default_color = 3,76.general_config = 4,77.disc_pos = 5,78.disc_size = 6,79},80.clut_offset = 0x400,81},82{83.name = "overlay1",84.formats = &atmel_hlcdc_plane_rgb_formats,85.regs_offset = 0x100,86.id = 1,87.type = ATMEL_HLCDC_OVERLAY_LAYER,88.cfgs_offset = 0x2c,89.layout = {90.pos = 2,91.size = 3,92.xstride = { 4 },93.pstride = { 5 },94.default_color = 6,95.chroma_key = 7,96.chroma_key_mask = 8,97.general_config = 9,98},99.clut_offset = 0x800,100},101{102.name = "high-end-overlay",103.formats = &atmel_hlcdc_plane_rgb_and_yuv_formats,104.regs_offset = 0x280,105.id = 2,106.type = ATMEL_HLCDC_OVERLAY_LAYER,107.cfgs_offset = 0x4c,108.layout = {109.pos = 2,110.size = 3,111.memsize = 4,112.xstride = { 5, 7 },113.pstride = { 6, 8 },114.default_color = 9,115.chroma_key = 10,116.chroma_key_mask = 11,117.general_config = 12,118.scaler_config = 13,119.csc = 14,120},121.clut_offset = 0x1000,122},123{124.name = "cursor",125.formats = &atmel_hlcdc_plane_rgb_formats,126.regs_offset = 0x340,127.id = 3,128.type = ATMEL_HLCDC_CURSOR_LAYER,129.max_width = 128,130.max_height = 128,131.cfgs_offset = 0x2c,132.layout = {133.pos = 2,134.size = 3,135.xstride = { 4 },136.default_color = 6,137.chroma_key = 7,138.chroma_key_mask = 8,139.general_config = 9,140},141.clut_offset = 0x1400,142},143};144145static const struct atmel_hlcdc_dc_desc atmel_hlcdc_dc_at91sam9x5 = {146.min_width = 0,147.min_height = 0,148.max_width = 800,149.max_height = 600,150.max_spw = 0x3f,151.max_vpw = 0x3f,152.max_hpw = 0xff,153.conflicting_output_formats = true,154.nlayers = ARRAY_SIZE(atmel_hlcdc_at91sam9x5_layers),155.layers = atmel_hlcdc_at91sam9x5_layers,156.ops = &atmel_hlcdc_ops,157};158159static const struct atmel_hlcdc_layer_desc atmel_hlcdc_sama5d3_layers[] = {160{161.name = "base",162.formats = &atmel_hlcdc_plane_rgb_formats,163.regs_offset = 0x40,164.id = 0,165.type = ATMEL_HLCDC_BASE_LAYER,166.cfgs_offset = 0x2c,167.layout = {168.xstride = { 2 },169.default_color = 3,170.general_config = 4,171.disc_pos = 5,172.disc_size = 6,173},174.clut_offset = 0x600,175},176{177.name = "overlay1",178.formats = &atmel_hlcdc_plane_rgb_formats,179.regs_offset = 0x140,180.id = 1,181.type = ATMEL_HLCDC_OVERLAY_LAYER,182.cfgs_offset = 0x2c,183.layout = {184.pos = 2,185.size = 3,186.xstride = { 4 },187.pstride = { 5 },188.default_color = 6,189.chroma_key = 7,190.chroma_key_mask = 8,191.general_config = 9,192},193.clut_offset = 0xa00,194},195{196.name = "overlay2",197.formats = &atmel_hlcdc_plane_rgb_formats,198.regs_offset = 0x240,199.id = 2,200.type = ATMEL_HLCDC_OVERLAY_LAYER,201.cfgs_offset = 0x2c,202.layout = {203.pos = 2,204.size = 3,205.xstride = { 4 },206.pstride = { 5 },207.default_color = 6,208.chroma_key = 7,209.chroma_key_mask = 8,210.general_config = 9,211},212.clut_offset = 0xe00,213},214{215.name = "high-end-overlay",216.formats = &atmel_hlcdc_plane_rgb_and_yuv_formats,217.regs_offset = 0x340,218.id = 3,219.type = ATMEL_HLCDC_OVERLAY_LAYER,220.cfgs_offset = 0x4c,221.layout = {222.pos = 2,223.size = 3,224.memsize = 4,225.xstride = { 5, 7 },226.pstride = { 6, 8 },227.default_color = 9,228.chroma_key = 10,229.chroma_key_mask = 11,230.general_config = 12,231.scaler_config = 13,232.phicoeffs = {233.x = 17,234.y = 33,235},236.csc = 14,237},238.clut_offset = 0x1200,239},240{241.name = "cursor",242.formats = &atmel_hlcdc_plane_rgb_formats,243.regs_offset = 0x440,244.id = 4,245.type = ATMEL_HLCDC_CURSOR_LAYER,246.max_width = 128,247.max_height = 128,248.cfgs_offset = 0x2c,249.layout = {250.pos = 2,251.size = 3,252.xstride = { 4 },253.pstride = { 5 },254.default_color = 6,255.chroma_key = 7,256.chroma_key_mask = 8,257.general_config = 9,258.scaler_config = 13,259},260.clut_offset = 0x1600,261},262};263264static const struct atmel_hlcdc_dc_desc atmel_hlcdc_dc_sama5d3 = {265.min_width = 0,266.min_height = 0,267.max_width = 2048,268.max_height = 2048,269.max_spw = 0x3f,270.max_vpw = 0x3f,271.max_hpw = 0x1ff,272.conflicting_output_formats = true,273.nlayers = ARRAY_SIZE(atmel_hlcdc_sama5d3_layers),274.layers = atmel_hlcdc_sama5d3_layers,275.ops = &atmel_hlcdc_ops,276};277278static const struct atmel_hlcdc_layer_desc atmel_hlcdc_sama5d4_layers[] = {279{280.name = "base",281.formats = &atmel_hlcdc_plane_rgb_formats,282.regs_offset = 0x40,283.id = 0,284.type = ATMEL_HLCDC_BASE_LAYER,285.cfgs_offset = 0x2c,286.layout = {287.xstride = { 2 },288.default_color = 3,289.general_config = 4,290.disc_pos = 5,291.disc_size = 6,292},293.clut_offset = 0x600,294},295{296.name = "overlay1",297.formats = &atmel_hlcdc_plane_rgb_formats,298.regs_offset = 0x140,299.id = 1,300.type = ATMEL_HLCDC_OVERLAY_LAYER,301.cfgs_offset = 0x2c,302.layout = {303.pos = 2,304.size = 3,305.xstride = { 4 },306.pstride = { 5 },307.default_color = 6,308.chroma_key = 7,309.chroma_key_mask = 8,310.general_config = 9,311},312.clut_offset = 0xa00,313},314{315.name = "overlay2",316.formats = &atmel_hlcdc_plane_rgb_formats,317.regs_offset = 0x240,318.id = 2,319.type = ATMEL_HLCDC_OVERLAY_LAYER,320.cfgs_offset = 0x2c,321.layout = {322.pos = 2,323.size = 3,324.xstride = { 4 },325.pstride = { 5 },326.default_color = 6,327.chroma_key = 7,328.chroma_key_mask = 8,329.general_config = 9,330},331.clut_offset = 0xe00,332},333{334.name = "high-end-overlay",335.formats = &atmel_hlcdc_plane_rgb_and_yuv_formats,336.regs_offset = 0x340,337.id = 3,338.type = ATMEL_HLCDC_OVERLAY_LAYER,339.cfgs_offset = 0x4c,340.layout = {341.pos = 2,342.size = 3,343.memsize = 4,344.xstride = { 5, 7 },345.pstride = { 6, 8 },346.default_color = 9,347.chroma_key = 10,348.chroma_key_mask = 11,349.general_config = 12,350.scaler_config = 13,351.phicoeffs = {352.x = 17,353.y = 33,354},355.csc = 14,356},357.clut_offset = 0x1200,358},359};360361static const struct atmel_hlcdc_dc_desc atmel_hlcdc_dc_sama5d4 = {362.min_width = 0,363.min_height = 0,364.max_width = 2048,365.max_height = 2048,366.max_spw = 0xff,367.max_vpw = 0xff,368.max_hpw = 0x3ff,369.nlayers = ARRAY_SIZE(atmel_hlcdc_sama5d4_layers),370.layers = atmel_hlcdc_sama5d4_layers,371.ops = &atmel_hlcdc_ops,372};373374static const struct atmel_hlcdc_layer_desc atmel_hlcdc_sam9x60_layers[] = {375{376.name = "base",377.formats = &atmel_hlcdc_plane_rgb_formats,378.regs_offset = 0x60,379.id = 0,380.type = ATMEL_HLCDC_BASE_LAYER,381.cfgs_offset = 0x2c,382.layout = {383.xstride = { 2 },384.default_color = 3,385.general_config = 4,386.disc_pos = 5,387.disc_size = 6,388},389.clut_offset = 0x600,390},391{392.name = "overlay1",393.formats = &atmel_hlcdc_plane_rgb_formats,394.regs_offset = 0x160,395.id = 1,396.type = ATMEL_HLCDC_OVERLAY_LAYER,397.cfgs_offset = 0x2c,398.layout = {399.pos = 2,400.size = 3,401.xstride = { 4 },402.pstride = { 5 },403.default_color = 6,404.chroma_key = 7,405.chroma_key_mask = 8,406.general_config = 9,407},408.clut_offset = 0xa00,409},410{411.name = "overlay2",412.formats = &atmel_hlcdc_plane_rgb_formats,413.regs_offset = 0x260,414.id = 2,415.type = ATMEL_HLCDC_OVERLAY_LAYER,416.cfgs_offset = 0x2c,417.layout = {418.pos = 2,419.size = 3,420.xstride = { 4 },421.pstride = { 5 },422.default_color = 6,423.chroma_key = 7,424.chroma_key_mask = 8,425.general_config = 9,426},427.clut_offset = 0xe00,428},429{430.name = "high-end-overlay",431.formats = &atmel_hlcdc_plane_rgb_and_yuv_formats,432.regs_offset = 0x360,433.id = 3,434.type = ATMEL_HLCDC_OVERLAY_LAYER,435.cfgs_offset = 0x4c,436.layout = {437.pos = 2,438.size = 3,439.memsize = 4,440.xstride = { 5, 7 },441.pstride = { 6, 8 },442.default_color = 9,443.chroma_key = 10,444.chroma_key_mask = 11,445.general_config = 12,446.scaler_config = 13,447.phicoeffs = {448.x = 17,449.y = 33,450},451.csc = 14,452},453.clut_offset = 0x1200,454},455};456457static const struct atmel_hlcdc_dc_desc atmel_hlcdc_dc_sam9x60 = {458.min_width = 0,459.min_height = 0,460.max_width = 2048,461.max_height = 2048,462.max_spw = 0xff,463.max_vpw = 0xff,464.max_hpw = 0x3ff,465.fixed_clksrc = true,466.nlayers = ARRAY_SIZE(atmel_hlcdc_sam9x60_layers),467.layers = atmel_hlcdc_sam9x60_layers,468.ops = &atmel_hlcdc_ops,469};470471static const struct atmel_hlcdc_layer_desc atmel_xlcdc_sam9x75_layers[] = {472{473.name = "base",474.formats = &atmel_hlcdc_plane_rgb_formats,475.regs_offset = 0x60,476.id = 0,477.type = ATMEL_HLCDC_BASE_LAYER,478.cfgs_offset = 0x1c,479.layout = {480.xstride = { 2 },481.default_color = 3,482.general_config = 4,483.disc_pos = 5,484.disc_size = 6,485},486.clut_offset = 0x700,487},488{489.name = "overlay1",490.formats = &atmel_hlcdc_plane_rgb_formats,491.regs_offset = 0x160,492.id = 1,493.type = ATMEL_HLCDC_OVERLAY_LAYER,494.cfgs_offset = 0x1c,495.layout = {496.pos = 2,497.size = 3,498.xstride = { 4 },499.pstride = { 5 },500.default_color = 6,501.chroma_key = 7,502.chroma_key_mask = 8,503.general_config = 9,504},505.clut_offset = 0xb00,506},507{508.name = "overlay2",509.formats = &atmel_hlcdc_plane_rgb_formats,510.regs_offset = 0x260,511.id = 2,512.type = ATMEL_HLCDC_OVERLAY_LAYER,513.cfgs_offset = 0x1c,514.layout = {515.pos = 2,516.size = 3,517.xstride = { 4 },518.pstride = { 5 },519.default_color = 6,520.chroma_key = 7,521.chroma_key_mask = 8,522.general_config = 9,523},524.clut_offset = 0xf00,525},526{527.name = "high-end-overlay",528.formats = &atmel_hlcdc_plane_rgb_and_yuv_formats,529.regs_offset = 0x360,530.id = 3,531.type = ATMEL_HLCDC_OVERLAY_LAYER,532.cfgs_offset = 0x30,533.layout = {534.pos = 2,535.size = 3,536.memsize = 4,537.xstride = { 5, 7 },538.pstride = { 6, 8 },539.default_color = 9,540.chroma_key = 10,541.chroma_key_mask = 11,542.general_config = 12,543.csc = 16,544.scaler_config = 23,545.vxs_config = 30,546.hxs_config = 31,547},548.clut_offset = 0x1300,549},550};551552static const struct atmel_hlcdc_dc_desc atmel_xlcdc_dc_sam9x75 = {553.min_width = 0,554.min_height = 0,555.max_width = 2048,556.max_height = 2048,557.max_spw = 0x3ff,558.max_vpw = 0x3ff,559.max_hpw = 0x3ff,560.fixed_clksrc = true,561.is_xlcdc = true,562.nlayers = ARRAY_SIZE(atmel_xlcdc_sam9x75_layers),563.layers = atmel_xlcdc_sam9x75_layers,564.ops = &atmel_xlcdc_ops,565};566567static const struct of_device_id atmel_hlcdc_of_match[] = {568{569.compatible = "atmel,at91sam9n12-hlcdc",570.data = &atmel_hlcdc_dc_at91sam9n12,571},572{573.compatible = "atmel,at91sam9x5-hlcdc",574.data = &atmel_hlcdc_dc_at91sam9x5,575},576{577.compatible = "atmel,sama5d2-hlcdc",578.data = &atmel_hlcdc_dc_sama5d4,579},580{581.compatible = "atmel,sama5d3-hlcdc",582.data = &atmel_hlcdc_dc_sama5d3,583},584{585.compatible = "atmel,sama5d4-hlcdc",586.data = &atmel_hlcdc_dc_sama5d4,587},588{589.compatible = "microchip,sam9x60-hlcdc",590.data = &atmel_hlcdc_dc_sam9x60,591},592{593.compatible = "microchip,sam9x75-xlcdc",594.data = &atmel_xlcdc_dc_sam9x75,595},596{ /* sentinel */ },597};598MODULE_DEVICE_TABLE(of, atmel_hlcdc_of_match);599600enum drm_mode_status601atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc,602const struct drm_display_mode *mode)603{604int vfront_porch = mode->vsync_start - mode->vdisplay;605int vback_porch = mode->vtotal - mode->vsync_end;606int vsync_len = mode->vsync_end - mode->vsync_start;607int hfront_porch = mode->hsync_start - mode->hdisplay;608int hback_porch = mode->htotal - mode->hsync_end;609int hsync_len = mode->hsync_end - mode->hsync_start;610611if (hsync_len > dc->desc->max_spw + 1 || hsync_len < 1)612return MODE_HSYNC;613614if (vsync_len > dc->desc->max_spw + 1 || vsync_len < 1)615return MODE_VSYNC;616617if (hfront_porch > dc->desc->max_hpw + 1 || hfront_porch < 1 ||618hback_porch > dc->desc->max_hpw + 1 || hback_porch < 1 ||619mode->hdisplay < 1)620return MODE_H_ILLEGAL;621622if (vfront_porch > dc->desc->max_vpw + 1 || vfront_porch < 1 ||623vback_porch > dc->desc->max_vpw || vback_porch < 0 ||624mode->vdisplay < 1)625return MODE_V_ILLEGAL;626627return MODE_OK;628}629630static void atmel_hlcdc_layer_irq(struct atmel_hlcdc_layer *layer)631{632if (!layer)633return;634635if (layer->desc->type == ATMEL_HLCDC_BASE_LAYER ||636layer->desc->type == ATMEL_HLCDC_OVERLAY_LAYER ||637layer->desc->type == ATMEL_HLCDC_CURSOR_LAYER)638atmel_hlcdc_plane_irq(atmel_hlcdc_layer_to_plane(layer));639}640641static irqreturn_t atmel_hlcdc_dc_irq_handler(int irq, void *data)642{643struct drm_device *dev = data;644struct atmel_hlcdc_dc *dc = dev->dev_private;645unsigned long status;646unsigned int imr, isr;647int i;648649regmap_read(dc->hlcdc->regmap, ATMEL_HLCDC_IMR, &imr);650regmap_read(dc->hlcdc->regmap, ATMEL_HLCDC_ISR, &isr);651status = imr & isr;652if (!status)653return IRQ_NONE;654655if (status & ATMEL_HLCDC_SOF)656atmel_hlcdc_crtc_irq(dc->crtc);657658for (i = 0; i < ATMEL_HLCDC_MAX_LAYERS; i++) {659if (ATMEL_HLCDC_LAYER_STATUS(i) & status)660atmel_hlcdc_layer_irq(dc->layers[i]);661}662663return IRQ_HANDLED;664}665666static void atmel_hlcdc_dc_irq_postinstall(struct drm_device *dev)667{668struct atmel_hlcdc_dc *dc = dev->dev_private;669unsigned int cfg = 0;670int i;671672/* Enable interrupts on activated layers */673for (i = 0; i < ATMEL_HLCDC_MAX_LAYERS; i++) {674if (dc->layers[i])675cfg |= ATMEL_HLCDC_LAYER_STATUS(i);676}677678regmap_write(dc->hlcdc->regmap, ATMEL_HLCDC_IER, cfg);679}680681static void atmel_hlcdc_dc_irq_disable(struct drm_device *dev)682{683struct atmel_hlcdc_dc *dc = dev->dev_private;684unsigned int isr;685686regmap_write(dc->hlcdc->regmap, ATMEL_HLCDC_IDR, 0xffffffff);687regmap_read(dc->hlcdc->regmap, ATMEL_HLCDC_ISR, &isr);688}689690static int atmel_hlcdc_dc_irq_install(struct drm_device *dev, unsigned int irq)691{692int ret;693694atmel_hlcdc_dc_irq_disable(dev);695696ret = devm_request_irq(dev->dev, irq, atmel_hlcdc_dc_irq_handler, 0,697dev->driver->name, dev);698if (ret)699return ret;700701atmel_hlcdc_dc_irq_postinstall(dev);702703return 0;704}705706static void atmel_hlcdc_dc_irq_uninstall(struct drm_device *dev)707{708atmel_hlcdc_dc_irq_disable(dev);709}710711static const struct drm_mode_config_funcs mode_config_funcs = {712.fb_create = drm_gem_fb_create,713.atomic_check = drm_atomic_helper_check,714.atomic_commit = drm_atomic_helper_commit,715};716717static int atmel_hlcdc_dc_modeset_init(struct drm_device *dev)718{719struct atmel_hlcdc_dc *dc = dev->dev_private;720int ret;721722drm_mode_config_init(dev);723724ret = atmel_hlcdc_create_outputs(dev);725if (ret) {726dev_err(dev->dev, "failed to create HLCDC outputs: %d\n", ret);727return ret;728}729730ret = atmel_hlcdc_create_planes(dev);731if (ret) {732dev_err(dev->dev, "failed to create planes: %d\n", ret);733return ret;734}735736ret = atmel_hlcdc_crtc_create(dev);737if (ret) {738dev_err(dev->dev, "failed to create crtc\n");739return ret;740}741742dev->mode_config.min_width = dc->desc->min_width;743dev->mode_config.min_height = dc->desc->min_height;744dev->mode_config.max_width = dc->desc->max_width;745dev->mode_config.max_height = dc->desc->max_height;746dev->mode_config.funcs = &mode_config_funcs;747dev->mode_config.async_page_flip = true;748749return 0;750}751752static int atmel_hlcdc_dc_load(struct drm_device *dev)753{754struct platform_device *pdev = to_platform_device(dev->dev);755const struct of_device_id *match;756struct atmel_hlcdc_dc *dc;757int ret;758759match = of_match_node(atmel_hlcdc_of_match, dev->dev->parent->of_node);760if (!match) {761dev_err(&pdev->dev, "invalid compatible string\n");762return -ENODEV;763}764765if (!match->data) {766dev_err(&pdev->dev, "invalid hlcdc description\n");767return -EINVAL;768}769770dc = devm_kzalloc(dev->dev, sizeof(*dc), GFP_KERNEL);771if (!dc)772return -ENOMEM;773774dc->desc = match->data;775dc->hlcdc = dev_get_drvdata(dev->dev->parent);776dev->dev_private = dc;777778ret = clk_prepare_enable(dc->hlcdc->periph_clk);779if (ret) {780dev_err(dev->dev, "failed to enable periph_clk\n");781return ret;782}783784pm_runtime_enable(dev->dev);785786ret = drm_vblank_init(dev, 1);787if (ret < 0) {788dev_err(dev->dev, "failed to initialize vblank\n");789goto err_periph_clk_disable;790}791792ret = atmel_hlcdc_dc_modeset_init(dev);793if (ret < 0) {794dev_err(dev->dev, "failed to initialize mode setting\n");795goto err_periph_clk_disable;796}797798drm_mode_config_reset(dev);799800pm_runtime_get_sync(dev->dev);801ret = atmel_hlcdc_dc_irq_install(dev, dc->hlcdc->irq);802pm_runtime_put_sync(dev->dev);803if (ret < 0) {804dev_err(dev->dev, "failed to install IRQ handler\n");805goto err_periph_clk_disable;806}807808platform_set_drvdata(pdev, dev);809810drm_kms_helper_poll_init(dev);811812return 0;813814err_periph_clk_disable:815pm_runtime_disable(dev->dev);816clk_disable_unprepare(dc->hlcdc->periph_clk);817818return ret;819}820821static void atmel_hlcdc_dc_unload(struct drm_device *dev)822{823struct atmel_hlcdc_dc *dc = dev->dev_private;824825drm_kms_helper_poll_fini(dev);826drm_atomic_helper_shutdown(dev);827drm_mode_config_cleanup(dev);828829pm_runtime_get_sync(dev->dev);830atmel_hlcdc_dc_irq_uninstall(dev);831pm_runtime_put_sync(dev->dev);832833dev->dev_private = NULL;834835pm_runtime_disable(dev->dev);836clk_disable_unprepare(dc->hlcdc->periph_clk);837}838839DEFINE_DRM_GEM_DMA_FOPS(fops);840841static const struct drm_driver atmel_hlcdc_dc_driver = {842.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,843DRM_GEM_DMA_DRIVER_OPS,844DRM_FBDEV_DMA_DRIVER_OPS,845.fops = &fops,846.name = "atmel-hlcdc",847.desc = "Atmel HLCD Controller DRM",848.major = 1,849.minor = 0,850};851852static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev)853{854struct drm_device *ddev;855int ret;856857ddev = drm_dev_alloc(&atmel_hlcdc_dc_driver, &pdev->dev);858if (IS_ERR(ddev))859return PTR_ERR(ddev);860861ret = atmel_hlcdc_dc_load(ddev);862if (ret)863goto err_put;864865ret = drm_dev_register(ddev, 0);866if (ret)867goto err_unload;868869drm_client_setup_with_fourcc(ddev, DRM_FORMAT_RGB888);870871return 0;872873err_unload:874atmel_hlcdc_dc_unload(ddev);875876err_put:877drm_dev_put(ddev);878879return ret;880}881882static void atmel_hlcdc_dc_drm_remove(struct platform_device *pdev)883{884struct drm_device *ddev = platform_get_drvdata(pdev);885886drm_dev_unregister(ddev);887atmel_hlcdc_dc_unload(ddev);888drm_dev_put(ddev);889}890891static void atmel_hlcdc_dc_drm_shutdown(struct platform_device *pdev)892{893drm_atomic_helper_shutdown(platform_get_drvdata(pdev));894}895896static int atmel_hlcdc_dc_drm_suspend(struct device *dev)897{898struct drm_device *drm_dev = dev_get_drvdata(dev);899struct atmel_hlcdc_dc *dc = drm_dev->dev_private;900struct regmap *regmap = dc->hlcdc->regmap;901struct drm_atomic_state *state;902903state = drm_atomic_helper_suspend(drm_dev);904if (IS_ERR(state))905return PTR_ERR(state);906907dc->suspend.state = state;908909regmap_read(regmap, ATMEL_HLCDC_IMR, &dc->suspend.imr);910regmap_write(regmap, ATMEL_HLCDC_IDR, dc->suspend.imr);911clk_disable_unprepare(dc->hlcdc->periph_clk);912913return 0;914}915916static int atmel_hlcdc_dc_drm_resume(struct device *dev)917{918struct drm_device *drm_dev = dev_get_drvdata(dev);919struct atmel_hlcdc_dc *dc = drm_dev->dev_private;920921clk_prepare_enable(dc->hlcdc->periph_clk);922regmap_write(dc->hlcdc->regmap, ATMEL_HLCDC_IER, dc->suspend.imr);923924return drm_atomic_helper_resume(drm_dev, dc->suspend.state);925}926927static DEFINE_SIMPLE_DEV_PM_OPS(atmel_hlcdc_dc_drm_pm_ops,928atmel_hlcdc_dc_drm_suspend,929atmel_hlcdc_dc_drm_resume);930931static const struct of_device_id atmel_hlcdc_dc_of_match[] = {932{ .compatible = "atmel,hlcdc-display-controller" },933{ },934};935936static struct platform_driver atmel_hlcdc_dc_platform_driver = {937.probe = atmel_hlcdc_dc_drm_probe,938.remove = atmel_hlcdc_dc_drm_remove,939.shutdown = atmel_hlcdc_dc_drm_shutdown,940.driver = {941.name = "atmel-hlcdc-display-controller",942.pm = pm_sleep_ptr(&atmel_hlcdc_dc_drm_pm_ops),943.of_match_table = atmel_hlcdc_dc_of_match,944},945};946drm_module_platform_driver(atmel_hlcdc_dc_platform_driver);947948MODULE_AUTHOR("Jean-Jacques Hiblot <[email protected]>");949MODULE_AUTHOR("Boris Brezillon <[email protected]>");950MODULE_DESCRIPTION("Atmel HLCDC Display Controller DRM Driver");951MODULE_LICENSE("GPL");952MODULE_ALIAS("platform:atmel-hlcdc-dc");953954955