Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3837746pxu; Mon, 30 Nov 2020 11:16:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKBNrw1aCuWPkYfVe92sRx0hQ+A1KcaAVy9eLocLlV81la14YhzbESwPWTRKIhy8mNxBCf X-Received: by 2002:a17:906:f905:: with SMTP id lc5mr20099205ejb.177.1606763807897; Mon, 30 Nov 2020 11:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606763807; cv=none; d=google.com; s=arc-20160816; b=xXsaRFxPEKcBzzTnH5E8wl57LVNf67s7XUCVkwlFxU1vS8C1/qWu1mJWFR89q6P7tg d4NhtekrxHmJtIlKRj7pinA2Vm0Iwh+7HAx19M4hBRDTpF7TF/NeBvZrBnZCGioBVZZ0 7cMCBVB5cfBoKnjb/ARObJPmWHSQFR1fDX+Z8CB9RMGRCo18iXadbAo8hARILIeIGTJG EebzGkyArRkz1z9K2WnO8Xllm6364Oq6KoMa/wd8XFJ0igq/7YhR79JX9EY5ya5UGCec 7FCV1ilqbuYXmKJAiwt/vfBjL21uQ+q0IX9vDvd5vyUtXTfW9XwU+i0EeK52A/W2e8Rz QWOg== 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=qhoqT/m6QP2iHAwluk/LX+wOo/cBuZcFuXiuawLlKL0=; b=wBnW5k4eKvA8SljkOJ7mteG2JRK5Y0dCSDyY8PPVWVMzV5vL8JBt9pvHxnkIJkQu14 4tGN1hcvq8PqcvHXYya8G57xadWH6A1yK5kkOYFbM8uL5WNzUeVdfavLzrd7bJtjxcJ0 P44sgN2qwpl08CYFPJOZfn39zMcQfsMlKpnPvZn4YfD3mIw8/0ZS182Xm77z5YQmN0QW 4McqY8Jofo48DUdJTdtY6CyA8p7iXkhiiC3G3kew5JN3X8nv6PM6TCgnulih8hIXdVpP Iyq4/UuB3NN4MARPX0R2F0sX/9hSRxzKyNDpuC0QNxNXOfqgA4zYCww87Jx1YIhn0EVD 0DhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lEOyaHhb; 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 b4si6294635ejv.71.2020.11.30.11.16.24; Mon, 30 Nov 2020 11:16:47 -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=lEOyaHhb; 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 S2388269AbgK3TNB (ORCPT + 99 others); Mon, 30 Nov 2020 14:13:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388007AbgK3TNB (ORCPT ); Mon, 30 Nov 2020 14:13:01 -0500 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7C54C0613CF for ; Mon, 30 Nov 2020 11:12:20 -0800 (PST) Received: by mail-lj1-x244.google.com with SMTP id y10so19677637ljc.7 for ; Mon, 30 Nov 2020 11:12:20 -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=qhoqT/m6QP2iHAwluk/LX+wOo/cBuZcFuXiuawLlKL0=; b=lEOyaHhbG/Czm59pk368rryL3Wzn2gIYx7RaGWiZZJydaUZV+2BQZx5e5TKeZIyTga XuAdZVX9BHGl/7+ZBXy331Ec/0IBawT6MIt7L83HDIT1/94lx19nMmlJZN1eGb5eKd8+ 3UdmkmeD4Ivb/XLxm8E0ruLAMjMqIgdVPhTYQ= 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=qhoqT/m6QP2iHAwluk/LX+wOo/cBuZcFuXiuawLlKL0=; b=XbVVjVlnfPdKvLtKTqRIbej8gNDI3pPgvgQ08kGnuSVyKSYINzZIMtakt0sonGtwxR yp6Pe7Xu/IUau9OAtdxczbiZgeqrWrRsOGFWbHvZ43ar6U72+9bMnwYK5bgEPwYUPHNT ys41CpAPDIH/K2F4zH9D24IJ5C4cnwAmwAIlwULK03m4hsUxVXNuQAFLqU0tFaM4HiRu l2RCbZHClbbX5SFWZxpCoS0yOKiw9vQDq+ciR5fkJpQHAI93rCuRjWMYd3VvFZyXOoRi WIx+qsV38ffXf5ZZKEftffGJGjn1n5BkZnBBi+8beOcmxKyrKZUomksxd9Tg6J/urhV8 F2KA== X-Gm-Message-State: AOAM532vwyNBG7MPd9vVeFiJ6Ccvj6FxjZNNX3sWjGUWrUqQxy79xK0y mfKJQoJ8m7Bb2K3V2JMk9+TSK0xbSh5niA== X-Received: by 2002:a2e:a312:: with SMTP id l18mr11154566lje.231.1606763538801; Mon, 30 Nov 2020 11:12:18 -0800 (PST) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com. [209.85.167.50]) by smtp.gmail.com with ESMTPSA id o20sm1289289lfl.157.2020.11.30.11.12.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2020 11:12:17 -0800 (PST) Received: by mail-lf1-f50.google.com with SMTP id j205so23784014lfj.6 for ; Mon, 30 Nov 2020 11:12:17 -0800 (PST) X-Received: by 2002:a19:ca0a:: with SMTP id a10mr9856079lfg.121.1606763536477; Mon, 30 Nov 2020 11:12:16 -0800 (PST) MIME-Version: 1.0 References: <20201118234025.376412-1-evgreen@chromium.org> <20201118153951.RESEND.v3.2.Idef164c23d326f5e5edecfc5d3eb2a68fcf18be1@changeid> In-Reply-To: From: Evan Green Date: Mon, 30 Nov 2020 11:11:39 -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: Andy Shevchenko Cc: Peter Rosin , Wolfram Sang , 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 Hi Andy, Peter, On Fri, Nov 20, 2020 at 10:59 AM 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. Any thoughts on this? > -Evan > > > > > -- > > With Best Regards, > > Andy Shevchenko