11/*
22 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
3+ * Copyright (C) 2013, Intel Corporation
34 *
45 * This program is free software; you can redistribute it and/or modify
56 * it under the terms of the GNU General Public License as published by
@@ -61,6 +62,98 @@ MODULE_ALIAS("platform:pxa2xx-spi");
6162 | SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
6263 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
6364
65+ #define LPSS_RX_THRESH_DFLT 64
66+ #define LPSS_TX_LOTHRESH_DFLT 160
67+ #define LPSS_TX_HITHRESH_DFLT 224
68+
69+ /* Offset from drv_data->lpss_base */
70+ #define SPI_CS_CONTROL 0x18
71+ #define SPI_CS_CONTROL_SW_MODE BIT(0)
72+ #define SPI_CS_CONTROL_CS_HIGH BIT(1)
73+
74+ static bool is_lpss_ssp (const struct driver_data * drv_data )
75+ {
76+ return drv_data -> ssp_type == LPSS_SSP ;
77+ }
78+
79+ /*
80+ * Read and write LPSS SSP private registers. Caller must first check that
81+ * is_lpss_ssp() returns true before these can be called.
82+ */
83+ static u32 __lpss_ssp_read_priv (struct driver_data * drv_data , unsigned offset )
84+ {
85+ WARN_ON (!drv_data -> lpss_base );
86+ return readl (drv_data -> lpss_base + offset );
87+ }
88+
89+ static void __lpss_ssp_write_priv (struct driver_data * drv_data ,
90+ unsigned offset , u32 value )
91+ {
92+ WARN_ON (!drv_data -> lpss_base );
93+ writel (value , drv_data -> lpss_base + offset );
94+ }
95+
96+ /*
97+ * lpss_ssp_setup - perform LPSS SSP specific setup
98+ * @drv_data: pointer to the driver private data
99+ *
100+ * Perform LPSS SSP specific setup. This function must be called first if
101+ * one is going to use LPSS SSP private registers.
102+ */
103+ static void lpss_ssp_setup (struct driver_data * drv_data )
104+ {
105+ unsigned offset = 0x400 ;
106+ u32 value , orig ;
107+
108+ if (!is_lpss_ssp (drv_data ))
109+ return ;
110+
111+ /*
112+ * Perform auto-detection of the LPSS SSP private registers. They
113+ * can be either at 1k or 2k offset from the base address.
114+ */
115+ orig = readl (drv_data -> ioaddr + offset + SPI_CS_CONTROL );
116+
117+ value = orig | SPI_CS_CONTROL_SW_MODE ;
118+ writel (value , drv_data -> ioaddr + offset + SPI_CS_CONTROL );
119+ value = readl (drv_data -> ioaddr + offset + SPI_CS_CONTROL );
120+ if (value != (orig | SPI_CS_CONTROL_SW_MODE )) {
121+ offset = 0x800 ;
122+ goto detection_done ;
123+ }
124+
125+ value &= ~SPI_CS_CONTROL_SW_MODE ;
126+ writel (value , drv_data -> ioaddr + offset + SPI_CS_CONTROL );
127+ value = readl (drv_data -> ioaddr + offset + SPI_CS_CONTROL );
128+ if (value != orig ) {
129+ offset = 0x800 ;
130+ goto detection_done ;
131+ }
132+
133+ detection_done :
134+ /* Now set the LPSS base */
135+ drv_data -> lpss_base = drv_data -> ioaddr + offset ;
136+
137+ /* Enable software chip select control */
138+ value = SPI_CS_CONTROL_SW_MODE | SPI_CS_CONTROL_CS_HIGH ;
139+ __lpss_ssp_write_priv (drv_data , SPI_CS_CONTROL , value );
140+ }
141+
142+ static void lpss_ssp_cs_control (struct driver_data * drv_data , bool enable )
143+ {
144+ u32 value ;
145+
146+ if (!is_lpss_ssp (drv_data ))
147+ return ;
148+
149+ value = __lpss_ssp_read_priv (drv_data , SPI_CS_CONTROL );
150+ if (enable )
151+ value &= ~SPI_CS_CONTROL_CS_HIGH ;
152+ else
153+ value |= SPI_CS_CONTROL_CS_HIGH ;
154+ __lpss_ssp_write_priv (drv_data , SPI_CS_CONTROL , value );
155+ }
156+
64157static void cs_assert (struct driver_data * drv_data )
65158{
66159 struct chip_data * chip = drv_data -> cur_chip ;
@@ -75,8 +168,12 @@ static void cs_assert(struct driver_data *drv_data)
75168 return ;
76169 }
77170
78- if (gpio_is_valid (chip -> gpio_cs ))
171+ if (gpio_is_valid (chip -> gpio_cs )) {
79172 gpio_set_value (chip -> gpio_cs , chip -> gpio_cs_inverted );
173+ return ;
174+ }
175+
176+ lpss_ssp_cs_control (drv_data , true);
80177}
81178
82179static void cs_deassert (struct driver_data * drv_data )
@@ -91,8 +188,12 @@ static void cs_deassert(struct driver_data *drv_data)
91188 return ;
92189 }
93190
94- if (gpio_is_valid (chip -> gpio_cs ))
191+ if (gpio_is_valid (chip -> gpio_cs )) {
95192 gpio_set_value (chip -> gpio_cs , !chip -> gpio_cs_inverted );
193+ return ;
194+ }
195+
196+ lpss_ssp_cs_control (drv_data , false);
96197}
97198
98199int pxa2xx_spi_flush (struct driver_data * drv_data )
@@ -642,6 +743,13 @@ static void pump_transfers(unsigned long data)
642743 write_SSSR_CS (drv_data , drv_data -> clear_sr );
643744 }
644745
746+ if (is_lpss_ssp (drv_data )) {
747+ if ((read_SSIRF (reg ) & 0xff ) != chip -> lpss_rx_threshold )
748+ write_SSIRF (chip -> lpss_rx_threshold , reg );
749+ if ((read_SSITF (reg ) & 0xffff ) != chip -> lpss_tx_threshold )
750+ write_SSITF (chip -> lpss_tx_threshold , reg );
751+ }
752+
645753 /* see if we need to reload the config registers */
646754 if ((read_SSCR0 (reg ) != cr0 )
647755 || (read_SSCR1 (reg ) & SSCR1_CHANGE_MASK ) !=
@@ -754,8 +862,17 @@ static int setup(struct spi_device *spi)
754862 struct chip_data * chip ;
755863 struct driver_data * drv_data = spi_master_get_devdata (spi -> master );
756864 unsigned int clk_div ;
757- uint tx_thres = TX_THRESH_DFLT ;
758- uint rx_thres = RX_THRESH_DFLT ;
865+ uint tx_thres , tx_hi_thres , rx_thres ;
866+
867+ if (is_lpss_ssp (drv_data )) {
868+ tx_thres = LPSS_TX_LOTHRESH_DFLT ;
869+ tx_hi_thres = LPSS_TX_HITHRESH_DFLT ;
870+ rx_thres = LPSS_RX_THRESH_DFLT ;
871+ } else {
872+ tx_thres = TX_THRESH_DFLT ;
873+ tx_hi_thres = 0 ;
874+ rx_thres = RX_THRESH_DFLT ;
875+ }
759876
760877 if (!pxa25x_ssp_comp (drv_data )
761878 && (spi -> bits_per_word < 4 || spi -> bits_per_word > 32 )) {
@@ -808,6 +925,8 @@ static int setup(struct spi_device *spi)
808925 chip -> timeout = chip_info -> timeout ;
809926 if (chip_info -> tx_threshold )
810927 tx_thres = chip_info -> tx_threshold ;
928+ if (chip_info -> tx_hi_threshold )
929+ tx_hi_thres = chip_info -> tx_hi_threshold ;
811930 if (chip_info -> rx_threshold )
812931 rx_thres = chip_info -> rx_threshold ;
813932 chip -> enable_dma = drv_data -> master_info -> enable_dma ;
@@ -819,6 +938,10 @@ static int setup(struct spi_device *spi)
819938 chip -> threshold = (SSCR1_RxTresh (rx_thres ) & SSCR1_RFT ) |
820939 (SSCR1_TxTresh (tx_thres ) & SSCR1_TFT );
821940
941+ chip -> lpss_rx_threshold = SSIRF_RxThresh (rx_thres );
942+ chip -> lpss_tx_threshold = SSITF_TxLoThresh (tx_thres )
943+ | SSITF_TxHiThresh (tx_hi_thres );
944+
822945 /* set dma burst and threshold outside of chip_info path so that if
823946 * chip_info goes away after setting chip->enable_dma, the
824947 * burst and threshold can still respond to changes in bits_per_word */
@@ -1006,6 +1129,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
10061129 write_SSTO (0 , drv_data -> ioaddr );
10071130 write_SSPSP (0 , drv_data -> ioaddr );
10081131
1132+ lpss_ssp_setup (drv_data );
1133+
10091134 tasklet_init (& drv_data -> pump_transfers , pump_transfers ,
10101135 (unsigned long )drv_data );
10111136
0 commit comments