linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Allow specifying properties with spi_register_board_info
@ 2017-02-28 22:25 Dmitry Torokhov
  2017-02-28 22:25 ` [PATCH v3 1/2] spi: allow attaching device properties to SPI board info Dmitry Torokhov
  2017-02-28 22:25 ` [PATCH v3 2/2] spi: allow registering empty spi_board_info lists Dmitry Torokhov
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2017-02-28 22:25 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Andy Shevchenko

I am trying to convert some input drivers to use only generic device
properties, and get rid of legacy platform data. For that I need to be
able to attach property lists to devices before they are registered, and
quite a few boards use spi_register_board_info() to create their devices.

v3: dropped former patch #2 (spi: allocate spi_board_info entries one by
    one), changed patch #1 to not copy empty property sets and also to
    remove added properties when spi_add_device() fails (when it is
    successful driver core will free properties upon device removal).

v2: change patch #2 from kmemdup to kmalloc + copy as they are different
    data types.

v1: initial posting


Dmitry Torokhov (2):
  spi: allow attaching device properties to SPI board info
  spi: allow registering empty spi_board_info lists

 drivers/spi/spi.c       | 34 +++++++++++++++++++++++++++++-----
 include/linux/spi/spi.h |  4 ++++
 2 files changed, 33 insertions(+), 5 deletions(-)

-- 
Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 1/2] spi: allow attaching device properties to SPI board info
  2017-02-28 22:25 [PATCH v3 0/2] Allow specifying properties with spi_register_board_info Dmitry Torokhov
@ 2017-02-28 22:25 ` Dmitry Torokhov
  2017-02-28 22:25 ` [PATCH v3 2/2] spi: allow registering empty spi_board_info lists Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2017-02-28 22:25 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Andy Shevchenko

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 <dmitry.torokhov@gmail.com>
---
 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 <linux/of_gpio.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm_domain.h>
+#include <linux/property.h>
 #include <linux/export.h>
 #include <linux/sched/rt.h>
 #include <linux/delay.h>
@@ -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 <linux/scatterlist.h>
 
 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;
 
-- 
2.11.0.483.g087da7b7c-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v3 2/2] spi: allow registering empty spi_board_info lists
  2017-02-28 22:25 [PATCH v3 0/2] Allow specifying properties with spi_register_board_info Dmitry Torokhov
  2017-02-28 22:25 ` [PATCH v3 1/2] spi: allow attaching device properties to SPI board info Dmitry Torokhov
@ 2017-02-28 22:25 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2017-02-28 22:25 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Andy Shevchenko

Many boards form list of spi_board_info entries depending on config,
and it is possible to end up with empty list. Do not report error
in such cases.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/spi/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index bdecba9be2fa..ff37bc5b3947 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -687,7 +687,7 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
 	int i;
 
 	if (!n)
-		return -EINVAL;
+		return 0;
 
 	bi = kzalloc(n * sizeof(*bi), GFP_KERNEL);
 	if (!bi)
-- 
2.11.0.483.g087da7b7c-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-01  0:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28 22:25 [PATCH v3 0/2] Allow specifying properties with spi_register_board_info Dmitry Torokhov
2017-02-28 22:25 ` [PATCH v3 1/2] spi: allow attaching device properties to SPI board info Dmitry Torokhov
2017-02-28 22:25 ` [PATCH v3 2/2] spi: allow registering empty spi_board_info lists Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).