From patchwork Fri Sep 30 10:54:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 12995249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88835C433FE for ; Fri, 30 Sep 2022 11:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231355AbiI3LO4 (ORCPT ); Fri, 30 Sep 2022 07:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231358AbiI3LO3 (ORCPT ); Fri, 30 Sep 2022 07:14:29 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D33DBF1D8; Fri, 30 Sep 2022 03:54:27 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id g1so6284096lfu.12; Fri, 30 Sep 2022 03:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date; bh=vt4anCeshQmpiBAIkV+85GsPhIKG979bY2xHCX0TUWI=; b=Wa+S+q8QyCffEYBzox4w4HqnuUEYeyAkthi5BEHLLCnyCWTL4PHBMGJW4BLsWMW8Xx gcysaVyAizRveM48sYPDkQXlxV5fZXbPEbwdIWPtb/ukp2ICABCeRHWcTK2idn8rhVUQ cAyBK20q5Hn7qmzgZ8YLq+zf1khAr4dV0ZQ59GqOshhVYPi5qCYa0hT63BOGsJPfCuDO XB1PAcA/mubqnYvDqC5Hc0X+b/eOySLFWSMxYdaEQB/bzpWbH/RjeBSgfEz8ICp80HaJ +Is23YZsiEB+Mm+pWlgTA+uaPIEl06FxWJ/HzTCW7xlaomssg3xbQqJ8kbLsUSk+lR19 KECA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=vt4anCeshQmpiBAIkV+85GsPhIKG979bY2xHCX0TUWI=; b=i4io4aW+eKxLT80T+LDrmyoao/1nvi96gl0Sd7xsAqAjIqObZdgQDxVclSMdQtH71z I++sZZLQc1YKdup1Ng3S8VZdB58qB1EsDTHvNg7N0OCCtYw1EmPSygHt+PRUSEi2VZF9 cSL8YLSgxZDzfSvKy2VuAsGCtCSzdCva5OxMNu1PHsqUdisq+YzRDQMyFY9KI4Vbacog 8G7uSQ+DKyoyxYZ3TQxL8+1J8eRr1+kLQNdsrYhJSlq3klEpJq3qNGjJ8ALXUvk2ZWZ5 K7kmohWVzSY72+qf2e+A3gqsdSr7AUCMEn50YpxfBqEhdzDuj51gr7UBGA+Jan4fuQDW Jj5A== X-Gm-Message-State: ACrzQf0JeMaJgdsyfbRwXO3ci/F4hqOyeYEEqK6r/JnPgr08nPJh1q41 wdwdJ5muyNX+a1HWK0cHQfA= X-Google-Smtp-Source: AMsMyM50tO3mQSdFG6Os81ZjoAEmNUS6e26q/o86wVvr0FXiZYyQ52RLD1uEmRsDyyrRPR686qpTWA== X-Received: by 2002:ac2:4945:0:b0:498:eb8d:e283 with SMTP id o5-20020ac24945000000b00498eb8de283mr3210641lfi.192.1664535265313; Fri, 30 Sep 2022 03:54:25 -0700 (PDT) Received: from fedora ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id u1-20020a056512128100b0049b8c0571e5sm258565lfs.113.2022.09.30.03.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 03:54:24 -0700 (PDT) Date: Fri, 30 Sep 2022 13:54:08 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Cosmin Tanislav , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Eugen Hristev , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Alexandru Ardelean , Srinivas Pandruvada , Miaoqian Lin , Miquel Raynal , Uwe =?iso-8859-1?q?Kleine-K=F6nig?= , Matti Vaittinen , Mihail Chindris , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] iio: Add IIO_STATIC_CONST_DEVICE_ATTR Message-ID: <57fa292756e187d104249f39a655ae736cbcaa76.1664534676.git.mazziesaccount@gmail.com> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add IIO_STATIC_CONST_DEVICE_ATTR macro for creating an read-only iio_dev_attr which returns constant value. This macro is intended to be used when replacing the IIO_CONST_ATTR - attributes for triggered buffers because the triggered buffer attributes must be of type iio_dev_attr. Signed-off-by: Matti Vaittinen --- I am not thrilled about how keyword 'static' is handled here but in my calendar this day seems to be called the day of the developer without working ideas. Feel free to suggest something if you guys have more luck with ideas. :) And I still think this macro is better than adding the summy 'show' callback in each individual driver :/ include/linux/iio/sysfs.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/linux/iio/sysfs.h b/include/linux/iio/sysfs.h index e51fba66de4b..de5bb125815c 100644 --- a/include/linux/iio/sysfs.h +++ b/include/linux/iio/sysfs.h @@ -97,6 +97,17 @@ struct iio_const_attr { = { .string = _string, \ .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)} +#define IIO_STATIC_CONST_DEVICE_ATTR(_name, _string) \ + static ssize_t iio_const_dev_attr_show_##_name( \ + struct device *dev, \ + struct device_attribute *attr, \ + char *buf) \ + { \ + return sysfs_emit(buf, "%s\n", _string); \ + } \ + static IIO_DEVICE_ATTR(_name, 0444, \ + iio_const_dev_attr_show_##_name, NULL, 0) + /* Generic attributes of onetype or another */ /**