Lines Matching +full:host +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-only
29 struct memstick_device_id *id) in memstick_dev_match() argument
31 if (id->match_flags & MEMSTICK_MATCH_ALL) { in memstick_dev_match()
32 if ((id->type == card->id.type) in memstick_dev_match()
33 && (id->category == card->id.category) in memstick_dev_match()
34 && (id->class == card->id.class)) in memstick_dev_match()
47 struct memstick_device_id *ids = ms_drv->id_table; in memstick_bus_match()
50 while (ids->match_flags) { in memstick_bus_match()
64 if (add_uevent_var(env, "MEMSTICK_TYPE=%02X", card->id.type)) in memstick_uevent()
65 return -ENOMEM; in memstick_uevent()
67 if (add_uevent_var(env, "MEMSTICK_CATEGORY=%02X", card->id.category)) in memstick_uevent()
68 return -ENOMEM; in memstick_uevent()
70 if (add_uevent_var(env, "MEMSTICK_CLASS=%02X", card->id.class)) in memstick_uevent()
71 return -ENOMEM; in memstick_uevent()
80 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_probe()
83 int rc = -ENODEV; in memstick_device_probe()
85 if (dev->driver && drv->probe) { in memstick_device_probe()
86 rc = drv->probe(card); in memstick_device_probe()
97 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_remove()
101 if (dev->driver && drv->remove) { in memstick_device_remove()
102 drv->remove(card); in memstick_device_remove()
103 card->dev.driver = NULL; in memstick_device_remove()
115 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_suspend()
119 if (dev->driver && drv->suspend) in memstick_device_suspend()
120 return drv->suspend(card, state); in memstick_device_suspend()
128 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_resume()
132 if (dev->driver && drv->resume) in memstick_device_resume()
133 return drv->resume(card); in memstick_device_resume()
150 return sprintf(buf, format, card->id.name); \
179 struct memstick_host *host = container_of(dev, struct memstick_host, in memstick_free() local
181 kfree(host); in memstick_free()
202 * memstick_detect_change - schedule media detection on memstick host
203 * @host - host to use
205 void memstick_detect_change(struct memstick_host *host) in memstick_detect_change() argument
207 queue_work(workqueue, &host->media_checker); in memstick_detect_change()
212 * memstick_next_req - called by host driver to obtain next request to process
213 * @host - host to use
214 * @mrq - pointer to stick the request to
216 * Host calls this function from idle state (*mrq == NULL) or after finishing
219 * of 0 means that new request was assigned to the host.
221 int memstick_next_req(struct memstick_host *host, struct memstick_request **mrq) in memstick_next_req() argument
223 int rc = -ENXIO; in memstick_next_req()
225 if ((*mrq) && (*mrq)->error && host->retries) { in memstick_next_req()
226 (*mrq)->error = rc; in memstick_next_req()
227 host->retries--; in memstick_next_req()
231 if (host->card && host->card->next_request) in memstick_next_req()
232 rc = host->card->next_request(host->card, mrq); in memstick_next_req()
235 host->retries = cmd_retries > 1 ? cmd_retries - 1 : 1; in memstick_next_req()
244 * memstick_new_req - notify the host that some requests are pending
245 * @host - host to use
247 void memstick_new_req(struct memstick_host *host) in memstick_new_req() argument
249 if (host->card) { in memstick_new_req()
250 host->retries = cmd_retries; in memstick_new_req()
251 reinit_completion(&host->card->mrq_complete); in memstick_new_req()
252 host->request(host); in memstick_new_req()
258 * memstick_init_req_sg - set request fields needed for bulk data transfer
259 * @mrq - request to use
260 * @tpc - memstick Transport Protocol Command
261 * @sg - TPC argument
266 mrq->tpc = tpc; in memstick_init_req_sg()
268 mrq->data_dir = WRITE; in memstick_init_req_sg()
270 mrq->data_dir = READ; in memstick_init_req_sg()
272 mrq->sg = *sg; in memstick_init_req_sg()
273 mrq->long_data = 1; in memstick_init_req_sg()
276 mrq->need_card_int = 1; in memstick_init_req_sg()
278 mrq->need_card_int = 0; in memstick_init_req_sg()
283 * memstick_init_req - set request fields needed for short data transfer
284 * @mrq - request to use
285 * @tpc - memstick Transport Protocol Command
286 * @buf - TPC argument buffer
287 * @length - TPC argument size
296 mrq->tpc = tpc; in memstick_init_req()
298 mrq->data_dir = WRITE; in memstick_init_req()
300 mrq->data_dir = READ; in memstick_init_req()
302 mrq->data_len = length > sizeof(mrq->data) ? sizeof(mrq->data) : length; in memstick_init_req()
303 if (mrq->data_dir == WRITE) in memstick_init_req()
304 memcpy(mrq->data, buf, mrq->data_len); in memstick_init_req()
306 mrq->long_data = 0; in memstick_init_req()
309 mrq->need_card_int = 1; in memstick_init_req()
311 mrq->need_card_int = 0; in memstick_init_req()
318 * ongoing, while special error value of -EAGAIN means that current request is
328 memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, &id_reg, in h_memstick_read_dev_id()
330 *mrq = &card->current_mrq; in h_memstick_read_dev_id()
333 if (!(*mrq)->error) { in h_memstick_read_dev_id()
334 memcpy(&id_reg, (*mrq)->data, sizeof(id_reg)); in h_memstick_read_dev_id()
335 card->id.match_flags = MEMSTICK_MATCH_ALL; in h_memstick_read_dev_id()
336 card->id.type = id_reg.type; in h_memstick_read_dev_id()
337 card->id.category = id_reg.category; in h_memstick_read_dev_id()
338 card->id.class = id_reg.class; in h_memstick_read_dev_id()
339 dev_dbg(&card->dev, "if_mode = %02x\n", id_reg.if_mode); in h_memstick_read_dev_id()
341 complete(&card->mrq_complete); in h_memstick_read_dev_id()
342 return -EAGAIN; in h_memstick_read_dev_id()
349 memstick_init_req(&card->current_mrq, MS_TPC_SET_RW_REG_ADRS, in h_memstick_set_rw_addr()
350 (char *)&card->reg_addr, in h_memstick_set_rw_addr()
351 sizeof(card->reg_addr)); in h_memstick_set_rw_addr()
352 *mrq = &card->current_mrq; in h_memstick_set_rw_addr()
355 complete(&card->mrq_complete); in h_memstick_set_rw_addr()
356 return -EAGAIN; in h_memstick_set_rw_addr()
361 * memstick_set_rw_addr - issue SET_RW_REG_ADDR request and wait for it to
363 * @card - media device to use
367 card->next_request = h_memstick_set_rw_addr; in memstick_set_rw_addr()
368 memstick_new_req(card->host); in memstick_set_rw_addr()
369 wait_for_completion(&card->mrq_complete); in memstick_set_rw_addr()
371 return card->current_mrq.error; in memstick_set_rw_addr()
375 static struct memstick_dev *memstick_alloc_card(struct memstick_host *host) in memstick_alloc_card() argument
379 struct memstick_dev *old_card = host->card; in memstick_alloc_card()
383 card->host = host; in memstick_alloc_card()
384 dev_set_name(&card->dev, "%s", dev_name(&host->dev)); in memstick_alloc_card()
385 card->dev.parent = &host->dev; in memstick_alloc_card()
386 card->dev.bus = &memstick_bus_type; in memstick_alloc_card()
387 card->dev.release = memstick_free_card; in memstick_alloc_card()
388 card->check = memstick_dummy_check; in memstick_alloc_card()
390 card->reg_addr.r_offset = offsetof(struct ms_register, id); in memstick_alloc_card()
391 card->reg_addr.r_length = sizeof(id_reg); in memstick_alloc_card()
392 card->reg_addr.w_offset = offsetof(struct ms_register, id); in memstick_alloc_card()
393 card->reg_addr.w_length = sizeof(id_reg); in memstick_alloc_card()
395 init_completion(&card->mrq_complete); in memstick_alloc_card()
397 host->card = card; in memstick_alloc_card()
401 card->next_request = h_memstick_read_dev_id; in memstick_alloc_card()
402 memstick_new_req(host); in memstick_alloc_card()
403 wait_for_completion(&card->mrq_complete); in memstick_alloc_card()
405 if (card->current_mrq.error) in memstick_alloc_card()
408 host->card = old_card; in memstick_alloc_card()
411 host->card = old_card; in memstick_alloc_card()
412 kfree_const(card->dev.kobj.name); in memstick_alloc_card()
417 static int memstick_power_on(struct memstick_host *host) in memstick_power_on() argument
419 int rc = host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON); in memstick_power_on()
422 rc = host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL); in memstick_power_on()
429 struct memstick_host *host = container_of(work, struct memstick_host, in memstick_check() local
433 dev_dbg(&host->dev, "memstick_check started\n"); in memstick_check()
434 pm_runtime_get_noresume(host->dev.parent); in memstick_check()
435 mutex_lock(&host->lock); in memstick_check()
436 if (!host->card) { in memstick_check()
437 if (memstick_power_on(host)) in memstick_check()
439 } else if (host->card->stop) in memstick_check()
440 host->card->stop(host->card); in memstick_check()
442 if (host->removing) in memstick_check()
445 card = memstick_alloc_card(host); in memstick_check()
448 if (host->card) { in memstick_check()
449 device_unregister(&host->card->dev); in memstick_check()
450 host->card = NULL; in memstick_check()
453 dev_dbg(&host->dev, "new card %02x, %02x, %02x\n", in memstick_check()
454 card->id.type, card->id.category, card->id.class); in memstick_check()
455 if (host->card) { in memstick_check()
456 if (memstick_set_rw_addr(host->card) in memstick_check()
457 || !memstick_dev_match(host->card, &card->id) in memstick_check()
458 || !(host->card->check(host->card))) { in memstick_check()
459 device_unregister(&host->card->dev); in memstick_check()
460 host->card = NULL; in memstick_check()
461 } else if (host->card->start) in memstick_check()
462 host->card->start(host->card); in memstick_check()
465 if (!host->card) { in memstick_check()
466 host->card = card; in memstick_check()
467 if (device_register(&card->dev)) { in memstick_check()
468 put_device(&card->dev); in memstick_check()
469 host->card = NULL; in memstick_check()
472 kfree_const(card->dev.kobj.name); in memstick_check()
478 if (!host->card) in memstick_check()
479 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_check()
481 mutex_unlock(&host->lock); in memstick_check()
482 pm_runtime_put(host->dev.parent); in memstick_check()
483 dev_dbg(&host->dev, "memstick_check finished\n"); in memstick_check()
487 * memstick_alloc_host - allocate a memstick_host structure
489 * @dev: parent device of the host
494 struct memstick_host *host; in memstick_alloc_host() local
496 host = kzalloc(sizeof(struct memstick_host) + extra, GFP_KERNEL); in memstick_alloc_host()
497 if (host) { in memstick_alloc_host()
498 mutex_init(&host->lock); in memstick_alloc_host()
499 INIT_WORK(&host->media_checker, memstick_check); in memstick_alloc_host()
500 host->dev.class = &memstick_host_class; in memstick_alloc_host()
501 host->dev.parent = dev; in memstick_alloc_host()
502 device_initialize(&host->dev); in memstick_alloc_host()
504 return host; in memstick_alloc_host()
509 * memstick_add_host - start request processing on memstick host
510 * @host - host to use
512 int memstick_add_host(struct memstick_host *host) in memstick_add_host() argument
519 rc = idr_alloc(&memstick_host_idr, host, 0, 0, GFP_NOWAIT); in memstick_add_host()
521 host->id = rc; in memstick_add_host()
528 dev_set_name(&host->dev, "memstick%u", host->id); in memstick_add_host()
530 rc = device_add(&host->dev); in memstick_add_host()
533 idr_remove(&memstick_host_idr, host->id); in memstick_add_host()
538 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_add_host()
539 memstick_detect_change(host); in memstick_add_host()
545 * memstick_remove_host - stop request processing on memstick host
546 * @host - host to use
548 void memstick_remove_host(struct memstick_host *host) in memstick_remove_host() argument
550 host->removing = 1; in memstick_remove_host()
552 mutex_lock(&host->lock); in memstick_remove_host()
553 if (host->card) in memstick_remove_host()
554 device_unregister(&host->card->dev); in memstick_remove_host()
555 host->card = NULL; in memstick_remove_host()
556 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_remove_host()
557 mutex_unlock(&host->lock); in memstick_remove_host()
560 idr_remove(&memstick_host_idr, host->id); in memstick_remove_host()
562 device_del(&host->dev); in memstick_remove_host()
567 * memstick_free_host - free memstick host
568 * @host - host to use
570 void memstick_free_host(struct memstick_host *host) in memstick_free_host() argument
572 mutex_destroy(&host->lock); in memstick_free_host()
573 put_device(&host->dev); in memstick_free_host()
578 * memstick_suspend_host - notify bus driver of host suspension
579 * @host - host to use
581 void memstick_suspend_host(struct memstick_host *host) in memstick_suspend_host() argument
583 mutex_lock(&host->lock); in memstick_suspend_host()
584 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_suspend_host()
585 mutex_unlock(&host->lock); in memstick_suspend_host()
590 * memstick_resume_host - notify bus driver of host resumption
591 * @host - host to use
593 void memstick_resume_host(struct memstick_host *host) in memstick_resume_host() argument
597 mutex_lock(&host->lock); in memstick_resume_host()
598 if (host->card) in memstick_resume_host()
599 rc = memstick_power_on(host); in memstick_resume_host()
600 mutex_unlock(&host->lock); in memstick_resume_host()
603 memstick_detect_change(host); in memstick_resume_host()
609 drv->driver.bus = &memstick_bus_type; in memstick_register_driver()
611 return driver_register(&drv->driver); in memstick_register_driver()
617 driver_unregister(&drv->driver); in memstick_unregister_driver()
628 return -ENOMEM; in memstick_init()