@@ -72,13 +72,14 @@ static void host1x_subdev_del(struct host1x_subdev *subdev)
7272/**
7373 * host1x_device_parse_dt() - scan device tree and add matching subdevices
7474 */
75- static int host1x_device_parse_dt (struct host1x_device * device )
75+ static int host1x_device_parse_dt (struct host1x_device * device ,
76+ struct host1x_driver * driver )
7677{
7778 struct device_node * np ;
7879 int err ;
7980
8081 for_each_child_of_node (device -> dev .parent -> of_node , np ) {
81- if (of_match_node (device -> driver -> subdevs , np ) &&
82+ if (of_match_node (driver -> subdevs , np ) &&
8283 of_device_is_available (np )) {
8384 err = host1x_subdev_add (device , np );
8485 if (err < 0 )
@@ -109,36 +110,29 @@ static void host1x_subdev_register(struct host1x_device *device,
109110 mutex_unlock (& device -> clients_lock );
110111 mutex_unlock (& device -> subdevs_lock );
111112
112- /*
113- * When all subdevices have been registered, the composite device is
114- * ready to be probed.
115- */
116113 if (list_empty (& device -> subdevs )) {
117- err = device -> driver -> probe ( device );
114+ err = device_add ( & device -> dev );
118115 if (err < 0 )
119- dev_err (& device -> dev , "probe failed for %ps: %d\n" ,
120- device -> driver , err );
116+ dev_err (& device -> dev , "failed to add: %d\n" , err );
121117 else
122- device -> bound = true;
118+ device -> registered = true;
123119 }
124120}
125121
126122static void __host1x_subdev_unregister (struct host1x_device * device ,
127123 struct host1x_subdev * subdev )
128124{
129125 struct host1x_client * client = subdev -> client ;
130- int err ;
131126
132127 /*
133128 * If all subdevices have been activated, we're about to remove the
134129 * first active subdevice, so unload the driver first.
135130 */
136- if (list_empty (& device -> subdevs ) && device -> bound ) {
137- err = device -> driver -> remove (device );
138- if (err < 0 )
139- dev_err (& device -> dev , "remove failed: %d\n" , err );
140-
141- device -> bound = false;
131+ if (list_empty (& device -> subdevs )) {
132+ if (device -> registered ) {
133+ device -> registered = false;
134+ device_del (& device -> dev );
135+ }
142136 }
143137
144138 /*
@@ -265,20 +259,60 @@ static int host1x_del_client(struct host1x *host1x,
265259 return - ENODEV ;
266260}
267261
268- static struct bus_type host1x_bus_type = {
269- .name = "host1x" ,
270- };
262+ static int host1x_device_match (struct device * dev , struct device_driver * drv )
263+ {
264+ return strcmp (dev_name (dev ), drv -> name ) == 0 ;
265+ }
271266
272- int host1x_bus_init ( void )
267+ static int host1x_device_probe ( struct device * dev )
273268{
274- return bus_register (& host1x_bus_type );
269+ struct host1x_driver * driver = to_host1x_driver (dev -> driver );
270+ struct host1x_device * device = to_host1x_device (dev );
271+
272+ if (driver -> probe )
273+ return driver -> probe (device );
274+
275+ return 0 ;
275276}
276277
277- void host1x_bus_exit ( void )
278+ static int host1x_device_remove ( struct device * dev )
278279{
279- bus_unregister (& host1x_bus_type );
280+ struct host1x_driver * driver = to_host1x_driver (dev -> driver );
281+ struct host1x_device * device = to_host1x_device (dev );
282+
283+ if (driver -> remove )
284+ return driver -> remove (device );
285+
286+ return 0 ;
280287}
281288
289+ static void host1x_device_shutdown (struct device * dev )
290+ {
291+ struct host1x_driver * driver = to_host1x_driver (dev -> driver );
292+ struct host1x_device * device = to_host1x_device (dev );
293+
294+ if (driver -> shutdown )
295+ driver -> shutdown (device );
296+ }
297+
298+ static const struct dev_pm_ops host1x_device_pm_ops = {
299+ .suspend = pm_generic_suspend ,
300+ .resume = pm_generic_resume ,
301+ .freeze = pm_generic_freeze ,
302+ .thaw = pm_generic_thaw ,
303+ .poweroff = pm_generic_poweroff ,
304+ .restore = pm_generic_restore ,
305+ };
306+
307+ struct bus_type host1x_bus_type = {
308+ .name = "host1x" ,
309+ .match = host1x_device_match ,
310+ .probe = host1x_device_probe ,
311+ .remove = host1x_device_remove ,
312+ .shutdown = host1x_device_shutdown ,
313+ .pm = & host1x_device_pm_ops ,
314+ };
315+
282316static void __host1x_device_del (struct host1x_device * device )
283317{
284318 struct host1x_subdev * subdev , * sd ;
@@ -347,6 +381,8 @@ static int host1x_device_add(struct host1x *host1x,
347381 if (!device )
348382 return - ENOMEM ;
349383
384+ device_initialize (& device -> dev );
385+
350386 mutex_init (& device -> subdevs_lock );
351387 INIT_LIST_HEAD (& device -> subdevs );
352388 INIT_LIST_HEAD (& device -> active );
@@ -357,18 +393,14 @@ static int host1x_device_add(struct host1x *host1x,
357393
358394 device -> dev .coherent_dma_mask = host1x -> dev -> coherent_dma_mask ;
359395 device -> dev .dma_mask = & device -> dev .coherent_dma_mask ;
396+ dev_set_name (& device -> dev , "%s" , driver -> driver .name );
360397 device -> dev .release = host1x_device_release ;
361- dev_set_name (& device -> dev , "%s" , driver -> name );
362398 device -> dev .bus = & host1x_bus_type ;
363399 device -> dev .parent = host1x -> dev ;
364400
365- err = device_register (& device -> dev );
366- if (err < 0 )
367- return err ;
368-
369- err = host1x_device_parse_dt (device );
401+ err = host1x_device_parse_dt (device , driver );
370402 if (err < 0 ) {
371- device_unregister ( & device -> dev );
403+ kfree ( device );
372404 return err ;
373405 }
374406
@@ -399,7 +431,12 @@ static int host1x_device_add(struct host1x *host1x,
399431static void host1x_device_del (struct host1x * host1x ,
400432 struct host1x_device * device )
401433{
402- device_unregister (& device -> dev );
434+ if (device -> registered ) {
435+ device -> registered = false;
436+ device_del (& device -> dev );
437+ }
438+
439+ put_device (& device -> dev );
403440}
404441
405442static void host1x_attach_driver (struct host1x * host1x ,
@@ -474,7 +511,8 @@ int host1x_unregister(struct host1x *host1x)
474511 return 0 ;
475512}
476513
477- int host1x_driver_register (struct host1x_driver * driver )
514+ int host1x_driver_register_full (struct host1x_driver * driver ,
515+ struct module * owner )
478516{
479517 struct host1x * host1x ;
480518
@@ -491,9 +529,12 @@ int host1x_driver_register(struct host1x_driver *driver)
491529
492530 mutex_unlock (& devices_lock );
493531
494- return 0 ;
532+ driver -> driver .bus = & host1x_bus_type ;
533+ driver -> driver .owner = owner ;
534+
535+ return driver_register (& driver -> driver );
495536}
496- EXPORT_SYMBOL (host1x_driver_register );
537+ EXPORT_SYMBOL (host1x_driver_register_full );
497538
498539void host1x_driver_unregister (struct host1x_driver * driver )
499540{
0 commit comments