Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2//
  3// Bus implementation for the NuBus subsystem.
  4//
  5// Copyright (C) 2017 Finn Thain
  6
  7#include <linux/device.h>
  8#include <linux/dma-mapping.h>
  9#include <linux/list.h>
 10#include <linux/nubus.h>
 11#include <linux/seq_file.h>
 12#include <linux/slab.h>
 13
 14#define to_nubus_board(d)       container_of(d, struct nubus_board, dev)
 15#define to_nubus_driver(d)      container_of(d, struct nubus_driver, driver)
 16
 
 
 
 
 
 17static int nubus_device_probe(struct device *dev)
 18{
 19	struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
 20	int err = -ENODEV;
 21
 22	if (ndrv->probe)
 23		err = ndrv->probe(to_nubus_board(dev));
 24	return err;
 25}
 26
 27static void nubus_device_remove(struct device *dev)
 28{
 29	struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
 
 30
 31	if (ndrv->remove)
 32		ndrv->remove(to_nubus_board(dev));
 
 33}
 34
 35static const struct bus_type nubus_bus_type = {
 36	.name		= "nubus",
 
 37	.probe		= nubus_device_probe,
 38	.remove		= nubus_device_remove,
 39};
 
 40
 41int nubus_driver_register(struct nubus_driver *ndrv)
 42{
 43	ndrv->driver.bus = &nubus_bus_type;
 44	return driver_register(&ndrv->driver);
 45}
 46EXPORT_SYMBOL(nubus_driver_register);
 47
 48void nubus_driver_unregister(struct nubus_driver *ndrv)
 49{
 50	driver_unregister(&ndrv->driver);
 51}
 52EXPORT_SYMBOL(nubus_driver_unregister);
 53
 54static struct device nubus_parent = {
 55	.init_name	= "nubus",
 56};
 57
 58static int __init nubus_bus_register(void)
 59{
 60	return bus_register(&nubus_bus_type);
 61}
 62postcore_initcall(nubus_bus_register);
 63
 64int __init nubus_parent_device_register(void)
 65{
 66	return device_register(&nubus_parent);
 67}
 68
 69static void nubus_device_release(struct device *dev)
 70{
 71	struct nubus_board *board = to_nubus_board(dev);
 72	struct nubus_rsrc *fres, *tmp;
 73
 74	list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list)
 75		if (fres->board == board) {
 76			list_del(&fres->list);
 77			kfree(fres);
 78		}
 79	kfree(board);
 80}
 81
 82int nubus_device_register(struct nubus_board *board)
 83{
 84	board->dev.parent = &nubus_parent;
 85	board->dev.release = nubus_device_release;
 86	board->dev.bus = &nubus_bus_type;
 87	dev_set_name(&board->dev, "slot.%X", board->slot);
 88	board->dev.dma_mask = &board->dev.coherent_dma_mask;
 89	dma_set_mask(&board->dev, DMA_BIT_MASK(32));
 90	return device_register(&board->dev);
 91}
 92
 93static int nubus_print_device_name_fn(struct device *dev, void *data)
 94{
 95	struct nubus_board *board = to_nubus_board(dev);
 96	struct seq_file *m = data;
 97
 98	seq_printf(m, "Slot %X: %s\n", board->slot, board->name);
 99	return 0;
100}
101
102int nubus_proc_show(struct seq_file *m, void *data)
103{
104	return bus_for_each_dev(&nubus_bus_type, NULL, m,
105				nubus_print_device_name_fn);
106}
v5.4
  1// SPDX-License-Identifier: GPL-2.0
  2//
  3// Bus implementation for the NuBus subsystem.
  4//
  5// Copyright (C) 2017 Finn Thain
  6
  7#include <linux/device.h>
  8#include <linux/dma-mapping.h>
  9#include <linux/list.h>
 10#include <linux/nubus.h>
 11#include <linux/seq_file.h>
 12#include <linux/slab.h>
 13
 14#define to_nubus_board(d)       container_of(d, struct nubus_board, dev)
 15#define to_nubus_driver(d)      container_of(d, struct nubus_driver, driver)
 16
 17static int nubus_bus_match(struct device *dev, struct device_driver *driver)
 18{
 19	return 1;
 20}
 21
 22static int nubus_device_probe(struct device *dev)
 23{
 24	struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
 25	int err = -ENODEV;
 26
 27	if (ndrv->probe)
 28		err = ndrv->probe(to_nubus_board(dev));
 29	return err;
 30}
 31
 32static int nubus_device_remove(struct device *dev)
 33{
 34	struct nubus_driver *ndrv = to_nubus_driver(dev->driver);
 35	int err = -ENODEV;
 36
 37	if (dev->driver && ndrv->remove)
 38		err = ndrv->remove(to_nubus_board(dev));
 39	return err;
 40}
 41
 42struct bus_type nubus_bus_type = {
 43	.name		= "nubus",
 44	.match		= nubus_bus_match,
 45	.probe		= nubus_device_probe,
 46	.remove		= nubus_device_remove,
 47};
 48EXPORT_SYMBOL(nubus_bus_type);
 49
 50int nubus_driver_register(struct nubus_driver *ndrv)
 51{
 52	ndrv->driver.bus = &nubus_bus_type;
 53	return driver_register(&ndrv->driver);
 54}
 55EXPORT_SYMBOL(nubus_driver_register);
 56
 57void nubus_driver_unregister(struct nubus_driver *ndrv)
 58{
 59	driver_unregister(&ndrv->driver);
 60}
 61EXPORT_SYMBOL(nubus_driver_unregister);
 62
 63static struct device nubus_parent = {
 64	.init_name	= "nubus",
 65};
 66
 67static int __init nubus_bus_register(void)
 68{
 69	return bus_register(&nubus_bus_type);
 70}
 71postcore_initcall(nubus_bus_register);
 72
 73int __init nubus_parent_device_register(void)
 74{
 75	return device_register(&nubus_parent);
 76}
 77
 78static void nubus_device_release(struct device *dev)
 79{
 80	struct nubus_board *board = to_nubus_board(dev);
 81	struct nubus_rsrc *fres, *tmp;
 82
 83	list_for_each_entry_safe(fres, tmp, &nubus_func_rsrcs, list)
 84		if (fres->board == board) {
 85			list_del(&fres->list);
 86			kfree(fres);
 87		}
 88	kfree(board);
 89}
 90
 91int nubus_device_register(struct nubus_board *board)
 92{
 93	board->dev.parent = &nubus_parent;
 94	board->dev.release = nubus_device_release;
 95	board->dev.bus = &nubus_bus_type;
 96	dev_set_name(&board->dev, "slot.%X", board->slot);
 97	board->dev.dma_mask = &board->dev.coherent_dma_mask;
 98	dma_set_mask(&board->dev, DMA_BIT_MASK(32));
 99	return device_register(&board->dev);
100}
101
102static int nubus_print_device_name_fn(struct device *dev, void *data)
103{
104	struct nubus_board *board = to_nubus_board(dev);
105	struct seq_file *m = data;
106
107	seq_printf(m, "Slot %X: %s\n", board->slot, board->name);
108	return 0;
109}
110
111int nubus_proc_show(struct seq_file *m, void *data)
112{
113	return bus_for_each_dev(&nubus_bus_type, NULL, m,
114				nubus_print_device_name_fn);
115}