diff options
Diffstat (limited to 'drivers/spi/amba-pl022.c')
-rw-r--r-- | drivers/spi/amba-pl022.c | 121 |
1 files changed, 53 insertions, 68 deletions
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c index db0c67908d2b..59c90f3ccc26 100644 --- a/drivers/spi/amba-pl022.c +++ b/drivers/spi/amba-pl022.c | |||
@@ -1595,12 +1595,6 @@ static int destroy_queue(struct pl022 *pl022) | |||
1595 | static int verify_controller_parameters(struct pl022 *pl022, | 1595 | static int verify_controller_parameters(struct pl022 *pl022, |
1596 | struct pl022_config_chip *chip_info) | 1596 | struct pl022_config_chip *chip_info) |
1597 | { | 1597 | { |
1598 | if ((chip_info->lbm != LOOPBACK_ENABLED) | ||
1599 | && (chip_info->lbm != LOOPBACK_DISABLED)) { | ||
1600 | dev_err(chip_info->dev, | ||
1601 | "loopback Mode is configured incorrectly\n"); | ||
1602 | return -EINVAL; | ||
1603 | } | ||
1604 | if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI) | 1598 | if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI) |
1605 | || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) { | 1599 | || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) { |
1606 | dev_err(chip_info->dev, | 1600 | dev_err(chip_info->dev, |
@@ -1626,24 +1620,6 @@ static int verify_controller_parameters(struct pl022 *pl022, | |||
1626 | "cpsdvsr is configured incorrectly\n"); | 1620 | "cpsdvsr is configured incorrectly\n"); |
1627 | return -EINVAL; | 1621 | return -EINVAL; |
1628 | } | 1622 | } |
1629 | if ((chip_info->endian_rx != SSP_RX_MSB) | ||
1630 | && (chip_info->endian_rx != SSP_RX_LSB)) { | ||
1631 | dev_err(chip_info->dev, | ||
1632 | "RX FIFO endianess is configured incorrectly\n"); | ||
1633 | return -EINVAL; | ||
1634 | } | ||
1635 | if ((chip_info->endian_tx != SSP_TX_MSB) | ||
1636 | && (chip_info->endian_tx != SSP_TX_LSB)) { | ||
1637 | dev_err(chip_info->dev, | ||
1638 | "TX FIFO endianess is configured incorrectly\n"); | ||
1639 | return -EINVAL; | ||
1640 | } | ||
1641 | if ((chip_info->data_size < SSP_DATA_BITS_4) | ||
1642 | || (chip_info->data_size > SSP_DATA_BITS_32)) { | ||
1643 | dev_err(chip_info->dev, | ||
1644 | "DATA Size is configured incorrectly\n"); | ||
1645 | return -EINVAL; | ||
1646 | } | ||
1647 | if ((chip_info->com_mode != INTERRUPT_TRANSFER) | 1623 | if ((chip_info->com_mode != INTERRUPT_TRANSFER) |
1648 | && (chip_info->com_mode != DMA_TRANSFER) | 1624 | && (chip_info->com_mode != DMA_TRANSFER) |
1649 | && (chip_info->com_mode != POLLING_TRANSFER)) { | 1625 | && (chip_info->com_mode != POLLING_TRANSFER)) { |
@@ -1663,20 +1639,6 @@ static int verify_controller_parameters(struct pl022 *pl022, | |||
1663 | "TX FIFO Trigger Level is configured incorrectly\n"); | 1639 | "TX FIFO Trigger Level is configured incorrectly\n"); |
1664 | return -EINVAL; | 1640 | return -EINVAL; |
1665 | } | 1641 | } |
1666 | if (chip_info->iface == SSP_INTERFACE_MOTOROLA_SPI) { | ||
1667 | if ((chip_info->clk_phase != SSP_CLK_FIRST_EDGE) | ||
1668 | && (chip_info->clk_phase != SSP_CLK_SECOND_EDGE)) { | ||
1669 | dev_err(chip_info->dev, | ||
1670 | "Clock Phase is configured incorrectly\n"); | ||
1671 | return -EINVAL; | ||
1672 | } | ||
1673 | if ((chip_info->clk_pol != SSP_CLK_POL_IDLE_LOW) | ||
1674 | && (chip_info->clk_pol != SSP_CLK_POL_IDLE_HIGH)) { | ||
1675 | dev_err(chip_info->dev, | ||
1676 | "Clock Polarity is configured incorrectly\n"); | ||
1677 | return -EINVAL; | ||
1678 | } | ||
1679 | } | ||
1680 | if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { | 1642 | if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { |
1681 | if ((chip_info->ctrl_len < SSP_BITS_4) | 1643 | if ((chip_info->ctrl_len < SSP_BITS_4) |
1682 | || (chip_info->ctrl_len > SSP_BITS_32)) { | 1644 | || (chip_info->ctrl_len > SSP_BITS_32)) { |
@@ -1825,23 +1787,14 @@ static int calculate_effective_freq(struct pl022 *pl022, | |||
1825 | * controller hardware here, that is not done until the actual transfer | 1787 | * controller hardware here, that is not done until the actual transfer |
1826 | * commence. | 1788 | * commence. |
1827 | */ | 1789 | */ |
1828 | |||
1829 | /* FIXME: JUST GUESSING the spi->mode bits understood by this driver */ | ||
1830 | #define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ | ||
1831 | | SPI_LSB_FIRST | SPI_LOOP) | ||
1832 | |||
1833 | static int pl022_setup(struct spi_device *spi) | 1790 | static int pl022_setup(struct spi_device *spi) |
1834 | { | 1791 | { |
1835 | struct pl022_config_chip *chip_info; | 1792 | struct pl022_config_chip *chip_info; |
1836 | struct chip_data *chip; | 1793 | struct chip_data *chip; |
1837 | int status = 0; | 1794 | int status = 0; |
1838 | struct pl022 *pl022 = spi_master_get_devdata(spi->master); | 1795 | struct pl022 *pl022 = spi_master_get_devdata(spi->master); |
1839 | 1796 | unsigned int bits = spi->bits_per_word; | |
1840 | if (spi->mode & ~MODEBITS) { | 1797 | u32 tmp; |
1841 | dev_dbg(&spi->dev, "unsupported mode bits %x\n", | ||
1842 | spi->mode & ~MODEBITS); | ||
1843 | return -EINVAL; | ||
1844 | } | ||
1845 | 1798 | ||
1846 | if (!spi->max_speed_hz) | 1799 | if (!spi->max_speed_hz) |
1847 | return -EINVAL; | 1800 | return -EINVAL; |
@@ -1884,18 +1837,12 @@ static int pl022_setup(struct spi_device *spi) | |||
1884 | * Set controller data default values: | 1837 | * Set controller data default values: |
1885 | * Polling is supported by default | 1838 | * Polling is supported by default |
1886 | */ | 1839 | */ |
1887 | chip_info->lbm = LOOPBACK_DISABLED; | ||
1888 | chip_info->com_mode = POLLING_TRANSFER; | 1840 | chip_info->com_mode = POLLING_TRANSFER; |
1889 | chip_info->iface = SSP_INTERFACE_MOTOROLA_SPI; | 1841 | chip_info->iface = SSP_INTERFACE_MOTOROLA_SPI; |
1890 | chip_info->hierarchy = SSP_SLAVE; | 1842 | chip_info->hierarchy = SSP_SLAVE; |
1891 | chip_info->slave_tx_disable = DO_NOT_DRIVE_TX; | 1843 | chip_info->slave_tx_disable = DO_NOT_DRIVE_TX; |
1892 | chip_info->endian_tx = SSP_TX_LSB; | ||
1893 | chip_info->endian_rx = SSP_RX_LSB; | ||
1894 | chip_info->data_size = SSP_DATA_BITS_12; | ||
1895 | chip_info->rx_lev_trig = SSP_RX_1_OR_MORE_ELEM; | 1844 | chip_info->rx_lev_trig = SSP_RX_1_OR_MORE_ELEM; |
1896 | chip_info->tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC; | 1845 | chip_info->tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC; |
1897 | chip_info->clk_phase = SSP_CLK_SECOND_EDGE; | ||
1898 | chip_info->clk_pol = SSP_CLK_POL_IDLE_LOW; | ||
1899 | chip_info->ctrl_len = SSP_BITS_8; | 1846 | chip_info->ctrl_len = SSP_BITS_8; |
1900 | chip_info->wait_state = SSP_MWIRE_WAIT_ZERO; | 1847 | chip_info->wait_state = SSP_MWIRE_WAIT_ZERO; |
1901 | chip_info->duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX; | 1848 | chip_info->duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX; |
@@ -1933,12 +1880,16 @@ static int pl022_setup(struct spi_device *spi) | |||
1933 | chip->xfer_type = chip_info->com_mode; | 1880 | chip->xfer_type = chip_info->com_mode; |
1934 | chip->cs_control = chip_info->cs_control; | 1881 | chip->cs_control = chip_info->cs_control; |
1935 | 1882 | ||
1936 | if (chip_info->data_size <= 8) { | 1883 | if (bits <= 3) { |
1937 | dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n"); | 1884 | /* PL022 doesn't support less than 4-bits */ |
1885 | status = -ENOTSUPP; | ||
1886 | goto err_config_params; | ||
1887 | } else if (bits <= 8) { | ||
1888 | dev_dbg(&spi->dev, "4 <= n <=8 bits per word\n"); | ||
1938 | chip->n_bytes = 1; | 1889 | chip->n_bytes = 1; |
1939 | chip->read = READING_U8; | 1890 | chip->read = READING_U8; |
1940 | chip->write = WRITING_U8; | 1891 | chip->write = WRITING_U8; |
1941 | } else if (chip_info->data_size <= 16) { | 1892 | } else if (bits <= 16) { |
1942 | dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n"); | 1893 | dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n"); |
1943 | chip->n_bytes = 2; | 1894 | chip->n_bytes = 2; |
1944 | chip->read = READING_U16; | 1895 | chip->read = READING_U16; |
@@ -1955,6 +1906,7 @@ static int pl022_setup(struct spi_device *spi) | |||
1955 | dev_err(&spi->dev, | 1906 | dev_err(&spi->dev, |
1956 | "a standard pl022 can only handle " | 1907 | "a standard pl022 can only handle " |
1957 | "1 <= n <= 16 bit words\n"); | 1908 | "1 <= n <= 16 bit words\n"); |
1909 | status = -ENOTSUPP; | ||
1958 | goto err_config_params; | 1910 | goto err_config_params; |
1959 | } | 1911 | } |
1960 | } | 1912 | } |
@@ -1987,6 +1939,8 @@ static int pl022_setup(struct spi_device *spi) | |||
1987 | 1939 | ||
1988 | /* Special setup for the ST micro extended control registers */ | 1940 | /* Special setup for the ST micro extended control registers */ |
1989 | if (pl022->vendor->extended_cr) { | 1941 | if (pl022->vendor->extended_cr) { |
1942 | u32 etx; | ||
1943 | |||
1990 | if (pl022->vendor->pl023) { | 1944 | if (pl022->vendor->pl023) { |
1991 | /* These bits are only in the PL023 */ | 1945 | /* These bits are only in the PL023 */ |
1992 | SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay, | 1946 | SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay, |
@@ -2002,29 +1956,51 @@ static int pl022_setup(struct spi_device *spi) | |||
2002 | SSP_WRITE_BITS(chip->cr1, chip_info->wait_state, | 1956 | SSP_WRITE_BITS(chip->cr1, chip_info->wait_state, |
2003 | SSP_CR1_MASK_MWAIT_ST, 6); | 1957 | SSP_CR1_MASK_MWAIT_ST, 6); |
2004 | } | 1958 | } |
2005 | SSP_WRITE_BITS(chip->cr0, chip_info->data_size, | 1959 | SSP_WRITE_BITS(chip->cr0, bits - 1, |
2006 | SSP_CR0_MASK_DSS_ST, 0); | 1960 | SSP_CR0_MASK_DSS_ST, 0); |
2007 | SSP_WRITE_BITS(chip->cr1, chip_info->endian_rx, | 1961 | |
2008 | SSP_CR1_MASK_RENDN_ST, 4); | 1962 | if (spi->mode & SPI_LSB_FIRST) { |
2009 | SSP_WRITE_BITS(chip->cr1, chip_info->endian_tx, | 1963 | tmp = SSP_RX_LSB; |
2010 | SSP_CR1_MASK_TENDN_ST, 5); | 1964 | etx = SSP_TX_LSB; |
1965 | } else { | ||
1966 | tmp = SSP_RX_MSB; | ||
1967 | etx = SSP_TX_MSB; | ||
1968 | } | ||
1969 | SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_RENDN_ST, 4); | ||
1970 | SSP_WRITE_BITS(chip->cr1, etx, SSP_CR1_MASK_TENDN_ST, 5); | ||
2011 | SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig, | 1971 | SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig, |
2012 | SSP_CR1_MASK_RXIFLSEL_ST, 7); | 1972 | SSP_CR1_MASK_RXIFLSEL_ST, 7); |
2013 | SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig, | 1973 | SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig, |
2014 | SSP_CR1_MASK_TXIFLSEL_ST, 10); | 1974 | SSP_CR1_MASK_TXIFLSEL_ST, 10); |
2015 | } else { | 1975 | } else { |
2016 | SSP_WRITE_BITS(chip->cr0, chip_info->data_size, | 1976 | SSP_WRITE_BITS(chip->cr0, bits - 1, |
2017 | SSP_CR0_MASK_DSS, 0); | 1977 | SSP_CR0_MASK_DSS, 0); |
2018 | SSP_WRITE_BITS(chip->cr0, chip_info->iface, | 1978 | SSP_WRITE_BITS(chip->cr0, chip_info->iface, |
2019 | SSP_CR0_MASK_FRF, 4); | 1979 | SSP_CR0_MASK_FRF, 4); |
2020 | } | 1980 | } |
1981 | |||
2021 | /* Stuff that is common for all versions */ | 1982 | /* Stuff that is common for all versions */ |
2022 | SSP_WRITE_BITS(chip->cr0, chip_info->clk_pol, SSP_CR0_MASK_SPO, 6); | 1983 | if (spi->mode & SPI_CPOL) |
2023 | SSP_WRITE_BITS(chip->cr0, chip_info->clk_phase, SSP_CR0_MASK_SPH, 7); | 1984 | tmp = SSP_CLK_POL_IDLE_HIGH; |
1985 | else | ||
1986 | tmp = SSP_CLK_POL_IDLE_LOW; | ||
1987 | SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPO, 6); | ||
1988 | |||
1989 | if (spi->mode & SPI_CPHA) | ||
1990 | tmp = SSP_CLK_SECOND_EDGE; | ||
1991 | else | ||
1992 | tmp = SSP_CLK_FIRST_EDGE; | ||
1993 | SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPH, 7); | ||
1994 | |||
2024 | SSP_WRITE_BITS(chip->cr0, chip_info->clk_freq.scr, SSP_CR0_MASK_SCR, 8); | 1995 | SSP_WRITE_BITS(chip->cr0, chip_info->clk_freq.scr, SSP_CR0_MASK_SCR, 8); |
2025 | /* Loopback is available on all versions except PL023 */ | 1996 | /* Loopback is available on all versions except PL023 */ |
2026 | if (!pl022->vendor->pl023) | 1997 | if (!pl022->vendor->pl023) { |
2027 | SSP_WRITE_BITS(chip->cr1, chip_info->lbm, SSP_CR1_MASK_LBM, 0); | 1998 | if (spi->mode & SPI_LOOP) |
1999 | tmp = LOOPBACK_ENABLED; | ||
2000 | else | ||
2001 | tmp = LOOPBACK_DISABLED; | ||
2002 | SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_LBM, 0); | ||
2003 | } | ||
2028 | SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1); | 2004 | SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1); |
2029 | SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2); | 2005 | SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2); |
2030 | SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3); | 2006 | SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3); |
@@ -2033,6 +2009,7 @@ static int pl022_setup(struct spi_device *spi) | |||
2033 | spi_set_ctldata(spi, chip); | 2009 | spi_set_ctldata(spi, chip); |
2034 | return status; | 2010 | return status; |
2035 | err_config_params: | 2011 | err_config_params: |
2012 | spi_set_ctldata(spi, NULL); | ||
2036 | err_first_setup: | 2013 | err_first_setup: |
2037 | kfree(chip); | 2014 | kfree(chip); |
2038 | return status; | 2015 | return status; |
@@ -2095,6 +2072,14 @@ pl022_probe(struct amba_device *adev, struct amba_id *id) | |||
2095 | master->setup = pl022_setup; | 2072 | master->setup = pl022_setup; |
2096 | master->transfer = pl022_transfer; | 2073 | master->transfer = pl022_transfer; |
2097 | 2074 | ||
2075 | /* | ||
2076 | * Supports mode 0-3, loopback, and active low CS. Transfers are | ||
2077 | * always MS bit first on the original pl022. | ||
2078 | */ | ||
2079 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; | ||
2080 | if (pl022->vendor->extended_cr) | ||
2081 | master->mode_bits |= SPI_LSB_FIRST; | ||
2082 | |||
2098 | dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num); | 2083 | dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num); |
2099 | 2084 | ||
2100 | status = amba_request_regions(adev, NULL); | 2085 | status = amba_request_regions(adev, NULL); |