• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision87069c79e830b2ab909537946a1e1db0e5fe7d8c (tree)
Time2022-07-27 20:00:54
AuthorTom Rini <trini@kons...>
CommiterTom Rini

Log Message

Change Summary

Incremental Difference

--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -1048,6 +1048,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
10481048 {
10491049 int err;
10501050 struct mmc *mmc;
1051+ int part;
10511052
10521053 mmc = init_mmc_device(curr_device, false);
10531054 if (!mmc)
@@ -1056,7 +1057,14 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
10561057 printf("It is not an eMMC device\n");
10571058 return CMD_RET_FAILURE;
10581059 }
1059- err = mmc_boot_wp(mmc);
1060+
1061+ if (argc == 2) {
1062+ part = dectoul(argv[1], NULL);
1063+ err = mmc_boot_wp_single_partition(mmc, part);
1064+ } else {
1065+ err = mmc_boot_wp(mmc);
1066+ }
1067+
10601068 if (err)
10611069 return CMD_RET_FAILURE;
10621070 printf("boot areas protected\n");
@@ -1066,7 +1074,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
10661074 static struct cmd_tbl cmd_mmc[] = {
10671075 U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
10681076 U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
1069- U_BOOT_CMD_MKENT(wp, 1, 0, do_mmc_boot_wp, "", ""),
1077+ U_BOOT_CMD_MKENT(wp, 2, 0, do_mmc_boot_wp, "", ""),
10701078 #if CONFIG_IS_ENABLED(MMC_WRITE)
10711079 U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
10721080 U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
@@ -1140,7 +1148,11 @@ U_BOOT_CMD(
11401148 " [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52, UHS_SDR12, UHS_SDR25,\n"
11411149 " UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200, MMC_HS_400, MMC_HS_400_ES]\n"
11421150 "mmc list - lists available devices\n"
1143- "mmc wp - power on write protect boot partitions\n"
1151+ "mmc wp [PART] - power on write protect boot partitions\n"
1152+ " arguments:\n"
1153+ " PART - [0|1]\n"
1154+ " : 0 - first boot partition, 1 - second boot partition\n"
1155+ " if not assigned, write protect all boot partitions\n"
11441156 #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
11451157 "mmc hwpartition <USER> <GP> <MODE> - does hardware partitioning\n"
11461158 " arguments (sizes in 512-byte blocks):\n"
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -618,6 +618,18 @@ config MMC_SDHCI_MV
618618
619619 If unsure, say N.
620620
621+config MMC_SDHCI_NPCM
622+ bool "SDHCI support on Nuvoton NPCM device"
623+ depends on MMC_SDHCI
624+ depends on DM_MMC
625+ help
626+ This selects the Secure Digital Host Controller Interface (SDHCI)
627+ on Nuvoton NPCM device.
628+
629+ If you have a controller with this interface, say Y here.
630+
631+ If unsure, say N.
632+
621633 config MMC_SDHCI_PIC32
622634 bool "Microchip PIC32 on-chip SDHCI support"
623635 depends on DM_MMC && MACH_PIC32
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -66,6 +66,7 @@ obj-$(CONFIG_MMC_SDHCI_IPROC) += iproc_sdhci.o
6666 obj-$(CONFIG_MMC_SDHCI_KONA) += kona_sdhci.o
6767 obj-$(CONFIG_MMC_SDHCI_MSM) += msm_sdhci.o
6868 obj-$(CONFIG_MMC_SDHCI_MV) += mv_sdhci.o
69+obj-$(CONFIG_MMC_SDHCI_NPCM) += npcm_sdhci.o
6970 obj-$(CONFIG_MMC_SDHCI_PIC32) += pic32_sdhci.o
7071 obj-$(CONFIG_MMC_SDHCI_ROCKCHIP) += rockchip_sdhci.o
7172 obj-$(CONFIG_MMC_SDHCI_S5P) += s5p_sdhci.o
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -504,6 +504,7 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
504504 u32 time_out;
505505 u32 value;
506506 uint clk;
507+ u32 hostver;
507508
508509 if (clock < mmc->cfg->f_min)
509510 clock = mmc->cfg->f_min;
@@ -544,6 +545,14 @@ static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
544545
545546 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
546547
548+ /* Only newer eSDHC controllers set PRSSTAT_SDSTB flag */
549+ hostver = esdhc_read32(&priv->esdhc_regs->hostver);
550+ if (HOSTVER_VENDOR(hostver) <= VENDOR_V_22) {
551+ udelay(10000);
552+ esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
553+ return;
554+ }
555+
547556 time_out = 20;
548557 value = PRSSTAT_SDSTB;
549558 while (!(esdhc_read32(&regs->prsstat) & value)) {
@@ -563,6 +572,7 @@ static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
563572 struct fsl_esdhc *regs = priv->esdhc_regs;
564573 u32 value;
565574 u32 time_out;
575+ u32 hostver;
566576
567577 value = esdhc_read32(&regs->sysctl);
568578
@@ -573,6 +583,13 @@ static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
573583
574584 esdhc_write32(&regs->sysctl, value);
575585
586+ /* Only newer eSDHC controllers set PRSSTAT_SDSTB flag */
587+ hostver = esdhc_read32(&priv->esdhc_regs->hostver);
588+ if (HOSTVER_VENDOR(hostver) <= VENDOR_V_22) {
589+ udelay(10000);
590+ return;
591+ }
592+
576593 time_out = 20;
577594 value = PRSSTAT_SDSTB;
578595 while (!(esdhc_read32(&regs->prsstat) & value)) {
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -863,6 +863,33 @@ int mmc_boot_wp(struct mmc *mmc)
863863 return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, 1);
864864 }
865865
866+int mmc_boot_wp_single_partition(struct mmc *mmc, int partition)
867+{
868+ u8 value;
869+ int ret;
870+
871+ value = EXT_CSD_BOOT_WP_B_PWR_WP_EN;
872+
873+ if (partition == 0) {
874+ value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL;
875+ ret = mmc_switch(mmc,
876+ EXT_CSD_CMD_SET_NORMAL,
877+ EXT_CSD_BOOT_WP,
878+ value);
879+ } else if (partition == 1) {
880+ value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL;
881+ value |= EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL;
882+ ret = mmc_switch(mmc,
883+ EXT_CSD_CMD_SET_NORMAL,
884+ EXT_CSD_BOOT_WP,
885+ value);
886+ } else {
887+ ret = mmc_boot_wp(mmc);
888+ }
889+
890+ return ret;
891+}
892+
866893 #if !CONFIG_IS_ENABLED(MMC_TINY)
867894 static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode,
868895 bool hsdowngrade)
--- /dev/null
+++ b/drivers/mmc/npcm_sdhci.c
@@ -0,0 +1,86 @@
1+// SPDX-License-Identifier: GPL-2.0+
2+/*
3+ * Copyright (c) 2022 Nuvoton Technology Corp.
4+ */
5+
6+#include <common.h>
7+#include <dm.h>
8+#include <sdhci.h>
9+#include <clk.h>
10+#include <power/regulator.h>
11+
12+#define NPCM_SDHC_MIN_FREQ 400000
13+
14+struct npcm_sdhci_plat {
15+ struct mmc_config cfg;
16+ struct mmc mmc;
17+};
18+
19+static int npcm_sdhci_probe(struct udevice *dev)
20+{
21+ struct npcm_sdhci_plat *plat = dev_get_plat(dev);
22+ struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
23+ struct sdhci_host *host = dev_get_priv(dev);
24+ struct udevice *vqmmc_supply;
25+ int vqmmc_uv, ret;
26+ struct clk clk;
27+
28+ host->name = dev->name;
29+ host->ioaddr = dev_read_addr_ptr(dev);
30+ host->max_clk = dev_read_u32_default(dev, "clock-frequency", 0);
31+
32+ ret = clk_get_by_index(dev, 0, &clk);
33+ if (!ret && host->max_clk) {
34+ ret = clk_set_rate(&clk, host->max_clk);
35+ if (ret < 0)
36+ return ret;
37+ }
38+
39+ if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
40+ device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_supply);
41+ vqmmc_uv = dev_read_u32_default(dev, "vqmmc-microvolt", 0);
42+ /* Set IO voltage */
43+ if (vqmmc_supply && vqmmc_uv)
44+ regulator_set_value(vqmmc_supply, vqmmc_uv);
45+ }
46+
47+ host->index = dev_read_u32_default(dev, "index", 0);
48+ ret = mmc_of_parse(dev, &plat->cfg);
49+ if (ret)
50+ return ret;
51+
52+ host->mmc = &plat->mmc;
53+ host->mmc->priv = host;
54+ host->mmc->dev = dev;
55+ upriv->mmc = host->mmc;
56+
57+ ret = sdhci_setup_cfg(&plat->cfg, host, 0, NPCM_SDHC_MIN_FREQ);
58+ if (ret)
59+ return ret;
60+
61+ return sdhci_probe(dev);
62+}
63+
64+static int npcm_sdhci_bind(struct udevice *dev)
65+{
66+ struct npcm_sdhci_plat *plat = dev_get_plat(dev);
67+
68+ return sdhci_bind(dev, &plat->mmc, &plat->cfg);
69+}
70+
71+static const struct udevice_id npcm_mmc_ids[] = {
72+ { .compatible = "nuvoton,npcm750-sdhci" },
73+ { .compatible = "nuvoton,npcm845-sdhci" },
74+ { }
75+};
76+
77+U_BOOT_DRIVER(npcm_sdhci_drv) = {
78+ .name = "npcm_sdhci",
79+ .id = UCLASS_MMC,
80+ .of_match = npcm_mmc_ids,
81+ .ops = &sdhci_ops,
82+ .bind = npcm_sdhci_bind,
83+ .probe = npcm_sdhci_probe,
84+ .priv_auto = sizeof(struct sdhci_host),
85+ .plat_auto = sizeof(struct npcm_sdhci_plat),
86+};
--- a/drivers/mmc/pci_mmc.c
+++ b/drivers/mmc/pci_mmc.c
@@ -86,6 +86,7 @@ static int pci_mmc_bind(struct udevice *dev)
8686 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
8787 }
8888
89+__maybe_unused
8990 static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev,
9091 struct acpi_ctx *ctx)
9192 {
@@ -138,7 +139,9 @@ static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev,
138139 }
139140
140141 struct acpi_ops pci_mmc_acpi_ops = {
142+#ifdef CONFIG_ACPIGEN
141143 .fill_ssdt = pci_mmc_acpi_fill_ssdt,
144+#endif
142145 };
143146
144147 static const struct udevice_id pci_mmc_match[] = {
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -308,6 +308,10 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
308308
309309 #define EXT_CSD_HS_CTRL_REL (1 << 0) /* host controlled WR_REL_SET */
310310
311+#define EXT_CSD_BOOT_WP_B_SEC_WP_SEL (0x80) /* enable partition selector */
312+#define EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL (0x02) /* partition selector to protect */
313+#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) /* power-on write-protect */
314+
311315 #define EXT_CSD_WR_DATA_REL_USR (1 << 0) /* user data area WR_REL */
312316 #define EXT_CSD_WR_DATA_REL_GP(x) (1 << ((x)+1)) /* GP part (x+1) WR_REL */
313317
@@ -991,6 +995,18 @@ int mmc_send_ext_csd(struct mmc *mmc, u8 *ext_csd);
991995 */
992996 int mmc_boot_wp(struct mmc *mmc);
993997
998+/**
999+ * mmc_boot_wp_single_partition() - set write protection to a boot partition.
1000+ *
1001+ * This function sets a single boot partition to protect and leave the
1002+ * other partition writable.
1003+ *
1004+ * @param mmc the mmc device.
1005+ * @param partition 0 - first boot partition, 1 - second boot partition.
1006+ * @return 0 for success
1007+ */
1008+int mmc_boot_wp_single_partition(struct mmc *mmc, int partition);
1009+
9941010 static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data)
9951011 {
9961012 return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;