Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-misc-2.6
[linux-2.6] / drivers / media / dvb / siano / smsendian.c
1 /****************************************************************
2
3  Siano Mobile Silicon, Inc.
4  MDTV receiver kernel modules.
5  Copyright (C) 2006-2009, Uri Shkolnik
6
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 2 of the License, or
10  (at your option) any later version.
11
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16
17  You should have received a copy of the GNU General Public License
18  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20  ****************************************************************/
21
22 #include <asm/byteorder.h>
23
24 #include "smsendian.h"
25 #include "smscoreapi.h"
26
27 void smsendian_handle_tx_message(void *buffer)
28 {
29 #ifdef __BIG_ENDIAN
30         struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *)buffer;
31         int i;
32         int msgWords;
33
34         switch (msg->xMsgHeader.msgType) {
35         case MSG_SMS_DATA_DOWNLOAD_REQ:
36         {
37                 msg->msgData[0] = le32_to_cpu(msg->msgData[0]);
38                 break;
39         }
40
41         default:
42                 msgWords = (msg->xMsgHeader.msgLength -
43                                 sizeof(struct SmsMsgHdr_ST))/4;
44
45                 for (i = 0; i < msgWords; i++)
46                         msg->msgData[i] = le32_to_cpu(msg->msgData[i]);
47
48                 break;
49         }
50 #endif /* __BIG_ENDIAN */
51 }
52 EXPORT_SYMBOL_GPL(smsendian_handle_tx_message);
53
54 void smsendian_handle_rx_message(void *buffer)
55 {
56 #ifdef __BIG_ENDIAN
57         struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *)buffer;
58         int i;
59         int msgWords;
60
61         switch (msg->xMsgHeader.msgType) {
62         case MSG_SMS_GET_VERSION_EX_RES:
63         {
64                 struct SmsVersionRes_ST *ver =
65                         (struct SmsVersionRes_ST *) msg;
66                 ver->ChipModel = le16_to_cpu(ver->ChipModel);
67                 break;
68         }
69
70         case MSG_SMS_DVBT_BDA_DATA:
71         case MSG_SMS_DAB_CHANNEL:
72         case MSG_SMS_DATA_MSG:
73         {
74                 break;
75         }
76
77         default:
78         {
79                 msgWords = (msg->xMsgHeader.msgLength -
80                                 sizeof(struct SmsMsgHdr_ST))/4;
81
82                 for (i = 0; i < msgWords; i++)
83                         msg->msgData[i] = le32_to_cpu(msg->msgData[i]);
84
85                 break;
86         }
87         }
88 #endif /* __BIG_ENDIAN */
89 }
90 EXPORT_SYMBOL_GPL(smsendian_handle_rx_message);
91
92 void smsendian_handle_message_header(void *msg)
93 {
94 #ifdef __BIG_ENDIAN
95         struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)msg;
96
97         phdr->msgType = le16_to_cpu(phdr->msgType);
98         phdr->msgLength = le16_to_cpu(phdr->msgLength);
99         phdr->msgFlags = le16_to_cpu(phdr->msgFlags);
100 #endif /* __BIG_ENDIAN */
101 }
102 EXPORT_SYMBOL_GPL(smsendian_handle_message_header);