drm/lsdc: add drm driver support for loongson display controller
Subsystems (2)
PATCH 1/1 drm/lsdc: add drm driver support for loongson display controller
There is a display controller in loongson's LS2K1000 SoC and LS7A1000 bridge, and the DC in those chip is a PCI device. This display controller have two display pipes but with only one hardware cursor.
This display controller is uncommon outside of china, it don't have rich document either. This patch try to provide a minimal support for it, which is mainly for graphic environment bring up. Hope the code can speak for itself.
For LS7A1000, there are 4 gpios whoes register is located at dc register space which is used to emulation i2c. LS2K1000 and LS2K0500 SoC don't have those hardware, they use general purpose gpio or hardware i2c to serve this purpose.
LS2K1000 is a double core 1.0Ghz mips64r2 compatible SoC[3]. LS7A1000 is a bridge chip made by Loongson corporation which act as north and/or south bridge of loongson's desktop and server level processor. It is equivalent to RS780E or something like that. More details can be read from its user manual[1].
This bridge chip is typically use with LS3A3000, LS3A4000 and LS3A5000 cpu. LS3A3000 is 4 core 1.45gHz mips64r2 compatible cpu.
LS3A4000 is 4 core 1.8gHz mips64r5 compatible cpu.
LS3A5000 is 4 core 2.5gHz loongarch cpu[2].
[1] https://loongson.github.io/LoongArch-Documentation/Loongson-7A1000-usermanual-EN.html
[2] https://loongson.github.io/LoongArch-Documentation/Loongson-3A5000-usermanual-EN.html
[3] https://wiki.debian.org/InstallingDebianOn/Lemote/Loongson2K1000
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/lsdc/Kconfig | 32 + drivers/gpu/drm/lsdc/Makefile | 15 + drivers/gpu/drm/lsdc/lsdc_connector.c | 441 ++++++++++++++ drivers/gpu/drm/lsdc/lsdc_connector.h | 60 ++ drivers/gpu/drm/lsdc/lsdc_crtc.c | 438 ++++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.c | 823 ++++++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_drv.h | 212 +++++++ drivers/gpu/drm/lsdc/lsdc_encoder.c | 79 +++ drivers/gpu/drm/lsdc/lsdc_i2c.c | 220 +++++++ drivers/gpu/drm/lsdc/lsdc_i2c.h | 61 ++ drivers/gpu/drm/lsdc/lsdc_irq.c | 49 ++ drivers/gpu/drm/lsdc/lsdc_irq.h | 37 ++ drivers/gpu/drm/lsdc/lsdc_plane.c | 711 ++++++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.c | 596 +++++++++++++++++++ drivers/gpu/drm/lsdc/lsdc_pll.h | 109 ++++ drivers/gpu/drm/lsdc/lsdc_regs.h | 242 ++++++++ 18 files changed, 4128 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_connector.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_connector.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_crtc.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_encoder.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_i2c.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_i2c.h create mode 100644 drivers/gpu/drm/lsdc/lsdc_irq.c create mode 100644 drivers/gpu/drm/lsdc/lsdc_irq.h 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.h
drivers/gpu/drm/Kconfig +2 -0
@@ -405,6 +405,8 @@ source "drivers/gpu/drm/gud/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
@@ -133,3 +133,4 @@ obj-y += xlnx/ obj-y += gud/ obj-$(CONFIG_DRM_HYPERV) += hyperv/ obj-$(CONFIG_DRM_SPRD) += sprd/ +obj-$(CONFIG_DRM_LSDC) += lsdc/
drivers/gpu/drm/lsdc/Kconfig new file +32 -0
@@ -0,0 +1,32 @@ +config DRM_LSDC + tristate "DRM Support for loongson's display controller" + depends on DRM && PCI + depends on MACH_LOONGSON64 || LOONGARCH || MIPS || COMPILE_TEST + select OF + select CMA if HAVE_DMA_CONTIGUOUS + select DMA_CMA if HAVE_DMA_CONTIGUOUS + select DRM_KMS_HELPER + select DRM_KMS_FB_HELPER + select DRM_GEM_CMA_HELPER + select VIDEOMODE_HELPERS + select BACKLIGHT_PWM if CPU_LOONGSON2K + select I2C_GPIO if CPU_LOONGSON2K + select I2C_LS2X if CPU_LOONGSON2K + default m + help + This is a KMS driver for the display controller in the LS7A1000 + bridge chip and LS2K1000 SoC. The display controller have two + display pipes and it is a pci device. + When using it on LS2K1000/LS2K0500 SoC, its framebuffer is + located at system memory. + If "M" is selected, the module will be called lsdc. + + If in doubt, say "Y". + +config DRM_LSDC_VRAM_DRIVER + bool "vram helpper based device driver support" + depends on DRM_LSDC + select DRM_VRAM_HELPER + default y + help + If in doubt, say "n".
drivers/gpu/drm/lsdc/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +# +# Makefile for the lsdc drm device driver. +# + +lsdc-y := \ + lsdc_drv.o \ + lsdc_crtc.o \ + lsdc_irq.o \ + lsdc_plane.o \ + lsdc_pll.o \ + lsdc_i2c.o \ + lsdc_encoder.o \ + lsdc_connector.o + +obj-$(CONFIG_DRM_LSDC) += lsdc.o
drivers/gpu/drm/lsdc/lsdc_connector.c new file +441 -0
441 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_connector.h new file +60 -0
60 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_crtc.c new file +438 -0
438 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_drv.c new file +823 -0
823 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_drv.h new file +212 -0
212 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_encoder.c new file +79 -0
79 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_i2c.c new file +220 -0
220 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_i2c.h new file +61 -0
61 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_irq.c new file +49 -0
49 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_irq.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2020 Loongson Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +*/ + +/* +* Authors: +* Sui Jingfeng <[email protected]> +*/ + +#ifndef __LSDC_IRQ_H__ +#define __LSDC_IRQ_H__ + +irqreturn_t lsdc_irq_thread_cb (int irq,void *arg); +irqreturn_t lsdc_irq_handler_cb (int irq,void *arg); + +#endif
drivers/gpu/drm/lsdc/lsdc_plane.c new file +711 -0
521 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_pll.c new file +596 -0
596 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_pll.h new file +109 -0
109 lines not on this page · raw message
drivers/gpu/drm/lsdc/lsdc_regs.h new file +242 -0
242 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.20.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 Sui,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on drm/drm-next]
[also build test WARNING on v5.17-rc2 next-20220128]
[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]
url: https://github.com/0day-ci/linux/commits/Sui-Jingfeng/drm-lsdc-add-drm-driver-support-for-loongson-display-controller/20220130-130855 base: git://anongit.freedesktop.org/drm/drm drm-next config: s390-randconfig-r044-20220130 (https://download.01.org/0day-ci/archive/20220131/202201310744.a12EW0LM-lkp(a)intel.com/config) compiler: s390-linux-gcc (GCC) 11.2.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/0day-ci/linux/commit/3595361f14c6607486d8c94cf7f012f8c8b267c3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Sui-Jingfeng/drm-lsdc-add-drm-driver-support-for-loongson-display-controller/20220130-130855 git checkout 3595361f14c6607486d8c94cf7f012f8c8b267c3
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=s390 SHELL=/bin/bash drivers/gpu/drm/lsdc/
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
drivers/gpu/drm/lsdc/lsdc_pll.c:219: warning: Function parameter or member 'this' not described in 'lsdc_pixpll_find' drivers/gpu/drm/lsdc/lsdc_pll.c:219: warning: Function parameter or member 'clock' not described in 'lsdc_pixpll_find' drivers/gpu/drm/lsdc/lsdc_pll.c:219: warning: Function parameter or member 'pout' not described in 'lsdc_pixpll_find'
>> drivers/gpu/drm/lsdc/lsdc_pll.c:219: warning: expecting prototype for lsdc_crtc_init(). Prototype was for lsdc_pixpll_find() instead
vim +219 drivers/gpu/drm/lsdc/lsdc_pll.c
195
196
197 /**
198 * lsdc_crtc_init
199 *
200 * @ddev: point to the drm_device structure
201 * @index: hardware crtc index
202 *
203 * Init CRTC
204 */
205
206 /*
207 * Find a set of pll parameters (to generate pixel clock) from a static
208 * local table, which avoid to compute the pll parameter everytime a
209 * modeset is triggered.
210 *
211 * @clock: the desired pixel clock wanted to generate, the unit is kHz
212 * @pout: pointer to where hardware pll parameters(if found) to save
213 *
214 * Return true if a parameter is found, otherwise return false.
215 */
216 static bool lsdc_pixpll_find(struct lsdc_pll * const this,
217 unsigned int clock,
218 struct lsdc_pll_core_values * const pout)
> 219 { 220 unsigned int num = ARRAY_SIZE(pll_param_table);
221 unsigned int i;
222
223 for (i = 0; i < num; i++) {
224 if (clock != pll_param_table[i].clock)
225 continue;
226
227 pout->div_ref = pll_param_table[i].div_ref;
228 pout->loopc = pll_param_table[i].loopc;
229 pout->div_out = pll_param_table[i].div_out;
230
231 return true;
232 }
233
234 drm_dbg(this->ddev, "pixel clock %u: miss\n", clock);
235
236 return false;
237 }
238
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Sui,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on drm/drm-next]
[also build test ERROR on v5.17-rc2 next-20220128]
[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]
url: https://github.com/0day-ci/linux/commits/Sui-Jingfeng/drm-lsdc-add-drm-driver-support-for-loongson-display-controller/20220130-130855 base: git://anongit.freedesktop.org/drm/drm drm-next config: arc-randconfig-r043-20220130 (https://download.01.org/0day-ci/archive/20220131/202201311126.DzQNRNnI-lkp(a)intel.com/config) compiler: arc-elf-gcc (GCC) 11.2.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/0day-ci/linux/commit/3595361f14c6607486d8c94cf7f012f8c8b267c3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Sui-Jingfeng/drm-lsdc-add-drm-driver-support-for-loongson-display-controller/20220130-130855 git checkout 3595361f14c6607486d8c94cf7f012f8c8b267c3
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash drivers/gpu/drm/lsdc/
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
In file included from include/linux/device.h:15,
from include/linux/pci.h:37,
from drivers/gpu/drm/lsdc/lsdc_drv.c:34:
drivers/gpu/drm/lsdc/lsdc_drv.c: In function 'lsdc_vram_init':
>> include/drm/drm_print.h:425:39: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 3 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~~~~~
include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~
include/linux/dev_printk.h:150:58: note: in expansion of macro 'dev_fmt'
150 | dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~
include/drm/drm_print.h:425:9: note: in expansion of macro 'dev_info'
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~
include/drm/drm_print.h:429:9: note: in expansion of macro '__drm_printk'
429 | __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/gpu/drm/lsdc/lsdc_drv.c:580:9: note: in expansion of macro 'drm_info'
580 | drm_info(ddev, "vram start: 0x%llx, size: %lluMB\n", base, size >> 20);
| ^~~~~~~~
>> include/drm/drm_print.h:425:39: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'resource_size_t' {aka 'unsigned int'} [-Wformat=]
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~~~~~
include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~
include/linux/dev_printk.h:150:58: note: in expansion of macro 'dev_fmt'
150 | dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~
include/drm/drm_print.h:425:9: note: in expansion of macro 'dev_info'
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~
include/drm/drm_print.h:429:9: note: in expansion of macro '__drm_printk'
429 | __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/gpu/drm/lsdc/lsdc_drv.c:580:9: note: in expansion of macro 'drm_info'
580 | drm_info(ddev, "vram start: 0x%llx, size: %lluMB\n", base, size >> 20);
| ^~~~~~~~
>> drivers/gpu/drm/lsdc/lsdc_drv.c:600:63: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
600 | drm_info(ddev, "vram virtual addr: 0x%llx\n", (u64)ldev->vram);
| ^
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:425:9: note: in expansion of macro 'dev_info'
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~
include/drm/drm_print.h:429:9: note: in expansion of macro '__drm_printk'
429 | __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/gpu/drm/lsdc/lsdc_drv.c:600:17: note: in expansion of macro 'drm_info'
600 | drm_info(ddev, "vram virtual addr: 0x%llx\n", (u64)ldev->vram);
| ^~~~~~~~
--
>> drivers/gpu/drm/lsdc/lsdc_crtc.c:321:6: warning: no previous prototype for 'lsdc_enable_display' [-Wmissing-prototypes]
321 | void lsdc_enable_display(struct lsdc_device *ldev, unsigned int index)
| ^~~~~~~~~~~~~~~~~~~
--
>> drivers/gpu/drm/lsdc/lsdc_irq.c:9:13: warning: no previous prototype for 'lsdc_irq_thread_cb' [-Wmissing-prototypes]
9 | irqreturn_t lsdc_irq_thread_cb(int irq, void *arg)
| ^~~~~~~~~~~~~~~~~~
>> drivers/gpu/drm/lsdc/lsdc_irq.c:33:13: warning: no previous prototype for 'lsdc_irq_handler_cb' [-Wmissing-prototypes] 33 | irqreturn_t lsdc_irq_handler_cb(int irq, void *arg)
| ^~~~~~~~~~~~~~~~~~~
--
In file included from include/linux/device.h:15,
from include/drm/drm_print.h:32,
from drivers/gpu/drm/lsdc/lsdc_pll.c:30:
drivers/gpu/drm/lsdc/lsdc_pll.c: In function 'lsdc_pixpll_setup':
>> drivers/gpu/drm/lsdc/lsdc_pll.c:191:62: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
191 | this->index, this->reg_base, this->reg_size, (u64)this->mmio);
| ^
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:425:9: note: in expansion of macro 'dev_info'
425 | dev_##level##type((drm)->dev, "[drm] " fmt, ##__VA_ARGS__)
| ^~~~
include/drm/drm_print.h:429:9: note: in expansion of macro '__drm_printk'
429 | __drm_printk((drm), info,, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~
drivers/gpu/drm/lsdc/lsdc_pll.c:190:9: note: in expansion of macro 'drm_info'
190 | drm_info(this->ddev, "PIXPLL%u REG[%x, %u] map to %llx\n",
| ^~~~~~~~
drivers/gpu/drm/lsdc/lsdc_pll.c: In function 'ls2k1000_pixpll_param_update':
>> drivers/gpu/drm/lsdc/lsdc_pll.c:386:19: error: implicit declaration of function 'readq'; did you mean 'readb'? [-Werror=implicit-function-declaration]
386 | u64 val = readq(reg);
| ^~~~~
| readb
>> drivers/gpu/drm/lsdc/lsdc_pll.c:393:9: error: implicit declaration of function 'writeq'; did you mean 'writeb'? [-Werror=implicit-function-declaration]
393 | writeq(val, reg);
| ^~~~~~
| writeb
>> drivers/gpu/drm/lsdc/lsdc_pll.c:395:31: warning: left shift count >= width of type [-Wshift-count-overflow]
395 | val = (1L << 7) | (1L << 42) | (3L << 10); /* allow L1 PLL locked */
| ^~
drivers/gpu/drm/lsdc/lsdc_pll.c:396:44: warning: left shift count >= width of type [-Wshift-count-overflow]
396 | val |= (unsigned long)param->loopc << 32; /* set loopc */
| ^~cc1: some warnings being treated as errors
vim +386 drivers/gpu/drm/lsdc/lsdc_pll.c
184
185
186 static int lsdc_pixpll_setup(struct lsdc_pll * const this)
187 {
188 this->mmio = ioremap(this->reg_base, this->reg_size);
189
190 drm_info(this->ddev, "PIXPLL%u REG[%x, %u] map to %llx\n",
> 191 this->index, this->reg_base, this->reg_size, (u64)this->mmio);
192
193 return 0;
194 }
195
196
197 /**
198 * lsdc_crtc_init
199 *
200 * @ddev: point to the drm_device structure
201 * @index: hardware crtc index
202 *
203 * Init CRTC
204 */
205
206 /*
207 * Find a set of pll parameters (to generate pixel clock) from a static
208 * local table, which avoid to compute the pll parameter everytime a
209 * modeset is triggered.
210 *
211 * @clock: the desired pixel clock wanted to generate, the unit is kHz
212 * @pout: pointer to where hardware pll parameters(if found) to save
213 *
214 * Return true if a parameter is found, otherwise return false.
215 */
216 static bool lsdc_pixpll_find(struct lsdc_pll * const this,
217 unsigned int clock,
218 struct lsdc_pll_core_values * const pout)
219 {
220 unsigned int num = ARRAY_SIZE(pll_param_table);
221 unsigned int i;
222
223 for (i = 0; i < num; i++) {
224 if (clock != pll_param_table[i].clock)
225 continue;
226
227 pout->div_ref = pll_param_table[i].div_ref;
228 pout->loopc = pll_param_table[i].loopc;
229 pout->div_out = pll_param_table[i].div_out;
230
231 return true;
232 }
233
234 drm_dbg(this->ddev, "pixel clock %u: miss\n", clock);
235
236 return false;
237 }
238
239 /*
240 * Find a set of pll parameters which have minimal difference with desired
241 * clock frequency. It does that by computing the all of pll parameters
242 * combines possible and compare the diff and find the minimal.
243 *
244 * clock_out = refclk / div_ref * loopc / div_out
245 *
246 * refclk is fixed as 100MHz in ls7a1000, ls2k1000 and ls2k0500
247 *
248 * @clk: the desired pixel clock wanted to generate, the unit is kHz
249 * @pout: pointer to where hardware pll parameters(if found) to save
250 * @verbose: print the pll parameter and the actual pixel clock.
251 *
252 * Return true if a parameter is found, otherwise return false.
253 */
254 static bool lsdc_pixpll_compute(struct lsdc_pll * const this,
255 unsigned int clk,
256 bool verbose,
257 struct lsdc_pll_core_values * const pout)
258 {
259 unsigned int refclk = this->ref_clock;
260 const unsigned int tolerance = 1000;
261 unsigned int min = tolerance;
262 unsigned int div_out, loopc, div_ref;
263
264 if (lsdc_pixpll_find(this, clk, pout))
265 return true;
266
267 for (div_out = 6; div_out < 64; div_out++) {
268 for (div_ref = 3; div_ref < 6; div_ref++) {
269 for (loopc = 6; loopc < 161; loopc++) {
270 int diff;
271
272 if (loopc < 12 * div_ref)
273 continue;
274 if (loopc > 32 * div_ref)
275 continue;
276
277 diff = clk * div_out - refclk * loopc / div_ref;
278
279 if (diff < 0)
280 diff = -diff;
281
282 if (diff < min) {
283 min = diff;
284 pout->div_ref = div_ref;
285 pout->div_out = div_out;
286 pout->loopc = loopc;
287
288 if (diff == 0)
289 return true;
290 }
291 }
292 }
293 }
294
295 if (verbose) {
296 unsigned int clk_out;
297
298 clk_out = refclk / pout->div_ref * pout->loopc / pout->div_out;
299
300 drm_info(this->ddev, "pixpll%u\n", this->index);
301
302 drm_info(this->ddev, "div_ref=%u, loopc=%u, div_out=%u\n",
303 pout->div_ref, pout->loopc, pout->div_out);
304
305 drm_info(this->ddev, "desired clk=%u, actual out=%u, diff=%d\n",
306 clk, clk_out, clk_out - clk);
307 }
308
309 return min < tolerance;
310 }
311
312
313 static int ls7a1000_pixpll_param_update(struct lsdc_pll * const this,
314 const struct lsdc_pll_core_values * const param)
315 {
316 u32 val;
317 unsigned int counter = 0;
318 void __iomem *reg = this->mmio;
319 bool locked;
320
321
322 /* clear sel_pll_out0 */
323 val = readl(reg + 0x4);
324 val &= ~(1 << 8);
325 writel(val, reg + 0x4);
326
327 /* set pll_pd */
328 val = readl(reg + 0x4);
329 val |= (1 << 13);
330 writel(val, reg + 0x4);
331
332 /* clear set_pll_param */
333 val = readl(reg + 0x4);
334 val &= ~(1 << 11);
335 writel(val, reg + 0x4);
336
337 /* clear old value & config new value */
338 val = readl(reg + 0x04);
339 val &= ~0x7F;
340
341 val |= param->div_ref; /* div_ref */
342 writel(val, reg + 0x4);
343
344 val = readl(reg);
345 val &= ~(0x7f << 0);
346 val |= param->div_out; /* div_out */
347 val &= ~(0x1ffUL << 21);
348 val |= param->loopc << 21; /* loopc */
349 writel(val, reg);
350
351 /* set set_pll_param */
352 val = readl(reg + 0x4);
353 val |= (1 << 11);
354 writel(val, reg + 0x4);
355
356 /* clear pll_pd */
357 val = readl(reg + 0x4);
358 val &= ~(1 << 13);
359 writel(val, reg + 0x4);
360
361 /* wait pll lock */
362 do {
363 val = readl(reg + 0x4);
364 locked = val & 0x80;
365 counter++;
366 } while (locked == false);
367
368 drm_dbg_kms(this->ddev, "%u loop waited\n", counter);
369
370 /* set sel_pll_out0 */
371 val = readl(reg + 0x4);
372 val |= (1UL << 8);
373 writel(val, reg + 0x4);
374
375 return 0;
376 }
377
378
379 /*
380 * the PIX PLL be software configurable when SYS_CLKSEL[1:0] is 10b
381 */
382 static int ls2k1000_pixpll_param_update(struct lsdc_pll * const this,
383 const struct lsdc_pll_core_values * const param)
384 {
385 void __iomem *reg = this->mmio;
> 386 u64 val = readq(reg);
387 bool locked;
388 unsigned int counter = 0;
389
390 val &= ~(1 << 0); /* Bypass the PLL, using refclk directly */
391 val |= (1 << 19); /* powerdown the PLL */
392 val &= ~(1 << 2); /* don't use the software configure param */
> 393 writeq(val, reg);
394
> 395 val = (1L << 7) | (1L << 42) | (3L << 10); /* allow L1 PLL locked */
396 val |= (unsigned long)param->loopc << 32; /* set loopc */
397 val |= (unsigned long)param->div_ref << 26; /* set div_ref */ 398 writeq(val, reg);
399 writeq(param->div_out, reg + 8); /* set div_out */
400
401 val = readq(reg);
402 val |= (1 << 2); /* use the software configure param */
403 val &= ~(1 << 19); /* powerup the PLL */
404 writeq(val, reg);
405
406 /* wait pll setup and locked */
407 do {
408 val = readl(reg);
409 locked = val & 0x10000;
410 counter++;
411 } while (locked == false);
412
413 drm_dbg_kms(this->ddev, "%u loop waited\n", counter);
414
415 val = readq(reg);
416 val |= (1 << 0); /* switch to the software configured pll */
417 writeq(val, reg);
418
419 return 0;
420 }
421
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]