aboutsummaryrefslogtreecommitdiffstats
path: root/samples/firmware_class
diff options
context:
space:
mode:
Diffstat (limited to 'samples/firmware_class')
-rw-r--r--samples/firmware_class/firmware_sample_driver.c45
-rw-r--r--samples/firmware_class/firmware_sample_firmware_class.c33
2 files changed, 40 insertions, 38 deletions
diff --git a/samples/firmware_class/firmware_sample_driver.c b/samples/firmware_class/firmware_sample_driver.c
index ff0f2f2bd1a8..165cff98032e 100644
--- a/samples/firmware_class/firmware_sample_driver.c
+++ b/samples/firmware_class/firmware_sample_driver.c
@@ -12,8 +12,7 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/string.h> 14#include <linux/string.h>
15 15#include <linux/firmware.h>
16#include "linux/firmware.h"
17 16
18static struct device ghost_device = { 17static struct device ghost_device = {
19 .bus_id = "ghost0", 18 .bus_id = "ghost0",
@@ -31,11 +30,14 @@ static void sample_firmware_load(char *firmware, int size)
31static void sample_probe_default(void) 30static void sample_probe_default(void)
32{ 31{
33 /* uses the default method to get the firmware */ 32 /* uses the default method to get the firmware */
34 const struct firmware *fw_entry; 33 const struct firmware *fw_entry;
35 printk(KERN_INFO "firmware_sample_driver: a ghost device got inserted :)\n"); 34 int retval;
35
36 printk(KERN_INFO "firmware_sample_driver: "
37 "a ghost device got inserted :)\n");
36 38
37 if(request_firmware(&fw_entry, "sample_driver_fw", &ghost_device)!=0) 39 retval = request_firmware(&fw_entry, "sample_driver_fw", &ghost_device);
38 { 40 if (retval) {
39 printk(KERN_ERR 41 printk(KERN_ERR
40 "firmware_sample_driver: Firmware not available\n"); 42 "firmware_sample_driver: Firmware not available\n");
41 return; 43 return;
@@ -47,17 +49,20 @@ static void sample_probe_default(void)
47 49
48 /* finish setting up the device */ 50 /* finish setting up the device */
49} 51}
52
50static void sample_probe_specific(void) 53static void sample_probe_specific(void)
51{ 54{
55 int retval;
52 /* Uses some specific hotplug support to get the firmware from 56 /* Uses some specific hotplug support to get the firmware from
53 * userspace directly into the hardware, or via some sysfs file */ 57 * userspace directly into the hardware, or via some sysfs file */
54 58
55 /* NOTE: This currently doesn't work */ 59 /* NOTE: This currently doesn't work */
56 60
57 printk(KERN_INFO "firmware_sample_driver: a ghost device got inserted :)\n"); 61 printk(KERN_INFO "firmware_sample_driver: "
62 "a ghost device got inserted :)\n");
58 63
59 if(request_firmware(NULL, "sample_driver_fw", &ghost_device)!=0) 64 retval = request_firmware(NULL, "sample_driver_fw", &ghost_device);
60 { 65 if (retval) {
61 printk(KERN_ERR 66 printk(KERN_ERR
62 "firmware_sample_driver: Firmware load failed\n"); 67 "firmware_sample_driver: Firmware load failed\n");
63 return; 68 return;
@@ -70,7 +75,7 @@ static void sample_probe_specific(void)
70} 75}
71static void sample_probe_async_cont(const struct firmware *fw, void *context) 76static void sample_probe_async_cont(const struct firmware *fw, void *context)
72{ 77{
73 if(!fw){ 78 if (!fw) {
74 printk(KERN_ERR 79 printk(KERN_ERR
75 "firmware_sample_driver: firmware load failed\n"); 80 "firmware_sample_driver: firmware load failed\n");
76 return; 81 return;
@@ -80,19 +85,18 @@ static void sample_probe_async_cont(const struct firmware *fw, void *context)
80 (char *)context); 85 (char *)context);
81 sample_firmware_load(fw->data, fw->size); 86 sample_firmware_load(fw->data, fw->size);
82} 87}
88
83static void sample_probe_async(void) 89static void sample_probe_async(void)
84{ 90{
85 /* Let's say that I can't sleep */ 91 /* Let's say that I can't sleep */
86 int error; 92 int error;
87 error = request_firmware_nowait (THIS_MODULE, FW_ACTION_NOHOTPLUG, 93 error = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
88 "sample_driver_fw", &ghost_device, 94 "sample_driver_fw", &ghost_device,
89 "my device pointer", 95 "my device pointer",
90 sample_probe_async_cont); 96 sample_probe_async_cont);
91 if(error){ 97 if (error)
92 printk(KERN_ERR 98 printk(KERN_ERR "firmware_sample_driver:"
93 "firmware_sample_driver:"
94 " request_firmware_nowait failed\n"); 99 " request_firmware_nowait failed\n");
95 }
96} 100}
97 101
98static int sample_init(void) 102static int sample_init(void)
@@ -105,11 +109,12 @@ static int sample_init(void)
105 sample_probe_async(); 109 sample_probe_async();
106 return 0; 110 return 0;
107} 111}
112
108static void __exit sample_exit(void) 113static void __exit sample_exit(void)
109{ 114{
110} 115}
111 116
112module_init (sample_init); 117module_init(sample_init);
113module_exit (sample_exit); 118module_exit(sample_exit);
114 119
115MODULE_LICENSE("GPL"); 120MODULE_LICENSE("GPL");
diff --git a/samples/firmware_class/firmware_sample_firmware_class.c b/samples/firmware_class/firmware_sample_firmware_class.c
index 2799c472133e..9392116e47b0 100644
--- a/samples/firmware_class/firmware_sample_firmware_class.c
+++ b/samples/firmware_class/firmware_sample_firmware_class.c
@@ -25,30 +25,27 @@ MODULE_LICENSE("GPL");
25 25
26static inline struct class_device *to_class_dev(struct kobject *obj) 26static inline struct class_device *to_class_dev(struct kobject *obj)
27{ 27{
28 return container_of(obj,struct class_device,kobj); 28 return container_of(obj, struct class_device, kobj);
29} 29}
30
30static inline 31static inline
31struct class_device_attribute *to_class_dev_attr(struct attribute *_attr) 32struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
32{ 33{
33 return container_of(_attr,struct class_device_attribute,attr); 34 return container_of(_attr, struct class_device_attribute, attr);
34} 35}
35 36
36int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr);
37int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr);
38
39struct firmware_priv { 37struct firmware_priv {
40 char fw_id[FIRMWARE_NAME_MAX]; 38 char fw_id[FIRMWARE_NAME_MAX];
41 s32 loading:2; 39 s32 loading:2;
42 u32 abort:1; 40 u32 abort:1;
43}; 41};
44 42
45extern struct class firmware_class;
46
47static ssize_t firmware_loading_show(struct class_device *class_dev, char *buf) 43static ssize_t firmware_loading_show(struct class_device *class_dev, char *buf)
48{ 44{
49 struct firmware_priv *fw_priv = class_get_devdata(class_dev); 45 struct firmware_priv *fw_priv = class_get_devdata(class_dev);
50 return sprintf(buf, "%d\n", fw_priv->loading); 46 return sprintf(buf, "%d\n", fw_priv->loading);
51} 47}
48
52static ssize_t firmware_loading_store(struct class_device *class_dev, 49static ssize_t firmware_loading_store(struct class_device *class_dev,
53 const char *buf, size_t count) 50 const char *buf, size_t count)
54{ 51{
@@ -57,7 +54,7 @@ static ssize_t firmware_loading_store(struct class_device *class_dev,
57 54
58 fw_priv->loading = simple_strtol(buf, NULL, 10); 55 fw_priv->loading = simple_strtol(buf, NULL, 10);
59 56
60 switch(fw_priv->loading){ 57 switch (fw_priv->loading) {
61 case -1: 58 case -1:
62 /* abort load an panic */ 59 /* abort load an panic */
63 break; 60 break;
@@ -65,7 +62,7 @@ static ssize_t firmware_loading_store(struct class_device *class_dev,
65 /* setup load */ 62 /* setup load */
66 break; 63 break;
67 case 0: 64 case 0:
68 if(prev_loading==1){ 65 if (prev_loading == 1) {
69 /* finish load and get the device back to working 66 /* finish load and get the device back to working
70 * state */ 67 * state */
71 } 68 }
@@ -130,24 +127,24 @@ static int fw_setup_class_device(struct class_device *class_dev,
130 class_dev->class = &firmware_class, 127 class_dev->class = &firmware_class,
131 class_set_devdata(class_dev, fw_priv); 128 class_set_devdata(class_dev, fw_priv);
132 retval = class_device_register(class_dev); 129 retval = class_device_register(class_dev);
133 if (retval){ 130 if (retval) {
134 printk(KERN_ERR "%s: class_device_register failed\n", 131 printk(KERN_ERR "%s: class_device_register failed\n",
135 __FUNCTION__); 132 __func__);
136 goto error_free_fw_priv; 133 goto error_free_fw_priv;
137 } 134 }
138 135
139 retval = sysfs_create_bin_file(&class_dev->kobj, &firmware_attr_data); 136 retval = sysfs_create_bin_file(&class_dev->kobj, &firmware_attr_data);
140 if (retval){ 137 if (retval) {
141 printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", 138 printk(KERN_ERR "%s: sysfs_create_bin_file failed\n",
142 __FUNCTION__); 139 __func__);
143 goto error_unreg_class_dev; 140 goto error_unreg_class_dev;
144 } 141 }
145 142
146 retval = class_device_create_file(class_dev, 143 retval = class_device_create_file(class_dev,
147 &class_device_attr_loading); 144 &class_device_attr_loading);
148 if (retval){ 145 if (retval) {
149 printk(KERN_ERR "%s: class_device_create_file failed\n", 146 printk(KERN_ERR "%s: class_device_create_file failed\n",
150 __FUNCTION__); 147 __func__);
151 goto error_remove_data; 148 goto error_remove_data;
152 } 149 }
153 150
@@ -183,16 +180,16 @@ static int __init firmware_sample_init(void)
183 180
184 device_initialize(&my_device); 181 device_initialize(&my_device);
185 class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL); 182 class_dev = kmalloc(sizeof(struct class_device), GFP_KERNEL);
186 if(!class_dev) 183 if (!class_dev)
187 return -ENOMEM; 184 return -ENOMEM;
188 185
189 error = fw_setup_class_device(class_dev, "my_firmware_image", 186 error = fw_setup_class_device(class_dev, "my_firmware_image",
190 &my_device); 187 &my_device);
191 if(error){ 188 if (error) {
192 kfree(class_dev); 189 kfree(class_dev);
193 return error; 190 return error;
194 } 191 }
195 return 0; 192 return 0;
196 193
197} 194}
198static void __exit firmware_sample_exit(void) 195static void __exit firmware_sample_exit(void)