Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pwm: Try to load modules during pwm_get()

Add a module name string to the pwm_lookup struct and if specified try
to load the module using request_module() if pwmchip_find_by_name() is
unable to find the PWM chip.

This is a last resort to work around drivers that can't - and can't be
made to - deal with deferred probe.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
[thierry.reding@gmail.com: rename new macro, reword commit message]
[thierry.reding@gmail.com: add comment explaining use-case]
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Hans de Goede and committed by
Thierry Reding
b526a314 69efb343

+29 -8
+14
drivers/pwm/core.c
··· 765 765 unsigned int best = 0; 766 766 struct pwm_lookup *p, *chosen = NULL; 767 767 unsigned int match; 768 + int err; 768 769 769 770 /* look up via DT first */ 770 771 if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) ··· 826 825 return ERR_PTR(-ENODEV); 827 826 828 827 chip = pwmchip_find_by_name(chosen->provider); 828 + 829 + /* 830 + * If the lookup entry specifies a module, load the module and retry 831 + * the PWM chip lookup. This can be used to work around driver load 832 + * ordering issues if driver's can't be made to properly support the 833 + * deferred probe mechanism. 834 + */ 835 + if (!chip && chosen->module) { 836 + err = request_module(chosen->module); 837 + if (err == 0) 838 + chip = pwmchip_find_by_name(chosen->provider); 839 + } 840 + 829 841 if (!chip) 830 842 return ERR_PTR(-EPROBE_DEFER); 831 843
+15 -8
include/linux/pwm.h
··· 603 603 const char *con_id; 604 604 unsigned int period; 605 605 enum pwm_polarity polarity; 606 + const char *module; /* optional, may be NULL */ 606 607 }; 607 608 608 - #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \ 609 - { \ 610 - .provider = _provider, \ 611 - .index = _index, \ 612 - .dev_id = _dev_id, \ 613 - .con_id = _con_id, \ 614 - .period = _period, \ 615 - .polarity = _polarity \ 609 + #define PWM_LOOKUP_WITH_MODULE(_provider, _index, _dev_id, _con_id, \ 610 + _period, _polarity, _module) \ 611 + { \ 612 + .provider = _provider, \ 613 + .index = _index, \ 614 + .dev_id = _dev_id, \ 615 + .con_id = _con_id, \ 616 + .period = _period, \ 617 + .polarity = _polarity, \ 618 + .module = _module, \ 616 619 } 620 + 621 + #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \ 622 + PWM_LOOKUP_WITH_MODULE(_provider, _index, _dev_id, _con_id, _period, \ 623 + _polarity, NULL) 617 624 618 625 #if IS_ENABLED(CONFIG_PWM) 619 626 void pwm_add_table(struct pwm_lookup *table, size_t num);