]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - arch/arm/mach-omap2/hsmmc.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
[mirror_ubuntu-hirsute-kernel.git] / arch / arm / mach-omap2 / hsmmc.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/mach-omap2/hsmmc.c
4 *
5 * Copyright (C) 2007-2008 Texas Instruments
6 * Copyright (C) 2008 Nokia Corporation
7 * Author: Texas Instruments
8 */
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include <linux/string.h>
12 #include <linux/delay.h>
13 #include <linux/mmc/host.h>
14 #include <linux/platform_data/hsmmc-omap.h>
15
16 #include "soc.h"
17 #include "omap_device.h"
18
19 #include "hsmmc.h"
20 #include "control.h"
21
22 #if IS_ENABLED(CONFIG_MMC_OMAP_HS)
23
24 static u16 control_pbias_offset;
25 static u16 control_devconf1_offset;
26
27 #define HSMMC_NAME_LEN 9
28
29 static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
30 struct omap_hsmmc_platform_data *mmc)
31 {
32 char *hc_name;
33
34 hc_name = kzalloc(HSMMC_NAME_LEN + 1, GFP_KERNEL);
35 if (!hc_name) {
36 kfree(hc_name);
37 return -ENOMEM;
38 }
39
40 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
41 mmc->name = hc_name;
42 mmc->caps = c->caps;
43 mmc->reg_offset = 0;
44
45 return 0;
46 }
47
48 static int omap_hsmmc_done;
49
50 void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
51 {
52 struct platform_device *pdev;
53 int res;
54
55 if (omap_hsmmc_done)
56 return;
57
58 omap_hsmmc_done = 1;
59
60 for (; c->mmc; c++) {
61 pdev = c->pdev;
62 if (!pdev)
63 continue;
64 res = omap_device_register(pdev);
65 if (res)
66 pr_err("Could not late init MMC\n");
67 }
68 }
69
70 #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
71
72 static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
73 int ctrl_nr)
74 {
75 struct omap_hwmod *oh;
76 struct omap_hwmod *ohs[1];
77 struct omap_device *od;
78 struct platform_device *pdev;
79 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
80 struct omap_hsmmc_platform_data *mmc_data;
81 struct omap_hsmmc_dev_attr *mmc_dev_attr;
82 char *name;
83 int res;
84
85 mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
86 if (!mmc_data)
87 return;
88
89 res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
90 if (res < 0)
91 goto free_mmc;
92
93 name = "omap_hsmmc";
94 res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
95 "mmc%d", ctrl_nr);
96 WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
97 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
98
99 oh = omap_hwmod_lookup(oh_name);
100 if (!oh) {
101 pr_err("Could not look up %s\n", oh_name);
102 goto free_name;
103 }
104 ohs[0] = oh;
105 if (oh->dev_attr != NULL) {
106 mmc_dev_attr = oh->dev_attr;
107 mmc_data->controller_flags = mmc_dev_attr->flags;
108 }
109
110 pdev = platform_device_alloc(name, ctrl_nr - 1);
111 if (!pdev) {
112 pr_err("Could not allocate pdev for %s\n", name);
113 goto free_name;
114 }
115 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
116
117 od = omap_device_alloc(pdev, ohs, 1);
118 if (IS_ERR(od)) {
119 pr_err("Could not allocate od for %s\n", name);
120 goto put_pdev;
121 }
122
123 res = platform_device_add_data(pdev, mmc_data,
124 sizeof(struct omap_hsmmc_platform_data));
125 if (res) {
126 pr_err("Could not add pdata for %s\n", name);
127 goto put_pdev;
128 }
129
130 hsmmcinfo->pdev = pdev;
131
132 res = omap_device_register(pdev);
133 if (res) {
134 pr_err("Could not register od for %s\n", name);
135 goto free_od;
136 }
137
138 goto free_mmc;
139
140 free_od:
141 omap_device_delete(od);
142
143 put_pdev:
144 platform_device_put(pdev);
145
146 free_name:
147 kfree(mmc_data->name);
148
149 free_mmc:
150 kfree(mmc_data);
151 }
152
153 void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
154 {
155 if (omap_hsmmc_done)
156 return;
157
158 omap_hsmmc_done = 1;
159
160 if (cpu_is_omap2430()) {
161 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
162 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
163 } else {
164 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
165 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
166 }
167
168 for (; controllers->mmc; controllers++)
169 omap_hsmmc_init_one(controllers, controllers->mmc);
170
171 }
172
173 #endif