From patchwork Mon Mar 15 16:26:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 85994 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2FGQTaT015186 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 15 Mar 2010 16:27:05 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1NrD7d-0004dL-6o; Mon, 15 Mar 2010 16:26:29 +0000 Received: from sfi-mx-3.v28.ch3.sourceforge.com ([172.29.28.123] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1NrD7b-0004cv-Pd for spi-devel-general@lists.sourceforge.net; Mon, 15 Mar 2010 16:26:27 +0000 Received-SPF: pass (sfi-mx-3.v28.ch3.sourceforge.com: domain of gmail.com designates 209.85.220.214 as permitted sender) client-ip=209.85.220.214; envelope-from=mika.westerberg@gmail.com; helo=mail-fx0-f214.google.com; Received: from mail-fx0-f214.google.com ([209.85.220.214]) by sfi-mx-3.v28.ch3.sourceforge.com with esmtp (Exim 4.69) id 1NrD7a-00015w-G5 for spi-devel-general@lists.sourceforge.net; Mon, 15 Mar 2010 16:26:27 +0000 Received: by fxm6 with SMTP id 6so5276878fxm.2 for ; Mon, 15 Mar 2010 09:26:19 -0700 (PDT) Received: by 10.223.5.81 with SMTP id 17mr754937fau.3.1268670379516; Mon, 15 Mar 2010 09:26:19 -0700 (PDT) Received: from localhost.localdomain (a88-115-42-115.elisa-laajakaista.fi [88.115.42.115]) by mx.google.com with ESMTPS id z10sm7344413fka.31.2010.03.15.09.26.18 (version=SSLv3 cipher=RC4-MD5); Mon, 15 Mar 2010 09:26:19 -0700 (PDT) From: Mika Westerberg To: spi-devel-general@lists.sourceforge.net Date: Mon, 15 Mar 2010 18:26:09 +0200 Message-Id: X-Mailer: git-send-email 1.5.6.5 X-Spam-Score: -1.5 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.0 DKIM_VERIFIED Domain Keys Identified Mail: signature passes verification 0.0 DKIM_SIGNED Domain Keys Identified Mail: message has a signature X-Headers-End: 1NrD7a-00015w-G5 Cc: linux-arm-kernel@lists.infradead.org Subject: [spi-devel-general] [PATCH 0/3] spi: driver for Cirrus EP93xx SPI controller X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 15 Mar 2010 16:27:06 +0000 (UTC) diff --git a/arch/arm/mach-ep93xx/ts72xx.c b/arch/arm/mach-ep93xx/ts72xx.c index fac1ec7..425225a 100644 --- a/arch/arm/mach-ep93xx/ts72xx.c +++ b/arch/arm/mach-ep93xx/ts72xx.c @@ -14,11 +14,15 @@ #include #include #include +#include #include #include +#include +#include #include #include +#include #include #include @@ -190,6 +194,105 @@ static struct ep93xx_eth_data ts72xx_eth_data = { .phy_id = 1, }; +static const struct spi_board_info ts72xx_spi_devices[] __initconst = { + { + .modalias = "mmc_spi", + .max_speed_hz = 10 * 1000 * 1000, + .bus_num = 0, + .chip_select = 1, + .mode = SPI_MODE_0, + }, +}; + +/* + * Mapping of SPI chip selects to GPIO pins. In TS-72xx we have GPIO lines + * 8-15 wired into DIO1 header which can be used as chip selects. + */ +static const unsigned ts72xx_spi_chip_selects[] = { + [0] = EP93XX_GPIO_LINE_EGPIO8, + [1] = EP93XX_GPIO_LINE_EGPIO9, + /* + * Add more here as needed. + */ +}; + +static inline unsigned cs_to_gpio(unsigned cs) +{ + BUG_ON(cs >= ARRAY_SIZE(ts72xx_spi_chip_selects)); + return ts72xx_spi_chip_selects[cs]; +} + +static void ts72xx_spi_cs_control(unsigned cs, unsigned value, void *data) +{ + (void)data; + gpio_set_value(cs_to_gpio(cs), value); +} + +static struct ep93xx_spi_info ts72xx_spi_info = { + .num_chipselect = ARRAY_SIZE(ts72xx_spi_chip_selects), + .cs_control = ts72xx_spi_cs_control, +}; + +/** + * ts72xx_init_spi() - initializes board SPI devices + * + * This function initializes all the SPI devices declared in ts72xx_spi_devices + * array. It also allocates GPIO line as chip selects for each device. Chip + * selects are declared in ts72xx_spi_chip_selects array. + */ +static void __init ts72xx_init_spi(void) +{ + unsigned gpio; + int i, err; + + /* + * Now go through all SPI peripherals that board wants to register + * and acquire gpio for every chip select. + */ + for (i = 0; i < ARRAY_SIZE(ts72xx_spi_devices); i++) { + gpio = cs_to_gpio(ts72xx_spi_devices[i].chip_select); + + err = gpio_request(gpio, "ep93xx-spi"); + if (err) { + pr_err("failed to allocate GPIO%d\n", gpio); + goto fail; + } + + /* + * We default chip selects to be active low. This can be + * changed by the protocol drivers passing SPI_CS_HIGH flag + * to ep93xx-spi driver. The driver then changes the value + * by using info->cs_control(). + */ + err = gpio_direction_output(gpio, 1); + if (err) { + pr_err("failed to configure GPIO%d\n", gpio); + goto fail; + } + } + + err = spi_register_board_info(ts72xx_spi_devices, + ARRAY_SIZE(ts72xx_spi_devices)); + if (err) { + pr_err("failed to register SPI devices\n"); + goto fail; + } + + err = ep93xx_register_spi(&ts72xx_spi_info); + if (err) { + pr_err("failed to register SPI platform device\n"); + goto fail; + } + + return; + +fail: + while (--i >= 0) { + gpio = cs_to_gpio(ts72xx_spi_devices[i].chip_select); + gpio_free(gpio); + } +} + static void __init ts72xx_init_machine(void) { ep93xx_init_devices(); @@ -198,6 +301,7 @@ static void __init ts72xx_init_machine(void) platform_device_register(&ts72xx_wdt_device); ep93xx_register_eth(&ts72xx_eth_data, 1); + ts72xx_init_spi(); } MACHINE_START(TS72XX, "Technologic Systems TS-72xx SBC")