From patchwork Sun Mar 3 19:37:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Schaefer X-Patchwork-Id: 17074 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1UCEj6-0003Cj-Du; Sun, 03 Mar 2013 20:37:40 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-3) with esmtp id 1UCEj5-000555-FD; Sun, 03 Mar 2013 20:37:40 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754066Ab3CCThg (ORCPT + 1 other); Sun, 3 Mar 2013 14:37:36 -0500 Received: from mail-ee0-f51.google.com ([74.125.83.51]:36587 "EHLO mail-ee0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753336Ab3CCThJ (ORCPT ); Sun, 3 Mar 2013 14:37:09 -0500 Received: by mail-ee0-f51.google.com with SMTP id d17so3369880eek.10 for ; Sun, 03 Mar 2013 11:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=DMov/p7en+3BK/YVWWneOoFy7eVDRxRXyjjvR4JoNhs=; b=Spt0Rz4yVpAv3SN7h5IJTfHH1i9TCElrOc5zuG8YUwxsi1qOf6ZP7zYPmOqLM8yZYd 5raB9CVis2OLhlqO7h4fr4cV7ZE2BVRqjmHZQbZhNWJozfhtSW50Mo04h4ZVWsj5zSea okjxWP8rQkFNoCZiXU2ZxfefWlWfP49OMD7DBpXdjG2aOyPAEd9kkfBDU28hRTw3n4z+ S6upInFDUn1bgyAgKQsNra06GgWN+wgLPkt3BTdesdYXEZOXRAfJFGjzPgtuu17RTK77 z2h8coSUwwwRyV7C7Uq2TENUkalV0fFIQcQptna4dwLYiG6Cm+BGTKNfRxvyR0R+5I5W 7KrA== X-Received: by 10.15.100.202 with SMTP id bn50mr50757084eeb.36.1362339428219; Sun, 03 Mar 2013 11:37:08 -0800 (PST) Received: from Athlon64X2-5000.site (ip-88-153-204-20.unitymediagroup.de. [88.153.204.20]) by mx.google.com with ESMTPS id d47sm28321257eem.9.2013.03.03.11.37.07 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 Mar 2013 11:37:07 -0800 (PST) From: =?UTF-8?q?Frank=20Sch=C3=A4fer?= To: mchehab@redhat.com Cc: linux-media@vger.kernel.org, =?UTF-8?q?Frank=20Sch=C3=A4fer?= Subject: [PATCH v2 05/11] em28xx: fix eeprom data endianess Date: Sun, 3 Mar 2013 20:37:38 +0100 Message-Id: <1362339464-3373-6-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362339464-3373-1-git-send-email-fschaefer.oss@googlemail.com> References: <1362339464-3373-1-git-send-email-fschaefer.oss@googlemail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2013.3.3.192715 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, CT_TEXT_PLAIN_UTF8_CAPS 0, DKIM_SIGNATURE 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __FRAUD_BODY_WEBMAIL 0, __FRAUD_WEBMAIL 0, __FRAUD_WEBMAIL_FROM 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __PHISH_SPEAR_STRUCTURE_1 0, __SANE_MSGID 0, __STOCK_PHRASE_7 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' The data is stored as little endian in the eeprom. Hence the correct data types should be used and the data should be converted to the machine endianess before using it. The eeprom id (key) also isn't a 32 bit value but 4 separate bytes instead. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-i2c.c | 22 ++++++++++++---------- drivers/media/usb/em28xx/em28xx.h | 12 ++++++------ 2 Dateien geändert, 18 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-) diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c index 9612086..19f3e4f 100644 --- a/drivers/media/usb/em28xx/em28xx-i2c.c +++ b/drivers/media/usb/em28xx/em28xx-i2c.c @@ -434,19 +434,21 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) printk("\n"); } - if (em_eeprom->id != 0x9567eb1a) { + if (em_eeprom->id[0] != 0x1a || em_eeprom->id[1] != 0xeb || + em_eeprom->id[2] != 0x67 || em_eeprom->id[3] != 0x95 ) { em28xx_errdev("Unknown eeprom type or eeprom corrupted !"); return -ENODEV; } dev->hash = em28xx_hash_mem(eedata, len, 32); - em28xx_info("EEPROM ID = 0x%08x, EEPROM hash = 0x%08lx\n", - em_eeprom->id, dev->hash); + em28xx_info("EEPROM ID = %02x %02x %02x %02x, EEPROM hash = 0x%08lx\n", + em_eeprom->id[0], em_eeprom->id[1], + em_eeprom->id[2], em_eeprom->id[3], dev->hash); em28xx_info("EEPROM info:\n"); - switch (em_eeprom->chip_conf >> 4 & 0x3) { + switch (le16_to_cpu(em_eeprom->chip_conf) >> 4 & 0x3) { case 0: em28xx_info("\tNo audio on board.\n"); break; @@ -461,13 +463,13 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) break; } - if (em_eeprom->chip_conf & 1 << 3) + if (le16_to_cpu(em_eeprom->chip_conf) & 1 << 3) em28xx_info("\tUSB Remote wakeup capable\n"); - if (em_eeprom->chip_conf & 1 << 2) + if (le16_to_cpu(em_eeprom->chip_conf) & 1 << 2) em28xx_info("\tUSB Self power capable\n"); - switch (em_eeprom->chip_conf & 0x3) { + switch (le16_to_cpu(em_eeprom->chip_conf) & 0x3) { case 0: em28xx_info("\t500mA max power\n"); break; @@ -483,9 +485,9 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len) } em28xx_info("\tTable at offset 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n", em_eeprom->string_idx_table, - em_eeprom->string1, - em_eeprom->string2, - em_eeprom->string3); + le16_to_cpu(em_eeprom->string1), + le16_to_cpu(em_eeprom->string2), + le16_to_cpu(em_eeprom->string3)); return 0; } diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index 4160a2a..90266a1 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -405,15 +405,15 @@ struct em28xx_board { }; struct em28xx_eeprom { - u32 id; /* 0x9567eb1a */ - u16 vendor_ID; - u16 product_ID; + u8 id[4]; /* 1a eb 67 95 */ + __le16 vendor_ID; + __le16 product_ID; - u16 chip_conf; + __le16 chip_conf; - u16 board_conf; + __le16 board_conf; - u16 string1, string2, string3; + __le16 string1, string2, string3; u8 string_idx_table; };