2019-06-04 11:11:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-12-11 04:37:17 +03:00
|
|
|
/*
|
2010-02-15 21:03:34 +03:00
|
|
|
* linux/arch/arm/mach-omap2/hsmmc.c
|
2008-12-11 04:37:17 +03:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2008 Texas Instruments
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
* Author: Texas Instruments
|
|
|
|
*/
|
2010-02-15 21:03:34 +03:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/string.h>
|
2008-12-11 04:37:17 +03:00
|
|
|
#include <linux/delay.h>
|
2014-11-08 17:33:08 +03:00
|
|
|
#include <linux/mmc/host.h>
|
2014-11-08 17:33:09 +03:00
|
|
|
#include <linux/platform_data/hsmmc-omap.h>
|
2012-08-31 02:37:24 +04:00
|
|
|
|
2012-10-06 00:25:59 +04:00
|
|
|
#include "soc.h"
|
2012-10-03 04:25:48 +04:00
|
|
|
#include "omap_device.h"
|
2008-12-11 04:37:17 +03:00
|
|
|
|
2010-02-15 21:03:34 +03:00
|
|
|
#include "hsmmc.h"
|
2010-10-08 21:40:20 +04:00
|
|
|
#include "control.h"
|
2008-12-11 04:37:17 +03:00
|
|
|
|
2016-08-11 22:29:45 +03:00
|
|
|
#if IS_ENABLED(CONFIG_MMC_OMAP_HS)
|
2008-12-11 04:37:17 +03:00
|
|
|
|
|
|
|
static u16 control_pbias_offset;
|
|
|
|
static u16 control_devconf1_offset;
|
|
|
|
|
|
|
|
#define HSMMC_NAME_LEN 9
|
|
|
|
|
2012-02-20 21:43:30 +04:00
|
|
|
static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
|
2014-11-08 17:33:09 +03:00
|
|
|
struct omap_hsmmc_platform_data *mmc)
|
2011-02-28 18:18:04 +03:00
|
|
|
{
|
|
|
|
char *hc_name;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 00:03:40 +03:00
|
|
|
hc_name = kzalloc(HSMMC_NAME_LEN + 1, GFP_KERNEL);
|
2011-02-28 18:18:04 +03:00
|
|
|
if (!hc_name) {
|
|
|
|
kfree(hc_name);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-07-14 15:46:43 +03:00
|
|
|
snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", c->mmc, 1);
|
2014-11-08 17:33:14 +03:00
|
|
|
mmc->name = hc_name;
|
|
|
|
mmc->caps = c->caps;
|
2013-05-30 23:53:06 +04:00
|
|
|
mmc->reg_offset = 0;
|
2011-02-28 18:18:04 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-20 21:43:28 +04:00
|
|
|
static int omap_hsmmc_done;
|
2012-02-20 21:43:29 +04:00
|
|
|
|
|
|
|
void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev;
|
|
|
|
int res;
|
|
|
|
|
2017-09-08 22:15:51 +03:00
|
|
|
if (omap_hsmmc_done)
|
2012-02-20 21:43:29 +04:00
|
|
|
return;
|
|
|
|
|
2017-09-08 22:15:51 +03:00
|
|
|
omap_hsmmc_done = 1;
|
2012-02-20 21:43:29 +04:00
|
|
|
|
|
|
|
for (; c->mmc; c++) {
|
|
|
|
pdev = c->pdev;
|
|
|
|
if (!pdev)
|
|
|
|
continue;
|
|
|
|
res = omap_device_register(pdev);
|
|
|
|
if (res)
|
2017-07-14 15:46:43 +03:00
|
|
|
pr_err("Could not late init MMC\n");
|
2012-02-20 21:43:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-28 18:18:04 +03:00
|
|
|
#define MAX_OMAP_MMC_HWMOD_NAME_LEN 16
|
|
|
|
|
2012-03-08 06:54:24 +04:00
|
|
|
static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
|
2012-02-20 21:43:29 +04:00
|
|
|
int ctrl_nr)
|
2011-02-28 18:18:04 +03:00
|
|
|
{
|
|
|
|
struct omap_hwmod *oh;
|
2012-02-20 21:43:29 +04:00
|
|
|
struct omap_hwmod *ohs[1];
|
|
|
|
struct omap_device *od;
|
2011-07-22 00:48:45 +04:00
|
|
|
struct platform_device *pdev;
|
2011-02-28 18:18:04 +03:00
|
|
|
char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
|
2014-11-08 17:33:09 +03:00
|
|
|
struct omap_hsmmc_platform_data *mmc_data;
|
|
|
|
struct omap_hsmmc_dev_attr *mmc_dev_attr;
|
2011-02-28 18:18:04 +03:00
|
|
|
char *name;
|
2012-02-20 21:43:29 +04:00
|
|
|
int res;
|
2011-02-28 18:18:04 +03:00
|
|
|
|
2014-11-08 17:33:09 +03:00
|
|
|
mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
|
2017-06-03 18:24:27 +03:00
|
|
|
if (!mmc_data)
|
2012-02-20 21:43:29 +04:00
|
|
|
return;
|
2011-02-28 18:18:04 +03:00
|
|
|
|
2012-02-20 21:43:29 +04:00
|
|
|
res = omap_hsmmc_pdata_init(hsmmcinfo, mmc_data);
|
|
|
|
if (res < 0)
|
|
|
|
goto free_mmc;
|
|
|
|
|
2011-02-28 18:18:05 +03:00
|
|
|
name = "omap_hsmmc";
|
2012-02-20 21:43:29 +04:00
|
|
|
res = snprintf(oh_name, MAX_OMAP_MMC_HWMOD_NAME_LEN,
|
2011-02-28 18:18:04 +03:00
|
|
|
"mmc%d", ctrl_nr);
|
2012-02-20 21:43:29 +04:00
|
|
|
WARN(res >= MAX_OMAP_MMC_HWMOD_NAME_LEN,
|
2011-02-28 18:18:04 +03:00
|
|
|
"String buffer overflow in MMC%d device setup\n", ctrl_nr);
|
2012-02-20 21:43:29 +04:00
|
|
|
|
2011-02-28 18:18:04 +03:00
|
|
|
oh = omap_hwmod_lookup(oh_name);
|
|
|
|
if (!oh) {
|
|
|
|
pr_err("Could not look up %s\n", oh_name);
|
2012-02-20 21:43:29 +04:00
|
|
|
goto free_name;
|
2011-02-28 18:18:04 +03:00
|
|
|
}
|
2012-02-20 21:43:29 +04:00
|
|
|
ohs[0] = oh;
|
2011-02-28 18:18:04 +03:00
|
|
|
if (oh->dev_attr != NULL) {
|
|
|
|
mmc_dev_attr = oh->dev_attr;
|
|
|
|
mmc_data->controller_flags = mmc_dev_attr->flags;
|
|
|
|
}
|
|
|
|
|
2012-02-20 21:43:29 +04: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 18:18:04 +03:00
|
|
|
}
|
2012-02-20 21:43:29 +04:00
|
|
|
dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
|
|
|
|
|
2013-01-26 11:48:53 +04:00
|
|
|
od = omap_device_alloc(pdev, ohs, 1);
|
2012-09-21 10:30:50 +04:00
|
|
|
if (IS_ERR(od)) {
|
2012-02-20 21:43:29 +04: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 17:33:09 +03:00
|
|
|
sizeof(struct omap_hsmmc_platform_data));
|
2012-02-20 21:43:29 +04: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 17:33:14 +03:00
|
|
|
kfree(mmc_data->name);
|
2011-02-28 18:18:04 +03:00
|
|
|
|
2012-02-20 21:43:29 +04:00
|
|
|
free_mmc:
|
2011-02-28 18:18:04 +03:00
|
|
|
kfree(mmc_data);
|
|
|
|
}
|
2008-12-11 04:37:17 +03:00
|
|
|
|
2012-02-20 21:43:30 +04:00
|
|
|
void __init omap_hsmmc_init(struct omap2_hsmmc_info *controllers)
|
2008-12-11 04:37:17 +03:00
|
|
|
{
|
2012-02-20 21:43:28 +04:00
|
|
|
if (omap_hsmmc_done)
|
|
|
|
return;
|
|
|
|
|
|
|
|
omap_hsmmc_done = 1;
|
|
|
|
|
2013-05-30 23:53:06 +04:00
|
|
|
if (cpu_is_omap2430()) {
|
|
|
|
control_pbias_offset = OMAP243X_CONTROL_PBIAS_LITE;
|
|
|
|
control_devconf1_offset = OMAP243X_CONTROL_DEVCONF1;
|
2008-12-11 04:37:17 +03:00
|
|
|
} else {
|
2013-05-30 23:53:06 +04:00
|
|
|
control_pbias_offset = OMAP343X_CONTROL_PBIAS_LITE;
|
|
|
|
control_devconf1_offset = OMAP343X_CONTROL_DEVCONF1;
|
2008-12-11 04:37:17 +03:00
|
|
|
}
|
|
|
|
|
2011-02-28 18:18:04 +03:00
|
|
|
for (; controllers->mmc; controllers++)
|
2012-02-20 21:43:29 +04:00
|
|
|
omap_hsmmc_init_one(controllers, controllers->mmc);
|
2009-03-24 04:23:47 +03:00
|
|
|
|
2008-12-11 04:37:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|