forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/mmc/core/sdio_bus.c
....@@ -1,12 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * linux/drivers/mmc/core/sdio_bus.c
34 *
45 * Copyright 2007 Pierre Ossman
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or (at
9
- * your option) any later version.
106 *
117 * SDIO function driver model
128 */
....@@ -32,34 +28,50 @@
3228 #define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
3329
3430 /* show configuration fields */
35
-#define sdio_config_attr(field, format_string) \
31
+#define sdio_config_attr(field, format_string, args...) \
3632 static ssize_t \
3733 field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
3834 { \
3935 struct sdio_func *func; \
4036 \
4137 func = dev_to_sdio_func (dev); \
42
- return sprintf (buf, format_string, func->field); \
38
+ return sprintf(buf, format_string, args); \
4339 } \
4440 static DEVICE_ATTR_RO(field)
4541
46
-sdio_config_attr(class, "0x%02x\n");
47
-sdio_config_attr(vendor, "0x%04x\n");
48
-sdio_config_attr(device, "0x%04x\n");
42
+sdio_config_attr(class, "0x%02x\n", func->class);
43
+sdio_config_attr(vendor, "0x%04x\n", func->vendor);
44
+sdio_config_attr(device, "0x%04x\n", func->device);
45
+sdio_config_attr(revision, "%u.%u\n", func->major_rev, func->minor_rev);
46
+sdio_config_attr(modalias, "sdio:c%02Xv%04Xd%04X\n", func->class, func->vendor, func->device);
4947
50
-static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
51
-{
52
- struct sdio_func *func = dev_to_sdio_func (dev);
48
+#define sdio_info_attr(num) \
49
+static ssize_t info##num##_show(struct device *dev, struct device_attribute *attr, char *buf) \
50
+{ \
51
+ struct sdio_func *func = dev_to_sdio_func(dev); \
52
+ \
53
+ if (num > func->num_info) \
54
+ return -ENODATA; \
55
+ if (!func->info[num-1][0]) \
56
+ return 0; \
57
+ return sprintf(buf, "%s\n", func->info[num-1]); \
58
+} \
59
+static DEVICE_ATTR_RO(info##num)
5360
54
- return sprintf(buf, "sdio:c%02Xv%04Xd%04X\n",
55
- func->class, func->vendor, func->device);
56
-}
57
-static DEVICE_ATTR_RO(modalias);
61
+sdio_info_attr(1);
62
+sdio_info_attr(2);
63
+sdio_info_attr(3);
64
+sdio_info_attr(4);
5865
5966 static struct attribute *sdio_dev_attrs[] = {
6067 &dev_attr_class.attr,
6168 &dev_attr_vendor.attr,
6269 &dev_attr_device.attr,
70
+ &dev_attr_revision.attr,
71
+ &dev_attr_info1.attr,
72
+ &dev_attr_info2.attr,
73
+ &dev_attr_info3.attr,
74
+ &dev_attr_info4.attr,
6375 &dev_attr_modalias.attr,
6476 NULL,
6577 };
....@@ -110,6 +122,7 @@
110122 sdio_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
111123 {
112124 struct sdio_func *func = dev_to_sdio_func(dev);
125
+ unsigned int i;
113126
114127 if (add_uevent_var(env,
115128 "SDIO_CLASS=%02X", func->class))
....@@ -118,6 +131,15 @@
118131 if (add_uevent_var(env,
119132 "SDIO_ID=%04X:%04X", func->vendor, func->device))
120133 return -ENOMEM;
134
+
135
+ if (add_uevent_var(env,
136
+ "SDIO_REVISION=%u.%u", func->major_rev, func->minor_rev))
137
+ return -ENOMEM;
138
+
139
+ for (i = 0; i < func->num_info; i++) {
140
+ if (add_uevent_var(env, "SDIO_INFO%u=%s", i+1, func->info[i]))
141
+ return -ENOMEM;
142
+ }
121143
122144 if (add_uevent_var(env,
123145 "MODALIAS=sdio:c%02Xv%04Xd%04X",
....@@ -142,6 +164,8 @@
142164 if (ret)
143165 return ret;
144166
167
+ atomic_inc(&func->card->sdio_funcs_probed);
168
+
145169 /* Unbound SDIO functions are always suspended.
146170 * During probe, the function is set active and the usage count
147171 * is incremented. If the driver supports runtime PM,
....@@ -157,7 +181,10 @@
157181 /* Set the default block size so the driver is sure it's something
158182 * sensible. */
159183 sdio_claim_host(func);
160
- ret = sdio_set_block_size(func, 0);
184
+ if (mmc_card_removed(func->card))
185
+ ret = -ENOMEDIUM;
186
+ else
187
+ ret = sdio_set_block_size(func, 0);
161188 sdio_release_host(func);
162189 if (ret)
163190 goto disable_runtimepm;
....@@ -169,6 +196,7 @@
169196 return 0;
170197
171198 disable_runtimepm:
199
+ atomic_dec(&func->card->sdio_funcs_probed);
172200 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
173201 pm_runtime_put_noidle(dev);
174202 dev_pm_domain_detach(dev, false);
....@@ -179,13 +207,13 @@
179207 {
180208 struct sdio_driver *drv = to_sdio_driver(dev->driver);
181209 struct sdio_func *func = dev_to_sdio_func(dev);
182
- int ret = 0;
183210
184211 /* Make sure card is powered before invoking ->remove() */
185212 if (func->card->host->caps & MMC_CAP_POWER_OFF_CARD)
186213 pm_runtime_get_sync(dev);
187214
188215 drv->remove(func);
216
+ atomic_dec(&func->card->sdio_funcs_probed);
189217
190218 if (func->irq_handler) {
191219 pr_warn("WARNING: driver %s did not remove its interrupt handler!\n",
....@@ -205,7 +233,7 @@
205233
206234 dev_pm_domain_detach(dev, false);
207235
208
- return ret;
236
+ return 0;
209237 }
210238
211239 static const struct dev_pm_ops sdio_bus_pm_ops = {
....@@ -264,7 +292,14 @@
264292 {
265293 struct sdio_func *func = dev_to_sdio_func(dev);
266294
267
- sdio_free_func_cis(func);
295
+ if (!(func->card->quirks & MMC_QUIRK_NONSTD_SDIO))
296
+ sdio_free_func_cis(func);
297
+
298
+ /*
299
+ * We have now removed the link to the tuples in the
300
+ * card structure, so remove the reference.
301
+ */
302
+ put_device(&func->card->dev);
268303
269304 kfree(func->info);
270305 kfree(func->tmpbuf);
....@@ -295,6 +330,12 @@
295330 func->card = card;
296331
297332 device_initialize(&func->dev);
333
+
334
+ /*
335
+ * We may link to tuples in the card structure,
336
+ * we need make sure we have a reference to it.
337
+ */
338
+ get_device(&func->card->dev);
298339
299340 func->dev.parent = &card->dev;
300341 func->dev.bus = &sdio_bus_type;
....@@ -349,10 +390,9 @@
349390 */
350391 void sdio_remove_func(struct sdio_func *func)
351392 {
352
- if (!sdio_func_present(func))
353
- return;
393
+ if (sdio_func_present(func))
394
+ device_del(&func->dev);
354395
355
- device_del(&func->dev);
356396 of_node_put(func->dev.of_node);
357397 put_device(&func->dev);
358398 }