1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (C) 2020 Maxime Ripard <maxime@cerno.tech> */ 3 4 #include <linux/device.h> 5 #include <linux/dma-map-ops.h> 6 #include <linux/init.h> 7 #include <linux/notifier.h> 8 #include <linux/of.h> 9 #include <linux/platform_device.h> 10 11 static const char * const sunxi_mbus_devices[] = { 12 /* 13 * The display engine virtual devices are not strictly speaking 14 * connected to the MBUS, but since DRM will perform all the 15 * memory allocations and DMA operations through that device, we 16 * need to have the quirk on those devices too. 17 */ 18 "allwinner,sun4i-a10-display-engine", 19 "allwinner,sun5i-a10s-display-engine", 20 "allwinner,sun5i-a13-display-engine", 21 "allwinner,sun6i-a31-display-engine", 22 "allwinner,sun6i-a31s-display-engine", 23 "allwinner,sun7i-a20-display-engine", 24 "allwinner,sun8i-a23-display-engine", 25 "allwinner,sun8i-a33-display-engine", 26 "allwinner,sun8i-a83t-display-engine", 27 "allwinner,sun8i-h3-display-engine", 28 "allwinner,sun8i-r40-display-engine", 29 "allwinner,sun8i-v3s-display-engine", 30 "allwinner,sun9i-a80-display-engine", 31 "allwinner,sun50i-a64-display-engine", 32 33 /* 34 * And now we have the regular devices connected to the MBUS 35 * (that we know of). 36 */ 37 "allwinner,sun4i-a10-csi1", 38 "allwinner,sun4i-a10-display-backend", 39 "allwinner,sun4i-a10-display-frontend", 40 "allwinner,sun4i-a10-video-engine", 41 "allwinner,sun5i-a13-display-backend", 42 "allwinner,sun5i-a13-video-engine", 43 "allwinner,sun6i-a31-csi", 44 "allwinner,sun6i-a31-display-backend", 45 "allwinner,sun7i-a20-csi0", 46 "allwinner,sun7i-a20-display-backend", 47 "allwinner,sun7i-a20-display-frontend", 48 "allwinner,sun7i-a20-video-engine", 49 "allwinner,sun8i-a23-display-backend", 50 "allwinner,sun8i-a23-display-frontend", 51 "allwinner,sun8i-a33-display-backend", 52 "allwinner,sun8i-a33-display-frontend", 53 "allwinner,sun8i-a33-video-engine", 54 "allwinner,sun8i-a83t-csi", 55 "allwinner,sun8i-h3-csi", 56 "allwinner,sun8i-h3-video-engine", 57 "allwinner,sun8i-v3s-csi", 58 "allwinner,sun9i-a80-display-backend", 59 "allwinner,sun50i-a64-csi", 60 "allwinner,sun50i-a64-video-engine", 61 "allwinner,sun50i-h5-video-engine", 62 NULL, 63 }; 64 65 static int sunxi_mbus_notifier(struct notifier_block *nb, 66 unsigned long event, void *__dev) 67 { 68 struct device *dev = __dev; 69 int ret; 70 71 if (event != BUS_NOTIFY_ADD_DEVICE) 72 return NOTIFY_DONE; 73 74 /* 75 * Only the devices that need a large memory bandwidth do DMA 76 * directly over the memory bus (called MBUS), instead of going 77 * through the regular system bus. 78 */ 79 if (!of_device_compatible_match(dev->of_node, sunxi_mbus_devices)) 80 return NOTIFY_DONE; 81 82 /* 83 * Devices with an interconnects property have the MBUS 84 * relationship described in their DT and dealt with by 85 * of_dma_configure, so we can just skip them. 86 * 87 * Older DTs or SoCs who are not clearly understood need to set 88 * that DMA offset though. 89 */ 90 if (of_find_property(dev->of_node, "interconnects", NULL)) 91 return NOTIFY_DONE; 92 93 ret = dma_direct_set_offset(dev, PHYS_OFFSET, 0, SZ_4G); 94 if (ret) 95 dev_err(dev, "Couldn't setup our DMA offset: %d\n", ret); 96 97 return NOTIFY_DONE; 98 } 99 100 static struct notifier_block sunxi_mbus_nb = { 101 .notifier_call = sunxi_mbus_notifier, 102 }; 103 104 static const char * const sunxi_mbus_platforms[] __initconst = { 105 "allwinner,sun4i-a10", 106 "allwinner,sun5i-a10s", 107 "allwinner,sun5i-a13", 108 "allwinner,sun6i-a31", 109 "allwinner,sun7i-a20", 110 "allwinner,sun8i-a23", 111 "allwinner,sun8i-a33", 112 "allwinner,sun8i-a83t", 113 "allwinner,sun8i-h3", 114 "allwinner,sun8i-r40", 115 "allwinner,sun8i-v3", 116 "allwinner,sun8i-v3s", 117 "allwinner,sun9i-a80", 118 "allwinner,sun50i-a64", 119 "allwinner,sun50i-h5", 120 "nextthing,gr8", 121 NULL, 122 }; 123 124 static int __init sunxi_mbus_init(void) 125 { 126 if (!of_device_compatible_match(of_root, sunxi_mbus_platforms)) 127 return 0; 128 129 bus_register_notifier(&platform_bus_type, &sunxi_mbus_nb); 130 return 0; 131 } 132 arch_initcall(sunxi_mbus_init); 133