|
19 | 19 | static DEFINE_IDR(tifm_adapter_idr); |
20 | 20 | static DEFINE_SPINLOCK(tifm_adapter_lock); |
21 | 21 |
|
22 | | -static tifm_media_id *tifm_device_match(tifm_media_id *ids, |
23 | | - struct tifm_dev *dev) |
| 22 | +static const char *tifm_media_type_name(unsigned char type, unsigned char nt) |
24 | 23 | { |
25 | | - while (*ids) { |
26 | | - if (dev->media_id == *ids) |
27 | | - return ids; |
28 | | - ids++; |
29 | | - } |
30 | | - return NULL; |
| 24 | + const char *card_type_name[3][3] = { |
| 25 | + { "SmartMedia/xD", "MemoryStick", "MMC/SD" }, |
| 26 | + { "XD", "MS", "SD"}, |
| 27 | + { "xd", "ms", "sd"} |
| 28 | + }; |
| 29 | + |
| 30 | + if (nt > 2 || type < 1 || type > 3) |
| 31 | + return NULL; |
| 32 | + return card_type_name[nt][type - 1]; |
31 | 33 | } |
32 | 34 |
|
33 | | -static int tifm_match(struct device *dev, struct device_driver *drv) |
| 35 | +static int tifm_dev_match(struct tifm_dev *sock, struct tifm_device_id *id) |
34 | 36 | { |
35 | | - struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev); |
36 | | - struct tifm_driver *fm_drv; |
37 | | - |
38 | | - fm_drv = container_of(drv, struct tifm_driver, driver); |
39 | | - if (!fm_drv->id_table) |
40 | | - return -EINVAL; |
41 | | - if (tifm_device_match(fm_drv->id_table, fm_dev)) |
| 37 | + if (sock->type == id->type) |
42 | 38 | return 1; |
43 | | - return -ENODEV; |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +static int tifm_bus_match(struct device *dev, struct device_driver *drv) |
| 43 | +{ |
| 44 | + struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev); |
| 45 | + struct tifm_driver *fm_drv = container_of(drv, struct tifm_driver, |
| 46 | + driver); |
| 47 | + struct tifm_device_id *ids = fm_drv->id_table; |
| 48 | + |
| 49 | + if (ids) { |
| 50 | + while (ids->type) { |
| 51 | + if (tifm_dev_match(sock, ids)) |
| 52 | + return 1; |
| 53 | + ++ids; |
| 54 | + } |
| 55 | + } |
| 56 | + return 0; |
44 | 57 | } |
45 | 58 |
|
46 | 59 | static int tifm_uevent(struct device *dev, char **envp, int num_envp, |
47 | 60 | char *buffer, int buffer_size) |
48 | 61 | { |
49 | | - struct tifm_dev *fm_dev; |
| 62 | + struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev); |
50 | 63 | int i = 0; |
51 | 64 | int length = 0; |
52 | | - const char *card_type_name[] = {"INV", "SM", "MS", "SD"}; |
53 | 65 |
|
54 | | - if (!dev || !(fm_dev = container_of(dev, struct tifm_dev, dev))) |
55 | | - return -ENODEV; |
56 | 66 | if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length, |
57 | | - "TIFM_CARD_TYPE=%s", card_type_name[fm_dev->media_id])) |
| 67 | + "TIFM_CARD_TYPE=%s", |
| 68 | + tifm_media_type_name(sock->type, 1))) |
58 | 69 | return -ENOMEM; |
59 | 70 |
|
60 | 71 | return 0; |
@@ -132,7 +143,7 @@ static int tifm_device_resume(struct device *dev) |
132 | 143 |
|
133 | 144 | static struct bus_type tifm_bus_type = { |
134 | 145 | .name = "tifm", |
135 | | - .match = tifm_match, |
| 146 | + .match = tifm_bus_match, |
136 | 147 | .uevent = tifm_uevent, |
137 | 148 | .probe = tifm_device_probe, |
138 | 149 | .remove = tifm_device_remove, |
|
0 commit comments