Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved. |
| 3 | * |
| 4 | * This software is licensed under the terms of the GNU General Public |
| 5 | * License version 2, as published by the Free Software Foundation, and |
| 6 | * may be copied, distributed, and modified under those terms. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Jaime Arrocha | 77e8a50 | 2015-05-26 13:14:05 -0500 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 15 | #include "gdm_endian.h" |
| 16 | |
Won Kang | 9c02d0d | 2013-07-27 15:42:18 +0900 | [diff] [blame] | 17 | void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian) |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 18 | { |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 19 | if (dev_endian == ENDIANNESS_BIG) |
| 20 | ed->dev_ed = ENDIANNESS_BIG; |
| 21 | else |
| 22 | ed->dev_ed = ENDIANNESS_LITTLE; |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x) |
| 26 | { |
Jaime Arrocha | 77e8a50 | 2015-05-26 13:14:05 -0500 | [diff] [blame] | 27 | if (ed->dev_ed == ENDIANNESS_LITTLE) |
| 28 | return cpu_to_le16(x); |
| 29 | else |
| 30 | return cpu_to_be16(x); |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x) |
| 34 | { |
Jaime Arrocha | 77e8a50 | 2015-05-26 13:14:05 -0500 | [diff] [blame] | 35 | if (ed->dev_ed == ENDIANNESS_LITTLE) |
| 36 | return le16_to_cpu(x); |
| 37 | else |
| 38 | return be16_to_cpu(x); |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x) |
| 42 | { |
Jaime Arrocha | 77e8a50 | 2015-05-26 13:14:05 -0500 | [diff] [blame] | 43 | if (ed->dev_ed == ENDIANNESS_LITTLE) |
| 44 | return cpu_to_le32(x); |
| 45 | else |
| 46 | return cpu_to_be32(x); |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x) |
| 50 | { |
Jaime Arrocha | 77e8a50 | 2015-05-26 13:14:05 -0500 | [diff] [blame] | 51 | if (ed->dev_ed == ENDIANNESS_LITTLE) |
| 52 | return le32_to_cpu(x); |
| 53 | else |
| 54 | return be32_to_cpu(x); |
Won Kang | 61e1210 | 2013-07-25 03:36:17 +0900 | [diff] [blame] | 55 | } |