Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3286678ybl; Sun, 11 Aug 2019 20:10:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPkzDnXJ9hZH1AKK6HElLz3xdMZXA0qMSsBEvtH+uWwpt2uW8AqJb8SSKjDFFaWCl0QX+7 X-Received: by 2002:a63:f304:: with SMTP id l4mr28317687pgh.66.1565579408912; Sun, 11 Aug 2019 20:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565579408; cv=none; d=google.com; s=arc-20160816; b=kC8uECAYvpPCTe2DWSCdHNqd8bbeCuP2wVs/NK4x9y4lyWF2Pm97IGWN3lvDDWghWk 4JdKdCriGKnP+vWSzKz70F9j8efiJsOHeL3Rl4eBQOmfgnaM85JRaW7Pc7qplkpX0scG +EzuwS1OHb1UGGId13ynm01ZvRAJT0pTzwfnswBJ0AoNlejSshocu3wkkM4oPl4x9uz9 0Y4wYUvOZQD72DAiF2sIGeP4q6uS0ZO2CccFDKO+lfy4HLO1X+L/dPwCP/hf8SqXueT/ xvFWeboTl2TzoiaUuaaIa9Pw0imNtSemf5YCJEi9WUPFtBLpJEQcjG0CR1nYpGLmwLXy ob5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=3BHln4JLAi8p+6dYartRdUhirndR07U30/OncdUPI58=; b=sMl0H3hPt4IAJD2tI6MNFWYiKyXXnORXMFIQJf0BBRlCxhe/dHUItZQkbHuhB2p0wl bY5PCOBUBIx0bTiPdCx7C9U8hdVc4ys1o7qOf1a1ejy5oZZaxo76oEVcDunIHzPM81Ds zFL7tFH+021EnP2b/E9dWHHIgRQL3RHKf5W5fHmyiJ7LioDCtNX9WOH7jSbk7vQLufDm kre5E9cD4NA+5GEK80+AMJ4N3v8x2lkaa1YTOjR/K+d9NBRrdvZ9+km41StNFM5QNlWM sSWXdC5dzjnEEsvG1huTxo1tKT3UqYuPn5+S7+L1k5NKWeGmkWpKv70sz1PdWA8lMiic j3Cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65si67360419pff.220.2019.08.11.20.09.53; Sun, 11 Aug 2019 20:10:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbfHLDH4 (ORCPT + 99 others); Sun, 11 Aug 2019 23:07:56 -0400 Received: from mga17.intel.com ([192.55.52.151]:12631 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726011AbfHLDHw (ORCPT ); Sun, 11 Aug 2019 23:07:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Aug 2019 20:07:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,375,1559545200"; d="scan'208";a="199987471" Received: from hao-dev.bj.intel.com ([10.238.157.65]) by fmsmga004.fm.intel.com with ESMTP; 11 Aug 2019 20:07:49 -0700 From: Wu Hao To: gregkh@linuxfoundation.org, mdf@kernel.org, linux-fpga@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, atull@kernel.org, Wu Hao Subject: [PATCH v5 3/9] fpga: dfl: afu: convert platform_driver to use dev_groups Date: Mon, 12 Aug 2019 10:49:58 +0800 Message-Id: <1565578204-13969-4-git-send-email-hao.wu@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565578204-13969-1-git-send-email-hao.wu@intel.com> References: <1565578204-13969-1-git-send-email-hao.wu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch takes advantage of driver core which helps to create and remove sysfs attribute files, so there is no need to register sysfs entries manually in dfl-afu platform river code. Signed-off-by: Wu Hao --- drivers/fpga/dfl-afu-main.c | 69 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/drivers/fpga/dfl-afu-main.c b/drivers/fpga/dfl-afu-main.c index e50c45e..e955149 100644 --- a/drivers/fpga/dfl-afu-main.c +++ b/drivers/fpga/dfl-afu-main.c @@ -282,24 +282,17 @@ static int port_get_id(struct platform_device *pdev) &dev_attr_power_state.attr, NULL, }; -ATTRIBUTE_GROUPS(port_hdr); + +static const struct attribute_group port_hdr_group = { + .attrs = port_hdr_attrs, +}; static int port_hdr_init(struct platform_device *pdev, struct dfl_feature *feature) { - dev_dbg(&pdev->dev, "PORT HDR Init.\n"); - port_reset(pdev); - return device_add_groups(&pdev->dev, port_hdr_groups); -} - -static void port_hdr_uinit(struct platform_device *pdev, - struct dfl_feature *feature) -{ - dev_dbg(&pdev->dev, "PORT HDR UInit.\n"); - - device_remove_groups(&pdev->dev, port_hdr_groups); + return 0; } static long @@ -330,7 +323,6 @@ static void port_hdr_uinit(struct platform_device *pdev, static const struct dfl_feature_ops port_hdr_ops = { .init = port_hdr_init, - .uinit = port_hdr_uinit, .ioctl = port_hdr_ioctl, }; @@ -361,32 +353,37 @@ static void port_hdr_uinit(struct platform_device *pdev, &dev_attr_afu_id.attr, NULL }; -ATTRIBUTE_GROUPS(port_afu); -static int port_afu_init(struct platform_device *pdev, - struct dfl_feature *feature) +static umode_t port_afu_attrs_visible(struct kobject *kobj, + struct attribute *attr, int n) { - struct resource *res = &pdev->resource[feature->resource_index]; - int ret; - - dev_dbg(&pdev->dev, "PORT AFU Init.\n"); + struct device *dev = kobj_to_dev(kobj); - ret = afu_mmio_region_add(dev_get_platdata(&pdev->dev), - DFL_PORT_REGION_INDEX_AFU, resource_size(res), - res->start, DFL_PORT_REGION_READ | - DFL_PORT_REGION_WRITE | DFL_PORT_REGION_MMAP); - if (ret) - return ret; + /* + * sysfs entries are visible only if related private feature is + * enumerated. + */ + if (!dfl_get_feature_by_id(dev, PORT_FEATURE_ID_AFU)) + return 0; - return device_add_groups(&pdev->dev, port_afu_groups); + return attr->mode; } -static void port_afu_uinit(struct platform_device *pdev, - struct dfl_feature *feature) +static const struct attribute_group port_afu_group = { + .attrs = port_afu_attrs, + .is_visible = port_afu_attrs_visible, +}; + +static int port_afu_init(struct platform_device *pdev, + struct dfl_feature *feature) { - dev_dbg(&pdev->dev, "PORT AFU UInit.\n"); + struct resource *res = &pdev->resource[feature->resource_index]; - device_remove_groups(&pdev->dev, port_afu_groups); + return afu_mmio_region_add(dev_get_platdata(&pdev->dev), + DFL_PORT_REGION_INDEX_AFU, + resource_size(res), res->start, + DFL_PORT_REGION_MMAP | DFL_PORT_REGION_READ | + DFL_PORT_REGION_WRITE); } static const struct dfl_feature_id port_afu_id_table[] = { @@ -396,7 +393,6 @@ static void port_afu_uinit(struct platform_device *pdev, static const struct dfl_feature_ops port_afu_ops = { .init = port_afu_init, - .uinit = port_afu_uinit, }; static struct dfl_feature_driver port_feature_drvs[] = { @@ -748,9 +744,16 @@ static int afu_remove(struct platform_device *pdev) return 0; } +static const struct attribute_group *afu_dev_groups[] = { + &port_hdr_group, + &port_afu_group, + NULL +}; + static struct platform_driver afu_driver = { .driver = { - .name = DFL_FPGA_FEATURE_DEV_PORT, + .name = DFL_FPGA_FEATURE_DEV_PORT, + .dev_groups = afu_dev_groups, }, .probe = afu_probe, .remove = afu_remove, -- 1.8.3.1