blob: 5b614388d72f4b7ca8be1c851f1369f719ce2c29 [file] [log] [blame]
Tony Lindgren90c62bf2008-12-10 17:37:17 -08001/*
Adrian Hunterd02a900b2010-02-15 10:03:34 -08002 * linux/arch/arm/mach-omap2/hsmmc.c
Tony Lindgren90c62bf2008-12-10 17:37:17 -08003 *
4 * Copyright (C) 2007-2008 Texas Instruments
5 * Copyright (C) 2008 Nokia Corporation
6 * Author: Texas Instruments
7 *
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.
11 */
Adrian Hunterdb0fefc2010-02-15 10:03:34 -080012#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/string.h>
Tony Lindgren90c62bf2008-12-10 17:37:17 -080015#include <linux/delay.h>
Silesh C V5e4698f2011-07-04 04:10:00 -070016#include <linux/gpio.h>
Andreas Fenkart826c71a2014-11-08 15:33:08 +010017#include <linux/mmc/host.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070018#include <linux/platform_data/gpio-omap.h>
Andreas Fenkart55143432014-11-08 15:33:09 +010019#include <linux/platform_data/hsmmc-omap.h>
Tony Lindgren4b254082012-08-30 15:37:24 -070020
Tony Lindgrene4c060d2012-10-05 13:25:59 -070021#include "soc.h"
Tony Lindgren25c7d492012-10-02 17:25:48 -070022#include "omap_device.h"
Tony Lindgren1d5aef42012-10-03 16:36:40 -070023#include "omap-pm.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080024
Adrian Hunterd02a900b2010-02-15 10:03:34 -080025#include "hsmmc.h"
Paul Walmsley4814ced2010-10-08 11:40:20 -060026#include "control.h"
Tony Lindgren90c62bf2008-12-10 17:37:17 -080027
Javier Martinez Canillas502ad2a2016-08-11 15:29:45 -040028#if IS_ENABLED(CONFIG_MMC_OMAP_HS)
Tony Lindgren90c62bf2008-12-10 17:37:17 -080029
Tony Lindgren90c62bf2008-12-10 17:37:17 -080030static u16 control_pbias_offset;
31static u16 control_devconf1_offset;
32
33#define HSMMC_NAME_LEN 9
34
Tony Lindgrend1589f02012-02-20 09:43:30 -080035static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
Andreas Fenkart55143432014-11-08 15:33:09 +010036 struct omap_hsmmc_platform_data *mmc)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053037{
38 char *hc_name;
39
40 hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL);
41 if (!hc_name) {
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053042 kfree(hc_name);
43 return -ENOMEM;
44 }
45
Faiz Abbasba647922017-07-14 18:16:43 +053046 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
Andreas Fenkart326119c2014-11-08 15:33:14 +010047 mmc->name = hc_name;
Andreas Fenkart326119c2014-11-08 15:33:14 +010048 mmc->caps = c->caps;
Tony Lindgrenb30e3212013-05-30 12:53:06 -070049 mmc->reg_offset = 0;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053050
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053051 return 0;
52}
53
Tony Lindgren97899e52012-02-20 09:43:28 -080054static int omap_hsmmc_done;
Tony Lindgren3b972bf2012-02-20 09:43:29 -080055
56void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
57{
58 struct platform_device *pdev;
Tony Lindgren3b972bf2012-02-20 09:43:29 -080059 int res;
60
61 if (omap_hsmmc_done != 1)
62 return;
63
64 omap_hsmmc_done++;
65
66 for (; c->mmc; c++) {
Tony Lindgren3b972bf2012-02-20 09:43:29 -080067 pdev = c->pdev;
68 if (!pdev)
69 continue;
Tony Lindgren3b972bf2012-02-20 09:43:29 -080070 res = omap_device_register(pdev);
71 if (res)
Faiz Abbasba647922017-07-14 18:16:43 +053072 pr_err("Could not late init MMC\n");
Tony Lindgren3b972bf2012-02-20 09:43:29 -080073 }
74}
75
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053076#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
77
Tony Lindgren60285052012-03-07 18:54:24 -080078static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
Tony Lindgren3b972bf2012-02-20 09:43:29 -080079 int ctrl_nr)
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053080{
81 struct omap_hwmod *oh;
Tony Lindgren3b972bf2012-02-20 09:43:29 -080082 struct omap_hwmod *ohs[1];
83 struct omap_device *od;
Kevin Hilman3528c582011-07-21 13:48:45 -070084 struct platform_device *pdev;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053085 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
Andreas Fenkart55143432014-11-08 15:33:09 +010086 struct omap_hsmmc_platform_data *mmc_data;
87 struct omap_hsmmc_dev_attr *mmc_dev_attr;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053088 char *name;
Tony Lindgren3b972bf2012-02-20 09:43:29 -080089 int res;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053090
Andreas Fenkart55143432014-11-08 15:33:09 +010091 mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
Markus Elfring1a61a2a2017-06-03 17:24:27 +020092 if (!mmc_data)
Tony Lindgren3b972bf2012-02-20 09:43:29 -080093 return;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +053094
Tony Lindgren3b972bf2012-02-20 09:43:29 -080095 res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
96 if (res < 0)
97 goto free_mmc;
98
Kishore Kadiyala0005ae72011-02-28 20:48:05 +053099 name = "omap_hsmmc";
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800100 res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530101 "mmc%d", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800102 WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530103 "String buffer overflow in MMC%d device setup\n", ctrl_nr);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800104
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530105 oh = omap_hwmod_lookup(oh_name);
106 if (!oh) {
107 pr_err("Could not look up %s\n", oh_name);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800108 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530109 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800110 ohs[0] = oh;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530111 if (oh->dev_attr != NULL) {
112 mmc_dev_attr = oh->dev_attr;
113 mmc_data->controller_flags = mmc_dev_attr->flags;
114 }
115
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800116 pdev = platform_device_alloc(name, ctrl_nr - 1);
117 if (!pdev) {
118 pr_err("Could not allocate pdev for %s\n", name);
119 goto free_name;
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530120 }
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800121 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530122
Paul Walmsleyc1d1cd52013-01-26 00:48:53 -0700123 od = omap_device_alloc(pdev, ohs, 1);
Wei Yongjun64de3a02012-09-21 14:30:50 +0800124 if (IS_ERR(od)) {
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800125 pr_err("Could not allocate od for %s\n", name);
126 goto put_pdev;
127 }
128
129 res = platform_device_add_data(pdev, mmc_data,
Andreas Fenkart55143432014-11-08 15:33:09 +0100130 sizeof(struct omap_hsmmc_platform_data));
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800131 if (res) {
132 pr_err("Could not add pdata for %s\n", name);
133 goto put_pdev;
134 }
135
136 hsmmcinfo->pdev = pdev;
137
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800138 res = omap_device_register(pdev);
139 if (res) {
140 pr_err("Could not register od for %s\n", name);
141 goto free_od;
142 }
143
144 goto free_mmc;
145
146free_od:
147 omap_device_delete(od);
148
149put_pdev:
150 platform_device_put(pdev);
151
152free_name:
Andreas Fenkart326119c2014-11-08 15:33:14 +0100153 kfree(mmc_data->name);
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800154
155free_mmc:
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530156 kfree(mmc_data);
157}
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800158
Tony Lindgrend1589f02012-02-20 09:43:30 -0800159void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800160{
Tony Lindgren97899e52012-02-20 09:43:28 -0800161 if (omap_hsmmc_done)
162 return;
163
164 omap_hsmmc_done = 1;
165
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700166 if (cpu_is_omap2430()) {
167 control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
168 control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800169 } else {
Tony Lindgrenb30e3212013-05-30 12:53:06 -0700170 control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
171 control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800172 }
173
Kishore Kadiyala4621d5f2011-02-28 20:48:04 +0530174 for (; controllers->mmc; controllers++)
Tony Lindgren3b972bf2012-02-20 09:43:29 -0800175 omap_hsmmc_init_one(controllers, controllers->mmc);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800176
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800177}
178
179#endif