2 * linux/arch/arm/mach-omap2/hsmmc.c
4 * Copyright (C) 2007-2008 Texas Instruments
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: Texas Instruments
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/string.h>
15 #include <linux/delay.h>
16 #include <linux/mmc/host.h>
17 #include <linux/platform_data/hsmmc-omap.h>
20 #include "omap_device.h"
26 #if IS_ENABLED(CONFIG_MMC_OMAP_HS)
28 static u16 control_pbias_offset;
29 static u16 control_devconf1_offset;
31 #define HSMMC_NAME_LEN 9
33 static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
34 struct omap_hsmmc_platform_data *mmc)
38 hc_name = kzalloc(HSMMC_NAME_LEN + 1, GFP_KERNEL);
44 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
52 static int omap_hsmmc_done;
54 void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
56 struct platform_device *pdev;
68 res = omap_device_register(pdev);
70 pr_err("Could not late init MMC\n");
74 #define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
76 static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
79 struct omap_hwmod *oh;
80 struct omap_hwmod *ohs[1];
81 struct omap_device *od;
82 struct platform_device *pdev;
83 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
84 struct omap_hsmmc_platform_data *mmc_data;
85 struct omap_hsmmc_dev_attr *mmc_dev_attr;
89 mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
93 res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
98 res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
100 WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
101 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
103 oh = omap_hwmod_lookup(oh_name);
105 pr_err("Could not look up %s\n", oh_name);
109 if (oh->dev_attr != NULL) {
110 mmc_dev_attr = oh->dev_attr;
111 mmc_data->controller_flags = mmc_dev_attr->flags;
114 pdev = platform_device_alloc(name, ctrl_nr - 1);
116 pr_err("Could not allocate pdev for %s\n", name);
119 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
121 od = omap_device_alloc(pdev, ohs, 1);
123 pr_err("Could not allocate od for %s\n", name);
127 res = platform_device_add_data(pdev, mmc_data,
128 sizeof(struct omap_hsmmc_platform_data));
130 pr_err("Could not add pdata for %s\n", name);
134 hsmmcinfo->pdev = pdev;
136 res = omap_device_register(pdev);
138 pr_err("Could not register od for %s\n", name);
145 omap_device_delete(od);
148 platform_device_put(pdev);
151 kfree(mmc_data->name);
157 void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
164 if (cpu_is_omap2430()) {
165 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
166 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
168 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
169 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
172 for (; controllers->mmc; controllers++)
173 omap_hsmmc_init_one(controllers, controllers->mmc);