Lines Matching +full:system +full:- +full:bus
1 // SPDX-License-Identifier: GPL-2.0-only
3 * MEN Chameleon Bus.
21 while (ids->device) { in mcb_match_id()
22 if (ids->device == dev->id) in mcb_match_id()
37 found_id = mcb_match_id(mdrv->id_table, mdev); in mcb_match()
49 ret = add_uevent_var(env, "MODALIAS=mcb:16z%03d", mdev->id); in mcb_uevent()
51 return -ENOMEM; in mcb_uevent()
58 struct mcb_driver *mdrv = to_mcb_driver(dev->driver); in mcb_probe()
64 found_id = mcb_match_id(mdrv->id_table, mdev); in mcb_probe()
66 return -ENODEV; in mcb_probe()
68 carrier_mod = mdev->dev.parent->driver->owner; in mcb_probe()
70 return -EINVAL; in mcb_probe()
73 ret = mdrv->probe(mdev, found_id); in mcb_probe()
84 struct mcb_driver *mdrv = to_mcb_driver(dev->driver); in mcb_remove()
88 mdrv->remove(mdev); in mcb_remove()
90 carrier_mod = mdev->dev.parent->driver->owner; in mcb_remove()
93 put_device(&mdev->dev); in mcb_remove()
98 struct mcb_driver *mdrv = to_mcb_driver(dev->driver); in mcb_shutdown()
101 if (mdrv && mdrv->shutdown) in mcb_shutdown()
102 mdrv->shutdown(mdev); in mcb_shutdown()
108 struct mcb_bus *bus = to_mcb_bus(dev); in revision_show() local
110 return scnprintf(buf, PAGE_SIZE, "%d\n", bus->revision); in revision_show()
117 struct mcb_bus *bus = to_mcb_bus(dev); in model_show() local
119 return scnprintf(buf, PAGE_SIZE, "%c\n", bus->model); in model_show()
126 struct mcb_bus *bus = to_mcb_bus(dev); in minor_show() local
128 return scnprintf(buf, PAGE_SIZE, "%d\n", bus->minor); in minor_show()
135 struct mcb_bus *bus = to_mcb_bus(dev); in name_show() local
137 return scnprintf(buf, PAGE_SIZE, "%s\n", bus->name); in name_show()
169 .name = "mcb-carrier",
174 * __mcb_register_driver() - Register a @mcb_driver at the system
179 * Register a @mcb_driver at the system. Perform some sanity checks, if
185 if (!drv->probe || !drv->remove) in __mcb_register_driver()
186 return -EINVAL; in __mcb_register_driver()
188 drv->driver.owner = owner; in __mcb_register_driver()
189 drv->driver.bus = &mcb_bus_type; in __mcb_register_driver()
190 drv->driver.mod_name = mod_name; in __mcb_register_driver()
192 return driver_register(&drv->driver); in __mcb_register_driver()
197 * mcb_unregister_driver() - Unregister a @mcb_driver from the system
200 * Unregister a @mcb_driver from the system.
204 driver_unregister(&drv->driver); in mcb_unregister_driver()
212 mcb_bus_put(mdev->bus); in mcb_release_dev()
217 * mcb_device_register() - Register a mcb_device
218 * @bus: The @mcb_bus of the device
221 * Register a specific @mcb_device at a @mcb_bus and the system itself.
223 int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev) in mcb_device_register() argument
228 device_initialize(&dev->dev); in mcb_device_register()
229 mcb_bus_get(bus); in mcb_device_register()
230 dev->dev.bus = &mcb_bus_type; in mcb_device_register()
231 dev->dev.parent = bus->dev.parent; in mcb_device_register()
232 dev->dev.release = mcb_release_dev; in mcb_device_register()
233 dev->dma_dev = bus->carrier; in mcb_device_register()
235 device_id = dev->id; in mcb_device_register()
236 dev_set_name(&dev->dev, "mcb%d-16z%03d-%d:%d:%d", in mcb_device_register()
237 bus->bus_nr, device_id, dev->inst, dev->group, dev->var); in mcb_device_register()
239 ret = device_add(&dev->dev); in mcb_device_register()
241 pr_err("Failed registering device 16z%03d on bus mcb%d (%d)\n", in mcb_device_register()
242 device_id, bus->bus_nr, ret); in mcb_device_register()
249 put_device(&dev->dev); in mcb_device_register()
257 struct mcb_bus *bus = to_mcb_bus(dev); in mcb_free_bus() local
259 put_device(bus->carrier); in mcb_free_bus()
260 ida_free(&mcb_ida, bus->bus_nr); in mcb_free_bus()
261 kfree(bus); in mcb_free_bus()
265 * mcb_alloc_bus() - Allocate a new @mcb_bus
272 struct mcb_bus *bus; in mcb_alloc_bus() local
276 bus = kzalloc(sizeof(struct mcb_bus), GFP_KERNEL); in mcb_alloc_bus()
277 if (!bus) in mcb_alloc_bus()
278 return ERR_PTR(-ENOMEM); in mcb_alloc_bus()
282 kfree(bus); in mcb_alloc_bus()
286 bus->bus_nr = bus_nr; in mcb_alloc_bus()
287 bus->carrier = get_device(carrier); in mcb_alloc_bus()
289 device_initialize(&bus->dev); in mcb_alloc_bus()
290 bus->dev.parent = carrier; in mcb_alloc_bus()
291 bus->dev.bus = &mcb_bus_type; in mcb_alloc_bus()
292 bus->dev.type = &mcb_carrier_device_type; in mcb_alloc_bus()
293 bus->dev.release = mcb_free_bus; in mcb_alloc_bus()
295 dev_set_name(&bus->dev, "mcb:%d", bus_nr); in mcb_alloc_bus()
296 rc = device_add(&bus->dev); in mcb_alloc_bus()
300 return bus; in mcb_alloc_bus()
303 put_device(&bus->dev); in mcb_alloc_bus()
314 static void mcb_devices_unregister(struct mcb_bus *bus) in mcb_devices_unregister() argument
316 bus_for_each_dev(bus->dev.bus, NULL, NULL, __mcb_devices_unregister); in mcb_devices_unregister()
319 * mcb_release_bus() - Free a @mcb_bus
320 * @bus: The @mcb_bus to release
322 * Release an allocated @mcb_bus from the system.
324 void mcb_release_bus(struct mcb_bus *bus) in mcb_release_bus() argument
326 mcb_devices_unregister(bus); in mcb_release_bus()
331 * mcb_bus_get() - Increment refcnt
332 * @bus: The @mcb_bus
336 struct mcb_bus *mcb_bus_get(struct mcb_bus *bus) in mcb_bus_get() argument
338 if (bus) in mcb_bus_get()
339 get_device(&bus->dev); in mcb_bus_get()
341 return bus; in mcb_bus_get()
346 * mcb_bus_put() - Decrement refcnt
347 * @bus: The @mcb_bus
351 void mcb_bus_put(struct mcb_bus *bus) in mcb_bus_put() argument
353 if (bus) in mcb_bus_put()
354 put_device(&bus->dev); in mcb_bus_put()
359 * mcb_alloc_dev() - Allocate a device
360 * @bus: The @mcb_bus the device is part of
362 * Allocate a @mcb_device and add bus.
364 struct mcb_device *mcb_alloc_dev(struct mcb_bus *bus) in mcb_alloc_dev() argument
372 dev->bus = bus; in mcb_alloc_dev()
379 * mcb_free_dev() - Free @mcb_device
404 * mcb_bus_add_devices() - Add devices in the bus' internal device list
405 * @bus: The @mcb_bus we add the devices
407 * Add devices in the bus' internal device list to the system.
409 void mcb_bus_add_devices(const struct mcb_bus *bus) in mcb_bus_add_devices() argument
411 bus_for_each_dev(bus->dev.bus, NULL, NULL, __mcb_bus_add_devices); in mcb_bus_add_devices()
416 * mcb_get_resource() - get a resource for a mcb device
423 return &dev->mem; in mcb_get_resource()
425 return &dev->irq; in mcb_get_resource()
432 * mcb_request_mem() - Request memory
445 name = dev->dev.driver->name; in mcb_request_mem()
447 size = resource_size(&dev->mem); in mcb_request_mem()
449 mem = request_mem_region(dev->mem.start, size, name); in mcb_request_mem()
451 return ERR_PTR(-EBUSY); in mcb_request_mem()
458 * mcb_release_mem() - Release memory requested by device
468 release_mem_region(mem->start, size); in mcb_release_mem()
478 return irq->start; in __mcb_get_irq()
482 * mcb_get_irq() - Get device's IRQ number
489 struct mcb_bus *bus = dev->bus; in mcb_get_irq() local
491 if (bus->get_irq) in mcb_get_irq()
492 return bus->get_irq(dev); in mcb_get_irq()
516 MODULE_DESCRIPTION("MEN Chameleon Bus Driver");