2008-12-11 09:37:17 +08:00
|
|
|
/*
|
2010-02-16 02:03:34 +08:00
|
|
|
* linux/arch/arm/mach-omap2/hsmmc.c
|
2008-12-11 09:37:17 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Texas Instruments
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
* Author: Texas Instruments
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
2010-02-16 02:03:34 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
2008-12-11 09:37:17 +08:00
|
|
|
#include <linux/delay.h>
|
2011-07-04 19:10:00 +08:00
|
|
|
#include <linux/gpio.h>
|
2014-11-08 22:33:08 +08:00
|
|
|
#include <linux/mmc/host.h>
|
2012-08-31 06:37:24 +08:00
|
|
|
#include <linux/platform_data/gpio-omap.h>
|
2014-11-08 22:33:09 +08:00
|
|
|
#include <linux/platform_data/hsmmc-omap.h>
|
2012-08-31 06:37:24 +08:00
|
|
|
|
2012-10-06 04:25:59 +08:00
|
|
|
#include "soc.h"
|
2012-10-03 08:25:48 +08:00
|
|
|
#include "omap_device.h"
|
2012-10-04 07:36:40 +08:00
|
|
|
#include "omap-pm.h"
|
2008-12-11 09:37:17 +08:00
|
|
|
|
2010-02-16 02:03:34 +08:00
|
|
|
#include "hsmmc.h"
|
2010-10-09 01:40:20 +08:00
|
|
|
#include "control.h"
|
2008-12-11 09:37:17 +08:00
|
|
|
|
2016-08-12 03:29:45 +08:00
|
|
|
#if IS_ENABLED(CONFIG_MMC_OMAP_HS)
|
2008-12-11 09:37:17 +08:00
|
|
|
|
|
|
|
static u16 control_pbias_offset;
|
|
|
|
static u16 control_devconf1_offset;
|
|
|
|
|
|
|
|
#define HSMMC_NAME_LEN 9
|
|
|
|
|
2012-02-21 01:43:30 +08:00
|
|
|
static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
|
2014-11-08 22:33:09 +08:00
|
|
|
struct omap_hsmmc_platform_data *mmc)
|
2011-02-28 23:18:04 +08:00
|
|
|
{
|
|
|
|
char *hc_name;
|
|
|
|
|
|
|
|
hc_name = kzalloc(sizeof(char) * (HSMMC_NAME_LEN + 1), GFP_KERNEL);
|
|
|
|
if (!hc_name) {
|
|
|
|
kfree(hc_name);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-07-14 20:46:43 +08:00
|
|
|
snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
|
2014-11-08 22:33:14 +08:00
|
|
|
mmc->name = hc_name;
|
|
|
|
mmc->caps = c->caps;
|
2013-05-31 03:53:06 +08:00
|
|
|
mmc->reg_offset = 0;
|
2011-02-28 23:18:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-21 01:43:28 +08:00
|
|
|
static int omap_hsmmc_done;
|
2012-02-21 01:43:29 +08:00
|
|
|
|
|
|
|
void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (omap_hsmmc_done != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
omap_hsmmc_done++;
|
|
|
|
|
|
|
|
for (; c->mmc; c++) {
|
|
|
|
pdev = c->pdev;
|
|
|
|
if (!pdev)
|
|
|
|
continue;
|
|
|
|
res = omap_device_register(pdev);
|
|
|
|
if (res)
|
2017-07-14 20:46:43 +08:00
|
|
|
pr_err("Could not late init MMC\n");
|
2012-02-21 01:43:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-28 23:18:04 +08:00
|
|
|
#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
|
|
|
|
|
2012-03-08 10:54:24 +08:00
|
|
|
static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
|
2012-02-21 01:43:29 +08:00
|
|
|
int ctrl_nr)
|
2011-02-28 23:18:04 +08:00
|
|
|
{
|
|
|
|
struct omap_hwmod *oh;
|
2012-02-21 01:43:29 +08:00
|
|
|
struct omap_hwmod *ohs[1];
|
|
|
|
struct omap_device *od;
|
2011-07-22 04:48:45 +08:00
|
|
|
struct platform_device *pdev;
|
2011-02-28 23:18:04 +08:00
|
|
|
char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
|
2014-11-08 22:33:09 +08:00
|
|
|
struct omap_hsmmc_platform_data *mmc_data;
|
|
|
|
struct omap_hsmmc_dev_attr *mmc_dev_attr;
|
2011-02-28 23:18:04 +08:00
|
|
|
char *name;
|
2012-02-21 01:43:29 +08:00
|
|
|
int res;
|
2011-02-28 23:18:04 +08:00
|
|
|
|
2014-11-08 22:33:09 +08:00
|
|
|
mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
|
2017-06-03 23:24:27 +08:00
|
|
|
if (!mmc_data)
|
2012-02-21 01:43:29 +08:00
|
|
|
return;
|
2011-02-28 23:18:04 +08:00
|
|
|
|
2012-02-21 01:43:29 +08:00
|
|
|
res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
|
|
|
|
if (res < 0)
|
|
|
|
goto free_mmc;
|
|
|
|
|
2011-02-28 23:18:05 +08:00
|
|
|
name = "omap_hsmmc";
|
2012-02-21 01:43:29 +08:00
|
|
|
res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
|
2011-02-28 23:18:04 +08:00
|
|
|
"mmc%d", ctrl_nr);
|
2012-02-21 01:43:29 +08:00
|
|
|
WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
|
2011-02-28 23:18:04 +08:00
|
|
|
"String buffer overflow in MMC%d device setup\n", ctrl_nr);
|
2012-02-21 01:43:29 +08:00
|
|
|
|
2011-02-28 23:18:04 +08:00
|
|
|
oh = omap_hwmod_lookup(oh_name);
|
|
|
|
if (!oh) {
|
|
|
|
pr_err("Could not look up %s\n", oh_name);
|
2012-02-21 01:43:29 +08:00
|
|
|
goto free_name;
|
2011-02-28 23:18:04 +08:00
|
|
|
}
|
2012-02-21 01:43:29 +08:00
|
|
|
ohs[0] = oh;
|
2011-02-28 23:18:04 +08:00
|
|
|
if (oh->dev_attr != NULL) {
|
|
|
|
mmc_dev_attr = oh->dev_attr;
|
|
|
|
mmc_data->controller_flags = mmc_dev_attr->flags;
|
|
|
|
}
|
|
|
|
|
2012-02-21 01:43:29 +08:00
|
|
|
pdev = platform_device_alloc(name, ctrl_nr - 1);
|
|
|
|
if (!pdev) {
|
|
|
|
pr_err("Could not allocate pdev for %s\n", name);
|
|
|
|
goto free_name;
|
2011-02-28 23:18:04 +08:00
|
|
|
}
|
2012-02-21 01:43:29 +08:00
|
|
|
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
|
|
|
|
|
2013-01-26 15:48:53 +08:00
|
|
|
od = omap_device_alloc(pdev, ohs, 1);
|
2012-09-21 14:30:50 +08:00
|
|
|
if (IS_ERR(od)) {
|
2012-02-21 01:43:29 +08:00
|
|
|
pr_err("Could not allocate od for %s\n", name);
|
|
|
|
goto put_pdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = platform_device_add_data(pdev, mmc_data,
|
2014-11-08 22:33:09 +08:00
|
|
|
sizeof(struct omap_hsmmc_platform_data));
|
2012-02-21 01:43:29 +08:00
|
|
|
if (res) {
|
|
|
|
pr_err("Could not add pdata for %s\n", name);
|
|
|
|
goto put_pdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
hsmmcinfo->pdev = pdev;
|
|
|
|
|
|
|
|
res = omap_device_register(pdev);
|
|
|
|
if (res) {
|
|
|
|
pr_err("Could not register od for %s\n", name);
|
|
|
|
goto free_od;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto free_mmc;
|
|
|
|
|
|
|
|
free_od:
|
|
|
|
omap_device_delete(od);
|
|
|
|
|
|
|
|
put_pdev:
|
|
|
|
platform_device_put(pdev);
|
|
|
|
|
|
|
|
free_name:
|
2014-11-08 22:33:14 +08:00
|
|
|
kfree(mmc_data->name);
|
2011-02-28 23:18:04 +08:00
|
|
|
|
2012-02-21 01:43:29 +08:00
|
|
|
free_mmc:
|
2011-02-28 23:18:04 +08:00
|
|
|
kfree(mmc_data);
|
|
|
|
}
|
2008-12-11 09:37:17 +08:00
|
|
|
|
2012-02-21 01:43:30 +08:00
|
|
|
void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
|
2008-12-11 09:37:17 +08:00
|
|
|
{
|
2012-02-21 01:43:28 +08:00
|
|
|
if (omap_hsmmc_done)
|
|
|
|
return;
|
|
|
|
|
|
|
|
omap_hsmmc_done = 1;
|
|
|
|
|
2013-05-31 03:53:06 +08:00
|
|
|
if (cpu_is_omap2430()) {
|
|
|
|
control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
|
|
|
|
control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
|
2008-12-11 09:37:17 +08:00
|
|
|
} else {
|
2013-05-31 03:53:06 +08:00
|
|
|
control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
|
|
|
|
control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
|
2008-12-11 09:37:17 +08:00
|
|
|
}
|
|
|
|
|
2011-02-28 23:18:04 +08:00
|
|
|
for (; controllers->mmc; controllers++)
|
2012-02-21 01:43:29 +08:00
|
|
|
omap_hsmmc_init_one(controllers, controllers->mmc);
|
2009-03-24 09:23:47 +08:00
|
|
|
|
2008-12-11 09:37:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|