Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69d5af8d authored by Lee Jones's avatar Lee Jones Committed by Brian Norris
Browse files

mtd: st_spi_fsm: Obtain and use EMI clock



ST's Common Clk Framework is now available. This patch ensures the FSM
makes use of it by obtaining and enabling the EMI clock. If system fails
to provide the EMI clock, we bomb out.

Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent 5ecd3ea1
Loading
Loading
Loading
Loading
+38 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/clk.h>

#include "serial_flash_cmds.h"

@@ -262,6 +263,7 @@ struct stfsm {
	struct mtd_info		mtd;
	struct mutex		lock;
	struct flash_info       *info;
	struct clk              *clk;

	uint32_t                configuration;
	uint32_t                fifo_dir_delay;
@@ -1906,8 +1908,7 @@ static void stfsm_set_freq(struct stfsm *fsm, uint32_t spi_freq)
	uint32_t emi_freq;
	uint32_t clk_div;

	/* TODO: Make this dynamic */
	emi_freq = STFSM_DEFAULT_EMI_FREQ;
	emi_freq = clk_get_rate(fsm->clk);

	/*
	 * Calculate clk_div - values between 2 and 128
@@ -2057,6 +2058,18 @@ static int stfsm_probe(struct platform_device *pdev)
		return PTR_ERR(fsm->base);
	}

	fsm->clk = devm_clk_get(&pdev->dev, NULL);
	if (IS_ERR(fsm->clk)) {
		dev_err(fsm->dev, "Couldn't find EMI clock.\n");
		return PTR_ERR(fsm->clk);
	}

	ret = clk_prepare_enable(fsm->clk);
	if (ret) {
		dev_err(fsm->dev, "Failed to enable EMI clock.\n");
		return ret;
	}

	mutex_init(&fsm->lock);

	ret = stfsm_init(fsm);
@@ -2121,6 +2134,28 @@ static int stfsm_remove(struct platform_device *pdev)
	return mtd_device_unregister(&fsm->mtd);
}

#ifdef CONFIG_PM_SLEEP
static int stfsmfsm_suspend(struct device *dev)
{
	struct stfsm *fsm = dev_get_drvdata(dev);

	clk_disable_unprepare(fsm->clk);

	return 0;
}

static int stfsmfsm_resume(struct device *dev)
{
	struct stfsm *fsm = dev_get_drvdata(dev);

	clk_prepare_enable(fsm->clk);

	return 0;
}
#endif

static SIMPLE_DEV_PM_OPS(stfsm_pm_ops, stfsmfsm_suspend, stfsmfsm_resume);

static const struct of_device_id stfsm_match[] = {
	{ .compatible = "st,spi-fsm", },
	{},
@@ -2133,6 +2168,7 @@ static struct platform_driver stfsm_driver = {
	.driver		= {
		.name	= "st-spi-fsm",
		.of_match_table = stfsm_match,
		.pm     = &stfsm_pm_ops,
	},
};
module_platform_driver(stfsm_driver);