Lines Matching refs:device

11 #include <linux/device.h>
157 static const struct ieee1394_device_id *unit_match(struct device *dev,
173 static bool is_fw_unit(struct device *dev);
175 static int fw_unit_match(struct device *dev, struct device_driver *drv)
181 static int fw_unit_probe(struct device *dev)
189 static void fw_unit_remove(struct device *dev)
208 static int fw_unit_uevent(const struct device *dev, struct kobj_uevent_env *env)
229 int fw_device_enable_phys_dma(struct fw_device *device)
231 int generation = device->generation;
233 /* device->node_id, accessed below, must not be older than generation */
236 return device->card->driver->enable_phys_dma(device->card,
237 device->node_id,
247 static ssize_t show_immediate(struct device *dev,
279 static ssize_t show_text_leaf(struct device *dev,
332 static void init_fw_attribute_group(struct device *dev,
356 static ssize_t modalias_show(struct device *dev,
368 static ssize_t rom_index_show(struct device *dev,
371 struct fw_device *device = fw_device(dev->parent);
374 return sysfs_emit(buf, "%td\n", unit->directory - device->config_rom);
383 static ssize_t config_rom_show(struct device *dev,
386 struct fw_device *device = fw_device(dev);
390 length = device->config_rom_length * 4;
391 memcpy(buf, device->config_rom, length);
397 static ssize_t guid_show(struct device *dev,
400 struct fw_device *device = fw_device(dev);
404 ret = sysfs_emit(buf, "0x%08x%08x\n", device->config_rom[3], device->config_rom[4]);
410 static ssize_t is_local_show(struct device *dev,
413 struct fw_device *device = fw_device(dev);
415 return sprintf(buf, "%u\n", device->is_local);
440 static ssize_t units_show(struct device *dev,
443 struct fw_device *device = fw_device(dev);
448 fw_csr_iterator_init(&ci, &device->config_rom[5]);
472 static int read_rom(struct fw_device *device,
478 /* device->node_id, accessed below, must not be older than generation */
482 rcode = fw_run_transaction(device->card,
483 TCODE_READ_QUADLET_REQUEST, device->node_id,
484 generation, device->max_speed, offset, data, 4);
504 static int read_config_rom(struct fw_device *device, int generation)
506 struct fw_card *card = device->card;
520 device->max_speed = SCODE_100;
524 ret = read_rom(device, generation, i, &rom[i]);
541 device->max_speed = device->node->max_speed;
552 if ((rom[2] & 0x7) < device->max_speed ||
553 device->max_speed == SCODE_BETA ||
558 if (device->max_speed == SCODE_BETA)
559 device->max_speed = card->link_speed;
561 while (device->max_speed > SCODE_100) {
562 if (read_rom(device, generation, 0, &dummy) ==
565 device->max_speed--;
594 ret = read_rom(device, generation, i, &rom[i]);
618 ret = read_rom(device, generation, i, &rom[i]);
645 old_rom = device->config_rom;
653 device->config_rom = new_rom;
654 device->config_rom_length = length;
659 device->max_rec = rom[2] >> 12 & 0xf;
660 device->cmc = rom[2] >> 30 & 1;
661 device->irmc = rom[2] >> 31 & 1;
668 static void fw_unit_release(struct device *dev)
681 static bool is_fw_unit(struct device *dev)
686 static void create_units(struct fw_device *device)
693 fw_csr_iterator_init(&ci, &device->config_rom[5]);
707 unit->device.bus = &fw_bus_type;
708 unit->device.type = &fw_unit_type;
709 unit->device.parent = &device->device;
710 dev_set_name(&unit->device, "%s.%d", dev_name(&device->device), i++);
715 init_fw_attribute_group(&unit->device,
719 fw_device_get(device);
720 if (device_register(&unit->device) < 0) {
721 put_device(&unit->device);
727 static int shutdown_unit(struct device *device, void *data)
729 device_unregister(device);
747 struct fw_device *device;
750 device = idr_find(&fw_device_idr, MINOR(devt));
751 if (device)
752 fw_device_get(device);
755 return device;
761 static void fw_schedule_device_work(struct fw_device *device,
764 queue_delayed_work(fw_workqueue, &device->work, delay);
769 * rom. It shouldn't be necessary to tweak these; if the device
785 struct fw_device *device =
787 int minor = MINOR(device->device.devt);
790 device->card->reset_jiffies + SHUTDOWN_DELAY)
791 && !list_empty(&device->card->link)) {
792 fw_schedule_device_work(device, SHUTDOWN_DELAY);
796 if (atomic_cmpxchg(&device->state,
801 fw_device_cdev_remove(device);
802 device_for_each_child(&device->device, NULL, shutdown_unit);
803 device_unregister(&device->device);
809 fw_device_put(device);
812 static void fw_device_release(struct device *dev)
814 struct fw_device *device = fw_device(dev);
815 struct fw_card *card = device->card;
824 device->node->data = NULL;
827 fw_node_put(device->node);
828 kfree(device->config_rom);
829 kfree(device);
837 static bool is_fw_device(struct device *dev)
842 static int update_unit(struct device *dev, void *data)
858 struct fw_device *device =
861 fw_device_cdev_update(device);
862 device_for_each_child(&device->device, NULL, update_unit);
866 * If a device was pending for deletion because its node went away but its
868 * device, revive the existing fw_device.
871 static int lookup_existing_device(struct device *dev, void *data)
901 fw_notice(card, "rediscovered device %s\n", dev_name(dev));
920 static void set_broadcast_channel(struct fw_device *device, int generation)
922 struct fw_card *card = device->card;
936 if (!device->irmc || device->max_rec < 8)
943 if (device->bc_implemented == BC_UNKNOWN) {
945 device->node_id, generation, device->max_speed,
951 device->bc_implemented = BC_IMPLEMENTED;
956 device->bc_implemented = BC_UNIMPLEMENTED;
960 if (device->bc_implemented == BC_IMPLEMENTED) {
964 device->node_id, generation, device->max_speed,
970 int fw_device_set_broadcast_channel(struct device *dev, void *gen)
980 struct fw_device *device =
982 struct fw_card *card = device->card;
983 struct device *revived_dev;
989 * device.
992 ret = read_config_rom(device, device->generation);
994 if (device->config_rom_retries < MAX_RETRIES &&
995 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
996 device->config_rom_retries++;
997 fw_schedule_device_work(device, RETRY_DELAY);
999 if (device->node->link_on)
1001 device->node_id,
1003 if (device->node == card->root_node)
1005 fw_device_release(&device->device);
1010 revived_dev = device_find_child(card->device,
1011 device, lookup_existing_device);
1014 fw_device_release(&device->device);
1019 device_initialize(&device->device);
1021 fw_device_get(device);
1023 minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS,
1030 device->device.bus = &fw_bus_type;
1031 device->device.type = &fw_device_type;
1032 device->device.parent = card->device;
1033 device->device.devt = MKDEV(fw_cdev_major, minor);
1034 dev_set_name(&device->device, "fw%d", minor);
1036 BUILD_BUG_ON(ARRAY_SIZE(device->attribute_group.attrs) <
1039 init_fw_attribute_group(&device->device,
1041 &device->attribute_group);
1043 if (device_add(&device->device)) {
1044 fw_err(card, "failed to add device\n");
1048 create_units(device);
1051 * Transition the device to running state. If it got pulled
1053 * have to shut down the device again here. Normally, though,
1059 if (atomic_cmpxchg(&device->state,
1062 device->workfn = fw_device_shutdown;
1063 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1065 fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
1066 dev_name(&device->device),
1067 device->config_rom[3], device->config_rom[4],
1068 1 << device->max_speed);
1069 device->config_rom_retries = 0;
1071 set_broadcast_channel(device, device->generation);
1073 add_device_randomness(&device->config_rom[3], 8);
1082 if (device->node == card->root_node)
1092 fw_device_put(device); /* fw_device_idr's reference */
1094 put_device(&device->device); /* our reference */
1098 static int reread_config_rom(struct fw_device *device, int generation,
1105 rcode = read_rom(device, generation, i, &q);
1113 if (q != device->config_rom[i]) {
1125 struct fw_device *device =
1127 struct fw_card *card = device->card;
1128 int ret, node_id = device->node_id;
1131 ret = reread_config_rom(device, device->generation, &changed);
1136 if (atomic_cmpxchg(&device->state,
1142 device->config_rom_retries = 0;
1150 device_for_each_child(&device->device, NULL, shutdown_unit);
1152 ret = read_config_rom(device, device->generation);
1156 fw_device_cdev_update(device);
1157 create_units(device);
1160 kobject_uevent(&device->device.kobj, KOBJ_CHANGE);
1162 if (atomic_cmpxchg(&device->state,
1167 fw_notice(card, "refreshed device %s\n", dev_name(&device->device));
1168 device->config_rom_retries = 0;
1172 if (device->config_rom_retries < MAX_RETRIES &&
1173 atomic_read(&device->state) == FW_DEVICE_INITIALIZING) {
1174 device->config_rom_retries++;
1175 fw_schedule_device_work(device, RETRY_DELAY);
1179 fw_notice(card, "giving up on refresh of device %s: %s\n",
1180 dev_name(&device->device), fw_rcode_string(ret));
1182 atomic_set(&device->state, FW_DEVICE_GONE);
1183 device->workfn = fw_device_shutdown;
1184 fw_schedule_device_work(device, SHUTDOWN_DELAY);
1192 struct fw_device *device = container_of(to_delayed_work(work),
1194 device->workfn(work);
1199 struct fw_device *device;
1210 device = kzalloc(sizeof(*device), GFP_ATOMIC);
1211 if (device == NULL)
1215 * Do minimal initialization of the device here, the
1220 * You can basically just check device->state and
1224 atomic_set(&device->state, FW_DEVICE_INITIALIZING);
1225 device->card = fw_card_get(card);
1226 device->node = fw_node_get(node);
1227 device->node_id = node->node_id;
1228 device->generation = card->generation;
1229 device->is_local = node == card->local_node;
1230 mutex_init(&device->client_list_mutex);
1231 INIT_LIST_HEAD(&device->client_list);
1234 * Set the node data to point back to this device so
1236 * and generation for the device.
1238 node->data = device;
1246 device->workfn = fw_device_init;
1247 INIT_DELAYED_WORK(&device->work, fw_device_workfn);
1248 fw_schedule_device_work(device, INITIAL_DELAY);
1253 device = node->data;
1254 if (device == NULL)
1257 device->node_id = node->node_id;
1259 device->generation = card->generation;
1260 if (atomic_cmpxchg(&device->state,
1263 device->workfn = fw_device_refresh;
1264 fw_schedule_device_work(device,
1265 device->is_local ? 0 : INITIAL_DELAY);
1270 device = node->data;
1271 if (device == NULL)
1274 device->node_id = node->node_id;
1276 device->generation = card->generation;
1277 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
1278 device->workfn = fw_device_update;
1279 fw_schedule_device_work(device, 0);
1289 * Destroy the device associated with the node. There
1290 * are two cases here: either the device is fully
1294 * initialized we can reuse device->work to schedule a
1297 * the device in shutdown state to have that code fail
1298 * to create the device.
1300 device = node->data;
1301 if (atomic_xchg(&device->state,
1303 device->workfn = fw_device_shutdown;
1304 fw_schedule_device_work(device,