diff options
| author | Randy Dunlap <randy.dunlap@oracle.com> | 2008-02-20 16:20:50 -0500 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@suse.de> | 2008-04-19 22:10:20 -0400 |
| commit | d289bf7bdd84d636054acb0b3d14a4708f8a8233 (patch) | |
| tree | 827bf43c58a95017b59eeac7deb5c3d5d760750e /samples/firmware_class | |
| parent | 3612e06b2c1cec41e9a59da3eec673a206af4643 (diff) | |
firmware: move firmware_class from Documentation/ to samples/
Move the firmware_class sample drivers to samples/ so that they are
buildable and can be maintained.
Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'samples/firmware_class')
| -rw-r--r-- | samples/firmware_class/firmware_sample_driver.c | 115 | ||||
| -rw-r--r-- | samples/firmware_class/firmware_sample_firmware_class.c | 207 |
2 files changed, 322 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..ff0f2f2bd1a8 --- /dev/null +++ b/samples/firmware_class/firmware_sample_driver.c | |||
| @@ -0,0 +1,115 @@ | |||
| 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 | |||
| 16 | #include "linux/firmware.h" | ||
| 17 | |||
| 18 | static struct device ghost_device = { | ||
| 19 | .bus_id = "ghost0", | ||
| 20 | }; | ||
| 21 | |||
| 22 | |||
| 23 | static void sample_firmware_load(char *firmware, int size) | ||
| 24 | { | ||
| 25 | u8 buf[size+1]; | ||
| 26 | memcpy(buf, firmware, size); | ||
| 27 | buf[size] = '\0'; | ||
| 28 | printk(KERN_INFO "firmware_sample_driver: firmware: %s\n", buf); | ||
| 29 | } | ||
| 30 | |||
| 31 | static void sample_probe_default(void) | ||
| 32 | { | ||
| 33 | /* uses the default method to get the firmware */ | ||
| 34 | const struct firmware *fw_entry; | ||
| 35 | printk(KERN_INFO "firmware_sample_driver: a ghost device got inserted :)\n"); | ||
| 36 | |||
| 37 | if(request_firmware(&fw_entry, "sample_driver_fw", &ghost_device)!=0) | ||
| 38 | { | ||
| 39 | printk(KERN_ERR | ||
| 40 | "firmware_sample_driver: Firmware not available\n"); | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | |||
| 44 | sample_firmware_load(fw_entry->data, fw_entry->size); | ||
| 45 | |||
| 46 | release_firmware(fw_entry); | ||
| 47 | |||
| 48 | /* finish setting up the device */ | ||
| 49 | } | ||
| 50 | static void sample_probe_specific(void) | ||
| 51 | { | ||
| 52 | /* Uses some specific hotplug support to get the firmware from | ||
| 53 | * userspace directly into the hardware, or via some sysfs file */ | ||
| 54 | |||
| 55 | /* NOTE: This currently doesn't work */ | ||
| 56 | |||
| 57 | printk(KERN_INFO "firmware_sample_driver: a ghost device got inserted :)\n"); | ||
| 58 | |||
| 59 | if(request_firmware(NULL, "sample_driver_fw", &ghost_device)!=0) | ||
| 60 | { | ||
| 61 | printk(KERN_ERR | ||
| 62 | "firmware_sample_driver: Firmware load failed\n"); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | |||
| 66 | /* request_firmware blocks until userspace finished, so at | ||
| 67 | * this point the firmware should be already in the device */ | ||
| 68 | |||
| 69 | /* finish setting up the device */ | ||
| 70 | } | ||
| 71 | static void sample_probe_async_cont(const struct firmware *fw, void *context) | ||
| 72 | { | ||
| 73 | if(!fw){ | ||
| 74 | printk(KERN_ERR | ||
| 75 | "firmware_sample_driver: firmware load failed\n"); | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | |||
| 79 | printk(KERN_INFO "firmware_sample_driver: device pointer \"%s\"\n", | ||
| 80 | (char *)context); | ||
| 81 | sample_firmware_load(fw->data, fw->size); | ||
| 82 | } | ||
| 83 | static void sample_probe_async(void) | ||
| 84 | { | ||
| 85 | /* Let's say that I can't sleep */ | ||
| 86 | int error; | ||
| 87 | error = request_firmware_nowait (THIS_MODULE, FW_ACTION_NOHOTPLUG, | ||
| 88 | "sample_driver_fw", &ghost_device, | ||
| 89 | "my device pointer", | ||
| 90 | sample_probe_async_cont); | ||
| 91 | if(error){ | ||
| 92 | printk(KERN_ERR | ||
| 93 | "firmware_sample_driver:" | ||
| 94 | " request_firmware_nowait failed\n"); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | static int sample_init(void) | ||
| 99 | { | ||
| 100 | device_initialize(&ghost_device); | ||
| 101 | /* since there is no real hardware insertion I just call the | ||
| 102 | * sample probe functions here */ | ||
| 103 | sample_probe_specific(); | ||
| 104 | sample_probe_default(); | ||
| 105 | sample_probe_async(); | ||
| 106 | return 0; | ||
| 107 | } | ||
| 108 | static void __exit sample_exit(void) | ||
| 109 | { | ||
| 110 | } | ||
| 111 | |||
| 112 | module_init (sample_init); | ||
| 113 | module_exit (sample_exit); | ||
| 114 | |||
| 115 | MODULE_LICENSE("GPL"); | ||
diff --git a/samples/firmware_class/firmware_sample_firmware_class.c b/samples/firmware_class/firmware_sample_firmware_class.c new file mode 100644 index 000000000000..2799c472133e --- /dev/null +++ b/samples/firmware_class/firmware_sample_firmware_class.c | |||
| @@ -0,0 +1,207 @@ | |||
| 1 | /* | ||
| 2 | * firmware_sample_firmware_class.c - | ||
| 3 | * | ||
| 4 | * Copyright (c) 2003 Manuel Estrada Sainz | ||
| 5 | * | ||
| 6 | * NOTE: This is just a probe of concept, if you think that your driver would | ||
| 7 | * be well served by this mechanism please contact me first. | ||
| 8 | * | ||
| 9 | * DON'T USE THIS CODE AS IS | ||
| 10 | * | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/device.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/timer.h> | ||
| 17 | #include <linux/slab.h> | ||
| 18 | #include <linux/string.h> | ||
| 19 | #include <linux/firmware.h> | ||
| 20 | |||
| 21 | |||
| 22 | MODULE_AUTHOR("Manuel Estrada Sainz"); | ||
| 23 | MODULE_DESCRIPTION("Hackish sample for using firmware class directly"); | ||
| 24 | MODULE_LICENSE("GPL"); | ||
| 25 | |||
| 26 | static inline struct class_device *to_class_dev(struct kobject *obj) | ||
| 27 | { | ||
| 28 | return container_of(obj,struct class_device,kobj); | ||
| 29 | } | ||
| 30 | static inline | ||
| 31 | struct class_device_attribute *to_class_dev_attr(struct attribute *_attr) | ||
| 32 | { | ||
| 33 | return container_of(_attr,struct class_device_attribute,attr); | ||
| 34 | } | ||
| 35 | |||
| 36 | int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr); | ||
| 37 | int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr); | ||
| 38 | |||
| 39 | struct firmware_priv { | ||
| 40 | char fw_id[FIRMWARE_NAME_MAX]; | ||
| 41 | s32 loading:2; | ||
| 42 | u32 abort:1; | ||
| 43 | }; | ||
| 44 | |||
| 45 | extern struct class firmware_class; | ||
| 46 | |||
| 47 | static ssize_t firmware_loading_show(struct class_device *class_dev, char *buf) | ||
| 48 | { | ||
| 49 | struct firmware_priv *fw_priv = class_get_devdata(class_dev); | ||
| 50 | return sprintf(buf, "%d\n", fw_priv->loading); | ||
| 51 | } | ||
| 52 | static ssize_t firmware_loading_store(struct class_device *class_dev, | ||
| 53 | const char *buf, size_t count) | ||
| 54 | { | ||
| 55 | struct firmware_priv *fw_priv = class_get_devdata(class_dev); | ||
| 56 | int prev_loading = fw_priv->loading; | ||
| 57 | |||
| 58 | fw_priv->loading = simple_strtol(buf, NULL, 10); | ||
| 59 | |||
| 60 | switch(fw_priv->loading){ | ||
| 61 | case -1: | ||
| 62 | /* abort load an panic */ | ||
| 63 | break; | ||
