]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
spi: tegra: add support to enable pincontrol after setup
authorLaxman Dewangan <ldewangan@nvidia.com>
Wed, 29 Jul 2015 14:31:50 +0000 (20:01 +0530)
committerLaxman Dewangan <ldewangan@nvidia.com>
Tue, 4 Aug 2015 12:08:49 +0000 (05:08 -0700)
Some of interface required to enable SPI interface only when
spi controller is configured properly.
TO support this, add support to enable the interface through
pin-control  dynamically after configuring the controller.

bug 1650455

Change-Id: I5ff5fb889bd4ed54ce3415d04414fe04d51b176b
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
(cherry picked from commit 6edbbe5c7efac9d44a06bf7d0c383bf55c385719)
Reviewed-on: http://git-master/r/778272
GVS: Gerrit_Virtual_Submit

drivers/spi/spi-tegra114.c

index 01dc9a3e18ec967fcc3f474e4bc9b72fa822bc7d..4ae1573306f7ce918622ad0b60d7a1d5c7cfa1d8 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/kthread.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -250,6 +251,8 @@ struct tegra_spi_data {
        struct tegra_spi_device_controller_data cdata[MAX_CHIP_SELECT];
        bool                                    cs_gpio_reqstd[MAX_CHIP_SELECT];
        struct tegra_prod_list *prod_list;
+       struct pinctrl *pinctrl;
+       struct pinctrl_state *enable_interface;
 };
 
 
@@ -1779,6 +1782,21 @@ static int tegra_spi_probe(struct platform_device *pdev)
                goto exit_free_master;
        }
 
+       tspi->pinctrl = devm_pinctrl_get(&pdev->dev);
+       if (IS_ERR(tspi->pinctrl)) {
+               dev_info(&pdev->dev, "Pincontrol not found\n");
+               tspi->pinctrl = NULL;
+       }
+
+       if (tspi->pinctrl) {
+               tspi->enable_interface = pinctrl_lookup_state(tspi->pinctrl,
+                                               "interface-enable");
+               if (IS_ERR(tspi->enable_interface)) {
+                       dev_info(&pdev->dev, "Static pin configuration used\n");
+                       tspi->enable_interface = NULL;
+               }
+       }
+
        tspi->max_buf_size = SPI_FIFO_DEPTH << 2;
        tspi->dma_buf_size = (pdata->max_dma_buffer_size) ?
                                pdata->max_dma_buffer_size :
@@ -1842,8 +1860,22 @@ static int tegra_spi_probe(struct platform_device *pdev)
                dev_err(&pdev->dev, "can not register to master err %d\n", ret);
                goto exit_pm_disable;
        }
+
+       if (tspi->enable_interface) {
+               ret = pinctrl_select_state(tspi->pinctrl,
+                               tspi->enable_interface);
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "Enable pin interface failed: %d\n",
+                               ret);
+                       goto exit_master_unreg;
+               }
+       }
+
        return ret;
 
+exit_master_unreg:
+       spi_unregister_master(master);
+
 exit_pm_disable:
        pm_runtime_disable(&pdev->dev);
        if (!pm_runtime_status_suspended(&pdev->dev))