Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp266701pxu; Wed, 7 Oct 2020 02:30:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT5Zu0ypchU9KjRf9GWa6eapxn+mt9O3YaVod67H/+tA5SZZ6oti6J55TUTGY19obbAFHg X-Received: by 2002:a17:906:cf9d:: with SMTP id um29mr2346491ejb.307.1602063051928; Wed, 07 Oct 2020 02:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602063051; cv=none; d=google.com; s=arc-20160816; b=sU0jKevC2LmAr+rtHhuzR50l00N7nL5nf7/F4fDeOMz+j1kfLkLsuOfDZMerhnUqEX kj2sPkE6+KmbWAaMQvMedTLhPOoKX5XNBg0SP+XZHZz3HjRDbK95yBYeniPABf7wNiTD ayMcYcBERUU/i5yxstvFEWDcEi1nr8L6zzvfk9GvmfgWMJcBGuCabtdGNOpxcdVG9DVn LopVe2O/cQ+s7wgnF9XHIypyC/0DXpBF89u5Zdv6cYqFIo/okzQrL5ZMG2kDx87DHr6s X/Uh0Hy1PPzekMTQ7k3APaA/BO5Nz7xUii19HhilJHVyLjh0/RRBl+fykgLAiIsSHQMJ r8nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SceNR/oD7tQAm04CP/j4aCTT/R0rZhZ+UNIW4isI3tY=; b=DpY3khZHVU9DndXfbKS8pehKoHLktuufcV5dcTYlLF0lKflCEWU9apNpOgUHoNHVSU QrlihXN9y1OwdIO5isWVLTh8oDyL9xVptB+MI7TrCyOsxp6iJtEo7kF8jV14ok7cqFld vfwJWh2qrkC9lteT9gXVkysst2/jzTwRpGnF4m0Rlk+ykamnJlUl8x6khCjykMlfyxyq Bfz/xRi4Pt5il/cUdN+PE9+VgfOqqBz/wziuquZiTMFmU3j6rFyj/RNZ4Yp38lqcZYu0 cHKJyX93com8IbO0bC/+ANAB9f4o9rQcXA3xwsbRFObfoGI5AEVDSCoYuatAG3INcpZp 71jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HxjsgaPs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si1079494ejj.113.2020.10.07.02.30.27; Wed, 07 Oct 2020 02:30:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HxjsgaPs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727277AbgJGJ3X (ORCPT + 99 others); Wed, 7 Oct 2020 05:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727235AbgJGJ3X (ORCPT ); Wed, 7 Oct 2020 05:29:23 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D88AC0613D4 for ; Wed, 7 Oct 2020 02:29:22 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id l13so1249831ljg.10 for ; Wed, 07 Oct 2020 02:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SceNR/oD7tQAm04CP/j4aCTT/R0rZhZ+UNIW4isI3tY=; b=HxjsgaPs/YW7Kb1vjNYC3Tv/LiJo53znWxtLkXB7gYYA2GnjLM/F3+1ylTvx1FCbpn geQdbezZxe75ZA7zyN/wUYDb+uhgVAFz7O5yCmW5RWh6cqHw//S+OzFaS6OoUAS1wtwJ 02LUW0BWd+ANlv1yb9KM1WcO9I8LOzlEjhbzsU3dUzmom+4HfqZSr/oMNCCvoj2+fkqI nyx2k9DPKpjglWrROYh9wr5HW9l6KMCvCaqMpawQGlQqMJ74qu3aXfIWzVkBo2XcDlmr Kk0rY5Xc5Y3XiumzzYBNVYNO5vFD7T6fjhDd/c230vfaEhrbYX6HXEM2KSpVJcqTw8vZ suiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SceNR/oD7tQAm04CP/j4aCTT/R0rZhZ+UNIW4isI3tY=; b=FkLPthSRsGqkdRVBwFpKi/qpa010mPOj+fzMVCaIDY2JXItTlLv3kih0f5uMRfjeOt uiIgBVRaAPIweZUwMDgCsUwfJzijT7SQC4J0TQCy0jE84y9DS2oN6DMFnKY/G46Vise0 BtrbJwwE8bOCP513RqmsENwmbV4Fmvrv/ZFQhgZKBbQJrEH+gRugF0qvQpjJZ9qBNaLX +H97A+koC5G9aUTdm+VehrKGSIHQ2qCBrIEh1krVo0MEMJRiTJZOkSXjKbtwSu5WaeAt xhLLbZii4q50IqtVVlcBwoP/ijgND6rqfYNS2i9a66uqJkUS527j7rWIAqgeJOLx1AsJ VsSA== X-Gm-Message-State: AOAM533Tcf73fHtgN3QIre+bPdpE+amGQF9vh4WKMHy4DIElGoeXyrf0 6MP7rsH8Wc9T8jmg8noHoxtQQ+kyPmwxWI9fx673dA== X-Received: by 2002:a2e:9b0c:: with SMTP id u12mr782404lji.338.1602062960819; Wed, 07 Oct 2020 02:29:20 -0700 (PDT) MIME-Version: 1.0 References: <20201004162908.3216898-1-martin.blumenstingl@googlemail.com> <20201004162908.3216898-4-martin.blumenstingl@googlemail.com> In-Reply-To: <20201004162908.3216898-4-martin.blumenstingl@googlemail.com> From: Linus Walleij Date: Wed, 7 Oct 2020 11:29:10 +0200 Message-ID: Subject: Re: [RFC PATCH 3/3] gpio: ej1x8: Add GPIO driver for Etron Tech Inc. EJ168/EJ188/EJ198 To: Martin Blumenstingl , linux-usb Cc: linux-pci , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "open list:GPIO SUBSYSTEM" , Rob Herring , Bartosz Golaszewski , "linux-kernel@vger.kernel.org" , Bjorn Helgaas Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Martin, thanks for your patch! As noted on the earlier patches I think this should be folded into the existing XHCI USB driver in drivers/usb/host/xhci-pci.c or, if that gets messy, as a separate bolt-on, something like xhci-pci-gpio.[c|h] in the drivers/usb/host/* directory. You can use a Kconfig symbol for the GPIO portions or not. On Sun, Oct 4, 2020 at 8:00 PM Martin Blumenstingl wrote: > EJ168/EJ188/EJ198 are USB xHCI controllers. They also contain four GPIO > lines which are used on some systems to toggle an LED based on whether a > USB device is connected. > > There is no public datasheet available for this hardware. All > information in this driver is taken from the > "F9K1115v2.03.97-GPL-10.2.85-20140313" GPL code dump of the Belkin > F9K1115v2. This board comes with an EJ168 USB xHCI controller and the > USB 3.0 LED is connected to one of the GPIOs. Inside the GPL source > archive the related code can be found in: > linux/kernels/mips-linux-2.6.31/drivers/usb/host/etxhci-pci.c > > Signed-off-by: Martin Blumenstingl (...) > +config GPIO_EJ1X8 > + tristate "Etron Tech Inc. EJ168/EJ188/EJ198 GPIO driver" > + depends on OF_GPIO && PCI It is fine to just select GPIOLIB if you want this to always be compiled-in (if the USB maintainers agree). > + help > + Selecting this option will enable the GPIO pins present on > + the Etron Tech Inc. EJ168/EJ188/EJ198 USB xHCI controllers. > + > + If unsure, say N. (...) > +#define EJ1X8_GPIO_INIT 0x44 > +#define EJ1X8_GPIO_WRITE 0x68 > +#define EJ1X8_GPIO_READ 0x6c > + > +#define EJ1X8_GPIO_CTRL 0x18005020 > +#define EJ1X8_GPIO_CTRL_READ_ALL_MASK GENMASK(7, 0) > +#define EJ1X8_GPIO_CTRL_WRITE_ALL_MASK GENMASK(23, 16) > +#define EJ1X8_GPIO_CTRL_OUT_LOW 0x0 > +#define EJ1X8_GPIO_CTRL_OUT_HIGH 0x1 > +#define EJ1X8_GPIO_CTRL_IN 0x2 > +#define EJ1X8_GPIO_CTRL_MASK 0x3 > + > +#define EJ1X8_GPIO_MODE 0x18005022 > +#define EJ1X8_GPIO_MODE_READ_WRITE_ALL_MASK GENMASK(23, 16) > +#define EJ1X8_GPIO_MODE_DISABLE 0x0 > +#define EJ1X8_GPIO_MODE_ENABLE 0x1 > +#define EJ1X8_GPIO_MODE_MASK 0x3 Nice that you got all of this out of reverse-engineering! > +static LIST_HEAD(ej1x8_gpios); This should not be necessary. Tie the GPIO state into the PCI device driver state, possibly using some #ifdefs. > +static u8 ej1x8_gpio_shift(unsigned int gpio, u8 mask) > +{ > + return (gpio * fls(mask)); > +} > + > +static u8 ej1x8_gpio_mask(unsigned int gpio, u8 mask) > +{ > + return mask << ej1x8_gpio_shift(gpio, mask); > +} This looks a bit like regmap but trying to use regmap for this would probably be overengineering. Looking at the code I get annoyed that it uses the config space to manipulate the GPIOs, else you could have used GPIO_GENERIC but now you can't, how typical. Other than that the code looks nice, but fold it into the USB host driver somehow unless there is a compelling argument as to why not. Yours, Linus Walleij