diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-21 18:49:58 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-21 18:49:58 -0400 |
commit | e80ab411e589e00550e2e6e5a6a02d59cc730357 (patch) | |
tree | 870225ff7b5b8d03e82a996963213a4bb9cce248 /samples/firmware_class/firmware_sample_driver.c | |
parent | 529a41e36673b518c9e091f3a8d932b6b9e3c461 (diff) | |
parent | ee959b00c335d7780136c5abda37809191fe52c3 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6: (36 commits)
SCSI: convert struct class_device to struct device
DRM: remove unused dev_class
IB: rename "dev" to "srp_dev" in srp_host structure
IB: convert struct class_device to struct device
memstick: convert struct class_device to struct device
driver core: replace remaining __FUNCTION__ occurrences
sysfs: refill attribute buffer when reading from offset 0
PM: Remove destroy_suspended_device()
Firmware: add iSCSI iBFT Support
PM: Remove legacy PM (fix)
Kobject: Replace list_for_each() with list_for_each_entry().
SYSFS: Explicitly include required header file slab.h.
Driver core: make device_is_registered() work for class devices
PM: Convert wakeup flag accessors to inline functions
PM: Make wakeup flags available whenever CONFIG_PM is set
PM: Fix misuse of wakeup flag accessors in serial core
Driver core: Call device_pm_add() after bus_add_device() in device_add()
PM: Handle device registrations during suspend/resume
block: send disk "change" event for rescan_partitions()
sysdev: detect multiple driver registrations
...
Fixed trivial conflict in include/linux/memory.h due to semaphore header
file change (made irrelevant by the change to mutex).
Diffstat (limited to 'samples/firmware_class/firmware_sample_driver.c')
-rw-r--r-- | samples/firmware_class/firmware_sample_driver.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/samples/firmware_class/firmware_sample_driver.c b/samples/firmware_class/firmware_sample_driver.c new file mode 100644 index 000000000000..165cff98032e --- /dev/null +++ b/samples/firmware_class/firmware_sample_driver.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * firmware_sample_driver.c - | ||
3 | * | ||
4 | * Copyright (c) 2003 Manuel Estrada Sainz | ||
5 | * | ||
6 | * Sample code on how to use request_firmware() from drivers. | ||
7 | * | ||
8 | */ | ||
9 | |||
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> | ||
16 | |||
17 | static struct device ghost_device = { | ||
18 | .bus_id = "ghost0", | ||
19 | }; | ||
20 | |||
21 | |||
22 | static void sample_firmware_load(char *firmware, int size) | ||
23 | { | ||
24 | u8 buf[size+1]; | ||
25 | memcpy(buf, firmware, size); | ||
26 | buf[size] = '\0'; | ||
27 | printk(KERN_INFO "firmware_sample_driver: firmware: %s\n", buf); | ||
28 | } | ||
29 | |||
30 | static void sample_probe_default(void) | ||
31 | { | ||
32 | /* uses the default method to get the firmware */ | ||
33 | const struct firmware *fw_entry; | ||
34 | int retval; | ||
35 | |||
36 | printk(KERN_INFO "firmware_sample_driver: " | ||
37 | "a ghost device got inserted :)\n"); | ||
38 | |||
39 | retval = request_firmware(&fw_entry, "sample_driver_fw", &ghost_device); | ||
40 | if (retval) { | ||
41 | printk(KERN_ERR | ||
42 | "firmware_sample_driver: Firmware not available\n"); | ||
43 | return; | ||
44 | } | ||
45 | |||
46 | sample_firmware_load(fw_entry->data, fw_entry->size); | ||
47 | |||
48 | release_firmware(fw_entry); | ||
49 | |||
50 | /* finish setting up the device */ | ||
51 | } | ||
52 | |||
53 | static void sample_probe_specific(void) | ||
54 | { | ||
55 | int retval; | ||
56 | /* Uses some specific hotplug support to get the firmware from | ||
57 | * userspace directly into the hardware, or via some sysfs file */ | ||
58 | |||
59 | /* NOTE: This currently doesn't work */ | ||
60 | |||
61 | printk(KERN_INFO "firmware_sample_driver: " | ||
62 | "a ghost device got inserted :)\n"); | ||
63 | |||
64 | retval = request_firmware(NULL, "sample_driver_fw", &ghost_device); | ||
65 | if (retval) { | ||
66 | printk(KERN_ERR | ||
67 | "firmware_sample_driver: Firmware load failed\n"); | ||
68 | return; | ||
69 | } | ||
70 | |||
71 | /* request_firmware blocks until userspace finished, so at | ||
72 | * this point the firmware should be already in the device */ | ||
73 | |||
74 | /* finish setting up the device */ | ||
75 | } | ||
76 | static void sample_probe_async_cont(const struct firmware *fw, void *context) | ||
77 | { | ||
78 | if (!fw) { | ||
79 | printk(KERN_ERR | ||
80 | "firmware_sample_driver: firmware load failed\n"); | ||
81 | return; | ||
82 | } | ||
83 | |||
84 | printk(KERN_INFO "firmware_sample_driver: device pointer \"%s\"\n", | ||
85 | (char *)context); | ||
86 | sample_firmware_load(fw->data, fw->size); | ||
87 | } | ||
88 | |||
89 | static void sample_probe_async(void) | ||
90 | { | ||
91 | /* Let's say that I can't sleep */ | ||
92 | int error; | ||
93 | error = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG, | ||
94 | "sample_driver_fw", &ghost_device, | ||
95 | "my device pointer", | ||
96 | sample_probe_async_cont); | ||
97 | if (error) | ||
98 | printk(KERN_ERR "firmware_sample_driver:" | ||
99 | " request_firmware_nowait failed\n"); | ||
100 | } | ||
101 | |||
102 | static int sample_init(void) | ||
103 | { | ||
104 | device_initialize(&ghost_device); | ||
105 | /* since there is no real hardware insertion I just call the | ||
106 | * sample probe functions here */ | ||
107 | sample_probe_specific(); | ||
108 | sample_probe_default(); | ||
109 | sample_probe_async(); | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | static void __exit sample_exit(void) | ||
114 | { | ||
115 | } | ||
116 | |||
117 | module_init(sample_init); | ||
118 | module_exit(sample_exit); | ||
119 | |||
120 | MODULE_LICENSE("GPL"); | ||