1919 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
2020 */
2121
22- #include <linux/init.h>
2322#include <linux/io.h>
2423#include <linux/iommu.h>
2524#include <linux/list.h>
2625#include <linux/moduleparam.h>
27- #include <linux/of_device .h>
26+ #include <linux/platform_device .h>
2827#include <linux/slab.h>
2928#include <linux/spinlock.h>
3029#include <linux/vmalloc.h>
3130
31+ #include <soc/tegra/mc.h>
32+
3233/* bitmap of the page sizes currently supported */
3334#define GART_IOMMU_PGSIZES (SZ_4K)
3435
@@ -397,9 +398,8 @@ static const struct iommu_ops gart_iommu_ops = {
397398 .iotlb_sync = gart_iommu_sync ,
398399};
399400
400- static int tegra_gart_suspend (struct device * dev )
401+ int tegra_gart_suspend (struct gart_device * gart )
401402{
402- struct gart_device * gart = dev_get_drvdata (dev );
403403 unsigned long iova ;
404404 u32 * data = gart -> savedata ;
405405 unsigned long flags ;
@@ -411,9 +411,8 @@ static int tegra_gart_suspend(struct device *dev)
411411 return 0 ;
412412}
413413
414- static int tegra_gart_resume (struct device * dev )
414+ int tegra_gart_resume (struct gart_device * gart )
415415{
416- struct gart_device * gart = dev_get_drvdata (dev );
417416 unsigned long flags ;
418417
419418 spin_lock_irqsave (& gart -> pte_lock , flags );
@@ -422,41 +421,33 @@ static int tegra_gart_resume(struct device *dev)
422421 return 0 ;
423422}
424423
425- static int tegra_gart_probe (struct platform_device * pdev )
424+ struct gart_device * tegra_gart_probe (struct device * dev , struct tegra_mc * mc )
426425{
427426 struct gart_device * gart ;
428- struct resource * res , * res_remap ;
427+ struct resource * res_remap ;
429428 void __iomem * gart_regs ;
430- struct device * dev = & pdev -> dev ;
431429 int ret ;
432430
433431 BUILD_BUG_ON (PAGE_SHIFT != GART_PAGE_SHIFT );
434432
435433 /* the GART memory aperture is required */
436- res = platform_get_resource (pdev , IORESOURCE_MEM , 0 );
437- res_remap = platform_get_resource ( pdev , IORESOURCE_MEM , 1 );
438- if (!res || ! res_remap ) {
434+ res_remap = platform_get_resource (to_platform_device ( dev ),
435+ IORESOURCE_MEM , 1 );
436+ if (!res_remap ) {
439437 dev_err (dev , "GART memory aperture expected\n" );
440- return - ENXIO ;
438+ return ERR_PTR ( - ENXIO ) ;
441439 }
442440
443441 gart = devm_kzalloc (dev , sizeof (* gart ), GFP_KERNEL );
444442 if (!gart ) {
445443 dev_err (dev , "failed to allocate gart_device\n" );
446- return - ENOMEM ;
447- }
448-
449- gart_regs = devm_ioremap (dev , res -> start , resource_size (res ));
450- if (!gart_regs ) {
451- dev_err (dev , "failed to remap GART registers\n" );
452- return - ENXIO ;
444+ return ERR_PTR (- ENOMEM );
453445 }
454446
455- ret = iommu_device_sysfs_add (& gart -> iommu , & pdev -> dev , NULL ,
456- dev_name (& pdev -> dev ));
447+ ret = iommu_device_sysfs_add (& gart -> iommu , dev , NULL , "gart" );
457448 if (ret ) {
458449 dev_err (dev , "Failed to register IOMMU in sysfs\n" );
459- return ret ;
450+ return ERR_PTR ( ret ) ;
460451 }
461452
462453 iommu_device_set_ops (& gart -> iommu , & gart_iommu_ops );
@@ -468,7 +459,8 @@ static int tegra_gart_probe(struct platform_device *pdev)
468459 goto remove_sysfs ;
469460 }
470461
471- gart -> dev = & pdev -> dev ;
462+ gart -> dev = dev ;
463+ gart_regs = mc -> regs + GART_REG_BASE ;
472464 spin_lock_init (& gart -> pte_lock );
473465 spin_lock_init (& gart -> client_lock );
474466 INIT_LIST_HEAD (& gart -> client );
@@ -483,46 +475,19 @@ static int tegra_gart_probe(struct platform_device *pdev)
483475 goto unregister_iommu ;
484476 }
485477
486- platform_set_drvdata (pdev , gart );
487478 do_gart_setup (gart , NULL );
488479
489480 gart_handle = gart ;
490481
491- return 0 ;
482+ return gart ;
492483
493484unregister_iommu :
494485 iommu_device_unregister (& gart -> iommu );
495486remove_sysfs :
496487 iommu_device_sysfs_remove (& gart -> iommu );
497488
498- return ret ;
499- }
500-
501- static const struct dev_pm_ops tegra_gart_pm_ops = {
502- .suspend = tegra_gart_suspend ,
503- .resume = tegra_gart_resume ,
504- };
505-
506- static const struct of_device_id tegra_gart_of_match [] = {
507- { .compatible = "nvidia,tegra20-gart" , },
508- { },
509- };
510-
511- static struct platform_driver tegra_gart_driver = {
512- .probe = tegra_gart_probe ,
513- .driver = {
514- .name = "tegra-gart" ,
515- .pm = & tegra_gart_pm_ops ,
516- .of_match_table = tegra_gart_of_match ,
517- .suppress_bind_attrs = true,
518- },
519- };
520-
521- static int __init tegra_gart_init (void )
522- {
523- return platform_driver_register (& tegra_gart_driver );
489+ return ERR_PTR (ret );
524490}
525- subsys_initcall (tegra_gart_init );
526491
527492module_param (gart_debug , bool , 0644 );
528493MODULE_PARM_DESC (gart_debug , "Enable GART debugging" );
0 commit comments