Skip to content

Commit 4facdde

Browse files
committed
mmc: core: Move public functions from card.h to private headers
A significant amount of functions and other definitions are available through the public mmc card.h header file. Let's slim down this public mmc interface, as to prevent users from abusing it, by moving some of the functions/definitions to private mmc header files. This change concentrates on moving the functions into private mmc headers, following changes may continue with additional clean-ups. Signed-off-by: Ulf Hansson <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Shawn Lin <[email protected]>
1 parent 2e4af7b commit 4facdde

File tree

16 files changed

+263
-242
lines changed

16 files changed

+263
-242
lines changed

drivers/mmc/core/block.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "queue.h"
4949
#include "block.h"
5050
#include "core.h"
51+
#include "card.h"
52+
#include "bus.h"
5153
#include "mmc_ops.h"
5254
#include "sd_ops.h"
5355

drivers/mmc/core/bus.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/mmc/host.h>
2424

2525
#include "core.h"
26+
#include "card.h"
2627
#include "sdio_cis.h"
2728
#include "bus.h"
2829

drivers/mmc/core/bus.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#ifndef _MMC_CORE_BUS_H
1212
#define _MMC_CORE_BUS_H
1313

14+
#include <linux/device.h>
15+
1416
struct mmc_host;
1517
struct mmc_card;
16-
struct device_type;
1718

1819
#define MMC_DEV_ATTR(name, fmt, args...) \
1920
static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
@@ -31,5 +32,14 @@ void mmc_remove_card(struct mmc_card *card);
3132
int mmc_register_bus(void);
3233
void mmc_unregister_bus(void);
3334

34-
#endif
35+
struct mmc_driver {
36+
struct device_driver drv;
37+
int (*probe)(struct mmc_card *card);
38+
void (*remove)(struct mmc_card *card);
39+
void (*shutdown)(struct mmc_card *card);
40+
};
3541

42+
int mmc_register_driver(struct mmc_driver *drv);
43+
void mmc_unregister_driver(struct mmc_driver *drv);
44+
45+
#endif

drivers/mmc/core/card.h

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/*
2+
* Private header for the mmc subsystem
3+
*
4+
* Copyright (C) 2016 Linaro Ltd
5+
*
6+
* Author: Ulf Hansson <[email protected]>
7+
*
8+
* License terms: GNU General Public License (GPL) version 2
9+
*/
10+
11+
#ifndef _MMC_CORE_CARD_H
12+
#define _MMC_CORE_CARD_H
13+
14+
#include <linux/mmc/card.h>
15+
16+
#define mmc_card_name(c) ((c)->cid.prod_name)
17+
#define mmc_card_id(c) (dev_name(&(c)->dev))
18+
#define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev)
19+
20+
/* Card states */
21+
#define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
22+
#define MMC_STATE_READONLY (1<<1) /* card is read-only */
23+
#define MMC_STATE_BLOCKADDR (1<<2) /* card uses block-addressing */
24+
#define MMC_CARD_SDXC (1<<3) /* card is SDXC */
25+
#define MMC_CARD_REMOVED (1<<4) /* card has been removed */
26+
#define MMC_STATE_DOING_BKOPS (1<<5) /* card is doing BKOPS */
27+
#define MMC_STATE_SUSPENDED (1<<6) /* card is suspended */
28+
29+
#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
30+
#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
31+
#define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
32+
#define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
33+
#define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
34+
#define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS)
35+
#define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED)
36+
37+
#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
38+
#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
39+
#define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
40+
#define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
41+
#define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
42+
#define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS)
43+
#define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS)
44+
#define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
45+
#define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
46+
47+
/*
48+
* The world is not perfect and supplies us with broken mmc/sdio devices.
49+
* For at least some of these bugs we need a work-around.
50+
*/
51+
struct mmc_fixup {
52+
/* CID-specific fields. */
53+
const char *name;
54+
55+
/* Valid revision range */
56+
u64 rev_start, rev_end;
57+
58+
unsigned int manfid;
59+
unsigned short oemid;
60+
61+
/* SDIO-specific fields. You can use SDIO_ANY_ID here of course */
62+
u16 cis_vendor, cis_device;
63+
64+
/* for MMC cards */
65+
unsigned int ext_csd_rev;
66+
67+
void (*vendor_fixup)(struct mmc_card *card, int data);
68+
int data;
69+
};
70+
71+
#define CID_MANFID_ANY (-1u)
72+
#define CID_OEMID_ANY ((unsigned short) -1)
73+
#define CID_NAME_ANY (NULL)
74+
75+
#define EXT_CSD_REV_ANY (-1u)
76+
77+
#define CID_MANFID_SANDISK 0x2
78+
#define CID_MANFID_TOSHIBA 0x11
79+
#define CID_MANFID_MICRON 0x13
80+
#define CID_MANFID_SAMSUNG 0x15
81+
#define CID_MANFID_KINGSTON 0x70
82+
#define CID_MANFID_HYNIX 0x90
83+
84+
#define END_FIXUP { NULL }
85+
86+
#define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \
87+
_cis_vendor, _cis_device, \
88+
_fixup, _data, _ext_csd_rev) \
89+
{ \
90+
.name = (_name), \
91+
.manfid = (_manfid), \
92+
.oemid = (_oemid), \
93+
.rev_start = (_rev_start), \
94+
.rev_end = (_rev_end), \
95+
.cis_vendor = (_cis_vendor), \
96+
.cis_device = (_cis_device), \
97+
.vendor_fixup = (_fixup), \
98+
.data = (_data), \
99+
.ext_csd_rev = (_ext_csd_rev), \
100+
}
101+
102+
#define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \
103+
_fixup, _data, _ext_csd_rev) \
104+
_FIXUP_EXT(_name, _manfid, \
105+
_oemid, _rev_start, _rev_end, \
106+
SDIO_ANY_ID, SDIO_ANY_ID, \
107+
_fixup, _data, _ext_csd_rev) \
108+
109+
#define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
110+
MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \
111+
EXT_CSD_REV_ANY)
112+
113+
#define MMC_FIXUP_EXT_CSD_REV(_name, _manfid, _oemid, _fixup, _data, \
114+
_ext_csd_rev) \
115+
MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \
116+
_ext_csd_rev)
117+
118+
#define SDIO_FIXUP(_vendor, _device, _fixup, _data) \
119+
_FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \
120+
CID_OEMID_ANY, 0, -1ull, \
121+
_vendor, _device, \
122+
_fixup, _data, EXT_CSD_REV_ANY) \
123+
124+
#define cid_rev(hwrev, fwrev, year, month) \
125+
(((u64) hwrev) << 40 | \
126+
((u64) fwrev) << 32 | \
127+
((u64) year) << 16 | \
128+
((u64) month))
129+
130+
#define cid_rev_card(card) \
131+
cid_rev(card->cid.hwrev, \
132+
card->cid.fwrev, \
133+
card->cid.year, \
134+
card->cid.month)
135+
136+
/*
137+
* Unconditionally quirk add/remove.
138+
*/
139+
static inline void __maybe_unused add_quirk(struct mmc_card *card, int data)
140+
{
141+
card->quirks |= data;
142+
}
143+
144+
static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
145+
{
146+
card->quirks &= ~data;
147+
}
148+
149+
/*
150+
* Quirk add/remove for MMC products.
151+
*/
152+
static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data)
153+
{
154+
if (mmc_card_mmc(card))
155+
card->quirks |= data;
156+
}
157+
158+
static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card,
159+
int data)
160+
{
161+
if (mmc_card_mmc(card))
162+
card->quirks &= ~data;
163+
}
164+
165+
/*
166+
* Quirk add/remove for SD products.
167+
*/
168+
static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data)
169+
{
170+
if (mmc_card_sd(card))
171+
card->quirks |= data;
172+
}
173+
174+
static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card,
175+
int data)
176+
{
177+
if (mmc_card_sd(card))
178+
card->quirks &= ~data;
179+
}
180+
181+
static inline int mmc_card_lenient_fn0(const struct mmc_card *c)
182+
{
183+
return c->quirks & MMC_QUIRK_LENIENT_FN0;
184+
}
185+
186+
static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c)
187+
{
188+
return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
189+
}
190+
191+
static inline int mmc_card_disable_cd(const struct mmc_card *c)
192+
{
193+
return c->quirks & MMC_QUIRK_DISABLE_CD;
194+
}
195+
196+
static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c)
197+
{
198+
return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF;
199+
}
200+
201+
static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c)
202+
{
203+
return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512;
204+
}
205+
206+
static inline int mmc_card_long_read_time(const struct mmc_card *c)
207+
{
208+
return c->quirks & MMC_QUIRK_LONG_READ_TIME;
209+
}
210+
211+
static inline int mmc_card_broken_irq_polling(const struct mmc_card *c)
212+
{
213+
return c->quirks & MMC_QUIRK_BROKEN_IRQ_POLLING;
214+
}
215+
216+
static inline int mmc_card_broken_hpi(const struct mmc_card *c)
217+
{
218+
return c->quirks & MMC_QUIRK_BROKEN_HPI;
219+
}
220+
221+
void mmc_fixup_device(struct mmc_card *card, const struct mmc_fixup *table);
222+
223+
#endif

drivers/mmc/core/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <trace/events/mmc.h>
4141

4242
#include "core.h"
43+
#include "card.h"
4344
#include "bus.h"
4445
#include "host.h"
4546
#include "sdio_bus.h"

drivers/mmc/core/debugfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/mmc/host.h>
2121

2222
#include "core.h"
23+
#include "card.h"
2324
#include "mmc_ops.h"
2425

2526
#ifdef CONFIG_FAIL_MMC_REQUEST

drivers/mmc/core/mmc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/mmc/mmc.h>
2222

2323
#include "core.h"
24+
#include "card.h"
2425
#include "host.h"
2526
#include "bus.h"
2627
#include "mmc_ops.h"
@@ -307,6 +308,18 @@ static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd)
307308
}
308309
}
309310

311+
static void mmc_part_add(struct mmc_card *card, unsigned int size,
312+
unsigned int part_cfg, char *name, int idx, bool ro,
313+
int area_type)
314+
{
315+
card->part[card->nr_parts].size = size;
316+
card->part[card->nr_parts].part_cfg = part_cfg;
317+
sprintf(card->part[card->nr_parts].name, name, idx);
318+
card->part[card->nr_parts].force_ro = ro;
319+
card->part[card->nr_parts].area_type = area_type;
320+
card->nr_parts++;
321+
}
322+
310323
static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
311324
{
312325
int idx;

drivers/mmc/core/mmc_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <linux/module.h>
2424

2525
#include "core.h"
26+
#include "card.h"
27+
#include "bus.h"
2628

2729
#define RESULT_OK 0
2830
#define RESULT_FAIL 1

drivers/mmc/core/queue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "queue.h"
2222
#include "block.h"
2323
#include "core.h"
24+
#include "card.h"
2425

2526
#define MMC_QUEUE_BOUNCESZ 65536
2627

drivers/mmc/core/quirks.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/mmc/card.h>
1616
#include <linux/mmc/sdio_ids.h>
1717

18+
#include "card.h"
19+
1820
#ifndef SDIO_VENDOR_ID_TI
1921
#define SDIO_VENDOR_ID_TI 0x0097
2022
#endif

0 commit comments

Comments
 (0)