diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-01-30 17:23:50 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-31 04:40:41 -0500 |
commit | 8cd98c826352b74281b8995a592b02e1c71b7204 (patch) | |
tree | ceaebabd2b008c160a99b1ed046b999cdcd080cd | |
parent | 2bdaef1afc15ae675a1d26e19d2b77bde215ef4a (diff) |
staging: comedi: das08_cs: convert to auto attach
Convert this pcmcia driver to the comedi auto attach mechanism.
This allows getting rid of the "hack" needed to pass the pcmcia_device
pointer from the pcmcia_driver to the comedi_driver.
We still need the boardinfo because the das08 driver uses it. But we
can get rid of the duplicate that allowed attaching with the driver
name.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/drivers/das08_cs.c | 130 |
1 files changed, 48 insertions, 82 deletions
diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c index ff67348be77d..23fdb119ada6 100644 --- a/drivers/staging/comedi/drivers/das08_cs.c +++ b/drivers/staging/comedi/drivers/das08_cs.c | |||
@@ -51,81 +51,25 @@ Command support does not exist, but could be added for this board. | |||
51 | 51 | ||
52 | #include "../comedidev.h" | 52 | #include "../comedidev.h" |
53 | 53 | ||
54 | #include "das08.h" | ||
55 | |||
56 | /* pcmcia includes */ | ||
57 | #include <pcmcia/cistpl.h> | 54 | #include <pcmcia/cistpl.h> |
58 | #include <pcmcia/ds.h> | 55 | #include <pcmcia/ds.h> |
59 | 56 | ||
57 | #include "das08.h" | ||
58 | |||
60 | static const struct das08_board_struct das08_cs_boards[] = { | 59 | static const struct das08_board_struct das08_cs_boards[] = { |
61 | { | 60 | { |
62 | .name = "pcm-das08", | 61 | .name = "pcm-das08", |
63 | .id = 0x0, /* XXX */ | 62 | .id = 0x0, /* XXX */ |
64 | .bustype = pcmcia, | 63 | .bustype = pcmcia, |
65 | .ai_nbits = 12, | 64 | .ai_nbits = 12, |
66 | .ai_pg = das08_bipolar5, | 65 | .ai_pg = das08_bipolar5, |
67 | .ai_encoding = das08_pcm_encode12, | 66 | .ai_encoding = das08_pcm_encode12, |
68 | .di_nchan = 3, | 67 | .di_nchan = 3, |
69 | .do_nchan = 3, | 68 | .do_nchan = 3, |
70 | .iosize = 16, | 69 | .iosize = 16, |
71 | }, | ||
72 | /* duplicate so driver name can be used also */ | ||
73 | { | ||
74 | .name = "das08_cs", | ||
75 | .id = 0x0, /* XXX */ | ||
76 | .bustype = pcmcia, | ||
77 | .ai_nbits = 12, | ||
78 | .ai_pg = das08_bipolar5, | ||
79 | .ai_encoding = das08_pcm_encode12, | ||
80 | .di_nchan = 3, | ||
81 | .do_nchan = 3, | ||
82 | .iosize = 16, | ||
83 | }, | 70 | }, |
84 | }; | 71 | }; |
85 | 72 | ||
86 | static struct pcmcia_device *cur_dev; | ||
87 | |||
88 | static int das08_cs_attach(struct comedi_device *dev, | ||
89 | struct comedi_devconfig *it) | ||
90 | { | ||
91 | const struct das08_board_struct *thisboard = comedi_board(dev); | ||
92 | struct das08_private_struct *devpriv; | ||
93 | unsigned long iobase; | ||
94 | struct pcmcia_device *link = cur_dev; /* XXX hack */ | ||
95 | |||
96 | devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); | ||
97 | if (!devpriv) | ||
98 | return -ENOMEM; | ||
99 | dev->private = devpriv; | ||
100 | |||
101 | dev_info(dev->class_dev, "das08_cs: attach\n"); | ||
102 | /* deal with a pci board */ | ||
103 | |||
104 | if (thisboard->bustype == pcmcia) { | ||
105 | if (link == NULL) { | ||
106 | dev_err(dev->class_dev, "no pcmcia cards found\n"); | ||
107 | return -EIO; | ||
108 | } | ||
109 | iobase = link->resource[0]->start; | ||
110 | } else { | ||
111 | dev_err(dev->class_dev, | ||
112 | "bug! board does not have PCMCIA bustype\n"); | ||
113 | return -EINVAL; | ||
114 | } | ||
115 | |||
116 | return das08_common_attach(dev, iobase); | ||
117 | } | ||
118 | |||
119 | static struct comedi_driver driver_das08_cs = { | ||
120 | .driver_name = "das08_cs", | ||
121 | .module = THIS_MODULE, | ||
122 | .attach = das08_cs_attach, | ||
123 | .detach = das08_common_detach, | ||
124 | .board_name = &das08_cs_boards[0].name, | ||
125 | .num_names = ARRAY_SIZE(das08_cs_boards), | ||
126 | .offset = sizeof(struct das08_board_struct), | ||
127 | }; | ||
128 | |||
129 | static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, | 73 | static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, |
130 | void *priv_data) | 74 | void *priv_data) |
131 | { | 75 | { |
@@ -135,35 +79,58 @@ static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, | |||
135 | return pcmcia_request_io(p_dev); | 79 | return pcmcia_request_io(p_dev); |
136 | } | 80 | } |
137 | 81 | ||
138 | static int das08_pcmcia_attach(struct pcmcia_device *link) | 82 | static int das08_cs_auto_attach(struct comedi_device *dev, |
83 | unsigned long context) | ||
139 | { | 84 | { |
85 | struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); | ||
86 | struct das08_private_struct *devpriv; | ||
87 | unsigned long iobase; | ||
140 | int ret; | 88 | int ret; |
141 | 89 | ||
90 | /* The das08 driver needs the board_ptr */ | ||
91 | dev->board_ptr = &das08_cs_boards[0]; | ||
92 | |||
142 | link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; | 93 | link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO; |
143 | 94 | ||
144 | ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); | 95 | ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); |
145 | if (ret) | 96 | if (ret) |
146 | goto failed; | 97 | return ret; |
147 | 98 | ||
148 | if (!link->irq) | 99 | if (!link->irq) |
149 | goto failed; | 100 | return -EINVAL; |
150 | 101 | ||
151 | ret = pcmcia_enable_device(link); | 102 | ret = pcmcia_enable_device(link); |
152 | if (ret) | 103 | if (ret) |
153 | goto failed; | 104 | return ret; |
105 | iobase = link->resource[0]->start; | ||
106 | |||
107 | devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); | ||
108 | if (!devpriv) | ||
109 | return -ENOMEM; | ||
110 | dev->private = devpriv; | ||
111 | |||
112 | return das08_common_attach(dev, iobase); | ||
113 | } | ||
154 | 114 | ||
155 | cur_dev = link; | 115 | static void das08_cs_detach(struct comedi_device *dev) |
156 | return 0; | 116 | { |
117 | struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); | ||
157 | 118 | ||
158 | failed: | 119 | das08_common_detach(dev); |
159 | pcmcia_disable_device(link); | 120 | if (dev->iobase) |
160 | return ret; | 121 | pcmcia_disable_device(link); |
161 | } | 122 | } |
162 | 123 | ||
163 | static void das08_pcmcia_detach(struct pcmcia_device *link) | 124 | static struct comedi_driver driver_das08_cs = { |
125 | .driver_name = "das08_cs", | ||
126 | .module = THIS_MODULE, | ||
127 | .auto_attach = das08_cs_auto_attach, | ||
128 | .detach = das08_cs_detach, | ||
129 | }; | ||
130 | |||
131 | static int das08_pcmcia_attach(struct pcmcia_device *link) | ||
164 | { | 132 | { |
165 | pcmcia_disable_device(link); | 133 | return comedi_pcmcia_auto_config(link, &driver_das08_cs); |
166 | cur_dev = NULL; | ||
167 | } | 134 | } |
168 | 135 | ||
169 | static const struct pcmcia_device_id das08_cs_id_table[] = { | 136 | static const struct pcmcia_device_id das08_cs_id_table[] = { |
@@ -175,11 +142,10 @@ MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table); | |||
175 | static struct pcmcia_driver das08_cs_driver = { | 142 | static struct pcmcia_driver das08_cs_driver = { |
176 | .name = "pcm-das08", | 143 | .name = "pcm-das08", |
177 | .owner = THIS_MODULE, | 144 | .owner = THIS_MODULE, |
178 | .probe = das08_pcmcia_attach, | ||
179 | .remove = das08_pcmcia_detach, | ||
180 | .id_table = das08_cs_id_table, | 145 | .id_table = das08_cs_id_table, |
146 | .probe = das08_pcmcia_attach, | ||
147 | .remove = comedi_pcmcia_auto_unconfig, | ||
181 | }; | 148 | }; |
182 | |||
183 | module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver); | 149 | module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver); |
184 | 150 | ||
185 | MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, " | 151 | MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, " |