mirror of
https://github.com/torvalds/linux.git
synced 2024-12-27 21:33:00 +00:00
9c9f1ddee7
Commit b9762bebc6
("gpiolib: Pass bitmaps, not integer arrays, to
get/set array") changed the way GPIO values are passed to
gpiod_get/set_array_value() and friends. The new code introduced into
mmc_pwrseq_simple_set_gpios_value() incorrectly interpretes the 'value'
argument as a bitmap of GPIO values and assigns it directly to the
'values' bitmap variable passed to gpiod_set_array_value_cansleep()
instead of filling that bitmap with bits equal to the 'value' argument.
As a result, only member 0 of the array is handled correctly.
Moreover, wrong assumption is taken about the 'values' bitmap size not
exceding the number of bits of the 'value' argument type.
Fix it.
Signed-off-by: Janusz Krzysztofik <jmkrzyszt@gmail.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
166 lines
4.2 KiB
C
166 lines
4.2 KiB
C
/*
|
|
* Copyright (C) 2014 Linaro Ltd
|
|
*
|
|
* Author: Ulf Hansson <ulf.hansson@linaro.org>
|
|
*
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
*
|
|
* Simple MMC power sequence management
|
|
*/
|
|
#include <linux/clk.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/device.h>
|
|
#include <linux/err.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/property.h>
|
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
#include "pwrseq.h"
|
|
|
|
struct mmc_pwrseq_simple {
|
|
struct mmc_pwrseq pwrseq;
|
|
bool clk_enabled;
|
|
u32 post_power_on_delay_ms;
|
|
u32 power_off_delay_us;
|
|
struct clk *ext_clk;
|
|
struct gpio_descs *reset_gpios;
|
|
};
|
|
|
|
#define to_pwrseq_simple(p) container_of(p, struct mmc_pwrseq_simple, pwrseq)
|
|
|
|
static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq,
|
|
int value)
|
|
{
|
|
struct gpio_descs *reset_gpios = pwrseq->reset_gpios;
|
|
|
|
if (!IS_ERR(reset_gpios)) {
|
|
unsigned long *values;
|
|
int nvalues = reset_gpios->ndescs;
|
|
|
|
values = bitmap_alloc(nvalues, GFP_KERNEL);
|
|
if (!values)
|
|
return;
|
|
|
|
if (value)
|
|
bitmap_fill(values, nvalues);
|
|
else
|
|
bitmap_zero(values, nvalues);
|
|
|
|
gpiod_set_array_value_cansleep(nvalues, reset_gpios->desc,
|
|
reset_gpios->info, values);
|
|
|
|
kfree(values);
|
|
}
|
|
}
|
|
|
|
static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
|
|
{
|
|
struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
|
|
|
|
if (!IS_ERR(pwrseq->ext_clk) && !pwrseq->clk_enabled) {
|
|
clk_prepare_enable(pwrseq->ext_clk);
|
|
pwrseq->clk_enabled = true;
|
|
}
|
|
|
|
mmc_pwrseq_simple_set_gpios_value(pwrseq, 1);
|
|
}
|
|
|
|
static void mmc_pwrseq_simple_post_power_on(struct mmc_host *host)
|
|
{
|
|
struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
|
|
|
|
mmc_pwrseq_simple_set_gpios_value(pwrseq, 0);
|
|
|
|
if (pwrseq->post_power_on_delay_ms)
|
|
msleep(pwrseq->post_power_on_delay_ms);
|
|
}
|
|
|
|
static void mmc_pwrseq_simple_power_off(struct mmc_host *host)
|
|
{
|
|
struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
|
|
|
|
mmc_pwrseq_simple_set_gpios_value(pwrseq, 1);
|
|
|
|
if (pwrseq->power_off_delay_us)
|
|
usleep_range(pwrseq->power_off_delay_us,
|
|
2 * pwrseq->power_off_delay_us);
|
|
|
|
if (!IS_ERR(pwrseq->ext_clk) && pwrseq->clk_enabled) {
|
|
clk_disable_unprepare(pwrseq->ext_clk);
|
|
pwrseq->clk_enabled = false;
|
|
}
|
|
}
|
|
|
|
static const struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = {
|
|
.pre_power_on = mmc_pwrseq_simple_pre_power_on,
|
|
.post_power_on = mmc_pwrseq_simple_post_power_on,
|
|
.power_off = mmc_pwrseq_simple_power_off,
|
|
};
|
|
|
|
static const struct of_device_id mmc_pwrseq_simple_of_match[] = {
|
|
{ .compatible = "mmc-pwrseq-simple",},
|
|
{/* sentinel */},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, mmc_pwrseq_simple_of_match);
|
|
|
|
static int mmc_pwrseq_simple_probe(struct platform_device *pdev)
|
|
{
|
|
struct mmc_pwrseq_simple *pwrseq;
|
|
struct device *dev = &pdev->dev;
|
|
|
|
pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL);
|
|
if (!pwrseq)
|
|
return -ENOMEM;
|
|
|
|
pwrseq->ext_clk = devm_clk_get(dev, "ext_clock");
|
|
if (IS_ERR(pwrseq->ext_clk) && PTR_ERR(pwrseq->ext_clk) != -ENOENT)
|
|
return PTR_ERR(pwrseq->ext_clk);
|
|
|
|
pwrseq->reset_gpios = devm_gpiod_get_array(dev, "reset",
|
|
GPIOD_OUT_HIGH);
|
|
if (IS_ERR(pwrseq->reset_gpios) &&
|
|
PTR_ERR(pwrseq->reset_gpios) != -ENOENT &&
|
|
PTR_ERR(pwrseq->reset_gpios) != -ENOSYS) {
|
|
return PTR_ERR(pwrseq->reset_gpios);
|
|
}
|
|
|
|
device_property_read_u32(dev, "post-power-on-delay-ms",
|
|
&pwrseq->post_power_on_delay_ms);
|
|
device_property_read_u32(dev, "power-off-delay-us",
|
|
&pwrseq->power_off_delay_us);
|
|
|
|
pwrseq->pwrseq.dev = dev;
|
|
pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops;
|
|
pwrseq->pwrseq.owner = THIS_MODULE;
|
|
platform_set_drvdata(pdev, pwrseq);
|
|
|
|
return mmc_pwrseq_register(&pwrseq->pwrseq);
|
|
}
|
|
|
|
static int mmc_pwrseq_simple_remove(struct platform_device *pdev)
|
|
{
|
|
struct mmc_pwrseq_simple *pwrseq = platform_get_drvdata(pdev);
|
|
|
|
mmc_pwrseq_unregister(&pwrseq->pwrseq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver mmc_pwrseq_simple_driver = {
|
|
.probe = mmc_pwrseq_simple_probe,
|
|
.remove = mmc_pwrseq_simple_remove,
|
|
.driver = {
|
|
.name = "pwrseq_simple",
|
|
.of_match_table = mmc_pwrseq_simple_of_match,
|
|
},
|
|
};
|
|
|
|
module_platform_driver(mmc_pwrseq_simple_driver);
|
|
MODULE_LICENSE("GPL v2");
|