Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753403AbcDRLw6 (ORCPT ); Mon, 18 Apr 2016 07:52:58 -0400 Received: from mail-db3on0133.outbound.protection.outlook.com ([157.55.234.133]:36592 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753316AbcDRLwz (ORCPT ); Mon, 18 Apr 2016 07:52:55 -0400 Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=toradex.com; From: Bhuvanchandra DV To: CC: , , , , Bhuvanchandra DV , Stefan Agner Subject: [RFC 2/2] spi core: Add new sysfs 'num_chipselect' file Date: Mon, 18 Apr 2016 16:48:28 +0530 Message-ID: <1460978308-8062-3-git-send-email-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1460978308-8062-1-git-send-email-bhuvanchandra.dv@toradex.com> References: <1460978308-8062-1-git-send-email-bhuvanchandra.dv@toradex.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.115.225.206] X-ClientProxiedBy: HKXPR03CA0066.apcprd03.prod.outlook.com (10.163.104.24) To AMSPR05MB262.eurprd05.prod.outlook.com (10.242.95.19) X-MS-Office365-Filtering-Correlation-Id: 42956029-05fa-41bd-0634-08d3677b4037 X-Microsoft-Exchange-Diagnostics: 1;AMSPR05MB262;2:uAl2xo2LBpixU53iXfzUb+dx0QoDNsRLBtKG+Xq50m8FxFAoxDMiy6eKup80BsSHmQSqXIeEydH+IuH3p26M5UeeOdq8NDU/BjvFMA6IQ5UOHsKZOK6nKwhBu8otp4uihf++JRtxbdYhYTYoi5kD9q7M+5/9SonU6L7Fmi725xP98D0RLbu2f0j6O/dXrNSK;3:gc4VvOJTVR33OJFpMR7HxHUF8Y7dnJWL75rU0J4zFyRxmcChKjtIRoAEUYVe52CHVV4v9PyMaiELRI2GJdGaNtwwV5tChHphXuqSj1VNnxGyH1mFxTl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sNTYhANN0cwmV8I4TkMeMFj8PJcHTwwdpNVqAbHvJJ2Zg+o0pSsSnzzB2ql7rxxP8T5UKo0y2y6J+JYldTxB7HNkbICFQLedWpw+4rDjClvpUftCAiKw4iRcnNWPw==;4:yP72NqjXo0sq263r2Hd5oUv5MWDRDiFQEBCbDjrVHNvYEZuZmiESXVM4ralcbnN53psDstNleyKNjGRJXz7ylZc78FHsIA+fxvqiDhEeifdWMo5qVW47OsKCDnsYnhGflvbp/5sNnC/vArdPbWm9y4i83LoEaPulSk7FOj3WYf6fG/3kIIjV/ODoevNTf/Ae8pD4FfxXZoVlxJIzn8XWNjGpS47+BUwwUfZZCMakuUej1dDiNSLtbnS99OBGsK0w9jHy4KSrrTNr9AL9St3X+6D8Oagusbct4X1pkUw4RIXLPrvlHPmlzTqWNzJu2hLYaREi9NkH7LDq2wbs4R1B7A4hsR900E/gpWjEoNOeCP7fwv6xRKRC3pQWcQ2OE+F0xA95Kv4ukxnGYMZR7OCw/w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521026)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046);SRVR:AMSPR05MB262;BCL:0;PCL:0;RULEID:;SRVR:AMSPR05MB262; X-Forefront-PRVS: 0916FC3A18 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(77096005)(586003)(92566002)(189998001)(36756003)(47776003)(229853001)(4326007)(2351001)(66066001)(3846002)(6116002)(1096002)(2950100001)(76176999)(50986999)(107886002)(110136002)(86362001)(33646002)(2906002)(19580395003)(19580405001)(53416004)(50466002)(81166005)(48376002)(42186005)(50226001)(5008740100001)(4001430100002);DIR:OUT;SFP:1102;SCL:1;SRVR:AMSPR05MB262;H:linuxdev-in.toradex.int;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AMSPR05MB262;23:4yriGYLpbFPgE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iSf42bLvA6OSuOqD3mT9srTFIkhoyLBufkSepXrsbPOKItxJ/y3D;24:JGaYbCqxlnravPthgi+j+YKO//GDPMvGsu8Yuh11QKk59YgYvrxyDvJXnamdysRuKZaJGZ3ATRdmzga279mzulTo/kM85JTGvHallerUxvs=;7:6XdBw82Axak+wBffz7Bl1euX3vs6aQmj8C9vkGp2UVFCWlwR1dOgR8nxqqXUfE7etocgaqBnnlG3i6ut/63P4nFOgYlKaj3L4XhzXSGq3onRwUuugwhsRwcZGoKRGGrfKjmqYp75tdG+cOXAB4+hWZt/jxkCuUOAw1czQ1Dnsmh467Oix1B4A++amcj6o3mKmg5L1ztO2XQcYsfTHg3qPHaiItO8nQfV/GnbBhwPFVY= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2016 11:19:01.3482 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMSPR05MB262 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2652 Lines: 76 Add new sysfs 'num_chipselect' file to expose the maximum number of chipselects a SPI master can support. This allows to create a script in user space which automatically creates a new spidev instance for every chipselect on a bus. Signed-off-by: Bhuvanchandra DV Signed-off-by: Stefan Agner --- Documentation/spi/spi-summary | 3 +++ drivers/spi/spi.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary index d1824b3..b4d15e4 100644 --- a/Documentation/spi/spi-summary +++ b/Documentation/spi/spi-summary @@ -181,6 +181,9 @@ shows up in sysfs in several locations: controller managing bus "B". All spiB.* devices share one physical SPI bus segment, with SCLK, MOSI, and MISO. + /sys/class/spi_master/spiB/num_chipselect ... exposes the maximum + number of chipselects a SPI master can support. + Note that the actual location of the controller's class state depends on whether you enabled CONFIG_SYSFS_DEPRECATED or not. At this time, the only class-specific state is the bus number ("B" in "spiB"), so diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index de2f2f9..c3eb29f 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -67,6 +67,19 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf) } static DEVICE_ATTR_RO(modalias); +static ssize_t +num_chipselect_show(struct device *dev, struct device_attribute *a, char *buf) +{ + struct spi_master *master = container_of(dev, + struct spi_master, dev); + + return sprintf(buf, "%d\n", master->num_chipselect); +} +static struct device_attribute dev_attr_num_chipselect = { + .attr = { .name = "num_chipselect", .mode = S_IRUGO }, + .show = num_chipselect_show, +}; + #define SPI_STATISTICS_ATTRS(field, file) \ static ssize_t spi_master_##field##_show(struct device *dev, \ struct device_attribute *attr, \ @@ -155,6 +168,15 @@ static const struct attribute_group spi_dev_group = { .attrs = spi_dev_attrs, }; +static struct attribute *spi_master_attrs[] = { + &dev_attr_num_chipselect.attr, + NULL, +}; + +static const struct attribute_group spi_master_group = { + .attrs = spi_master_attrs, +}; + static struct attribute *spi_device_statistics_attrs[] = { &dev_attr_spi_device_messages.attr, &dev_attr_spi_device_transfers.attr, @@ -236,6 +258,7 @@ static const struct attribute_group spi_master_statistics_group = { }; static const struct attribute_group *spi_master_groups[] = { + &spi_master_group, &spi_master_statistics_group, NULL, }; -- 2.7.3