Commit e23f2b8a authored by Alex Dubov's avatar Alex Dubov Committed by Pierre Ossman

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: default avatarAlex Dubov <oakad@yahoo.com>
Signed-off-by: default avatarPierre Ossman <drzeus@drzeus.cx>
parent 8dc4a61e
...@@ -73,7 +73,7 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id) ...@@ -73,7 +73,7 @@ static irqreturn_t tifm_7xx1_isr(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static tifm_media_id tifm_7xx1_toggle_sock_power(char __iomem *sock_addr, static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr,
int is_x2) int is_x2)
{ {
unsigned int s_state; unsigned int s_state;
...@@ -90,7 +90,7 @@ static tifm_media_id tifm_7xx1_toggle_sock_power(char __iomem *sock_addr, ...@@ -90,7 +90,7 @@ static tifm_media_id tifm_7xx1_toggle_sock_power(char __iomem *sock_addr,
s_state = readl(sock_addr + SOCK_PRESENT_STATE); s_state = readl(sock_addr + SOCK_PRESENT_STATE);
if (!(TIFM_SOCK_STATE_OCCUPIED & s_state)) if (!(TIFM_SOCK_STATE_OCCUPIED & s_state))
return FM_NULL; return 0;
if (is_x2) { if (is_x2) {
writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL); writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL);
...@@ -129,7 +129,7 @@ static int tifm_7xx1_switch_media(void *data) ...@@ -129,7 +129,7 @@ static int tifm_7xx1_switch_media(void *data)
{ {
struct tifm_adapter *fm = data; struct tifm_adapter *fm = data;
unsigned long flags; unsigned long flags;
tifm_media_id media_id; unsigned char media_id;
char *card_name = "xx"; char *card_name = "xx";
int cnt, rc; int cnt, rc;
struct tifm_dev *sock; struct tifm_dev *sock;
...@@ -184,7 +184,7 @@ static int tifm_7xx1_switch_media(void *data) ...@@ -184,7 +184,7 @@ static int tifm_7xx1_switch_media(void *data)
if (sock) { if (sock) {
sock->addr = tifm_7xx1_sock_addr(fm->addr, sock->addr = tifm_7xx1_sock_addr(fm->addr,
cnt); cnt);
sock->media_id = media_id; sock->type = media_id;
sock->socket_id = cnt; sock->socket_id = cnt;
switch (media_id) { switch (media_id) {
case 1: case 1:
...@@ -266,7 +266,7 @@ static int tifm_7xx1_resume(struct pci_dev *dev) ...@@ -266,7 +266,7 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
struct tifm_adapter *fm = pci_get_drvdata(dev); struct tifm_adapter *fm = pci_get_drvdata(dev);
int cnt, rc; int cnt, rc;
unsigned long flags; unsigned long flags;
tifm_media_id new_ids[fm->num_sockets]; unsigned char new_ids[fm->num_sockets];
pci_set_power_state(dev, PCI_D0); pci_set_power_state(dev, PCI_D0);
pci_restore_state(dev); pci_restore_state(dev);
...@@ -285,10 +285,10 @@ static int tifm_7xx1_resume(struct pci_dev *dev) ...@@ -285,10 +285,10 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
fm->socket_change_set = 0; fm->socket_change_set = 0;
for (cnt = 0; cnt < fm->num_sockets; cnt++) { for (cnt = 0; cnt < fm->num_sockets; cnt++) {
if (fm->sockets[cnt]) { if (fm->sockets[cnt]) {
if (fm->sockets[cnt]->media_id == new_ids[cnt]) if (fm->sockets[cnt]->type == new_ids[cnt])
fm->socket_change_set |= 1 << cnt; fm->socket_change_set |= 1 << cnt;
fm->sockets[cnt]->media_id = new_ids[cnt]; fm->sockets[cnt]->type = new_ids[cnt];
} }
} }
......
...@@ -19,42 +19,53 @@ ...@@ -19,42 +19,53 @@
static DEFINE_IDR(tifm_adapter_idr); static DEFINE_IDR(tifm_adapter_idr);
static DEFINE_SPINLOCK(tifm_adapter_lock); static DEFINE_SPINLOCK(tifm_adapter_lock);
static tifm_media_id *tifm_device_match(tifm_media_id *ids, static const char *tifm_media_type_name(unsigned char type, unsigned char nt)
struct tifm_dev *dev)
{ {
while (*ids) { const char *card_type_name[3][3] = {
if (dev->media_id == *ids) { "SmartMedia/xD", "MemoryStick", "MMC/SD" },
return ids; { "XD", "MS", "SD"},
ids++; { "xd", "ms", "sd"}
} };
if (nt > 2 || type < 1 || type > 3)
return NULL; return NULL;
return card_type_name[nt][type - 1];
} }
static int tifm_match(struct device *dev, struct device_driver *drv) static int tifm_dev_match(struct tifm_dev *sock, struct tifm_device_id *id)
{ {
struct tifm_dev *fm_dev = container_of(dev, struct tifm_dev, dev); if (sock->type == id->type)
struct tifm_driver *fm_drv; return 1;
return 0;
}
static int tifm_bus_match(struct device *dev, struct device_driver *drv)
{
struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
struct tifm_driver *fm_drv = container_of(drv, struct tifm_driver,
driver);
struct tifm_device_id *ids = fm_drv->id_table;
fm_drv = container_of(drv, struct tifm_driver, driver); if (ids) {
if (!fm_drv->id_table) while (ids->type) {
return -EINVAL; if (tifm_dev_match(sock, ids))
if (tifm_device_match(fm_drv->id_table, fm_dev))
return 1; return 1;
return -ENODEV; ++ids;
}
}
return 0;
} }
static int tifm_uevent(struct device *dev, char **envp, int num_envp, static int tifm_uevent(struct device *dev, char **envp, int num_envp,
char *buffer, int buffer_size) char *buffer, int buffer_size)
{ {
struct tifm_dev *fm_dev; struct tifm_dev *sock = container_of(dev, struct tifm_dev, dev);
int i = 0; int i = 0;
int length = 0; int length = 0;
const char *card_type_name[] = {"INV", "SM", "MS", "SD"};
if (!dev || !(fm_dev = container_of(dev, struct tifm_dev, dev)))
return -ENODEV;
if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length, if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length,
"TIFM_CARD_TYPE=%s", card_type_name[fm_dev->media_id])) "TIFM_CARD_TYPE=%s",
tifm_media_type_name(sock->type, 1)))
return -ENOMEM; return -ENOMEM;
return 0; return 0;
...@@ -132,7 +143,7 @@ static int tifm_device_resume(struct device *dev) ...@@ -132,7 +143,7 @@ static int tifm_device_resume(struct device *dev)
static struct bus_type tifm_bus_type = { static struct bus_type tifm_bus_type = {
.name = "tifm", .name = "tifm",
.match = tifm_match, .match = tifm_bus_match,
.uevent = tifm_uevent, .uevent = tifm_uevent,
.probe = tifm_device_probe, .probe = tifm_device_probe,
.remove = tifm_device_remove, .remove = tifm_device_remove,
......
...@@ -948,7 +948,7 @@ static int tifm_sd_resume(struct tifm_dev *sock) ...@@ -948,7 +948,7 @@ static int tifm_sd_resume(struct tifm_dev *sock)
struct mmc_host *mmc = tifm_get_drvdata(sock); struct mmc_host *mmc = tifm_get_drvdata(sock);
struct tifm_sd *host = mmc_priv(mmc); struct tifm_sd *host = mmc_priv(mmc);
if (sock->media_id != FM_SD if (sock->type != TIFM_TYPE_SD
|| tifm_sd_initialize_host(host)) { || tifm_sd_initialize_host(host)) {
tifm_eject(sock); tifm_eject(sock);
return 0; return 0;
...@@ -964,8 +964,8 @@ static int tifm_sd_resume(struct tifm_dev *sock) ...@@ -964,8 +964,8 @@ static int tifm_sd_resume(struct tifm_dev *sock)
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
static tifm_media_id tifm_sd_id_tbl[] = { static struct tifm_device_id tifm_sd_id_tbl[] = {
FM_SD, 0 { TIFM_TYPE_SD }, { }
}; };
static struct tifm_driver tifm_sd_driver = { static struct tifm_driver tifm_sd_driver = {
......
...@@ -74,13 +74,19 @@ enum { ...@@ -74,13 +74,19 @@ enum {
#define TIFM_DMA_TX 0x00008000 /* Meaning of this constant is unverified */ #define TIFM_DMA_TX 0x00008000 /* Meaning of this constant is unverified */
#define TIFM_DMA_EN 0x00000001 /* Meaning of this constant is unverified */ #define TIFM_DMA_EN 0x00000001 /* Meaning of this constant is unverified */
typedef enum {FM_NULL = 0, FM_XD = 0x01, FM_MS = 0x02, FM_SD = 0x03} tifm_media_id; #define TIFM_TYPE_XD 1
#define TIFM_TYPE_MS 2
#define TIFM_TYPE_SD 3
struct tifm_device_id {
unsigned char type;
};
struct tifm_driver; struct tifm_driver;
struct tifm_dev { struct tifm_dev {
char __iomem *addr; char __iomem *addr;
spinlock_t lock; spinlock_t lock;
tifm_media_id media_id; unsigned char type;
unsigned int socket_id; unsigned int socket_id;
void (*card_event)(struct tifm_dev *sock); void (*card_event)(struct tifm_dev *sock);
...@@ -90,7 +96,7 @@ struct tifm_dev { ...@@ -90,7 +96,7 @@ struct tifm_dev {
}; };
struct tifm_driver { struct tifm_driver {
tifm_media_id *id_table; struct tifm_device_id *id_table;
int (*probe)(struct tifm_dev *dev); int (*probe)(struct tifm_dev *dev);
void (*remove)(struct tifm_dev *dev); void (*remove)(struct tifm_dev *dev);
int (*suspend)(struct tifm_dev *dev, int (*suspend)(struct tifm_dev *dev,
...@@ -141,8 +147,4 @@ static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data) ...@@ -141,8 +147,4 @@ static inline void tifm_set_drvdata(struct tifm_dev *dev, void *data)
dev_set_drvdata(&dev->dev, data); dev_set_drvdata(&dev->dev, data);
} }
struct tifm_device_id {
tifm_media_id media_id;
};
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment