Lines Matching defs:mdev

139 	struct maple_device *mdev;
142 mdev = to_maple_dev(dev);
143 mq = mdev->mq;
146 kfree(mdev);
151 * @mdev: maple device
157 int maple_add_packet(struct maple_device *mdev, u32 function, u32 command,
172 mdev->mq->command = command;
173 mdev->mq->length = length;
176 mdev->mq->sendbuf = sendbuf;
179 list_add_tail(&mdev->mq->list, &maple_waitq);
186 static struct mapleq *maple_allocq(struct maple_device *mdev)
195 mq->dev = mdev;
206 dev_err(&mdev->dev, "could not allocate memory for device (%d, %d)\n",
207 mdev->port, mdev->unit);
213 struct maple_device *mdev;
218 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
219 if (!mdev)
222 mdev->port = port;
223 mdev->unit = unit;
225 mdev->mq = maple_allocq(mdev);
227 if (!mdev->mq) {
228 kfree(mdev);
231 mdev->dev.bus = &maple_bus_type;
232 mdev->dev.parent = &maple_bus;
233 init_waitqueue_head(&mdev->maple_wait);
234 return mdev;
237 static void maple_free_dev(struct maple_device *mdev)
239 kmem_cache_free(maple_queue_cache, mdev->mq->recvbuf);
240 kfree(mdev->mq);
241 kfree(mdev);
316 struct maple_device *mdev;
318 mdev = devptr;
320 if (mdev->devinfo.function & cpu_to_be32(maple_drv->function))
325 static void maple_detach_driver(struct maple_device *mdev)
327 device_unregister(&mdev->dev);
331 static void maple_attach_driver(struct maple_device *mdev)
337 recvbuf = mdev->mq->recvbuf->buf;
340 memcpy(&mdev->devinfo.function, recvbuf + 4, 4);
341 memcpy(&mdev->devinfo.function_data[0], recvbuf + 8, 12);
342 memcpy(&mdev->devinfo.area_code, recvbuf + 20, 1);
343 memcpy(&mdev->devinfo.connector_direction, recvbuf + 21, 1);
344 memcpy(&mdev->devinfo.product_name[0], recvbuf + 22, 30);
345 memcpy(&mdev->devinfo.standby_power, recvbuf + 112, 2);
346 memcpy(&mdev->devinfo.max_power, recvbuf + 114, 2);
347 memcpy(mdev->product_name, mdev->devinfo.product_name, 30);
348 mdev->product_name[30] = '\0';
349 memcpy(mdev->product_licence, mdev->devinfo.product_licence, 60);
350 mdev->product_licence[60] = '\0';
352 for (p = mdev->product_name + 29; mdev->product_name <= p; p--)
357 for (p = mdev->product_licence + 59; mdev->product_licence <= p; p--)
363 function = be32_to_cpu(mdev->devinfo.function);
365 dev_info(&mdev->dev, "detected %s: function 0x%lX: at (%d, %d)\n",
366 mdev->product_name, function, mdev->port, mdev->unit);
371 mdev->driver = &maple_unsupported_device;
372 dev_set_name(&mdev->dev, "%d:0.port", mdev->port);
375 bus_for_each_drv(&maple_bus_type, NULL, mdev,
380 dev_info(&mdev->dev, "no driver found\n");
381 mdev->driver = &maple_unsupported_device;
383 dev_set_name(&mdev->dev, "%d:0%d.%lX", mdev->port,
384 mdev->unit, function);
387 mdev->function = function;
388 mdev->dev.release = &maple_release_device;
390 atomic_set(&mdev->busy, 0);
391 error = device_register(&mdev->dev);
393 dev_warn(&mdev->dev, "could not register device at"
394 " (%d, %d), with error 0x%X\n", mdev->unit,
395 mdev->port, error);
396 maple_free_dev(mdev);
397 mdev = NULL;
410 struct maple_device *mdev;
413 mdev = to_maple_dev(device);
414 if (mdev->port == ds->port && mdev->unit == ds->unit)
422 struct maple_device *mdev = to_maple_dev(device);
423 if (mdev->interval > 0 && atomic_read(&mdev->busy) == 0 &&
424 time_after(jiffies, mdev->when)) {
426 add = maple_add_packet(mdev,
427 be32_to_cpu(mdev->devinfo.function),
430 mdev->when = jiffies + mdev->interval;
436 if (atomic_read(&mdev->busy) == 0) {
437 atomic_set(&mdev->busy, 1);
438 maple_add_packet(mdev, 0,
449 struct maple_device *mdev;
473 mdev = baseunits[x];
474 if (!mdev)
476 atomic_set(&mdev->busy, 1);
477 locking = maple_add_packet(mdev, 0,
492 static void maple_map_subunits(struct maple_device *mdev, int submask)
498 ds.port = mdev->port;
510 mdev_add = maple_alloc_dev(mdev->port, k + 1);
524 static void maple_clean_submap(struct maple_device *mdev)
528 killbit = (mdev->unit > 0 ? (1 << (mdev->unit - 1)) & 0x1f : 0x20);
531 subdevice_map[mdev->port] = subdevice_map[mdev->port] & killbit;
535 static void maple_response_none(struct maple_device *mdev)
537 maple_clean_submap(mdev);
539 if (likely(mdev->unit != 0)) {
549 if (mdev->can_unload) {
550 if (!mdev->can_unload(mdev)) {
551 atomic_set(&mdev->busy, 2);
552 wake_up(&mdev->maple_wait);
557 dev_info(&mdev->dev, "detaching device at (%d, %d)\n",
558 mdev->port, mdev->unit);
559 maple_detach_driver(mdev);
563 if (checked[mdev->port] == false) {
564 checked[mdev->port] = true;
565 empty[mdev->port] = true;
566 dev_info(&mdev->dev, "no devices"
567 " to port %d\n", mdev->port);
573 atomic_set(&mdev->busy, 0);
577 static void maple_response_devinfo(struct maple_device *mdev,
582 if ((mdev->unit == 0) && (checked[mdev->port] == false)) {
583 checked[mdev->port] = true;
584 maple_attach_driver(mdev);
586 if (mdev->unit != 0)
587 maple_attach_driver(mdev);
588 if (mdev->unit == 0) {
589 empty[mdev->port] = false;
590 maple_attach_driver(mdev);
594 if (mdev->unit == 0) {
596 if (submask ^ subdevice_map[mdev->port]) {
597 maple_map_subunits(mdev, submask);
598 subdevice_map[mdev->port] = submask;
603 static void maple_response_fileerr(struct maple_device *mdev, void *recvbuf)
605 if (mdev->fileerr_handler) {
606 mdev->fileerr_handler(mdev, recvbuf);
609 dev_warn(&mdev->dev, "device at (%d, %d) reports"
610 "file error 0x%X\n", mdev->port, mdev->unit,
617 struct maple_device *mdev;
623 mdev = baseunits[i];
624 maple_add_packet(mdev, 0, MAPLE_COMMAND_DEVINFO,
634 struct maple_device *mdev;
643 mdev = mq->dev;
652 maple_response_none(mdev);
656 maple_response_devinfo(mdev, recvbuf);
657 atomic_set(&mdev->busy, 0);
661 if (mdev->callback)
662 mdev->callback(mq);
663 atomic_set(&mdev->busy, 0);
664 wake_up(&mdev->maple_wait);
668 maple_response_fileerr(mdev, recvbuf);
669 atomic_set(&mdev->busy, 0);
670 wake_up(&mdev->maple_wait);
676 dev_warn(&mdev->dev, "non-fatal error"
678 mdev->port, mdev->unit);
679 atomic_set(&mdev->busy, 0);
683 dev_notice(&mdev->dev, "extended"
685 " but call is not supported\n", mdev->port,
686 mdev->unit);
687 atomic_set(&mdev->busy, 0);
691 atomic_set(&mdev->busy, 0);
692 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);