2 * firmware_sample_driver.c -
4 * Copyright (c) 2003 Manuel Estrada Sainz <ranty@debian.org>
6 * Sample code on how to use request_firmware() from drivers.
8 * Note that register_firmware() is currently useless.
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
17 #include "linux/firmware.h"
19 #define WE_CAN_NEED_FIRMWARE_BEFORE_USERSPACE_IS_AVAILABLE
20 #ifdef WE_CAN_NEED_FIRMWARE_BEFORE_USERSPACE_IS_AVAILABLE
21 char __init inkernel_firmware
[] = "let's say that this is firmware\n";
24 static struct device ghost_device
= {
25 .name
= "Ghost Device",
30 static void sample_firmware_load(char *firmware
, int size
)
33 memcpy(buf
, firmware
, size
);
35 printk("firmware_sample_driver: firmware: %s\n", buf
);
38 static void sample_probe_default(void)
40 /* uses the default method to get the firmware */
41 const struct firmware
*fw_entry
;
42 printk("firmware_sample_driver: a ghost device got inserted :)\n");
44 if(request_firmware(&fw_entry
, "sample_driver_fw", &ghost_device
)!=0)
47 "firmware_sample_driver: Firmware not available\n");
51 sample_firmware_load(fw_entry
->data
, fw_entry
->size
);
53 release_firmware(fw_entry
);
55 /* finish setting up the device */
57 static void sample_probe_specific(void)
59 /* Uses some specific hotplug support to get the firmware from
60 * userspace directly into the hardware, or via some sysfs file */
62 /* NOTE: This currently doesn't work */
64 printk("firmware_sample_driver: a ghost device got inserted :)\n");
66 if(request_firmware(NULL
, "sample_driver_fw", &ghost_device
)!=0)
69 "firmware_sample_driver: Firmware load failed\n");
73 /* request_firmware blocks until userspace finished, so at
74 * this point the firmware should be already in the device */
76 /* finish setting up the device */
78 static void sample_probe_async_cont(const struct firmware
*fw
, void *context
)
82 "firmware_sample_driver: firmware load failed\n");
86 printk("firmware_sample_driver: device pointer \"%s\"\n",
88 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
,
95 "sample_driver_fw", &ghost_device
,
97 sample_probe_async_cont
);
100 "firmware_sample_driver:"
101 " request_firmware_nowait failed\n");
105 static int sample_init(void)
107 #ifdef WE_CAN_NEED_FIRMWARE_BEFORE_USERSPACE_IS_AVAILABLE
108 register_firmware("sample_driver_fw", inkernel_firmware
,
109 sizeof(inkernel_firmware
));
111 device_initialize(&ghost_device
);
112 /* since there is no real hardware insertion I just call the
113 * sample probe functions here */
114 sample_probe_specific();
115 sample_probe_default();
116 sample_probe_async();
119 static void __exit
sample_exit(void)
123 module_init (sample_init
);
124 module_exit (sample_exit
);
126 MODULE_LICENSE("GPL");