From patchwork Mon Jun 8 13:22:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 49619 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2C4AA214B2 for ; Mon, 8 Jun 2015 13:24:46 +0000 (UTC) Received: by lbbqq2 with SMTP id qq2sf33581427lbb.0 for ; Mon, 08 Jun 2015 06:24:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id:cc :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=XcSStqc5r09uAvSCP+xvLtms9XCqRant6Pb9R7D1PmY=; b=AyG0L90N5dtx3CqKaO/Udqc4+SG1I+deLRoRkhPnqgjgU3RKWV/8DPybeWqgNJpXCN afJRMYCY6jUUXI+6HcvTC5HB5ghD9ugG8PKKPQnTQQF1sg42YHGQl5rC+wcUTP8knFWB rXJRW+Kc3GQhqXzJTcofBGsAQKygHz1lKy6kQMTMfNNPI3o9lJXjNp31v5qeMU7HM+Mg e7ug+JD6Wspxv32ia0XFZINozQNXdWaLPyQIuGVYtWBIszyY7AvtZ35ntjRwc7Tb45BN kPnJtTZEkXeDo9yCNlyTJWo5LHTXnRl0ORlFmf3c8zrkoXg6ijkIqoPrs/QzBM8oK02H IbzA== X-Gm-Message-State: ALoCoQkeyatw0S0/OaN8crQydjK5iZZK9BOXS8DXhGTduc6qh1FbBy0K+UZt+x79jCGWIfC/E+br X-Received: by 10.112.166.137 with SMTP id zg9mr17095528lbb.11.1433769885179; Mon, 08 Jun 2015 06:24:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.227 with SMTP id lf3ls671731lab.93.gmail; Mon, 08 Jun 2015 06:24:44 -0700 (PDT) X-Received: by 10.152.6.105 with SMTP id z9mr16360818laz.98.1433769884899; Mon, 08 Jun 2015 06:24:44 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id a8si2725327lbs.52.2015.06.08.06.24.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 06:24:44 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbtu8 with SMTP id tu8so64654139lbb.2 for ; Mon, 08 Jun 2015 06:24:44 -0700 (PDT) X-Received: by 10.152.225.166 with SMTP id rl6mr16752566lac.36.1433769884783; Mon, 08 Jun 2015 06:24:44 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1864033lbb; Mon, 8 Jun 2015 06:24:43 -0700 (PDT) X-Received: by 10.66.102.37 with SMTP id fl5mr30040086pab.88.1433769882984; Mon, 08 Jun 2015 06:24:42 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id d16si4096336pbu.156.2015.06.08.06.24.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 06:24:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z1x1F-0005Qc-HR; Mon, 08 Jun 2015 13:23:13 +0000 Received: from mail-la0-f52.google.com ([209.85.215.52]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z1x1C-0005LG-43 for linux-arm-kernel@lists.infradead.org; Mon, 08 Jun 2015 13:23:11 +0000 Received: by laar3 with SMTP id r3so47720154laa.3 for ; Mon, 08 Jun 2015 06:22:46 -0700 (PDT) X-Received: by 10.112.131.98 with SMTP id ol2mr17064799lbb.56.1433769766664; Mon, 08 Jun 2015 06:22:46 -0700 (PDT) Received: from localhost.localdomain (c-d37f71d5.01-192-6c756e10.cust.bredbandsbolaget.se. [213.113.127.211]) by mx.google.com with ESMTPSA id f5sm645768lbd.41.2015.06.08.06.22.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jun 2015 06:22:45 -0700 (PDT) From: Linus Walleij To: arm@kernel.org Subject: [PATCH] ARM: ep93xx: simone: support for SPI-based MMC/SD cards Date: Mon, 8 Jun 2015 15:22:39 +0200 Message-Id: <1433769759-6414-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 1.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150608_062310_364777_3C8954DA X-CRM114-Status: GOOD ( 19.31 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.52 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.52 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Mika Westerberg , Linus Walleij , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: linus.walleij@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Mika Westerberg This includes setting up EGPIOs 0 and 9 for card detection and chip select respectively. This patch is needed to mount a root filesystem on the SPI-based MMC card reader found on the Sim.One. Signed-off-by: Mika Westerberg Signed-off-by: Linus Walleij --- Hi ARM SoC guys, please apply this patch directly to ARM SoC if you're OK with it. It makes my Sim.One platform mount root successfully from SD/MMC which is kind of a prerequisite for work that I need to be doing to clean up this platform a bit. --- arch/arm/mach-ep93xx/simone.c | 135 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c index 36f22c1a31fe..3c950f5864f3 100644 --- a/arch/arm/mach-ep93xx/simone.c +++ b/arch/arm/mach-ep93xx/simone.c @@ -20,9 +20,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include -#include #include #include @@ -40,6 +45,132 @@ static struct ep93xxfb_mach_info __initdata simone_fb_info = { .flags = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING, }; +/* + * GPIO lines used for MMC card detection. + */ +#define MMC_CARD_DETECT_GPIO EP93XX_GPIO_LINE_EGPIO0 + +/* + * Up to v1.3, the Sim.One used SFRMOUT as SD card chip select, but this goes + * low between multi-message command blocks. From v1.4, it uses a GPIO instead. + * v1.3 parts will still work, since the signal on SFRMOUT is automatic. + */ +#define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO1 + +/* + * MMC SPI chip select GPIO handling. If you are using SFRMOUT (SFRM1) signal, + * you can leave these empty and pass NULL as .controller_data. + */ + +static int simone_mmc_spi_setup(struct spi_device *spi) +{ + unsigned int gpio = MMC_CHIP_SELECT_GPIO; + int err; + + err = gpio_request(gpio, spi->modalias); + if (err) + return err; + + err = gpio_direction_output(gpio, 1); + if (err) { + gpio_free(gpio); + return err; + } + + return 0; +} + +static void simone_mmc_spi_cleanup(struct spi_device *spi) +{ + unsigned int gpio = MMC_CHIP_SELECT_GPIO; + + gpio_set_value(gpio, 1); + gpio_direction_input(gpio); + gpio_free(gpio); +} + +static void simone_mmc_spi_cs_control(struct spi_device *spi, int value) +{ + gpio_set_value(MMC_CHIP_SELECT_GPIO, value); +} + +static struct ep93xx_spi_chip_ops simone_mmc_spi_ops = { + .setup = simone_mmc_spi_setup, + .cleanup = simone_mmc_spi_cleanup, + .cs_control = simone_mmc_spi_cs_control, +}; + +/* + * MMC card detection GPIO setup. + */ + +static int simone_mmc_spi_init(struct device *dev, + irqreturn_t (*irq_handler)(int, void *), void *mmc) +{ + unsigned int gpio = MMC_CARD_DETECT_GPIO; + int irq, err; + + err = gpio_request(gpio, dev_name(dev)); + if (err) + return err; + + err = gpio_direction_input(gpio); + if (err) + goto fail; + + irq = gpio_to_irq(gpio); + if (irq < 0) + goto fail; + + err = request_irq(irq, irq_handler, IRQF_TRIGGER_FALLING, + "MMC card detect", mmc); + if (err) + goto fail; + + printk(KERN_INFO "%s: using irq %d for MMC card detection\n", + dev_name(dev), irq); + + return 0; +fail: + gpio_free(gpio); + return err; +} + +static void simone_mmc_spi_exit(struct device *dev, void *mmc) +{ + unsigned int gpio = MMC_CARD_DETECT_GPIO; + + free_irq(gpio_to_irq(gpio), mmc); + gpio_free(gpio); +} + +static struct mmc_spi_platform_data simone_mmc_spi_data = { + .init = simone_mmc_spi_init, + .exit = simone_mmc_spi_exit, + .detect_delay = 500, + .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, +}; + +static struct spi_board_info simone_spi_devices[] __initdata = { + { + .modalias = "mmc_spi", + .controller_data = &simone_mmc_spi_ops, + .platform_data = &simone_mmc_spi_data, + /* + * We use 10 MHz even though the maximum is 3.7 MHz. The driver + * will limit it automatically to max. frequency. + */ + .max_speed_hz = 10 * 1000 * 1000, + .bus_num = 0, + .chip_select = 0, + .mode = SPI_MODE_3, + }, +}; + +static struct ep93xx_spi_info simone_spi_info __initdata = { + .num_chipselect = ARRAY_SIZE(simone_spi_devices), +}; + static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = { .sda_pin = EP93XX_GPIO_LINE_EEDAT, .sda_is_open_drain = 0, @@ -74,6 +205,8 @@ static void __init simone_init_machine(void) ep93xx_register_fb(&simone_fb_info); ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, ARRAY_SIZE(simone_i2c_board_info)); + ep93xx_register_spi(&simone_spi_info, simone_spi_devices, + ARRAY_SIZE(simone_spi_devices)); simone_register_audio(); }