1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2016 Google, Inc
4 * Written by Amar <amarendra.xt@samsung.com>
10 #include "mmc_private.h"
13 * This function changes the size of boot partition and the size of rpmb
14 * partition present on EMMC devices.
17 * struct *mmc: pointer for the mmc device strcuture
18 * bootsize: size of boot partition
19 * rpmbsize: size of rpmb partition
21 * Returns 0 on success.
24 int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
25 unsigned long rpmbsize)
30 /* Only use this command for raw EMMC moviNAND. Enter backdoor mode */
31 cmd.cmdidx = MMC_CMD_RES_MAN;
32 cmd.resp_type = MMC_RSP_R1b;
33 cmd.cmdarg = MMC_CMD62_ARG1;
35 err = mmc_send_cmd(mmc, &cmd, NULL);
37 debug("mmc_boot_partition_size_change: Error1 = %d\n", err);
41 /* Boot partition changing mode */
42 cmd.cmdidx = MMC_CMD_RES_MAN;
43 cmd.resp_type = MMC_RSP_R1b;
44 cmd.cmdarg = MMC_CMD62_ARG2;
46 err = mmc_send_cmd(mmc, &cmd, NULL);
48 debug("mmc_boot_partition_size_change: Error2 = %d\n", err);
51 /* boot partition size is multiple of 128KB */
52 bootsize = (bootsize * 1024) / 128;
54 /* Arg: boot partition size */
55 cmd.cmdidx = MMC_CMD_RES_MAN;
56 cmd.resp_type = MMC_RSP_R1b;
57 cmd.cmdarg = bootsize;
59 err = mmc_send_cmd(mmc, &cmd, NULL);
61 debug("mmc_boot_partition_size_change: Error3 = %d\n", err);
64 /* RPMB partition size is multiple of 128KB */
65 rpmbsize = (rpmbsize * 1024) / 128;
66 /* Arg: RPMB partition size */
67 cmd.cmdidx = MMC_CMD_RES_MAN;
68 cmd.resp_type = MMC_RSP_R1b;
69 cmd.cmdarg = rpmbsize;
71 err = mmc_send_cmd(mmc, &cmd, NULL);
73 debug("mmc_boot_partition_size_change: Error4 = %d\n", err);
80 * Modify EXT_CSD[177] which is BOOT_BUS_WIDTH
81 * based on the passed in values for BOOT_BUS_WIDTH, RESET_BOOT_BUS_WIDTH
84 * Returns 0 on success.
86 int mmc_set_boot_bus_width(struct mmc *mmc, u8 width, u8 reset, u8 mode)
88 return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_BUS_WIDTH,
89 EXT_CSD_BOOT_BUS_WIDTH_MODE(mode) |
90 EXT_CSD_BOOT_BUS_WIDTH_RESET(reset) |
91 EXT_CSD_BOOT_BUS_WIDTH_WIDTH(width));
95 * Modify EXT_CSD[179] which is PARTITION_CONFIG (formerly BOOT_CONFIG)
96 * based on the passed in values for BOOT_ACK, BOOT_PARTITION_ENABLE and
99 * Returns 0 on success.
101 int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
106 part_conf = EXT_CSD_BOOT_ACK(ack) |
107 EXT_CSD_BOOT_PART_NUM(part_num) |
108 EXT_CSD_PARTITION_ACCESS(access);
110 ret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
113 mmc->part_config = part_conf;
119 * Modify EXT_CSD[162] which is RST_n_FUNCTION based on the given value
120 * for enable. Note that this is a write-once field for non-zero values.
122 * Returns 0 on success.
124 int mmc_set_rst_n_function(struct mmc *mmc, u8 enable)
126 return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_RST_N_FUNCTION,