diff options
author | Dong Aisheng <aisheng.dong@freescale.com> | 2015-07-22 08:53:06 -0400 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2015-07-24 04:18:37 -0400 |
commit | 91fa4252878afccc9e75edd84f31047899ddd1b7 (patch) | |
tree | 26dcb6e025d5b628874d416bae96a84566457d35 | |
parent | 4800e87a2ee886c1972deb73f057d1a6541edb36 (diff) |
mmc: sdhci-esdhc-imx: move all non dt probe code into one function
This is an incremental fix of commit
e62bd351b("mmc: sdhci-esdhc-imx: Do not break platform data boards").
After commit 8d86e4fcccf6 ("mmc: sdhci-esdhc-imx: Call mmc_of_parse()"),
we do not need to run the check of boarddata->wp_type/cd_type/max_bus_width
again for dt platform since those are already handled by mmc_of_parse().
Current code only exclude the checking of wp_type for dt platform which
does not make sense.
This patch moves all non dt probe code into one function.
Besides, since we only support SD3.0/eMMC HS200 for dt platform, the
support_vsel checking and ultra high speed pinctrl state are also merged
into sdhci_esdhc_imx_probe_dt.
Then we have two separately probe function for dt and non dt type.
This can make the driver probe more clearly.
Signed-off-by: Dong Aisheng <aisheng.dong@freescale.com>
Reviewed-by: Johan Derycke <johan.derycke@barco.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
-rw-r--r-- | drivers/mmc/host/sdhci-esdhc-imx.c | 179 |
1 files changed, 94 insertions, 85 deletions
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c index 48153917ed08..10f03ee027ac 100644 --- a/drivers/mmc/host/sdhci-esdhc-imx.c +++ b/drivers/mmc/host/sdhci-esdhc-imx.c | |||
@@ -878,14 +878,12 @@ static const struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { | |||
878 | static int | 878 | static int |
879 | sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, | 879 | sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, |
880 | struct sdhci_host *host, | 880 | struct sdhci_host *host, |
881 | struct esdhc_platform_data *boarddata) | 881 | struct pltfm_imx_data *imx_data) |
882 | { | 882 | { |
883 | struct device_node *np = pdev->dev.of_node; | 883 | struct device_node *np = pdev->dev.of_node; |
884 | struct esdhc_platform_data *boarddata = &imx_data->boarddata; | ||
884 | int ret; | 885 | int ret; |
885 | 886 | ||
886 | if (!np) | ||
887 | return -ENODEV; | ||
888 | |||
889 | if (of_get_property(np, "non-removable", NULL)) | 887 | if (of_get_property(np, "non-removable", NULL)) |
890 | boarddata->cd_type = ESDHC_CD_PERMANENT; | 888 | boarddata->cd_type = ESDHC_CD_PERMANENT; |
891 | 889 | ||
@@ -917,6 +915,26 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, | |||
917 | 915 | ||
918 | mmc_of_parse_voltage(np, &host->ocr_mask); | 916 | mmc_of_parse_voltage(np, &host->ocr_mask); |
919 | 917 | ||
918 | /* sdr50 and sdr104 needs work on 1.8v signal voltage */ | ||
919 | if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data) && | ||
920 | !IS_ERR(imx_data->pins_default)) { | ||
921 | imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl, | ||
922 | ESDHC_PINCTRL_STATE_100MHZ); | ||
923 | imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl, | ||
924 | ESDHC_PINCTRL_STATE_200MHZ); | ||
925 | if (IS_ERR(imx_data->pins_100mhz) || | ||
926 | IS_ERR(imx_data->pins_200mhz)) { | ||
927 | dev_warn(mmc_dev(host->mmc), | ||
928 | "could not get ultra high speed state, work on normal mode\n"); | ||
929 | /* | ||
930 | * fall back to not support uhs by specify no 1.8v quirk | ||
931 | */ | ||
932 | host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; | ||
933 | } | ||
934 | } else { | ||
935 | host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; | ||
936 | } | ||
937 | |||
920 | /* call to generic mmc_of_parse to support additional capabilities */ | 938 | /* call to generic mmc_of_parse to support additional capabilities */ |
921 | ret = mmc_of_parse(host->mmc); | 939 | ret = mmc_of_parse(host->mmc); |
922 | if (ret) | 940 | if (ret) |
@@ -931,22 +949,85 @@ sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, | |||
931 | static inline int | 949 | static inline int |
932 | sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, | 950 | sdhci_esdhc_imx_probe_dt(struct platform_device *pdev, |
933 | struct sdhci_host *host, | 951 | struct sdhci_host *host, |
934 | struct esdhc_platform_data *boarddata) | 952 | struct pltfm_imx_data *imx_data) |
935 | { | 953 | { |
936 | return -ENODEV; | 954 | return -ENODEV; |
937 | } | 955 | } |
938 | #endif | 956 | #endif |
939 | 957 | ||
958 | static int sdhci_esdhc_imx_probe_nondt(struct platform_device *pdev, | ||
959 | struct sdhci_host *host, | ||
960 | struct pltfm_imx_data *imx_data) | ||
961 | { | ||
962 | struct esdhc_platform_data *boarddata = &imx_data->boarddata; | ||
963 | int err; | ||
964 | |||
965 | if (!host->mmc->parent->platform_data) { | ||
966 | dev_err(mmc_dev(host->mmc), "no board data!\n"); | ||
967 | return -EINVAL; | ||
968 | } | ||
969 | |||
970 | imx_data->boarddata = *((struct esdhc_platform_data *) | ||
971 | host->mmc->parent->platform_data); | ||
972 | /* write_protect */ | ||
973 | if (boarddata->wp_type == ESDHC_WP_GPIO) { | ||
974 | err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio); | ||
975 | if (err) { | ||
976 | dev_err(mmc_dev(host->mmc), | ||
977 | "failed to request write-protect gpio!\n"); | ||
978 | return err; | ||
979 | } | ||
980 | host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; | ||
981 | } | ||
982 | |||
983 | /* card_detect */ | ||
984 | switch (boarddata->cd_type) { | ||
985 | case ESDHC_CD_GPIO: | ||
986 | err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0); | ||
987 | if (err) { | ||
988 | dev_err(mmc_dev(host->mmc), | ||
989 | "failed to request card-detect gpio!\n"); | ||
990 | return err; | ||
991 | } | ||
992 | /* fall through */ | ||
993 | |||
994 | case ESDHC_CD_CONTROLLER: | ||
995 | /* we have a working card_detect back */ | ||
996 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; | ||
997 | break; | ||
998 | |||
999 | case ESDHC_CD_PERMANENT: | ||
1000 | host->mmc->caps |= MMC_CAP_NONREMOVABLE; | ||
1001 | break; | ||
1002 | |||
1003 | case ESDHC_CD_NONE: | ||
1004 | break; | ||
1005 | } | ||
1006 | |||
1007 | switch (boarddata->max_bus_width) { | ||
1008 | case 8: | ||
1009 | host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA; | ||
1010 | break; | ||
1011 | case 4: | ||
1012 | host->mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
1013 | break; | ||
1014 | case 1: | ||
1015 | default: | ||
1016 | host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; | ||
1017 | break; | ||
1018 | } | ||
1019 | |||
1020 | return 0; | ||
1021 | } | ||
1022 | |||
940 | static int sdhci_esdhc_imx_probe(struct platform_device *pdev) | 1023 | static int sdhci_esdhc_imx_probe(struct platform_device *pdev) |
941 | { | 1024 | { |
942 | const struct of_device_id *of_id = | 1025 | const struct of_device_id *of_id = |
943 | of_match_device(imx_esdhc_dt_ids, &pdev->dev); | 1026 | of_match_device(imx_esdhc_dt_ids, &pdev->dev); |
944 | struct sdhci_pltfm_host *pltfm_host; | 1027 | struct sdhci_pltfm_host *pltfm_host; |
945 | struct sdhci_host *host; | 1028 | struct sdhci_host *host; |
946 | struct esdhc_platform_data *boarddata; | ||
947 | int err; | 1029 | int err; |
948 | struct pltfm_imx_data *imx_data; | 1030 | struct pltfm_imx_data *imx_data; |
949 | bool dt = true; | ||
950 | 1031 | ||
951 | host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata, 0); | 1032 | host = sdhci_pltfm_init(pdev, &sdhci_esdhc_imx_pdata, 0); |
952 | if (IS_ERR(host)) | 1033 | if (IS_ERR(host)) |
@@ -1038,84 +1119,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev) | |||
1038 | if (imx_data->socdata->flags & ESDHC_FLAG_ERR004536) | 1119 | if (imx_data->socdata->flags & ESDHC_FLAG_ERR004536) |
1039 | host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; | 1120 | host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; |
1040 | 1121 | ||
1041 | boarddata = &imx_data->boarddata; | 1122 | if (of_id) |
1042 | if (sdhci_esdhc_imx_probe_dt(pdev, host, boarddata) < 0) { | 1123 | err = sdhci_esdhc_imx_probe_dt(pdev, host, imx_data); |
1043 | if (!host->mmc->parent->platform_data) { | 1124 | else |
1044 | dev_err(mmc_dev(host->mmc), "no board data!\n"); | 1125 | err = sdhci_esdhc_imx_probe_nondt(pdev, host, imx_data); |
1045 | err = -EINVAL; | 1126 | if (err) |
1046 | goto disable_clk; | 1127 | goto disable_clk; |
1047 | } | ||
1048 | imx_data->boarddata = *((struct esdhc_platform_data *) | ||
1049 | host->mmc->parent->platform_data); | ||
1050 | dt = false; | ||
1051 | } | ||
1052 | /* write_protect */ | ||
1053 | if (boarddata->wp_type == ESDHC_WP_GPIO && !dt) { | ||
1054 | err = mmc_gpio_request_ro(host->mmc, boarddata->wp_gpio); | ||
1055 | if (err) { | ||
1056 | dev_err(mmc_dev(host->mmc), | ||
1057 | "failed to request write-protect gpio!\n"); | ||
1058 | goto disable_clk; | ||
1059 | } | ||
1060 | host->mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; | ||
1061 | } | ||
1062 | |||
1063 | /* card_detect */ | ||
1064 | switch (boarddata->cd_type) { | ||
1065 | case ESDHC_CD_GPIO: | ||
1066 | if (dt) | ||
1067 | break; | ||
1068 | err = mmc_gpio_request_cd(host->mmc, boarddata->cd_gpio, 0); | ||
1069 | if (err) { | ||
1070 | dev_err(mmc_dev(host->mmc), | ||
1071 | "failed to request card-detect gpio!\n"); | ||
1072 | goto disable_clk; | ||
1073 | } | ||
1074 | /* fall through */ | ||
1075 | |||
1076 | case ESDHC_CD_CONTROLLER: | ||
1077 | /* we have a working card_detect back */ | ||
1078 | host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; | ||
1079 | break; | ||
1080 | |||
1081 | case ESDHC_CD_PERMANENT: | ||
1082 | host->mmc->caps |= MMC_CAP_NONREMOVABLE; | ||
1083 | break; | ||
1084 | |||
1085 | case ESDHC_CD_NONE: | ||
1086 | break; | ||
1087 | } | ||
1088 | |||
1089 | switch (boarddata->max_bus_width) { | ||
1090 | case 8: | ||
1091 | host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_4_BIT_DATA; | ||
1092 | break; | ||
1093 | case 4: | ||
1094 | host->mmc->caps |= MMC_CAP_4_BIT_DATA; | ||
1095 | break; | ||
1096 | case 1: | ||
1097 | default: | ||
1098 | host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; | ||
1099 | break; | ||
1100 | } | ||
1101 | |||
1102 | /* sdr50 and sdr104 needs work on 1.8v signal voltage */ | ||
1103 | if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data) && | ||
1104 | !IS_ERR(imx_data->pins_default)) { | ||
1105 | imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl, | ||
1106 | ESDHC_PINCTRL_STATE_100MHZ); | ||
1107 | imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl, | ||
1108 | ESDHC_PINCTRL_STATE_200MHZ); | ||
1109 | if (IS_ERR(imx_data->pins_100mhz) || | ||
1110 | IS_ERR(imx_data->pins_200mhz)) { | ||
1111 | dev_warn(mmc_dev(host->mmc), | ||
1112 | "could not get ultra high speed state, work on normal mode\n"); | ||
1113 | /* fall back to not support uhs by specify no 1.8v quirk */ | ||
1114 | host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; | ||
1115 | } | ||
1116 | } else { | ||
1117 | host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; | ||
1118 | } | ||
1119 | 1128 | ||
1120 | err = sdhci_add_host(host); | 1129 | err = sdhci_add_host(host); |
1121 | if (err) | 1130 | if (err) |