gdm_endian.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <linux/kernel.h>
  14. #include "gdm_endian.h"
  15. void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian)
  16. {
  17. if (dev_endian == ENDIANNESS_BIG)
  18. ed->dev_ed = ENDIANNESS_BIG;
  19. else
  20. ed->dev_ed = ENDIANNESS_LITTLE;
  21. }
  22. u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
  23. {
  24. if (ed->dev_ed == ENDIANNESS_LITTLE)
  25. return cpu_to_le16(x);
  26. else
  27. return cpu_to_be16(x);
  28. }
  29. u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x)
  30. {
  31. if (ed->dev_ed == ENDIANNESS_LITTLE)
  32. return le16_to_cpu(x);
  33. else
  34. return be16_to_cpu(x);
  35. }
  36. u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x)
  37. {
  38. if (ed->dev_ed == ENDIANNESS_LITTLE)
  39. return cpu_to_le32(x);
  40. else
  41. return cpu_to_be32(x);
  42. }
  43. u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x)
  44. {
  45. if (ed->dev_ed == ENDIANNESS_LITTLE)
  46. return le32_to_cpu(x);
  47. else
  48. return be32_to_cpu(x);
  49. }