b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From 02e92b21edb4df7285f27ea5f0403377dcabe22d Mon Sep 17 00:00:00 2001 |
| 2 | From: Ioana Ciornei <ioana.ciornei@nxp.com> |
| 3 | Date: Tue, 29 Oct 2019 22:48:55 +0200 |
| 4 | Subject: [PATCH] bus: fsl-mc: add autorescan sysfs |
| 5 | |
| 6 | Add the autorescan sysfs in order to enable/disable the DPRC IRQs on |
| 7 | which automatic rescan of the bus is performed. This is important when |
| 8 | dynamic creation of objects is needed to happen in a timely manner because |
| 9 | object creation can be bundled together. |
| 10 | |
| 11 | Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com> |
| 12 | --- |
| 13 | drivers/bus/fsl-mc/dprc-driver.c | 17 ++++++++++-- |
| 14 | drivers/bus/fsl-mc/fsl-mc-bus.c | 55 +++++++++++++++++++++++++++++++++++++ |
| 15 | drivers/bus/fsl-mc/fsl-mc-private.h | 4 +++ |
| 16 | include/linux/fsl/mc.h | 1 + |
| 17 | 4 files changed, 75 insertions(+), 2 deletions(-) |
| 18 | |
| 19 | --- a/drivers/bus/fsl-mc/dprc-driver.c |
| 20 | +++ b/drivers/bus/fsl-mc/dprc-driver.c |
| 21 | @@ -484,8 +484,9 @@ out: |
| 22 | /* |
| 23 | * Disable and clear interrupt for a given DPRC object |
| 24 | */ |
| 25 | -static int disable_dprc_irq(struct fsl_mc_device *mc_dev) |
| 26 | +int disable_dprc_irq(struct fsl_mc_device *mc_dev) |
| 27 | { |
| 28 | + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev); |
| 29 | int error; |
| 30 | struct fsl_mc_io *mc_io = mc_dev->mc_io; |
| 31 | |
| 32 | @@ -522,9 +523,18 @@ static int disable_dprc_irq(struct fsl_m |
| 33 | return error; |
| 34 | } |
| 35 | |
| 36 | + mc_bus->irq_enabled = 0; |
| 37 | + |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | +int get_dprc_irq_state(struct fsl_mc_device *mc_dev) |
| 42 | +{ |
| 43 | + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev); |
| 44 | + |
| 45 | + return mc_bus->irq_enabled; |
| 46 | +} |
| 47 | + |
| 48 | static int register_dprc_irq_handler(struct fsl_mc_device *mc_dev) |
| 49 | { |
| 50 | int error; |
| 51 | @@ -551,8 +561,9 @@ static int register_dprc_irq_handler(str |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | -static int enable_dprc_irq(struct fsl_mc_device *mc_dev) |
| 56 | +int enable_dprc_irq(struct fsl_mc_device *mc_dev) |
| 57 | { |
| 58 | + struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev); |
| 59 | int error; |
| 60 | |
| 61 | /* |
| 62 | @@ -580,6 +591,8 @@ static int enable_dprc_irq(struct fsl_mc |
| 63 | return error; |
| 64 | } |
| 65 | |
| 66 | + mc_bus->irq_enabled = 1; |
| 67 | + |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | --- a/drivers/bus/fsl-mc/fsl-mc-bus.c |
| 72 | +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c |
| 73 | @@ -237,8 +237,63 @@ static ssize_t rescan_store(struct bus_t |
| 74 | } |
| 75 | static BUS_ATTR_WO(rescan); |
| 76 | |
| 77 | +static int fsl_mc_bus_set_autorescan(struct device *dev, void *data) |
| 78 | +{ |
| 79 | + struct fsl_mc_device *root_mc_dev; |
| 80 | + unsigned long val; |
| 81 | + char *buf = data; |
| 82 | + |
| 83 | + if (!fsl_mc_is_root_dprc(dev)) |
| 84 | + goto exit; |
| 85 | + |
| 86 | + root_mc_dev = to_fsl_mc_device(dev); |
| 87 | + |
| 88 | + if (kstrtoul(buf, 0, &val) < 0) |
| 89 | + return -EINVAL; |
| 90 | + |
| 91 | + if (val) |
| 92 | + enable_dprc_irq(root_mc_dev); |
| 93 | + else |
| 94 | + disable_dprc_irq(root_mc_dev); |
| 95 | + |
| 96 | +exit: |
| 97 | + return 0; |
| 98 | +} |
| 99 | + |
| 100 | +static int fsl_mc_bus_get_autorescan(struct device *dev, void *data) |
| 101 | +{ |
| 102 | + struct fsl_mc_device *root_mc_dev; |
| 103 | + char *buf = data; |
| 104 | + |
| 105 | + if (!fsl_mc_is_root_dprc(dev)) |
| 106 | + goto exit; |
| 107 | + |
| 108 | + root_mc_dev = to_fsl_mc_device(dev); |
| 109 | + |
| 110 | + sprintf(buf, "%d\n", get_dprc_irq_state(root_mc_dev)); |
| 111 | +exit: |
| 112 | + return 0; |
| 113 | +} |
| 114 | + |
| 115 | +static ssize_t autorescan_store(struct bus_type *bus, |
| 116 | + const char *buf, size_t count) |
| 117 | +{ |
| 118 | + bus_for_each_dev(bus, NULL, (void *)buf, fsl_mc_bus_set_autorescan); |
| 119 | + |
| 120 | + return count; |
| 121 | +} |
| 122 | + |
| 123 | +static ssize_t autorescan_show(struct bus_type *bus, char *buf) |
| 124 | +{ |
| 125 | + bus_for_each_dev(bus, NULL, (void *)buf, fsl_mc_bus_get_autorescan); |
| 126 | + return strlen(buf); |
| 127 | +} |
| 128 | + |
| 129 | +static BUS_ATTR_RW(autorescan); |
| 130 | + |
| 131 | static struct attribute *fsl_mc_bus_attrs[] = { |
| 132 | &bus_attr_rescan.attr, |
| 133 | + &bus_attr_autorescan.attr, |
| 134 | NULL, |
| 135 | }; |
| 136 | |
| 137 | --- a/drivers/bus/fsl-mc/fsl-mc-private.h |
| 138 | +++ b/drivers/bus/fsl-mc/fsl-mc-private.h |
| 139 | @@ -203,4 +203,8 @@ static inline void fsl_mc_uapi_remove_de |
| 140 | |
| 141 | #endif |
| 142 | |
| 143 | +int disable_dprc_irq(struct fsl_mc_device *mc_dev); |
| 144 | +int enable_dprc_irq(struct fsl_mc_device *mc_dev); |
| 145 | +int get_dprc_irq_state(struct fsl_mc_device *mc_dev); |
| 146 | + |
| 147 | #endif /* _FSL_MC_PRIVATE_H_ */ |
| 148 | --- a/include/linux/fsl/mc.h |
| 149 | +++ b/include/linux/fsl/mc.h |
| 150 | @@ -1006,6 +1006,7 @@ struct fsl_mc_bus { |
| 151 | struct mutex scan_mutex; /* serializes bus scanning */ |
| 152 | struct dprc_attributes dprc_attr; |
| 153 | struct fsl_mc_uapi uapi_misc; |
| 154 | + int irq_enabled; |
| 155 | }; |
| 156 | |
| 157 | int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev, |