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()
48 struct memstick_device_id *ids = ms_drv->id_table; in memstick_bus_match()
51 while (ids->match_flags) { in memstick_bus_match()
65 if (add_uevent_var(env, "MEMSTICK_TYPE=%02X", card->id.type)) in memstick_uevent()
66 return -ENOMEM; in memstick_uevent()
68 if (add_uevent_var(env, "MEMSTICK_CATEGORY=%02X", card->id.category)) in memstick_uevent()
69 return -ENOMEM; in memstick_uevent()
71 if (add_uevent_var(env, "MEMSTICK_CLASS=%02X", card->id.class)) in memstick_uevent()
72 return -ENOMEM; in memstick_uevent()
81 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_probe()
84 int rc = -ENODEV; in memstick_device_probe()
86 if (dev->driver && drv->probe) { in memstick_device_probe()
87 rc = drv->probe(card); in memstick_device_probe()
98 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_remove()
102 if (dev->driver && drv->remove) { in memstick_device_remove()
103 drv->remove(card); in memstick_device_remove()
104 card->dev.driver = NULL; in memstick_device_remove()
116 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_suspend()
120 if (dev->driver && drv->suspend) in memstick_device_suspend()
121 return drv->suspend(card, state); in memstick_device_suspend()
129 struct memstick_driver *drv = container_of(dev->driver, in memstick_device_resume()
133 if (dev->driver && drv->resume) in memstick_device_resume()
134 return drv->resume(card); in memstick_device_resume()
151 return sprintf(buf, format, card->id.name); \
180 struct memstick_host *host = container_of(dev, struct memstick_host, in memstick_free() local
182 kfree(host); in memstick_free()
203 * memstick_detect_change - schedule media detection on memstick host
204 * @host - host to use
206 void memstick_detect_change(struct memstick_host *host) in memstick_detect_change() argument
208 queue_work(workqueue, &host->media_checker); in memstick_detect_change()
213 * memstick_next_req - called by host driver to obtain next request to process
214 * @host - host to use
215 * @mrq - pointer to stick the request to
217 * Host calls this function from idle state (*mrq == NULL) or after finishing
220 * of 0 means that new request was assigned to the host.
222 int memstick_next_req(struct memstick_host *host, struct memstick_request **mrq) in memstick_next_req() argument
224 int rc = -ENXIO; in memstick_next_req()
226 if ((*mrq) && (*mrq)->error && host->retries) { in memstick_next_req()
227 (*mrq)->error = rc; in memstick_next_req()
228 host->retries--; in memstick_next_req()
232 if (host->card && host->card->next_request) in memstick_next_req()
233 rc = host->card->next_request(host->card, mrq); in memstick_next_req()
236 host->retries = cmd_retries > 1 ? cmd_retries - 1 : 1; in memstick_next_req()
245 * memstick_new_req - notify the host that some requests are pending
246 * @host - host to use
248 void memstick_new_req(struct memstick_host *host) in memstick_new_req() argument
250 if (host->card) { in memstick_new_req()
251 host->retries = cmd_retries; in memstick_new_req()
252 reinit_completion(&host->card->mrq_complete); in memstick_new_req()
253 host->request(host); in memstick_new_req()
259 * memstick_init_req_sg - set request fields needed for bulk data transfer
260 * @mrq - request to use
261 * @tpc - memstick Transport Protocol Command
262 * @sg - TPC argument
267 mrq->tpc = tpc; in memstick_init_req_sg()
269 mrq->data_dir = WRITE; in memstick_init_req_sg()
271 mrq->data_dir = READ; in memstick_init_req_sg()
273 mrq->sg = *sg; in memstick_init_req_sg()
274 mrq->long_data = 1; in memstick_init_req_sg()
277 mrq->need_card_int = 1; in memstick_init_req_sg()
279 mrq->need_card_int = 0; in memstick_init_req_sg()
284 * memstick_init_req - set request fields needed for short data transfer
285 * @mrq - request to use
286 * @tpc - memstick Transport Protocol Command
287 * @buf - TPC argument buffer
288 * @length - TPC argument size
297 mrq->tpc = tpc; in memstick_init_req()
299 mrq->data_dir = WRITE; in memstick_init_req()
301 mrq->data_dir = READ; in memstick_init_req()
303 mrq->data_len = length > sizeof(mrq->data) ? sizeof(mrq->data) : length; in memstick_init_req()
304 if (mrq->data_dir == WRITE) in memstick_init_req()
305 memcpy(mrq->data, buf, mrq->data_len); in memstick_init_req()
307 mrq->long_data = 0; in memstick_init_req()
310 mrq->need_card_int = 1; in memstick_init_req()
312 mrq->need_card_int = 0; in memstick_init_req()
319 * ongoing, while special error value of -EAGAIN means that current request is
329 memstick_init_req(&card->current_mrq, MS_TPC_READ_REG, &id_reg, in h_memstick_read_dev_id()
331 *mrq = &card->current_mrq; in h_memstick_read_dev_id()
334 if (!(*mrq)->error) { in h_memstick_read_dev_id()
335 memcpy(&id_reg, (*mrq)->data, sizeof(id_reg)); in h_memstick_read_dev_id()
336 card->id.match_flags = MEMSTICK_MATCH_ALL; in h_memstick_read_dev_id()
337 card->id.type = id_reg.type; in h_memstick_read_dev_id()
338 card->id.category = id_reg.category; in h_memstick_read_dev_id()
339 card->id.class = id_reg.class; in h_memstick_read_dev_id()
340 dev_dbg(&card->dev, "if_mode = %02x\n", id_reg.if_mode); in h_memstick_read_dev_id()
342 complete(&card->mrq_complete); in h_memstick_read_dev_id()
343 return -EAGAIN; in h_memstick_read_dev_id()
350 memstick_init_req(&card->current_mrq, MS_TPC_SET_RW_REG_ADRS, in h_memstick_set_rw_addr()
351 (char *)&card->reg_addr, in h_memstick_set_rw_addr()
352 sizeof(card->reg_addr)); in h_memstick_set_rw_addr()
353 *mrq = &card->current_mrq; in h_memstick_set_rw_addr()
356 complete(&card->mrq_complete); in h_memstick_set_rw_addr()
357 return -EAGAIN; in h_memstick_set_rw_addr()
362 * memstick_set_rw_addr - issue SET_RW_REG_ADDR request and wait for it to
364 * @card - media device to use
368 card->next_request = h_memstick_set_rw_addr; in memstick_set_rw_addr()
369 memstick_new_req(card->host); in memstick_set_rw_addr()
370 wait_for_completion(&card->mrq_complete); in memstick_set_rw_addr()
372 return card->current_mrq.error; in memstick_set_rw_addr()
376 static struct memstick_dev *memstick_alloc_card(struct memstick_host *host) in memstick_alloc_card() argument
380 struct memstick_dev *old_card = host->card; in memstick_alloc_card()
384 card->host = host; in memstick_alloc_card()
385 dev_set_name(&card->dev, "%s", dev_name(&host->dev)); in memstick_alloc_card()
386 card->dev.parent = &host->dev; in memstick_alloc_card()
387 card->dev.bus = &memstick_bus_type; in memstick_alloc_card()
388 card->dev.release = memstick_free_card; in memstick_alloc_card()
389 card->check = memstick_dummy_check; in memstick_alloc_card()
391 card->reg_addr.r_offset = offsetof(struct ms_register, id); in memstick_alloc_card()
392 card->reg_addr.r_length = sizeof(id_reg); in memstick_alloc_card()
393 card->reg_addr.w_offset = offsetof(struct ms_register, id); in memstick_alloc_card()
394 card->reg_addr.w_length = sizeof(id_reg); in memstick_alloc_card()
396 init_completion(&card->mrq_complete); in memstick_alloc_card()
398 host->card = card; in memstick_alloc_card()
402 card->next_request = h_memstick_read_dev_id; in memstick_alloc_card()
403 memstick_new_req(host); in memstick_alloc_card()
404 wait_for_completion(&card->mrq_complete); in memstick_alloc_card()
406 if (card->current_mrq.error) in memstick_alloc_card()
409 host->card = old_card; in memstick_alloc_card()
412 host->card = old_card; in memstick_alloc_card()
413 kfree_const(card->dev.kobj.name); in memstick_alloc_card()
418 static int memstick_power_on(struct memstick_host *host) in memstick_power_on() argument
420 int rc = host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_ON); in memstick_power_on()
423 rc = host->set_param(host, MEMSTICK_INTERFACE, MEMSTICK_SERIAL); in memstick_power_on()
430 struct memstick_host *host = container_of(work, struct memstick_host, in memstick_check() local
434 dev_dbg(&host->dev, "memstick_check started\n"); in memstick_check()
435 pm_runtime_get_noresume(host->dev.parent); in memstick_check()
436 mutex_lock(&host->lock); in memstick_check()
437 if (!host->card) { in memstick_check()
438 if (memstick_power_on(host)) in memstick_check()
440 } else if (host->card->stop) in memstick_check()
441 host->card->stop(host->card); in memstick_check()
443 if (host->removing) in memstick_check()
446 card = memstick_alloc_card(host); in memstick_check()
449 if (host->card) { in memstick_check()
450 device_unregister(&host->card->dev); in memstick_check()
451 host->card = NULL; in memstick_check()
454 dev_dbg(&host->dev, "new card %02x, %02x, %02x\n", in memstick_check()
455 card->id.type, card->id.category, card->id.class); in memstick_check()
456 if (host->card) { in memstick_check()
457 if (memstick_set_rw_addr(host->card) in memstick_check()
458 || !memstick_dev_match(host->card, &card->id) in memstick_check()
459 || !(host->card->check(host->card))) { in memstick_check()
460 device_unregister(&host->card->dev); in memstick_check()
461 host->card = NULL; in memstick_check()
462 } else if (host->card->start) in memstick_check()
463 host->card->start(host->card); in memstick_check()
466 if (!host->card) { in memstick_check()
467 host->card = card; in memstick_check()
468 if (device_register(&card->dev)) { in memstick_check()
469 put_device(&card->dev); in memstick_check()
470 host->card = NULL; in memstick_check()
473 kfree_const(card->dev.kobj.name); in memstick_check()
479 if (!host->card) in memstick_check()
480 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_check()
482 mutex_unlock(&host->lock); in memstick_check()
483 pm_runtime_put(host->dev.parent); in memstick_check()
484 dev_dbg(&host->dev, "memstick_check finished\n"); in memstick_check()
488 * memstick_alloc_host - allocate a memstick_host structure
490 * @dev: parent device of the host
495 struct memstick_host *host; in memstick_alloc_host() local
497 host = kzalloc(sizeof(struct memstick_host) + extra, GFP_KERNEL); in memstick_alloc_host()
498 if (host) { in memstick_alloc_host()
499 mutex_init(&host->lock); in memstick_alloc_host()
500 INIT_WORK(&host->media_checker, memstick_check); in memstick_alloc_host()
501 host->dev.class = &memstick_host_class; in memstick_alloc_host()
502 host->dev.parent = dev; in memstick_alloc_host()
503 device_initialize(&host->dev); in memstick_alloc_host()
505 return host; in memstick_alloc_host()
510 * memstick_add_host - start request processing on memstick host
511 * @host - host to use
513 int memstick_add_host(struct memstick_host *host) in memstick_add_host() argument
520 rc = idr_alloc(&memstick_host_idr, host, 0, 0, GFP_NOWAIT); in memstick_add_host()
522 host->id = rc; in memstick_add_host()
529 dev_set_name(&host->dev, "memstick%u", host->id); in memstick_add_host()
531 rc = device_add(&host->dev); in memstick_add_host()
534 idr_remove(&memstick_host_idr, host->id); in memstick_add_host()
539 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_add_host()
540 memstick_detect_change(host); in memstick_add_host()
546 * memstick_remove_host - stop request processing on memstick host
547 * @host - host to use
549 void memstick_remove_host(struct memstick_host *host) in memstick_remove_host() argument
551 host->removing = 1; in memstick_remove_host()
553 mutex_lock(&host->lock); in memstick_remove_host()
554 if (host->card) in memstick_remove_host()
555 device_unregister(&host->card->dev); in memstick_remove_host()
556 host->card = NULL; in memstick_remove_host()
557 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_remove_host()
558 mutex_unlock(&host->lock); in memstick_remove_host()
561 idr_remove(&memstick_host_idr, host->id); in memstick_remove_host()
563 device_del(&host->dev); in memstick_remove_host()
568 * memstick_free_host - free memstick host
569 * @host - host to use
571 void memstick_free_host(struct memstick_host *host) in memstick_free_host() argument
573 mutex_destroy(&host->lock); in memstick_free_host()
574 put_device(&host->dev); in memstick_free_host()
579 * memstick_suspend_host - notify bus driver of host suspension
580 * @host - host to use
582 void memstick_suspend_host(struct memstick_host *host) in memstick_suspend_host() argument
584 mutex_lock(&host->lock); in memstick_suspend_host()
585 host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); in memstick_suspend_host()
586 mutex_unlock(&host->lock); in memstick_suspend_host()
591 * memstick_resume_host - notify bus driver of host resumption
592 * @host - host to use
594 void memstick_resume_host(struct memstick_host *host) in memstick_resume_host() argument
598 mutex_lock(&host->lock); in memstick_resume_host()
599 if (host->card) in memstick_resume_host()
600 rc = memstick_power_on(host); in memstick_resume_host()
601 mutex_unlock(&host->lock); in memstick_resume_host()
604 memstick_detect_change(host); in memstick_resume_host()
610 drv->driver.bus = &memstick_bus_type; in memstick_register_driver()
612 return driver_register(&drv->driver); in memstick_register_driver()
618 driver_unregister(&drv->driver); in memstick_unregister_driver()
629 return -ENOMEM; in memstick_init()