From patchwork Tue Feb 28 22:25:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9597071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 74A4F60429 for ; Tue, 28 Feb 2017 22:33:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6600C28549 for ; Tue, 28 Feb 2017 22:33:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A9FA2857F; Tue, 28 Feb 2017 22:33:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E781E28549 for ; Tue, 28 Feb 2017 22:33:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751961AbdB1Wco (ORCPT ); Tue, 28 Feb 2017 17:32:44 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33592 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751951AbdB1Wcl (ORCPT ); Tue, 28 Feb 2017 17:32:41 -0500 Received: by mail-pg0-f67.google.com with SMTP id x17so3235593pgi.0; Tue, 28 Feb 2017 14:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=C5lGTSPGPkETxT4PFOt7CtKt38ScJDzDVj507TXxcxA=; b=FQEPnt+g8WB2PV22XaWuyXwT7B5vI+j7oO3vFBXvvDWZIHdwd0981EkRM6Plzgsc46 bnYlKXgyS230o+9sNb88tQ3AXd01m8eiB8dXsmX7hkoAIroIM2BEEa8AbrC152+cFp4D /0nHAybqtlgHHaiBderOXE7FuslL2QbVoo7fuvNUUSGV+s2JbT7l3pS3HWg3qVkEQaSL rSemaPLO7y4Ol7Iz7uPp0pchEuz7vxvJ+kf3S1pwkZdP+N51kmfrvnz1pyEPnlgiyvN/ fBW2LbRmRRnVCgNbKEXOesyiPiTZCSMTxunBWHNpFQerwKasCGK5pViLtz+XQeY3d+W4 0yNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=C5lGTSPGPkETxT4PFOt7CtKt38ScJDzDVj507TXxcxA=; b=Gv9A22yo9UePuhTgHrT8w4fpC5oYyhS6xVEciWCqwUnipqTmDx5SrDtPeBXaZAajuh XwCV49Wp+0yJLLcJiQzcstJMEwV12olH4IMs5RDrcsfCO0aFdkAdniUw4CiM6rOJAWLY mgrpvLJu1u7xqioBtZ+mCsgOA3orySgLrUqhaKVIhBffE7gFcZ7nCXDJ2NeozUEAfSrW jSgDbS9SjIGdnLOAiXwit0q96nQFV3RC/N9/UgnJkncPwMU74a1tWg0WPT59UXywxows Zui12BjOaWt+ylpKQw/DV2rQ11D50nWplrBCIQ+ltinj15jF8tM2V/yEm1WJotJxz2iC +5eA== X-Gm-Message-State: AMke39k1FvDTSSX0NbnGXVlYNhoeiLr+0ZfTe4TMHRwglNaZ6EQEGjsKHNi2T9JxCP3Plw== X-Received: by 10.84.128.8 with SMTP id 8mr6075003pla.24.1488320722726; Tue, 28 Feb 2017 14:25:22 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id 9sm6082117pfk.121.2017.02.28.14.25.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Feb 2017 14:25:22 -0800 (PST) From: Dmitry Torokhov To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Shevchenko Subject: [PATCH v3 1/2] spi: allow attaching device properties to SPI board info Date: Tue, 28 Feb 2017 14:25:18 -0800 Message-Id: <20170228222519.38217-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170228222519.38217-1-dmitry.torokhov@gmail.com> References: <20170228222519.38217-1-dmitry.torokhov@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Generic device properties support statically defined property sets. For them to be usable, we need to attach these property sets before devices are registered and probed. Allowing to attach property list to spi_board_info structure will allow non-ACPI non-DT boards switch to using generic properties and get rid of custom platform data. Signed-off-by: Dmitry Torokhov --- drivers/spi/spi.c | 32 ++++++++++++++++++++++++++++---- include/linux/spi/spi.h | 4 ++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 656dd3e3220c..bdecba9be2fa 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -599,13 +600,28 @@ struct spi_device *spi_new_device(struct spi_master *master, proxy->controller_data = chip->controller_data; proxy->controller_state = NULL; - status = spi_add_device(proxy); - if (status < 0) { - spi_dev_put(proxy); - return NULL; + if (chip->properties) { + status = device_add_properties(&proxy->dev, chip->properties); + if (status) { + dev_err(&master->dev, + "failed to add properties to '%s': %d\n", + chip->modalias, status); + goto err_dev_put; + } } + status = spi_add_device(proxy); + if (status < 0) + goto err_remove_props; + return proxy; + +err_remove_props: + if (chip->properties) + device_remove_properties(&proxy->dev); +err_dev_put: + spi_dev_put(proxy); + return NULL; } EXPORT_SYMBOL_GPL(spi_new_device); @@ -661,6 +677,7 @@ static void spi_match_master_to_boardinfo(struct spi_master *master, * * The board info passed can safely be __initdata ... but be careful of * any embedded pointers (platform_data, etc), they're copied as-is. + * Device properties are deep-copied though. * * Return: zero on success, else a negative error code. */ @@ -680,6 +697,13 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) struct spi_master *master; memcpy(&bi->board_info, info, sizeof(*info)); + if (info->properties) { + bi->board_info.properties = + property_entries_dup(info->properties); + if (IS_ERR(bi->board_info.properties)) + return PTR_ERR(bi->board_info.properties); + } + mutex_lock(&board_lock); list_add_tail(&bi->list, &board_list); list_for_each_entry(master, &spi_master_list, list) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 75c6bd0ac605..5a8c4b24f2dc 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -23,6 +23,7 @@ #include struct dma_chan; +struct property_entry; struct spi_master; struct spi_transfer; struct spi_flash_read_message; @@ -1209,6 +1210,7 @@ int spi_flash_read(struct spi_device *spi, * @modalias: Initializes spi_device.modalias; identifies the driver. * @platform_data: Initializes spi_device.platform_data; the particular * data stored there is driver-specific. + * @properties: Additional device properties for the device. * @controller_data: Initializes spi_device.controller_data; some * controllers need hints about hardware setup, e.g. for DMA. * @irq: Initializes spi_device.irq; depends on how the board is wired. @@ -1241,10 +1243,12 @@ struct spi_board_info { * * platform_data goes to spi_device.dev.platform_data, * controller_data goes to spi_device.controller_data, + * device properties are copied and attached to spi_device, * irq is copied too */ char modalias[SPI_NAME_SIZE]; const void *platform_data; + const struct property_entry *properties; void *controller_data; int irq;