2 * Copyright (C) 2009 Texas Instruments.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * common vpss system module platform driver for all video drivers.
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/spinlock.h>
26 #include <linux/compiler.h>
28 #include <mach/hardware.h>
29 #include <media/davinci/vpss.h>
31 MODULE_LICENSE("GPL");
32 MODULE_DESCRIPTION("VPSS Driver");
33 MODULE_AUTHOR("Texas Instruments");
36 #define DM644X_SBL_PCR_VPSS (4)
38 #define DM355_VPSSBL_INTSEL 0x10
39 #define DM355_VPSSBL_EVTSEL 0x14
40 /* vpss BL register offsets */
41 #define DM355_VPSSBL_CCDCMUX 0x1c
42 /* vpss CLK register offsets */
43 #define DM355_VPSSCLK_CLKCTRL 0x04
44 /* masks and shifts */
45 #define VPSS_HSSISEL_SHIFT 4
47 * VDINT0 - vpss_int0, VDINT1 - vpss_int1, H3A - vpss_int4,
48 * IPIPE_INT1_SDR - vpss_int5
50 #define DM355_VPSSBL_INTSEL_DEFAULT 0xff83ff10
51 /* VENCINT - vpss_int8 */
52 #define DM355_VPSSBL_EVTSEL_DEFAULT 0x4
54 #define DM365_ISP5_PCCR 0x04
55 #define DM365_ISP5_INTSEL1 0x10
56 #define DM365_ISP5_INTSEL2 0x14
57 #define DM365_ISP5_INTSEL3 0x18
58 #define DM365_ISP5_CCDCMUX 0x20
59 #define DM365_ISP5_PG_FRAME_SIZE 0x28
60 #define DM365_VPBE_CLK_CTRL 0x00
62 * vpss interrupts. VDINT0 - vpss_int0, VDINT1 - vpss_int1,
65 #define DM365_ISP5_INTSEL1_DEFAULT 0x0b1f0100
66 /* AEW - vpss_int6, RSZ_INT_DMA - vpss_int5 */
67 #define DM365_ISP5_INTSEL2_DEFAULT 0x1f0a0f1f
68 /* VENC - vpss_int8 */
69 #define DM365_ISP5_INTSEL3_DEFAULT 0x00000015
71 /* masks and shifts for DM365*/
72 #define DM365_CCDC_PG_VD_POL_SHIFT 0
73 #define DM365_CCDC_PG_HD_POL_SHIFT 1
75 #define CCD_SRC_SEL_MASK (BIT_MASK(5) | BIT_MASK(4))
76 #define CCD_SRC_SEL_SHIFT 4
78 /* Different SoC platforms supported by this driver */
79 enum vpss_platform_type
{
86 * vpss operations. Depends on platform. Not all functions are available
87 * on all platforms. The api, first check if a functio is available before
88 * invoking it. In the probe, the function ptrs are intialized based on
89 * vpss name. vpss name can be "dm355_vpss", "dm644x_vpss" etc.
93 int (*enable_clock
)(enum vpss_clock_sel clock_sel
, int en
);
94 /* select input to ccdc */
95 void (*select_ccdc_source
)(enum vpss_ccdc_source_sel src_sel
);
96 /* clear wbl overflow bit */
97 int (*clear_wbl_overflow
)(enum vpss_wbl_sel wbl_sel
);
100 /* vpss configuration */
101 struct vpss_oper_config
{
102 __iomem
void *vpss_regs_base0
;
103 __iomem
void *vpss_regs_base1
;
104 enum vpss_platform_type platform
;
105 spinlock_t vpss_lock
;
106 struct vpss_hw_ops hw_ops
;
109 static struct vpss_oper_config oper_cfg
;
111 /* register access routines */
112 static inline u32
bl_regr(u32 offset
)
114 return __raw_readl(oper_cfg
.vpss_regs_base0
+ offset
);
117 static inline void bl_regw(u32 val
, u32 offset
)
119 __raw_writel(val
, oper_cfg
.vpss_regs_base0
+ offset
);
122 static inline u32
vpss_regr(u32 offset
)
124 return __raw_readl(oper_cfg
.vpss_regs_base1
+ offset
);
127 static inline void vpss_regw(u32 val
, u32 offset
)
129 __raw_writel(val
, oper_cfg
.vpss_regs_base1
+ offset
);
133 static inline u32
isp5_read(u32 offset
)
135 return __raw_readl(oper_cfg
.vpss_regs_base0
+ offset
);
139 static inline void isp5_write(u32 val
, u32 offset
)
141 __raw_writel(val
, oper_cfg
.vpss_regs_base0
+ offset
);
144 static void dm365_select_ccdc_source(enum vpss_ccdc_source_sel src_sel
)
146 u32 temp
= isp5_read(DM365_ISP5_CCDCMUX
) & ~CCD_SRC_SEL_MASK
;
148 /* if we are using pattern generator, enable it */
149 if (src_sel
== VPSS_PGLPBK
|| src_sel
== VPSS_CCDCPG
)
152 temp
|= (src_sel
<< CCD_SRC_SEL_SHIFT
);
153 isp5_write(temp
, DM365_ISP5_CCDCMUX
);
156 static void dm355_select_ccdc_source(enum vpss_ccdc_source_sel src_sel
)
158 bl_regw(src_sel
<< VPSS_HSSISEL_SHIFT
, DM355_VPSSBL_CCDCMUX
);
161 int vpss_select_ccdc_source(enum vpss_ccdc_source_sel src_sel
)
163 if (!oper_cfg
.hw_ops
.select_ccdc_source
)
166 oper_cfg
.hw_ops
.select_ccdc_source(src_sel
);
169 EXPORT_SYMBOL(vpss_select_ccdc_source
);
171 static int dm644x_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel
)
175 if (wbl_sel
< VPSS_PCR_AEW_WBL_0
||
176 wbl_sel
> VPSS_PCR_CCDC_WBL_O
)
179 /* writing a 0 clear the overflow */
180 mask
= ~(mask
<< wbl_sel
);
181 val
= bl_regr(DM644X_SBL_PCR_VPSS
) & mask
;
182 bl_regw(val
, DM644X_SBL_PCR_VPSS
);
186 int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel
)
188 if (!oper_cfg
.hw_ops
.clear_wbl_overflow
)
191 return oper_cfg
.hw_ops
.clear_wbl_overflow(wbl_sel
);
193 EXPORT_SYMBOL(vpss_clear_wbl_overflow
);
196 * dm355_enable_clock - Enable VPSS Clock
197 * @clock_sel: CLock to be enabled/disabled
198 * @en: enable/disable flag
200 * This is called to enable or disable a vpss clock
202 static int dm355_enable_clock(enum vpss_clock_sel clock_sel
, int en
)
205 u32 utemp
, mask
= 0x1, shift
= 0;
208 case VPSS_VPBE_CLOCK
:
209 /* nothing since lsb */
211 case VPSS_VENC_CLOCK_SEL
:
214 case VPSS_CFALD_CLOCK
:
220 case VPSS_IPIPE_CLOCK
:
223 case VPSS_CCDC_CLOCK
:
227 printk(KERN_ERR
"dm355_enable_clock:"
228 " Invalid selector: %d\n", clock_sel
);
232 spin_lock_irqsave(&oper_cfg
.vpss_lock
, flags
);
233 utemp
= vpss_regr(DM355_VPSSCLK_CLKCTRL
);
235 utemp
&= ~(mask
<< shift
);
237 utemp
|= (mask
<< shift
);
239 vpss_regw(utemp
, DM355_VPSSCLK_CLKCTRL
);
240 spin_unlock_irqrestore(&oper_cfg
.vpss_lock
, flags
);
244 static int dm365_enable_clock(enum vpss_clock_sel clock_sel
, int en
)
247 u32 utemp
, mask
= 0x1, shift
= 0, offset
= DM365_ISP5_PCCR
;
248 u32 (*read
)(u32 offset
) = isp5_read
;
249 void(*write
)(u32 val
, u32 offset
) = isp5_write
;
254 case VPSS_CCDC_CLOCK
:
263 case VPSS_IPIPE_CLOCK
:
266 case VPSS_IPIPEIF_CLOCK
:
269 case VPSS_PCLK_INTERNAL
:
272 case VPSS_PSYNC_CLOCK_SEL
:
275 case VPSS_VPBE_CLOCK
:
278 offset
= DM365_VPBE_CLK_CTRL
;
280 case VPSS_VENC_CLOCK_SEL
:
284 offset
= DM365_VPBE_CLK_CTRL
;
290 offset
= DM365_VPBE_CLK_CTRL
;
292 case VPSS_FDIF_CLOCK
:
296 offset
= DM365_VPBE_CLK_CTRL
;
298 case VPSS_OSD_CLOCK_SEL
:
302 offset
= DM365_VPBE_CLK_CTRL
;
304 case VPSS_LDC_CLOCK_SEL
:
308 offset
= DM365_VPBE_CLK_CTRL
;
311 printk(KERN_ERR
"dm365_enable_clock: Invalid selector: %d\n",
316 spin_lock_irqsave(&oper_cfg
.vpss_lock
, flags
);
317 utemp
= read(offset
);
320 utemp
&= (mask
<< shift
);
322 utemp
|= (mask
<< shift
);
324 write(utemp
, offset
);
325 spin_unlock_irqrestore(&oper_cfg
.vpss_lock
, flags
);
330 int vpss_enable_clock(enum vpss_clock_sel clock_sel
, int en
)
332 if (!oper_cfg
.hw_ops
.enable_clock
)
335 return oper_cfg
.hw_ops
.enable_clock(clock_sel
, en
);
337 EXPORT_SYMBOL(vpss_enable_clock
);
339 void dm365_vpss_set_sync_pol(struct vpss_sync_pol sync
)
342 val
= isp5_read(DM365_ISP5_CCDCMUX
);
344 val
|= (sync
.ccdpg_hdpol
<< DM365_CCDC_PG_HD_POL_SHIFT
);
345 val
|= (sync
.ccdpg_vdpol
<< DM365_CCDC_PG_VD_POL_SHIFT
);
347 isp5_write(val
, DM365_ISP5_CCDCMUX
);
349 EXPORT_SYMBOL(dm365_vpss_set_sync_pol
);
351 void dm365_vpss_set_pg_frame_size(struct vpss_pg_frame_size frame_size
)
353 int current_reg
= ((frame_size
.hlpfr
>> 1) - 1) << 16;
355 current_reg
|= (frame_size
.pplen
- 1);
356 isp5_write(current_reg
, DM365_ISP5_PG_FRAME_SIZE
);
358 EXPORT_SYMBOL(dm365_vpss_set_pg_frame_size
);
360 static int __init
vpss_probe(struct platform_device
*pdev
)
362 struct resource
*r1
, *r2
;
366 if (!pdev
->dev
.platform_data
) {
367 dev_err(&pdev
->dev
, "no platform data\n");
371 platform_name
= pdev
->dev
.platform_data
;
372 if (!strcmp(platform_name
, "dm355_vpss"))
373 oper_cfg
.platform
= DM355
;
374 else if (!strcmp(platform_name
, "dm365_vpss"))
375 oper_cfg
.platform
= DM365
;
376 else if (!strcmp(platform_name
, "dm644x_vpss"))
377 oper_cfg
.platform
= DM644X
;
379 dev_err(&pdev
->dev
, "vpss driver not supported on"
384 dev_info(&pdev
->dev
, "%s vpss probed\n", platform_name
);
385 r1
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
389 r1
= request_mem_region(r1
->start
, resource_size(r1
), r1
->name
);
393 oper_cfg
.vpss_regs_base0
= ioremap(r1
->start
, resource_size(r1
));
394 if (!oper_cfg
.vpss_regs_base0
) {
399 if (oper_cfg
.platform
== DM355
|| oper_cfg
.platform
== DM365
) {
400 r2
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
405 r2
= request_mem_region(r2
->start
, resource_size(r2
), r2
->name
);
411 oper_cfg
.vpss_regs_base1
= ioremap(r2
->start
,
413 if (!oper_cfg
.vpss_regs_base1
) {
419 if (oper_cfg
.platform
== DM355
) {
420 oper_cfg
.hw_ops
.enable_clock
= dm355_enable_clock
;
421 oper_cfg
.hw_ops
.select_ccdc_source
= dm355_select_ccdc_source
;
422 /* Setup vpss interrupts */
423 bl_regw(DM355_VPSSBL_INTSEL_DEFAULT
, DM355_VPSSBL_INTSEL
);
424 bl_regw(DM355_VPSSBL_EVTSEL_DEFAULT
, DM355_VPSSBL_EVTSEL
);
425 } else if (oper_cfg
.platform
== DM365
) {
426 oper_cfg
.hw_ops
.enable_clock
= dm365_enable_clock
;
427 oper_cfg
.hw_ops
.select_ccdc_source
= dm365_select_ccdc_source
;
428 /* Setup vpss interrupts */
429 isp5_write(DM365_ISP5_INTSEL1_DEFAULT
, DM365_ISP5_INTSEL1
);
430 isp5_write(DM365_ISP5_INTSEL2_DEFAULT
, DM365_ISP5_INTSEL2
);
431 isp5_write(DM365_ISP5_INTSEL3_DEFAULT
, DM365_ISP5_INTSEL3
);
433 oper_cfg
.hw_ops
.clear_wbl_overflow
= dm644x_clear_wbl_overflow
;
435 spin_lock_init(&oper_cfg
.vpss_lock
);
436 dev_info(&pdev
->dev
, "%s vpss probe success\n", platform_name
);
440 release_mem_region(r2
->start
, resource_size(r2
));
442 iounmap(oper_cfg
.vpss_regs_base0
);
444 release_mem_region(r1
->start
, resource_size(r1
));
448 static int __devexit
vpss_remove(struct platform_device
*pdev
)
450 struct resource
*res
;
452 iounmap(oper_cfg
.vpss_regs_base0
);
453 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
454 release_mem_region(res
->start
, resource_size(res
));
455 if (oper_cfg
.platform
== DM355
|| oper_cfg
.platform
== DM365
) {
456 iounmap(oper_cfg
.vpss_regs_base1
);
457 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
458 release_mem_region(res
->start
, resource_size(res
));
463 static struct platform_driver vpss_driver
= {
466 .owner
= THIS_MODULE
,
468 .remove
= __devexit_p(vpss_remove
),
472 static void vpss_exit(void)
474 platform_driver_unregister(&vpss_driver
);
477 static int __init
vpss_init(void)
479 return platform_driver_register(&vpss_driver
);
481 subsys_initcall(vpss_init
);
482 module_exit(vpss_exit
);