Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
0004  * Author: Jyri Sarha <jsarha@ti.com>
0005  */
0006 
0007 #include <linux/device.h>
0008 #include <linux/kernel.h>
0009 
0010 #include "tidss_scale_coefs.h"
0011 
0012 /*
0013  * These are interpolated with a custom python script from DSS5
0014  * (drivers/gpu/drm/omapdrm/dss/dispc_coef.c) coefficients.
0015  */
0016 static const struct tidss_scale_coefs coef5_m32 = {
0017     .c2 = { 28, 34, 40, 46, 52, 58, 64, 70, 0, 2, 4, 8, 12, 16, 20, 24, },
0018     .c1 = { 132, 138, 144, 150, 156, 162, 168, 174, 76, 84, 92, 98, 104, 110, 116, 124, },
0019     .c0 = { 192, 192, 192, 190, 188, 186, 184, 182, 180, },
0020 };
0021 
0022 static const struct tidss_scale_coefs coef5_m26 = {
0023     .c2 = { 24, 28, 32, 38, 44, 50, 56, 64, 0, 2, 4, 6, 8, 12, 16, 20, },
0024     .c1 = { 132, 138, 144, 152, 160, 166, 172, 178, 72, 80, 88, 94, 100, 108, 116, 124, },
0025     .c0 = { 200, 202, 204, 202, 200, 196, 192, 188, 184, },
0026 };
0027 
0028 static const struct tidss_scale_coefs coef5_m22 = {
0029     .c2 = { 16, 20, 24, 30, 36, 42, 48, 56, 0, 0, 0, 2, 4, 8, 12, 14, },
0030     .c1 = { 132, 140, 148, 156, 164, 172, 180, 186, 64, 72, 80, 88, 96, 104, 112, 122, },
0031     .c0 = { 216, 216, 216, 214, 212, 208, 204, 198, 192, },
0032 };
0033 
0034 static const struct tidss_scale_coefs coef5_m19 = {
0035     .c2 = { 12, 14, 16, 22, 28, 34, 40, 48, 0, 0, 0, 2, 4, 4, 4, 8, },
0036     .c1 = { 128, 140, 152, 160, 168, 176, 184, 192, 56, 64, 72, 82, 92, 100, 108, 118, },
0037     .c0 = { 232, 232, 232, 226, 220, 218, 216, 208, 200, },
0038 };
0039 
0040 static const struct tidss_scale_coefs coef5_m16 = {
0041     .c2 = { 0, 2, 4, 8, 12, 18, 24, 32, 0, 0, 0, -2, -4, -4, -4, -2, },
0042     .c1 = { 124, 138, 152, 164, 176, 186, 196, 206, 40, 48, 56, 68, 80, 90, 100, 112, },
0043     .c0 = { 264, 262, 260, 254, 248, 242, 236, 226, 216, },
0044 };
0045 
0046 static const struct tidss_scale_coefs coef5_m14 = {
0047     .c2 = { -8, -6, -4, -2, 0, 6, 12, 18, 0, -2, -4, -6, -8, -8, -8, -8, },
0048     .c1 = { 120, 134, 148, 164, 180, 194, 208, 220, 24, 32, 40, 52, 64, 78, 92, 106, },
0049     .c0 = { 288, 286, 284, 280, 276, 266, 256, 244, 232, },
0050 };
0051 
0052 static const struct tidss_scale_coefs coef5_m13 = {
0053     .c2 = { -12, -12, -12, -10, -8, -4, 0, 6, 0, -2, -4, -6, -8, -10, -12, -12, },
0054     .c1 = { 112, 130, 148, 164, 180, 196, 212, 228, 12, 22, 32, 44, 56, 70, 84, 98, },
0055     .c0 = { 312, 308, 304, 298, 292, 282, 272, 258, 244, },
0056 };
0057 
0058 static const struct tidss_scale_coefs coef5_m12 = {
0059     .c2 = { -16, -18, -20, -18, -16, -14, -12, -6, 0, -2, -4, -6, -8, -10, -12, -14, },
0060     .c1 = { 104, 124, 144, 164, 184, 202, 220, 238, 0, 10, 20, 30, 40, 56, 72, 88, },
0061     .c0 = { 336, 332, 328, 320, 312, 300, 288, 272, 256, },
0062 };
0063 
0064 static const struct tidss_scale_coefs coef5_m11 = {
0065     .c2 = { -20, -22, -24, -24, -24, -24, -24, -20, 0, -2, -4, -6, -8, -10, -12, -16, },
0066     .c1 = { 92, 114, 136, 158, 180, 204, 228, 250, -16, -8, 0, 12, 24, 38, 52, 72, },
0067     .c0 = { 368, 364, 360, 350, 340, 326, 312, 292, 272, },
0068 };
0069 
0070 static const struct tidss_scale_coefs coef5_m10 = {
0071     .c2 = { -16, -20, -24, -28, -32, -34, -36, -34, 0, 0, 0, -2, -4, -8, -12, -14, },
0072     .c1 = { 72, 96, 120, 148, 176, 204, 232, 260, -32, -26, -20, -10, 0, 16, 32, 52, },
0073     .c0 = { 400, 398, 396, 384, 372, 354, 336, 312, 288, },
0074 };
0075 
0076 static const struct tidss_scale_coefs coef5_m9 = {
0077     .c2 = { -12, -18, -24, -28, -32, -38, -44, -46, 0, 2, 4, 2, 0, -2, -4, -8, },
0078     .c1 = { 40, 68, 96, 128, 160, 196, 232, 268, -48, -46, -44, -36, -28, -14, 0, 20, },
0079     .c0 = { 456, 450, 444, 428, 412, 388, 364, 334, 304, },
0080 };
0081 
0082 static const struct tidss_scale_coefs coef5_m8 = {
0083     .c2 = { 0, -4, -8, -16, -24, -32, -40, -48, 0, 2, 4, 6, 8, 6, 4, 2, },
0084     .c1 = { 0, 28, 56, 94, 132, 176, 220, 266, -56, -60, -64, -62, -60, -50, -40, -20, },
0085     .c0 = { 512, 506, 500, 478, 456, 424, 392, 352, 312, },
0086 };
0087 
0088 static const struct tidss_scale_coefs coef3_m32 = {
0089     .c1 = { 108, 92, 76, 62, 48, 36, 24, 140, 256, 236, 216, 198, 180, 162, 144, 126, },
0090     .c0 = { 296, 294, 292, 288, 284, 278, 272, 136, 256, },
0091 };
0092 
0093 static const struct tidss_scale_coefs coef3_m26 = {
0094     .c1 = { 104, 90, 76, 60, 44, 32, 20, 138, 256, 236, 216, 198, 180, 160, 140, 122, },
0095     .c0 = { 304, 300, 296, 292, 288, 282, 276, 138, 256, },
0096 };
0097 
0098 static const struct tidss_scale_coefs coef3_m22 = {
0099     .c1 = { 100, 84, 68, 54, 40, 30, 20, 138, 256, 236, 216, 196, 176, 156, 136, 118, },
0100     .c0 = { 312, 310, 308, 302, 296, 286, 276, 138, 256, },
0101 };
0102 
0103 static const struct tidss_scale_coefs coef3_m19 = {
0104     .c1 = { 96, 80, 64, 50, 36, 26, 16, 136, 256, 236, 216, 194, 172, 152, 132, 114, },
0105     .c0 = { 320, 318, 316, 310, 304, 292, 280, 140, 256, },
0106 };
0107 
0108 static const struct tidss_scale_coefs coef3_m16 = {
0109     .c1 = { 88, 72, 56, 44, 32, 22, 12, 134, 256, 234, 212, 190, 168, 148, 128, 108, },
0110     .c0 = { 336, 332, 328, 320, 312, 300, 288, 144, 256, },
0111 };
0112 
0113 static const struct tidss_scale_coefs coef3_m14 = {
0114     .c1 = { 80, 64, 48, 36, 24, 16, 8, 132, 256, 232, 208, 186, 164, 142, 120, 100, },
0115     .c0 = { 352, 348, 344, 334, 324, 310, 296, 148, 256, },
0116 };
0117 
0118 static const struct tidss_scale_coefs coef3_m13 = {
0119     .c1 = { 72, 56, 40, 30, 20, 12, 4, 130, 256, 232, 208, 184, 160, 136, 112, 92, },
0120     .c0 = { 368, 364, 360, 346, 332, 316, 300, 150, 256, },
0121 };
0122 
0123 static const struct tidss_scale_coefs coef3_m12 = {
0124     .c1 = { 64, 50, 36, 26, 16, 10, 4, 130, 256, 230, 204, 178, 152, 128, 104, 84, },
0125     .c0 = { 384, 378, 372, 358, 344, 324, 304, 152, 256, },
0126 };
0127 
0128 static const struct tidss_scale_coefs coef3_m11 = {
0129     .c1 = { 56, 40, 24, 16, 8, 4, 0, 128, 256, 228, 200, 172, 144, 120, 96, 76, },
0130     .c0 = { 400, 396, 392, 376, 360, 336, 312, 156, 256, },
0131 };
0132 
0133 static const struct tidss_scale_coefs coef3_m10 = {
0134     .c1 = { 40, 26, 12, 6, 0, -2, -4, 126, 256, 226, 196, 166, 136, 110, 84, 62, },
0135     .c0 = { 432, 424, 416, 396, 376, 348, 320, 160, 256, },
0136 };
0137 
0138 static const struct tidss_scale_coefs coef3_m9 = {
0139     .c1 = { 24, 12, 0, -4, -8, -8, -8, 124, 256, 222, 188, 154, 120, 92, 64, 44, },
0140     .c0 = { 464, 456, 448, 424, 400, 366, 332, 166, 256, },
0141 };
0142 
0143 static const struct tidss_scale_coefs coef3_m8 = {
0144     .c1 = { 0, -8, -16, -16, -16, -12, -8, 124, 256, 214, 172, 134, 96, 66, 36, 18, },
0145     .c0 = { 512, 502, 492, 462, 432, 390, 348, 174, 256, },
0146 };
0147 
0148 const struct tidss_scale_coefs *tidss_get_scale_coefs(struct device *dev,
0149                               u32 firinc,
0150                               bool five_taps)
0151 {
0152     int i;
0153     int inc;
0154     static const struct {
0155         int mmin;
0156         int mmax;
0157         const struct tidss_scale_coefs *coef3;
0158         const struct tidss_scale_coefs *coef5;
0159         const char *name;
0160     } coefs[] = {
0161         { 27, 32, &coef3_m32, &coef5_m32, "M32" },
0162         { 23, 26, &coef3_m26, &coef5_m26, "M26" },
0163         { 20, 22, &coef3_m22, &coef5_m22, "M22" },
0164         { 17, 19, &coef3_m19, &coef5_m19, "M19" },
0165         { 15, 16, &coef3_m16, &coef5_m16, "M16" },
0166         { 14, 14, &coef3_m14, &coef5_m14, "M14" },
0167         { 13, 13, &coef3_m13, &coef5_m13, "M13" },
0168         { 12, 12, &coef3_m12, &coef5_m12, "M12" },
0169         { 11, 11, &coef3_m11, &coef5_m11, "M11" },
0170         { 10, 10, &coef3_m10, &coef5_m10, "M10" },
0171         {  9,  9, &coef3_m9, &coef5_m9, "M9" },
0172         {  4,  8, &coef3_m8, &coef5_m8, "M8" },
0173         /*
0174          * When upscaling more than two times, blockiness and outlines
0175          * around the image are observed when M8 tables are used. M11,
0176          * M16 and M19 tables are used to prevent this.
0177          */
0178         {  3,  3, &coef3_m11, &coef5_m11, "M11" },
0179         {  2,  2, &coef3_m16, &coef5_m16, "M16" },
0180         {  0,  1, &coef3_m19, &coef5_m19, "M19" },
0181     };
0182 
0183     /*
0184      * inc is result of 0x200000 * in_size / out_size. This dividing
0185      * by 0x40000 scales it down to 8 * in_size / out_size. After
0186      * division the actual scaling factor is 8/inc.
0187      */
0188     inc = firinc / 0x40000;
0189     for (i = 0; i < ARRAY_SIZE(coefs); ++i) {
0190         if (inc >= coefs[i].mmin && inc <= coefs[i].mmax) {
0191             if (five_taps)
0192                 return coefs[i].coef5;
0193             else
0194                 return coefs[i].coef3;
0195         }
0196     }
0197 
0198     dev_err(dev, "%s: Coefficients not found for firinc 0x%08x, inc %d\n",
0199         __func__, firinc, inc);
0200 
0201     return NULL;
0202 }