Skip to content

Commit 9c829c0

Browse files
bebarinoPeter Chen
authored andcommitted
of: device: Support loading a module with OF based modalias
In the case of ULPI devices, we want to be able to load the driver before registering the device so that we don't get stuck in a loop waiting for the phy module to appear and failing usb controller probe. Currently we request the ulpi module via the ulpi ids, but in the DT case we might need to request it with the OF based modalias instead. Add a common function that allows anyone to request a module with the OF based modalias. Acked-by: Rob Herring <[email protected]> Cc: <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Peter Chen <[email protected]>
1 parent 3f991aa commit 9c829c0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/of/device.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
226226
return tsize;
227227
}
228228

229+
int of_device_request_module(struct device *dev)
230+
{
231+
char *str;
232+
ssize_t size;
233+
int ret;
234+
235+
size = of_device_get_modalias(dev, NULL, 0);
236+
if (size < 0)
237+
return size;
238+
239+
str = kmalloc(size + 1, GFP_KERNEL);
240+
if (!str)
241+
return -ENOMEM;
242+
243+
of_device_get_modalias(dev, str, size);
244+
str[size] = '\0';
245+
ret = request_module(str);
246+
kfree(str);
247+
248+
return ret;
249+
}
250+
EXPORT_SYMBOL_GPL(of_device_request_module);
251+
229252
/**
230253
* of_device_uevent - Display OF related uevent information
231254
*/

include/linux/of_device.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern const void *of_device_get_match_data(const struct device *dev);
3737

3838
extern ssize_t of_device_get_modalias(struct device *dev,
3939
char *str, ssize_t len);
40+
extern int of_device_request_module(struct device *dev);
4041

4142
extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
4243
extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env);
@@ -78,6 +79,11 @@ static inline int of_device_get_modalias(struct device *dev,
7879
return -ENODEV;
7980
}
8081

82+
static inline int of_device_request_module(struct device *dev)
83+
{
84+
return -ENODEV;
85+
}
86+
8187
static inline int of_device_uevent_modalias(struct device *dev,
8288
struct kobj_uevent_env *env)
8389
{

0 commit comments

Comments
 (0)