From patchwork Tue Feb 28 04:08:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9594631 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 D348C60574 for ; Tue, 28 Feb 2017 04:16:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC0202850D for ; Tue, 28 Feb 2017 04:16:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C12BB28514; Tue, 28 Feb 2017 04:16:48 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham 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 5F80A2850D for ; Tue, 28 Feb 2017 04:16:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751410AbdB1EQk (ORCPT ); Mon, 27 Feb 2017 23:16:40 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34053 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751186AbdB1EQi (ORCPT ); Mon, 27 Feb 2017 23:16:38 -0500 Received: by mail-pf0-f195.google.com with SMTP id x66so58790pfb.1; Mon, 27 Feb 2017 20:16:21 -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; bh=rO8fqFOF6iI0wsDPi+okok4QXYw9NKAKh/qGvHJ8GFc=; b=Zwt+SURqX8j4oPwFw8s6SzWac03hgWgPkUom0E0WQVysiRkRv1TgdbJ/C9wHSdL9kj jlMJjW7ONb2Rllt+I8kNCaLSqoJp9hPvQoDCpBqBgDFTydEqaqEvnY/0mhaki6HNxJBZ 22ncbgSTZ59ipLOdyliO8bnGhC6d9KfGBuDfFwlCv7LojR8eKFffsxmDFwJ8/AZrxxrb 9uIOgTH8Zq3BXwT9rm2+CKtE+/NSMfbf6CFp6uJfnWtxOPG+K5Fkb98WF/WWcrbY66Mc pRx5O3iGGmusRFvuSbjPoElMLveXzIPXDq+pTFoLovDAoqeEuYKWMqYE9UZjFNW+YJeA F4Aw== 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; bh=rO8fqFOF6iI0wsDPi+okok4QXYw9NKAKh/qGvHJ8GFc=; b=kG4tmvgnu/2+oDb9oI+M66dnPMj1Qxv/ASLVxeceqK7XOJcPhWDO5Ix5fgtYSxlP8o rTI8l8YeLrsUIsPTc9kqQMZ560Y7AKBFAiWZzEAekxwcH7/BeTDdD8vWTulyunvs92KG b6wZZtq5rYusRdoXG3CmdmqbK7GOglVK2mFF9yDoBiPFzqbIEaqkNPCS9H2AC4RD3DZS 7Yqz/Ck1QTA0cvTT869HH76+LOI3YXSaUuacChWa8jj3cMCyONFz7ODbPesK6P4BfhaV UshnK0h+YK2q7ydR28B2Kn2scGQuc8udSfOZM/vHLnSWfiOVxrNz0vGv7mX+ZcPAuIA2 csHA== X-Gm-Message-State: AMke39kTD7QDpwIH8Yz9gW0YKABVV1z5+7aLPGBNWJhVAUMsesxeckAr/viNqaBNUYiKZA== X-Received: by 10.84.175.132 with SMTP id t4mr392960plb.38.1488254930224; Mon, 27 Feb 2017 20:08:50 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id v4sm614333pfb.36.2017.02.27.20.08.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Feb 2017 20:08:49 -0800 (PST) From: Dmitry Torokhov To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] spi: allow attaching device properties to SPI board info Date: Mon, 27 Feb 2017 20:08:46 -0800 Message-Id: <20170228040848.9447-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog 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 | 27 +++++++++++++++++++++++---- include/linux/spi/spi.h | 4 ++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 656dd3e3220c..b948d8cdbace 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,25 @@ 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_out; + } } + status = spi_add_device(proxy); + if (status < 0) + goto err_out; + return proxy; + +err_out: + spi_dev_put(proxy); + return NULL; } EXPORT_SYMBOL_GPL(spi_new_device); @@ -661,6 +674,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 +694,11 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n) struct spi_master *master; memcpy(&bi->board_info, info, sizeof(*info)); + 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;