Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3756842imm; Tue, 17 Jul 2018 09:46:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdPhlauuotDNGeZz0cToxyCDJqbvXdM2RmaVavtZLe97/QA1HmEW8pWWDNxNpCtcrSGx0vJ X-Received: by 2002:a17:902:8506:: with SMTP id bj6-v6mr2332754plb.210.1531845983274; Tue, 17 Jul 2018 09:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531845983; cv=none; d=google.com; s=arc-20160816; b=T/AOCZft7Qcz7ZZt3KICddUUR+Itmx1ntJTqGfQeqbYF9AV0lChwDTfbsUyTDJYwls 37J49MSpC9lkZeFKXTHxceD6WsHWL0Kz0bRsEsPylHwXYhG2VOjHaSXdYHJzQQlOJV4+ LAdakwTTdKPrffTaZEfvUZ253oWoN6Yavma89UP4Pd1ltsNa0WFsicpTlXaC152lmUyC QMvJKGhhFLLED63xkS5GbnjQIIL82zMlV5ZkVk9Ny92TABr153wNeaOwvFRG8ewR0HvU Dm7XqcRCryGO1qMkSAWnz3B9ZsoLdoFfOR6VLtIcbmFF34IAQhAJLIMauX9LQrbhjPKF 3Blw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=u9ga8HTmKGK6Pe1u61T+sGtdMHnMAPOGEgXgguJFlb4=; b=T/bUaobW/Kmx0nxtI89lzw+aMl6SWHIJTmvOcANbq5toYuK3hOjLgcPX1fkTRwQGi0 MLo+5Txkit0f2DvmIHFrAv8g6tgcRQjar/lbz6rcrKGPRAq2aBF8FkJhMya4Ml5s3Tsm DMdfxHW0TDV2QcfPkRmzlggtmvJk9OHoEwl8iTtZLPlp+Kz5Q3F7NtPwFA9p2P6bej4v G3IS1uFUf3eQOD8oiL0xte8030fLmQHVkqsoX/cwFPOrVvedxd5bBU5whu00zYMrpitl OaTApDot7LNSP2i0WzXK6rQp2KL8VgYg6w/a5sf3XRhQ2EajmwABuYwakEf1y5NTBAYu Bdjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=bGMWN+NN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17-v6si1226660pgp.289.2018.07.17.09.46.08; Tue, 17 Jul 2018 09:46:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=bGMWN+NN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729838AbeGQRSy (ORCPT + 99 others); Tue, 17 Jul 2018 13:18:54 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:41206 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729710AbeGQRSy (ORCPT ); Tue, 17 Jul 2018 13:18:54 -0400 Received: by mail-qt0-f196.google.com with SMTP id e19-v6so1454414qtp.8 for ; Tue, 17 Jul 2018 09:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id; bh=u9ga8HTmKGK6Pe1u61T+sGtdMHnMAPOGEgXgguJFlb4=; b=bGMWN+NNX+IgRHeO5UYbfvNxFs+46oepM5wDqSvtOy+DaRoR/mPV9cT+iAN2RaCW9n AJ1QQt7mbkWZznDirhlMOU7i0LWUL9PWyHpf2vAa5UjnR86Ssk8XXHQaFNwAn0tiXMSz KKAtCpiEEhQkcUd/ADEC0BCyari+3tjwVlDQI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=u9ga8HTmKGK6Pe1u61T+sGtdMHnMAPOGEgXgguJFlb4=; b=hbIwD9IPAprDac9yemccAi4IMa19EiE0j2pX3udhQSXcwJVXMoNRzAyBGnVyTcUAZs FK4pUkvplOeSEVO3NPBwfIK0clAbinB0Ed2tdE8LrgGOx0TEEC3+ZozrQSRAo7yyRlq2 /ET3pa+tV0eAWTkGAbsidQ6EL5Wv4jF6VZjJy0ESwo3EPGeM+D7Tb2h/avTSPKHefk7q /N+t1jql7SH2bTLpVWgcGcEsBNxl7lrUqHj690PBI/0fmKTEnzqLshZTSsgVteaVvqSV Feu3GZU5DMZdbAPOS93NIgbf7dQThB67ZVMFbwebANGW4Kq62PZrR2pZ+GLmGO1p5iXm MsGA== X-Gm-Message-State: AOUpUlGOxyNm2iKzNPv3Z50GcOpe+MtDmW5UwXlTxvGC51BZR9865s0v 3g7q3i6WLJ+L0Q/neX/1LvWjsg== X-Received: by 2002:a0c:f643:: with SMTP id s3-v6mr2585073qvm.131.1531845922707; Tue, 17 Jul 2018 09:45:22 -0700 (PDT) Received: from mannams-OptiPlex-7010.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 8-v6sm1040624qtz.46.2018.07.17.09.45.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jul 2018 09:45:21 -0700 (PDT) From: Srinath Mannam To: Ulf Hansson , Adrian Hunter , Ray Jui , Scott Branden , Jon Mason Cc: bcm-kernel-feedback-list@broadcom.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Srinath Mannam Subject: [PATCH] mmc: host: iproc: Add ACPI support to IPROC SDHCI Date: Tue, 17 Jul 2018 22:15:07 +0530 Message-Id: <1531845907-26213-1-git-send-email-srinath.mannam@broadcom.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add ACPI support to all IPROC SDHCI varients Signed-off-by: Srinath Mannam Reviewed-by: Ray Jui Reviewed-by: Scott Branden Reviewed-by: Vladimir Olovyannikov --- drivers/mmc/host/Kconfig | 1 + drivers/mmc/host/sdhci-iproc.c | 187 ++++++++++++++++++++++++++++------------- 2 files changed, 128 insertions(+), 60 deletions(-) diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index 0581c19..bc6702e 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -334,6 +334,7 @@ config MMC_SDHCI_IPROC tristate "SDHCI support for the BCM2835 & iProc SD/MMC Controller" depends on ARCH_BCM2835 || ARCH_BCM_IPROC || COMPILE_TEST depends on MMC_SDHCI_PLTFM + depends on OF || ACPI default ARCH_BCM_IPROC select MMC_SDHCI_IO_ACCESSORS help diff --git a/drivers/mmc/host/sdhci-iproc.c b/drivers/mmc/host/sdhci-iproc.c index d0e83db..7c5c923 100644 --- a/drivers/mmc/host/sdhci-iproc.c +++ b/drivers/mmc/host/sdhci-iproc.c @@ -15,6 +15,7 @@ * iProc SDHCI platform driver */ +#include #include #include #include @@ -162,9 +163,19 @@ static void sdhci_iproc_writeb(struct sdhci_host *host, u8 val, int reg) sdhci_iproc_writel(host, newval, reg & ~3); } +static unsigned int sdhci_iproc_get_max_clock(struct sdhci_host *host) +{ + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + + if (pltfm_host->clk) + return sdhci_pltfm_clk_get_max_clock(host); + else + return pltfm_host->clock; +} + static const struct sdhci_ops sdhci_iproc_ops = { .set_clock = sdhci_set_clock, - .get_max_clock = sdhci_pltfm_clk_get_max_clock, + .get_max_clock = sdhci_iproc_get_max_clock, .set_bus_width = sdhci_set_bus_width, .reset = sdhci_reset, .set_uhs_signaling = sdhci_set_uhs_signaling, @@ -178,34 +189,24 @@ static const struct sdhci_ops sdhci_iproc_32only_ops = { .write_w = sdhci_iproc_writew, .write_b = sdhci_iproc_writeb, .set_clock = sdhci_set_clock, - .get_max_clock = sdhci_pltfm_clk_get_max_clock, + .get_max_clock = sdhci_iproc_get_max_clock, .set_bus_width = sdhci_set_bus_width, .reset = sdhci_reset, .set_uhs_signaling = sdhci_set_uhs_signaling, }; +enum sdhci_pltfm_type { + SDHCI_PLTFM_IPROC_CYGNUS, + SDHCI_PLTFM_IPROC, + SDHCI_PLTFM_BCM2835, +}; + static const struct sdhci_pltfm_data sdhci_iproc_cygnus_pltfm_data = { .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK, .quirks2 = SDHCI_QUIRK2_ACMD23_BROKEN | SDHCI_QUIRK2_HOST_OFF_CARD_ON, .ops = &sdhci_iproc_32only_ops, }; -static const struct sdhci_iproc_data iproc_cygnus_data = { - .pdata = &sdhci_iproc_cygnus_pltfm_data, - .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT) - & SDHCI_MAX_BLOCK_MASK) | - SDHCI_CAN_VDD_330 | - SDHCI_CAN_VDD_180 | - SDHCI_CAN_DO_SUSPEND | - SDHCI_CAN_DO_HISPD | - SDHCI_CAN_DO_ADMA2 | - SDHCI_CAN_DO_SDMA, - .caps1 = SDHCI_DRIVER_TYPE_C | - SDHCI_DRIVER_TYPE_D | - SDHCI_SUPPORT_DDR50, - .mmc_caps = MMC_CAP_1_8V_DDR, -}; - static const struct sdhci_pltfm_data sdhci_iproc_pltfm_data = { .quirks = SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12, @@ -213,21 +214,6 @@ static const struct sdhci_pltfm_data sdhci_iproc_pltfm_data = { .ops = &sdhci_iproc_ops, }; -static const struct sdhci_iproc_data iproc_data = { - .pdata = &sdhci_iproc_pltfm_data, - .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT) - & SDHCI_MAX_BLOCK_MASK) | - SDHCI_CAN_VDD_330 | - SDHCI_CAN_VDD_180 | - SDHCI_CAN_DO_SUSPEND | - SDHCI_CAN_DO_HISPD | - SDHCI_CAN_DO_ADMA2 | - SDHCI_CAN_DO_SDMA, - .caps1 = SDHCI_DRIVER_TYPE_C | - SDHCI_DRIVER_TYPE_D | - SDHCI_SUPPORT_DDR50, -}; - static const struct sdhci_pltfm_data sdhci_bcm2835_pltfm_data = { .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION | SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK | @@ -237,38 +223,104 @@ static const struct sdhci_pltfm_data sdhci_bcm2835_pltfm_data = { .ops = &sdhci_iproc_32only_ops, }; -static const struct sdhci_iproc_data bcm2835_data = { - .pdata = &sdhci_bcm2835_pltfm_data, - .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT) - & SDHCI_MAX_BLOCK_MASK) | - SDHCI_CAN_VDD_330 | - SDHCI_CAN_DO_HISPD, - .caps1 = SDHCI_DRIVER_TYPE_A | - SDHCI_DRIVER_TYPE_C, - .mmc_caps = 0x00000000, +static const struct sdhci_iproc_data sdhci_iproc_data_list[] = { + [SDHCI_PLTFM_IPROC_CYGNUS] = { + /* SDHCI IPROC CYGNUS */ + .pdata = &sdhci_iproc_cygnus_pltfm_data, + .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT) + & SDHCI_MAX_BLOCK_MASK) | + SDHCI_CAN_VDD_330 | + SDHCI_CAN_VDD_180 | + SDHCI_CAN_DO_SUSPEND | + SDHCI_CAN_DO_HISPD | + SDHCI_CAN_DO_ADMA2 | + SDHCI_CAN_DO_SDMA, + .caps1 = SDHCI_DRIVER_TYPE_C | + SDHCI_DRIVER_TYPE_D | + SDHCI_SUPPORT_DDR50, + .mmc_caps = MMC_CAP_1_8V_DDR, + }, + [SDHCI_PLTFM_IPROC] = { + /* SDHCI IPROC */ + .pdata = &sdhci_iproc_pltfm_data, + .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT) + & SDHCI_MAX_BLOCK_MASK) | + SDHCI_CAN_VDD_330 | + SDHCI_CAN_VDD_180 | + SDHCI_CAN_DO_SUSPEND | + SDHCI_CAN_DO_HISPD | + SDHCI_CAN_DO_ADMA2 | + SDHCI_CAN_DO_SDMA, + .caps1 = SDHCI_DRIVER_TYPE_C | + SDHCI_DRIVER_TYPE_D | + SDHCI_SUPPORT_DDR50, + }, + [SDHCI_PLTFM_BCM2835] = { + /* SDHCI BCM2835 */ + .pdata = &sdhci_bcm2835_pltfm_data, + .caps = ((0x1 << SDHCI_MAX_BLOCK_SHIFT) + & SDHCI_MAX_BLOCK_MASK) | + SDHCI_CAN_VDD_330 | + SDHCI_CAN_DO_HISPD, + .caps1 = SDHCI_DRIVER_TYPE_A | + SDHCI_DRIVER_TYPE_C, + .mmc_caps = 0x00000000, + + }, }; static const struct of_device_id sdhci_iproc_of_match[] = { - { .compatible = "brcm,bcm2835-sdhci", .data = &bcm2835_data }, - { .compatible = "brcm,sdhci-iproc-cygnus", .data = &iproc_cygnus_data}, - { .compatible = "brcm,sdhci-iproc", .data = &iproc_data }, + { + .compatible = "brcm,bcm2835-sdhci", + .data = (void *)SDHCI_PLTFM_BCM2835 + }, + { + .compatible = "brcm,sdhci-iproc-cygnus", + .data = (void *)SDHCI_PLTFM_IPROC_CYGNUS + }, + { + .compatible = "brcm,sdhci-iproc", + .data = (void *)SDHCI_PLTFM_IPROC + }, { } }; MODULE_DEVICE_TABLE(of, sdhci_iproc_of_match); +static const struct acpi_device_id sdhci_iproc_acpi_ids[] = { + { .id = "BRCM5871", .driver_data = SDHCI_PLTFM_IPROC_CYGNUS }, + { .id = "BRCM5872", .driver_data = SDHCI_PLTFM_IPROC }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(acpi, sdhci_iproc_acpi_ids); + static int sdhci_iproc_probe(struct platform_device *pdev) { + struct device *dev = &pdev->dev; const struct of_device_id *match; + const struct acpi_device_id *acpi_id; const struct sdhci_iproc_data *iproc_data; struct sdhci_host *host; struct sdhci_iproc_host *iproc_host; struct sdhci_pltfm_host *pltfm_host; int ret; + enum sdhci_pltfm_type plat_type; + + if (dev->of_node) { + match = of_match_device(sdhci_iproc_of_match, dev); + if (match) + plat_type = (enum sdhci_pltfm_type)match->data; + else + return -ENODEV; + } else if (has_acpi_companion(dev)) { + acpi_id = acpi_match_device(sdhci_iproc_acpi_ids, dev); + if (acpi_id) + plat_type = (enum sdhci_pltfm_type)acpi_id->driver_data; + else + return -ENODEV; + } else + return -ENODEV; - match = of_match_device(sdhci_iproc_of_match, &pdev->dev); - if (!match) - return -EINVAL; - iproc_data = match->data; + iproc_data = &sdhci_iproc_data_list[plat_type]; host = sdhci_pltfm_init(pdev, iproc_data->pdata, sizeof(*iproc_host)); if (IS_ERR(host)) @@ -284,17 +336,30 @@ static int sdhci_iproc_probe(struct platform_device *pdev) host->mmc->caps |= iproc_host->data->mmc_caps; - pltfm_host->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(pltfm_host->clk)) { - ret = PTR_ERR(pltfm_host->clk); - goto err; - } - ret = clk_prepare_enable(pltfm_host->clk); - if (ret) { - dev_err(&pdev->dev, "failed to enable host clk\n"); - goto err; + if (dev->of_node) { + pltfm_host->clk = devm_clk_get(dev, NULL); + if (IS_ERR(pltfm_host->clk)) { + ret = PTR_ERR(pltfm_host->clk); + goto err; + } + ret = clk_prepare_enable(pltfm_host->clk); + if (ret) { + dev_err(dev, "failed to enable host clk\n"); + goto err; + } + } else if (has_acpi_companion(dev)) { + /* + * When Driver probe with ACPI device, clock devices + * are not available, so sdhci clock get from + * clock-frequency property given in _DSD object. + */ + device_property_read_u32(dev, "clock-frequency", + &pltfm_host->clock); + if (!pltfm_host->clock) { + ret = -ENODEV; + goto err; + } } - if (iproc_host->data->pdata->quirks & SDHCI_QUIRK_MISSING_CAPS) { host->caps = iproc_host->data->caps; host->caps1 = iproc_host->data->caps1; @@ -307,7 +372,8 @@ static int sdhci_iproc_probe(struct platform_device *pdev) return 0; err_clk: - clk_disable_unprepare(pltfm_host->clk); + if (dev->of_node) + clk_disable_unprepare(pltfm_host->clk); err: sdhci_pltfm_free(pdev); return ret; @@ -317,6 +383,7 @@ static struct platform_driver sdhci_iproc_driver = { .driver = { .name = "sdhci-iproc", .of_match_table = sdhci_iproc_of_match, + .acpi_match_table = ACPI_PTR(sdhci_iproc_acpi_ids), .pm = &sdhci_pltfm_pmops, }, .probe = sdhci_iproc_probe, -- 2.7.4