@@ -562,30 +562,13 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
EXPORT_SYMBOL_GPL(spi_alloc_master);
/**
- * spi_register_master - register SPI master controller
- * @master: initialized master, originally from spi_alloc_master()
- * Context: can sleep
- *
- * SPI master controllers connect to their drivers using some non-SPI bus,
- * such as the platform bus. The final stage of probe() in that code
- * includes calling spi_register_master() to hook up to this SPI bus glue.
- *
- * SPI controllers use board specific (often SOC specific) bus numbers,
- * and board-specific addressing for SPI devices combines those numbers
- * with chip select numbers. Since SPI does not directly support dynamic
- * device identification, boards need configuration tables telling which
- * chip is at which address.
- *
- * This must be called from context that can sleep. It returns zero on
- * success, else a negative error code (dropping the master's refcount).
- * After a successful return, the caller is responsible for calling
- * spi_unregister_master().
+ * spi_prepare_master() - initialize the SPI master structure
+ * @master: the master struct to initialize
*/
-int spi_register_master(struct spi_master *master)
+static int spi_prepare_master(struct spi_master *master)
{
static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1);
struct device *dev = master->dev.parent;
- struct boardinfo *bi;
int status = -ENODEV;
int dynamic = 0;
@@ -611,15 +594,26 @@ int spi_register_master(struct spi_master *master)
mutex_init(&master->bus_lock_mutex);
master->bus_lock_flag = 0;
- /* register the device, then userspace will see it.
+ /*
+ * register the device, then userspace will see it.
* registration fails if the bus ID is in use.
*/
dev_set_name(&master->dev, "spi%u", master->bus_num);
status = device_add(&master->dev);
if (status < 0)
- goto done;
+ return status;
dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev),
dynamic ? " (dynamic)" : "");
+ return 0;
+}
+
+/**
+ * spi_finalize_master() - finalize the SPI master, adding devices
+ * @master: the master to finalize
+ */
+static void spi_finalize_master(struct spi_master *master)
+{
+ struct boardinfo *bi;
mutex_lock(&board_lock);
list_add_tail(&master->list, &spi_master_list);
@@ -627,12 +621,40 @@ int spi_register_master(struct spi_master *master)
spi_match_master_to_boardinfo(master, &bi->board_info);
mutex_unlock(&board_lock);
- status = 0;
-
/* Register devices from the device tree */
of_register_spi_devices(master);
-done:
- return status;
+}
+
+/**
+ * spi_register_master - register SPI master controller
+ * @master: initialized master, originally from spi_alloc_master()
+ * Context: can sleep
+ *
+ * SPI master controllers connect to their drivers using some non-SPI bus,
+ * such as the platform bus. The final stage of probe() in that code
+ * includes calling spi_register_master() to hook up to this SPI bus glue.
+ *
+ * SPI controllers use board specific (often SOC specific) bus numbers,
+ * and board-specific addressing for SPI devices combines those numbers
+ * with chip select numbers. Since SPI does not directly support dynamic
+ * device identification, boards need configuration tables telling which
+ * chip is at which address.
+ *
+ * This must be called from context that can sleep. It returns zero on
+ * success, else a negative error code (dropping the master's refcount).
+ * After a successful return, the caller is responsible for calling
+ * spi_unregister_master().
+ */
+int spi_register_master(struct spi_master *master)
+{
+ int ret;
+
+ ret = spi_prepare_master(master);
+ if (ret)
+ return ret;
+ spi_finalize_master(master);
+
+ return 0;
}
EXPORT_SYMBOL_GPL(spi_register_master);