aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/serial_cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/serial/serial_cs.c')
-rw-r--r--drivers/serial/serial_cs.c119
1 files changed, 22 insertions, 97 deletions
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 7ce0c7e66d37..96969cb960a9 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -114,15 +114,7 @@ struct serial_cfg_mem {
114 114
115 115
116static void serial_config(dev_link_t * link); 116static void serial_config(dev_link_t * link);
117static int serial_event(event_t event, int priority,
118 event_callback_args_t * args);
119 117
120static dev_info_t dev_info = "serial_cs";
121
122static dev_link_t *serial_attach(void);
123static void serial_detach(dev_link_t *);
124
125static dev_link_t *dev_list = NULL;
126 118
127/*====================================================================== 119/*======================================================================
128 120
@@ -159,8 +151,9 @@ static void serial_remove(dev_link_t *link)
159 } 151 }
160} 152}
161 153
162static void serial_suspend(dev_link_t *link) 154static int serial_suspend(struct pcmcia_device *dev)
163{ 155{
156 dev_link_t *link = dev_to_instance(dev);
164 link->state |= DEV_SUSPEND; 157 link->state |= DEV_SUSPEND;
165 158
166 if (link->state & DEV_CONFIG) { 159 if (link->state & DEV_CONFIG) {
@@ -173,10 +166,13 @@ static void serial_suspend(dev_link_t *link)
173 if (!info->slave) 166 if (!info->slave)
174 pcmcia_release_configuration(link->handle); 167 pcmcia_release_configuration(link->handle);
175 } 168 }
169
170 return 0;
176} 171}
177 172
178static void serial_resume(dev_link_t *link) 173static int serial_resume(struct pcmcia_device *dev)
179{ 174{
175 dev_link_t *link = dev_to_instance(dev);
180 link->state &= ~DEV_SUSPEND; 176 link->state &= ~DEV_SUSPEND;
181 177
182 if (DEV_OK(link)) { 178 if (DEV_OK(link)) {
@@ -189,6 +185,8 @@ static void serial_resume(dev_link_t *link)
189 for (i = 0; i < info->ndev; i++) 185 for (i = 0; i < info->ndev; i++)
190 serial8250_resume_port(info->line[i]); 186 serial8250_resume_port(info->line[i]);
191 } 187 }
188
189 return 0;
192} 190}
193 191
194/*====================================================================== 192/*======================================================================
@@ -199,19 +197,17 @@ static void serial_resume(dev_link_t *link)
199 197
200======================================================================*/ 198======================================================================*/
201 199
202static dev_link_t *serial_attach(void) 200static int serial_probe(struct pcmcia_device *p_dev)
203{ 201{
204 struct serial_info *info; 202 struct serial_info *info;
205 client_reg_t client_reg;
206 dev_link_t *link; 203 dev_link_t *link;
207 int ret;
208 204
209 DEBUG(0, "serial_attach()\n"); 205 DEBUG(0, "serial_attach()\n");
210 206
211 /* Create new serial device */ 207 /* Create new serial device */
212 info = kmalloc(sizeof (*info), GFP_KERNEL); 208 info = kmalloc(sizeof (*info), GFP_KERNEL);
213 if (!info) 209 if (!info)
214 return NULL; 210 return -ENOMEM;
215 memset(info, 0, sizeof (*info)); 211 memset(info, 0, sizeof (*info));
216 link = &info->link; 212 link = &info->link;
217 link->priv = info; 213 link->priv = info;
@@ -227,20 +223,12 @@ static dev_link_t *serial_attach(void)
227 } 223 }
228 link->conf.IntType = INT_MEMORY_AND_IO; 224 link->conf.IntType = INT_MEMORY_AND_IO;
229 225
230 /* Register with Card Services */ 226 link->handle = p_dev;
231 link->next = dev_list; 227 p_dev->instance = link;
232 dev_list = link; 228 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
233 client_reg.dev_info = &dev_info; 229 serial_config(link);
234 client_reg.Version = 0x0210;
235 client_reg.event_callback_args.client_data = link;
236 ret = pcmcia_register_client(&link->handle, &client_reg);
237 if (ret != CS_SUCCESS) {
238 cs_error(link->handle, RegisterClient, ret);
239 serial_detach(link);
240 return NULL;
241 }
242 230
243 return link; 231 return 0;
244} 232}
245 233
246/*====================================================================== 234/*======================================================================
@@ -252,21 +240,13 @@ static dev_link_t *serial_attach(void)
252 240
253======================================================================*/ 241======================================================================*/
254 242
255static void serial_detach(dev_link_t * link) 243static void serial_detach(struct pcmcia_device *p_dev)
256{ 244{
245 dev_link_t *link = dev_to_instance(p_dev);
257 struct serial_info *info = link->priv; 246 struct serial_info *info = link->priv;
258 dev_link_t **linkp;
259 int ret;
260 247
261 DEBUG(0, "serial_detach(0x%p)\n", link); 248 DEBUG(0, "serial_detach(0x%p)\n", link);
262 249
263 /* Locate device structure */
264 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
265 if (*linkp == link)
266 break;
267 if (*linkp == NULL)
268 return;
269
270 /* 250 /*
271 * Ensure any outstanding scheduled tasks are completed. 251 * Ensure any outstanding scheduled tasks are completed.
272 */ 252 */
@@ -277,14 +257,7 @@ static void serial_detach(dev_link_t * link)
277 */ 257 */
278 serial_remove(link); 258 serial_remove(link);
279 259
280 if (link->handle) { 260 /* free bits */
281 ret = pcmcia_deregister_client(link->handle);
282 if (ret != CS_SUCCESS)
283 cs_error(link->handle, DeregisterClient, ret);
284 }
285
286 /* Unlink device structure, free bits */
287 *linkp = link->next;
288 kfree(info); 261 kfree(info);
289} 262}
290 263
@@ -718,54 +691,6 @@ void serial_config(dev_link_t * link)
718 kfree(cfg_mem); 691 kfree(cfg_mem);
719} 692}
720 693
721/*======================================================================
722
723 The card status event handler. Mostly, this schedules other
724 stuff to run after an event is received. A CARD_REMOVAL event
725 also sets some flags to discourage the serial drivers from
726 talking to the ports.
727
728======================================================================*/
729
730static int
731serial_event(event_t event, int priority, event_callback_args_t * args)
732{
733 dev_link_t *link = args->client_data;
734 struct serial_info *info = link->priv;
735
736 DEBUG(1, "serial_event(0x%06x)\n", event);
737
738 switch (event) {
739 case CS_EVENT_CARD_REMOVAL:
740 serial_remove(link);
741 break;
742
743 case CS_EVENT_CARD_INSERTION:
744 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
745 serial_config(link);
746 break;
747
748 case CS_EVENT_PM_SUSPEND:
749 serial_suspend(link);
750 break;
751
752 case CS_EVENT_RESET_PHYSICAL:
753 if ((link->state & DEV_CONFIG) && !info->slave)
754 pcmcia_release_configuration(link->handle);
755 break;
756
757 case CS_EVENT_PM_RESUME:
758 serial_resume(link);
759 break;
760
761 case CS_EVENT_CARD_RESET:
762 if (DEV_OK(link) && !info->slave)
763 pcmcia_request_configuration(link->handle, &link->conf);
764 break;
765 }
766 return 0;
767}
768
769static struct pcmcia_device_id serial_ids[] = { 694static struct pcmcia_device_id serial_ids[] = {
770 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0057, 0x0021), 695 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0057, 0x0021),
771 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0089, 0x110a), 696 PCMCIA_PFC_DEVICE_MANF_CARD(1, 0x0089, 0x110a),
@@ -877,10 +802,11 @@ static struct pcmcia_driver serial_cs_driver = {
877 .drv = { 802 .drv = {
878 .name = "serial_cs", 803 .name = "serial_cs",
879 }, 804 },
880 .attach = serial_attach, 805 .probe = serial_probe,
881 .event = serial_event, 806 .remove = serial_detach,
882 .detach = serial_detach,
883 .id_table = serial_ids, 807 .id_table = serial_ids,
808 .suspend = serial_suspend,
809 .resume = serial_resume,
884}; 810};
885 811
886static int __init init_serial_cs(void) 812static int __init init_serial_cs(void)
@@ -891,7 +817,6 @@ static int __init init_serial_cs(void)
891static void __exit exit_serial_cs(void) 817static void __exit exit_serial_cs(void)
892{ 818{
893 pcmcia_unregister_driver(&serial_cs_driver); 819 pcmcia_unregister_driver(&serial_cs_driver);
894 BUG_ON(dev_list != NULL);
895} 820}
896 821
897module_init(init_serial_cs); 822module_init(init_serial_cs);