2013-07-24 12:36:17 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2, as published by the Free Software Foundation, and
|
|
|
|
* may be copied, distributed, and modified under those terms.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2015-05-26 12:14:05 -06:00
|
|
|
#include <linux/kernel.h>
|
2013-07-24 12:36:17 -06:00
|
|
|
#include "gdm_endian.h"
|
|
|
|
|
2013-07-27 00:42:18 -06:00
|
|
|
void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian)
|
2013-07-24 12:36:17 -06:00
|
|
|
{
|
|
|
|
if (dev_endian == ENDIANNESS_BIG)
|
|
|
|
ed->dev_ed = ENDIANNESS_BIG;
|
|
|
|
else
|
|
|
|
ed->dev_ed = ENDIANNESS_LITTLE;
|
|
|
|
}
|
|
|
|
|
2017-01-05 01:22:15 -07:00
|
|
|
__dev16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
|
2013-07-24 12:36:17 -06:00
|
|
|
{
|
2015-05-26 12:14:05 -06:00
|
|
|
if (ed->dev_ed == ENDIANNESS_LITTLE)
|
2017-01-05 01:22:15 -07:00
|
|
|
return (__force __dev16)cpu_to_le16(x);
|
2015-05-26 12:14:05 -06:00
|
|
|
else
|
2017-01-05 01:22:15 -07:00
|
|
|
return (__force __dev16)cpu_to_be16(x);
|
2013-07-24 12:36:17 -06:00
|
|
|
}
|
|
|
|
|
2017-01-05 01:22:15 -07:00
|
|
|
u16 gdm_dev16_to_cpu(struct gdm_endian *ed, __dev16 x)
|
2013-07-24 12:36:17 -06:00
|
|
|
{
|
2015-05-26 12:14:05 -06:00
|
|
|
if (ed->dev_ed == ENDIANNESS_LITTLE)
|
2017-01-05 01:22:15 -07:00
|
|
|
return le16_to_cpu((__force __le16)x);
|
2015-05-26 12:14:05 -06:00
|
|
|
else
|
2017-01-05 01:22:15 -07:00
|
|
|
return be16_to_cpu((__force __be16)x);
|
2013-07-24 12:36:17 -06:00
|
|
|
}
|
|
|
|
|
2017-01-05 01:22:15 -07:00
|
|
|
__dev32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x)
|
2013-07-24 12:36:17 -06:00
|
|
|
{
|
2015-05-26 12:14:05 -06:00
|
|
|
if (ed->dev_ed == ENDIANNESS_LITTLE)
|
2017-01-05 01:22:15 -07:00
|
|
|
return (__force __dev32)cpu_to_le32(x);
|
2015-05-26 12:14:05 -06:00
|
|
|
else
|
2017-01-05 01:22:15 -07:00
|
|
|
return (__force __dev32)cpu_to_be32(x);
|
2013-07-24 12:36:17 -06:00
|
|
|
}
|
|
|
|
|
2017-01-05 01:22:15 -07:00
|
|
|
u32 gdm_dev32_to_cpu(struct gdm_endian *ed, __dev32 x)
|
2013-07-24 12:36:17 -06:00
|
|
|
{
|
2015-05-26 12:14:05 -06:00
|
|
|
if (ed->dev_ed == ENDIANNESS_LITTLE)
|
2017-01-05 01:22:15 -07:00
|
|
|
return le32_to_cpu((__force __le32)x);
|
2015-05-26 12:14:05 -06:00
|
|
|
else
|
2017-01-05 01:22:15 -07:00
|
|
|
return be32_to_cpu((__force __be32)x);
|
2013-07-24 12:36:17 -06:00
|
|
|
}
|