]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
gpu: ipu-v3: Add rotation mode conversion utilities
authorSteve Longerbeam <slongerbeam@gmail.com>
Thu, 26 Jun 2014 01:05:37 +0000 (18:05 -0700)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Tue, 2 Sep 2014 12:55:46 +0000 (14:55 +0200)
Add two functions:

- ipu_degrees_to_rot_mode(): converts a degrees, hflip, and vflip setting
  to an IPU rotation mode.
- ipu_rot_mode_to_degrees(): converts an IPU rotation mode with given hflip
  and vflip settings to degrees.

Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
drivers/gpu/ipu-v3/ipu-common.c
include/video/imx-ipu-v3.h

index 49ee990b4d1fbd97cec55ab8c85637f4cb94c78a..a1d42eed5d060aa15da55c6aee16fe7a48cf78f8 100644 (file)
@@ -114,6 +114,70 @@ enum ipu_color_space ipu_mbus_code_to_colorspace(u32 mbus_code)
 }
 EXPORT_SYMBOL_GPL(ipu_mbus_code_to_colorspace);
 
+int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
+                           bool hflip, bool vflip)
+{
+       u32 r90, vf, hf;
+
+       switch (degrees) {
+       case 0:
+               vf = hf = r90 = 0;
+               break;
+       case 90:
+               vf = hf = 0;
+               r90 = 1;
+               break;
+       case 180:
+               vf = hf = 1;
+               r90 = 0;
+               break;
+       case 270:
+               vf = hf = r90 = 1;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       hf ^= (u32)hflip;
+       vf ^= (u32)vflip;
+
+       *mode = (enum ipu_rotate_mode)((r90 << 2) | (hf << 1) | vf);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_degrees_to_rot_mode);
+
+int ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode,
+                           bool hflip, bool vflip)
+{
+       u32 r90, vf, hf;
+
+       r90 = ((u32)mode >> 2) & 0x1;
+       hf = ((u32)mode >> 1) & 0x1;
+       vf = ((u32)mode >> 0) & 0x1;
+       hf ^= (u32)hflip;
+       vf ^= (u32)vflip;
+
+       switch ((enum ipu_rotate_mode)((r90 << 2) | (hf << 1) | vf)) {
+       case IPU_ROTATE_NONE:
+               *degrees = 0;
+               break;
+       case IPU_ROTATE_90_RIGHT:
+               *degrees = 90;
+               break;
+       case IPU_ROTATE_180:
+               *degrees = 180;
+               break;
+       case IPU_ROTATE_90_LEFT:
+               *degrees = 270;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ipu_rot_mode_to_degrees);
+
 struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned num)
 {
        struct ipuv3_channel *channel;
index 7c97ccaf39f692cb63bb60bffcd66ea32c0ec5a4..3562698528bda9d61f09e9a04c03fafb7c4bb485 100644 (file)
@@ -301,6 +301,10 @@ int ipu_smfc_set_watermark(struct ipu_smfc *smfc, u32 set_level, u32 clr_level);
 enum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc);
 enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat);
 enum ipu_color_space ipu_mbus_code_to_colorspace(u32 mbus_code);
+int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
+                           bool hflip, bool vflip);
+int ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode,
+                           bool hflip, bool vflip);
 
 struct ipu_client_platformdata {
        int csi;