2 * firmware_sample_driver.c -
4 * Copyright (c) 2003 Manuel Estrada Sainz
6 * Sample code on how to use request_firmware() from drivers.
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/device.h>
14 #include <linux/string.h>
15 #include <linux/firmware.h>
17 static struct device ghost_device = {
22 static void sample_firmware_load(char *firmware, int size)
25 memcpy(buf, firmware, size);
27 printk(KERN_INFO "firmware_sample_driver: firmware: %s\n", buf);
30 static void sample_probe_default(void)
32 /* uses the default method to get the firmware */
33 const struct firmware *fw_entry;
36 printk(KERN_INFO "firmware_sample_driver: "
37 "a ghost device got inserted :)\n");
39 retval = request_firmware(&fw_entry, "sample_driver_fw", &ghost_device);
42 "firmware_sample_driver: Firmware not available\n");
46 sample_firmware_load(fw_entry->data, fw_entry->size);
48 release_firmware(fw_entry);
50 /* finish setting up the device */
53 static void sample_probe_specific(void)
56 /* Uses some specific hotplug support to get the firmware from
57 * userspace directly into the hardware, or via some sysfs file */
59 /* NOTE: This currently doesn't work */
61 printk(KERN_INFO "firmware_sample_driver: "
62 "a ghost device got inserted :)\n");
64 retval = request_firmware(NULL, "sample_driver_fw", &ghost_device);
67 "firmware_sample_driver: Firmware load failed\n");
71 /* request_firmware blocks until userspace finished, so at
72 * this point the firmware should be already in the device */
74 /* finish setting up the device */
77 static void sample_probe_async_cont(const struct firmware *fw, void *context)
81 "firmware_sample_driver: firmware load failed\n");
85 printk(KERN_INFO "firmware_sample_driver: device pointer \"%s\"\n",
87 sample_firmware_load(fw->data, fw->size);
90 static void sample_probe_async(void)
92 /* Let's say that I can't sleep */
94 error = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
95 "sample_driver_fw", &ghost_device,
97 sample_probe_async_cont);
99 printk(KERN_ERR "firmware_sample_driver:"
100 " request_firmware_nowait failed\n");
103 static int __init sample_init(void)
105 device_initialize(&ghost_device);
106 /* since there is no real hardware insertion I just call the
107 * sample probe functions here */
108 sample_probe_specific();
109 sample_probe_default();
110 sample_probe_async();
114 static void __exit sample_exit(void)
118 module_init(sample_init);
119 module_exit(sample_exit);
121 MODULE_LICENSE("GPL");