On 12/17/24 5:30 AM, Nuno Sá wrote: > On Wed, 2024-12-11 at 14:54 -0600, David Lechner wrote: >> Extend SPI offloading to support hardware triggers. >> ... >> +static struct spi_offload_trigger >> +*spi_offload_trigger_get(enum spi_offload_trigger_type type, >> + struct fwnode_reference_args *args) >> +{ >> + struct spi_offload_trigger *trigger; >> + bool match = false; >> + int ret; >> + >> + guard(mutex)(&spi_offload_triggers_lock); >> + >> + list_for_each_entry(trigger, &spi_offload_triggers, list) { >> + if (trigger->fwnode != args->fwnode) >> + continue; >> + >> + match = trigger->ops->match(trigger, type, args->args, args- >>> nargs); >> + if (match) >> + break; >> + } >> + >> + if (!match) >> + return ERR_PTR(-EPROBE_DEFER); >> + >> + guard(mutex)(&trigger->lock); >> + >> + if (!trigger->ops) >> + return ERR_PTR(-ENODEV); >> + >> + if (trigger->ops->request) { >> + ret = trigger->ops->request(trigger, type, args->args, args- >>> nargs); >> + if (ret) >> + return ERR_PTR(ret); >> + } >> + >> + kref_get(&trigger->ref); > > maybe try_module_get() would also make sense... Even if a module had more than one trigger? Or do you mean in addition to the kref_get()? > >> + >> + return trigger; >> +} >> + >> +/** >> + * devm_spi_offload_trigger_get() - Get an offload trigger instance >> + * @dev: Device for devm purposes. >> + * @offload: Offload instance connected to a trigger. >> + * @type: Trigger type to get. >> + * >> + * Return: Offload trigger instance or error on failure. >> + */ >> +struct spi_offload_trigger >> +*devm_spi_offload_trigger_get(struct device *dev, >> + struct spi_offload *offload, >> + enum spi_offload_trigger_type type) >> +{ >> + struct spi_offload_trigger *trigger; >> + struct fwnode_reference_args args; >> + int ret; >> + >> + ret = fwnode_property_get_reference_args(dev_fwnode(offload- >>> provider_dev), >> + "trigger-sources", >> + "#trigger-source-cells", 0, >> 0, >> + &args); > > I guess at some point we can add these to fwlinks? > Yes. Although we'll need to investigate how it would affect leds since they use the same binding. So perhaps we can save that for later since the rest of this series seems ready now.