Googler | 9398cc3 | 2022-12-02 17:21:52 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| 2 | /* |
| 3 | * Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <linux/types.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/fs.h> |
| 11 | #include <linux/device.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/stat.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/ctype.h> |
| 19 | #include <linux/vmalloc.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/amlogic/media/registers/register_map.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/workqueue.h> |
| 24 | |
| 25 | #include "frc_drv.h" |
| 26 | |
| 27 | void __iomem *frc_base; |
| 28 | |
| 29 | //#define FRC_DISABLE_REG_RD_WR |
| 30 | |
| 31 | void WRITE_FRC_REG(unsigned int reg, unsigned int val) |
| 32 | { |
| 33 | #ifndef FRC_DISABLE_REG_RD_WR |
| 34 | if (get_frc_devp()->power_on_flag == 0) |
| 35 | return; |
| 36 | writel(val, (frc_base + (reg << 2))); |
| 37 | #endif |
| 38 | } |
| 39 | EXPORT_SYMBOL(WRITE_FRC_REG); |
| 40 | |
| 41 | |
| 42 | void WRITE_FRC_BITS(unsigned int reg, unsigned int value, |
| 43 | unsigned int start, unsigned int len) |
| 44 | { |
| 45 | #ifndef FRC_DISABLE_REG_RD_WR |
| 46 | unsigned int tmp, orig; |
| 47 | unsigned int mask = (((1L << len) - 1) << start); |
| 48 | int r = (reg << 2); |
| 49 | if (get_frc_devp()->power_on_flag == 0) |
| 50 | return; |
| 51 | orig = readl((frc_base + r)); |
| 52 | tmp = orig & ~mask; |
| 53 | tmp |= (value << start) & mask; |
| 54 | writel(tmp, (frc_base + r)); |
| 55 | #endif |
| 56 | } |
| 57 | EXPORT_SYMBOL(WRITE_FRC_BITS); |
| 58 | |
| 59 | |
| 60 | void UPDATE_FRC_REG_BITS(unsigned int reg, |
| 61 | unsigned int value, |
| 62 | unsigned int mask) |
| 63 | { |
| 64 | #ifndef FRC_DISABLE_REG_RD_WR |
| 65 | unsigned int val; |
| 66 | |
| 67 | if (get_frc_devp()->power_on_flag == 0) |
| 68 | return; |
| 69 | value &= mask; |
| 70 | val = readl(frc_base + (reg << 2)); |
| 71 | val &= ~mask; |
| 72 | val |= value; |
| 73 | writel(val, (frc_base + (reg << 2))); |
| 74 | #endif |
| 75 | } |
| 76 | EXPORT_SYMBOL(UPDATE_FRC_REG_BITS); |
| 77 | |
| 78 | |
| 79 | int READ_FRC_REG(unsigned int reg) |
| 80 | { |
| 81 | #ifndef FRC_DISABLE_REG_RD_WR |
| 82 | if (get_frc_devp()->power_on_flag == 0) |
| 83 | return 0; |
| 84 | return readl(frc_base + (reg << 2)); |
| 85 | #else |
| 86 | return 0; |
| 87 | #endif |
| 88 | } |
| 89 | EXPORT_SYMBOL(READ_FRC_REG); |
| 90 | |
| 91 | u32 READ_FRC_BITS(u32 reg, const u32 start, const u32 len) |
| 92 | { |
| 93 | u32 val = 0; |
| 94 | |
| 95 | #ifndef FRC_DISABLE_REG_RD_WR |
| 96 | if (get_frc_devp()->power_on_flag == 0) |
| 97 | return 0; |
| 98 | val = ((READ_FRC_REG(reg) >> (start)) & ((1L << (len)) - 1)); |
| 99 | #endif |
| 100 | return val; |
| 101 | } |
| 102 | EXPORT_SYMBOL(READ_FRC_BITS); |
| 103 | |
| 104 | u32 floor_rs(u32 ix, u32 rs) |
| 105 | { |
| 106 | u32 rst = 0; |
| 107 | |
| 108 | rst = (ix) >> rs; |
| 109 | |
| 110 | return rst; |
| 111 | } |
| 112 | EXPORT_SYMBOL(floor_rs); |
| 113 | |
| 114 | u32 ceil_rx(u32 ix, u32 rs) |
| 115 | { |
| 116 | u32 rst = 0; |
| 117 | u32 tmp = 0; |
| 118 | |
| 119 | tmp = 1 << rs; |
| 120 | rst = (ix + tmp - 1) >> rs; |
| 121 | |
| 122 | return rst; |
| 123 | } |
| 124 | EXPORT_SYMBOL(ceil_rx); |
| 125 | |
| 126 | s32 negative_convert(s32 data, u32 fbits) |
| 127 | { |
| 128 | s32 rst = 0; |
| 129 | s64 sign_base = (s64)1 << (fbits - 1); |
| 130 | |
| 131 | if ((data & sign_base) == sign_base) |
| 132 | rst = -((sign_base << 1) - data); |
| 133 | else |
| 134 | rst = data; |
| 135 | |
| 136 | return rst; |
| 137 | } |
| 138 | EXPORT_SYMBOL(negative_convert); |
| 139 | |