aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-pl022.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-pl022.c')
-rw-r--r--drivers/spi/spi-pl022.c251
1 files changed, 208 insertions, 43 deletions
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 6abbe23c39b4..919464102d33 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * A driver for the ARM PL022 PrimeCell SSP/SPI bus master. 2 * A driver for the ARM PL022 PrimeCell SSP/SPI bus master.
3 * 3 *
4 * Copyright (C) 2008-2009 ST-Ericsson AB 4 * Copyright (C) 2008-2012 ST-Ericsson AB
5 * Copyright (C) 2006 STMicroelectronics Pvt. Ltd. 5 * Copyright (C) 2006 STMicroelectronics Pvt. Ltd.
6 * 6 *
7 * Author: Linus Walleij <linus.walleij@stericsson.com> 7 * Author: Linus Walleij <linus.walleij@stericsson.com>
@@ -40,6 +40,9 @@
40#include <linux/dma-mapping.h> 40#include <linux/dma-mapping.h>
41#include <linux/scatterlist.h> 41#include <linux/scatterlist.h>
42#include <linux/pm_runtime.h> 42#include <linux/pm_runtime.h>
43#include <linux/gpio.h>
44#include <linux/of_gpio.h>
45#include <linux/pinctrl/consumer.h>
43 46
44/* 47/*
45 * This macro is used to define some register default values. 48 * This macro is used to define some register default values.
@@ -356,6 +359,8 @@ struct vendor_data {
356 * @sgt_rx: scattertable for the RX transfer 359 * @sgt_rx: scattertable for the RX transfer
357 * @sgt_tx: scattertable for the TX transfer 360 * @sgt_tx: scattertable for the TX transfer
358 * @dummypage: a dummy page used for driving data on the bus with DMA 361 * @dummypage: a dummy page used for driving data on the bus with DMA
362 * @cur_cs: current chip select (gpio)
363 * @chipselects: list of chipselects (gpios)
359 */ 364 */
360struct pl022 { 365struct pl022 {
361 struct amba_device *adev; 366 struct amba_device *adev;
@@ -363,6 +368,10 @@ struct pl022 {
363 resource_size_t phybase; 368 resource_size_t phybase;
364 void __iomem *virtbase; 369 void __iomem *virtbase;
365 struct clk *clk; 370 struct clk *clk;
371 /* Two optional pin states - default & sleep */
372 struct pinctrl *pinctrl;
373 struct pinctrl_state *pins_default;
374 struct pinctrl_state *pins_sleep;
366 struct spi_master *master; 375 struct spi_master *master;
367 struct pl022_ssp_controller *master_info; 376 struct pl022_ssp_controller *master_info;
368 /* Message per-transfer pump */ 377 /* Message per-transfer pump */
@@ -389,6 +398,8 @@ struct pl022 {
389 char *dummypage; 398 char *dummypage;
390 bool dma_running; 399 bool dma_running;
391#endif 400#endif
401 int cur_cs;
402 int *chipselects;
392}; 403};
393 404
394/** 405/**
@@ -433,6 +444,14 @@ static void null_cs_control(u32 command)
433 pr_debug("pl022: dummy chip select control, CS=0x%x\n", command); 444 pr_debug("pl022: dummy chip select control, CS=0x%x\n", command);
434} 445}
435 446
447static void pl022_cs_control(struct pl022 *pl022, u32 command)
448{
449 if (gpio_is_valid(pl022->cur_cs))
450 gpio_set_value(pl022->cur_cs, command);
451 else
452 pl022->cur_chip->cs_control(command);
453}
454
436/** 455/**
437 * giveback - current spi_message is over, schedule next message and call 456 * giveback - current spi_message is over, schedule next message and call
438 * callback of this message. Assumes that caller already 457 * callback of this message. Assumes that caller already
@@ -479,7 +498,7 @@ static void giveback(struct pl022 *pl022)
479 if (next_msg && next_msg->spi != pl022->cur_msg->spi) 498 if (next_msg && next_msg->spi != pl022->cur_msg->spi)
480 next_msg = NULL; 499 next_msg = NULL;
481 if (!next_msg || pl022->cur_msg->state == STATE_ERROR) 500 if (!next_msg || pl022->cur_msg->state == STATE_ERROR)
482 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT); 501 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
483 else 502 else
484 pl022->next_msg_cs_active = true; 503 pl022->next_msg_cs_active = true;
485 504
@@ -818,8 +837,7 @@ static void dma_callback(void *data)
818 /* Update total bytes transferred */ 837 /* Update total bytes transferred */
819 msg->actual_length += pl022->cur_transfer->len; 838 msg->actual_length += pl022->cur_transfer->len;
820 if (pl022->cur_transfer->cs_change) 839 if (pl022->cur_transfer->cs_change)
821 pl022->cur_chip-> 840 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
822 cs_control(SSP_CHIP_DESELECT);
823 841
824 /* Move to next transfer */ 842 /* Move to next transfer */
825 msg->state = next_transfer(pl022); 843 msg->state = next_transfer(pl022);
@@ -1252,8 +1270,7 @@ static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id)
1252 /* Update total bytes transferred */ 1270 /* Update total bytes transferred */
1253 msg->actual_length += pl022->cur_transfer->len; 1271 msg->actual_length += pl022->cur_transfer->len;
1254 if (pl022->cur_transfer->cs_change) 1272 if (pl022->cur_transfer->cs_change)
1255 pl022->cur_chip-> 1273 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
1256 cs_control(SSP_CHIP_DESELECT);
1257 /* Move to next transfer */ 1274 /* Move to next transfer */
1258 msg->state = next_transfer(pl022); 1275 msg->state = next_transfer(pl022);
1259 tasklet_schedule(&pl022->pump_transfers); 1276 tasklet_schedule(&pl022->pump_transfers);
@@ -1338,7 +1355,7 @@ static void pump_transfers(unsigned long data)
1338 1355
1339 /* Reselect chip select only if cs_change was requested */ 1356 /* Reselect chip select only if cs_change was requested */
1340 if (previous->cs_change) 1357 if (previous->cs_change)
1341 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1358 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1342 } else { 1359 } else {
1343 /* STATE_START */ 1360 /* STATE_START */
1344 message->state = STATE_RUNNING; 1361 message->state = STATE_RUNNING;
@@ -1377,7 +1394,7 @@ static void do_interrupt_dma_transfer(struct pl022 *pl022)
1377 1394
1378 /* Enable target chip, if not already active */ 1395 /* Enable target chip, if not already active */
1379 if (!pl022->next_msg_cs_active) 1396 if (!pl022->next_msg_cs_active)
1380 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1397 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1381 1398
1382 if (set_up_next_transfer(pl022, pl022->cur_transfer)) { 1399 if (set_up_next_transfer(pl022, pl022->cur_transfer)) {
1383 /* Error path */ 1400 /* Error path */
@@ -1429,12 +1446,12 @@ static void do_polling_transfer(struct pl022 *pl022)
1429 if (previous->delay_usecs) 1446 if (previous->delay_usecs)
1430 udelay(previous->delay_usecs); 1447 udelay(previous->delay_usecs);
1431 if (previous->cs_change) 1448 if (previous->cs_change)
1432 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1449 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1433 } else { 1450 } else {
1434 /* STATE_START */ 1451 /* STATE_START */
1435 message->state = STATE_RUNNING; 1452 message->state = STATE_RUNNING;
1436 if (!pl022->next_msg_cs_active) 1453 if (!pl022->next_msg_cs_active)
1437 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1454 pl022_cs_control(pl022, SSP_CHIP_SELECT);
1438 } 1455 }
1439 1456
1440 /* Configuration Changing Per Transfer */ 1457 /* Configuration Changing Per Transfer */
@@ -1466,7 +1483,7 @@ static void do_polling_transfer(struct pl022 *pl022)
1466 /* Update total byte transferred */ 1483 /* Update total byte transferred */
1467 message->actual_length += pl022->cur_transfer->len; 1484 message->actual_length += pl022->cur_transfer->len;
1468 if (pl022->cur_transfer->cs_change) 1485 if (pl022->cur_transfer->cs_change)
1469 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT); 1486 pl022_cs_control(pl022, SSP_CHIP_DESELECT);
1470 /* Move to next transfer */ 1487 /* Move to next transfer */
1471 message->state = next_transfer(pl022); 1488 message->state = next_transfer(pl022);
1472 } 1489 }
@@ -1495,6 +1512,7 @@ static int pl022_transfer_one_message(struct spi_master *master,
1495 1512
1496 /* Setup the SPI using the per chip configuration */ 1513 /* Setup the SPI using the per chip configuration */
1497 pl022->cur_chip = spi_get_ctldata(msg->spi); 1514 pl022->cur_chip = spi_get_ctldata(msg->spi);
1515 pl022->cur_cs = pl022->chipselects[msg->spi->chip_select];
1498 1516
1499 restore_state(pl022); 1517 restore_state(pl022);
1500 flush(pl022); 1518 flush(pl022);
@@ -1766,12 +1784,14 @@ static const struct pl022_config_chip pl022_default_chip_info = {
1766static int pl022_setup(struct spi_device *spi) 1784static int pl022_setup(struct spi_device *spi)
1767{ 1785{
1768 struct pl022_config_chip const *chip_info; 1786 struct pl022_config_chip const *chip_info;
1787 struct pl022_config_chip chip_info_dt;
1769 struct chip_data *chip; 1788 struct chip_data *chip;
1770 struct ssp_clock_params clk_freq = { .cpsdvsr = 0, .scr = 0}; 1789 struct ssp_clock_params clk_freq = { .cpsdvsr = 0, .scr = 0};
1771 int status = 0; 1790 int status = 0;
1772 struct pl022 *pl022 = spi_master_get_devdata(spi->master); 1791 struct pl022 *pl022 = spi_master_get_devdata(spi->master);
1773 unsigned int bits = spi->bits_per_word; 1792 unsigned int bits = spi->bits_per_word;
1774 u32 tmp; 1793 u32 tmp;
1794 struct device_node *np = spi->dev.of_node;
1775 1795
1776 if (!spi->max_speed_hz) 1796 if (!spi->max_speed_hz)
1777 return -EINVAL; 1797 return -EINVAL;
@@ -1794,10 +1814,32 @@ static int pl022_setup(struct spi_device *spi)
1794 chip_info = spi->controller_data; 1814 chip_info = spi->controller_data;
1795 1815
1796 if (chip_info == NULL) { 1816 if (chip_info == NULL) {
1797 chip_info = &pl022_default_chip_info; 1817 if (np) {
1798 /* spi_board_info.controller_data not is supplied */ 1818 chip_info_dt = pl022_default_chip_info;
1799 dev_dbg(&spi->dev, 1819
1800 "using default controller_data settings\n"); 1820 chip_info_dt.hierarchy = SSP_MASTER;
1821 of_property_read_u32(np, "pl022,interface",
1822 &chip_info_dt.iface);
1823 of_property_read_u32(np, "pl022,com-mode",
1824 &chip_info_dt.com_mode);
1825 of_property_read_u32(np, "pl022,rx-level-trig",
1826 &chip_info_dt.rx_lev_trig);
1827 of_property_read_u32(np, "pl022,tx-level-trig",
1828 &chip_info_dt.tx_lev_trig);
1829 of_property_read_u32(np, "pl022,ctrl-len",
1830 &chip_info_dt.ctrl_len);
1831 of_property_read_u32(np, "pl022,wait-state",
1832 &chip_info_dt.wait_state);
1833 of_property_read_u32(np, "pl022,duplex",
1834 &chip_info_dt.duplex);
1835
1836 chip_info = &chip_info_dt;
1837 } else {
1838 chip_info = &pl022_default_chip_info;
1839 /* spi_board_info.controller_data not is supplied */
1840 dev_dbg(&spi->dev,
1841 "using default controller_data settings\n");
1842 }
1801 } else 1843 } else
1802 dev_dbg(&spi->dev, 1844 dev_dbg(&spi->dev,
1803 "using user supplied controller_data settings\n"); 1845 "using user supplied controller_data settings\n");
@@ -1840,8 +1882,9 @@ static int pl022_setup(struct spi_device *spi)
1840 chip->xfer_type = chip_info->com_mode; 1882 chip->xfer_type = chip_info->com_mode;
1841 if (!chip_info->cs_control) { 1883 if (!chip_info->cs_control) {
1842 chip->cs_control = null_cs_control; 1884 chip->cs_control = null_cs_control;
1843 dev_warn(&spi->dev, 1885 if (!gpio_is_valid(pl022->chipselects[spi->chip_select]))
1844 "chip select function is NULL for this chip\n"); 1886 dev_warn(&spi->dev,
1887 "invalid chip select\n");
1845 } else 1888 } else
1846 chip->cs_control = chip_info->cs_control; 1889 chip->cs_control = chip_info->cs_control;
1847 1890
@@ -1986,6 +2029,34 @@ static void pl022_cleanup(struct spi_device *spi)
1986 kfree(chip); 2029 kfree(chip);
1987} 2030}
1988 2031
2032static struct pl022_ssp_controller *
2033pl022_platform_data_dt_get(struct device *dev)
2034{
2035 struct device_node *np = dev->of_node;
2036 struct pl022_ssp_controller *pd;
2037 u32 tmp;
2038
2039 if (!np) {
2040 dev_err(dev, "no dt node defined\n");
2041 return NULL;
2042 }
2043
2044 pd = devm_kzalloc(dev, sizeof(struct pl022_ssp_controller), GFP_KERNEL);
2045 if (!pd) {
2046 dev_err(dev, "cannot allocate platform data memory\n");
2047 return NULL;
2048 }
2049
2050 pd->bus_id = -1;
2051 of_property_read_u32(np, "num-cs", &tmp);
2052 pd->num_chipselect = tmp;
2053 of_property_read_u32(np, "pl022,autosuspend-delay",
2054 &pd->autosuspend_delay);
2055 pd->rt = of_property_read_bool(np, "pl022,rt");
2056
2057 return pd;
2058}
2059
1989static int __devinit 2060static int __devinit
1990pl022_probe(struct amba_device *adev, const struct amba_id *id) 2061pl022_probe(struct amba_device *adev, const struct amba_id *id)
1991{ 2062{
@@ -1993,22 +2064,31 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
1993 struct pl022_ssp_controller *platform_info = adev->dev.platform_data; 2064 struct pl022_ssp_controller *platform_info = adev->dev.platform_data;
1994 struct spi_master *master; 2065 struct spi_master *master;
1995 struct pl022 *pl022 = NULL; /*Data for this driver */ 2066 struct pl022 *pl022 = NULL; /*Data for this driver */
1996 int status = 0; 2067 struct device_node *np = adev->dev.of_node;
2068 int status = 0, i, num_cs;
1997 2069
1998 dev_info(&adev->dev, 2070 dev_info(&adev->dev,
1999 "ARM PL022 driver, device ID: 0x%08x\n", adev->periphid); 2071 "ARM PL022 driver, device ID: 0x%08x\n", adev->periphid);
2000 if (platform_info == NULL) { 2072 if (!platform_info && IS_ENABLED(CONFIG_OF))
2001 dev_err(&adev->dev, "probe - no platform data supplied\n"); 2073 platform_info = pl022_platform_data_dt_get(dev);
2002 status = -ENODEV; 2074
2003 goto err_no_pdata; 2075 if (!platform_info) {
2076 dev_err(dev, "probe: no platform data defined\n");
2077 return -ENODEV;
2078 }
2079
2080 if (platform_info->num_chipselect) {
2081 num_cs = platform_info->num_chipselect;
2082 } else {
2083 dev_err(dev, "probe: no chip select defined\n");
2084 return -ENODEV;
2004 } 2085 }
2005 2086
2006 /* Allocate master with space for data */ 2087 /* Allocate master with space for data */
2007 master = spi_alloc_master(dev, sizeof(struct pl022)); 2088 master = spi_alloc_master(dev, sizeof(struct pl022));
2008 if (master == NULL) { 2089 if (master == NULL) {
2009 dev_err(&adev->dev, "probe - cannot alloc SPI master\n"); 2090 dev_err(&adev->dev, "probe - cannot alloc SPI master\n");
2010 status = -ENOMEM; 2091 return -ENOMEM;
2011 goto err_no_master;
2012 } 2092 }
2013 2093
2014 pl022 = spi_master_get_devdata(master); 2094 pl022 = spi_master_get_devdata(master);
@@ -2016,19 +2096,71 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2016 pl022->master_info = platform_info; 2096 pl022->master_info = platform_info;
2017 pl022->adev = adev; 2097 pl022->adev = adev;
2018 pl022->vendor = id->data; 2098 pl022->vendor = id->data;
2099 pl022->chipselects = devm_kzalloc(dev, num_cs * sizeof(int),
2100 GFP_KERNEL);
2101
2102 pl022->pinctrl = devm_pinctrl_get(dev);
2103 if (IS_ERR(pl022->pinctrl)) {
2104 status = PTR_ERR(pl022->pinctrl);
2105 goto err_no_pinctrl;
2106 }
2107
2108 pl022->pins_default = pinctrl_lookup_state(pl022->pinctrl,
2109 PINCTRL_STATE_DEFAULT);
2110 /* enable pins to be muxed in and configured */
2111 if (!IS_ERR(pl022->pins_default)) {
2112 status = pinctrl_select_state(pl022->pinctrl,
2113 pl022->pins_default);
2114 if (status)
2115 dev_err(dev, "could not set default pins\n");
2116 } else
2117 dev_err(dev, "could not get default pinstate\n");
2118
2119 pl022->pins_sleep = pinctrl_lookup_state(pl022->pinctrl,
2120 PINCTRL_STATE_SLEEP);
2121 if (IS_ERR(pl022->pins_sleep))
2122 dev_dbg(dev, "could not get sleep pinstate\n");
2019 2123
2020 /* 2124 /*
2021 * Bus Number Which has been Assigned to this SSP controller 2125 * Bus Number Which has been Assigned to this SSP controller
2022 * on this board 2126 * on this board
2023 */ 2127 */
2024 master->bus_num = platform_info->bus_id; 2128 master->bus_num = platform_info->bus_id;
2025 master->num_chipselect = platform_info->num_chipselect; 2129 master->num_chipselect = num_cs;
2026 master->cleanup = pl022_cleanup; 2130 master->cleanup = pl022_cleanup;
2027 master->setup = pl022_setup; 2131 master->setup = pl022_setup;
2028 master->prepare_transfer_hardware = pl022_prepare_transfer_hardware; 2132 master->prepare_transfer_hardware = pl022_prepare_transfer_hardware;
2029 master->transfer_one_message = pl022_transfer_one_message; 2133 master->transfer_one_message = pl022_transfer_one_message;
2030 master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware; 2134 master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware;
2031 master->rt = platform_info->rt; 2135 master->rt = platform_info->rt;
2136 master->dev.of_node = dev->of_node;
2137
2138 if (platform_info->num_chipselect && platform_info->chipselects) {
2139 for (i = 0; i < num_cs; i++)
2140 pl022->chipselects[i] = platform_info->chipselects[i];
2141 } else if (IS_ENABLED(CONFIG_OF)) {
2142 for (i = 0; i < num_cs; i++) {
2143 int cs_gpio = of_get_named_gpio(np, "cs-gpios", i);
2144
2145 if (cs_gpio == -EPROBE_DEFER) {
2146 status = -EPROBE_DEFER;
2147 goto err_no_gpio;
2148 }
2149
2150 pl022->chipselects[i] = cs_gpio;
2151
2152 if (gpio_is_valid(cs_gpio)) {
2153 if (devm_gpio_request(dev, cs_gpio, "ssp-pl022"))
2154 dev_err(&adev->dev,
2155 "could not request %d gpio\n",
2156 cs_gpio);
2157 else if (gpio_direction_output(cs_gpio, 1))
2158 dev_err(&adev->dev,
2159 "could set gpio %d as output\n",
2160 cs_gpio);
2161 }
2162 }
2163 }
2032 2164
2033 /* 2165 /*
2034 * Supports mode 0-3, loopback, and active low CS. Transfers are 2166 * Supports mode 0-3, loopback, and active low CS. Transfers are
@@ -2045,7 +2177,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2045 goto err_no_ioregion; 2177 goto err_no_ioregion;
2046 2178
2047 pl022->phybase = adev->res.start; 2179 pl022->phybase = adev->res.start;
2048 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 2180 pl022->virtbase = devm_ioremap(dev, adev->res.start,
2181 resource_size(&adev->res));
2049 if (pl022->virtbase == NULL) { 2182 if (pl022->virtbase == NULL) {
2050 status = -ENOMEM; 2183 status = -ENOMEM;
2051 goto err_no_ioremap; 2184 goto err_no_ioremap;
@@ -2055,7 +2188,7 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2055 2188
2056 pm_runtime_resume(dev); 2189 pm_runtime_resume(dev);
2057 2190
2058 pl022->clk = clk_get(&adev->dev, NULL); 2191 pl022->clk = devm_clk_get(&adev->dev, NULL);
2059 if (IS_ERR(pl022->clk)) { 2192 if (IS_ERR(pl022->clk)) {
2060 status = PTR_ERR(pl022->clk); 2193 status = PTR_ERR(pl022->clk);
2061 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n"); 2194 dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n");
@@ -2083,8 +2216,8 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2083 SSP_CR1(pl022->virtbase)); 2216 SSP_CR1(pl022->virtbase));
2084 load_ssp_default_config(pl022); 2217 load_ssp_default_config(pl022);
2085 2218
2086 status = request_irq(adev->irq[0], pl022_interrupt_handler, 0, "pl022", 2219 status = devm_request_irq(dev, adev->irq[0], pl022_interrupt_handler,
2087 pl022); 2220 0, "pl022", pl022);
2088 if (status < 0) { 2221 if (status < 0) {
2089 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status); 2222 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status);
2090 goto err_no_irq; 2223 goto err_no_irq;
@@ -2124,22 +2257,18 @@ pl022_probe(struct amba_device *adev, const struct amba_id *id)
2124 err_spi_register: 2257 err_spi_register:
2125 if (platform_info->enable_dma) 2258 if (platform_info->enable_dma)
2126 pl022_dma_remove(pl022); 2259 pl022_dma_remove(pl022);
2127
2128 free_irq(adev->irq[0], pl022);
2129 err_no_irq: 2260 err_no_irq:
2130 clk_disable(pl022->clk); 2261 clk_disable(pl022->clk);
2131 err_no_clk_en: 2262 err_no_clk_en:
2132 clk_unprepare(pl022->clk); 2263 clk_unprepare(pl022->clk);
2133 err_clk_prep: 2264 err_clk_prep:
2134 clk_put(pl022->clk);
2135 err_no_clk: 2265 err_no_clk:
2136 iounmap(pl022->virtbase);
2137 err_no_ioremap: 2266 err_no_ioremap:
2138 amba_release_regions(adev); 2267 amba_release_regions(adev);
2139 err_no_ioregion: 2268 err_no_ioregion:
2269 err_no_gpio:
2270 err_no_pinctrl:
2140 spi_master_put(master); 2271 spi_master_put(master);
2141 err_no_master:
2142 err_no_pdata:
2143 return status; 2272 return status;
2144} 2273}
2145 2274
@@ -2161,20 +2290,55 @@ pl022_remove(struct amba_device *adev)
2161 if (pl022->master_info->enable_dma) 2290 if (pl022->master_info->enable_dma)
2162 pl022_dma_remove(pl022); 2291 pl022_dma_remove(pl022);
2163 2292
2164 free_irq(adev->irq[0], pl022);
2165 clk_disable(pl022->clk); 2293 clk_disable(pl022->clk);
2166 clk_unprepare(pl022->clk); 2294 clk_unprepare(pl022->clk);
2167 clk_put(pl022->clk);
2168 pm_runtime_disable(&adev->dev); 2295 pm_runtime_disable(&adev->dev);
2169 iounmap(pl022->virtbase);
2170 amba_release_regions(adev); 2296 amba_release_regions(adev);
2171 tasklet_disable(&pl022->pump_transfers); 2297 tasklet_disable(&pl022->pump_transfers);
2172 spi_unregister_master(pl022->master); 2298 spi_unregister_master(pl022->master);
2173 spi_master_put(pl022->master);
2174 amba_set_drvdata(adev, NULL); 2299 amba_set_drvdata(adev, NULL);
2175 return 0; 2300 return 0;
2176} 2301}
2177 2302
2303#if defined(CONFIG_SUSPEND) || defined(CONFIG_PM_RUNTIME)
2304/*
2305 * These two functions are used from both suspend/resume and
2306 * the runtime counterparts to handle external resources like
2307 * clocks, pins and regulators when going to sleep.
2308 */
2309static void pl022_suspend_resources(struct pl022 *pl022)
2310{
2311 int ret;
2312
2313 clk_disable(pl022->clk);
2314
2315 /* Optionally let pins go into sleep states */
2316 if (!IS_ERR(pl022->pins_sleep)) {
2317 ret = pinctrl_select_state(pl022->pinctrl,
2318 pl022->pins_sleep);
2319 if (ret)
2320 dev_err(&pl022->adev->dev,
2321 "could not set pins to sleep state\n");
2322 }
2323}
2324
2325static void pl022_resume_resources(struct pl022 *pl022)
2326{
2327 int ret;
2328
2329 /* Optionaly enable pins to be muxed in and configured */
2330 if (!IS_ERR(pl022->pins_default)) {
2331 ret = pinctrl_select_state(pl022->pinctrl,
2332 pl022->pins_default);
2333 if (ret)
2334 dev_err(&pl022->adev->dev,
2335 "could not set default pins\n");
2336 }
2337
2338 clk_enable(pl022->clk);
2339}
2340#endif
2341
2178#ifdef CONFIG_SUSPEND 2342#ifdef CONFIG_SUSPEND
2179static int pl022_suspend(struct device *dev) 2343static int pl022_suspend(struct device *dev)
2180{ 2344{
@@ -2186,6 +2350,7 @@ static int pl022_suspend(struct device *dev)
2186 dev_warn(dev, "cannot suspend master\n"); 2350 dev_warn(dev, "cannot suspend master\n");
2187 return ret; 2351 return ret;
2188 } 2352 }
2353 pl022_suspend_resources(pl022);
2189 2354
2190 dev_dbg(dev, "suspended\n"); 2355 dev_dbg(dev, "suspended\n");
2191 return 0; 2356 return 0;
@@ -2196,6 +2361,8 @@ static int pl022_resume(struct device *dev)
2196 struct pl022 *pl022 = dev_get_drvdata(dev); 2361 struct pl022 *pl022 = dev_get_drvdata(dev);
2197 int ret; 2362 int ret;
2198 2363
2364 pl022_resume_resources(pl022);
2365
2199 /* Start the queue running */ 2366 /* Start the queue running */
2200 ret = spi_master_resume(pl022->master); 2367 ret = spi_master_resume(pl022->master);
2201 if (ret) 2368 if (ret)
@@ -2212,8 +2379,7 @@ static int pl022_runtime_suspend(struct device *dev)
2212{ 2379{
2213 struct pl022 *pl022 = dev_get_drvdata(dev); 2380 struct pl022 *pl022 = dev_get_drvdata(dev);
2214 2381
2215 clk_disable(pl022->clk); 2382 pl022_suspend_resources(pl022);
2216
2217 return 0; 2383 return 0;
2218} 2384}
2219 2385
@@ -2221,8 +2387,7 @@ static int pl022_runtime_resume(struct device *dev)
2221{ 2387{
2222 struct pl022 *pl022 = dev_get_drvdata(dev); 2388 struct pl022 *pl022 = dev_get_drvdata(dev);
2223 2389
2224 clk_enable(pl022->clk); 2390 pl022_resume_resources(pl022);
2225
2226 return 0; 2391 return 0;
2227} 2392}
2228#endif 2393#endif