blob: 756a9824e3e41ddb09d9c55abd7824e8b8ce86dd [file] [log] [blame]
Simon Glassc40704f2016-06-12 23:30:18 -06001/*
2 * Copyright (C) 2016 Google, Inc
3 * Written by Amar <amarendra.xt@samsung.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <mmc.h>
10#include "mmc_private.h"
11
12/*
13 * This function changes the size of boot partition and the size of rpmb
14 * partition present on EMMC devices.
15 *
16 * Input Parameters:
17 * struct *mmc: pointer for the mmc device strcuture
18 * bootsize: size of boot partition
19 * rpmbsize: size of rpmb partition
20 *
21 * Returns 0 on success.
22 */
23
24int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
25 unsigned long rpmbsize)
26{
27 int err;
28 struct mmc_cmd cmd;
29
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;
34
35 err = mmc_send_cmd(mmc, &cmd, NULL);
36 if (err) {
37 debug("mmc_boot_partition_size_change: Error1 = %d\n", err);
38 return err;
39 }
40
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;
45
46 err = mmc_send_cmd(mmc, &cmd, NULL);
47 if (err) {
48 debug("mmc_boot_partition_size_change: Error2 = %d\n", err);
49 return err;
50 }
51 /* boot partition size is multiple of 128KB */
52 bootsize = (bootsize * 1024) / 128;
53
54 /* Arg: boot partition size */
55 cmd.cmdidx = MMC_CMD_RES_MAN;
56 cmd.resp_type = MMC_RSP_R1b;
57 cmd.cmdarg = bootsize;
58
59 err = mmc_send_cmd(mmc, &cmd, NULL);
60 if (err) {
61 debug("mmc_boot_partition_size_change: Error3 = %d\n", err);
62 return err;
63 }
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;
70
71 err = mmc_send_cmd(mmc, &cmd, NULL);
72 if (err) {
73 debug("mmc_boot_partition_size_change: Error4 = %d\n", err);
74 return err;
75 }
76 return 0;
77}
78
79/*
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
82 * and BOOT_MODE.
83 *
84 * Returns 0 on success.
85 */
86int mmc_set_boot_bus_width(struct mmc *mmc, u8 width, u8 reset, u8 mode)
87{
88 int err;
89
90 err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_BUS_WIDTH,
91 EXT_CSD_BOOT_BUS_WIDTH_MODE(mode) |
92 EXT_CSD_BOOT_BUS_WIDTH_RESET(reset) |
93 EXT_CSD_BOOT_BUS_WIDTH_WIDTH(width));
94
95 if (err)
96 return err;
97 return 0;
98}
99
100/*
101 * Modify EXT_CSD[179] which is PARTITION_CONFIG (formerly BOOT_CONFIG)
102 * based on the passed in values for BOOT_ACK, BOOT_PARTITION_ENABLE and
103 * PARTITION_ACCESS.
104 *
105 * Returns 0 on success.
106 */
107int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
108{
109 int err;
110
111 err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
112 EXT_CSD_BOOT_ACK(ack) |
113 EXT_CSD_BOOT_PART_NUM(part_num) |
114 EXT_CSD_PARTITION_ACCESS(access));
115
116 if (err)
117 return err;
118 return 0;
119}
120
121/*
122 * Modify EXT_CSD[162] which is RST_n_FUNCTION based on the given value
123 * for enable. Note that this is a write-once field for non-zero values.
124 *
125 * Returns 0 on success.
126 */
127int mmc_set_rst_n_function(struct mmc *mmc, u8 enable)
128{
129 return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_RST_N_FUNCTION,
130 enable);
131}