forked from mirrors/linux
		
	spi: spi-xilinx: Add run run-time endian detection
Do not load endian value from platform data and rather autodetect it. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Mark Brown <broonie@linaro.org>
This commit is contained in:
		
							parent
							
								
									d683b96b07
								
							
						
					
					
						commit
						082339bc63
					
				
					 3 changed files with 21 additions and 10 deletions
				
			
		| 
						 | 
					@ -145,7 +145,6 @@ static struct spi_board_info timberdale_spi_8bit_board_info[] = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct xspi_platform_data timberdale_xspi_platform_data = {
 | 
					static struct xspi_platform_data timberdale_xspi_platform_data = {
 | 
				
			||||||
	.num_chipselect = 3,
 | 
						.num_chipselect = 3,
 | 
				
			||||||
	.little_endian = true,
 | 
					 | 
				
			||||||
	/* bits per word and devices will be filled in runtime depending
 | 
						/* bits per word and devices will be filled in runtime depending
 | 
				
			||||||
	 * on the HW config
 | 
						 * on the HW config
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#define XSPI_CR_OFFSET		0x60	/* Control Register */
 | 
					#define XSPI_CR_OFFSET		0x60	/* Control Register */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define XSPI_CR_LOOP		0x01
 | 
				
			||||||
#define XSPI_CR_ENABLE		0x02
 | 
					#define XSPI_CR_ENABLE		0x02
 | 
				
			||||||
#define XSPI_CR_MASTER_MODE	0x04
 | 
					#define XSPI_CR_MASTER_MODE	0x04
 | 
				
			||||||
#define XSPI_CR_CPOL		0x08
 | 
					#define XSPI_CR_CPOL		0x08
 | 
				
			||||||
| 
						 | 
					@ -359,11 +360,12 @@ static const struct of_device_id xilinx_spi_of_match[] = {
 | 
				
			||||||
MODULE_DEVICE_TABLE(of, xilinx_spi_of_match);
 | 
					MODULE_DEVICE_TABLE(of, xilinx_spi_of_match);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 | 
					struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 | 
				
			||||||
	u32 irq, s16 bus_num, int num_cs, int little_endian, int bits_per_word)
 | 
						u32 irq, s16 bus_num, int num_cs, int bits_per_word)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct spi_master *master;
 | 
						struct spi_master *master;
 | 
				
			||||||
	struct xilinx_spi *xspi;
 | 
						struct xilinx_spi *xspi;
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
 | 
						u32 tmp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	master = spi_alloc_master(dev, sizeof(struct xilinx_spi));
 | 
						master = spi_alloc_master(dev, sizeof(struct xilinx_spi));
 | 
				
			||||||
	if (!master)
 | 
						if (!master)
 | 
				
			||||||
| 
						 | 
					@ -396,13 +398,25 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	xspi->mem = *mem;
 | 
						xspi->mem = *mem;
 | 
				
			||||||
	xspi->irq = irq;
 | 
						xspi->irq = irq;
 | 
				
			||||||
	if (little_endian) {
 | 
					
 | 
				
			||||||
		xspi->read_fn = xspi_read32;
 | 
						/*
 | 
				
			||||||
		xspi->write_fn = xspi_write32;
 | 
						 * Detect endianess on the IP via loop bit in CR. Detection
 | 
				
			||||||
	} else {
 | 
						 * must be done before reset is sent because incorrect reset
 | 
				
			||||||
 | 
						 * value generates error interrupt.
 | 
				
			||||||
 | 
						 * Setup little endian helper functions first and try to use them
 | 
				
			||||||
 | 
						 * and check if bit was correctly setup or not.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
						xspi->read_fn = xspi_read32;
 | 
				
			||||||
 | 
						xspi->write_fn = xspi_write32;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						xspi->write_fn(XSPI_CR_LOOP, xspi->regs + XSPI_CR_OFFSET);
 | 
				
			||||||
 | 
						tmp = xspi->read_fn(xspi->regs + XSPI_CR_OFFSET);
 | 
				
			||||||
 | 
						tmp &= XSPI_CR_LOOP;
 | 
				
			||||||
 | 
						if (tmp != XSPI_CR_LOOP) {
 | 
				
			||||||
		xspi->read_fn = xspi_read32_be;
 | 
							xspi->read_fn = xspi_read32_be;
 | 
				
			||||||
		xspi->write_fn = xspi_write32_be;
 | 
							xspi->write_fn = xspi_write32_be;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	xspi->bits_per_word = bits_per_word;
 | 
						xspi->bits_per_word = bits_per_word;
 | 
				
			||||||
	if (xspi->bits_per_word == 8) {
 | 
						if (xspi->bits_per_word == 8) {
 | 
				
			||||||
		xspi->tx_fn = xspi_tx8;
 | 
							xspi->tx_fn = xspi_tx8;
 | 
				
			||||||
| 
						 | 
					@ -466,14 +480,13 @@ static int xilinx_spi_probe(struct platform_device *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct xspi_platform_data *pdata;
 | 
						struct xspi_platform_data *pdata;
 | 
				
			||||||
	struct resource *r;
 | 
						struct resource *r;
 | 
				
			||||||
	int irq, num_cs = 0, little_endian = 0, bits_per_word = 8;
 | 
						int irq, num_cs = 0, bits_per_word = 8;
 | 
				
			||||||
	struct spi_master *master;
 | 
						struct spi_master *master;
 | 
				
			||||||
	u8 i;
 | 
						u8 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pdata = dev->dev.platform_data;
 | 
						pdata = dev->dev.platform_data;
 | 
				
			||||||
	if (pdata) {
 | 
						if (pdata) {
 | 
				
			||||||
		num_cs = pdata->num_chipselect;
 | 
							num_cs = pdata->num_chipselect;
 | 
				
			||||||
		little_endian = pdata->little_endian;
 | 
					 | 
				
			||||||
		bits_per_word = pdata->bits_per_word;
 | 
							bits_per_word = pdata->bits_per_word;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -505,7 +518,7 @@ static int xilinx_spi_probe(struct platform_device *dev)
 | 
				
			||||||
		return -ENXIO;
 | 
							return -ENXIO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	master = xilinx_spi_init(&dev->dev, r, irq, dev->id, num_cs,
 | 
						master = xilinx_spi_init(&dev->dev, r, irq, dev->id, num_cs,
 | 
				
			||||||
				 little_endian, bits_per_word);
 | 
									 bits_per_word);
 | 
				
			||||||
	if (!master)
 | 
						if (!master)
 | 
				
			||||||
		return -ENODEV;
 | 
							return -ENODEV;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,6 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct xspi_platform_data {
 | 
					struct xspi_platform_data {
 | 
				
			||||||
	u16 num_chipselect;
 | 
						u16 num_chipselect;
 | 
				
			||||||
	bool little_endian;
 | 
					 | 
				
			||||||
	u8 bits_per_word;
 | 
						u8 bits_per_word;
 | 
				
			||||||
	struct spi_board_info *devices;
 | 
						struct spi_board_info *devices;
 | 
				
			||||||
	u8 num_devices;
 | 
						u8 num_devices;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue