Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp477940pxb; Thu, 14 Jan 2021 10:22:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJz34UUVrbDBuPR8qLU16LhQvm2FqS7zkmelhqm10kXG59/JCLETzN25IbD3JyWbGYe7p7tQ X-Received: by 2002:a17:906:3283:: with SMTP id 3mr1201441ejw.243.1610648547271; Thu, 14 Jan 2021 10:22:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610648547; cv=none; d=google.com; s=arc-20160816; b=NcljSm4iDeSotSV1GUxxSeKwA56JyMc7AXQg/stVCojdonH0PMhly1B24NqpV4E/ye 7W1aNLnxy1oByOHL8INeH22+q9XHpsXQ8xpKy73XPS1w7XQ1Rx5dO4++XaBhRVEgGfC0 b/05YfZva89xOjAQA7GO3n9NFFXHT7oVspPaxw1R+XGjk+g+5IVZwmlRdzbLqBDV1xvk 7k/Itl480QRsCalktPEcSViPwrEUCMkGI49BW2VSJmev2frABoX/IaTsbinTOhLNjFYv LOlGWoGLl8Du+utled28AccOqzFV6Pvc6rnaZtkjvOrU84w5/fAsuZIq5YZgZiq1MmH4 bYDg== 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=pJvCZAHLaqoKEh3y+oXgKjwlwnBYnY7borzTim+qS1o=; b=hKapxEFOEFXcm7JVKsbjDXahq4vdIiUZ0eJI/Z4eXOQvLjvGHTeKlD+uo/b2ECrHy/ TUCq8+oAk8rFz4ynyb+FMl3AP2sITYg+nza2MKIta3sA7NNY0OtCECvs22SHEArlKLAY OfNKhT1wg9XK1d1g/kD4GadMvraVaaNjHzZCFcd0P2bgpZS7m13cH8RgdDj+4Gkre+7G PYdFYuJKRqEyKAZO3D6YJbOps9euklOUzmPz0KRVxqo+w4S6hPdPg09fZ8CZR10iYXwL 1yaK/CWAdYiLbSgv6eabTuhGLgmJFtgo8uGkUbAbT0Rq36d+hxYxW6owEvA+8y7vSeuZ VoAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cS4njNwz; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si2624773ejj.266.2021.01.14.10.22.03; Thu, 14 Jan 2021 10:22:27 -0800 (PST) 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=@chromium.org header.s=google header.b=cS4njNwz; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727801AbhANSUW (ORCPT + 99 others); Thu, 14 Jan 2021 13:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729848AbhANSUK (ORCPT ); Thu, 14 Jan 2021 13:20:10 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69766C0617A5 for ; Thu, 14 Jan 2021 10:18:39 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id a12so9381398lfl.6 for ; Thu, 14 Jan 2021 10:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pJvCZAHLaqoKEh3y+oXgKjwlwnBYnY7borzTim+qS1o=; b=cS4njNwz1nYL1oLQgguEnWk/vDzwqTbhtnDQOGZFDlONuogA+k6cMdUtps27GV41L/ eM8uU49Q5s4mDy3pPtaNcswW/tT9DMGkPJ/mlrPx2a/2GUm7nUZcOq2oV2smZePEhD++ S+YWl3vuAzLSeIEFoL1okEkoP/yPulGSm20Hc= 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=pJvCZAHLaqoKEh3y+oXgKjwlwnBYnY7borzTim+qS1o=; b=UEUc3m321uDKAau7s6AqhS2eHznNwaJBSePxvt7AuNGIxLXZdDJD2q1DtR4CGvkCfx NoIMh6//Dwo7FSJfCFs5kgckx0i1wHRr8LaBouh0KiuOqIXnRNhwDP8GWK3gn8K2VEnP DXgstmIbqbJY7vibTjJ4j4pVrXB4uJP1Ne5aHqlkUqiaCizGtSib4dgQA5VRycEazCbo ft60FCVsojBw3134L9HQm+eWmZZPz1xCDErID5ret+xeJBEDorXfpcTGGNQ+0pfJIACS p2DEv3/Wo2NuHkO5zQQPvjPPiAVZ899hDPlm9I3B88mZVwa5+WNNFJsZud3/+f4p6T9B Wg7Q== X-Gm-Message-State: AOAM5321aJc5eaukHnAvkPhGtlPbz7mhn0sZckumbmZtABNfRiZNs22A RujG5DuWJlItX5GhOQr9/v3TuFIRyEtGEA== X-Received: by 2002:ac2:5d4f:: with SMTP id w15mr3674272lfd.321.1610648317350; Thu, 14 Jan 2021 10:18:37 -0800 (PST) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id o26sm532810ljg.55.2021.01.14.10.18.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Jan 2021 10:18:36 -0800 (PST) Received: by mail-lj1-f178.google.com with SMTP id p13so7572519ljg.2 for ; Thu, 14 Jan 2021 10:18:36 -0800 (PST) X-Received: by 2002:a2e:a40b:: with SMTP id p11mr3547850ljn.315.1610648315779; Thu, 14 Jan 2021 10:18:35 -0800 (PST) MIME-Version: 1.0 References: <20201118234025.376412-1-evgreen@chromium.org> <20201118153951.RESEND.v3.2.Idef164c23d326f5e5edecfc5d3eb2a68fcf18be1@changeid> <20210105102505.GG2000@ninjato> In-Reply-To: <20210105102505.GG2000@ninjato> From: Evan Green Date: Thu, 14 Jan 2021 10:17:59 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RESEND PATCH v3 2/2] i2c: i2c-mux-gpio: Enable this driver in ACPI land To: Wolfram Sang Cc: Andy Shevchenko , Peter Rosin , Randy Dunlap , Peter Korsgaard , linux-i2c , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 5, 2021 at 2:25 AM Wolfram Sang wrote: > > On Fri, Nov 20, 2020 at 10:59:12AM -0800, Evan Green wrote: > > On Thu, Nov 19, 2020 at 7:24 AM Andy Shevchenko > > wrote: > > > > > > On Thu, Nov 19, 2020 at 1:40 AM Evan Green wrote: > > > > > > > > Enable i2c-mux-gpio devices to be defined via ACPI. The idle-state > > > > property translates directly to a fwnode_property_*() call. The child > > > > reg property translates naturally into _ADR in ACPI. > > > > > > > > The i2c-parent binding is a relic from the days when the bindings > > > > dictated that all direct children of an I2C controller had to be I2C > > > > devices. These days that's no longer required. The i2c-mux can sit as a > > > > direct child of its parent controller, which is where it makes the most > > > > sense from a hardware description perspective. For the ACPI > > > > implementation we'll assume that's always how the i2c-mux-gpio is > > > > instantiated. > > > > > > ... > > > > > > > +#ifdef CONFIG_ACPI > > > > + > > > > +static int i2c_mux_gpio_get_acpi_adr(struct device *dev, > > > > + struct fwnode_handle *fwdev, > > > > + unsigned int *adr) > > > > + > > > > +{ > > > > + unsigned long long adr64; > > > > + acpi_status status; > > > > + > > > > + status = acpi_evaluate_integer(ACPI_HANDLE_FWNODE(fwdev), > > > > + METHOD_NAME__ADR, > > > > + NULL, &adr64); > > > > + > > > > + if (!ACPI_SUCCESS(status)) { > > > > + dev_err(dev, "Cannot get address\n"); > > > > + return -EINVAL; > > > > + } > > > > + > > > > + *adr = adr64; > > > > + if (*adr != adr64) { > > > > + dev_err(dev, "Address out of range\n"); > > > > + return -ERANGE; > > > > + } > > > > + > > > > + return 0; > > > > +} > > > > + > > > > +#else > > > > + > > > > +static int i2c_mux_gpio_get_acpi_adr(struct device *dev, > > > > + struct fwnode_handle *fwdev, > > > > + unsigned int *adr) > > > > +{ > > > > + return -EINVAL; > > > > +} > > > > + > > > > +#endif > > > > > > I'm wondering if you may use acpi_find_child_device() here. > > > Or is it a complementary function? > > > > I think it's complementary. The code above is "I have a device, I want > > its _ADR". whereas acpi_find_child_device() is "I have an _ADR, I want > > its device". I could flip things around to use this, but it would turn > > the code from linear into quadratic. I'd have to scan each possible > > address and call acpi_find_child_device() with that _ADR to see if > > there's a child device there. > > > > > > > > ... > > > > > > > + device_for_each_child_node(dev, child) { > > > > + if (is_of_node(child)) { > > > > + fwnode_property_read_u32(child, "reg", values + i); > > > > + > > > > + } else if (is_acpi_node(child)) { > > > > + rc = i2c_mux_gpio_get_acpi_adr(dev, child, values + i); > > > > + if (rc) > > > > + return rc; > > > > + } > > > > + > > > > i++; > > > > } > > > > > > And for this I already told in two different threads with similar code > > > that perhaps we need common helper that will check reg followed by > > > _ADR. > > > > Oh, I'm not aware of those threads. I'd need some advice: I guess a > > new fwnode_* API would make sense for this, but I had trouble coming > > up with a generic interface. _ADR is just a blobbo 64 bit int, but > > DT's "reg" is a little more flexible, having a length, and potentially > > being an array. I suppose it would have to be something like: > > > > int fwnode_property_read_reg(const struct fwnode_handle *fwnode, > > size_t index, uint64_t *addr, uint64_t *len); > > > > But then ACPI would always return 0 for length, and only index 0 would > > ever work? I'm worried I'm designing an API that's only useful to me. > > > > I tried to look around for other examples of this specific pattern of > > _ADR then "reg", but struggled to turn up much. > > -Evan > > Andy, is Evan's answer satisfying for you? Can this be accepted as-is, or should I resend? -Evan