drm: add kms driver for loongson display controller
Subsystems (2)
PATCH 1/1 drm: add kms driver for loongson display controller
From: suijingfeng <[email protected]>
The display controller is a PCI device and It has two display pipe. Loongson display controllers are simple which require scanout buffers to be physically contiguous.
For LS7A1000 bridge chip, each way has a DVO interface which provide RGB888 signals, vertical & horizontal synchronisations, and the pixel clock. Each CRTC is able to support 1920x1080 resolution at 60Hz, the maximum resolution is 2048x2048 according to the hardware spec.
For the DC in LS7A2000 bridge chip, each way is connected with a built-in HDMI encoder which support 3840x2160@30.
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/lsdc/Kconfig | 18 + drivers/gpu/drm/lsdc/Makefile | 14 + drivers/gpu/drm/lsdc/lsdc_crtc.c | 437 +++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_debugfs.c | 243 ++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.c | 535 ++++++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.h | 274 +++++++++++++ drivers/gpu/drm/lsdc/lsdc_i2c.c | 187 +++++++++ drivers/gpu/drm/lsdc/lsdc_irq.c | 81 ++++ drivers/gpu/drm/lsdc/lsdc_output.c | 366 ++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_plane.c | 447 ++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.c | 571 ++++++++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.h | 78 ++++ drivers/gpu/drm/lsdc/lsdc_regs.c | 29 ++ drivers/gpu/drm/lsdc/lsdc_regs.h | 294 ++++++++++++++ 16 files changed, 3577 insertions(+) create mode 100644 drivers/gpu/drm/lsdc/Kconfig create mode 100644 drivers/gpu/drm/lsdc/Makefile create mode 100644 drivers/gpu/drm/lsdc/lsdc_crtc.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_debugfs.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_drv.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_drv.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_i2c.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_irq.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_output.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_plane.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_pll.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_pll.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_regs.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_regs.h
drivers/gpu/drm/Kconfig +2 -0
@@ -368,6 +368,8 @@ source "drivers/gpu/drm/solomon/Kconfig" source "drivers/gpu/drm/sprd/Kconfig" +source "drivers/gpu/drm/lsdc/Kconfig" + config DRM_HYPERV tristate "DRM Support for Hyper-V synthetic video device" depends on DRM && PCI && MMU && HYPERV
drivers/gpu/drm/Makefile +1 -0
@@ -197,3 +197,4 @@ obj-y += gud/ obj-$(CONFIG_DRM_HYPERV) += hyperv/ obj-y += solomon/ obj-$(CONFIG_DRM_SPRD) += sprd/ +obj-$(CONFIG_DRM_LSDC) += lsdc/
drivers/gpu/drm/lsdc/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 + +config DRM_LSDC + tristate "DRM support for loongson display controller" + depends on DRM && PCI && (MACH_LOONGSON64 || LOONGARCH || MIPS) + select OF + select DRM_KMS_HELPER + select DRM_TTM + select DRM_TTM_HELPER + select DRM_VRAM_HELPER + select VIDEOMODE_HELPERS + default m + help + This is a KMS driver for loongson display controller in the + LS7A1000/LS7A2000 bridge chip and LS2K1000/LS2K0500 SoC. + If "M" is selected, the module will be called lsdc. + + If in doubt, say "Y".
drivers/gpu/drm/lsdc/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0 + +lsdc-y := \ + lsdc_drv.o \ + lsdc_crtc.o \ + lsdc_irq.o \ + lsdc_plane.o \ + lsdc_pll.o \ + lsdc_i2c.o \ + lsdc_output.o \ + lsdc_regs.o \ + lsdc_debugfs.o + +obj-$(CONFIG_DRM_LSDC) += lsdc.o
drivers/gpu/drm/lsdc/lsdc_crtc.c new file +437 -0
437 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_debugfs.c new file +243 -0
243 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_drv.c new file +535 -0
535 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_drv.h new file +274 -0
274 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_i2c.c new file +187 -0
187 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_irq.c new file +81 -0
81 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_output.c new file +366 -0
366 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_plane.c new file +447 -0
447 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_pll.c new file +571 -0
386 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_pll.h new file +78 -0
78 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_regs.c new file +29 -0
Lines of this file are not shown. View the raw message.
drivers/gpu/drm/lsdc/lsdc_regs.h new file +294 -0
294 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.1
Part of the diff is not shown here. View the raw message.
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi suijingfeng,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v6.2-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/suijingfeng/drm-add-kms-driver-for-loongson-display-controller/20230202-011138 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230201170403.167665-1-15330273260%40189.cn patch subject: [PATCH] drm: add kms driver for loongson display controller config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20230203/[email protected]/config) compiler: mips-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/ff8d5959f6dcf4abbbdbf2951345f552dc3bea46
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review suijingfeng/drm-add-kms-driver-for-loongson-display-controller/20230202-011138 git checkout ff8d5959f6dcf4abbbdbf2951345f552dc3bea46
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=mips olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash drivers/gpu/drm/lsdc/
If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/lsdc/lsdc_drv.c:227:1: warning: no previous prototype for 'lsdc_detect_chip' [-Wmissing-prototypes]
227 | lsdc_detect_chip(struct pci_dev *pdev, const struct pci_device_id * const ent)
| ^~~~~~~~~~~~~~~~
>> drivers/gpu/drm/lsdc/lsdc_drv.c:295:21: warning: no previous prototype for 'lsdc_create_device' [-Wmissing-prototypes]
295 | struct lsdc_device *lsdc_create_device(struct pci_dev *pdev,
| ^~~~~~~~~~~~~~~~~~
In file included from include/linux/device.h:15,
from include/linux/pci.h:37,
from drivers/gpu/drm/lsdc/lsdc_drv.c:11:
drivers/gpu/drm/lsdc/lsdc_drv.c: In function 'lsdc_create_device':
>> drivers/gpu/drm/lsdc/lsdc_drv.c:325:46: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
325 | drm_info(ddev, "reg base: 0x%llx\n", (u64)ldev->reg_base);
| ^
include/linux/dev_printk.h:110:37: note: in definition of macro 'dev_printk_index_wrap'
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/drm/drm_print.h:456:9: note: in expansion of macro 'dev_info'
456 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~
include/drm/drm_print.h:460:9: note: in expansion of macro '__drm_printk'
460 | __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/gpu/drm/lsdc/lsdc_drv.c:325:9: note: in expansion of macro 'drm_info'
325 | drm_info(ddev, "reg base: 0x%llx\n", (u64)ldev->reg_base);
| ^~~~~~~~
drivers/gpu/drm/lsdc/lsdc_drv.c: At top level:
drivers/gpu/drm/lsdc/lsdc_drv.c:52:31: warning: 'dc_in_ls2k1000' defined but not used [-Wunused-const-variable=]
52 | static const struct lsdc_desc dc_in_ls2k1000 = {
| ^~~~~~~~~~~~~~
drivers/gpu/drm/lsdc/lsdc_drv.c:34:31: warning: 'dc_in_ls2k0500' defined but not used [-Wunused-const-variable=]
34 | static const struct lsdc_desc dc_in_ls2k0500 = {
| ^~~~~~~~~~~~~~vim +/lsdc_detect_chip +227 drivers/gpu/drm/lsdc/lsdc_drv.c
222
223 /*
224 * lsdc_detect_chip - a function to tell different chips apart.
225 */
226 const struct lsdc_desc *
> 227 lsdc_detect_chip(struct pci_dev *pdev, const struct pci_device_id * const ent)
228 {
229 if (ent) {
230 struct lsdc_desc *dc_descp;
231
232 dc_descp = (struct lsdc_desc *)ent->driver_data;
233 if (dc_descp->chip == CHIP_LS7A1000)
234 dev_info(&pdev->dev, "LS7A1000 Found, revision: %u\n", pdev->revision);
235 else if (dc_descp->chip == CHIP_LS7A2000)
236 dev_info(&pdev->dev, "LS7A2000 Found, revison: %u\n", pdev->revision);
237
238 return dc_descp;
239 }
240
241 dev_err(&pdev->dev, "No Known Device Found\n");
242
243 return NULL;
244 }
245
246 static int lsdc_vram_init(struct lsdc_device *ldev,
247 const struct lsdc_desc *descp)
248 {
249 struct drm_device *ddev = &ldev->base;
250 struct pci_dev *gpu;
251 resource_size_t base, size;
252
253 /* The GPU and display controller in LS7A1000/LS7A2000 are separated
254 * PCIE devices, they are two devices not one. The DC is a pci device,
255 * but it don't have a dedicate VRAM bar, the BIOS engineer choose to
256 * assign the VRAM to the gpu device. Sadly, after years application,
257 * this decision form as a convention for loongson integrate graphics.
258 * For LS7A1000 and LS7A2000, bar 2 of GPU device contain the VRAM,
259 * both the GPU and the DC can make use of the VRAM depend on how DRM
260 * device driver is written. Therefore, we have to do some tricks here.
261 */
262 if (descp->chip == CHIP_LS7A1000)
263 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A15, NULL);
264 else if (descp->chip == CHIP_LS7A2000)
265 gpu = pci_get_device(PCI_VENDOR_ID_LOONGSON, 0x7A25, NULL);
266
267 if (!gpu) {
268 drm_warn(ddev, "No GPU device found\n");
269 return -ENODEV;
270 }
271
272 base = pci_resource_start(gpu, 2);
273 size = pci_resource_len(gpu, 2);
274
275 ldev->vram_base = base;
276 ldev->vram_size = size;
277
278 drm_info(ddev, "vram start: 0x%llx, size: %uMB\n",
279 (u64)base, (u32)(size >> 20));
280
281 return 0;
282 }
283
284 static int
285 lsdc_remove_conflicting_framebuffers(const struct drm_driver *pdriver,
286 resource_size_t base,
287 resource_size_t size)
288 {
289 return drm_aperture_remove_conflicting_framebuffers(base,
290 size,
291 false,
292 pdriver);
293 }
294
> 295 struct lsdc_device *lsdc_create_device(struct pci_dev *pdev,
296 const struct pci_device_id *ent,
297 const struct drm_driver *drv)
298 {
299 struct lsdc_device *ldev;
300 struct drm_device *ddev;
301 const struct lsdc_desc *descp;
302 int ret;
303
304 ldev = devm_drm_dev_alloc(&pdev->dev, drv, struct lsdc_device, base);
305 if (IS_ERR(ldev))
306 return ldev;
307
308 ddev = &ldev->base;
309
310 pci_set_drvdata(pdev, ddev);
311
312 descp = lsdc_detect_chip(pdev, ent);
313 if (!descp)
314 return NULL;
315
316 ldev->descp = descp;
317
318 spin_lock_init(&ldev->reglock);
319
320 /* BAR 0 the DC device contains registers */
321 ldev->reg_base = pcim_iomap(pdev, 0, 0);
322 if (!ldev->reg_base)
323 return ERR_PTR(-EIO);
324
> 325 drm_info(ddev, "reg base: 0x%llx\n", (u64)ldev->reg_base);
326
327 ret = lsdc_vram_init(ldev, descp);
328 if (ret)
329 return ERR_PTR(ret);
330
331 ret = lsdc_remove_conflicting_framebuffers(drv,
332 ldev->vram_base,
333 ldev->vram_size);
334 if (ret) {
335 drm_err(ddev, "remove firmware framebuffers failed: %d\n", ret);
336 return ERR_PTR(ret);
337 }
338
339 ret = drmm_vram_helper_init(ddev, ldev->vram_base, ldev->vram_size);
340 if (ret) {
341 drm_err(ddev, "vram helper init failed: %d\n", ret);
342 goto err;
343 }
344
345 ret = lsdc_mode_config_init(ddev, descp);
346 if (ret) {
347 drm_dbg(ddev, "%s: %d\n", __func__, ret);
348 goto err;
349 }
350
351 ret = lsdc_modeset_init(ldev, descp);
352 if (ret)
353 goto err;
354
355 ret = drm_vblank_init(ddev, descp->num_of_crtc);
356 if (ret)
357 goto err;
358
359 ret = request_threaded_irq(pdev->irq,
360 lsdc_get_irq_handler(ldev),
361 lsdc_irq_thread_handler,
362 IRQF_ONESHOT,
363 dev_name(ddev->dev),
364 ddev); 365 if (ret) {
366 drm_err(ddev, "Failed to register lsdc interrupt\n");
367 goto err;
368 }
369
370 drm_kms_helper_poll_init(ddev);
371
372 return ldev;
373
374 err:
375 return ERR_PTR(ret);
376 }
377
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests