Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1500278pxb; Fri, 20 Nov 2020 11:01:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbjy5k3UrsyEpEwIUqN1e344qz1FLnbmGqr+nKJ95QiWB6Q1+4f5TLGj++M/foIksxGaFH X-Received: by 2002:aa7:d54a:: with SMTP id u10mr12937332edr.168.1605898901926; Fri, 20 Nov 2020 11:01:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605898901; cv=none; d=google.com; s=arc-20160816; b=XKCw7jBjGnITDtMpNBKm2QMHyM98d39Jv6JDFQDDA5gRYKTL9g+3z8Edhg/W+SN9Dh sU8hYLrwzkrQtqSNehO4mHkmuC7h1bQpqbJZMCv+F4lBuoqLkQ7yseNgrKCw/wDFG32T ZdgHNfA0B6rCwYir/kYimEuQXsKwQ4bwUjFYMbT66yk2kvOyd2ynIoUUW/uY04mOsAKd qCMD9vJVFpg4/TahE5zZ9eOR0eyrRTl3FwktYVQkSZgIsHPZ7eHmliJByMpHylmP4gSU 0CN8K8Q3g5kM/L6Elx3EUG2inQpK1E26voOFbDZE5OhHMGpkinJthnFQA6uzu54wOCdh 4TEg== 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=WP40hyIHVW+8+OBoS/eJu6n4FBxVosTt45ETp9kRxys=; b=LuepUqhJbYpbbUtcHBwJWZY7zrO8wfJ/rN3vsSc/jfrm8GlK6bMR1sz76/+Ie8zH9A CH18otBtgp687qOaAzWmn5ovp+W1K/1XrGT2Ck9aYfytOriiAGI9CGt3fCZ43YN91H6d dtf6TQVSUg4yDLGfJlMJscKilVQUS22JKtM23/4tb8tyqCCXuExfLNfXcZCuyQ2V1aXk yUgHE1Ds7MOOstCtRs9RTyuC6QK6aQ9GfuwbU8zG5VuzuVQFMJV/4VENzfLIFbBaJnFe Cvx969Jvbo8qmtdVmI9Siv0yDY4aNyCrihSWcYzff1MAc88QyAggu+njJqENHGeBz4Ty f6nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iH6DYysS; 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 gc15si2214857ejb.621.2020.11.20.11.01.17; Fri, 20 Nov 2020 11:01:41 -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=iH6DYysS; 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 S1730313AbgKTS7z (ORCPT + 99 others); Fri, 20 Nov 2020 13:59:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730111AbgKTS7y (ORCPT ); Fri, 20 Nov 2020 13:59:54 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47089C061A04 for ; Fri, 20 Nov 2020 10:59:53 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id y16so11153877ljh.0 for ; Fri, 20 Nov 2020 10:59:53 -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=WP40hyIHVW+8+OBoS/eJu6n4FBxVosTt45ETp9kRxys=; b=iH6DYysSkQwGTz88LDkNljp6oFZgEGlYTmTVobZl/qFx8kbV2sq8WPrsBYs0JqxPs2 JpaDdHbB3ZHYnEequccgC9CERCbsDthVuEYtV+ObOSVmw6eq2mY2SvY3M9lsPF6azORX r5UUMhtjVIbCM0g0fIXmo0aIeRDt4oDjgxLrA= 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=WP40hyIHVW+8+OBoS/eJu6n4FBxVosTt45ETp9kRxys=; b=nKybNiREtXu0vgTOlu7G92SA6Lc03O4DX/t8DoORni/E5vQVqPqYF8lzImcRuZXu4h r2qdRktwnDNoO437uRP7DzDCOBhtiRB1qC+kHYMc6Z0IzN0N7KUFIDYTwO7hpEBXErK0 0OZ/DTevFi3JaKgrwDCZXskm2wf+pSbfvmVvffQzi1TmyYwrlpt3Iq2DHc5NRH2KvCkl 2qRKXQzBrQqIPoz8y/xUXz+ogtVsouPXYISGzri6qtdf6bthZejyVB/qZYsHjfROd4qX xJor3nfRMc96NVvC7Wvmc1XRo99Yt0Bv2PIrXneFH9RdmHGGzCam3o97INd2iNOD0cYQ R9LA== X-Gm-Message-State: AOAM5312DcwZ3lkRuDY/JBVfxVMBRVLhLHWYoYDHO+l2C7/2X5pJT57m L+b3FCCoh2+vT4wn4ZlOKHEue7b7DMGUsw== X-Received: by 2002:a2e:908c:: with SMTP id l12mr8338599ljg.60.1605898791252; Fri, 20 Nov 2020 10:59:51 -0800 (PST) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com. [209.85.167.43]) by smtp.gmail.com with ESMTPSA id w123sm434483lff.138.2020.11.20.10.59.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Nov 2020 10:59:50 -0800 (PST) Received: by mail-lf1-f43.google.com with SMTP id v144so14871876lfa.13 for ; Fri, 20 Nov 2020 10:59:49 -0800 (PST) X-Received: by 2002:a19:4b92:: with SMTP id y140mr8175542lfa.485.1605898789139; Fri, 20 Nov 2020 10:59:49 -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: Fri, 20 Nov 2020 10:59:12 -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 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 > > -- > With Best Regards, > Andy Shevchenko