diff options
Diffstat (limited to 'drivers/char/pcmcia/cm4000_cs.c')
-rw-r--r-- | drivers/char/pcmcia/cm4000_cs.c | 162 |
1 files changed, 51 insertions, 111 deletions
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c index 61681c9f3f72..649677b5dc36 100644 --- a/drivers/char/pcmcia/cm4000_cs.c +++ b/drivers/char/pcmcia/cm4000_cs.c | |||
@@ -66,7 +66,6 @@ static char *version = "cm4000_cs.c v2.4.0gm5 - All bugs added by Harald Welte"; | |||
66 | #define T_100MSEC msecs_to_jiffies(100) | 66 | #define T_100MSEC msecs_to_jiffies(100) |
67 | #define T_500MSEC msecs_to_jiffies(500) | 67 | #define T_500MSEC msecs_to_jiffies(500) |
68 | 68 | ||
69 | static void cm4000_detach(dev_link_t *link); | ||
70 | static void cm4000_release(dev_link_t *link); | 69 | static void cm4000_release(dev_link_t *link); |
71 | 70 | ||
72 | static int major; /* major number we get from the kernel */ | 71 | static int major; /* major number we get from the kernel */ |
@@ -156,7 +155,6 @@ struct cm4000_dev { | |||
156 | /*sbuf*/ 512*sizeof(char) - \ | 155 | /*sbuf*/ 512*sizeof(char) - \ |
157 | /*queue*/ 4*sizeof(wait_queue_head_t)) | 156 | /*queue*/ 4*sizeof(wait_queue_head_t)) |
158 | 157 | ||
159 | static dev_info_t dev_info = MODULE_NAME; | ||
160 | static dev_link_t *dev_table[CM4000_MAX_DEV]; | 158 | static dev_link_t *dev_table[CM4000_MAX_DEV]; |
161 | 159 | ||
162 | /* This table doesn't use spaces after the comma between fields and thus | 160 | /* This table doesn't use spaces after the comma between fields and thus |
@@ -1864,68 +1862,36 @@ cs_release: | |||
1864 | link->state &= ~DEV_CONFIG_PENDING; | 1862 | link->state &= ~DEV_CONFIG_PENDING; |
1865 | } | 1863 | } |
1866 | 1864 | ||
1867 | static int cm4000_event(event_t event, int priority, | 1865 | static int cm4000_suspend(struct pcmcia_device *p_dev) |
1868 | event_callback_args_t *args) | ||
1869 | { | 1866 | { |
1870 | dev_link_t *link; | 1867 | dev_link_t *link = dev_to_instance(p_dev); |
1871 | struct cm4000_dev *dev; | 1868 | struct cm4000_dev *dev; |
1872 | int devno; | ||
1873 | 1869 | ||
1874 | link = args->client_data; | ||
1875 | dev = link->priv; | 1870 | dev = link->priv; |
1876 | 1871 | ||
1877 | DEBUGP(3, dev, "-> cm4000_event\n"); | 1872 | link->state |= DEV_SUSPEND; |
1878 | for (devno = 0; devno < CM4000_MAX_DEV; devno++) | 1873 | if (link->state & DEV_CONFIG) |
1879 | if (dev_table[devno] == link) | 1874 | pcmcia_release_configuration(link->handle); |
1880 | break; | 1875 | stop_monitor(dev); |
1881 | 1876 | ||
1882 | if (devno == CM4000_MAX_DEV) | 1877 | return 0; |
1883 | return CS_BAD_ADAPTER; | 1878 | } |
1884 | 1879 | ||
1885 | switch (event) { | 1880 | static int cm4000_resume(struct pcmcia_device *p_dev) |
1886 | case CS_EVENT_CARD_INSERTION: | 1881 | { |
1887 | DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n"); | 1882 | dev_link_t *link = dev_to_instance(p_dev); |
1888 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | 1883 | struct cm4000_dev *dev; |
1889 | cm4000_config(link, devno); | 1884 | |
1890 | break; | 1885 | dev = link->priv; |
1891 | case CS_EVENT_CARD_REMOVAL: | 1886 | |
1892 | DEBUGP(5, dev, "CS_EVENT_CARD_REMOVAL\n"); | 1887 | link->state &= ~DEV_SUSPEND; |
1893 | link->state &= ~DEV_PRESENT; | 1888 | if (link->state & DEV_CONFIG) |
1894 | stop_monitor(dev); | 1889 | pcmcia_request_configuration(link->handle, &link->conf); |
1895 | break; | 1890 | |
1896 | case CS_EVENT_PM_SUSPEND: | 1891 | if (link->open) |
1897 | DEBUGP(5, dev, "CS_EVENT_PM_SUSPEND " | 1892 | start_monitor(dev); |
1898 | "(fall-through to CS_EVENT_RESET_PHYSICAL)\n"); | 1893 | |
1899 | link->state |= DEV_SUSPEND; | 1894 | return 0; |
1900 | /* fall-through */ | ||
1901 | case CS_EVENT_RESET_PHYSICAL: | ||
1902 | DEBUGP(5, dev, "CS_EVENT_RESET_PHYSICAL\n"); | ||
1903 | if (link->state & DEV_CONFIG) { | ||
1904 | DEBUGP(5, dev, "ReleaseConfiguration\n"); | ||
1905 | pcmcia_release_configuration(link->handle); | ||
1906 | } | ||
1907 | stop_monitor(dev); | ||
1908 | break; | ||
1909 | case CS_EVENT_PM_RESUME: | ||
1910 | DEBUGP(5, dev, "CS_EVENT_PM_RESUME " | ||
1911 | "(fall-through to CS_EVENT_CARD_RESET)\n"); | ||
1912 | link->state &= ~DEV_SUSPEND; | ||
1913 | /* fall-through */ | ||
1914 | case CS_EVENT_CARD_RESET: | ||
1915 | DEBUGP(5, dev, "CS_EVENT_CARD_RESET\n"); | ||
1916 | if ((link->state & DEV_CONFIG)) { | ||
1917 | DEBUGP(5, dev, "RequestConfiguration\n"); | ||
1918 | pcmcia_request_configuration(link->handle, &link->conf); | ||
1919 | } | ||
1920 | if (link->open) | ||
1921 | start_monitor(dev); | ||
1922 | break; | ||
1923 | default: | ||
1924 | DEBUGP(5, dev, "unknown event %.2x\n", event); | ||
1925 | break; | ||
1926 | } | ||
1927 | DEBUGP(3, dev, "<- cm4000_event\n"); | ||
1928 | return CS_SUCCESS; | ||
1929 | } | 1895 | } |
1930 | 1896 | ||
1931 | static void cm4000_release(dev_link_t *link) | 1897 | static void cm4000_release(dev_link_t *link) |
@@ -1935,11 +1901,10 @@ static void cm4000_release(dev_link_t *link) | |||
1935 | pcmcia_release_io(link->handle, &link->io); | 1901 | pcmcia_release_io(link->handle, &link->io); |
1936 | } | 1902 | } |
1937 | 1903 | ||
1938 | static dev_link_t *cm4000_attach(void) | 1904 | static int cm4000_attach(struct pcmcia_device *p_dev) |
1939 | { | 1905 | { |
1940 | struct cm4000_dev *dev; | 1906 | struct cm4000_dev *dev; |
1941 | dev_link_t *link; | 1907 | dev_link_t *link; |
1942 | client_reg_t client_reg; | ||
1943 | int i; | 1908 | int i; |
1944 | 1909 | ||
1945 | for (i = 0; i < CM4000_MAX_DEV; i++) | 1910 | for (i = 0; i < CM4000_MAX_DEV; i++) |
@@ -1948,76 +1913,55 @@ static dev_link_t *cm4000_attach(void) | |||
1948 | 1913 | ||
1949 | if (i == CM4000_MAX_DEV) { | 1914 | if (i == CM4000_MAX_DEV) { |
1950 | printk(KERN_NOTICE MODULE_NAME ": all devices in use\n"); | 1915 | printk(KERN_NOTICE MODULE_NAME ": all devices in use\n"); |
1951 | return NULL; | 1916 | return -ENODEV; |
1952 | } | 1917 | } |
1953 | 1918 | ||
1954 | /* create a new cm4000_cs device */ | 1919 | /* create a new cm4000_cs device */ |
1955 | dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL); | 1920 | dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL); |
1956 | if (dev == NULL) | 1921 | if (dev == NULL) |
1957 | return NULL; | 1922 | return -ENOMEM; |
1958 | 1923 | ||
1959 | link = &dev->link; | 1924 | link = &dev->link; |
1960 | link->priv = dev; | 1925 | link->priv = dev; |
1961 | link->conf.IntType = INT_MEMORY_AND_IO; | 1926 | link->conf.IntType = INT_MEMORY_AND_IO; |
1962 | dev_table[i] = link; | 1927 | dev_table[i] = link; |
1963 | 1928 | ||
1964 | /* register with card services */ | ||
1965 | client_reg.dev_info = &dev_info; | ||
1966 | client_reg.EventMask = | ||
1967 | CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | | ||
1968 | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | | ||
1969 | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; | ||
1970 | client_reg.Version = 0x0210; | ||
1971 | client_reg.event_callback_args.client_data = link; | ||
1972 | |||
1973 | i = pcmcia_register_client(&link->handle, &client_reg); | ||
1974 | if (i) { | ||
1975 | cs_error(link->handle, RegisterClient, i); | ||
1976 | cm4000_detach(link); | ||
1977 | return NULL; | ||
1978 | } | ||
1979 | |||
1980 | init_waitqueue_head(&dev->devq); | 1929 | init_waitqueue_head(&dev->devq); |
1981 | init_waitqueue_head(&dev->ioq); | 1930 | init_waitqueue_head(&dev->ioq); |
1982 | init_waitqueue_head(&dev->atrq); | 1931 | init_waitqueue_head(&dev->atrq); |
1983 | init_waitqueue_head(&dev->readq); | 1932 | init_waitqueue_head(&dev->readq); |
1984 | 1933 | ||
1985 | return link; | 1934 | link->handle = p_dev; |
1986 | } | 1935 | p_dev->instance = link; |
1987 | |||
1988 | static void cm4000_detach_by_devno(int devno, dev_link_t * link) | ||
1989 | { | ||
1990 | struct cm4000_dev *dev = link->priv; | ||
1991 | |||
1992 | DEBUGP(3, dev, "-> detach_by_devno(devno=%d)\n", devno); | ||
1993 | |||
1994 | if (link->state & DEV_CONFIG) { | ||
1995 | DEBUGP(5, dev, "device still configured (try to release it)\n"); | ||
1996 | cm4000_release(link); | ||
1997 | } | ||
1998 | 1936 | ||
1999 | if (link->handle) { | 1937 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; |
2000 | pcmcia_deregister_client(link->handle); | 1938 | cm4000_config(link, i); |
2001 | } | ||
2002 | 1939 | ||
2003 | dev_table[devno] = NULL; | 1940 | return 0; |
2004 | kfree(dev); | ||
2005 | return; | ||
2006 | } | 1941 | } |
2007 | 1942 | ||
2008 | static void cm4000_detach(dev_link_t * link) | 1943 | static void cm4000_detach(struct pcmcia_device *p_dev) |
2009 | { | 1944 | { |
2010 | int i; | 1945 | dev_link_t *link = dev_to_instance(p_dev); |
1946 | struct cm4000_dev *dev = link->priv; | ||
1947 | int devno; | ||
2011 | 1948 | ||
2012 | /* find device */ | 1949 | /* find device */ |
2013 | for (i = 0; i < CM4000_MAX_DEV; i++) | 1950 | for (devno = 0; devno < CM4000_MAX_DEV; devno++) |
2014 | if (dev_table[i] == link) | 1951 | if (dev_table[devno] == link) |
2015 | break; | 1952 | break; |
2016 | 1953 | if (devno == CM4000_MAX_DEV) | |
2017 | if (i == CM4000_MAX_DEV) | ||
2018 | return; | 1954 | return; |
2019 | 1955 | ||
2020 | cm4000_detach_by_devno(i, link); | 1956 | link->state &= ~DEV_PRESENT; |
1957 | stop_monitor(dev); | ||
1958 | |||
1959 | if (link->state & DEV_CONFIG) | ||
1960 | cm4000_release(link); | ||
1961 | |||
1962 | dev_table[devno] = NULL; | ||
1963 | kfree(dev); | ||
1964 | |||
2021 | return; | 1965 | return; |
2022 | } | 1966 | } |
2023 | 1967 | ||
@@ -2042,9 +1986,10 @@ static struct pcmcia_driver cm4000_driver = { | |||
2042 | .drv = { | 1986 | .drv = { |
2043 | .name = "cm4000_cs", | 1987 | .name = "cm4000_cs", |
2044 | }, | 1988 | }, |
2045 | .attach = cm4000_attach, | 1989 | .probe = cm4000_attach, |
2046 | .detach = cm4000_detach, | 1990 | .remove = cm4000_detach, |
2047 | .event = cm4000_event, | 1991 | .suspend = cm4000_suspend, |
1992 | .resume = cm4000_resume, | ||
2048 | .id_table = cm4000_ids, | 1993 | .id_table = cm4000_ids, |
2049 | }; | 1994 | }; |
2050 | 1995 | ||
@@ -2064,13 +2009,8 @@ static int __init cmm_init(void) | |||
2064 | 2009 | ||
2065 | static void __exit cmm_exit(void) | 2010 | static void __exit cmm_exit(void) |
2066 | { | 2011 | { |
2067 | int i; | ||
2068 | |||
2069 | printk(KERN_INFO MODULE_NAME ": unloading\n"); | 2012 | printk(KERN_INFO MODULE_NAME ": unloading\n"); |
2070 | pcmcia_unregister_driver(&cm4000_driver); | 2013 | pcmcia_unregister_driver(&cm4000_driver); |
2071 | for (i = 0; i < CM4000_MAX_DEV; i++) | ||
2072 | if (dev_table[i]) | ||
2073 | cm4000_detach_by_devno(i, dev_table[i]); | ||
2074 | unregister_chrdev(major, DEVICE_NAME); | 2014 | unregister_chrdev(major, DEVICE_NAME); |
2075 | }; | 2015 | }; |
2076 | 2016 | ||