aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2017-02-28 17:25:18 -0500
committerMark Brown <broonie@kernel.org>2017-03-06 05:38:03 -0500
commit826cf175ed705f70a49d04aca832c1cc9ff048d8 (patch)
tree97407688809ba1b00b3c5c77e6cdbb529a0e8fce
parentc1ae3cfa0e89fa1a7ecc4c99031f5e9ae99d9201 (diff)
spi: allow attaching device properties to SPI board info
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> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/spi/spi.c32
-rw-r--r--include/linux/spi/spi.h4
2 files changed, 32 insertions, 4 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 90b5b2efafbf..6cc86060d22f 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -31,6 +31,7 @@
31#include <linux/of_gpio.h> 31#include <linux/of_gpio.h>
32#include <linux/pm_runtime.h> 32#include <linux/pm_runtime.h>
33#include <linux/pm_domain.h> 33#include <linux/pm_domain.h>
34#include <linux/property.h>
34#include <linux/export.h> 35#include <linux/export.h>
35#include <linux/sched/rt.h> 36#include <linux/sched/rt.h>
36#include <uapi/linux/sched/types.h> 37#include <uapi/linux/sched/types.h>
@@ -600,13 +601,28 @@ struct spi_device *spi_new_device(struct spi_master *master,
600 proxy->controller_data = chip->controller_data; 601 proxy->controller_data = chip->controller_data;
601 proxy->controller_state = NULL; 602 proxy->controller_state = NULL;
602 603
603 status = spi_add_device(proxy); 604 if (chip->properties) {
604 if (status < 0) { 605 status = device_add_properties(&proxy->dev, chip->properties);
605 spi_dev_put(proxy); 606 if (status) {
606 return NULL; 607 dev_err(&master->dev,
608 "failed to add properties to '%s': %d\n",
609 chip->modalias, status);
610 goto err_dev_put;
611 }
607 } 612 }
608 613
614 status = spi_add_device(proxy);
615 if (status < 0)
616 goto err_remove_props;
617
609 return proxy; 618 return proxy;
619
620err_remove_props:
621 if (chip->properties)
622 device_remove_properties(&proxy->dev);
623err_dev_put:
624 spi_dev_put(proxy);
625 return NULL;
610} 626}
611EXPORT_SYMBOL_GPL(spi_new_device); 627EXPORT_SYMBOL_GPL(spi_new_device);
612 628
@@ -664,6 +680,7 @@ static void spi_match_master_to_boardinfo(struct spi_master *master,
664 * 680 *
665 * The board info passed can safely be __initdata ... but be careful of 681 * The board info passed can safely be __initdata ... but be careful of
666 * any embedded pointers (platform_data, etc), they're copied as-is. 682 * any embedded pointers (platform_data, etc), they're copied as-is.
683 * Device properties are deep-copied though.
667 * 684 *
668 * Return: zero on success, else a negative error code. 685 * Return: zero on success, else a negative error code.
669 */ 686 */
@@ -683,6 +700,13 @@ int spi_register_board_info(struct spi_board_info const *info, unsigned n)
683 struct spi_master *master; 700 struct spi_master *master;
684 701
685 memcpy(&bi->board_info, info, sizeof(*info)); 702 memcpy(&bi->board_info, info, sizeof(*info));
703 if (info->properties) {
704 bi->board_info.properties =
705 property_entries_dup(info->properties);
706 if (IS_ERR(bi->board_info.properties))
707 return PTR_ERR(bi->board_info.properties);
708 }
709
686 mutex_lock(&board_lock); 710 mutex_lock(&board_lock);
687 list_add_tail(&bi->list, &board_list); 711 list_add_tail(&bi->list, &board_list);
688 list_for_each_entry(master, &spi_master_list, list) 712 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 @@
23#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
24 24
25struct dma_chan; 25struct dma_chan;
26struct property_entry;
26struct spi_master; 27struct spi_master;
27struct spi_transfer; 28struct spi_transfer;
28struct spi_flash_read_message; 29struct spi_flash_read_message;
@@ -1209,6 +1210,7 @@ int spi_flash_read(struct spi_device *spi,
1209 * @modalias: Initializes spi_device.modalias; identifies the driver. 1210 * @modalias: Initializes spi_device.modalias; identifies the driver.
1210 * @platform_data: Initializes spi_device.platform_data; the particular 1211 * @platform_data: Initializes spi_device.platform_data; the particular
1211 * data stored there is driver-specific. 1212 * data stored there is driver-specific.
1213 * @properties: Additional device properties for the device.
1212 * @controller_data: Initializes spi_device.controller_data; some 1214 * @controller_data: Initializes spi_device.controller_data; some
1213 * controllers need hints about hardware setup, e.g. for DMA. 1215 * controllers need hints about hardware setup, e.g. for DMA.
1214 * @irq: Initializes spi_device.irq; depends on how the board is wired. 1216 * @irq: Initializes spi_device.irq; depends on how the board is wired.
@@ -1241,10 +1243,12 @@ struct spi_board_info {
1241 * 1243 *
1242 * platform_data goes to spi_device.dev.platform_data, 1244 * platform_data goes to spi_device.dev.platform_data,
1243 * controller_data goes to spi_device.controller_data, 1245 * controller_data goes to spi_device.controller_data,
1246 * device properties are copied and attached to spi_device,
1244 * irq is copied too 1247 * irq is copied too
1245 */ 1248 */
1246 char modalias[SPI_NAME_SIZE]; 1249 char modalias[SPI_NAME_SIZE];
1247 const void *platform_data; 1250 const void *platform_data;
1251 const struct property_entry *properties;
1248 void *controller_data; 1252 void *controller_data;
1249 int irq; 1253 int irq;
1250 1254