From patchwork Fri Mar 1 23:12:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Schaefer X-Patchwork-Id: 17024 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1UBZ7O-0006mx-5Q; Sat, 02 Mar 2013 00:11:58 +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-2) with esmtp id 1UBZ7N-0006m2-Hb; Sat, 02 Mar 2013 00:11:58 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752180Ab3CAXLz (ORCPT + 1 other); Fri, 1 Mar 2013 18:11:55 -0500 Received: from mail-ea0-f177.google.com ([209.85.215.177]:51673 "EHLO mail-ea0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752153Ab3CAXLy (ORCPT ); Fri, 1 Mar 2013 18:11:54 -0500 Received: by mail-ea0-f177.google.com with SMTP id n13so407523eaa.22 for ; Fri, 01 Mar 2013 15:11:52 -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=aLCtjYJ4gock2l5losbsj9LDOwbyYoydEXjBQlmbjs0=; b=w0SGYH+qvuYyGlErzjOVWm+fLHtqPA2nrDXjnjP6AYzkSbUiD2/eupgT+7/Y4QDTst 43Ut57CJ+rPzFgF4UkPLsubq/xq1SgCcS09h9AXaxITgSfV9MUQugk7ntODJ87Sju+KI mdc4zct5Gqo37h29ulH55ExjOUOXnNY3ZugnVWMH6YSO4FOAiJDIlAlDOGlp7LPNrxs5 po3wpqhmTLUt34Wh90o195bqMCmQnIN5VoxrRvHs5HDQFscQQhizio+Ng7k9PMeToi+U BKS7pnAf/6/QqyOVVDD4gc0uU39QSg1pebzdD6Yd+NHwPoRDLao637Nn9Z8wfjba7GbH K4gQ== X-Received: by 10.14.173.196 with SMTP id v44mr32216278eel.29.1362179512527; Fri, 01 Mar 2013 15:11:52 -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.50 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Mar 2013 15:11:50 -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 10/11] em28xx: extract the device configuration dataset from eeproms with 16 bit address width Date: Sat, 2 Mar 2013 00:12:14 +0100 Message-Id: <1362179535-18929-11-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, 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 new eeproms with 16 address width still have the the device config dataset (the content of the old 8 bit eeproms) embedded. Hauppauge also continues to include the tveeprom data structure inside this dataset in their devices. The start address of the dataset depends on the start address of the microcode and a variable additional offset. It should be mentioned that camera devices seem to use a different dataset type, which is not yet supported. Tested with devices "Hauppauge HVR-930C". I've also checked the USB-log from the "MSI Digivox ATSC" and it works the same way. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-i2c.c | 117 +++++++++++++++++++++++---------- drivers/media/usb/em28xx/em28xx.h | 4 +- 2 Dateien geändert, 85 Zeilen hinzugefügt(+), 36 Zeilen entfernt(-) diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c index dfbc22e..44bef43 100644 --- a/drivers/media/usb/em28xx/em28xx-i2c.c +++ b/drivers/media/usb/em28xx/em28xx-i2c.c @@ -405,13 +405,18 @@ static int em28xx_i2c_read_block(struct em28xx *dev, u16 addr, bool addr_w16, return len; } -static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char **eedata, int len) +static int em28xx_i2c_eeprom(struct em28xx *dev, u8 **eedata, u16 *eedata_len) { - u8 buf, *data; - struct em28xx_eeprom *em_eeprom; + const u16 len = 256; + /* FIXME common length/size for bytes to read, to display, hash + * calculation and returned device dataset. Simplifies the code a lot, + * but we might have to deal with multiple sizes in the future ! */ int i, err; + struct em28xx_eeprom *dev_config; + u8 buf, *data; *eedata = NULL; + *eedata_len = 0; dev->i2c_client.addr = 0xa0 >> 1; @@ -431,8 +436,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char **eedata, int len len, data); if (err != len) { em28xx_errdev("failed to read eeprom (err=%d)\n", err); - kfree(data); - return err; + goto error; } /* Display eeprom content */ @@ -447,15 +451,25 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char **eedata, int len if (15 == (i % 16)) printk("\n"); } + if (dev->eeprom_addrwidth_16bit) + em28xx_info("i2c eeprom %04x: ... (skipped)\n", i); if (dev->eeprom_addrwidth_16bit && data[0] == 0x26 && data[3] == 0x00) { /* new eeprom format; size 4-64kb */ + u16 mc_start; + u16 hwconf_offset; + dev->hash = em28xx_hash_mem(data, len, 32); - em28xx_info("EEPROM hash = 0x%08lx\n", dev->hash); - em28xx_info("EEPROM info: boot page address = 0x%02x04, " + mc_start = (data[1] << 8) + 4; /* usually 0x0004 */ + + em28xx_info("EEPROM ID = %02x %02x %02x %02x, " + "EEPROM hash = 0x%08lx\n", + data[0], data[1], data[2], data[3], dev->hash); + em28xx_info("EEPROM info:\n"); + em28xx_info("\tmicrocode start address = 0x%04x, " "boot configuration = 0x%02x\n", - data[1], data[2]); + mc_start, data[2]); /* boot configuration (address 0x0002): * [0] microcode download speed: 1 = 400 kHz; 0 = 100 kHz * [1] always selects 12 kb RAM @@ -465,32 +479,61 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char **eedata, int len * characterization */ - /* FIXME: - * - read more than 256 bytes / addresses above 0x00ff - * - find offset for device config dataset and extract it - * - decrypt eeprom data for camera bridges (em25xx, em276x+) - * - use separate/different eeprom hashes (not yet used) + /* Read hardware config dataset offset from address + * (microcode start + 46) */ + err = em28xx_i2c_read_block(dev, mc_start + 46, 1, 2, data); + if (err != 2) { + em28xx_errdev("failed to read hardware configuration data from eeprom (err=%d)\n", + err); + goto error; + } + + /* Calculate hardware config dataset start address */ + hwconf_offset = mc_start + data[0] + (data[1] << 8); + + /* Read hardware config dataset */ + /* NOTE: the microcode copy can be multiple pages long, but + * we assume the hardware config dataset is the same as in + * the old eeprom and not longer than 256 bytes. + * tveeprom is currently also limited to 256 bytes. */ + err = em28xx_i2c_read_block(dev, hwconf_offset, 1, len, data); + if (err != len) { + em28xx_errdev("failed to read hardware configuration data from eeprom (err=%d)\n", + err); + goto error; + } - return 0; - } else if (data[0] != 0x1a || data[1] != 0xeb || - data[2] != 0x67 || data[3] != 0x95 ) { + /* Verify hardware config dataset */ + /* NOTE: not all devices provide this type of dataset */ + if (data[0] != 0x1a || data[1] != 0xeb || + data[2] != 0x67 || data[3] != 0x95 ) { + em28xx_info("no hardware configuration dataset found in eeprom\n"); + kfree(data); + return 0; + } + + /* TODO: decrypt eeprom data for camera bridges (em25xx, em276x+) */ + + } else if (!dev->eeprom_addrwidth_16bit && + data[0] == 0x1a && data[1] == 0xeb && + data[2] == 0x67 && data[3] == 0x95 ) { + dev->hash = em28xx_hash_mem(data, len, 32); + em28xx_info("EEPROM ID = %02x %02x %02x %02x, " + "EEPROM hash = 0x%08lx\n", + data[0], data[1], data[2], data[3], dev->hash); + em28xx_info("EEPROM info:\n"); + } else { em28xx_info("unknown eeprom format or eeprom corrupted !\n"); - return -ENODEV; + err = -ENODEV; + goto error; } *eedata = data; - em_eeprom = (void *)eedata; + *eedata_len = len; + dev_config = (void *)eedata; - dev->hash = em28xx_hash_mem(data, len, 32); - - 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 (le16_to_cpu(em_eeprom->chip_conf) >> 4 & 0x3) { + switch (le16_to_cpu(dev_config->chip_conf) >> 4 & 0x3) { case 0: em28xx_info("\tNo audio on board.\n"); break; @@ -505,13 +548,13 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char **eedata, int len break; } - if (le16_to_cpu(em_eeprom->chip_conf) & 1 << 3) + if (le16_to_cpu(dev_config->chip_conf) & 1 << 3) em28xx_info("\tUSB Remote wakeup capable\n"); - if (le16_to_cpu(em_eeprom->chip_conf) & 1 << 2) + if (le16_to_cpu(dev_config->chip_conf) & 1 << 2) em28xx_info("\tUSB Self power capable\n"); - switch (le16_to_cpu(em_eeprom->chip_conf) & 0x3) { + switch (le16_to_cpu(dev_config->chip_conf) & 0x3) { case 0: em28xx_info("\t500mA max power\n"); break; @@ -526,12 +569,16 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char **eedata, int len break; } em28xx_info("\tTable at offset 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n", - em_eeprom->string_idx_table, - le16_to_cpu(em_eeprom->string1), - le16_to_cpu(em_eeprom->string2), - le16_to_cpu(em_eeprom->string3)); + dev_config->string_idx_table, + le16_to_cpu(dev_config->string1), + le16_to_cpu(dev_config->string2), + le16_to_cpu(dev_config->string3)); return 0; + +error: + kfree(data); + return err; } /* ----------------------------------------------------------- */ @@ -640,7 +687,7 @@ int em28xx_i2c_register(struct em28xx *dev) dev->i2c_client = em28xx_client_template; dev->i2c_client.adapter = &dev->i2c_adap; - retval = em28xx_i2c_eeprom(dev, &dev->eedata, 256); + retval = em28xx_i2c_eeprom(dev, &dev->eedata, &dev->eedata_len); if ((retval < 0) && (retval != -ENODEV)) { em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n", __func__, retval); diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index 77f600d..2d6d31a 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -562,7 +562,9 @@ struct em28xx { /* resources in use */ unsigned int resources; - u8 *eedata; /* currently always 256 bytes */ + /* eeprom content */ + u8 *eedata; + u16 eedata_len; /* Isoc control struct */ struct em28xx_dmaqueue vidq;