From patchwork Tue Feb 28 04:18:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9594659 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 C772260453 for ; Tue, 28 Feb 2017 04:30:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5A5428500 for ; Tue, 28 Feb 2017 04:30:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BACB228515; Tue, 28 Feb 2017 04:30:29 +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 62D3D28500 for ; Tue, 28 Feb 2017 04:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751373AbdB1EaH (ORCPT ); Mon, 27 Feb 2017 23:30:07 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34206 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751030AbdB1EaE (ORCPT ); Mon, 27 Feb 2017 23:30:04 -0500 Received: by mail-pf0-f193.google.com with SMTP id x66so85862pfb.1 for ; Mon, 27 Feb 2017 20:28:24 -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=rO8fqFOF6iI0wsDPi+okok4QXYw9NKAKh/qGvHJ8GFc=; b=FPjZixHGOih+V+uI1JUnOjzDbXUfxAfqd5iOopIULBHh7QSUCdNFfSWTG0qoorFw2U takxJ+MKK5ESccLSUhDWdu74eBqXEoYhCwRI+rzca2INqXfGFLVAuxLETW6eRZsWQNXX ZTdtIJB994LXhb+UefM9jdK9tidJYAjM9bJ1KaclBK9xWxC5nu2EkurV2RlRpH4eTy95 Y2klmQuLbgiwOr5jhnO8vgLNpbDhSy8+agw5ShyVFs187QwbJwEA4L04rh6iMlx+yCaJ QkQ3Z/OJN6NIlZvSfb5GyyWXQC+JCsIMWW8W+O79C+tArsxwVC3Cr3oP0GXS9qT0/TdA dQPw== 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=rO8fqFOF6iI0wsDPi+okok4QXYw9NKAKh/qGvHJ8GFc=; b=HG2oeI+ufFL6hp6+MQWz/S2XXMe5xvDevBIfUXQpnOr+mgGocwDm89moKZXoa6HtCz DSB2WxOnegJj3XLu1PiYk8a1+iysWbv3Ig3IksgNCt7cBbIe0YTnNl60tADbK0nxlrvg R5/BlN3uPtbNLx/OsW5BALIUlJ36UDLRLIoTc2wHixw98QeTYvC9YJJsdTZxfPEl1Kvp QFdSWYqryaQRRYZM/65towtC+/FSqEV5wnE7CwrqqOi963AKap9OUWpbp2G6Y6zvXe37 1khDc9jQHR47ndAwLd+RFiFn4O3NJHixjEO07KbFFxL2g1jN+DNjPJi4X/qoz5QCGbQp xvJw== X-Gm-Message-State: AMke39m9mPKp4z2092L3NM/XEkhjqFopUl3goTGj3MmL1+ybLtobcCO2SSW4OL8+HBwbQA== X-Received: by 10.99.106.199 with SMTP id f190mr357722pgc.110.1488255540016; Mon, 27 Feb 2017 20:19:00 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([172.22.152.34]) by smtp.gmail.com with ESMTPSA id t6sm670035pgt.8.2017.02.27.20.18.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Feb 2017 20:18:59 -0800 (PST) From: Dmitry Torokhov To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] spi: allow attaching device properties to SPI board info Date: Mon, 27 Feb 2017 20:18:55 -0800 Message-Id: <20170228041857.13292-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170228041857.13292-1-dmitry.torokhov@gmail.com> References: <20170228041857.13292-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 | 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;