blob: 3ec649f2b82d391b4f359c5e9d866d3459394112 [file] [log] [blame]
Simon Glasse5db1152016-05-01 13:52:35 -06001/*
2 * Copyright (C) 2016 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <mmc.h>
10
11static struct list_head mmc_devices;
12static int cur_dev_num = -1;
13
14struct mmc *find_mmc_device(int dev_num)
15{
16 struct mmc *m;
17 struct list_head *entry;
18
19 list_for_each(entry, &mmc_devices) {
20 m = list_entry(entry, struct mmc, link);
21
22 if (m->block_dev.devnum == dev_num)
23 return m;
24 }
25
26#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
27 printf("MMC Device %d not found\n", dev_num);
28#endif
29
30 return NULL;
31}
32
33int mmc_get_next_devnum(void)
34{
35 return cur_dev_num++;
36}
37
38struct blk_desc *mmc_get_blk_desc(struct mmc *mmc)
39{
40 return &mmc->block_dev;
41}
42
43int get_mmc_num(void)
44{
45 return cur_dev_num;
46}
47
48void mmc_do_preinit(void)
49{
50 struct mmc *m;
51 struct list_head *entry;
52
53 list_for_each(entry, &mmc_devices) {
54 m = list_entry(entry, struct mmc, link);
55
56#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
57 mmc_set_preinit(m, 1);
58#endif
59 if (m->preinit)
60 mmc_start_init(m);
61 }
62}
63
64void mmc_list_init(void)
65{
66 INIT_LIST_HEAD(&mmc_devices);
67 cur_dev_num = 0;
68}
69
70void mmc_list_add(struct mmc *mmc)
71{
72 INIT_LIST_HEAD(&mmc->link);
73
74 list_add_tail(&mmc->link, &mmc_devices);
75}
76
77#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
78void print_mmc_devices(char separator)
79{
80 struct mmc *m;
81 struct list_head *entry;
82 char *mmc_type;
83
84 list_for_each(entry, &mmc_devices) {
85 m = list_entry(entry, struct mmc, link);
86
87 if (m->has_init)
88 mmc_type = IS_SD(m) ? "SD" : "eMMC";
89 else
90 mmc_type = NULL;
91
92 printf("%s: %d", m->cfg->name, m->block_dev.devnum);
93 if (mmc_type)
94 printf(" (%s)", mmc_type);
95
96 if (entry->next != &mmc_devices) {
97 printf("%c", separator);
98 if (separator != '\n')
99 puts(" ");
100 }
101 }
102
103 printf("\n");
104}
105
106#else
107void print_mmc_devices(char separator) { }
108#endif