Commit | Line | Data |
---|---|---|
d25bc64b JY |
1 | /* |
2 | * | |
142b0cea | 3 | * (C) COPYRIGHT 2011-2014, 2016-2017 ARM Limited. All rights reserved. |
d25bc64b JY |
4 | * |
5 | * This program is free software and is provided to you under the terms of the | |
6 | * GNU General Public License version 2 as published by the Free Software | |
7 | * Foundation, and any use by you of this program is subject to the terms | |
8 | * of such GNU licence. | |
9 | * | |
10 | * A copy of the licence is included with the program, and can also be obtained | |
11 | * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
12 | * Boston, MA 02110-1301, USA. | |
13 | * | |
14 | */ | |
15 | ||
16 | ||
17 | ||
d25bc64b JY |
18 | #include <linux/errno.h> |
19 | #include <linux/export.h> | |
20 | #include <linux/ioport.h> | |
21 | #include <linux/platform_device.h> | |
22 | #include <linux/string.h> | |
23 | ||
d25bc64b JY |
24 | |
25 | /* | |
26 | * This file is included only for type definitions and functions belonging to | |
27 | * specific platform folders. Do not add dependencies with symbols that are | |
28 | * defined somewhere else. | |
29 | */ | |
30 | #include <mali_kbase_config.h> | |
31 | ||
32 | #define PLATFORM_CONFIG_RESOURCE_COUNT 4 | |
33 | #define PLATFORM_CONFIG_IRQ_RES_COUNT 3 | |
34 | ||
35 | static struct platform_device *mali_device; | |
36 | ||
37 | #ifndef CONFIG_OF | |
38 | /** | |
39 | * @brief Convert data in struct kbase_io_resources struct to Linux-specific resources | |
40 | * | |
41 | * Function converts data in struct kbase_io_resources struct to an array of Linux resource structures. Note that function | |
42 | * assumes that size of linux_resource array is at least PLATFORM_CONFIG_RESOURCE_COUNT. | |
43 | * Resources are put in fixed order: I/O memory region, job IRQ, MMU IRQ, GPU IRQ. | |
44 | * | |
45 | * @param[in] io_resource Input IO resource data | |
46 | * @param[out] linux_resources Pointer to output array of Linux resource structures | |
47 | */ | |
48 | static void kbasep_config_parse_io_resources(const struct kbase_io_resources *io_resources, struct resource *const linux_resources) | |
49 | { | |
50 | if (!io_resources || !linux_resources) { | |
51 | pr_err("%s: couldn't find proper resources\n", __func__); | |
52 | return; | |
53 | } | |
54 | ||
55 | memset(linux_resources, 0, PLATFORM_CONFIG_RESOURCE_COUNT * sizeof(struct resource)); | |
56 | ||
57 | linux_resources[0].start = io_resources->io_memory_region.start; | |
58 | linux_resources[0].end = io_resources->io_memory_region.end; | |
59 | linux_resources[0].flags = IORESOURCE_MEM; | |
51f89798 | 60 | |
d25bc64b JY |
61 | linux_resources[1].start = io_resources->job_irq_number; |
62 | linux_resources[1].end = io_resources->job_irq_number; | |
63 | linux_resources[1].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL; | |
64 | ||
65 | linux_resources[2].start = io_resources->mmu_irq_number; | |
66 | linux_resources[2].end = io_resources->mmu_irq_number; | |
67 | linux_resources[2].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL; | |
68 | ||
69 | linux_resources[3].start = io_resources->gpu_irq_number; | |
70 | linux_resources[3].end = io_resources->gpu_irq_number; | |
71 | linux_resources[3].flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL; | |
72 | } | |
73 | #endif /* CONFIG_OF */ | |
74 | ||
142b0cea | 75 | int kbase_platform_register(void) |
d25bc64b JY |
76 | { |
77 | struct kbase_platform_config *config; | |
78 | #ifndef CONFIG_OF | |
79 | struct resource resources[PLATFORM_CONFIG_RESOURCE_COUNT]; | |
80 | #endif | |
81 | int err; | |
82 | ||
83 | config = kbase_get_platform_config(); /* declared in midgard/mali_kbase_config.h but defined in platform folder */ | |
84 | if (config == NULL) { | |
85 | pr_err("%s: couldn't get platform config\n", __func__); | |
86 | return -ENODEV; | |
87 | } | |
88 | ||
89 | mali_device = platform_device_alloc("mali", 0); | |
90 | if (mali_device == NULL) | |
91 | return -ENOMEM; | |
92 | ||
93 | #ifndef CONFIG_OF | |
94 | kbasep_config_parse_io_resources(config->io_resources, resources); | |
95 | err = platform_device_add_resources(mali_device, resources, PLATFORM_CONFIG_RESOURCE_COUNT); | |
96 | if (err) { | |
97 | platform_device_put(mali_device); | |
98 | mali_device = NULL; | |
99 | return err; | |
100 | } | |
101 | #endif /* CONFIG_OF */ | |
102 | ||
103 | err = platform_device_add(mali_device); | |
104 | if (err) { | |
105 | platform_device_unregister(mali_device); | |
106 | mali_device = NULL; | |
107 | return err; | |
108 | } | |
109 | ||
110 | return 0; | |
111 | } | |
142b0cea | 112 | EXPORT_SYMBOL(kbase_platform_register); |
d25bc64b | 113 | |
142b0cea | 114 | void kbase_platform_unregister(void) |
d25bc64b JY |
115 | { |
116 | if (mali_device) | |
117 | platform_device_unregister(mali_device); | |
118 | } | |
142b0cea | 119 | EXPORT_SYMBOL(kbase_platform_unregister); |