From patchwork Fri Mar 1 23:12:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Schaefer X-Patchwork-Id: 17019 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1UBZ7D-0006jc-P6; Sat, 02 Mar 2013 00:11:47 +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 1UBZ7D-0006Xd-D7; Sat, 02 Mar 2013 00:11:47 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752001Ab3CAXLp (ORCPT + 1 other); Fri, 1 Mar 2013 18:11:45 -0500 Received: from mail-ee0-f48.google.com ([74.125.83.48]:47889 "EHLO mail-ee0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751836Ab3CAXLn (ORCPT ); Fri, 1 Mar 2013 18:11:43 -0500 Received: by mail-ee0-f48.google.com with SMTP id t10so2804096eei.35 for ; Fri, 01 Mar 2013 15:11:42 -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=NS12AXUWPvJ6yZ/P+MlijHdK7BdT4Dz7Xsm8h7Imj1efspdN9ZQK+/dpW7InOSNuQb H3FH7eE+yy8rpzGJc1YFRFpn38a7clP5tEdjocVp493N6+K5ZWDJUX7O+cGOS31eJNjY +vMc82reLukSBAvJm3IkpiFg5oe9TiyT8cJICcd0Nxw8alByOn3L71ChS97qSyj+jlrL 5Ul/u8/LM4jQzXmMvOpX54ieURxbuC3vixigQYcOZhAIfYyFUlJGSbTMCUNExN1d8WIh tD7K/qRYEpIZ6WYsMPqvnRWjtBUxrhEevqDO8MIS3BKQu1a71gsUZhGaNrly/5/0E35y RcsQ== X-Received: by 10.14.207.200 with SMTP id n48mr32606956eeo.4.1362179502707; Fri, 01 Mar 2013 15:11:42 -0800 (PST) Received: from Athlon64X2-5000.site (ip-178-201-83-213.unitymediagroup.de. [178.201.83.213]) by mx.google.com with ESMTPS id d47sm19488041eem.9.2013.03.01.15.11.41 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Mar 2013 15:11:42 -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 05/11] em28xx: fix eeprom data endianess Date: Sat, 2 Mar 2013 00:12:09 +0100 Message-Id: <1362179535-18929-6-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362179535-18929-1-git-send-email-fschaefer.oss@googlemail.com> References: <1362179535-18929-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.1.230018 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; };