Lines Matching +full:drv +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0
3 * card.c - contains functions for managing groups of PnP devices
13 #include <linux/dma-mapping.h>
19 static const struct pnp_card_device_id *match_card(struct pnp_card_driver *drv, in match_card() argument
22 const struct pnp_card_device_id *drv_id = drv->id_table; in match_card()
24 while (*drv_id->id) { in match_card()
25 if (compare_pnp_id(card->id, drv_id->id)) { in match_card()
33 !*drv_id->devs[i].id) in match_card()
37 if (compare_pnp_id(dev->id, in match_card()
38 drv_id->devs[i].id)) { in match_card()
55 dev->card_link = NULL; in card_remove()
60 struct pnp_card_driver *drv = to_pnp_card_driver(dev->driver); in card_remove_first() local
62 if (!dev->card || !drv) in card_remove_first()
64 if (drv->remove) in card_remove_first()
65 drv->remove(dev->card_link); in card_remove_first()
66 drv->link.remove = &card_remove; in card_remove_first()
67 kfree(dev->card_link); in card_remove_first()
71 static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv) in card_probe() argument
73 const struct pnp_card_device_id *id; in card_probe() local
77 if (!drv->probe) in card_probe()
79 id = match_card(drv, card); in card_probe()
80 if (!id) in card_probe()
86 clink->card = card; in card_probe()
87 clink->driver = drv; in card_probe()
88 clink->pm_state = PMSG_ON; in card_probe()
90 if (drv->probe(clink, id) >= 0) in card_probe()
95 if (dev->card_link == clink) in card_probe()
103 * pnp_add_card_id - adds an EISA id to the specified card
104 * @id: pointer to a pnp_id structure
107 static struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id) in pnp_add_card_id() argument
115 dev_id->id[0] = id[0]; in pnp_add_card_id()
116 dev_id->id[1] = id[1]; in pnp_add_card_id()
117 dev_id->id[2] = id[2]; in pnp_add_card_id()
118 dev_id->id[3] = tolower(id[3]); in pnp_add_card_id()
119 dev_id->id[4] = tolower(id[4]); in pnp_add_card_id()
120 dev_id->id[5] = tolower(id[5]); in pnp_add_card_id()
121 dev_id->id[6] = tolower(id[6]); in pnp_add_card_id()
122 dev_id->id[7] = '\0'; in pnp_add_card_id()
124 dev_id->next = NULL; in pnp_add_card_id()
125 ptr = card->id; in pnp_add_card_id()
126 while (ptr && ptr->next) in pnp_add_card_id()
127 ptr = ptr->next; in pnp_add_card_id()
129 ptr->next = dev_id; in pnp_add_card_id()
131 card->id = dev_id; in pnp_add_card_id()
138 struct pnp_id *id; in pnp_free_card_ids() local
141 id = card->id; in pnp_free_card_ids()
142 while (id) { in pnp_free_card_ids()
143 next = id->next; in pnp_free_card_ids()
144 kfree(id); in pnp_free_card_ids()
145 id = next; in pnp_free_card_ids()
157 struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid) in pnp_alloc_card() argument
166 card->protocol = protocol; in pnp_alloc_card()
167 card->number = id; in pnp_alloc_card()
169 card->dev.parent = &card->protocol->dev; in pnp_alloc_card()
170 dev_set_name(&card->dev, "%02x:%02x", card->protocol->number, card->number); in pnp_alloc_card()
172 card->dev.coherent_dma_mask = DMA_BIT_MASK(24); in pnp_alloc_card()
173 card->dev.dma_mask = &card->dev.coherent_dma_mask; in pnp_alloc_card()
190 str += sprintf(str, "%s\n", card->name); in name_show()
191 return (str - buf); in name_show()
201 struct pnp_id *pos = card->id; in card_id_show()
204 str += sprintf(str, "%s\n", pos->id); in card_id_show()
205 pos = pos->next; in card_id_show()
207 return (str - buf); in card_id_show()
214 int rc = device_create_file(&card->dev, &dev_attr_name); in pnp_interface_attach_card()
219 rc = device_create_file(&card->dev, &dev_attr_card_id); in pnp_interface_attach_card()
226 device_remove_file(&card->dev, &dev_attr_name); in pnp_interface_attach_card()
231 * pnp_add_card - adds a PnP card to the PnP Layer
239 card->dev.bus = NULL; in pnp_add_card()
240 card->dev.release = &pnp_release_card; in pnp_add_card()
241 error = device_register(&card->dev); in pnp_add_card()
243 dev_err(&card->dev, "could not register (err=%d)\n", error); in pnp_add_card()
244 put_device(&card->dev); in pnp_add_card()
250 list_add_tail(&card->global_list, &pnp_cards); in pnp_add_card()
251 list_add_tail(&card->protocol_list, &card->protocol->cards); in pnp_add_card()
257 list_for_each(pos, &card->devices) { in pnp_add_card()
264 struct pnp_card_driver *drv = in pnp_add_card() local
267 card_probe(card, drv); in pnp_add_card()
273 * pnp_remove_card - removes a PnP card from the PnP Layer
280 device_unregister(&card->dev); in pnp_remove_card()
282 list_del(&card->global_list); in pnp_remove_card()
283 list_del(&card->protocol_list); in pnp_remove_card()
285 list_for_each_safe(pos, temp, &card->devices) { in pnp_remove_card()
292 * pnp_add_card_device - adds a device to the specified card
298 dev->dev.parent = &card->dev; in pnp_add_card_device()
299 dev->card_link = NULL; in pnp_add_card_device()
300 dev_set_name(&dev->dev, "%02x:%02x.%02x", in pnp_add_card_device()
301 dev->protocol->number, card->number, dev->number); in pnp_add_card_device()
303 dev->card = card; in pnp_add_card_device()
304 list_add_tail(&dev->card_list, &card->devices); in pnp_add_card_device()
310 * pnp_remove_card_device- removes a device from the specified card
316 dev->card = NULL; in pnp_remove_card_device()
317 list_del(&dev->card_list); in pnp_remove_card_device()
323 * pnp_request_card_device - Searches for a PnP device under the specified card
325 * @id: pointer to a PnP ID structure that explains the rules for finding the device
329 const char *id, struct pnp_dev *from) in pnp_request_card_device() argument
333 struct pnp_card_driver *drv; in pnp_request_card_device() local
336 if (!clink || !id) in pnp_request_card_device()
339 card = clink->card; in pnp_request_card_device()
340 drv = clink->driver; in pnp_request_card_device()
342 pos = card->devices.next; in pnp_request_card_device()
344 if (from->card != card) in pnp_request_card_device()
346 pos = from->card_list.next; in pnp_request_card_device()
348 while (pos != &card->devices) { in pnp_request_card_device()
350 if ((!dev->card_link) && compare_pnp_id(dev->id, id)) in pnp_request_card_device()
352 pos = pos->next; in pnp_request_card_device()
358 dev->card_link = clink; in pnp_request_card_device()
359 dev->dev.driver = &drv->link.driver; in pnp_request_card_device()
360 if (pnp_bus_type.probe(&dev->dev)) in pnp_request_card_device()
362 if (device_bind_driver(&dev->dev)) in pnp_request_card_device()
368 dev->dev.driver = NULL; in pnp_request_card_device()
369 dev->card_link = NULL; in pnp_request_card_device()
375 * pnp_release_card_device - call this when the driver no longer needs the device
380 struct pnp_card_driver *drv = dev->card_link->driver; in pnp_release_card_device() local
382 drv->link.remove = &card_remove; in pnp_release_card_device()
383 device_release_driver(&dev->dev); in pnp_release_card_device()
384 drv->link.remove = &card_remove_first; in pnp_release_card_device()
393 struct pnp_card_link *link = dev->card_link; in card_suspend()
395 if (link->pm_state.event == state.event) in card_suspend()
397 link->pm_state = state; in card_suspend()
398 return link->driver->suspend(link, state); in card_suspend()
403 struct pnp_card_link *link = dev->card_link; in card_resume()
405 if (link->pm_state.event == PM_EVENT_ON) in card_resume()
407 link->pm_state = PMSG_ON; in card_resume()
408 link->driver->resume(link); in card_resume()
413 * pnp_register_card_driver - registers a PnP card driver with the PnP Layer
414 * @drv: pointer to the driver to register
416 int pnp_register_card_driver(struct pnp_card_driver *drv) in pnp_register_card_driver() argument
421 drv->link.name = drv->name; in pnp_register_card_driver()
422 drv->link.id_table = NULL; /* this will disable auto matching */ in pnp_register_card_driver()
423 drv->link.flags = drv->flags; in pnp_register_card_driver()
424 drv->link.probe = NULL; in pnp_register_card_driver()
425 drv->link.remove = &card_remove_first; in pnp_register_card_driver()
426 drv->link.suspend = drv->suspend ? card_suspend : NULL; in pnp_register_card_driver()
427 drv->link.resume = drv->resume ? card_resume : NULL; in pnp_register_card_driver()
429 error = pnp_register_driver(&drv->link); in pnp_register_card_driver()
434 list_add_tail(&drv->global_list, &pnp_card_drivers); in pnp_register_card_driver()
440 card_probe(card, drv); in pnp_register_card_driver()
447 * pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer
448 * @drv: pointer to the driver to unregister
450 void pnp_unregister_card_driver(struct pnp_card_driver *drv) in pnp_unregister_card_driver() argument
453 list_del(&drv->global_list); in pnp_unregister_card_driver()
455 pnp_unregister_driver(&drv->link); in pnp_unregister_card_driver()