Lines Matching refs:device
34 * host1x_subdev_add() - add a new subdevice with an associated device node
35 * @device: host1x device to add the subdevice to
37 * @np: device node
39 static int host1x_subdev_add(struct host1x_device *device,
54 mutex_lock(&device->subdevs_lock);
55 list_add_tail(&subdev->list, &device->subdevs);
56 mutex_unlock(&device->subdevs_lock);
62 err = host1x_subdev_add(device, driver, child);
86 * host1x_device_parse_dt() - scan device tree and add matching subdevices
87 * @device: host1x logical device
90 static int host1x_device_parse_dt(struct host1x_device *device,
96 for_each_child_of_node(device->dev.parent->of_node, np) {
99 err = host1x_subdev_add(device, driver, np);
110 static void host1x_subdev_register(struct host1x_device *device,
119 * client with its parent device.
121 mutex_lock(&device->subdevs_lock);
122 mutex_lock(&device->clients_lock);
123 list_move_tail(&client->list, &device->clients);
124 list_move_tail(&subdev->list, &device->active);
125 client->host = &device->dev;
127 mutex_unlock(&device->clients_lock);
128 mutex_unlock(&device->subdevs_lock);
130 if (list_empty(&device->subdevs)) {
131 err = device_add(&device->dev);
133 dev_err(&device->dev, "failed to add: %d\n", err);
135 device->registered = true;
139 static void __host1x_subdev_unregister(struct host1x_device *device,
148 if (list_empty(&device->subdevs)) {
149 if (device->registered) {
150 device->registered = false;
151 device_del(&device->dev);
159 mutex_lock(&device->clients_lock);
162 list_move_tail(&subdev->list, &device->subdevs);
165 * when the device is about to be deleted.
169 * also when the composite device is about to be removed.
172 mutex_unlock(&device->clients_lock);
175 static void host1x_subdev_unregister(struct host1x_device *device,
178 mutex_lock(&device->subdevs_lock);
179 __host1x_subdev_unregister(device, subdev);
180 mutex_unlock(&device->subdevs_lock);
184 * host1x_device_init() - initialize a host1x logical device
185 * @device: host1x logical device
187 * The driver for the host1x logical device can call this during execution of
193 int host1x_device_init(struct host1x_device *device)
198 mutex_lock(&device->clients_lock);
200 list_for_each_entry(client, &device->clients, list) {
204 dev_err(&device->dev, "failed to early initialize %s: %d\n",
211 list_for_each_entry(client, &device->clients, list) {
215 dev_err(&device->dev,
223 mutex_unlock(&device->clients_lock);
228 list_for_each_entry_continue_reverse(client, &device->clients, list)
233 client = list_entry(&device->clients, struct host1x_client, list);
236 list_for_each_entry_continue_reverse(client, &device->clients, list)
240 mutex_unlock(&device->clients_lock);
246 * host1x_device_exit() - uninitialize host1x logical device
247 * @device: host1x logical device
249 * When the driver for a host1x logical device is unloaded, it can call this
254 int host1x_device_exit(struct host1x_device *device)
259 mutex_lock(&device->clients_lock);
261 list_for_each_entry_reverse(client, &device->clients, list) {
265 dev_err(&device->dev,
268 mutex_unlock(&device->clients_lock);
274 list_for_each_entry_reverse(client, &device->clients, list) {
278 dev_err(&device->dev, "failed to late cleanup %s: %d\n",
280 mutex_unlock(&device->clients_lock);
286 mutex_unlock(&device->clients_lock);
295 struct host1x_device *device;
300 list_for_each_entry(device, &host1x->devices, list) {
301 list_for_each_entry(subdev, &device->subdevs, list) {
303 host1x_subdev_register(device, subdev, client);
317 struct host1x_device *device, *dt;
322 list_for_each_entry_safe(device, dt, &host1x->devices, list) {
323 list_for_each_entry(subdev, &device->active, list) {
325 host1x_subdev_unregister(device, subdev);
336 static int host1x_device_match(struct device *dev, struct device_driver *drv)
346 static int host1x_device_uevent(const struct device *dev,
354 static int host1x_dma_configure(struct device *dev)
376 static void __host1x_device_del(struct host1x_device *device)
381 mutex_lock(&device->subdevs_lock);
384 list_for_each_entry_safe(subdev, sd, &device->active, list) {
396 __host1x_subdev_unregister(device, subdev);
405 list_for_each_entry_safe(subdev, sd, &device->subdevs, list)
408 mutex_unlock(&device->subdevs_lock);
412 mutex_lock(&device->clients_lock);
414 list_for_each_entry_safe(client, cl, &device->clients, list)
417 mutex_unlock(&device->clients_lock);
420 /* finally remove the device */
421 list_del_init(&device->list);
424 static void host1x_device_release(struct device *dev)
426 struct host1x_device *device = to_host1x_device(dev);
428 __host1x_device_del(device);
429 kfree(device);
437 struct host1x_device *device;
440 device = kzalloc(sizeof(*device), GFP_KERNEL);
441 if (!device)
444 device_initialize(&device->dev);
446 mutex_init(&device->subdevs_lock);
447 INIT_LIST_HEAD(&device->subdevs);
448 INIT_LIST_HEAD(&device->active);
449 mutex_init(&device->clients_lock);
450 INIT_LIST_HEAD(&device->clients);
451 INIT_LIST_HEAD(&device->list);
452 device->driver = driver;
454 device->dev.coherent_dma_mask = host1x->dev->coherent_dma_mask;
455 device->dev.dma_mask = &device->dev.coherent_dma_mask;
456 dev_set_name(&device->dev, "%s", driver->driver.name);
457 device->dev.release = host1x_device_release;
458 device->dev.bus = &host1x_bus_type;
459 device->dev.parent = host1x->dev;
461 of_dma_configure(&device->dev, host1x->dev->of_node, true);
463 device->dev.dma_parms = &device->dma_parms;
464 dma_set_max_seg_size(&device->dev, UINT_MAX);
466 err = host1x_device_parse_dt(device, driver);
468 kfree(device);
472 list_add_tail(&device->list, &host1x->devices);
477 list_for_each_entry(subdev, &device->subdevs, list) {
479 host1x_subdev_register(device, subdev, client);
491 * Removes a device by first unregistering any subdevices and then removing
497 struct host1x_device *device)
499 if (device->registered) {
500 device->registered = false;
501 device_del(&device->dev);
504 put_device(&device->dev);
510 struct host1x_device *device;
515 list_for_each_entry(device, &host1x->devices, list) {
516 if (device->driver == driver) {
524 dev_err(host1x->dev, "failed to allocate device: %d\n", err);
532 struct host1x_device *device, *tmp;
536 list_for_each_entry_safe(device, tmp, &host1x->devices, list)
537 if (device->driver == driver)
538 host1x_device_del(host1x, device);
546 struct host1x_device *device;
550 list_for_each_entry(device, &host1x->devices, list) {
553 seq_printf(s, "%s\n", dev_name(&device->dev));
555 mutex_lock(&device->subdevs_lock);
557 list_for_each_entry(subdev, &device->active, list)
561 list_for_each_entry(subdev, &device->subdevs, list)
564 mutex_unlock(&device->subdevs_lock);
627 static int host1x_device_probe(struct device *dev)
630 struct host1x_device *device = to_host1x_device(dev);
633 return driver->probe(device);
638 static int host1x_device_remove(struct device *dev)
641 struct host1x_device *device = to_host1x_device(dev);
644 return driver->remove(device);
649 static void host1x_device_shutdown(struct device *dev)
652 struct host1x_device *device = to_host1x_device(dev);
655 driver->shutdown(device);
665 * registration of the driver actually triggers tho logical device creation.
666 * A logical device will be created for each host1x instance.
754 * device and call host1x_device_init(), which will in turn call each client's
787 * device has already been initialized, it will be torn down.
892 struct host1x_bo_mapping *host1x_bo_pin(struct device *dev, struct host1x_bo *bo,