Skip to content

Commit e23f2b8

Browse files
oakadPierre Ossman
authored andcommitted
tifm: simplify bus match and uevent handlers
Remove code duplicating the kernel functionality and clean up data structures involved in driver matching. Signed-off-by: Alex Dubov <oakad@yahoo.com> Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
1 parent 8dc4a61 commit e23f2b8

4 files changed

Lines changed: 53 additions & 40 deletions

File tree

‎drivers/misc/tifm_7xx1.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id)
7373
return IRQ_HANDLED;
7474
}
7575

76-
static tifm_media_id tifm_7xx1_toggle_sock_power(char __iomem *sock_addr,
76+
static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr,
7777
int is_x2)
7878
{
7979
unsigned int s_state;
@@ -90,7 +90,7 @@ static tifm_media_id tifm_7xx1_toggle_sock_power(char __iomem *sock_addr,
9090

9191
s_state = readl(sock_addr + SOCK_PRESENT_STATE);
9292
if (!(TIFM_SOCK_STATE_OCCUPIED & s_state))
93-
return FM_NULL;
93+
return 0;
9494

9595
if (is_x2) {
9696
writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL);
@@ -129,7 +129,7 @@ static int tifm_7xx1_switch_media(void *data)
129129
{
130130
struct tifm_adapter *fm = data;
131131
unsigned long flags;
132-
tifm_media_id media_id;
132+
unsigned char media_id;
133133
char *card_name = "xx";
134134
int cnt, rc;
135135
struct tifm_dev *sock;
@@ -184,7 +184,7 @@ static int tifm_7xx1_switch_media(void *data)
184184
if (sock) {
185185
sock->addr = tifm_7xx1_sock_addr(fm->addr,
186186
cnt);
187-
sock->media_id = media_id;
187+
sock->type = media_id;
188188
sock->socket_id = cnt;
189189
switch (media_id) {
190190
case 1:
@@ -266,7 +266,7 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
266266
struct tifm_adapter *fm = pci_get_drvdata(dev);
267267
int cnt, rc;
268268
unsigned long flags;
269-
tifm_media_id new_ids[fm->num_sockets];
269+
unsigned char new_ids[fm->num_sockets];
270270

271271
pci_set_power_state(dev, PCI_D0);
272272
pci_restore_state(dev);
@@ -285,10 +285,10 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
285285
fm->socket_change_set = 0;
286286
for (cnt = 0; cnt < fm->num_sockets; cnt++) {
287287
if (fm->sockets[cnt]) {
288-
if (fm->sockets[cnt]->media_id == new_ids[cnt])
288+
if (fm->sockets[cnt]->type == new_ids[cnt])
289289
fm->socket_change_set |= 1 << cnt;
290290

291-
fm->sockets[cnt]->media_id = new_ids[cnt];
291+
fm->sockets[cnt]->type = new_ids[cnt];
292292
}
293293
}
294294

‎drivers/misc/tifm_core.c‎

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,53 @@
1919
static DEFINE_IDR(tifm_adapter_idr);
2020
static DEFINE_SPINLOCK(tifm_adapter_lock);
2121

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)
2423
{
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];
3133
}
3234

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)
3436
{
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)
4238
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;
4457
}
4558

4659
static int tifm_uevent(struct device *dev, char **envp, int num_envp,
4760
char *buffer, int buffer_size)
4861
{
49-
struct tifm_dev *fm_dev;
62+
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
5063
int i = 0;
5164
int length = 0;
52-
const char *card_type_name[] = {"INV", "SM", "MS", "SD"};
5365

54-
if (!dev || !(fm_dev = container_of(dev, struct tifm_dev, dev)))
55-
return -ENODEV;
5666
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)))
5869
return -ENOMEM;
5970

6071
return 0;
@@ -132,7 +143,7 @@ static int tifm_device_resume(struct device *dev)
132143

133144
static struct bus_type tifm_bus_type = {
134145
.name = "tifm",
135-
.match = tifm_match,
146+
.match = tifm_bus_match,
136147
.uevent = tifm_uevent,
137148
.probe = tifm_device_probe,
138149
.remove = tifm_device_remove,

‎drivers/mmc/tifm_sd.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ static int tifm_sd_resume(struct tifm_dev *sock)
948948
struct mmc_host *mmc = tifm_get_drvdata(sock);
949949
struct tifm_sd *host = mmc_priv(mmc);
950950

951-
if (sock->media_id != FM_SD
951+
if (sock->type != TIFM_TYPE_SD
952952
|| tifm_sd_initialize_host(host)) {
953953
tifm_eject(sock);
954954
return 0;
@@ -964,8 +964,8 @@ static int tifm_sd_resume(struct tifm_dev *sock)
964964

965965
#endif /* CONFIG_PM */
966966

967-
static tifm_media_id tifm_sd_id_tbl[] = {
968-
FM_SD, 0
967+
static struct tifm_device_id tifm_sd_id_tbl[] = {
968+
{ TIFM_TYPE_SD }, { }
969969
};
970970

971971
static struct tifm_driver tifm_sd_driver = {

‎include/linux/tifm.h‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,19 @@ enum {
7474
#define TIFM_DMA_TX 0x00008000 /* Meaning of this constant is unverified */
7575
#define TIFM_DMA_EN 0x00000001 /* Meaning of this constant is unverified */
7676

77-
typedef enum {FM_NULL = 0, FM_XD = 0x01, FM_MS = 0x02, FM_SD = 0x03} tifm_media_id;
77+
#define TIFM_TYPE_XD 1
78+
#define TIFM_TYPE_MS 2
79+
#define TIFM_TYPE_SD 3
80+
81+
struct tifm_device_id {
82+
unsigned char type;
83+
};
7884

7985
struct tifm_driver;
8086
struct tifm_dev {
8187
char __iomem *addr;
8288
spinlock_t lock;
83-
tifm_media_id media_id;
89+
unsigned char type;
8490
unsigned int socket_id;
8591

8692
void (*card_event)(struct tifm_dev *sock);
@@ -90,7 +96,7 @@ struct tifm_dev {
9096
};
9197

9298
struct tifm_driver {
93-
tifm_media_id *id_table;
99+
struct tifm_device_id *id_table;
94100
int (*probe)(struct tifm_dev *dev);
95101
void (*remove)(struct tifm_dev *dev);
96102
int (*suspend)(struct tifm_dev *dev,
@@ -141,8 +147,4 @@ static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data)
141147
dev_set_drvdata(&dev->dev, data);
142148
}
143149

144-
struct tifm_device_id {
145-
tifm_media_id media_id;
146-
};
147-
148150
#endif

0 commit comments

Comments
 (0)