@@ -83,6 +83,7 @@ MODULE_PARM_DESC(polling_limit_us,
8383 * struct bcm2835_spi - BCM2835 SPI controller
8484 * @regs: base address of register map
8585 * @clk: core clock, divided to calculate serial clock
86+ * @clk_hz: core clock cached speed
8687 * @irq: interrupt, signals TX FIFO empty or RX FIFO ¾ full
8788 * @tfr: SPI transfer currently processed
8889 * @ctlr: SPI controller reverse lookup
@@ -116,6 +117,7 @@ MODULE_PARM_DESC(polling_limit_us,
116117struct bcm2835_spi {
117118 void __iomem * regs ;
118119 struct clk * clk ;
120+ unsigned long clk_hz ;
119121 int irq ;
120122 struct spi_transfer * tfr ;
121123 struct spi_controller * ctlr ;
@@ -1045,27 +1047,26 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr,
10451047{
10461048 struct bcm2835_spi * bs = spi_controller_get_devdata (ctlr );
10471049 struct bcm2835_spidev * slv = spi_get_ctldata (spi );
1048- unsigned long spi_hz , clk_hz , cdiv ;
1050+ unsigned long spi_hz , cdiv ;
10491051 unsigned long hz_per_byte , byte_limit ;
10501052 u32 cs = slv -> prepare_cs ;
10511053
10521054 /* set clock */
10531055 spi_hz = tfr -> speed_hz ;
1054- clk_hz = clk_get_rate (bs -> clk );
10551056
1056- if (spi_hz >= clk_hz / 2 ) {
1057+ if (spi_hz >= bs -> clk_hz / 2 ) {
10571058 cdiv = 2 ; /* clk_hz/2 is the fastest we can go */
10581059 } else if (spi_hz ) {
10591060 /* CDIV must be a multiple of two */
1060- cdiv = DIV_ROUND_UP (clk_hz , spi_hz );
1061+ cdiv = DIV_ROUND_UP (bs -> clk_hz , spi_hz );
10611062 cdiv += (cdiv % 2 );
10621063
10631064 if (cdiv >= 65536 )
10641065 cdiv = 0 ; /* 0 is the slowest we can go */
10651066 } else {
10661067 cdiv = 0 ; /* 0 is the slowest we can go */
10671068 }
1068- tfr -> effective_speed_hz = cdiv ? (clk_hz / cdiv ) : (clk_hz / 65536 );
1069+ tfr -> effective_speed_hz = cdiv ? (bs -> clk_hz / cdiv ) : (bs -> clk_hz / 65536 );
10691070 bcm2835_wr (bs , BCM2835_SPI_CLK , cdiv );
10701071
10711072 /* handle all the 3-wire mode */
@@ -1354,6 +1355,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
13541355 return bs -> irq ? bs -> irq : - ENODEV ;
13551356
13561357 clk_prepare_enable (bs -> clk );
1358+ bs -> clk_hz = clk_get_rate (bs -> clk );
13571359
13581360 err = bcm2835_dma_init (ctlr , & pdev -> dev , bs );
13591361 if (err )
0 commit comments