2 * Copyright (C) Jernej Skrabec <jernej.skrabec@siol.net>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
12 #include "sun8i_csc.h"
13 #include "sun8i_mixer.h"
15 static const u32 ccsc_base
[2][2] = {
16 {CCSC00_OFFSET
, CCSC01_OFFSET
},
17 {CCSC10_OFFSET
, CCSC11_OFFSET
},
21 * Factors are in two's complement format, 10 bits for fractinal part.
22 * First tree values in each line are multiplication factor and last
23 * value is constant, which is added at the end.
25 static const u32 yuv2rgb
[] = {
26 0x000004A8, 0x00000000, 0x00000662, 0xFFFC845A,
27 0x000004A8, 0xFFFFFE6F, 0xFFFFFCBF, 0x00021DF4,
28 0x000004A8, 0x00000813, 0x00000000, 0xFFFBAC4A,
31 static const u32 yvu2rgb
[] = {
32 0x000004A8, 0x00000662, 0x00000000, 0xFFFC845A,
33 0x000004A8, 0xFFFFFCBF, 0xFFFFFE6F, 0x00021DF4,
34 0x000004A8, 0x00000000, 0x00000813, 0xFFFBAC4A,
37 static void sun8i_csc_set_coefficients(struct regmap
*map
, u32 base
,
38 enum sun8i_csc_mode mode
)
44 case SUN8I_CSC_MODE_YUV2RGB
:
47 case SUN8I_CSC_MODE_YVU2RGB
:
51 DRM_WARN("Wrong CSC mode specified.\n");
55 for (i
= 0; i
< 12; i
++) {
57 /* For some reason, 0x200 must be added to constant parts */
58 if (((i
+ 1) & 3) == 0)
60 regmap_write(map
, SUN8I_CSC_COEFF(base
, i
), data
);
64 static void sun8i_csc_enable(struct regmap
*map
, u32 base
, bool enable
)
69 val
= SUN8I_CSC_CTRL_EN
;
73 regmap_update_bits(map
, SUN8I_CSC_CTRL(base
), SUN8I_CSC_CTRL_EN
, val
);
76 void sun8i_csc_set_ccsc_coefficients(struct sun8i_mixer
*mixer
, int layer
,
77 enum sun8i_csc_mode mode
)
81 base
= ccsc_base
[mixer
->cfg
->ccsc
][layer
];
83 sun8i_csc_set_coefficients(mixer
->engine
.regs
, base
, mode
);
86 void sun8i_csc_enable_ccsc(struct sun8i_mixer
*mixer
, int layer
, bool enable
)
90 base
= ccsc_base
[mixer
->cfg
->ccsc
][layer
];
92 sun8i_csc_enable(mixer
->engine
.regs
, base
, enable
);