From patchwork Sun Aug 26 11:52:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thomas.abraham@linaro.org X-Patchwork-Id: 10957 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 46C5123EFE for ; Sun, 26 Aug 2012 11:34:31 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id D5E58A18263 for ; Sun, 26 Aug 2012 11:34:07 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id j25so3776090iaf.11 for ; Sun, 26 Aug 2012 04:34:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-gm-message-state; bh=80s4tzu5RYWVHfmpHpmjWn2viszDSfHe7X2fBOpCOVs=; b=Hzwt2I0yI5mcZhnn6NFCGUIcGqhsENA3dekF3XIr15FVMs1ERWMW4Xz15Hup0co36x 2iYLTyfn5UlAanSRMeoxj57C+cF7WvwOHk/xwxrE/6M+wl4PLlU90OHylUC4HSSaeaEs ztspeGD1NkdIA51jW0FldVeUCQrDpyZR+drJFoIO0jdwx4vRXKhyGN1/J0O65Q8oFBvf Scl0pOKOD9bBBLjbpPMffkt0mPi4J7WXcAUzCpoH3VoWF54cyQfTXazuVvy8/ibcU3EZ 7TD4//UfsF6cUji5T0JCsBde92bBS2aZ6zm2FGsJefV3vfvY9JgD6F+h6wjPisZ17UTz g0yg== Received: by 10.42.109.194 with SMTP id m2mr8393232icp.48.1345980870707; Sun, 26 Aug 2012 04:34:30 -0700 (PDT) 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.50.184.232 with SMTP id ex8csp396434igc; Sun, 26 Aug 2012 04:34:30 -0700 (PDT) Received: by 10.66.73.133 with SMTP id l5mr14200426pav.74.1345980870016; Sun, 26 Aug 2012 04:34:30 -0700 (PDT) Received: from mailout3.samsung.com (mailout3.samsung.com. [203.254.224.33]) by mx.google.com with ESMTP id gk6si27213401pbc.185.2012.08.26.04.34.29; Sun, 26 Aug 2012 04:34:30 -0700 (PDT) Received-SPF: neutral (google.com: 203.254.224.33 is neither permitted nor denied by best guess record for domain of thomas.abraham@linaro.org) client-ip=203.254.224.33; Authentication-Results: mx.google.com; spf=neutral (google.com: 203.254.224.33 is neither permitted nor denied by best guess record for domain of thomas.abraham@linaro.org) smtp.mail=thomas.abraham@linaro.org Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M9D004031HCOI10@mailout3.samsung.com>; Sun, 26 Aug 2012 20:34:28 +0900 (KST) X-AuditID: cbfee61b-b7faf6d00000476a-ce-503a09c40f66 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id A8.E9.18282.4C90A305; Sun, 26 Aug 2012 20:34:28 +0900 (KST) Received: from localhost.localdomain ([107.108.73.37]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M9D00AQQ1GN7UA0@mmp1.samsung.com>; Sun, 26 Aug 2012 20:34:28 +0900 (KST) From: Thomas Abraham To: linux-mmc@vger.kernel.org, devicetree-discuss@lists.ozlabs.org Cc: cjb@laptop.org, grant.likely@secretlab.ca, rob.herring@calxeda.com, linux-samsung-soc@vger.kernel.org, kgene.kim@samsung.com, girish.shivananjappa@linaro.org, jh80.chung@samsung.com, tgih.jun@samsung.com, patches@linaro.org Subject: [PATCH v4 8/9] mmc: dw_mmc: add support for implementation specific callbacks Date: Sun, 26 Aug 2012 17:22:06 +0530 Message-id: <1345981927-26359-9-git-send-email-thomas.abraham@linaro.org> X-Mailer: git-send-email 1.6.6.rc2 In-reply-to: <1345981927-26359-1-git-send-email-thomas.abraham@linaro.org> References: <1345981927-26359-1-git-send-email-thomas.abraham@linaro.org> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGJMWRmVeSWpSXmKPExsVy+t9jAd0jnFYBBq86tC2+fD3BZjHl8BcW ByaPO9f2sAUwRnHZpKTmZJalFunbJXBlHP6jVjDPrmLT67WsDYz7jLsYOTkkBEwk1m+axARh i0lcuLeerYuRi0NIYBGjRFfLYkYIp41JYu2v+ywgVWwCBhKPFr5jB7FFBJwklsydwAxSxCzw klFi5q6ZbCAJYYEIiaPPGoEaODhYBFQlTnSEgZi8Ap4S57fyQyxTktjQexRsMaeAl8SNRa1g I4WASo7P+M44gZF3ASPDKkbR1ILkguKk9FwjveLE3OLSvHS95PzcTYxg3z+T3sG4qsHiEKMA B6MSD69AqWWAEGtiWXFl7iFGCQ5mJRHe7/uBQrwpiZVVqUX58UWlOanFhxilOViUxHn5+wwD hATSE0tSs1NTC1KLYLJMHJxSDYxzD0WU7zLbVhmZL9yv62g//UqyiuJazpd7eFTl+WzMXATm P+rqPq1ndsDBKtvx06PQTmsDXo85V6fbX42ubX1m1P6gmb09RsE7JDjoGEMT818zZR/Zq5WM rqdUfc3cDEM3suT1hvsrMG6uVrpW1X1RL7082idPetbCDRtnMCzVbLOsW2emxFKckWioxVxU nAgAFMdNp/kBAAA= X-Gm-Message-State: ALoCoQnmg9zXOGT/3f+NMtc7idtGySAbYq391JaA6Z3YL5d2RepoaMhd8tXJOGPKH5J+V8s2G2Xa The core dw-mshc controller driver can let platform specific implementations of the dw-mshc controller to control the hardware as required by such implementations. This is acheived by invoking implementation specific (optional) callbacks. Define the list of callbacks supported the add invocation points for the same. Signed-off-by: Thomas Abraham --- drivers/mmc/host/dw_mmc-pltfm.c | 12 ++++++++++-- drivers/mmc/host/dw_mmc-pltfm.h | 3 ++- drivers/mmc/host/dw_mmc.c | 36 +++++++++++++++++++++++++++++++++++- drivers/mmc/host/dw_mmc.h | 22 ++++++++++++++++++++++ include/linux/mmc/dw_mmc.h | 4 ++++ 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c index 57df3eb..1b3e6b3 100644 --- a/drivers/mmc/host/dw_mmc-pltfm.c +++ b/drivers/mmc/host/dw_mmc-pltfm.c @@ -23,7 +23,8 @@ #include "dw_mmc.h" -int dw_mci_pltfm_register(struct platform_device *pdev) +int dw_mci_pltfm_register(struct platform_device *pdev, + struct dw_mci_drv_data *drv_data) { struct dw_mci *host; struct resource *regs; @@ -41,6 +42,7 @@ int dw_mci_pltfm_register(struct platform_device *pdev) if (host->irq < 0) return host->irq; + host->drv_data = drv_data; host->dev = &pdev->dev; host->irq_flags = 0; host->pdata = pdev->dev.platform_data; @@ -48,6 +50,12 @@ int dw_mci_pltfm_register(struct platform_device *pdev) if (!host->regs) return -ENOMEM; + if (host->drv_data->init) { + ret = host->drv_data->init(host); + if (ret) + return ret; + } + platform_set_drvdata(pdev, host); ret = dw_mci_probe(host); return ret; @@ -56,7 +64,7 @@ EXPORT_SYMBOL_GPL(dw_mci_pltfm_register); static int dw_mci_pltfm_probe(struct platform_device *pdev) { - return dw_mci_pltfm_register(pdev); + return dw_mci_pltfm_register(pdev, NULL); } int __exit dw_mci_pltfm_remove(struct platform_device *pdev) diff --git a/drivers/mmc/host/dw_mmc-pltfm.h b/drivers/mmc/host/dw_mmc-pltfm.h index 5618608..f226c21 100644 --- a/drivers/mmc/host/dw_mmc-pltfm.h +++ b/drivers/mmc/host/dw_mmc-pltfm.h @@ -12,7 +12,8 @@ #ifndef _DW_MMC_PLTFM_H_ #define _DW_MMC_PLTFM_H_ -extern int dw_mci_pltfm_register(struct platform_device *pdev); +extern int dw_mci_pltfm_register(struct platform_device *pdev, + struct dw_mci_drv_data *drv_data); extern int __exit dw_mci_pltfm_remove(struct platform_device *pdev); extern const struct dev_pm_ops dw_mci_pltfm_pmops; diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index b8ec067..bd51050 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -231,6 +231,7 @@ static void dw_mci_set_timeout(struct dw_mci *host) static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) { struct mmc_data *data; + struct dw_mci_slot *slot = mmc_priv(mmc); u32 cmdr; cmd->error = -EINPROGRESS; @@ -260,6 +261,9 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) cmdr |= SDMMC_CMD_DAT_WR; } + if (slot->host->drv_data->prepare_command) + slot->host->drv_data->prepare_command(slot->host, &cmdr); + return cmdr; } @@ -812,6 +816,9 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) slot->clock = ios->clock; } + if (slot->host->drv_data->set_ios) + slot->host->drv_data->set_ios(slot->host, ios); + switch (ios->power_mode) { case MMC_POWER_UP: set_bit(DW_MMC_CARD_NEED_INIT, &slot->flags); @@ -1813,6 +1820,7 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id) { struct mmc_host *mmc; struct dw_mci_slot *slot; + int ctrl_id, ret; u8 bus_width; mmc = mmc_alloc_host(sizeof(struct dw_mci_slot), host->dev); @@ -1844,6 +1852,14 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id) if (host->pdata->caps) mmc->caps = host->pdata->caps; + if (host->dev->of_node) { + ctrl_id = of_alias_get_id(host->dev->of_node, "mshc"); + if (ctrl_id < 0) + ctrl_id = 0; + } + if (host->drv_data && host->drv_data->caps) + mmc->caps |= host->drv_data->caps[ctrl_id]; + if (host->pdata->caps2) mmc->caps2 = host->pdata->caps2; @@ -1854,6 +1870,14 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id) else bus_width = 1; + if (host->drv_data->setup_bus) { + struct device_node *slot_np; + slot_np = dw_mci_of_find_slot_node(host->dev, slot->id); + ret = host->drv_data->setup_bus(host, slot_np, bus_width); + if (ret) + goto err_setup_bus; + } + switch (bus_width) { case 8: mmc->caps |= MMC_CAP_8_BIT_DATA; @@ -1920,6 +1944,10 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id) queue_work(host->card_workqueue, &host->card_work); return 0; + +err_setup_bus: + mmc_free_host(mmc); + return -EINVAL; } static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id) @@ -2014,7 +2042,7 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) struct dw_mci_board *pdata; struct device *dev = host->dev; struct device_node *np = dev->of_node; - int idx; + int idx, ret; pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) { @@ -2041,6 +2069,12 @@ static struct dw_mci_board *dw_mci_parse_dt(struct dw_mci *host) of_property_read_u32(np, "card-detect-delay", &pdata->detect_delay_ms); + if (host->drv_data->parse_dt) { + ret = host->drv_data->parse_dt(host); + if (ret) + return ERR_PTR(ret); + } + return pdata; } diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h index 15c27e1..a9f045a 100644 --- a/drivers/mmc/host/dw_mmc.h +++ b/drivers/mmc/host/dw_mmc.h @@ -182,4 +182,26 @@ extern int dw_mci_suspend(struct dw_mci *host); extern int dw_mci_resume(struct dw_mci *host); #endif +/** + * dw_mci driver data - dw-mshc implementation specific driver data. + * @caps: mmc subsystem specified capabilities of the controller(s). + * @init: early implementation specific initialization. + * @prepare_command: handle CMD register extensions. + * @set_ios: handle bus specific extensions. + * @parse_dt: parse implementation specific device tree properties. + * @setup_bus: initialize io-interface + * + * Provide controller implementation specific extensions. The usage of this + * data structure is fully optional and usage of each member in this structure + * is optional as well. + */ +struct dw_mci_drv_data { + unsigned long *caps; + int (*init)(struct dw_mci *host); + void (*prepare_command)(struct dw_mci *host, u32 *cmdr); + void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); + int (*parse_dt)(struct dw_mci *host); + int (*setup_bus)(struct dw_mci *host, + struct device_node *slot_np, u8 bus_width); +}; #endif /* _DW_MMC_H_ */ diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h index b72e4aa..6cb043e 100644 --- a/include/linux/mmc/dw_mmc.h +++ b/include/linux/mmc/dw_mmc.h @@ -78,6 +78,8 @@ struct mmc_data; * @data_offset: Set the offset of DATA register according to VERID. * @dev: Device associated with the MMC controller. * @pdata: Platform data associated with the MMC controller. + * @drv_data: Driver specific data for identified variant of the controller + * @priv: Implementation defined private data. * @biu_clk: Pointer to bus interface unit clock instance. * @ciu_clk: Pointer to card interface unit clock instance. * @slot: Slots sharing this MMC controller. @@ -160,6 +162,8 @@ struct dw_mci { u16 data_offset; struct device *dev; struct dw_mci_board *pdata; + struct dw_mci_drv_data *drv_data; + void *priv; struct clk *biu_clk; struct clk *ciu_clk; struct dw_mci_slot *slot[MAX_MCI_SLOTS];