Driver for Freescale Display Interface Unit (A LCD controller)
Subsystems (4)
The following patches are for Freescale DIU. The first patch is a DIU driver. The second patch is the platform code to support the driver. It is a frame buffer driver for DIU. Descriptions can be found in the patches.
It is a new feature targeting 2.6.26 kernel.
PATCH 2/2 Add DIU platform code for MPC8610HPCD
In reply to York SunAdd platform code to support Freescale DIU. The platform code includes framebuffer memory allocation, pixel format, monitor port, etc.
---
This patch is targeting 2.6.26.
arch/powerpc/platforms/86xx/mpc8610_hpcd.c | 266 +++++++++++++++++++++++++++- 1 files changed, 264 insertions(+), 2 deletions(-)
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +264 -2
@@ -3,6 +3,7 @@* * Initial author: Xianghua Xiao <[email protected]> * Recode: Jason Jin <[email protected]> +* York Sun <[email protected]> * * Rewrite the interrupt routing. remove the 8259PIC support, * All the integrated device in ULI use sideband interrupt.
@@ -38,6 +39,17 @@#include <sysdev/fsl_pci.h> #include <sysdev/fsl_soc.h> +#include <linux/bootmem.h> +#include <asm/rheap.h> + +#undef DEBUG +#ifdef DEBUG +#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__, ## args) +#else +#define DPRINTK(fmt, args...) +#endif +static unsigned char *pixis_bdcfg0, *pixis_arch; +static struct of_device_id __initdata mpc8610_ids[] = { { .compatible ="fsl,mpc8610-immr" , }, {}
@@ -161,12 +173,251 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_AL ,0x5288 , final_uli5288);#endif /* CONFIG_PCI */ +static u32 get_busfreq (void ) +{ +struct device_node *node; + +u32 fs_busfreq =0 ; + node =of_find_node_by_type (NULL ,"cpu" ); +if (node) { +unsigned int size; +const unsigned int *prop = +of_get_property (node,"bus-frequency" , &size); +if (prop) + fs_busfreq = *prop; +of_node_put (node); + }; +return fs_busfreq; +} + +#ifdef CONFIG_FB_FSL_DIU + +static rh_block_t diu_rh_block[16 ]; +static rh_info_t diu_rh_info; +static unsigned long diu_size =1280 *1024 *4 ;/* One 1280x1024 buffer */ +static void *diu_mem; + +unsigned int platform_get_pixel_format + (unsigned int bits_per_pixel,int monitor_port) +{ +static const unsigned long pixelformat[][3 ] = { + {0x88882317 ,0x88083218 ,0x65052119 }, + {0x88883316 ,0x88082219 ,0x65053118 }, + }; +unsigned int pix_fmt, arch_monitor; + + arch_monitor = ((*pixis_arch ==0x01 ) && (monitor_port ==0 ))?0 :1 ; +/* DVI port for board version 0x01 */ + +if (bits_per_pixel ==32 ) + pix_fmt = pixelformat[arch_monitor][0 ]; +else if (bits_per_pixel ==24 ) + pix_fmt = pixelformat[arch_monitor][1 ]; +else if (bits_per_pixel ==16 ) + pix_fmt = pixelformat[arch_monitor][2 ]; +else + pix_fmt = pixelformat[1 ][0 ]; + +return pix_fmt; +} +EXPORT_SYMBOL (platform_get_pixel_format); + +void platform_set_gamma_table (int monitor_port,char *gamma_table_base) +{ +int i; +if (monitor_port ==2 ) {/* dual link LVDS */ +for (i =0 ; i <256 *3 ; i++) + gamma_table_base[i] = (gamma_table_base[i] <<2 ) | + ((gamma_table_base[i] >>6 ) &0x03 ); + } +} +EXPORT_SYMBOL (platform_set_gamma_table); + +void platform_set_monitor_port (int monitor_port) +{ +static const u8 bdcfg[] = {0xBD ,0xB5 ,0xA5 }; +if (monitor_port <3 ) + *pixis_bdcfg0 = bdcfg[monitor_port]; +} +EXPORT_SYMBOL (platform_set_monitor_port); + +void platform_set_pixel_clock (unsigned int pixclock) +{ +u32 __iomem *clkdvdr; +u32 temp; +/* variables for pixel clock calcs */ +ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock; +ulong pixval; +long err; +int i; + + clkdvdr =ioremap (get_immrbase () +0xe0800 ,sizeof (u32)); + +/* Pixel Clock configuration */ +DPRINTK ("DIU: Bus Frequency = %d\n" ,get_busfreq ()); + speed_ccb =get_busfreq (); + +/* Calculate the pixel clock with the smallest error */ +/* calculate the following in steps to avoid overflow */ +DPRINTK ("DIU pixclock in ps - %d\n" , pixclock); + temp =1000000000 /pixclock; + temp *=1000 ; + pixclock = temp; +DPRINTK ("DIU pixclock freq - %lu\n" , pixclock); + + temp = pixclock *5 /100 ; +DPRINTK ("deviation = %d\n" , temp); + minpixclock = pixclock - temp; + maxpixclock = pixclock + temp; +DPRINTK ("DIU minpixclock - %lu\n" , minpixclock); +DPRINTK ("DIU maxpixclock - %lu\n" , maxpixclock); + pixval = speed_ccb/pixclock; +DPRINTK ("DIU pixval = %lu\n" , pixval); + + err =100000000 ; + bestval = pixval; +DPRINTK ("DIU bestval = %lu\n" , bestval); + + bestfreq =0 ; +for (i =-1 ; i <=1 ; i++) { + temp = speed_ccb / ((pixval+i) +1 ); +DPRINTK ("DIU test pixval i= %d, pixval=%lu, temp freq. = %u\n" , + i, pixval, temp); +if ((temp < minpixclock) || (temp > maxpixclock)) +DPRINTK ("DIU exceeds monitor range (%lu to %lu)\n" , + minpixclock, maxpixclock); +else if (abs (temp - pixclock) < err) { +DPRINTK ("Entered the else if block %d\n" , i); + err =abs (temp - pixclock); + bestval = pixval+i; + bestfreq = temp; + } + } + +DPRINTK ("DIU chose = %lx\n" , bestval); +DPRINTK ("DIU error = %ld\n NomPixClk " , err); +DPRINTK ("DIU: Best Freq = %lx\n" , bestfreq); +/* Modify PXCLK in GUTS CLKDVDR */ +DPRINTK ("DIU: Current value of CLKDVDR = 0x%08x\n" , (*clkdvdr)); + temp = (*clkdvdr) &0x2000FFFF ; + *clkdvdr = temp;/* turn off clock */ + *clkdvdr = temp |0x80000000 | (((bestval) &0x1F ) <<16 ); +DPRINTK ("DIU: Modified value of CLKDVDR = 0x%08x\n" , (*clkdvdr)); +} +EXPORT_SYMBOL (platform_set_pixel_clock); + +ssize_t platform_show_monitor_port (int monitor_port,char *buf) +{ +return snprintf (buf,PAGE_SIZE , +"%c0 - DVI\n" +"%c1 - Single link LVDS\n" +"%c2 - Dual link LVDS\n" , + monitor_port ==0 ?'*' :' ' , + monitor_port ==1 ?'*' :' ' , + monitor_port ==2 ?'*' :' ' ); +} +EXPORT_SYMBOL (platform_show_monitor_port); + +int platform_set_sysfs_monitor_port (int val) +{ +return val <3 ? val :0 ; +} +EXPORT_SYMBOL (platform_set_monitor_port); + +static void __init preallocate_diu_videomemory (void ) +{ +DPRINTK ("diu_size=%lu\n" , diu_size); + + diu_mem =__alloc_bootmem (diu_size,8 ,0 ); +if (!diu_mem) { +printk (KERN_ERR "fsl-diu: cannot allocate %lu bytes\n" , + diu_size); +return ; + } + +printk (KERN_INFO "%s: diu_mem=%p\n" , __func__, diu_mem); + +rh_init (&diu_rh_info,4096 ,ARRAY_SIZE (diu_rh_block), diu_rh_block); +rh_attach_region (&diu_rh_info, diu_mem, diu_size); +} + +/* To allocate memory for framebuffer. First try dma_alloc_coherent. If it +* fails, try rh_alloc. The reason is dma_alloc_coherent cannot allocate +* very large memory (more than 4MB). We don't want to allocate all memory +* in rheap since small memory allocation/deallocation will fragment the +* rheap and make the furture large allocation fail. +*/ + +void *fsl_diu_alloc (unsigned long size,unsigned long *phys) +{ +void *virt; + +DPRINTK ("size=%lu\n" , size); + + virt =dma_alloc_coherent (0 , size, phys,GFP_DMA |GFP_KERNEL ); + +if (virt) { +DPRINTK ("dma virt=%p phys=%lx\n" , virt, *phys); +return virt; + } + +if (!diu_mem) { +printk (KERN_INFO "%s: no diu_mem\n" , __func__); +return NULL ; + } + + virt =rh_alloc (&diu_rh_info, size,"DIU" ); +if (virt) + *phys =virt_to_bus (virt); + +DPRINTK ("rh virt=%p phys=%x\n" , virt, *phys); + +return virt; +} +EXPORT_SYMBOL (fsl_diu_alloc); + +void fsl_diu_free (void *p,unsigned long size) +{ +DPRINTK ("p=%p size=%lu\n" , p, size); + +if (!p) +return ; + +if ((p >= diu_mem) && (p < (diu_mem + diu_size))) { +DPRINTK ("rh\n" ); +rh_free (&diu_rh_info, p); + }else { +DPRINTK ("dma\n" ); +dma_free_coherent (0 , size, p,0 ); + } +} +EXPORT_SYMBOL (fsl_diu_free); + +static int __init early_parse_diufb (char *p) +{ +if (!p) +return 1 ; + + diu_size =_ALIGN_UP (memparse (p, &p),8 ); + +printk (KERN_INFO "%s: diu_size=%lu\n" , __func__, diu_size); + +return 0 ; +} +early_param ("diufb" , early_parse_diufb); + +#else + +#define preallocate_diu_videomemory () do { } while (0) + +#endif +static void __init mpc86xx_hpcd_setup_arch (void ) { -#ifdef CONFIG_PCI +struct resource r;struct device_node *np; -#endif +if (ppc_md.progress) ppc_md.progress ("mpc86xx_hpcd_setup_arch()" ,0 );
@@ -183,6 +434,17 @@ mpc86xx_hpcd_setup_arch(void) } }#endif +preallocate_diu_videomemory (); + + np =of_find_compatible_node (NULL ,NULL ,"fsl,fpga-pixis" ); +if (np) { +of_address_to_resource (np,0 , &r); +of_node_put (np); + pixis_bdcfg0 =ioremap (r.start +0x00000008 ,sizeof (u8)); + pixis_arch =ioremap (r.start +0x00000001 ,sizeof (u8)); + }else +printk (KERN_ERR "Err: " +"can't find device node 'fsl,fpga-pixis'\n" );printk ("MPC86xx HPCD board from Freescale Semiconductor\n" ); }
Signature · 1 line
1.5.2.2
PATCH 1/2 Driver for Freescale 8610 and 5121 DIU
In reply to York SunThe following features are supported:
plane 0 works as a regular frame buffer, can be accessed by /dev/fb0 plane 1 has two AOIs (area of interest), can be accessed by /dev/fb1 and /dev/fb2 plane 2 has two AOIs, can be accessed by /dev/fb3 and /dev/fb4 Special ioctls support AOIs
All /dev/fb* can be used as regular frame buffer devices, except hardware change can only be made through /dev/fb0. Changing pixel clock has no effect on other fbs.
Limitation of usage of AOIs:
AOIs on the same plane can not be horizonally overlapped
AOIs have horizonal order, i.e. AOI0 should be always on top of AOI1 AOIs can not beyond phisical display area. Application should check AOI geometry before changing physical resolution on /dev/fb0
required command line parameters to preallocate memory for frame buffer diufb=15M
optional command line parameters to set modes and monitor video=fslfb:[resolution][,bpp][,monitor]
Syntax:
Resolution
xres x yres-bpp@refresh_rate, the -bpp and @refresh_rate are optional eg, 1024x768, 1280x1024, 1280x1024-32, 1280x1024@60, 1280x1024-32@60, 1280x480-32@60
Bpp
bpp=32, bpp=24, or bpp=16
Monitor
monitor=0, monitor=1, monitor=2
0 is DVI
1 is Single link LVDS
2 is Double link LVDS
Note: switching monitor is a board feather, not DIU feather. MPC8610HPCD has three monitor ports to swtich to. MPC5121ADS doesn't have additional monitor port. So switching monirot port for MPC5121ADS has no effect.
---
This patch is targeting 2.6.26, adding new feature.
Documentation/powerpc/booting-without-of.txt | 34 + arch/powerpc/boot/dts/mpc8610_hpcd.dts | 13 + drivers/video/Kconfig | 10 + drivers/video/Makefile | 1 + drivers/video/fsl-diu-fb.c | 1634 ++++++++++++++++++++++++++ drivers/video/fsl-diu-fb.h | 388 ++++++ 6 files changed, 2080 insertions(+), 0 deletions(-) create mode 100644 drivers/video/fsl-diu-fb.c create mode 100644 drivers/video/fsl-diu-fb.h
Documentation/powerpc/booting-without-of.txt +34 -0
@@ -2816,6 +2816,40 @@ platforms are moved over to use the flattened-device-tree model. big-endian; }; + r) Freescale Display Interface Unit + + The Freescale DIU is a LCD controller, with proper hardware, it can also + drive DVI monitors. + + Required properties: + - compatible : should be "fsl-diu". + - reg : should contain at least address and length of the DIU register + set. + - Interrupts : one DIU interrupt should be describe here. + + Example (MPC8610HPCD) + diu@2c000 { + device_type = "lcd"; + compatible = "fsl-diu"; + reg = <0x2c000 100>; + interrupts = <72 2>; + interrupt-parent = <&mpic>; + }; + + s) Freescale on board FPGA + + This is the memory-mapped registers for on board FPGA. + + Required properities: + - compatible : should be "fsl,fpga-pixis". + - reg : should contain the address and the lenght of the FPPGA register + set. + + Example (MPC8610HPCD) + fpga { + compatible = "fsl,fpga-pixis"; + reg = <0xe8000000 20>; + }; More devices will be defined as this spec matures.
arch/powerpc/boot/dts/mpc8610_hpcd.dts +13 -0
@@ -45,6 +45,11 @@ reg = <0x00000000 0x20000000>; // 512M at 0x0 }; + fpga { + compatible = "fsl,fpga-pixis"; + reg = <0xe8000000 20>; // pixis at 0xe8000000 + }; + soc@e0000000 { #address-cells = <1>; #size-cells = <1>;
@@ -104,6 +109,14 @@ interrupt-parent = <&mpic>; }; + diu@2c000 { + device_type = "lcd"; + compatible = "fsl-diu"; + reg = <0x2c000 100>; + interrupts = <72 2>; + interrupt-parent = <&mpic>; + }; + mpic: interrupt-controller@40000 { clock-frequency = <0>; interrupt-controller;
drivers/video/Kconfig +10 -0
@@ -1766,6 +1766,16 @@ config FB_MBX_DEBUG If unsure, say N. +config FB_FSL_DIU + tristate "Freescale MPC8610/MPC5121 DIU framebuffer support" + depends on FB && (MPC8610 || MPC5121) + select FB_CFB_FILLRECT + select FB_CFB_COPYAREA + select FB_CFB_IMAGEBLIT + select PPC_LIB_RHEAP + ---help--- + Framebuffer driver for the MPC8610/MPC5121 chip from Freescale + config FB_W100 tristate "W100 frame buffer support" depends on FB && PXA_SHARPSL
drivers/video/Makefile +1 -0
@@ -113,6 +113,7 @@ obj-$(CONFIG_FB_PS3) += ps3fb.o obj-$(CONFIG_FB_SM501) += sm501fb.o obj-$(CONFIG_FB_XILINX) += xilinxfb.o obj-$(CONFIG_FB_OMAP) += omap/ +obj-$(CONFIG_FB_FSL_DIU) += fsl-diu-fb.o # Platform or fallback drivers go here obj-$(CONFIG_FB_UVESA) += uvesafb.o
drivers/video/fsl-diu-fb.c new file +1634 -0
1,634 lines not on this page · raw message
drivers/video/fsl-diu-fb.h new file +388 -0
388 lines not on this page · raw message
Signature · 1 line
1.5.2.2
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
drivers/video/fsl-diu-fb.c line 1075
Quoted 11 lines · York Sun
drivers/video/fsl-diu-fb.c new file +11
-0+static int fsl_diu_open (struct fb_info *info,int user) +{ +struct mfb_info *mfbi = info->par; +int res =0 ; + +spin_lock (&diu_lock); + mfbi->count++; +if (mfbi->count ==1 ) { +DPRINTK ("open plane index %d\n" , mfbi->index); +fsl_diu_check_var (&info->var, info); +fsl_diu_set_par (info);
Please retest your code (at least) with sleep-inside spinlock debug option. If I see correctly you call GFP_KERNEL allocation somewhere deeper in this function, which might sleep.
Quoted 4 lines
drivers/video/fsl-diu-fb.c new file +4
-0+ res =fsl_diu_enable_panel (info); +if (res <0 ) + mfbi->count--; + }
drivers/video/fsl-diu-fb.c
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +9
-0+ +spin_unlock (&diu_lock); +return res; +} +static void __exit uninstall_fb(struct fb_info *info) +{ +struct mfb_info *mfbi = info->par; + +DPRINTK ("Entered: uninstall_fb\n" );
You don't need this stuff everywhere (kprobes).
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+if (!mfbi->registered) +return ; + +unregister_framebuffer (info); +unmap_video_memory (info); +if (&info->cmap) +fb_dealloc_cmap (&info->cmap); + + mfbi->registered =0 ; +}
[...]
Quoted 34 lines
drivers/video/fsl-diu-fb.c new file +34
-0+static int fsl_diu_probe (struct platform_device *pdev) +{ +struct mfb_info *mfbi; +unsigned long dummy_ad_addr; +int ret, i, error =0 ; + +DPRINTK ("Entered: fsl_diu_probe\n" ); + +/* Area descriptor memory pool aligns to 64-bit boundary */ +allocate_buf (&pool.ad,sizeof (struct diu_ad ) *FSL_AOI_NUM ,8 ); + +/* Get memory for Gamma Table - 32-byte aligned memory */ +allocate_buf (&pool.gamma,768 ,32 ); + +/* For performance, cursor bitmap buffer aligns to 32-byte boundary */ +allocate_buf (&pool.cursor,MAX_CURS *MAX_CURS *2 ,32 ); + + i =sizeof (fsl_diu_info) /sizeof (struct fb_info ); + dummy_ad = (struct diu_ad *)((u32 )pool.ad.vaddr + pool.ad.offset) + i; + dummy_ad->paddr = pool.ad.paddr + i *sizeof (struct diu_ad ); + dummy_aoi_virt =fsl_diu_alloc (64 , &dummy_ad_addr); + dummy_ad->addr =cpu_to_le32 (dummy_ad_addr); + dummy_ad->pix_fmt =0x88882317 ; + dummy_ad->src_size_g_alpha =cpu_to_le32 ((4 <<12 ) |4 ); + dummy_ad->aoi_size =cpu_to_le32 ((4 <<16 ) |2 ); + dummy_ad->offset_xyi =0 ; + dummy_ad->offset_xyd =0 ; + dummy_ad->next_ad =0 ; +memset (dummy_aoi_virt,0x00 ,64 ); +write_reg (&(dr.diu_reg->desc[0 ]), dummy_ad->paddr); +write_reg (&(dr.diu_reg->desc[1 ]), dummy_ad->paddr); +write_reg (&(dr.diu_reg->desc[2 ]), dummy_ad->paddr); + +for (i =0 ; i <sizeof (fsl_diu_info) /sizeof (struct fb_info ); i++) {
drivers/video/fsl-diu-fb.c line 1492
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+ fsl_diu_info[i].fix.smem_start =0 ; + mfbi = fsl_diu_info[i].par; + mfbi->ad = (struct diu_ad *)((u32 )pool.ad.vaddr + + pool.ad.offset) + i; + mfbi->ad->paddr = pool.ad.paddr + i *sizeof (struct diu_ad ); + ret =install_fb (&fsl_diu_info[i], pdev); +if (ret) { +printk (KERN_ERR "Failed to register framebuffer %d\n" , + i); +return ret;
some kind of free here
Quoted 2 lines
(quoted diff) +2
-0+ } + }
[...]
Quoted 8 lines
drivers/video/fsl-diu-fb.c new file +8
-0+int __init fsl_diu_init (void ) +{ +struct device_node *np; +struct resource r; +int error; +DPRINTK ("Entered: fsl_diu_init\n" ); + np =of_find_compatible_node (NULL ,NULL ,"fsl-diu" ); +if (!np) {
drivers/video/fsl-diu-fb.c line 1577
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+printk (KERN_ERR "Err: can't find device node 'fsl-diu'\n" ); +return -ENODEV ; + } + +of_address_to_resource (np,0 , &r); +of_node_put (np); + +DPRINTK ("%s, r.start: 0x%08x\n" , __func__, r.start); + + dr.diu_reg =ioremap (r.start,sizeof (struct diu ));
The arch never fails with remapping?
Quoted 16 lines
drivers/video/fsl-diu-fb.c new file +16
-0+ +write_reg (&(dr.diu_reg->diu_mode),0 );/* disable DIU anyway*/ + +spin_lock_init (&dr.reg_lock); + + +/* +* For kernel boot options (in 'video=xxxfb:<options>' format) +*/ +#ifndef MODULE + { +char *option; + +if (fb_get_options ("fslfb" , &option)) +return -ENODEV ; +fsl_diu_setup (option);
drivers/video/fsl-diu-fb.c line 1603
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+ } +#endif + error =platform_driver_register (&fsl_diu_driver); + +if (!error) { + error =platform_device_register (&fsl_diu_device); +if (error) { +printk (KERN_ERR "Err: " +"can't register FB device driver!\n" ); +platform_driver_unregister (&fsl_diu_driver);
iounmap
drivers/video/fsl-diu-fb.c line 1606
Quoted 3 lines
drivers/video/fsl-diu-fb.c new file +3
-0+ } +printk (KERN_INFO "FSL_DIU_FB: registed FB device driver!\n" ); + }
else iounmap
Quoted 3 lines
drivers/video/fsl-diu-fb.c new file +3
-0+ +return error; +}
[...]
Quoted 6 lines
drivers/video/fsl-diu-fb.h new file +0
-0@@ -0,0 +1,388 @@
[...]
drivers/video/fsl-diu-fb.h line 25
Quoted 5 lines
drivers/video/fsl-diu-fb.h new file +5
-0+#ifndef __FSL_DIU_FB_H__ +#define __FSL_DIU_FB_H__ + +/* FIXME: This should be changed to dev_dbg this will be done as soon as +* we can obtain dev through the dts setup
then use at least pr_debug() here:
drivers/video/fsl-diu-fb.h line 31
Quoted 6 lines
+ */
drivers/video/fsl-diu-fb.h new file +5
-0+#ifdef DEBUG +#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__, ## args) +#else +#define DPRINTK(fmt, args...) +#endif
regards,
Signature · 3 lines
Jiri Slaby Faculty of Informatics, Masaryk University Suse Labs
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
In reply to York SunHi York,
Just a few things from a first pass.
Quoted 4 lines · On Wed, 12 Mar 2008 16:43:42 -0500 York Sun <[email protected]> wrote:
+++
b/drivers/video/fsl-diu-fb.c+#include <
asm/of_platform.h>
Please include <linux/of_platform.h> instead.
drivers/video/fsl-diu-fb.c line 1391
Quoted 6 lines
drivers/video/fsl-diu-fb.c new file +5
-0+/* Align to 64-bit(8-byte), 32-byte, etc. */ +static int allocate_buf (struct diu_addr *buf,u32 size,u32 bytes_align) +{ + buf->vaddr = dma_alloc_coherent(0, ssize, + (dma_addr_t *) &(buf->paddr),
This cast is unnecessary as buf->paddr is a dma_addr_t ...
drivers/video/fsl-diu-fb.h line 106
Quoted 4 lines
+++
b/drivers/video/fsl-diu-fb.hdrivers/video/fsl-diu-fb.h new file +2
-0+static struct fb_videomode __devinitdata fsl_diu_default_mode = { +static struct fb_videomode __devinitdata fsl_diu_mode_db[] = {
Why are these in the .h file? They should be in the .c file.
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 5 lines · York Sun
The following patches are for Freescale DIU. The first patch is a DIU driver. The second patch is the platform code to support the driver. It is a frame buffer driver for DIU. Descriptions can be found in the patches.
It is a new feature targeting 2.6.26 kernel.
Please CC [email protected] when submitting new frame buffer device drivers. Thx!
With kind regards,
Geert Uytterhoeven
Software Architect
Sony Network and Software Technology Center Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium
Phone: +32 (0)2 700 8453 Fax: +32 (0)2 700 8622 E-mail: [email protected] Internet: http://www.sony-europe.com/
Sony Network and Software Technology Center Europe
A division of Sony Service Centre (Europe) N.V. Registered office: Technologielaan 7 · B-1840 Londerzeel · Belgium VAT BE 0413.825.160 · RPR Brussels
Fortis Bank Zaventem · Swift GEBABEBB08A · IBAN BE39001382358619
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
In reply to Jiri Slabyping.
Seeing this in -mm yet. Are those comments all wrong? Are you working on it?
Quoted 179 lines · Jiri Slaby
drivers/video/fsl-diu-fb.c line 1075
Quoted 11 lines · York Sun
drivers/video/fsl-diu-fb.c new file +11
-0+static int fsl_diu_open (struct fb_info *info,int user) +{ +struct mfb_info *mfbi = info->par; +int res =0 ; + +spin_lock (&diu_lock); + mfbi->count++; +if (mfbi->count ==1 ) { +DPRINTK ("open plane index %d\n" , mfbi->index); +fsl_diu_check_var (&info->var, info); +fsl_diu_set_par (info);Please retest your code (at least) with sleep-inside spinlock debug option. If I see correctly you call
GFP_KERNELallocation somewhere deeper in this function, which might sleep.Quoted 4 lines
drivers/video/fsl-diu-fb.c new file +4
-0+ res =fsl_diu_enable_panel (info); +if (res <0 ) + mfbi->count--; + }drivers/video/fsl-diu-fb.c
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +9
-0+ +spin_unlock (&diu_lock); +return res; +} +static void __exit uninstall_fb(struct fb_info *info) +{ +struct mfb_info *mfbi = info->par; + +DPRINTK ("Entered: uninstall_fb\n" );You don't need this stuff everywhere (kprobes).
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+if (!mfbi->registered) +return ; + +unregister_framebuffer (info); +unmap_video_memory (info); +if (&info->cmap) +fb_dealloc_cmap (&info->cmap); + + mfbi->registered =0 ; +}[...]
Quoted 37 lines
drivers/video/fsl-diu-fb.c new file +15
-0+static int fsl_diu_probe (struct platform_device *pdev) +{ +struct mfb_info *mfbi; +unsigned long dummy_ad_addr; +int ret, i, error =0 ; + +DPRINTK ("Entered: fsl_diu_probe\n" ); + +/* Area descriptor memory pool aligns to 64-bit boundary */ +allocate_buf (&pool.ad,sizeof (struct diu_ad ) *FSL_AOI_NUM ,8 ); + +/* Get memory for Gamma Table - 32-byte aligned memory */ +allocate_buf (&pool.gamma,768 ,32 ); + +/* For performance, cursor bitmap buffer aligns to 32-byte boundary */
drivers/video/fsl-diu-fb.c new file +20
-0+allocate_buf (&pool.cursor,MAX_CURS *MAX_CURS *2 ,32 ); + + i =sizeof (fsl_diu_info) /sizeof (struct fb_info ); + dummy_ad = (struct diu_ad *)((u32 )pool.ad.vaddr + pool.ad.offset) + i; + dummy_ad->paddr = pool.ad.paddr + i *sizeof (struct diu_ad ); + dummy_aoi_virt =fsl_diu_alloc (64 , &dummy_ad_addr); + dummy_ad->addr =cpu_to_le32 (dummy_ad_addr); + dummy_ad->pix_fmt =0x88882317 ; + dummy_ad->src_size_g_alpha =cpu_to_le32 ((4 <<12 ) |4 ); + dummy_ad->aoi_size =cpu_to_le32 ((4 <<16 ) |2 ); + dummy_ad->offset_xyi =0 ; + dummy_ad->offset_xyd =0 ; + dummy_ad->next_ad =0 ; +memset (dummy_aoi_virt,0x00 ,64 ); +write_reg (&(dr.diu_reg->desc[0 ]), dummy_ad->paddr); +write_reg (&(dr.diu_reg->desc[1 ]), dummy_ad->paddr); +write_reg (&(dr.diu_reg->desc[2 ]), dummy_ad->paddr); + + for (i = 0; i < sizeof(fsl_diu_info) / sizeof(struct fb_info);i++) {
drivers/video/fsl-diu-fb.c line 1492
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+ fsl_diu_info[i].fix.smem_start =0 ; + mfbi = fsl_diu_info[i].par; + mfbi->ad = (struct diu_ad *)((u32 )pool.ad.vaddr + + pool.ad.offset) + i; + mfbi->ad->paddr = pool.ad.paddr + i *sizeof (struct diu_ad ); + ret =install_fb (&fsl_diu_info[i], pdev); +if (ret) { +printk (KERN_ERR "Failed to register framebuffer %d\n" , + i); +return ret;some kind of free here
Quoted 2 lines
(quoted diff) +2
-0+ } + }[...]
Quoted 8 lines
drivers/video/fsl-diu-fb.c new file +8
-0+int __init fsl_diu_init (void ) +{ +struct device_node *np; +struct resource r; +int error; +DPRINTK ("Entered: fsl_diu_init\n" ); + np =of_find_compatible_node (NULL ,NULL ,"fsl-diu" ); +if (!np) {drivers/video/fsl-diu-fb.c line 1577
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+printk (KERN_ERR "Err: can't find device node 'fsl-diu'\n" ); +return -ENODEV ; + } + +of_address_to_resource (np,0 , &r); +of_node_put (np); + +DPRINTK ("%s, r.start: 0x%08x\n" , __func__, r.start); + + dr.diu_reg =ioremap (r.start,sizeof (struct diu ));The arch never fails with remapping?
Quoted 17 lines
(quoted diff) +2
-0+ + write_reg(&(dr.diu_reg->diu_mode), 0); /* disable DIUanyway*/
drivers/video/fsl-diu-fb.c new file +14
-0+ +spin_lock_init (&dr.reg_lock); + + +/* +* For kernel boot options (in 'video=xxxfb:<options>' format) +*/ +#ifndef MODULE + { +char *option; + +if (fb_get_options ("fslfb" , &option)) +return -ENODEV ; +fsl_diu_setup (option);drivers/video/fsl-diu-fb.c line 1603
Quoted 10 lines
drivers/video/fsl-diu-fb.c new file +10
-0+ } +#endif + error =platform_driver_register (&fsl_diu_driver); + +if (!error) { + error =platform_device_register (&fsl_diu_device); +if (error) { +printk (KERN_ERR "Err: " +"can't register FB device driver!\n" ); +platform_driver_unregister (&fsl_diu_driver);iounmap
drivers/video/fsl-diu-fb.c line 1606
Quoted 3 lines
drivers/video/fsl-diu-fb.c new file +3
-0+ } +printk (KERN_INFO "FSL_DIU_FB: registed FB device driver!\n" ); + }else iounmap
Quoted 3 lines
drivers/video/fsl-diu-fb.c new file +3
-0+ +return error; +}[...]
Quoted 6 lines
drivers/video/fsl-diu-fb.h new file +0
-0@@ -0,0 +1,388 @@[...]
drivers/video/fsl-diu-fb.h line 25
Quoted 5 lines
drivers/video/fsl-diu-fb.h new file +5
-0+#ifndef __FSL_DIU_FB_H__ +#define __FSL_DIU_FB_H__ + +/* FIXME: This should be changed to dev_dbg this will be done as soon as +* we can obtain dev through the dts setup then use at least
pr_debug()here:Quoted 7 lines
+ */
drivers/video/fsl-diu-fb.h new file +2
-0+#ifdef DEBUG +#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__,## args)
drivers/video/fsl-diu-fb.h new file +3
-0+#else +#define DPRINTK(fmt, args...) +#endif
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 19 lines · On Fri, 11 Apr 2008 23:45:35 +0200 Jiri Slaby <[email protected]> wrote:
Quoted 17 lines · Jiri Slaby
drivers/video/fsl-diu-fb.c line 1075
Quoted 11 lines · York Sun
drivers/video/fsl-diu-fb.c new file +11
-0+static int fsl_diu_open (struct fb_info *info,int user) +{ +struct mfb_info *mfbi = info->par; +int res =0 ; + +spin_lock (&diu_lock); + mfbi->count++; +if (mfbi->count ==1 ) { +DPRINTK ("open plane index %d\n" , mfbi->index); +fsl_diu_check_var (&info->var, info); +fsl_diu_set_par (info);Please retest your code (at least) with sleep-inside spinlock debug option. If I see correctly you call
GFP_KERNELallocation somewhere deeper in this function, which might sleep.
Quoted 6 lines
...
ping.
Seeing this in -mm yet. Are those comments all wrong? Are you working on it?
(top-posting repaired)
Thanks. I've made a note that this patch has outstanding issues. Usually this means that I'll defer merging it until they have been addressed:
either by fixing them or by successfully arguing against the objections.
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 3 lines · Andrew Morton
Thanks. I've made a note that this patch has outstanding issues. Usually this means that I'll defer merging it until they have been addressed:
either by fixing them or by successfully arguing against the objections.
Sorry, I must have gotten out of sync. What are the outstanding issues? I was under the impression that the latest patch (v5) resolved everything. In fact, the last email from you (dated 4/1) said that you picked it up, minus the defconfig.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 9 lines · Timur Tabi
Quoted 3 lines · Andrew Morton
Thanks. I've made a note that this patch has outstanding issues. Usually this means that I'll defer merging it until they have been addressed:
either by fixing them or by successfully arguing against the objections.Sorry, I must have gotten out of sync. What are the outstanding issues? I was under the impression that the latest patch (v5) resolved everything. In fact, the last email from you (dated 4/1) said that you picked it up, minus the defconfig.
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 2 lines · Jiri Slaby
That email is dated 3/12 and those comments are about v1 of the patch. The most recent posted version is v5 and it addresses all these issues. See
http://lkml.org/lkml/2008/4/1/346
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 8 lines · Timur Tabi
Quoted 2 lines · Jiri Slaby
That email is dated 3/12 and those comments are about v1 of the patch. The most recent posted version is v5 and it addresses all these issues. See
http://lkml.org/lkml/2008/4/1/346
Ok, how is the sleep-inside-spinlock in fsl_diu_open resolved? rh_alloc might sleep if I still see correctly, do I?
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 11 lines · Jiri Slaby
Quoted 7 lines · Timur Tabi
Quoted 2 lines · Jiri Slaby
That email is dated 3/12 and those comments are about v1 of the patch. The most recent posted version is v5 and it addresses all these issues. See
http://lkml.org/lkml/2008/4/1/346Ok, how is the sleep-inside-spinlock in
fsl_diu_openresolved?rh_allocmight sleep if I still see correctly, do I?
Hmmm... I thought I had an answer to this question, but I checked the patch again, and it looks like this particular issue hasn't been fixed. rh_alloc can still sleep. I know we worked on fixing this bug, so I'm not sure why it's still there.
However, we don't need to call rh_alloc(). The arch/powerpc code has been updated to remove the need for us to a use an rheap.
Unfortunately, the author of the patch, York, is out this week, so I'll have to take care of this. It'd be easier to modify rh_alloc() so that it doesn't sleep, so that's what I'm going to do.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 2/2] Add DIU platform code for MPC8610HPCD
In reply to York Sunarch/powerpc/platforms/86xx/mpc8610_hpcd.c line 50
Quoted 9 lines · York Sun
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +9
-0+#include <linux/bootmem.h> +#include <asm/rheap.h> + +#undef DEBUG +#ifdef DEBUG +#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__, ## args) +#else +#define DPRINTK(fmt, args...) +#endif
Please don't define your own debug macros, but rather use pr_debug and related helpers from linux/kernel.h.
arch/powerpc/platforms/86xx/mpc8610_hpcd.c line 52
Quoted 2 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +2
-0+static unsigned char *pixis_bdcfg0, *pixis_arch; +
These need to be __iomem, as far as I can see. Please run 'make C=1' to have this kind of problem checked by 'sparse' and clean up its findings.
Quoted 10 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +6
-0@@ -161,12 +173,251 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229);DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_AL ,0x5288 , final_uli5288);#endif /* CONFIG_PCI */ +static u32 get_busfreq (void ) +{ +struct device_node *node; + +u32 fs_busfreq =0 ; + node =of_find_node_by_type (NULL ,"cpu" );
arch/powerpc/platforms/86xx/mpc8610_hpcd.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229); · line 191
Quoted 10 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +10
-0+if (node) { +unsigned int size; +const unsigned int *prop = +of_get_property (node,"bus-frequency" , &size); +if (prop) + fs_busfreq = *prop; +of_node_put (node); + }; +return fs_busfreq; +}
I guess this breaks for frequencies larger than 2^32 Ghz, right? IIRC, there is a method for encoding higher frequencies in the device tree, and you should probably support that, or even better, refer to some other function that is already interpreting it.
arch/powerpc/platforms/86xx/mpc8610_hpcd.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229); · line 198
Quoted 6 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +6
-0+#ifdef CONFIG_FB_FSL_DIU + +static rh_block_t diu_rh_block[16 ]; +static rh_info_t diu_rh_info; +static unsigned long diu_size =1280 *1024 *4 ;/* One 1280x1024 buffer */ +static void *diu_mem;
diu_mem is probably __iomem as well, right?
Also, it would be cleaner to have the variables in a data structure pointed to by your device->driver_data. It would only be strictly necessary if you expect to see a system with multiple DIU instances, which I think is unlikely, but still it is the way that people expect to see the code when they read it.
Quoted 14 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +14
-0+unsigned int platform_get_pixel_format + (unsigned int bits_per_pixel,int monitor_port) +{ +static const unsigned long pixelformat[][3 ] = { + {0x88882317 ,0x88083218 ,0x65052119 }, + {0x88883316 ,0x88082219 ,0x65053118 }, + }; +unsigned int pix_fmt, arch_monitor; + + arch_monitor = ((*pixis_arch ==0x01 ) && (monitor_port ==0 ))?0 :1 ; +/* DVI port for board version 0x01 */ + +if (bits_per_pixel ==32 ) + pix_fmt = pixelformat[arch_monitor][0 ];
arch/powerpc/platforms/86xx/mpc8610_hpcd.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229); · line 223
Quoted 10 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +10
-0+else if (bits_per_pixel ==24 ) + pix_fmt = pixelformat[arch_monitor][1 ]; +else if (bits_per_pixel ==16 ) + pix_fmt = pixelformat[arch_monitor][2 ]; +else + pix_fmt = pixelformat[1 ][0 ]; + +return pix_fmt; +} +EXPORT_SYMBOL (platform_get_pixel_format);
Generally, when you create new functions that are going to be used just by your own code, they should be EXPORT_SYMBOL_GPL. It's your choice though, as you are the author.
arch/powerpc/platforms/86xx/mpc8610_hpcd.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229); · line 254
Quoted 11 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +11
-0+void platform_set_pixel_clock (unsigned int pixclock) +{ +u32 __iomem *clkdvdr; +u32 temp; +/* variables for pixel clock calcs */ +ulong bestval, bestfreq, speed_ccb, minpixclock, maxpixclock; +ulong pixval; +long err; +int i; + + clkdvdr =ioremap (get_immrbase () +0xe0800 ,sizeof (u32));
Please don't use get_immrbase in new code. Instead, register an of_platform_driver for the device in the device tree, then use of_iomap to map its register from the driver probe() callback.
Quoted 17 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +17
-0+void *fsl_diu_alloc (unsigned long size,unsigned long *phys) +{ +void *virt; + +DPRINTK ("size=%lu\n" , size); + + virt =dma_alloc_coherent (0 , size, phys,GFP_DMA |GFP_KERNEL ); + +if (virt) { +DPRINTK ("dma virt=%p phys=%lx\n" , virt, *phys); +return virt; + } + +if (!diu_mem) { +printk (KERN_INFO "%s: no diu_mem\n" , __func__); +return NULL ; + }
arch/powerpc/platforms/86xx/mpc8610_hpcd.c DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, 0x5229, quirk_uli5229); · line 377
Quoted 10 lines
arch/powerpc/platforms/86xx/mpc8610_hpcd.c +10
-0+ + virt =rh_alloc (&diu_rh_info, size,"DIU" ); +if (virt) + *phys =virt_to_bus (virt); + +DPRINTK ("rh virt=%p phys=%x\n" , virt, *phys); + +return virt; +} +EXPORT_SYMBOL (fsl_diu_alloc);
Don't use virt_to_bus in new code, it does not work with the DMA mapping API. Instead, use dma_map_single() to convert the kernel address into something that can be addressed by hardware.
You probably don't need the dma_alloc_coherent path in that case, but always use dma_map_single on a newly allocated piece of kernel memory.
Arnd <><
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
In reply to Timur TabiQuoted 3 lines · Timur Tabi
Unfortunately, the author of the patch, York, is out this week, so I'll have to take care of this. It'd be easier to modify
rh_alloc()so that it doesn't sleep, so that's what I'm going to do.
Anyway, why do you need the spin lock there (and not mutex)? As I think you are still trying to avoid the problem instead of fixing it. Removing GFP_WAIT (fsl_diu_alloc) doesn't seem to me as mm friendly solution, especially if you allocate that much memory and you can sleep. But I might be wrong, you may need the spinlock...
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 6 lines · Jiri Slaby
Quoted 3 lines · Timur Tabi
Unfortunately, the author of the patch, York, is out this week, so I'll have to take care of this. It'd be easier to modify
rh_alloc()so that it doesn't sleep, so that's what I'm going to do.Anyway, why do you need the spin lock there (and not mutex)?
I don't know. A spinlock just seemed obvious. Why would I prefer a mutex?
We need a mutual exclusion device in order to prevent multiple threads from opening the DIU driver simultaneously. When the driver is opened the first time, it needs to initialize the hardware. The hardware can't be initialized unless we allocate a buffer first.
Now, we could pre-allocate the buffer, but then this would be a permanent 5MB (8MB if we eliminate rh_alloc) allocation of physically contiguous memory. I'm assuming that this would be a bad thing. It wouldn't eliminate the spinlock, but at least we wouldn't be calling kmalloc().
I open to suggestion for improvements. I'm still going to post the rh_alloc atomic patch, because I think it makes sense anyway. This should fix the sleep-within-spinlock problem, but it does not fix the kmalloc-5MB-in-spinlock problem.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 8 lines · Timur Tabi
Quoted 5 lines · Jiri Slaby
Quoted 3 lines · Timur Tabi
Unfortunately, the author of the patch, York, is out this week, so I'll have to take care of this. It'd be easier to modify
rh_alloc()so that it doesn't sleep, so that's what I'm going to do.Anyway, why do you need the spin lock there (and not mutex)?
I don't know. A spinlock just seemed obvious. Why would I prefer a mutex?
Mainly because you can sleep inside locked mutex and because spinlock shouldn't be used for too many lines of code (busy waiting etc.). I think ldd3 will be more descriptive than me here :).
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 3 lines · Jiri Slaby
Mainly because you can sleep inside locked mutex and because spinlock shouldn't be used for too many lines of code (busy waiting etc.). I think ldd3 will be more descriptive than me here :).
Ok, I'll look into it.
Andrew, do you want us to respin the patch, or would you be willing to let us make the change in a follow-up patch?
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Re: [PATCH 1/2] Driver for Freescale 8610 and 5121 DIU
Quoted 10 lines · On Mon, 14 Apr 2008 10:46:29 -0500 Timur Tabi <[email protected]> wrote:
Quoted 3 lines · Jiri Slaby
Mainly because you can sleep inside locked mutex and because spinlock shouldn't be used for too many lines of code (busy waiting etc.). I think ldd3 will be more descriptive than me here :).
Ok, I'll look into it.
Andrew, do you want us to respin the patch, or would you be willing to let us make the change in a follow-up patch?
A fix against rc8-mm3 would be ideal for me. But a replacement patch is OK too - I'd convert that into an incremental so I can see what changed anyway.
Others might find the replacement patch harder to review though...