Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753493AbdDJTth (ORCPT ); Mon, 10 Apr 2017 15:49:37 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39959 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752010AbdDJTtb (ORCPT ); Mon, 10 Apr 2017 15:49:31 -0400 From: Christopher Bostic To: robh+dt@kernel.org, mark.rutland@arm.com, linux@armlinux.org.uk, rostedt@goodmis.org, mingo@redhat.com, gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Chris Bostic , joel@jms.id.au, linux-kernel@vger.kernel.org, andrew@aj.id.au, alistair@popple.id.au, benh@kernel.crashing.org Subject: [PATCH v6 11/23] drivers/fsi: Add master unscan Date: Mon, 10 Apr 2017 14:46:54 -0500 X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20170410194706.64280-1-cbostic@linux.vnet.ibm.com> References: <20170410194706.64280-1-cbostic@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17041019-0024-0000-0000-000002405113 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006912; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00845690; UDB=6.00417058; IPR=6.00624124; BA=6.00005281; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014997; XFM=3.00000013; UTC=2017-04-10 19:49:09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17041019-0025-0000-0000-00004341D72D Message-Id: <20170410194706.64280-12-cbostic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-10_15:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704100157 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2130 Lines: 80 From: Chris Bostic Allow a master to undo a previous scan. Should a master scan a bus twice it will need to ensure it doesn't double register any previously detected device. Signed-off-by: Chris Bostic Signed-off-by: Joel Stanley --- drivers/fsi/fsi-core.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index 4da0b030..75d2a88 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -69,6 +69,7 @@ struct fsi_slave { uint32_t size; /* size of slave address space */ }; +#define to_fsi_master(d) container_of(d, struct fsi_master, dev) #define to_fsi_slave(d) container_of(d, struct fsi_slave, dev) static int fsi_master_read(struct fsi_master *master, int link, @@ -491,6 +492,37 @@ static int fsi_master_scan(struct fsi_master *master) return 0; } +static int __fsi_slave_remove_device(struct device *dev, void *arg) +{ + device_unregister(dev); + return 0; +} + +static int __fsi_master_remove_slave(struct device *dev, void *arg) +{ + device_for_each_child(dev, NULL, __fsi_slave_remove_device); + device_unregister(dev); + return 0; +} + +static void fsi_master_unscan(struct fsi_master *master) +{ + device_for_each_child(&master->dev, NULL, __fsi_master_remove_slave); +} + +static ssize_t master_rescan_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct fsi_master *master = to_fsi_master(dev); + + fsi_master_unscan(master); + fsi_master_scan(master); + + return count; +} + +static DEVICE_ATTR(rescan, 0200, NULL, master_rescan_store); + int fsi_master_register(struct fsi_master *master) { int rc; @@ -507,7 +539,15 @@ int fsi_master_register(struct fsi_master *master) return rc; } + rc = device_create_file(&master->dev, &dev_attr_rescan); + if (rc) { + device_unregister(&master->dev); + ida_simple_remove(&master_ida, master->idx); + return rc; + } + fsi_master_scan(master); + return 0; } EXPORT_SYMBOL_GPL(fsi_master_register); -- 1.8.2.2