From patchwork Tue Oct 28 20:36:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pantelis Antoniou X-Patchwork-Id: 404331 X-Patchwork-Delegate: wolfram@the-dreams.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3E18D140085 for ; Wed, 29 Oct 2014 07:37:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755062AbaJ1Ug5 (ORCPT ); Tue, 28 Oct 2014 16:36:57 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:45711 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755047AbaJ1Ugy (ORCPT ); Tue, 28 Oct 2014 16:36:54 -0400 Received: by mail-wi0-f182.google.com with SMTP id d1so2821543wiv.15 for ; Tue, 28 Oct 2014 13:36:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=O9CVkiGjG3Q3hPxI8MJkKhl/I4Wb1bu6jE88cUFgbrU=; b=S3VyO2KK8xvnN3czPi4ImJKezj4Hv4UquwqE3rqBMSemiaSah1YKlNLaqGFprZVPxf 44Do1vrsRf9uBEfeLnbgYBq8rYQ+AB1MUvtdo70i1LyWIcC1k8jqwwfB5OAffglzXWKn +LANN5mGdH2SF2TEkdR6vU0C8jPiMCbd9pkPHIGsevGc0njRuOq8kr5XRS4vp6mt4Jsz 05ekOvYQvs6qKaSo1QOLQju+8XI0M54CuufxHLx7izAILv2bp/PcA/ftkVk9sTCSh8iZ 8S+3KKI+0eaR0eDuBmOwQQr/3abEQbCD7HMsrMAYobON4HHD/Xd47Xh7JEtpYpwdSzQu ZQXw== X-Gm-Message-State: ALoCoQnDDBj+sEX1k0CTIx4Wod4LuAbCQ1/Eg9dT+iBAAORGXicjIqh92X6qZaziZfyR9ZevKKH5 X-Received: by 10.194.119.193 with SMTP id kw1mr7394918wjb.37.1414528613087; Tue, 28 Oct 2014 13:36:53 -0700 (PDT) Received: from sles11esa.localdomain ([195.97.110.117]) by mx.google.com with ESMTPSA id td9sm3371380wic.15.2014.10.28.13.36.48 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 28 Oct 2014 13:36:52 -0700 (PDT) From: Pantelis Antoniou To: Grant Likely Cc: Rob Herring , Stephen Warren , Matt Porter , Koen Kooi , Greg Kroah-Hartman , Alison Chaiken , Dinh Nguyen , Jan Lubbe , Alexander Sverdlin , Michael Stickel , Guenter Roeck , Dirk Behme , Alan Tull , Sascha Hauer , Michael Bohan , Ionut Nicu , Michal Simek , Matt Ranostay , Joel Becker , devicetree@vger.kernel.org, Wolfram Sang , linux-i2c@vger.kernel.org, Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Pete Popov , Dan Malek , Georgi Vlaev , Pantelis Antoniou , Pantelis Antoniou Subject: [PATCH v8 8/8] OF: spi: Add OF notifier handler Date: Tue, 28 Oct 2014 22:36:05 +0200 Message-Id: <1414528565-10907-9-git-send-email-pantelis.antoniou@konsulko.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1414528565-10907-1-git-send-email-pantelis.antoniou@konsulko.com> References: <1414528565-10907-1-git-send-email-pantelis.antoniou@konsulko.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add OF notifier handler needed for creating/destroying spi devices according to dynamic runtime changes in the DT live tree. Signed-off-by: Pantelis Antoniou --- drivers/spi/spi.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index f81d799..f62a3e4 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2363,6 +2363,71 @@ EXPORT_SYMBOL_GPL(spi_write_then_read); /*-------------------------------------------------------------------------*/ +#if IS_ENABLED(CONFIG_OF) + +static int of_spi_notify(struct notifier_block *nb, + unsigned long action, void *arg) +{ + struct device_node *dn; + struct spi_master *master; + struct spi_device *spi; + int state; + + state = of_reconfig_get_state_change(action, arg); + if (state == -1) + return NOTIFY_OK; + + switch (action) { + case OF_RECONFIG_ATTACH_NODE: + case OF_RECONFIG_DETACH_NODE: + dn = arg; + break; + case OF_RECONFIG_ADD_PROPERTY: + case OF_RECONFIG_REMOVE_PROPERTY: + case OF_RECONFIG_UPDATE_PROPERTY: + dn = ((struct of_prop_reconfig *)arg)->dn; + break; + default: + return NOTIFY_OK; + } + + if (state) { + + master = of_find_spi_master_by_node(dn->parent); + if (master == NULL) + return NOTIFY_OK; /* not for us */ + + spi = of_register_spi_device(master, dn); + put_device(&master->dev); + + if (IS_ERR(spi)) { + pr_err("%s: failed to create for '%s'\n", + __func__, dn->full_name); + return notifier_from_errno(PTR_ERR(spi)); + } + + } else { + + /* find our device by node */ + spi = of_find_spi_device_by_node(dn); + if (spi == NULL) + return NOTIFY_OK; /* no? not meant for us */ + + /* unregister takes one ref away */ + spi_unregister_device(spi); + + /* and put the reference of the find */ + put_device(&spi->dev); + + } + + return NOTIFY_OK; +} + +static struct notifier_block spi_of_notifier; + +#endif + static int __init spi_init(void) { int status; @@ -2380,8 +2445,19 @@ static int __init spi_init(void) status = class_register(&spi_master_class); if (status < 0) goto err2; - return 0; +#if IS_ENABLED(CONFIG_OF) + spi_of_notifier.notifier_call = of_spi_notify; + status = of_reconfig_notifier_register(&spi_of_notifier); + if (status) + goto err3; +#endif + + return 0; +#if IS_ENABLED(CONFIG_OF) +err3: + class_unregister(&spi_master_class); +#endif err2: bus_unregister(&spi_bus_type); err1: