| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * pxa3xx-gcu.c - Linux kernel module for PXA3xx graphics controllers |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 7 | 8 | * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de> |
|---|
| 8 | 9 | * Copyright (c) 2009 Janine Kropp <nin@directfb.org> |
|---|
| 9 | 10 | * Copyright (c) 2009 Denis Oliver Kropp <dok@directfb.org> |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 12 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 13 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 14 | | - * (at your option) any later version. |
|---|
| 15 | | - * |
|---|
| 16 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 17 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | | - * GNU General Public License for more details. |
|---|
| 20 | | - * |
|---|
| 21 | | - * You should have received a copy of the GNU General Public License |
|---|
| 22 | | - * along with this program; if not, write to the Free Software |
|---|
| 23 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 24 | 11 | */ |
|---|
| 25 | 12 | |
|---|
| 26 | 13 | /* |
|---|
| .. | .. |
|---|
| 49 | 36 | #include "pxa3xx-gcu.h" |
|---|
| 50 | 37 | |
|---|
| 51 | 38 | #define DRV_NAME "pxa3xx-gcu" |
|---|
| 52 | | -#define MISCDEV_MINOR 197 |
|---|
| 53 | 39 | |
|---|
| 54 | 40 | #define REG_GCCR 0x00 |
|---|
| 55 | 41 | #define GCCR_SYNC_CLR (1 << 9) |
|---|
| .. | .. |
|---|
| 96 | 82 | }; |
|---|
| 97 | 83 | |
|---|
| 98 | 84 | struct pxa3xx_gcu_priv { |
|---|
| 85 | + struct device *dev; |
|---|
| 99 | 86 | void __iomem *mmio_base; |
|---|
| 100 | 87 | struct clk *clk; |
|---|
| 101 | 88 | struct pxa3xx_gcu_shared *shared; |
|---|
| .. | .. |
|---|
| 394 | 381 | struct pxa3xx_gcu_batch *buffer; |
|---|
| 395 | 382 | struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file); |
|---|
| 396 | 383 | |
|---|
| 397 | | - int words = count / 4; |
|---|
| 384 | + size_t words = count / 4; |
|---|
| 398 | 385 | |
|---|
| 399 | 386 | /* Does not need to be atomic. There's a lock in user space, |
|---|
| 400 | 387 | * but anyhow, this is just for statistics. */ |
|---|
| .. | .. |
|---|
| 493 | 480 | if (size != SHARED_SIZE) |
|---|
| 494 | 481 | return -EINVAL; |
|---|
| 495 | 482 | |
|---|
| 496 | | - return dma_mmap_coherent(NULL, vma, |
|---|
| 483 | + return dma_mmap_coherent(priv->dev, vma, |
|---|
| 497 | 484 | priv->shared, priv->shared_phys, size); |
|---|
| 498 | 485 | |
|---|
| 499 | 486 | case SHARED_SIZE >> PAGE_SHIFT: |
|---|
| .. | .. |
|---|
| 607 | 594 | * container_of(). This isn't really necessary as we have a fixed minor |
|---|
| 608 | 595 | * number anyway, but this is to avoid statics. */ |
|---|
| 609 | 596 | |
|---|
| 610 | | - priv->misc_dev.minor = MISCDEV_MINOR, |
|---|
| 597 | + priv->misc_dev.minor = PXA3XX_GCU_MINOR, |
|---|
| 611 | 598 | priv->misc_dev.name = DRV_NAME, |
|---|
| 612 | 599 | priv->misc_dev.fops = &pxa3xx_gcu_miscdev_fops; |
|---|
| 613 | 600 | |
|---|
| .. | .. |
|---|
| 650 | 637 | ret = misc_register(&priv->misc_dev); |
|---|
| 651 | 638 | if (ret < 0) { |
|---|
| 652 | 639 | dev_err(dev, "misc_register() for minor %d failed\n", |
|---|
| 653 | | - MISCDEV_MINOR); |
|---|
| 640 | + PXA3XX_GCU_MINOR); |
|---|
| 654 | 641 | goto err_free_dma; |
|---|
| 655 | 642 | } |
|---|
| 656 | 643 | |
|---|
| .. | .. |
|---|
| 663 | 650 | for (i = 0; i < 8; i++) { |
|---|
| 664 | 651 | ret = pxa3xx_gcu_add_buffer(dev, priv); |
|---|
| 665 | 652 | if (ret) { |
|---|
| 653 | + pxa3xx_gcu_free_buffers(dev, priv); |
|---|
| 666 | 654 | dev_err(dev, "failed to allocate DMA memory\n"); |
|---|
| 667 | 655 | goto err_disable_clk; |
|---|
| 668 | 656 | } |
|---|
| .. | .. |
|---|
| 670 | 658 | |
|---|
| 671 | 659 | platform_set_drvdata(pdev, priv); |
|---|
| 672 | 660 | priv->resource_mem = r; |
|---|
| 661 | + priv->dev = dev; |
|---|
| 673 | 662 | pxa3xx_gcu_reset(priv); |
|---|
| 674 | 663 | pxa3xx_gcu_init_debug_timer(priv); |
|---|
| 675 | 664 | |
|---|
| .. | .. |
|---|
| 678 | 667 | SHARED_SIZE, irq); |
|---|
| 679 | 668 | return 0; |
|---|
| 680 | 669 | |
|---|
| 681 | | -err_free_dma: |
|---|
| 682 | | - dma_free_coherent(dev, SHARED_SIZE, |
|---|
| 683 | | - priv->shared, priv->shared_phys); |
|---|
| 670 | +err_disable_clk: |
|---|
| 671 | + clk_disable_unprepare(priv->clk); |
|---|
| 684 | 672 | |
|---|
| 685 | 673 | err_misc_deregister: |
|---|
| 686 | 674 | misc_deregister(&priv->misc_dev); |
|---|
| 687 | 675 | |
|---|
| 688 | | -err_disable_clk: |
|---|
| 689 | | - clk_disable_unprepare(priv->clk); |
|---|
| 676 | +err_free_dma: |
|---|
| 677 | + dma_free_coherent(dev, SHARED_SIZE, |
|---|
| 678 | + priv->shared, priv->shared_phys); |
|---|
| 690 | 679 | |
|---|
| 691 | 680 | return ret; |
|---|
| 692 | 681 | } |
|---|
| .. | .. |
|---|
| 699 | 688 | pxa3xx_gcu_wait_idle(priv); |
|---|
| 700 | 689 | misc_deregister(&priv->misc_dev); |
|---|
| 701 | 690 | dma_free_coherent(dev, SHARED_SIZE, priv->shared, priv->shared_phys); |
|---|
| 691 | + clk_disable_unprepare(priv->clk); |
|---|
| 702 | 692 | pxa3xx_gcu_free_buffers(dev, priv); |
|---|
| 703 | 693 | |
|---|
| 704 | 694 | return 0; |
|---|
| .. | .. |
|---|
| 725 | 715 | |
|---|
| 726 | 716 | MODULE_DESCRIPTION("PXA3xx graphics controller unit driver"); |
|---|
| 727 | 717 | MODULE_LICENSE("GPL"); |
|---|
| 728 | | -MODULE_ALIAS_MISCDEV(MISCDEV_MINOR); |
|---|
| 718 | +MODULE_ALIAS_MISCDEV(PXA3XX_GCU_MINOR); |
|---|
| 729 | 719 | MODULE_AUTHOR("Janine Kropp <nin@directfb.org>, " |
|---|
| 730 | 720 | "Denis Oliver Kropp <dok@directfb.org>, " |
|---|
| 731 | 721 | "Daniel Mack <daniel@caiaq.de>"); |
|---|