From patchwork Thu Feb 2 12:59:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 6574 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 82F2223F03 for ; Thu, 2 Feb 2012 13:00:13 +0000 (UTC) Received: from mail-tul01m020-f180.google.com (mail-tul01m020-f180.google.com [209.85.214.180]) by fiordland.canonical.com (Postfix) with ESMTP id 2C2D0A180D5 for ; Thu, 2 Feb 2012 13:00:13 +0000 (UTC) Received: by obbuo19 with SMTP id uo19so3673391obb.11 for ; Thu, 02 Feb 2012 05:00:12 -0800 (PST) Received: by 10.50.236.5 with SMTP id uq5mr12114063igc.13.1328187612085; Thu, 02 Feb 2012 05:00:12 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.169.210 with SMTP id a18cs50041ibz; Thu, 2 Feb 2012 05:00:11 -0800 (PST) Received: by 10.213.19.212 with SMTP id c20mr1705957ebb.15.1328187610875; Thu, 02 Feb 2012 05:00:10 -0800 (PST) Received: from eu1sys200aog109.obsmtp.com (eu1sys200aog109.obsmtp.com. [207.126.144.127]) by mx.google.com with SMTP id x16si1267986eef.202.2012.02.02.05.00.01 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 02 Feb 2012 05:00:10 -0800 (PST) Received-SPF: neutral (google.com: 207.126.144.127 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.127 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob109.postini.com ([207.126.147.11]) with SMTP ID DSNKTyqI0a/y/ThxBHZrwKcfNP2J04g7yx7s@postini.com; Thu, 02 Feb 2012 13:00:10 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 21417354; Thu, 2 Feb 2012 12:59:54 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B8462259B; Thu, 2 Feb 2012 12:59:54 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 0335F24C075; Thu, 2 Feb 2012 13:59:48 +0100 (CET) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Thu, 2 Feb 2012 13:59:54 +0100 From: Linus Walleij To: Grant Likely , , Mark Brown Cc: Viresh Kumar , Linus Walleij Subject: [PATCH 2/3] spi: split spi_register_master Date: Thu, 2 Feb 2012 13:59:50 +0100 Message-ID: <1328187590-12947-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.8 MIME-Version: 1.0 From: Linus Walleij This splits the spi_register_master() function in two parts, easing the addition of a queued master and making the code somewhat easier to read. Cc: Mark Brown Signed-off-by: Linus Walleij --- drivers/spi/spi.c | 74 ++++++++++++++++++++++++++++++++++------------------ 1 files changed, 48 insertions(+), 26 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index b2ccdea..cd7ecd2 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -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);