Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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