From patchwork Sun Jun 26 07:28:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9199189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E755560754 for ; Sun, 26 Jun 2016 07:33:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA5D82853F for ; Sun, 26 Jun 2016 07:33:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF05C28542; Sun, 26 Jun 2016 07:33:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF65928541 for ; Sun, 26 Jun 2016 07:33:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bH4VN-0001RS-7p; Sun, 26 Jun 2016 07:29:21 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bH4V5-0000vA-Po for linux-arm-kernel@lists.infradead.org; Sun, 26 Jun 2016 07:29:05 +0000 Received: by mail-pf0-x229.google.com with SMTP id h14so51895657pfe.1 for ; Sun, 26 Jun 2016 00:28:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mt/6ateycLV2JH1btLhTp1EC6bn+JhTIADFFnCCLB9Y=; b=A/7ONPFpADnk4QiprDCzJgdDMSkbWaIrY2FZMvT44JPHdFQxYdzmkc3wibAw3RazWr dTRQ02EgQ52tY2DyZ4Ev5h0z7KZNn98aVJIXLi94amvgz/94rorVaeAXFlB4HMXLifa2 /aUuiW0hDoQMS63vJkTd/n9XCQh29wmwaPJeI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mt/6ateycLV2JH1btLhTp1EC6bn+JhTIADFFnCCLB9Y=; b=IKvxDyfNJaB4rPqPXfVavOj/a8lvUmn12edRk4rUsiIJs1mE4G4Mig6n3pnem5K0gv Whx4mK4/NGnqcFfGWdoKjXXDKWYDs6rQ21v8u6wlD+EGF5V+ZTKVGsST1549l4JfL81T pFRC1G4gXA9IxZVM2RKzStB3Fayej2Gwlr0gCuJ7hEi//WxeAU5GYc9HXetV9P8l9i28 3jxO3hVKrQ3ghfkzwdvg126UXgpnl1xVMuNJvr3FrXSXFfRP+LqYY4k+2xcNaEHeC+vp jm7pNWX8BDG7AyErGNosn+c194/SMo+4TPgU1QYAysEBthSH03lOM7ZCBdeOTR7XGRUv qzcg== X-Gm-Message-State: ALyK8tJTOnZZYZ4356BYS3fVl7ytH+7GcJ+VxkgaCxexF9njkPLL/TY/FPVFTVh0gFYdGwAD X-Received: by 10.98.9.141 with SMTP id 13mr22541780pfj.130.1466926125535; Sun, 26 Jun 2016 00:28:45 -0700 (PDT) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id f138sm3790495pfa.17.2016.06.26.00.28.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Jun 2016 00:28:45 -0700 (PDT) From: Stephen Boyd To: linux-usb@vger.kernel.org Subject: [PATCH 03/21] usb: ulpi: Avoid reading/writing in device creation with OF devices Date: Sun, 26 Jun 2016 00:28:20 -0700 Message-Id: <20160626072838.28082-4-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.9.0.rc2.8.ga28705d In-Reply-To: <20160626072838.28082-1-stephen.boyd@linaro.org> References: <20160626072838.28082-1-stephen.boyd@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160626_002903_915471_DDC92F91 X-CRM114-Status: GOOD ( 18.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Felipe Balbi , Heikki Krogerus , Arnd Bergmann , Neil Armstrong , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Andersson , Greg Kroah-Hartman , Andy Gross , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP ULPI devices are matched up against ULPI drivers by reading the vendor id and product id registers in the ULPI address space. Before we try to read those registers we'll do a scratch write to test the interface. Unfortunately, this doesn't work well if the ULPI device is not powered at the time of device creation. In that case, the scratch register writes fail and product and vendor ids can't be read. If the ULPI spec had some way to describe generic power requirements for the scratch, product, and vendor registers we could but power sequencing into the ULPI bus layer and power up the device before touching the hardware. Unfortunately this doesn't exist. Furthermore, the power information is device specific, so it varies from device to device and is not standard. Let's punt on doing the reads/writes here when we're using DT backed ULPI devices. This avoids any problems where we need to power on the device but haven't figured out which device it is yet to know what sort of regulators, clks, etc. that need to be turned on for it to work. Cc: Greg Kroah-Hartman Cc: Heikki Krogerus Signed-off-by: Stephen Boyd --- drivers/usb/common/ulpi.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c index 980af672bfe3..a6b2a150b176 100644 --- a/drivers/usb/common/ulpi.c +++ b/drivers/usb/common/ulpi.c @@ -197,25 +197,7 @@ static int ulpi_of_register(struct ulpi *ulpi) static int ulpi_register(struct device *dev, struct ulpi *ulpi) { - int ret; - - /* Test the interface */ - ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); - if (ret < 0) - return ret; - - ret = ulpi_read(ulpi, ULPI_SCRATCH); - if (ret < 0) - return ret; - - if (ret != 0xaa) - return -ENODEV; - - ulpi->id.vendor = ulpi_read(ulpi, ULPI_VENDOR_ID_LOW); - ulpi->id.vendor |= ulpi_read(ulpi, ULPI_VENDOR_ID_HIGH) << 8; - - ulpi->id.product = ulpi_read(ulpi, ULPI_PRODUCT_ID_LOW); - ulpi->id.product |= ulpi_read(ulpi, ULPI_PRODUCT_ID_HIGH) << 8; + int ret = -ENODEV; ulpi->dev.parent = dev; ulpi->dev.bus = &ulpi_bus; @@ -230,6 +212,26 @@ static int ulpi_register(struct device *dev, struct ulpi *ulpi) return ret; } + if (ret) { + /* Test the interface */ + ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa); + if (ret < 0) + return ret; + + ret = ulpi_read(ulpi, ULPI_SCRATCH); + if (ret < 0) + return ret; + + if (ret != 0xaa) + return -ENODEV; + + ulpi->id.vendor = ulpi_read(ulpi, ULPI_VENDOR_ID_LOW); + ulpi->id.vendor |= ulpi_read(ulpi, ULPI_VENDOR_ID_HIGH) << 8; + + ulpi->id.product = ulpi_read(ulpi, ULPI_PRODUCT_ID_LOW); + ulpi->id.product |= ulpi_read(ulpi, ULPI_PRODUCT_ID_HIGH) << 8; + } + if (of_device_request_module(&ulpi->dev)) request_module("ulpi:v%04xp%04x", ulpi->id.vendor, ulpi->id.product);