Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

amba: Make use of bus_type functions

Instead of assigning the needed functions for each driver separately do it
only once in amba_bustype. Move the definition of the functions to their
proper place among the other callbacks used there. Note that the bus's
shutdown function might be called for unbound devices, too, so it needs
additional guarding.

This prepares getting rid of these callbacks in struct device_driver.

Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20210126165835.687514-6-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
f170b59f 3fd269e7

+85 -81
+85 -81
drivers/amba/bus.c
··· 174 174 return retval; 175 175 } 176 176 177 - #ifdef CONFIG_PM 178 - /* 179 - * Hooks to provide runtime PM of the pclk (bus clock). It is safe to 180 - * enable/disable the bus clock at runtime PM suspend/resume as this 181 - * does not result in loss of context. 182 - */ 183 - static int amba_pm_runtime_suspend(struct device *dev) 184 - { 185 - struct amba_device *pcdev = to_amba_device(dev); 186 - int ret = pm_generic_runtime_suspend(dev); 187 - 188 - if (ret == 0 && dev->driver) { 189 - if (pm_runtime_is_irq_safe(dev)) 190 - clk_disable(pcdev->pclk); 191 - else 192 - clk_disable_unprepare(pcdev->pclk); 193 - } 194 - 195 - return ret; 196 - } 197 - 198 - static int amba_pm_runtime_resume(struct device *dev) 199 - { 200 - struct amba_device *pcdev = to_amba_device(dev); 201 - int ret; 202 - 203 - if (dev->driver) { 204 - if (pm_runtime_is_irq_safe(dev)) 205 - ret = clk_enable(pcdev->pclk); 206 - else 207 - ret = clk_prepare_enable(pcdev->pclk); 208 - /* Failure is probably fatal to the system, but... */ 209 - if (ret) 210 - return ret; 211 - } 212 - 213 - return pm_generic_runtime_resume(dev); 214 - } 215 - #endif /* CONFIG_PM */ 216 - 217 - static const struct dev_pm_ops amba_pm = { 218 - .suspend = pm_generic_suspend, 219 - .resume = pm_generic_resume, 220 - .freeze = pm_generic_freeze, 221 - .thaw = pm_generic_thaw, 222 - .poweroff = pm_generic_poweroff, 223 - .restore = pm_generic_restore, 224 - SET_RUNTIME_PM_OPS( 225 - amba_pm_runtime_suspend, 226 - amba_pm_runtime_resume, 227 - NULL 228 - ) 229 - }; 230 - 231 - /* 232 - * Primecells are part of the Advanced Microcontroller Bus Architecture, 233 - * so we call the bus "amba". 234 - * DMA configuration for platform and AMBA bus is same. So here we reuse 235 - * platform's DMA config routine. 236 - */ 237 - struct bus_type amba_bustype = { 238 - .name = "amba", 239 - .dev_groups = amba_dev_groups, 240 - .match = amba_match, 241 - .uevent = amba_uevent, 242 - .dma_configure = platform_dma_configure, 243 - .pm = &amba_pm, 244 - }; 245 - EXPORT_SYMBOL_GPL(amba_bustype); 246 - 247 - static int __init amba_init(void) 248 - { 249 - return bus_register(&amba_bustype); 250 - } 251 - 252 - postcore_initcall(amba_init); 253 - 254 177 /* 255 178 * These are the device model conversion veneers; they convert the 256 179 * device model structures to our more specific structures. ··· 242 319 243 320 static void amba_shutdown(struct device *dev) 244 321 { 245 - struct amba_driver *drv = to_amba_driver(dev->driver); 322 + struct amba_driver *drv; 246 323 324 + if (!dev->driver) 325 + return; 326 + 327 + drv = to_amba_driver(dev->driver); 247 328 if (drv->shutdown) 248 329 drv->shutdown(to_amba_device(dev)); 249 330 } 331 + 332 + #ifdef CONFIG_PM 333 + /* 334 + * Hooks to provide runtime PM of the pclk (bus clock). It is safe to 335 + * enable/disable the bus clock at runtime PM suspend/resume as this 336 + * does not result in loss of context. 337 + */ 338 + static int amba_pm_runtime_suspend(struct device *dev) 339 + { 340 + struct amba_device *pcdev = to_amba_device(dev); 341 + int ret = pm_generic_runtime_suspend(dev); 342 + 343 + if (ret == 0 && dev->driver) { 344 + if (pm_runtime_is_irq_safe(dev)) 345 + clk_disable(pcdev->pclk); 346 + else 347 + clk_disable_unprepare(pcdev->pclk); 348 + } 349 + 350 + return ret; 351 + } 352 + 353 + static int amba_pm_runtime_resume(struct device *dev) 354 + { 355 + struct amba_device *pcdev = to_amba_device(dev); 356 + int ret; 357 + 358 + if (dev->driver) { 359 + if (pm_runtime_is_irq_safe(dev)) 360 + ret = clk_enable(pcdev->pclk); 361 + else 362 + ret = clk_prepare_enable(pcdev->pclk); 363 + /* Failure is probably fatal to the system, but... */ 364 + if (ret) 365 + return ret; 366 + } 367 + 368 + return pm_generic_runtime_resume(dev); 369 + } 370 + #endif /* CONFIG_PM */ 371 + 372 + static const struct dev_pm_ops amba_pm = { 373 + .suspend = pm_generic_suspend, 374 + .resume = pm_generic_resume, 375 + .freeze = pm_generic_freeze, 376 + .thaw = pm_generic_thaw, 377 + .poweroff = pm_generic_poweroff, 378 + .restore = pm_generic_restore, 379 + SET_RUNTIME_PM_OPS( 380 + amba_pm_runtime_suspend, 381 + amba_pm_runtime_resume, 382 + NULL 383 + ) 384 + }; 385 + 386 + /* 387 + * Primecells are part of the Advanced Microcontroller Bus Architecture, 388 + * so we call the bus "amba". 389 + * DMA configuration for platform and AMBA bus is same. So here we reuse 390 + * platform's DMA config routine. 391 + */ 392 + struct bus_type amba_bustype = { 393 + .name = "amba", 394 + .dev_groups = amba_dev_groups, 395 + .match = amba_match, 396 + .uevent = amba_uevent, 397 + .probe = amba_probe, 398 + .remove = amba_remove, 399 + .shutdown = amba_shutdown, 400 + .dma_configure = platform_dma_configure, 401 + .pm = &amba_pm, 402 + }; 403 + EXPORT_SYMBOL_GPL(amba_bustype); 404 + 405 + static int __init amba_init(void) 406 + { 407 + return bus_register(&amba_bustype); 408 + } 409 + 410 + postcore_initcall(amba_init); 250 411 251 412 /** 252 413 * amba_driver_register - register an AMBA device driver ··· 346 339 return -EINVAL; 347 340 348 341 drv->drv.bus = &amba_bustype; 349 - drv->drv.probe = amba_probe; 350 - drv->drv.remove = amba_remove; 351 - drv->drv.shutdown = amba_shutdown; 352 342 353 343 return driver_register(&drv->drv); 354 344 }