source: trunk/target/linux/ar71xx/patches-3.3/204-spi-ath79-avoid-multiple-initialization-of-the-SPI-c.patch @ 31602

Last change on this file since 31602 was 31602, checked in by juhosg, 5 years ago

ar71xx: update 3.3 patches

File size: 3.0 KB
  • drivers/spi/spi-ath79.c

    From 47fdda225880ab0aaa8a75f61991a72fade591ab Mon Sep 17 00:00:00 2001
    From: Gabor Juhos <juhosg@openwrt.org>
    Date: Mon, 9 Jan 2012 15:00:46 +0100
    Subject: [PATCH 45/47] spi/ath79: avoid multiple initialization of the SPI controller
    
    Currently we are initializing the SPI controller in
    the chip select line function, and that function is
    called once for each SPI device on the bus. If a
    board has multiple SPI devices, the controller will
    be initialized multiple times.
    
    Introduce ath79_spi_{en,dis}able helper functions,
    and call those from probe/response in order to avoid
    the mutliple initialization of the controller.
    
    Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
    ---
     drivers/spi/spi-ath79.c |   41 ++++++++++++++++++++++++-----------------
     1 files changed, 24 insertions(+), 17 deletions(-)
    
    a b static void ath79_spi_chipselect(struct 
    9696 
    9797} 
    9898 
    99 static int ath79_spi_setup_cs(struct spi_device *spi) 
     99static void ath79_spi_enable(struct ath79_spi *sp) 
    100100{ 
    101         struct ath79_spi *sp = ath79_spidev_to_sp(spi); 
    102         struct ath79_spi_controller_data *cdata; 
    103         int status; 
    104  
    105         cdata = spi->controller_data; 
    106         if (spi->chip_select && !cdata) 
    107                 return -EINVAL; 
    108  
    109101        /* enable GPIO mode */ 
    110102        ath79_spi_wr(sp, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO); 
    111103 
    static int ath79_spi_setup_cs(struct spi 
    115107 
    116108        /* TODO: setup speed? */ 
    117109        ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43); 
     110} 
     111 
     112static void ath79_spi_disable(struct ath79_spi *sp) 
     113{ 
     114        /* restore CTRL register */ 
     115        ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl); 
     116        /* disable GPIO mode */ 
     117        ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0); 
     118} 
     119 
     120static int ath79_spi_setup_cs(struct spi_device *spi) 
     121{ 
     122        struct ath79_spi_controller_data *cdata; 
     123        int status; 
     124 
     125        cdata = spi->controller_data; 
     126        if (spi->chip_select && !cdata) 
     127                return -EINVAL; 
    118128 
    119129        status = 0; 
    120130        if (spi->chip_select) { 
    static int ath79_spi_setup_cs(struct spi 
    135145 
    136146static void ath79_spi_cleanup_cs(struct spi_device *spi) 
    137147{ 
    138         struct ath79_spi *sp = ath79_spidev_to_sp(spi); 
    139  
    140148        if (spi->chip_select) { 
    141149                struct ath79_spi_controller_data *cdata = spi->controller_data; 
    142150                gpio_free(cdata->gpio); 
    143151        } 
    144  
    145         /* restore CTRL register */ 
    146         ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, sp->reg_ctrl); 
    147         /* disable GPIO mode */ 
    148         ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0); 
    149152} 
    150153 
    151154static int ath79_spi_setup(struct spi_device *spi) 
    static __devinit int ath79_spi_probe(str 
    271274        dev_dbg(&pdev->dev, "register read/write delay is %u nsecs\n", 
    272275                sp->rrw_delay); 
    273276 
     277        ath79_spi_enable(sp); 
    274278        ret = spi_bitbang_start(&sp->bitbang); 
    275279        if (ret) 
    276                 goto err_clk_disable; 
     280                goto err_disable; 
    277281 
    278282        return 0; 
    279283 
     284err_disable: 
     285        ath79_spi_disable(sp); 
    280286err_clk_disable: 
    281287        clk_disable(sp->clk); 
    282288err_clk_put: 
    static __devexit int ath79_spi_remove(st 
    295301        struct ath79_spi *sp = platform_get_drvdata(pdev); 
    296302 
    297303        spi_bitbang_stop(&sp->bitbang); 
     304        ath79_spi_disable(sp); 
    298305        clk_disable(sp->clk); 
    299306        clk_put(sp->clk); 
    300307        iounmap(sp->base); 
Note: See TracBrowser for help on using the repository browser.