2121#include <linux/firmware.h>
2222#include "base.h"
2323
24+ #define to_dev (obj ) container_of(obj, struct device, kobj)
25+
2426MODULE_AUTHOR ("Manuel Estrada Sainz <ranty@debian.org>" );
2527MODULE_DESCRIPTION ("Multi purpose firmware loading support" );
2628MODULE_LICENSE ("GPL" );
@@ -86,12 +88,12 @@ firmware_timeout_store(struct class *class, const char *buf, size_t count)
8688
8789static CLASS_ATTR (timeout , 0644 , firmware_timeout_show , firmware_timeout_store ) ;
8890
89- static void fw_class_dev_release (struct class_device * class_dev );
91+ static void fw_dev_release (struct device * dev );
9092
91- static int firmware_class_uevent (struct class_device * class_dev , char * * envp ,
92- int num_envp , char * buffer , int buffer_size )
93+ static int firmware_uevent (struct device * dev , char * * envp , int num_envp ,
94+ char * buffer , int buffer_size )
9395{
94- struct firmware_priv * fw_priv = class_get_devdata ( class_dev );
96+ struct firmware_priv * fw_priv = dev_get_drvdata ( dev );
9597 int i = 0 , len = 0 ;
9698
9799 if (!test_bit (FW_STATUS_READY , & fw_priv -> status ))
@@ -110,21 +112,21 @@ static int firmware_class_uevent(struct class_device *class_dev, char **envp,
110112
111113static struct class firmware_class = {
112114 .name = "firmware" ,
113- .uevent = firmware_class_uevent ,
114- .release = fw_class_dev_release ,
115+ .dev_uevent = firmware_uevent ,
116+ .dev_release = fw_dev_release ,
115117};
116118
117- static ssize_t
118- firmware_loading_show ( struct class_device * class_dev , char * buf )
119+ static ssize_t firmware_loading_show ( struct device * dev ,
120+ struct device_attribute * attr , char * buf )
119121{
120- struct firmware_priv * fw_priv = class_get_devdata ( class_dev );
122+ struct firmware_priv * fw_priv = dev_get_drvdata ( dev );
121123 int loading = test_bit (FW_STATUS_LOADING , & fw_priv -> status );
122124 return sprintf (buf , "%d\n" , loading );
123125}
124126
125127/**
126128 * firmware_loading_store - set value in the 'loading' control file
127- * @class_dev: class_device pointer
129+ * @dev: device pointer
128130 * @buf: buffer to scan for loading control value
129131 * @count: number of bytes in @buf
130132 *
@@ -134,11 +136,11 @@ firmware_loading_show(struct class_device *class_dev, char *buf)
134136 * 0: Conclude the load and hand the data to the driver code.
135137 * -1: Conclude the load with an error and discard any written data.
136138 **/
137- static ssize_t
138- firmware_loading_store ( struct class_device * class_dev ,
139- const char * buf , size_t count )
139+ static ssize_t firmware_loading_store ( struct device * dev ,
140+ struct device_attribute * attr ,
141+ const char * buf , size_t count )
140142{
141- struct firmware_priv * fw_priv = class_get_devdata ( class_dev );
143+ struct firmware_priv * fw_priv = dev_get_drvdata ( dev );
142144 int loading = simple_strtol (buf , NULL , 10 );
143145
144146 switch (loading ) {
@@ -174,15 +176,14 @@ firmware_loading_store(struct class_device *class_dev,
174176 return count ;
175177}
176178
177- static CLASS_DEVICE_ATTR (loading , 0644 ,
178- firmware_loading_show , firmware_loading_store ) ;
179+ static DEVICE_ATTR (loading , 0644 , firmware_loading_show , firmware_loading_store ) ;
179180
180181static ssize_t
181182firmware_data_read (struct kobject * kobj ,
182183 char * buffer , loff_t offset , size_t count )
183184{
184- struct class_device * class_dev = to_class_dev (kobj );
185- struct firmware_priv * fw_priv = class_get_devdata ( class_dev );
185+ struct device * dev = to_dev (kobj );
186+ struct firmware_priv * fw_priv = dev_get_drvdata ( dev );
186187 struct firmware * fw ;
187188 ssize_t ret_count = count ;
188189
@@ -234,7 +235,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
234235
235236/**
236237 * firmware_data_write - write method for firmware
237- * @kobj: kobject for the class_device
238+ * @kobj: kobject for the device
238239 * @buffer: buffer being written
239240 * @offset: buffer offset for write in total data store area
240241 * @count: buffer size
@@ -246,8 +247,8 @@ static ssize_t
246247firmware_data_write (struct kobject * kobj ,
247248 char * buffer , loff_t offset , size_t count )
248249{
249- struct class_device * class_dev = to_class_dev (kobj );
250- struct firmware_priv * fw_priv = class_get_devdata ( class_dev );
250+ struct device * dev = to_dev (kobj );
251+ struct firmware_priv * fw_priv = dev_get_drvdata ( dev );
251252 struct firmware * fw ;
252253 ssize_t retval ;
253254
@@ -280,13 +281,12 @@ static struct bin_attribute firmware_attr_data_tmpl = {
280281 .write = firmware_data_write ,
281282};
282283
283- static void
284- fw_class_dev_release (struct class_device * class_dev )
284+ static void fw_dev_release (struct device * dev )
285285{
286- struct firmware_priv * fw_priv = class_get_devdata ( class_dev );
286+ struct firmware_priv * fw_priv = dev_get_drvdata ( dev );
287287
288288 kfree (fw_priv );
289- kfree (class_dev );
289+ kfree (dev );
290290
291291 module_put (THIS_MODULE );
292292}
@@ -298,26 +298,23 @@ firmware_class_timeout(u_long data)
298298 fw_load_abort (fw_priv );
299299}
300300
301- static inline void
302- fw_setup_class_device_id (struct class_device * class_dev , struct device * dev )
301+ static inline void fw_setup_device_id (struct device * f_dev , struct device * dev )
303302{
304303 /* XXX warning we should watch out for name collisions */
305- strlcpy (class_dev -> class_id , dev -> bus_id , BUS_ID_SIZE );
304+ strlcpy (f_dev -> bus_id , dev -> bus_id , BUS_ID_SIZE );
306305}
307306
308- static int
309- fw_register_class_device (struct class_device * * class_dev_p ,
310- const char * fw_name , struct device * device )
307+ static int fw_register_device (struct device * * dev_p , const char * fw_name ,
308+ struct device * device )
311309{
312310 int retval ;
313311 struct firmware_priv * fw_priv = kzalloc (sizeof (* fw_priv ),
314312 GFP_KERNEL );
315- struct class_device * class_dev = kzalloc (sizeof (* class_dev ),
316- GFP_KERNEL );
313+ struct device * f_dev = kzalloc (sizeof (* f_dev ), GFP_KERNEL );
317314
318- * class_dev_p = NULL ;
315+ * dev_p = NULL ;
319316
320- if (!fw_priv || !class_dev ) {
317+ if (!fw_priv || !f_dev ) {
321318 printk (KERN_ERR "%s: kmalloc failed\n" , __FUNCTION__ );
322319 retval = - ENOMEM ;
323320 goto error_kfree ;
@@ -331,55 +328,54 @@ fw_register_class_device(struct class_device **class_dev_p,
331328 fw_priv -> timeout .data = (u_long ) fw_priv ;
332329 init_timer (& fw_priv -> timeout );
333330
334- fw_setup_class_device_id ( class_dev , device );
335- class_dev -> dev = device ;
336- class_dev -> class = & firmware_class ;
337- class_set_devdata ( class_dev , fw_priv );
338- retval = class_device_register ( class_dev );
331+ fw_setup_device_id ( f_dev , device );
332+ f_dev -> parent = device ;
333+ f_dev -> class = & firmware_class ;
334+ dev_set_drvdata ( f_dev , fw_priv );
335+ retval = device_register ( f_dev );
339336 if (retval ) {
340- printk (KERN_ERR "%s: class_device_register failed\n" ,
337+ printk (KERN_ERR "%s: device_register failed\n" ,
341338 __FUNCTION__ );
342339 goto error_kfree ;
343340 }
344- * class_dev_p = class_dev ;
341+ * dev_p = f_dev ;
345342 return 0 ;
346343
347344error_kfree :
348345 kfree (fw_priv );
349- kfree (class_dev );
346+ kfree (f_dev );
350347 return retval ;
351348}
352349
353- static int
354- fw_setup_class_device ( struct firmware * fw , struct class_device * * class_dev_p ,
355- const char * fw_name , struct device * device , int uevent )
350+ static int fw_setup_device ( struct firmware * fw , struct device * * dev_p ,
351+ const char * fw_name , struct device * device ,
352+ int uevent )
356353{
357- struct class_device * class_dev ;
354+ struct device * f_dev ;
358355 struct firmware_priv * fw_priv ;
359356 int retval ;
360357
361- * class_dev_p = NULL ;
362- retval = fw_register_class_device ( & class_dev , fw_name , device );
358+ * dev_p = NULL ;
359+ retval = fw_register_device ( & f_dev , fw_name , device );
363360 if (retval )
364361 goto out ;
365362
366363 /* Need to pin this module until class device is destroyed */
367364 __module_get (THIS_MODULE );
368365
369- fw_priv = class_get_devdata ( class_dev );
366+ fw_priv = dev_get_drvdata ( f_dev );
370367
371368 fw_priv -> fw = fw ;
372- retval = sysfs_create_bin_file (& class_dev -> kobj , & fw_priv -> attr_data );
369+ retval = sysfs_create_bin_file (& f_dev -> kobj , & fw_priv -> attr_data );
373370 if (retval ) {
374371 printk (KERN_ERR "%s: sysfs_create_bin_file failed\n" ,
375372 __FUNCTION__ );
376373 goto error_unreg ;
377374 }
378375
379- retval = class_device_create_file (class_dev ,
380- & class_device_attr_loading );
376+ retval = device_create_file (f_dev , & dev_attr_loading );
381377 if (retval ) {
382- printk (KERN_ERR "%s: class_device_create_file failed\n" ,
378+ printk (KERN_ERR "%s: device_create_file failed\n" ,
383379 __FUNCTION__ );
384380 goto error_unreg ;
385381 }
@@ -388,11 +384,11 @@ fw_setup_class_device(struct firmware *fw, struct class_device **class_dev_p,
388384 set_bit (FW_STATUS_READY , & fw_priv -> status );
389385 else
390386 set_bit (FW_STATUS_READY_NOHOTPLUG , & fw_priv -> status );
391- * class_dev_p = class_dev ;
387+ * dev_p = f_dev ;
392388 goto out ;
393389
394390error_unreg :
395- class_device_unregister ( class_dev );
391+ device_unregister ( f_dev );
396392out :
397393 return retval ;
398394}
@@ -401,7 +397,7 @@ static int
401397_request_firmware (const struct firmware * * firmware_p , const char * name ,
402398 struct device * device , int uevent )
403399{
404- struct class_device * class_dev ;
400+ struct device * f_dev ;
405401 struct firmware_priv * fw_priv ;
406402 struct firmware * firmware ;
407403 int retval ;
@@ -417,20 +413,19 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
417413 goto out ;
418414 }
419415
420- retval = fw_setup_class_device (firmware , & class_dev , name , device ,
421- uevent );
416+ retval = fw_setup_device (firmware , & f_dev , name , device , uevent );
422417 if (retval )
423418 goto error_kfree_fw ;
424419
425- fw_priv = class_get_devdata ( class_dev );
420+ fw_priv = dev_get_drvdata ( f_dev );
426421
427422 if (uevent ) {
428423 if (loading_timeout > 0 ) {
429424 fw_priv -> timeout .expires = jiffies + loading_timeout * HZ ;
430425 add_timer (& fw_priv -> timeout );
431426 }
432427
433- kobject_uevent (& class_dev -> kobj , KOBJ_ADD );
428+ kobject_uevent (& f_dev -> kobj , KOBJ_ADD );
434429 wait_for_completion (& fw_priv -> completion );
435430 set_bit (FW_STATUS_DONE , & fw_priv -> status );
436431 del_timer_sync (& fw_priv -> timeout );
@@ -445,7 +440,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
445440 }
446441 fw_priv -> fw = NULL ;
447442 mutex_unlock (& fw_lock );
448- class_device_unregister ( class_dev );
443+ device_unregister ( f_dev );
449444 goto out ;
450445
451446error_kfree_fw :
0 commit comments