From: Maxime Coquelin <maxime.coquelin-qxv4g6HH51o@public.gmane.org>
To: Lee Jones <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: <devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
<broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
<kernel-F5mvAk5X5gdBDgjK7y7TUQ@public.gmane.org>,
<linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [PATCH 1/4] spi: Add new driver for STMicroelectronics' SPI Controller
Date: Thu, 27 Nov 2014 14:24:08 +0100 [thread overview]
Message-ID: <547725F8.1050106@st.com> (raw)
In-Reply-To: <1417088636-11994-2-git-send-email-lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
On 11/27/2014 12:43 PM, Lee Jones wrote:
> This patch adds support for the SPI portion of ST's SSC device.
>
> Signed-off-by: Lee Jones <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> drivers/spi/Kconfig | 8 +
> drivers/spi/Makefile | 1 +
> drivers/spi/spi-st.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 544 insertions(+)
> create mode 100644 drivers/spi/spi-st.c
<snip>
> +
> +static int spi_st_probe(struct platform_device *pdev)
> +{
> + struct device_node *np = pdev->dev.of_node;
> + struct device *dev = &pdev->dev;
> + struct spi_master *master;
> + struct resource *res;
> + struct spi_st *spi_st;
> + int num_cs, cs_gpio, i, ret = 0;
> + u32 var;
> +
> + printk("LEE: %s: %s()[%d]: Probing\n", __FILE__, __func__, __LINE__);
> +
> + master = spi_alloc_master(&pdev->dev, sizeof(*spi_st));
> + if (!master) {
> + dev_err(&pdev->dev, "failed to allocate spi master\n");
> + return -ENOMEM;
> + }
> + spi_st = spi_master_get_devdata(master);
> +
> + if (!IS_ERR(dev->pins->p)) {
> + spi_st->pins_sleep =
> + pinctrl_lookup_state(dev->pins->p, PINCTRL_STATE_SLEEP);
> + if (IS_ERR(spi_st->pins_sleep))
> + dev_warn(&pdev->dev, "could not get sleep pinstate\n");
> + }
> +
> + num_cs = of_gpio_named_count(np, "cs-gpios");
> +
> + for (i = 0; i < num_cs; i++) {
> + cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
> +
> + if (!gpio_is_valid(cs_gpio)) {
> + dev_err(&pdev->dev,
> + "%d is not a valid gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> +
> + if (devm_gpio_request(&pdev->dev, cs_gpio, pdev->name)) {
> + dev_err(&pdev->dev,
> + "could not request %d gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> + }
> +
> + spi_st->clk = of_clk_get_by_name(np, "ssc");
> + if (IS_ERR(spi_st->clk)) {
> + dev_err(&pdev->dev, "Unable to request clock\n");
> + ret = PTR_ERR(spi_st->clk);
> + goto free_master;
> + }
> +
> + ret = clk_prepare_enable(spi_st->clk);
> + if (ret)
> + goto free_master;
> +
> + master->dev.of_node = np;
> + master->bus_num = pdev->id;
> + master->mode_bits = MODEBITS;
> + spi_st->bitbang.master = spi_master_get(master);
> + spi_st->bitbang.setup_transfer = spi_st_setup_transfer;
> + spi_st->bitbang.txrx_bufs = spi_st_txrx_bufs;
> + spi_st->bitbang.master->setup = spi_st_setup;
> + spi_st->bitbang.master->cleanup = spi_st_cleanup;
> + spi_st->bitbang.chipselect = spi_st_gpio_chipselect;
> + spi_st->dev = dev;
> +
> + init_completion(&spi_st->done);
> +
> + /* Get resources */
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + spi_st->base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(spi_st->base)) {
> + ret = PTR_ERR(spi_st->base);
> + goto clk_disable;
> + }
> +
> + spi_st->irq = irq_of_parse_and_map(np, 0);
> + if (!spi_st->irq) {
> + dev_err(&pdev->dev, "IRQ missing or invalid\n");
> + ret = -EINVAL;
> + goto clk_disable;
> + }
> +
> + ret = devm_request_irq(&pdev->dev, spi_st->irq, spi_st_irq, 0,
> + pdev->name, spi_st);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to request irq %d\n", spi_st->irq);
> + goto clk_disable;
> + }
> +
> + /* Disable I2C and Reset SSC */
> + writel_relaxed(0x0, spi_st->base + SSC_I2C);
> + var = readw(spi_st->base + SSC_CTL);
Why not readw_relaxed to be consistent with readl:s?
> + var |= SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + udelay(1);
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Set SSC into slave mode before reconfiguring PIO pins */
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_MS;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Start "bitbang" worker */
> + ret = spi_bitbang_start(&spi_st->bitbang);
> + if (ret) {
> + dev_err(&pdev->dev, "bitbang start failed [%d]\n", ret);
> + goto clk_disable;
> + }
> +
> + dev_info(&pdev->dev, "registered SPI Bus %d\n", master->bus_num);
> +
> + platform_set_drvdata(pdev, master);
Shouldn't you call devm_spi_register_master ?
> +
> + /* by default the device is on */
> + pm_runtime_set_active(&pdev->dev);
> + pm_runtime_enable(&pdev->dev);
> +
> + return 0;
> +
> +clk_disable:
> + clk_disable_unprepare(spi_st->clk);
> +free_master:
> + spi_master_put(master);
> +
> + return ret;
> +}
> +
> +static int spi_st_remove(struct platform_device *pdev)
> +{
> + struct spi_master *master = platform_get_drvdata(pdev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + spi_bitbang_stop(&spi_st->bitbang);
> + clk_disable_unprepare(spi_st->clk);
> +
> + if (spi_st->pins_sleep)
> + pinctrl_select_state(pdev->dev.pins->p, spi_st->pins_sleep);
You should use pinctrl_pm_select_sleep_state(dev); instead.
> +
> + spi_master_put(spi_st->bitbang.master);
If you use devm_spi_register_master at probe time,
you shouldn't need to call spi_master_put IIUC.
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int spi_st_suspend(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + writel_relaxed(0, spi_st->base + SSC_IEN);
> +
> + if (!IS_ERR(spi_st->pins_sleep))
> + pinctrl_select_state(dev->pins->p, spi_st->pins_sleep);
Ditto
> +
> + clk_disable_unprepare(spi_st->clk);
> +
> + return 0;
> +}
> +
> +static int spi_st_resume(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> + int ret;
> +
> + ret = clk_prepare_enable(spi_st->clk);
> +
> + if (!IS_ERR(dev->pins->default_state))
> + pinctrl_select_state(dev->pins->p, dev->pins->default_state);
pinctrl_pm_select_default_state(i2c_dev->dev);
pinctrl_pm_select_idle_state(i2c_dev->dev);
> +
> + return ret;
> +}
> +#endif
> +
> +static SIMPLE_DEV_PM_OPS(spi_st_pm, spi_st_suspend, spi_st_resume);
> +
> +static struct of_device_id stm_spi_match[] = {
> + { .compatible = "st,comms-ssc-spi", },
> + { .compatible = "st,comms-ssc4-spi", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, stm_spi_match);
> +
> +static struct platform_driver spi_st_driver = {
> + .driver = {
> + .name = "spi-st",
> + .pm = &spi_st_pm,
> + .of_match_table = of_match_ptr(stm_spi_match),
> + },
> + .probe = spi_st_probe,
> + .remove = spi_st_remove,
> +};
> +module_platform_driver(spi_st_driver);
> +
> +MODULE_AUTHOR("Patrice Chotard <patrice.chotard-qxv4g6HH51o@public.gmane.org>");
> +MODULE_DESCRIPTION("STM SSC SPI driver");
> +MODULE_LICENSE("GPL v2");
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: maxime.coquelin@st.com (Maxime Coquelin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] spi: Add new driver for STMicroelectronics' SPI Controller
Date: Thu, 27 Nov 2014 14:24:08 +0100 [thread overview]
Message-ID: <547725F8.1050106@st.com> (raw)
In-Reply-To: <1417088636-11994-2-git-send-email-lee.jones@linaro.org>
On 11/27/2014 12:43 PM, Lee Jones wrote:
> This patch adds support for the SPI portion of ST's SSC device.
>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
> drivers/spi/Kconfig | 8 +
> drivers/spi/Makefile | 1 +
> drivers/spi/spi-st.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 544 insertions(+)
> create mode 100644 drivers/spi/spi-st.c
<snip>
> +
> +static int spi_st_probe(struct platform_device *pdev)
> +{
> + struct device_node *np = pdev->dev.of_node;
> + struct device *dev = &pdev->dev;
> + struct spi_master *master;
> + struct resource *res;
> + struct spi_st *spi_st;
> + int num_cs, cs_gpio, i, ret = 0;
> + u32 var;
> +
> + printk("LEE: %s: %s()[%d]: Probing\n", __FILE__, __func__, __LINE__);
> +
> + master = spi_alloc_master(&pdev->dev, sizeof(*spi_st));
> + if (!master) {
> + dev_err(&pdev->dev, "failed to allocate spi master\n");
> + return -ENOMEM;
> + }
> + spi_st = spi_master_get_devdata(master);
> +
> + if (!IS_ERR(dev->pins->p)) {
> + spi_st->pins_sleep =
> + pinctrl_lookup_state(dev->pins->p, PINCTRL_STATE_SLEEP);
> + if (IS_ERR(spi_st->pins_sleep))
> + dev_warn(&pdev->dev, "could not get sleep pinstate\n");
> + }
> +
> + num_cs = of_gpio_named_count(np, "cs-gpios");
> +
> + for (i = 0; i < num_cs; i++) {
> + cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
> +
> + if (!gpio_is_valid(cs_gpio)) {
> + dev_err(&pdev->dev,
> + "%d is not a valid gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> +
> + if (devm_gpio_request(&pdev->dev, cs_gpio, pdev->name)) {
> + dev_err(&pdev->dev,
> + "could not request %d gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> + }
> +
> + spi_st->clk = of_clk_get_by_name(np, "ssc");
> + if (IS_ERR(spi_st->clk)) {
> + dev_err(&pdev->dev, "Unable to request clock\n");
> + ret = PTR_ERR(spi_st->clk);
> + goto free_master;
> + }
> +
> + ret = clk_prepare_enable(spi_st->clk);
> + if (ret)
> + goto free_master;
> +
> + master->dev.of_node = np;
> + master->bus_num = pdev->id;
> + master->mode_bits = MODEBITS;
> + spi_st->bitbang.master = spi_master_get(master);
> + spi_st->bitbang.setup_transfer = spi_st_setup_transfer;
> + spi_st->bitbang.txrx_bufs = spi_st_txrx_bufs;
> + spi_st->bitbang.master->setup = spi_st_setup;
> + spi_st->bitbang.master->cleanup = spi_st_cleanup;
> + spi_st->bitbang.chipselect = spi_st_gpio_chipselect;
> + spi_st->dev = dev;
> +
> + init_completion(&spi_st->done);
> +
> + /* Get resources */
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + spi_st->base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(spi_st->base)) {
> + ret = PTR_ERR(spi_st->base);
> + goto clk_disable;
> + }
> +
> + spi_st->irq = irq_of_parse_and_map(np, 0);
> + if (!spi_st->irq) {
> + dev_err(&pdev->dev, "IRQ missing or invalid\n");
> + ret = -EINVAL;
> + goto clk_disable;
> + }
> +
> + ret = devm_request_irq(&pdev->dev, spi_st->irq, spi_st_irq, 0,
> + pdev->name, spi_st);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to request irq %d\n", spi_st->irq);
> + goto clk_disable;
> + }
> +
> + /* Disable I2C and Reset SSC */
> + writel_relaxed(0x0, spi_st->base + SSC_I2C);
> + var = readw(spi_st->base + SSC_CTL);
Why not readw_relaxed to be consistent with readl:s?
> + var |= SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + udelay(1);
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Set SSC into slave mode before reconfiguring PIO pins */
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_MS;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Start "bitbang" worker */
> + ret = spi_bitbang_start(&spi_st->bitbang);
> + if (ret) {
> + dev_err(&pdev->dev, "bitbang start failed [%d]\n", ret);
> + goto clk_disable;
> + }
> +
> + dev_info(&pdev->dev, "registered SPI Bus %d\n", master->bus_num);
> +
> + platform_set_drvdata(pdev, master);
Shouldn't you call devm_spi_register_master ?
> +
> + /* by default the device is on */
> + pm_runtime_set_active(&pdev->dev);
> + pm_runtime_enable(&pdev->dev);
> +
> + return 0;
> +
> +clk_disable:
> + clk_disable_unprepare(spi_st->clk);
> +free_master:
> + spi_master_put(master);
> +
> + return ret;
> +}
> +
> +static int spi_st_remove(struct platform_device *pdev)
> +{
> + struct spi_master *master = platform_get_drvdata(pdev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + spi_bitbang_stop(&spi_st->bitbang);
> + clk_disable_unprepare(spi_st->clk);
> +
> + if (spi_st->pins_sleep)
> + pinctrl_select_state(pdev->dev.pins->p, spi_st->pins_sleep);
You should use pinctrl_pm_select_sleep_state(dev); instead.
> +
> + spi_master_put(spi_st->bitbang.master);
If you use devm_spi_register_master at probe time,
you shouldn't need to call spi_master_put IIUC.
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int spi_st_suspend(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + writel_relaxed(0, spi_st->base + SSC_IEN);
> +
> + if (!IS_ERR(spi_st->pins_sleep))
> + pinctrl_select_state(dev->pins->p, spi_st->pins_sleep);
Ditto
> +
> + clk_disable_unprepare(spi_st->clk);
> +
> + return 0;
> +}
> +
> +static int spi_st_resume(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> + int ret;
> +
> + ret = clk_prepare_enable(spi_st->clk);
> +
> + if (!IS_ERR(dev->pins->default_state))
> + pinctrl_select_state(dev->pins->p, dev->pins->default_state);
pinctrl_pm_select_default_state(i2c_dev->dev);
pinctrl_pm_select_idle_state(i2c_dev->dev);
> +
> + return ret;
> +}
> +#endif
> +
> +static SIMPLE_DEV_PM_OPS(spi_st_pm, spi_st_suspend, spi_st_resume);
> +
> +static struct of_device_id stm_spi_match[] = {
> + { .compatible = "st,comms-ssc-spi", },
> + { .compatible = "st,comms-ssc4-spi", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, stm_spi_match);
> +
> +static struct platform_driver spi_st_driver = {
> + .driver = {
> + .name = "spi-st",
> + .pm = &spi_st_pm,
> + .of_match_table = of_match_ptr(stm_spi_match),
> + },
> + .probe = spi_st_probe,
> + .remove = spi_st_remove,
> +};
> +module_platform_driver(spi_st_driver);
> +
> +MODULE_AUTHOR("Patrice Chotard <patrice.chotard@st.com>");
> +MODULE_DESCRIPTION("STM SSC SPI driver");
> +MODULE_LICENSE("GPL v2");
WARNING: multiple messages have this Message-ID (diff)
From: Maxime Coquelin <maxime.coquelin-qxv4g6HH51o@public.gmane.org>
To: Lee Jones <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
kernel-F5mvAk5X5gdBDgjK7y7TUQ@public.gmane.org,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/4] spi: Add new driver for STMicroelectronics' SPI Controller
Date: Thu, 27 Nov 2014 14:24:08 +0100 [thread overview]
Message-ID: <547725F8.1050106@st.com> (raw)
In-Reply-To: <1417088636-11994-2-git-send-email-lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
On 11/27/2014 12:43 PM, Lee Jones wrote:
> This patch adds support for the SPI portion of ST's SSC device.
>
> Signed-off-by: Lee Jones <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> drivers/spi/Kconfig | 8 +
> drivers/spi/Makefile | 1 +
> drivers/spi/spi-st.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 544 insertions(+)
> create mode 100644 drivers/spi/spi-st.c
<snip>
> +
> +static int spi_st_probe(struct platform_device *pdev)
> +{
> + struct device_node *np = pdev->dev.of_node;
> + struct device *dev = &pdev->dev;
> + struct spi_master *master;
> + struct resource *res;
> + struct spi_st *spi_st;
> + int num_cs, cs_gpio, i, ret = 0;
> + u32 var;
> +
> + printk("LEE: %s: %s()[%d]: Probing\n", __FILE__, __func__, __LINE__);
> +
> + master = spi_alloc_master(&pdev->dev, sizeof(*spi_st));
> + if (!master) {
> + dev_err(&pdev->dev, "failed to allocate spi master\n");
> + return -ENOMEM;
> + }
> + spi_st = spi_master_get_devdata(master);
> +
> + if (!IS_ERR(dev->pins->p)) {
> + spi_st->pins_sleep =
> + pinctrl_lookup_state(dev->pins->p, PINCTRL_STATE_SLEEP);
> + if (IS_ERR(spi_st->pins_sleep))
> + dev_warn(&pdev->dev, "could not get sleep pinstate\n");
> + }
> +
> + num_cs = of_gpio_named_count(np, "cs-gpios");
> +
> + for (i = 0; i < num_cs; i++) {
> + cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
> +
> + if (!gpio_is_valid(cs_gpio)) {
> + dev_err(&pdev->dev,
> + "%d is not a valid gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> +
> + if (devm_gpio_request(&pdev->dev, cs_gpio, pdev->name)) {
> + dev_err(&pdev->dev,
> + "could not request %d gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> + }
> +
> + spi_st->clk = of_clk_get_by_name(np, "ssc");
> + if (IS_ERR(spi_st->clk)) {
> + dev_err(&pdev->dev, "Unable to request clock\n");
> + ret = PTR_ERR(spi_st->clk);
> + goto free_master;
> + }
> +
> + ret = clk_prepare_enable(spi_st->clk);
> + if (ret)
> + goto free_master;
> +
> + master->dev.of_node = np;
> + master->bus_num = pdev->id;
> + master->mode_bits = MODEBITS;
> + spi_st->bitbang.master = spi_master_get(master);
> + spi_st->bitbang.setup_transfer = spi_st_setup_transfer;
> + spi_st->bitbang.txrx_bufs = spi_st_txrx_bufs;
> + spi_st->bitbang.master->setup = spi_st_setup;
> + spi_st->bitbang.master->cleanup = spi_st_cleanup;
> + spi_st->bitbang.chipselect = spi_st_gpio_chipselect;
> + spi_st->dev = dev;
> +
> + init_completion(&spi_st->done);
> +
> + /* Get resources */
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + spi_st->base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(spi_st->base)) {
> + ret = PTR_ERR(spi_st->base);
> + goto clk_disable;
> + }
> +
> + spi_st->irq = irq_of_parse_and_map(np, 0);
> + if (!spi_st->irq) {
> + dev_err(&pdev->dev, "IRQ missing or invalid\n");
> + ret = -EINVAL;
> + goto clk_disable;
> + }
> +
> + ret = devm_request_irq(&pdev->dev, spi_st->irq, spi_st_irq, 0,
> + pdev->name, spi_st);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to request irq %d\n", spi_st->irq);
> + goto clk_disable;
> + }
> +
> + /* Disable I2C and Reset SSC */
> + writel_relaxed(0x0, spi_st->base + SSC_I2C);
> + var = readw(spi_st->base + SSC_CTL);
Why not readw_relaxed to be consistent with readl:s?
> + var |= SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + udelay(1);
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Set SSC into slave mode before reconfiguring PIO pins */
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_MS;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Start "bitbang" worker */
> + ret = spi_bitbang_start(&spi_st->bitbang);
> + if (ret) {
> + dev_err(&pdev->dev, "bitbang start failed [%d]\n", ret);
> + goto clk_disable;
> + }
> +
> + dev_info(&pdev->dev, "registered SPI Bus %d\n", master->bus_num);
> +
> + platform_set_drvdata(pdev, master);
Shouldn't you call devm_spi_register_master ?
> +
> + /* by default the device is on */
> + pm_runtime_set_active(&pdev->dev);
> + pm_runtime_enable(&pdev->dev);
> +
> + return 0;
> +
> +clk_disable:
> + clk_disable_unprepare(spi_st->clk);
> +free_master:
> + spi_master_put(master);
> +
> + return ret;
> +}
> +
> +static int spi_st_remove(struct platform_device *pdev)
> +{
> + struct spi_master *master = platform_get_drvdata(pdev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + spi_bitbang_stop(&spi_st->bitbang);
> + clk_disable_unprepare(spi_st->clk);
> +
> + if (spi_st->pins_sleep)
> + pinctrl_select_state(pdev->dev.pins->p, spi_st->pins_sleep);
You should use pinctrl_pm_select_sleep_state(dev); instead.
> +
> + spi_master_put(spi_st->bitbang.master);
If you use devm_spi_register_master at probe time,
you shouldn't need to call spi_master_put IIUC.
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int spi_st_suspend(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + writel_relaxed(0, spi_st->base + SSC_IEN);
> +
> + if (!IS_ERR(spi_st->pins_sleep))
> + pinctrl_select_state(dev->pins->p, spi_st->pins_sleep);
Ditto
> +
> + clk_disable_unprepare(spi_st->clk);
> +
> + return 0;
> +}
> +
> +static int spi_st_resume(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> + int ret;
> +
> + ret = clk_prepare_enable(spi_st->clk);
> +
> + if (!IS_ERR(dev->pins->default_state))
> + pinctrl_select_state(dev->pins->p, dev->pins->default_state);
pinctrl_pm_select_default_state(i2c_dev->dev);
pinctrl_pm_select_idle_state(i2c_dev->dev);
> +
> + return ret;
> +}
> +#endif
> +
> +static SIMPLE_DEV_PM_OPS(spi_st_pm, spi_st_suspend, spi_st_resume);
> +
> +static struct of_device_id stm_spi_match[] = {
> + { .compatible = "st,comms-ssc-spi", },
> + { .compatible = "st,comms-ssc4-spi", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, stm_spi_match);
> +
> +static struct platform_driver spi_st_driver = {
> + .driver = {
> + .name = "spi-st",
> + .pm = &spi_st_pm,
> + .of_match_table = of_match_ptr(stm_spi_match),
> + },
> + .probe = spi_st_probe,
> + .remove = spi_st_remove,
> +};
> +module_platform_driver(spi_st_driver);
> +
> +MODULE_AUTHOR("Patrice Chotard <patrice.chotard-qxv4g6HH51o@public.gmane.org>");
> +MODULE_DESCRIPTION("STM SSC SPI driver");
> +MODULE_LICENSE("GPL v2");
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Maxime Coquelin <maxime.coquelin@st.com>
To: Lee Jones <lee.jones@linaro.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Cc: <devicetree@vger.kernel.org>, <broonie@kernel.org>,
<kernel@stlinux.com>, <linux-spi@vger.kernel.org>
Subject: Re: [PATCH 1/4] spi: Add new driver for STMicroelectronics' SPI Controller
Date: Thu, 27 Nov 2014 14:24:08 +0100 [thread overview]
Message-ID: <547725F8.1050106@st.com> (raw)
In-Reply-To: <1417088636-11994-2-git-send-email-lee.jones@linaro.org>
On 11/27/2014 12:43 PM, Lee Jones wrote:
> This patch adds support for the SPI portion of ST's SSC device.
>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
> drivers/spi/Kconfig | 8 +
> drivers/spi/Makefile | 1 +
> drivers/spi/spi-st.c | 535 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 544 insertions(+)
> create mode 100644 drivers/spi/spi-st.c
<snip>
> +
> +static int spi_st_probe(struct platform_device *pdev)
> +{
> + struct device_node *np = pdev->dev.of_node;
> + struct device *dev = &pdev->dev;
> + struct spi_master *master;
> + struct resource *res;
> + struct spi_st *spi_st;
> + int num_cs, cs_gpio, i, ret = 0;
> + u32 var;
> +
> + printk("LEE: %s: %s()[%d]: Probing\n", __FILE__, __func__, __LINE__);
> +
> + master = spi_alloc_master(&pdev->dev, sizeof(*spi_st));
> + if (!master) {
> + dev_err(&pdev->dev, "failed to allocate spi master\n");
> + return -ENOMEM;
> + }
> + spi_st = spi_master_get_devdata(master);
> +
> + if (!IS_ERR(dev->pins->p)) {
> + spi_st->pins_sleep =
> + pinctrl_lookup_state(dev->pins->p, PINCTRL_STATE_SLEEP);
> + if (IS_ERR(spi_st->pins_sleep))
> + dev_warn(&pdev->dev, "could not get sleep pinstate\n");
> + }
> +
> + num_cs = of_gpio_named_count(np, "cs-gpios");
> +
> + for (i = 0; i < num_cs; i++) {
> + cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
> +
> + if (!gpio_is_valid(cs_gpio)) {
> + dev_err(&pdev->dev,
> + "%d is not a valid gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> +
> + if (devm_gpio_request(&pdev->dev, cs_gpio, pdev->name)) {
> + dev_err(&pdev->dev,
> + "could not request %d gpio\n", cs_gpio);
> + return -EINVAL;
> + }
> + }
> +
> + spi_st->clk = of_clk_get_by_name(np, "ssc");
> + if (IS_ERR(spi_st->clk)) {
> + dev_err(&pdev->dev, "Unable to request clock\n");
> + ret = PTR_ERR(spi_st->clk);
> + goto free_master;
> + }
> +
> + ret = clk_prepare_enable(spi_st->clk);
> + if (ret)
> + goto free_master;
> +
> + master->dev.of_node = np;
> + master->bus_num = pdev->id;
> + master->mode_bits = MODEBITS;
> + spi_st->bitbang.master = spi_master_get(master);
> + spi_st->bitbang.setup_transfer = spi_st_setup_transfer;
> + spi_st->bitbang.txrx_bufs = spi_st_txrx_bufs;
> + spi_st->bitbang.master->setup = spi_st_setup;
> + spi_st->bitbang.master->cleanup = spi_st_cleanup;
> + spi_st->bitbang.chipselect = spi_st_gpio_chipselect;
> + spi_st->dev = dev;
> +
> + init_completion(&spi_st->done);
> +
> + /* Get resources */
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + spi_st->base = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(spi_st->base)) {
> + ret = PTR_ERR(spi_st->base);
> + goto clk_disable;
> + }
> +
> + spi_st->irq = irq_of_parse_and_map(np, 0);
> + if (!spi_st->irq) {
> + dev_err(&pdev->dev, "IRQ missing or invalid\n");
> + ret = -EINVAL;
> + goto clk_disable;
> + }
> +
> + ret = devm_request_irq(&pdev->dev, spi_st->irq, spi_st_irq, 0,
> + pdev->name, spi_st);
> + if (ret) {
> + dev_err(&pdev->dev, "Failed to request irq %d\n", spi_st->irq);
> + goto clk_disable;
> + }
> +
> + /* Disable I2C and Reset SSC */
> + writel_relaxed(0x0, spi_st->base + SSC_I2C);
> + var = readw(spi_st->base + SSC_CTL);
Why not readw_relaxed to be consistent with readl:s?
> + var |= SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + udelay(1);
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_SR;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Set SSC into slave mode before reconfiguring PIO pins */
> + var = readl_relaxed(spi_st->base + SSC_CTL);
> + var &= ~SSC_CTL_MS;
> + writel_relaxed(var, spi_st->base + SSC_CTL);
> +
> + /* Start "bitbang" worker */
> + ret = spi_bitbang_start(&spi_st->bitbang);
> + if (ret) {
> + dev_err(&pdev->dev, "bitbang start failed [%d]\n", ret);
> + goto clk_disable;
> + }
> +
> + dev_info(&pdev->dev, "registered SPI Bus %d\n", master->bus_num);
> +
> + platform_set_drvdata(pdev, master);
Shouldn't you call devm_spi_register_master ?
> +
> + /* by default the device is on */
> + pm_runtime_set_active(&pdev->dev);
> + pm_runtime_enable(&pdev->dev);
> +
> + return 0;
> +
> +clk_disable:
> + clk_disable_unprepare(spi_st->clk);
> +free_master:
> + spi_master_put(master);
> +
> + return ret;
> +}
> +
> +static int spi_st_remove(struct platform_device *pdev)
> +{
> + struct spi_master *master = platform_get_drvdata(pdev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + spi_bitbang_stop(&spi_st->bitbang);
> + clk_disable_unprepare(spi_st->clk);
> +
> + if (spi_st->pins_sleep)
> + pinctrl_select_state(pdev->dev.pins->p, spi_st->pins_sleep);
You should use pinctrl_pm_select_sleep_state(dev); instead.
> +
> + spi_master_put(spi_st->bitbang.master);
If you use devm_spi_register_master at probe time,
you shouldn't need to call spi_master_put IIUC.
> +
> + return 0;
> +}
> +
> +#ifdef CONFIG_PM_SLEEP
> +static int spi_st_suspend(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> +
> + writel_relaxed(0, spi_st->base + SSC_IEN);
> +
> + if (!IS_ERR(spi_st->pins_sleep))
> + pinctrl_select_state(dev->pins->p, spi_st->pins_sleep);
Ditto
> +
> + clk_disable_unprepare(spi_st->clk);
> +
> + return 0;
> +}
> +
> +static int spi_st_resume(struct device *dev)
> +{
> + struct spi_master *master = dev_get_drvdata(dev);
> + struct spi_st *spi_st = spi_master_get_devdata(master);
> + int ret;
> +
> + ret = clk_prepare_enable(spi_st->clk);
> +
> + if (!IS_ERR(dev->pins->default_state))
> + pinctrl_select_state(dev->pins->p, dev->pins->default_state);
pinctrl_pm_select_default_state(i2c_dev->dev);
pinctrl_pm_select_idle_state(i2c_dev->dev);
> +
> + return ret;
> +}
> +#endif
> +
> +static SIMPLE_DEV_PM_OPS(spi_st_pm, spi_st_suspend, spi_st_resume);
> +
> +static struct of_device_id stm_spi_match[] = {
> + { .compatible = "st,comms-ssc-spi", },
> + { .compatible = "st,comms-ssc4-spi", },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, stm_spi_match);
> +
> +static struct platform_driver spi_st_driver = {
> + .driver = {
> + .name = "spi-st",
> + .pm = &spi_st_pm,
> + .of_match_table = of_match_ptr(stm_spi_match),
> + },
> + .probe = spi_st_probe,
> + .remove = spi_st_remove,
> +};
> +module_platform_driver(spi_st_driver);
> +
> +MODULE_AUTHOR("Patrice Chotard <patrice.chotard@st.com>");
> +MODULE_DESCRIPTION("STM SSC SPI driver");
> +MODULE_LICENSE("GPL v2");
next prev parent reply other threads:[~2014-11-27 13:24 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 11:43 [PATCH 0/4] spi: st: New driver for ST's SPI Controller Lee Jones
2014-11-27 11:43 ` Lee Jones
2014-11-27 11:43 ` Lee Jones
2014-11-27 11:43 ` [PATCH 1/4] spi: Add new driver for STMicroelectronics' " Lee Jones
2014-11-27 11:43 ` Lee Jones
2014-11-27 12:33 ` [STLinux Kernel] " Peter Griffin
2014-11-27 12:33 ` Peter Griffin
2014-11-27 12:33 ` Peter Griffin
[not found] ` <1417088636-11994-2-git-send-email-lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-11-27 12:59 ` Mark Brown
2014-11-27 12:59 ` Mark Brown
2014-11-27 12:59 ` Mark Brown
[not found] ` <20141127125904.GV7712-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-11-27 15:05 ` Lee Jones
2014-11-27 15:05 ` Lee Jones
2014-11-27 15:05 ` Lee Jones
2014-11-27 16:24 ` Mark Brown
2014-11-27 16:24 ` Mark Brown
2014-11-27 16:24 ` Mark Brown
2014-11-27 13:24 ` Maxime Coquelin [this message]
2014-11-27 13:24 ` Maxime Coquelin
2014-11-27 13:24 ` Maxime Coquelin
2014-11-27 13:24 ` Maxime Coquelin
2014-11-27 11:43 ` [PATCH 2/4] spi: st: Provide Device Tree binding documentation Lee Jones
2014-11-27 11:43 ` Lee Jones
[not found] ` <1417088636-11994-3-git-send-email-lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-11-27 13:00 ` Mark Brown
2014-11-27 13:00 ` Mark Brown
2014-11-27 13:00 ` Mark Brown
[not found] ` <20141127130053.GW7712-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2014-11-27 14:55 ` Lee Jones
2014-11-27 14:55 ` Lee Jones
2014-11-27 14:55 ` Lee Jones
2014-11-27 16:30 ` Mark Brown
2014-11-27 16:30 ` Mark Brown
2014-11-27 16:30 ` Mark Brown
[not found] ` <1417088636-11994-1-git-send-email-lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2014-11-27 11:43 ` [PATCH 3/4] ARM: sti: Provide DT nodes for SSC[0..4] Lee Jones
2014-11-27 11:43 ` Lee Jones
2014-11-27 11:43 ` Lee Jones
2014-11-27 11:43 ` [PATCH 4/4] ARM: sti: Provide DT nodes for SBC SSC[0..2] Lee Jones
2014-11-27 11:43 ` Lee Jones
2014-11-27 11:43 ` Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=547725F8.1050106@st.com \
--to=maxime.coquelin-qxv4g6hh51o@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=kernel-F5mvAk5X5gdBDgjK7y7TUQ@public.gmane.org \
--cc=lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.