Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3911763pxk; Tue, 29 Sep 2020 09:12:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKdJDZhdxqCyZOpt2rvyBHMOSS2QmFtBYqka5TrmvY5dkCuYjL0Pn4RniBE4I4VDt7UmT/ X-Received: by 2002:a50:e3c4:: with SMTP id c4mr4234534edm.90.1601395938388; Tue, 29 Sep 2020 09:12:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601395938; cv=none; d=google.com; s=arc-20160816; b=aAwNkchVqpBgxWayEJGuv5HFoOY4er3y0qq0M7AwPYuiTKSgkpX2IvYCYtgsXrTbXE 0dFRI2zBVyJZnJD6e5Y6b+4Rbg4h0u4GcLq8mXnHT9ZE1/ORRfz/JISVmpK85QLgVwbF R90Fpp6XmTTNn70LU5kLXgiJDvM3sdKCEkFqCqRq/LEV/GMO50aROuCjd5TSGPH6GwtX ySxpMRfnSEoZ92aLAEOp6iJnxb4o71jhNMvSe3mfxnvF/rdra8tk3uK7P57KQxNMzgc9 D97nmPdX1enmJuM6Evpc/CtLmTMNLJpLvss2lqlOq1WPNpRtjwYfljF9WlqPS3LB7+sJ UMKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=UuTGkML+V/bG8c9WQuENVdIwmVUvpfepi1FHI1A2IVs=; b=FBBM+CiQFi0SNC8LxFj3YC/IJlbplNlhEhqpoAF9CcNC2XQ/4G6H6/GXfVYz9FjF8v iSjQTO5ayfkeeiT1d35E8dtBvxK21RV98B0tuoqjFcYD/YgJpPl193CemQt4nT6Ceeii 1dwAyCwQywDmYAnUUFezkhe4VVVvYtoDR45TLXtAOtxqtZmw7aYEbLhDj0zFOH393LOA 8Xnc7FtxgVr4KG2hVJl7NAiBPfxwSGEEEMozMim9vwxM8dGa+r2f7fR7yEIuTxQodfee CavV6ufm2puBI/cr55TPlaSTXtLIskRxhWVx1t9cgU3JY8JAIMHsVvrPIQT726wvJUxw WGTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LyGFuuzN; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mh6si3077623ejb.243.2020.09.29.09.11.53; Tue, 29 Sep 2020 09:12:18 -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=@gmail.com header.s=20161025 header.b=LyGFuuzN; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728787AbgI2QKl (ORCPT + 99 others); Tue, 29 Sep 2020 12:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725497AbgI2QKl (ORCPT ); Tue, 29 Sep 2020 12:10:41 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9AA2C061755; Tue, 29 Sep 2020 09:10:40 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id z19so4997347pfn.8; Tue, 29 Sep 2020 09:10:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=UuTGkML+V/bG8c9WQuENVdIwmVUvpfepi1FHI1A2IVs=; b=LyGFuuzNN6b5MXt91Coi57plYltGjWT1itn9m8mAcbENHf7D0yJsumf+96wEJfdMbc 1oRgG0G2FaEATvZpdUolQAjXASHsYoNSIh6UX4I2pVD2KpKpfkZLtyQMh/FdVDtqVOUF WyI3Ahq11tOjVTY0jktOy6MmuhTO4mSSqEwSR7x6IbixaKkn5G6wzgpzpgscAuC9mWKX OjTJPYlJzbTHxmeqMFWVt0rEtzQbhmkVI7p3dY8HHKinHhnW16V+jPa9/haDt2qx1Er6 gJdZZvBVGeM+NmExKi+FwGAgBUVMO0oWFqY7gbUsjESKDmN17Jga+0HYbpogZDXZetUc oU3A== 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:content-transfer-encoding; bh=UuTGkML+V/bG8c9WQuENVdIwmVUvpfepi1FHI1A2IVs=; b=fQpHugreDnoEUD15adpA5J/SrspzU3E8BaAVWgMugb45qLm1yNX0e/ilpSybw2tbyZ Y1WCiJuzsh8O2FKq4EEnYK317lr9B1ZlR4zsosgoJRmA+okBkgSgt2oC30hMZJuGkUia 8pmn04hGj4wrhZSCr+obd2qMV76mxvocE/4O7FMmKl3tw94HJrDjEtGH8/MDWm7iusPH RX74arflqKhwAcRYamOWi97QE9lq2CD7V1NDjTZjoh3Lzr3NSPJMyqW4EHmx/Xu3Rz2K KMvinuNbHjqgKVp9kUmSMO+nWoGaMYT3G+ajoy2xCg8iBmfIVX1ZKLUQvLxhndaxI8u1 ZEnw== X-Gm-Message-State: AOAM532D0I+BoB3B56mg2VPdvPuvN8H6xj5fBvYu0wQ8GPRXo9iNZy2k 8gO1rqxL/AIIzRr5fg2aplmFC+R2O0MLFJkN9I3galaIGK9dhgW3 X-Received: by 2002:aa7:81d5:0:b029:142:2501:39fa with SMTP id c21-20020aa781d50000b0290142250139famr4930845pfn.73.1601395840312; Tue, 29 Sep 2020 09:10:40 -0700 (PDT) MIME-Version: 1.0 References: <9152bb8be33e4192a7766eb53c6ca9af@asem.it> In-Reply-To: From: Andy Shevchenko Date: Tue, 29 Sep 2020 19:10:21 +0300 Message-ID: Subject: Re: How to use an ACPI declared GPIO in a userspace ... To: Bartosz Golaszewski Cc: Flavio Suligoi , Andy Shevchenko , "linux-gpio@vger.kernel.org" , "linux-acpi@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2020 at 6:48 PM Bartosz Golaszewski wrote: > > On Tue, Sep 29, 2020 at 5:43 PM Flavio Suligoi wrote: > > > > Hi all, > > > > I need to expose to the userspace a GPIO, physically connected to a boa= rd > > push-button. This GPIO must expose a pre-defined name, such as > > "user-push-button", so that the userspace applications can use it witho= ut > > know any physical GPIO details. > > > > I can customize the board BIOS and so my goal is to add an ACPI table w= ith > > a content like this: > > > > ... > > Scope (\_SB.GPO1) > > { > > Device (BTNS) > > { > > Name (_HID, "PRP0001") > > Name (_DDN, "GPIO buttons device") > > > > Name (_CRS, ResourceTemplate () > > { > > GpioIo ( > > Exclusive, // Not shared > > PullNone, // No need for= pulls > > 0, // Debounce ti= meout > > 0, // Drive stren= gth > > IoRestrictionInputOnly, // Only used a= s input > > "\\_SB.GPO1", // GPIO contro= ller > > 0, ResourceConsumer, , ) // Must be 0 > > { > > 25, // GPIO number > > } > > ... > > > > I know that this GPIO can be used from other drivers. > > For example I successfully tested it using the "gpio-keys" device drive= r, > > giving to my GPIO a key-code and emulating in this way a keyboard key. > > This could be a possible solution. > > > > But I prefer to expose my GPIO as a classic GPIO, not as a keyboard key= . > > > > I was wondering if there is a generic GPIO driver that I can use to exp= ose > > this GPIO with its pre-defined name (caming from the ACPI table declara= tion), > > to the userspace... Unfortunately what you are describing in the second part is rather property of the controller which can hog the line, but this is not what you want in the first part. The Linux kernel, in many ways, is designed that you need a driver (I=C2=B2C user space device node is rather a mistake, but compromise for that time when most of the devices have access from user space drivers). So, the proper way is to define this as gpio-keys (either interrupt version or polling one) and connect a listener to the event. Summarize: you need to describe pin(s) via "gpio-line-names" property of the controller (it's not so easy task if ACPI tables already have parts of it, but I think your case should be feasible). And either provide a gpio-keys device, or use line directly by name as (libgpiod example): gpiodetect gpioinfo gpiochipX gpiofind $GPIO_LINE_NAME gpiomon gpiochipX $(gpiofind $GPIO_LINE_NAME) & Examples of ACPI are here [1] for controller part (look at the name list) and for device part [2]. You may look into other folders as well, though they are not so reach of examples. [1]: https://github.com/westeri/meta-acpi/blob/master/recipes-bsp/acpi-tabl= es/samples/edison/arduino.asli [2]: https://github.com/westeri/meta-acpi/blob/master/recipes-bsp/acpi-tabl= es/samples/edison/buttons.asli > Adding Andy who knows ACPI GPIO well. Thanks. > In general, the "gpio-line-names" property is used for that and it's > supported both for device tree as well as ACPI, although I have only > ever used the former. Right. ACPI supports properties via _DSD() method. --=20 With Best Regards, Andy Shevchenko