diff mbox

Siano 10234 big endian support

Message ID 107484.95792.qm@web110807.mail.gq1.yahoo.com (mailing list archive)
State Superseded
Headers show

Commit Message

Uri Shkolnik Jan. 15, 2009, 12:30 p.m. UTC
# HG changeset patch
# User Uri Shkolnik <uris@siano-ms.com>
# Date 1232021993 -7200
# Node ID 101e8cca3fad7a2f0fbc8249135bd35f5ca85b0e
# Parent  d1b03bfce9d6d68ce586d7be33a41482f1b6cec7
Add big endian support

From: Uri Shkolnik <uris@siano-ms.com>

Add big endian support

Priority: normal

Signed-off-by: Uri Shkolnik <uris@siano-ms.com>



      
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Trent Piepho Jan. 15, 2009, 5:14 p.m. UTC | #1
On Thu, 15 Jan 2009, Uri Shkolnik wrote:
> +	firmware->StartAddress = __le32_to_cpu(firmware->StartAddress);
> +	firmware->Length = __le32_to_cpu(firmware->Length);

Any reason you didn't just use le32_to_cpu()?
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff -r d1b03bfce9d6 -r 101e8cca3fad linux/drivers/media/dvb/siano/Makefile
--- a/linux/drivers/media/dvb/siano/Makefile	Thu Jan 15 13:55:21 2009 +0200
+++ b/linux/drivers/media/dvb/siano/Makefile	Thu Jan 15 14:19:53 2009 +0200
@@ -31,7 +31,7 @@  SMS_SPI_PXA310_DRV := 0
 
 
 # Default object, include in every build variant
-SMSOBJ := smscoreapi.o sms-cards.o
+SMSOBJ := smscoreapi.o sms-cards.o smsendian.o
 
 EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
 
diff -r d1b03bfce9d6 -r 101e8cca3fad linux/drivers/media/dvb/siano/smscoreapi.c
--- a/linux/drivers/media/dvb/siano/smscoreapi.c	Thu Jan 15 13:55:21 2009 +0200
+++ b/linux/drivers/media/dvb/siano/smscoreapi.c	Thu Jan 15 14:19:53 2009 +0200
@@ -29,8 +29,10 @@ 
 #include <linux/uaccess.h>
 
 #include <linux/firmware.h>
+#include <asm/byteorder.h>
 
 #include "smscoreapi.h"
+#include "smsendian.h"
 #include "sms-cards.h"
 
 #define MAX_GPIO_PIN_NUMBER	31
@@ -475,9 +477,14 @@  static int smscore_load_firmware_family2
 		void *buffer, size_t size) {
 	struct SmsFirmware_ST *firmware = (struct SmsFirmware_ST *) buffer;
 	struct SmsMsgHdr_ST *msg;
-	u32 mem_address = firmware->StartAddress;
+	u32 mem_address;
 	u8 *payload = firmware->Payload;
 	int rc = 0;
+
+	firmware->StartAddress = __le32_to_cpu(firmware->StartAddress);
+	firmware->Length = __le32_to_cpu(firmware->Length);
+
+	mem_address = firmware->StartAddress;
 
 	sms_info("loading FW to addr 0x%x size %d",
 			mem_address, firmware->Length);
@@ -496,6 +503,7 @@  static int smscore_load_firmware_family2
 		sms_debug("sending reload command.");
 		SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ,
 				sizeof(struct SmsMsgHdr_ST));
+		smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 		rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength,
 				&coredev->reload_start_done);
 		mem_address = *(u32 *) &payload[20];
@@ -513,6 +521,7 @@  static int smscore_load_firmware_family2
 		DataMsg->MemAddr = mem_address;
 		memcpy(DataMsg->Payload, payload, payload_size);
 
+		smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 		if ((coredev->device_flags & SMS_ROM_NO_RESPONSE) &&
 				(coredev->mode	== DEVICE_MODE_NONE))
 			rc = coredev->sendrequest_handler(coredev->context,
@@ -544,6 +553,7 @@  DataMsg,
 			TriggerMsg->msgData[3] = 0; /* Parameter */
 			TriggerMsg->msgData[4] = 4; /* Task ID */
 
+			smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 			if (coredev->device_flags & SMS_ROM_NO_RESPONSE) {
 				rc = coredev->sendrequest_handler(coredev->
 					context, TriggerMsg,
@@ -557,7 +567,7 @@  DataMsg,
 		} else {
 			SMS_INIT_MSG(msg, MSG_SW_RELOAD_EXEC_REQ,
 					sizeof(struct SmsMsgHdr_ST));
-
+			smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 			rc = coredev->sendrequest_handler(coredev->context, msg,
 					msg->msgLength);
 		}
@@ -706,6 +716,7 @@  static int smscore_detect_mode(struct sm
 	SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ,
 			sizeof(struct SmsMsgHdr_ST));
 
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 	rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength,
 			&coredev->version_ex_done);
 	if (rc == -ETIME) {
@@ -829,6 +840,7 @@  int smscore_set_device_mode(struct smsco
 					sizeof(struct SmsMsgData_ST));
 			msg->msgData[0] = mode;
 
+			smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
 			rc = smscore_sendrequest_and_wait(coredev, msg,
 					msg->xMsgHeader. msgLength,
 					&coredev->init_device_done);
@@ -1021,13 +1033,11 @@  void smscore_onresponse(struct smscore_d
 	data_total += cb->size;
 	/* If no client registered for type & id,
 	 * check for control client where type is not registered */
-	sms_debug("phdr->msgType = %d t size = %d", phdr->msgType, data_total);
-
 	if (client)
 		rc = client->onresponse_handler(client->context, cb);
 
 	if (rc < 0) {
-		sms_debug("rc < 0");
+		smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
 
 		switch (phdr->msgType) {
 		case MSG_SMS_GET_VERSION_EX_RES: {
@@ -1205,8 +1215,8 @@  int smscore_register_client(struct smsco
 	smscore_validate_client(coredev, newclient, params->data_type,
 			params->initial_id);
 	*client = newclient;
-	sms_debug("%p %d %d", params->context, params->data_type,
-			params->initial_id);
+	sms_debug("Register new client %p DT=%d ID=%d",
+		params->context, params->data_type, params->initial_id);
 
 	return 0;
 }
@@ -1441,6 +1451,7 @@  int smscore_gpio_configure(struct smscor
 		pMsg->msgData[5] = 0;
 	}
 
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
 	rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
 			&coredev->gpio_configuration_done);
 
@@ -1489,7 +1500,8 @@  int smscore_gpio_set_level(struct smscor
 	pMsg->msgData[0] = PinNum;
 	pMsg->msgData[1] = NewLevel;
 
-	/* Sent message to SMS */
+	/* Send message to SMS */
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
 	rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
 			&coredev->gpio_set_level_done);
 
@@ -1537,7 +1549,8 @@  int smscore_gpio_get_level(struct smscor
 	pMsg->msgData[0] = PinNum;
 	pMsg->msgData[1] = 0;
 
-	/* Sent message to SMS */
+	/* Send message to SMS */
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
 	rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
 			&coredev->gpio_get_level_done);
 
diff -r d1b03bfce9d6 -r 101e8cca3fad linux/drivers/media/dvb/siano/smsdvb.c
--- a/linux/drivers/media/dvb/siano/smsdvb.c	Thu Jan 15 13:55:21 2009 +0200
+++ b/linux/drivers/media/dvb/siano/smsdvb.c	Thu Jan 15 14:19:53 2009 +0200
@@ -21,8 +21,10 @@  along with this program.  If not, see <h
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <asm/byteorder.h>
 
 #include "smscoreapi.h"
+#include "smsendian.h"
 #include "sms-cards.h"
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
@@ -75,6 +77,8 @@  static int smsdvb_onresponse(void *conte
 	struct smsdvb_client_t *client = (struct smsdvb_client_t *)context;
 	struct SmsMsgHdr_ST *phdr =
 	    (struct SmsMsgHdr_ST *)(((u8 *) cb->p) + cb->offset);
+
+	smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
 
 	switch (phdr->msgType) {
 	case MSG_SMS_DVBT_BDA_DATA:
@@ -163,6 +167,7 @@  static int smsdvb_start_feed(struct dvb_
 	PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
 	PidMsg.msgData[0] = feed->pid;
 
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
 	return smsclient_sendrequest(client->smsclient,
 				     &PidMsg, sizeof(PidMsg));
 }
@@ -182,6 +187,7 @@  static int smsdvb_stop_feed(struct dvb_d
 	PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
 	PidMsg.msgData[0] = feed->pid;
 
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&PidMsg);
 	return smsclient_sendrequest(client->smsclient,
 				     &PidMsg, sizeof(PidMsg));
 }
@@ -190,7 +196,10 @@  static int smsdvb_sendrequest_and_wait(s
 				       void *buffer, size_t size,
 				       struct completion *completion)
 {
-	int rc = smsclient_sendrequest(client->smsclient, buffer, size);
+	int rc;
+
+	smsendian_handle_tx_message((struct SmsMsgHdr_ST *)buffer);
+	rc = smsclient_sendrequest(client->smsclient, buffer, size);
 	if (rc < 0)
 		return rc;
 
diff -r d1b03bfce9d6 -r 101e8cca3fad linux/drivers/media/dvb/siano/smsendian.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/siano/smsendian.c	Thu Jan 15 14:19:53 2009 +0200
@@ -0,0 +1,100 @@ 
+/****************************************************************
+
+ Siano Mobile Silicon, Inc.
+ MDTV receiver kernel modules.
+ Copyright (C) 2006-2009, Uri Shkolnik
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ ****************************************************************/
+
+#include <asm/byteorder.h>
+
+#include "smsendian.h"
+#include "smscoreapi.h"
+
+void smsendian_handle_tx_message(void *buffer)
+{
+#ifdef __BIG_ENDIAN
+	struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *)buffer;
+	int i;
+	int msgWords;
+
+	switch (msg->xMsgHeader.msgType) {
+	case MSG_SMS_DATA_DOWNLOAD_REQ:
+	{
+		msg->msgData[0] = __le32_to_cpu(msg->msgData[0]);
+		break;
+	}
+
+	default:
+		msgWords = (msg->xMsgHeader.msgLength -
+				sizeof(struct SmsMsgHdr_ST))/4;
+
+		for (i = 0; i < msgWords; i++)
+			msg->msgData[i] = __le32_to_cpu(msg->msgData[i]);
+
+		break;
+	}
+#endif /* __BIG_ENDIAN */
+}
+
+void smsendian_handle_rx_message(void *buffer)
+{
+#ifdef __BIG_ENDIAN
+	struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *)buffer;
+	int i;
+	int msgWords;
+
+	switch (msg->xMsgHeader.msgType) {
+	case MSG_SMS_GET_VERSION_EX_RES:
+	{
+		struct SmsVersionRes_ST *ver =
+			(struct SmsVersionRes_ST *) msg;
+		ver->ChipModel = __le16_to_cpu(ver->ChipModel);
+		break;
+	}
+
+	case MSG_SMS_DVBT_BDA_DATA:
+	case MSG_SMS_DAB_CHANNEL:
+	case MSG_SMS_DATA_MSG:
+	{
+		break;
+	}
+
+	default:
+	{
+		msgWords = (msg->xMsgHeader.msgLength -
+				sizeof(struct SmsMsgHdr_ST))/4;
+
+		for (i = 0; i < msgWords; i++)
+			msg->msgData[i] = __le32_to_cpu(msg->msgData[i]);
+
+		break;
+	}
+	}
+#endif /* __BIG_ENDIAN */
+}
+
+void smsendian_handle_message_header(void *msg)
+{
+#ifdef __BIG_ENDIAN
+	struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)msg;
+
+	phdr->msgType = __le16_to_cpu(phdr->msgType);
+	phdr->msgLength = __le16_to_cpu(phdr->msgLength);
+	phdr->msgFlags = __le16_to_cpu(phdr->msgFlags);
+#endif /* __BIG_ENDIAN */
+}
+
diff -r d1b03bfce9d6 -r 101e8cca3fad linux/drivers/media/dvb/siano/smsendian.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/linux/drivers/media/dvb/siano/smsendian.h	Thu Jan 15 14:19:53 2009 +0200
@@ -0,0 +1,32 @@ 
+/****************************************************************
+
+Siano Mobile Silicon, Inc.
+MDTV receiver kernel modules.
+Copyright (C) 2006-2009, Uri Shkolnik
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+ 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.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+****************************************************************/
+
+#ifndef __SMS_ENDIAN_H__
+#define __SMS_ENDIAN_H__
+
+#include <asm/byteorder.h>
+
+void smsendian_handle_tx_message(void *buffer);
+void smsendian_handle_rx_message(void *buffer);
+void smsendian_handle_message_header(void *msg);
+
+#endif /* __SMS_ENDIAN_H__ */
+
diff -r d1b03bfce9d6 -r 101e8cca3fad linux/drivers/media/dvb/siano/smsusb.c
--- a/linux/drivers/media/dvb/siano/smsusb.c	Thu Jan 15 13:55:21 2009 +0200
+++ b/linux/drivers/media/dvb/siano/smsusb.c	Thu Jan 15 14:19:53 2009 +0200
@@ -23,9 +23,11 @@  along with this program.  If not, see <h
 #include <linux/init.h>
 #include <linux/usb.h>
 #include <linux/firmware.h>
+#include <asm/byteorder.h>
 
 #include "smscoreapi.h"
 #include "sms-cards.h"
+#include "smsendian.h"
 
 #define USB1_BUFFER_SIZE		0x1000
 #define USB2_BUFFER_SIZE		0x4000
@@ -73,6 +75,7 @@  static void smsusb_onresponse(struct urb
 	if (urb->actual_length > 0) {
 		struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)surb->cb->p;
 
+		smsendian_handle_message_header(phdr);
 		if (urb->actual_length >= phdr->msgLength) {
 			surb->cb->size = phdr->msgLength;
 
@@ -172,6 +175,7 @@  static int smsusb_sendrequest(void *cont
 	struct smsusb_device_t *dev = (struct smsusb_device_t *)context;
 	int dummy;
 
+	smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer);
 	return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
 			    buffer, size, &dummy, 1000);
 }
@@ -330,7 +334,7 @@  static int smsusb_init_device(struct usb
 	case SMS_VEGA:
 		dev->buffer_size = USB2_BUFFER_SIZE;
 		dev->response_alignment =
-		    dev->udev->ep_in[1]->desc.wMaxPacketSize -
+		    __le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) -
 		    sizeof(struct SmsMsgHdr_ST);
 
 		params.flags |= SMS_DEVICE_FAMILY2;