2008-12-11 01:37:17 +00:00
|
|
|
/*
|
2010-02-15 18:03:34 +00:00
|
|
|
* linux/arch/arm/mach-omap2/hsmmc.c
|
2008-12-11 01:37:17 +00: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-15 18:03:34 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
2008-12-11 01:37:17 +00:00
|
|
|
#include <linux/delay.h>
|
2011-07-04 11:10:00 +00:00
|
|
|
#include <linux/gpio.h>
|
2014-11-08 14:33:08 +00:00
|
|
|
#include <linux/mmc/host.h>
|
2012-08-30 22:37:24 +00:00
|
|
|
#include <linux/platform_data/gpio-omap.h>
|
2014-11-08 14:33:09 +00:00
|
|
|
#include <linux/platform_data/hsmmc-omap.h>
|
2012-08-30 22:37:24 +00:00
|
|
|
|
2012-10-05 20:25:59 +00:00
|
|
|
#include "soc.h"
|
2012-10-03 00:25:48 +00:00
|
|
|
#include "omap_device.h"
|
2012-10-03 23:36:40 +00:00
|
|
|
#include "omap-pm.h"
|
2008-12-11 01:37:17 +00:00
|
|
|
|
2010-02-15 18:03:34 +00:00
|
|
|
#include "hsmmc.h"
|
2010-10-08 17:40:20 +00:00
|
|
|
#include "control.h"
|
2008-12-11 01:37:17 +00:00
|
|
|
|
2016-08-11 19:29:45 +00:00
|
|
|
#if IS_ENABLED(CONFIG_MMC_OMAP_HS)
|
2008-12-11 01:37:17 +00:00
|
|
|
|
|
|
|
static u16 control_pbias_offset;
|
|
|
|
static u16 control_devconf1_offset;
|
|
|
|
|
|
|
|
#define HSMMC_NAME_LEN 9
|
|
|
|
|
2012-02-20 17:43:30 +00:00
|
|
|
static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
|
2014-11-08 14:33:09 +00:00
|
|
|
struct omap_hsmmc_platform_data *mmc)
|
2011-02-28 15:18:04 +00: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 12:46:43 +00:00
|
|
|
snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
|
2014-11-08 14:33:14 +00:00
|
|
|
mmc->name = hc_name;
|
|
|
|
mmc->caps = c->caps;
|
2013-05-30 19:53:06 +00:00
|
|
|
mmc->reg_offset = 0;
|
2011-02-28 15:18:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-20 17:43:28 +00:00
|
|
|
static int omap_hsmmc_done;
|
2012-02-20 17:43:29 +00:00
|
|
|
|
|
|
|
void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev;
|
|
|
|
int res;
|
|
|
|
|
2017-09-08 19:15:51 +00:00
|
|
|
if (omap_hsmmc_done)
|
2012-02-20 17:43:29 +00:00
|
|
|
return;
|
|
|
|
|
2017-09-08 19:15:51 +00:00
|
|
|
omap_hsmmc_done = 1;
|
2012-02-20 17:43:29 +00:00
|
|
|
|
|
|
|
for (; c->mmc; c++) {
|
|
|
|
pdev = c->pdev;
|
|
|
|
if (!pdev)
|
|
|
|
continue;
|
|
|
|
res = omap_device_register(pdev);
|
|
|
|
if (res)
|
2017-07-14 12:46:43 +00:00
|
|
|
pr_err("Could not late init MMC\n");
|
2012-02-20 17:43:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-28 15:18:04 +00:00
|
|
|
#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
|
|
|
|
|
2012-03-08 02:54:24 +00:00
|
|
|
static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
|
2012-02-20 17:43:29 +00:00
|
|
|
int ctrl_nr)
|
2011-02-28 15:18:04 +00:00
|
|
|
{
|
|
|
|
struct omap_hwmod *oh;
|
2012-02-20 17:43:29 +00:00
|
|
|
struct omap_hwmod *ohs[1];
|
|
|
|
struct omap_device *od;
|
2011-07-21 20:48:45 +00:00
|
|
|
struct platform_device *pdev;
|
2011-02-28 15:18:04 +00:00
|
|
|
char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
|
2014-11-08 14:33:09 +00:00
|
|
|
struct omap_hsmmc_platform_data *mmc_data;
|
|
|
|
struct omap_hsmmc_dev_attr *mmc_dev_attr;
|
2011-02-28 15:18:04 +00:00
|
|
|
char *name;
|
2012-02-20 17:43:29 +00:00
|
|
|
int res;
|
2011-02-28 15:18:04 +00:00
|
|
|
|
2014-11-08 14:33:09 +00:00
|
|
|
mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
|
2017-06-03 15:24:27 +00:00
|
|
|
if (!mmc_data)
|
2012-02-20 17:43:29 +00:00
|
|
|
return;
|
2011-02-28 15:18:04 +00:00
|
|
|
|
2012-02-20 17:43:29 +00:00
|
|
|
res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
|
|
|
|
if (res < 0)
|
|
|
|
goto free_mmc;
|
|
|
|
|
2011-02-28 15:18:05 +00:00
|
|
|
name = "omap_hsmmc";
|
2012-02-20 17:43:29 +00:00
|
|
|
res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
|
2011-02-28 15:18:04 +00:00
|
|
|
"mmc%d", ctrl_nr);
|
2012-02-20 17:43:29 +00:00
|
|
|
WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
|
2011-02-28 15:18:04 +00:00
|
|
|
"String buffer overflow in MMC%d device setup\n", ctrl_nr);
|
2012-02-20 17:43:29 +00:00
|
|
|
|
2011-02-28 15:18:04 +00:00
|
|
|
oh = omap_hwmod_lookup(oh_name);
|
|
|
|
if (!oh) {
|
|
|
|
pr_err("Could not look up %s\n", oh_name);
|
2012-02-20 17:43:29 +00:00
|
|
|
goto free_name;
|
2011-02-28 15:18:04 +00:00
|
|
|
}
|
2012-02-20 17:43:29 +00:00
|
|
|
ohs[0] = oh;
|
2011-02-28 15:18:04 +00:00
|
|
|
if (oh->dev_attr != NULL) {
|
|
|
|
mmc_dev_attr = oh->dev_attr;
|
|
|
|
mmc_data->controller_flags = mmc_dev_attr->flags;
|
|
|
|
}
|
|
|
|
|
2012-02-20 17:43:29 +00: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 15:18:04 +00:00
|
|
|
}
|
2012-02-20 17:43:29 +00:00
|
|
|
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
|
|
|
|
|
2013-01-26 07:48:53 +00:00
|
|
|
od = omap_device_alloc(pdev, ohs, 1);
|
2012-09-21 06:30:50 +00:00
|
|
|
if (IS_ERR(od)) {
|
2012-02-20 17:43:29 +00: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 14:33:09 +00:00
|
|
|
sizeof(struct omap_hsmmc_platform_data));
|
2012-02-20 17:43:29 +00: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 14:33:14 +00:00
|
|
|
kfree(mmc_data->name);
|
2011-02-28 15:18:04 +00:00
|
|
|
|
2012-02-20 17:43:29 +00:00
|
|
|
free_mmc:
|
2011-02-28 15:18:04 +00:00
|
|
|
kfree(mmc_data);
|
|
|
|
}
|
2008-12-11 01:37:17 +00:00
|
|
|
|
2012-02-20 17:43:30 +00:00
|
|
|
void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
|
2008-12-11 01:37:17 +00:00
|
|
|
{
|
2012-02-20 17:43:28 +00:00
|
|
|
if (omap_hsmmc_done)
|
|
|
|
return;
|
|
|
|
|
|
|
|
omap_hsmmc_done = 1;
|
|
|
|
|
2013-05-30 19:53:06 +00:00
|
|
|
if (cpu_is_omap2430()) {
|
|
|
|
control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
|
|
|
|
control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
|
2008-12-11 01:37:17 +00:00
|
|
|
} else {
|
2013-05-30 19:53:06 +00:00
|
|
|
control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
|
|
|
|
control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
|
2008-12-11 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-28 15:18:04 +00:00
|
|
|
for (; controllers->mmc; controllers++)
|
2012-02-20 17:43:29 +00:00
|
|
|
omap_hsmmc_init_one(controllers, controllers->mmc);
|
2009-03-24 01:23:47 +00:00
|
|
|
|
2008-12-11 01:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|