Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Linaro Ltd. |
| 3 | * Copyright (c) 2013 Hisilicon Limited. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/clk.h> |
| 14 | #include <linux/mmc/host.h> |
| 15 | #include <linux/mmc/dw_mmc.h> |
| 16 | #include <linux/of_address.h> |
| 17 | |
| 18 | #include "dw_mmc.h" |
| 19 | #include "dw_mmc-pltfm.h" |
| 20 | |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 21 | static void dw_mci_k3_set_ios(struct dw_mci *host, struct mmc_ios *ios) |
| 22 | { |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 23 | int ret; |
| 24 | |
Zhangfei Gao | 0e66244 | 2014-01-13 17:14:29 +0800 | [diff] [blame] | 25 | ret = clk_set_rate(host->ciu_clk, ios->clock); |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 26 | if (ret) |
Zhangfei Gao | 0e66244 | 2014-01-13 17:14:29 +0800 | [diff] [blame] | 27 | dev_warn(host->dev, "failed to set rate %uHz\n", ios->clock); |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 28 | |
| 29 | host->bus_hz = clk_get_rate(host->ciu_clk); |
| 30 | } |
| 31 | |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 32 | static const struct dw_mci_drv_data k3_drv_data = { |
| 33 | .set_ios = dw_mci_k3_set_ios, |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static const struct of_device_id dw_mci_k3_match[] = { |
| 37 | { .compatible = "hisilicon,hi4511-dw-mshc", .data = &k3_drv_data, }, |
| 38 | {}, |
| 39 | }; |
| 40 | MODULE_DEVICE_TABLE(of, dw_mci_k3_match); |
| 41 | |
| 42 | static int dw_mci_k3_probe(struct platform_device *pdev) |
| 43 | { |
| 44 | const struct dw_mci_drv_data *drv_data; |
| 45 | const struct of_device_id *match; |
| 46 | |
| 47 | match = of_match_node(dw_mci_k3_match, pdev->dev.of_node); |
| 48 | drv_data = match->data; |
| 49 | |
| 50 | return dw_mci_pltfm_register(pdev, drv_data); |
| 51 | } |
| 52 | |
| 53 | static int dw_mci_k3_suspend(struct device *dev) |
| 54 | { |
| 55 | struct dw_mci *host = dev_get_drvdata(dev); |
| 56 | int ret; |
| 57 | |
| 58 | ret = dw_mci_suspend(host); |
| 59 | if (!ret) |
| 60 | clk_disable_unprepare(host->ciu_clk); |
| 61 | |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | static int dw_mci_k3_resume(struct device *dev) |
| 66 | { |
| 67 | struct dw_mci *host = dev_get_drvdata(dev); |
| 68 | int ret; |
| 69 | |
| 70 | ret = clk_prepare_enable(host->ciu_clk); |
| 71 | if (ret) { |
| 72 | dev_err(host->dev, "failed to enable ciu clock\n"); |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | return dw_mci_resume(host); |
| 77 | } |
| 78 | |
Wei Yongjun | 85136b7 | 2014-01-14 10:03:33 +0800 | [diff] [blame] | 79 | static SIMPLE_DEV_PM_OPS(dw_mci_k3_pmops, dw_mci_k3_suspend, dw_mci_k3_resume); |
Zhangfei Gao | 036f29d | 2014-01-09 22:35:11 +0800 | [diff] [blame] | 80 | |
| 81 | static struct platform_driver dw_mci_k3_pltfm_driver = { |
| 82 | .probe = dw_mci_k3_probe, |
| 83 | .remove = dw_mci_pltfm_remove, |
| 84 | .driver = { |
| 85 | .name = "dwmmc_k3", |
| 86 | .of_match_table = dw_mci_k3_match, |
| 87 | .pm = &dw_mci_k3_pmops, |
| 88 | }, |
| 89 | }; |
| 90 | |
| 91 | module_platform_driver(dw_mci_k3_pltfm_driver); |
| 92 | |
| 93 | MODULE_DESCRIPTION("K3 Specific DW-MSHC Driver Extension"); |
| 94 | MODULE_LICENSE("GPL v2"); |
| 95 | MODULE_ALIAS("platform:dwmmc-k3"); |