Lines Matching refs:mdev

138 	struct maple_device *mdev;
141 mdev = to_maple_dev(dev);
142 mq = mdev->mq;
145 kfree(mdev);
150 * @mdev: maple device
156 int maple_add_packet(struct maple_device *mdev, u32 function, u32 command,
171 mdev->mq->command = command;
172 mdev->mq->length = length;
175 mdev->mq->sendbuf = sendbuf;
178 list_add_tail(&mdev->mq->list, &maple_waitq);
185 static struct mapleq *maple_allocq(struct maple_device *mdev)
194 mq->dev = mdev;
205 dev_err(&mdev->dev, "could not allocate memory for device (%d, %d)\n",
206 mdev->port, mdev->unit);
212 struct maple_device *mdev;
217 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
218 if (!mdev)
221 mdev->port = port;
222 mdev->unit = unit;
224 mdev->mq = maple_allocq(mdev);
226 if (!mdev->mq) {
227 kfree(mdev);
230 mdev->dev.bus = &maple_bus_type;
231 mdev->dev.parent = &maple_bus;
232 init_waitqueue_head(&mdev->maple_wait);
233 return mdev;
236 static void maple_free_dev(struct maple_device *mdev)
238 kmem_cache_free(maple_queue_cache, mdev->mq->recvbuf);
239 kfree(mdev->mq);
240 kfree(mdev);
315 struct maple_device *mdev;
317 mdev = devptr;
319 if (mdev->devinfo.function & cpu_to_be32(maple_drv->function))
324 static void maple_detach_driver(struct maple_device *mdev)
326 device_unregister(&mdev->dev);
330 static void maple_attach_driver(struct maple_device *mdev)
336 recvbuf = mdev->mq->recvbuf->buf;
339 memcpy(&mdev->devinfo.function, recvbuf + 4, 4);
340 memcpy(&mdev->devinfo.function_data[0], recvbuf + 8, 12);
341 memcpy(&mdev->devinfo.area_code, recvbuf + 20, 1);
342 memcpy(&mdev->devinfo.connector_direction, recvbuf + 21, 1);
343 memcpy(&mdev->devinfo.product_name[0], recvbuf + 22, 30);
344 memcpy(&mdev->devinfo.standby_power, recvbuf + 112, 2);
345 memcpy(&mdev->devinfo.max_power, recvbuf + 114, 2);
346 memcpy(mdev->product_name, mdev->devinfo.product_name, 30);
347 mdev->product_name[30] = '\0';
348 memcpy(mdev->product_licence, mdev->devinfo.product_licence, 60);
349 mdev->product_licence[60] = '\0';
351 for (p = mdev->product_name + 29; mdev->product_name <= p; p--)
356 for (p = mdev->product_licence + 59; mdev->product_licence <= p; p--)
362 function = be32_to_cpu(mdev->devinfo.function);
364 dev_info(&mdev->dev, "detected %s: function 0x%lX: at (%d, %d)\n",
365 mdev->product_name, function, mdev->port, mdev->unit);
370 mdev->driver = &maple_unsupported_device;
371 dev_set_name(&mdev->dev, "%d:0.port", mdev->port);
374 bus_for_each_drv(&maple_bus_type, NULL, mdev,
379 dev_info(&mdev->dev, "no driver found\n");
380 mdev->driver = &maple_unsupported_device;
382 dev_set_name(&mdev->dev, "%d:0%d.%lX", mdev->port,
383 mdev->unit, function);
386 mdev->function = function;
387 mdev->dev.release = &maple_release_device;
389 atomic_set(&mdev->busy, 0);
390 error = device_register(&mdev->dev);
392 dev_warn(&mdev->dev, "could not register device at"
393 " (%d, %d), with error 0x%X\n", mdev->unit,
394 mdev->port, error);
395 maple_free_dev(mdev);
396 mdev = NULL;
409 struct maple_device *mdev;
412 mdev = to_maple_dev(device);
413 if (mdev->port == ds->port && mdev->unit == ds->unit)
421 struct maple_device *mdev = to_maple_dev(device);
422 if (mdev->interval > 0 && atomic_read(&mdev->busy) == 0 &&
423 time_after(jiffies, mdev->when)) {
425 add = maple_add_packet(mdev,
426 be32_to_cpu(mdev->devinfo.function),
429 mdev->when = jiffies + mdev->interval;
435 if (atomic_read(&mdev->busy) == 0) {
436 atomic_set(&mdev->busy, 1);
437 maple_add_packet(mdev, 0,
448 struct maple_device *mdev;
472 mdev = baseunits[x];
473 if (!mdev)
475 atomic_set(&mdev->busy, 1);
476 locking = maple_add_packet(mdev, 0,
491 static void maple_map_subunits(struct maple_device *mdev, int submask)
497 ds.port = mdev->port;
509 mdev_add = maple_alloc_dev(mdev->port, k + 1);
523 static void maple_clean_submap(struct maple_device *mdev)
527 killbit = (mdev->unit > 0 ? (1 << (mdev->unit - 1)) & 0x1f : 0x20);
530 subdevice_map[mdev->port] = subdevice_map[mdev->port] & killbit;
534 static void maple_response_none(struct maple_device *mdev)
536 maple_clean_submap(mdev);
538 if (likely(mdev->unit != 0)) {
548 if (mdev->can_unload) {
549 if (!mdev->can_unload(mdev)) {
550 atomic_set(&mdev->busy, 2);
551 wake_up(&mdev->maple_wait);
556 dev_info(&mdev->dev, "detaching device at (%d, %d)\n",
557 mdev->port, mdev->unit);
558 maple_detach_driver(mdev);
562 if (checked[mdev->port] == false) {
563 checked[mdev->port] = true;
564 empty[mdev->port] = true;
565 dev_info(&mdev->dev, "no devices"
566 " to port %d\n", mdev->port);
572 atomic_set(&mdev->busy, 0);
576 static void maple_response_devinfo(struct maple_device *mdev,
581 if ((mdev->unit == 0) && (checked[mdev->port] == false)) {
582 checked[mdev->port] = true;
583 maple_attach_driver(mdev);
585 if (mdev->unit != 0)
586 maple_attach_driver(mdev);
587 if (mdev->unit == 0) {
588 empty[mdev->port] = false;
589 maple_attach_driver(mdev);
593 if (mdev->unit == 0) {
595 if (submask ^ subdevice_map[mdev->port]) {
596 maple_map_subunits(mdev, submask);
597 subdevice_map[mdev->port] = submask;
602 static void maple_response_fileerr(struct maple_device *mdev, void *recvbuf)
604 if (mdev->fileerr_handler) {
605 mdev->fileerr_handler(mdev, recvbuf);
608 dev_warn(&mdev->dev, "device at (%d, %d) reports"
609 "file error 0x%X\n", mdev->port, mdev->unit,
616 struct maple_device *mdev;
622 mdev = baseunits[i];
623 maple_add_packet(mdev, 0, MAPLE_COMMAND_DEVINFO,
633 struct maple_device *mdev;
642 mdev = mq->dev;
651 maple_response_none(mdev);
655 maple_response_devinfo(mdev, recvbuf);
656 atomic_set(&mdev->busy, 0);
660 if (mdev->callback)
661 mdev->callback(mq);
662 atomic_set(&mdev->busy, 0);
663 wake_up(&mdev->maple_wait);
667 maple_response_fileerr(mdev, recvbuf);
668 atomic_set(&mdev->busy, 0);
669 wake_up(&mdev->maple_wait);
675 dev_warn(&mdev->dev, "non-fatal error"
677 mdev->port, mdev->unit);
678 atomic_set(&mdev->busy, 0);
682 dev_notice(&mdev->dev, "extended"
684 " but call is not supported\n", mdev->port,
685 mdev->unit);
686 atomic_set(&mdev->busy, 0);
690 atomic_set(&mdev->busy, 0);
691 wake_up(&mdev->maple_wait);
790 struct maple_device *mdev[MAPLE_PORTS];
842 mdev[i] = maple_alloc_dev(i, 0);
843 if (!mdev[i]) {
845 maple_free_dev(mdev[i]);
849 baseunits[i] = mdev[i];
850 atomic_set(&mdev[i]->busy, 1);
851 maple_add_packet(mdev[i], 0, MAPLE_COMMAND_DEVINFO, 0, NULL);