video: tegra: dc: Enable cursor window clipping
Prashant Malani [Thu, 7 Jun 2012 20:34:12 +0000 (13:34 -0700)]
Add a new ioctl to enable cursor clipping.
Modify set_cursor_image_hw() to preserve cursor
clipping status.

Change-Id: I4af4c342fc008203c4d8148609587618e333c71f
Signed-off-by: Prashant Malani <pmalani@nvidia.com>
Reviewed-on: http://git-master/r/131270
Reviewed-by: Rohan Somvanshi <rsomvanshi@nvidia.com>
Tested-by: Rohan Somvanshi <rsomvanshi@nvidia.com>

Rebase-Id: R44f6792eaf1ae5abdebac1786ff4051c349f1d32

drivers/video/tegra/dc/dc_priv.h
drivers/video/tegra/dc/ext/cursor.c
drivers/video/tegra/dc/ext/dev.c
drivers/video/tegra/dc/ext/tegra_dc_ext_priv.h
include/video/tegra_dc_ext.h

index 78da706..242615f 100644 (file)
 /* DDR: 8 bytes transfer per clock */
 #define DDR_BW_TO_FREQ(bw) ((bw) / 8)
 
+/* 29 bit offset for window clip number */
+#define CURSOR_CLIP_SHIFT_BITS(win)    (win << 29)
+#define CURSOR_CLIP_GET_WINDOW(reg)    ((reg >> 29) & 3)
+
 #if defined(CONFIG_TEGRA_EMC_TO_DDR_CLOCK)
 #define EMC_BW_TO_FREQ(bw) (DDR_BW_TO_FREQ(bw) * CONFIG_TEGRA_EMC_TO_DDR_CLOCK)
 #else
index 970f38f..6320c56 100644 (file)
@@ -62,6 +62,8 @@ static void set_cursor_image_hw(struct tegra_dc *dc,
                                struct tegra_dc_ext_cursor_image *args,
                                dma_addr_t phys_addr)
 {
+       int clip_win;
+
        tegra_dc_writel(dc,
                CURSOR_COLOR(args->foreground.r,
                             args->foreground.g,
@@ -75,7 +77,11 @@ static void set_cursor_image_hw(struct tegra_dc *dc,
 
        BUG_ON(phys_addr & ~CURSOR_START_ADDR_MASK);
 
-       tegra_dc_writel(dc,
+       /* Get the cursor clip window number */
+       clip_win = CURSOR_CLIP_GET_WINDOW(tegra_dc_readl(dc,
+                                         DC_DISP_CURSOR_START_ADDR));
+
+       tegra_dc_writel(dc, CURSOR_CLIP_SHIFT_BITS(clip_win) |
                CURSOR_START_ADDR(((unsigned long) phys_addr)) |
                ((args->flags & TEGRA_DC_EXT_CURSOR_IMAGE_FLAGS_SIZE_64x64) ?
                        CURSOR_SIZE_64 : 0),
@@ -201,3 +207,42 @@ unlock:
 
        return ret;
 }
+
+int tegra_dc_ext_cursor_clip(struct tegra_dc_ext_user *user,
+                           int *args)
+{
+       struct tegra_dc_ext *ext = user->ext;
+       struct tegra_dc *dc = ext->dc;
+       int ret;
+       unsigned long reg_val;
+
+       mutex_lock(&ext->cursor.lock);
+
+       if (ext->cursor.user != user) {
+               ret = -EACCES;
+               goto unlock;
+       }
+
+       if (!ext->enabled) {
+               ret = -ENXIO;
+               goto unlock;
+       }
+
+       mutex_lock(&dc->lock);
+
+       reg_val = tegra_dc_readl(dc, DC_DISP_CURSOR_START_ADDR);
+       reg_val &= ~CURSOR_CLIP_SHIFT_BITS(3); /* Clear out the old value */
+       tegra_dc_writel(dc, reg_val | CURSOR_CLIP_SHIFT_BITS(*args),
+                       DC_DISP_CURSOR_START_ADDR);
+
+       mutex_unlock(&dc->lock);
+
+       mutex_unlock(&ext->cursor.lock);
+
+       return 0;
+
+unlock:
+       mutex_unlock(&ext->cursor.lock);
+
+       return ret;
+}
index 436d924..2302372 100644 (file)
@@ -937,6 +937,15 @@ static long tegra_dc_ioctl(struct file *filp, unsigned int cmd,
                return ret;
        }
 
+       case TEGRA_DC_EXT_CURSOR_CLIP:
+       {
+               int args;
+               if (copy_from_user(&args, user_arg, sizeof(args)))
+                       return -EFAULT;
+
+               return tegra_dc_ext_cursor_clip(user, &args);
+       }
+
        default:
                return -EINVAL;
        }
index ef7361d..459181e 100644 (file)
@@ -137,6 +137,8 @@ extern int tegra_dc_ext_set_cursor_image(struct tegra_dc_ext_user *user,
                                         struct tegra_dc_ext_cursor_image *);
 extern int tegra_dc_ext_set_cursor(struct tegra_dc_ext_user *user,
                                   struct tegra_dc_ext_cursor *);
+extern int tegra_dc_ext_cursor_clip(struct tegra_dc_ext_user *user,
+                                       int *args);
 
 extern int tegra_dc_ext_control_init(void);
 
index 86511e8..5165cf5 100644 (file)
@@ -256,6 +256,9 @@ struct tegra_dc_ext_feature {
 #define TEGRA_DC_EXT_GET_FEATURES \
        _IOW('D', 0x0B, struct tegra_dc_ext_feature)
 
+#define TEGRA_DC_EXT_CURSOR_CLIP \
+       _IOW('D', 0x0C, __s32)
+
 enum tegra_dc_ext_control_output_type {
        TEGRA_DC_EXT_DSI,
        TEGRA_DC_EXT_LVDS,