Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: clps711x: Driver refactor

This is a complex patch for refactoring CLPS711X SPI driver.
This change adds devicetree support and removes board support.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Alexander Shiyan and committed by
Mark Brown
6acaadc8 1a695a90

+26 -43
+26 -43
drivers/spi/spi-clps711x.c
··· 1 1 /* 2 2 * CLPS711X SPI bus driver 3 3 * 4 - * Copyright (C) 2012-2014 Alexander Shiyan <shc_work@mail.ru> 4 + * Copyright (C) 2012-2016 Alexander Shiyan <shc_work@mail.ru> 5 5 * 6 6 * This program is free software; you can redistribute it and/or modify 7 7 * it under the terms of the GNU General Public License as published by ··· 12 12 #include <linux/io.h> 13 13 #include <linux/clk.h> 14 14 #include <linux/gpio.h> 15 - #include <linux/delay.h> 16 15 #include <linux/module.h> 17 16 #include <linux/interrupt.h> 18 17 #include <linux/platform_device.h> ··· 19 20 #include <linux/mfd/syscon.h> 20 21 #include <linux/mfd/syscon/clps711x.h> 21 22 #include <linux/spi/spi.h> 22 - #include <linux/platform_data/spi-clps711x.h> 23 23 24 - #define DRIVER_NAME "spi-clps711x" 24 + #define DRIVER_NAME "clps711x-spi" 25 25 26 26 #define SYNCIO_FRMLEN(x) ((x) << 8) 27 27 #define SYNCIO_TXFRMEN (1 << 14) ··· 38 40 39 41 static int spi_clps711x_setup(struct spi_device *spi) 40 42 { 43 + if (!spi->controller_state) { 44 + int ret; 45 + 46 + ret = devm_gpio_request(&spi->master->dev, spi->cs_gpio, 47 + dev_name(&spi->master->dev)); 48 + if (ret) 49 + return ret; 50 + 51 + spi->controller_state = spi; 52 + } 53 + 41 54 /* We are expect that SPI-device is not selected */ 42 55 gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); 43 56 ··· 113 104 static int spi_clps711x_probe(struct platform_device *pdev) 114 105 { 115 106 struct spi_clps711x_data *hw; 116 - struct spi_clps711x_pdata *pdata = dev_get_platdata(&pdev->dev); 117 107 struct spi_master *master; 118 108 struct resource *res; 119 - int i, irq, ret; 120 - 121 - if (!pdata) { 122 - dev_err(&pdev->dev, "No platform data supplied\n"); 123 - return -EINVAL; 124 - } 125 - 126 - if (pdata->num_chipselect < 1) { 127 - dev_err(&pdev->dev, "At least one CS must be defined\n"); 128 - return -EINVAL; 129 - } 109 + int irq, ret; 130 110 131 111 irq = platform_get_irq(pdev, 0); 132 112 if (irq < 0) ··· 125 127 if (!master) 126 128 return -ENOMEM; 127 129 128 - master->cs_gpios = devm_kzalloc(&pdev->dev, sizeof(int) * 129 - pdata->num_chipselect, GFP_KERNEL); 130 - if (!master->cs_gpios) { 131 - ret = -ENOMEM; 132 - goto err_out; 133 - } 134 - 135 - master->bus_num = pdev->id; 130 + master->bus_num = -1; 136 131 master->mode_bits = SPI_CPHA | SPI_CS_HIGH; 137 132 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8); 138 - master->num_chipselect = pdata->num_chipselect; 133 + master->dev.of_node = pdev->dev.of_node; 139 134 master->setup = spi_clps711x_setup; 140 135 master->prepare_message = spi_clps711x_prepare_message; 141 136 master->transfer_one = spi_clps711x_transfer_one; 142 137 143 138 hw = spi_master_get_devdata(master); 144 - 145 - for (i = 0; i < master->num_chipselect; i++) { 146 - master->cs_gpios[i] = pdata->chipselect[i]; 147 - ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i], 148 - DRIVER_NAME); 149 - if (ret) { 150 - dev_err(&pdev->dev, "Can't get CS GPIO %i\n", i); 151 - goto err_out; 152 - } 153 - } 154 139 155 140 hw->spi_clk = devm_clk_get(&pdev->dev, NULL); 156 141 if (IS_ERR(hw->spi_clk)) { ··· 141 160 goto err_out; 142 161 } 143 162 144 - hw->syscon = syscon_regmap_lookup_by_pdevname("syscon.3"); 163 + hw->syscon = 164 + syscon_regmap_lookup_by_compatible("cirrus,ep7209-syscon3"); 145 165 if (IS_ERR(hw->syscon)) { 146 166 ret = PTR_ERR(hw->syscon); 147 167 goto err_out; ··· 167 185 goto err_out; 168 186 169 187 ret = devm_spi_register_master(&pdev->dev, master); 170 - if (!ret) { 171 - dev_info(&pdev->dev, 172 - "SPI bus driver initialized. Master clock %u Hz\n", 173 - master->max_speed_hz); 188 + if (!ret) 174 189 return 0; 175 - } 176 - 177 - dev_err(&pdev->dev, "Failed to register master\n"); 178 190 179 191 err_out: 180 192 spi_master_put(master); ··· 176 200 return ret; 177 201 } 178 202 203 + static const struct of_device_id clps711x_spi_dt_ids[] = { 204 + { .compatible = "cirrus,ep7209-spi", }, 205 + { } 206 + }; 207 + MODULE_DEVICE_TABLE(of, clps711x_spi_dt_ids); 208 + 179 209 static struct platform_driver clps711x_spi_driver = { 180 210 .driver = { 181 211 .name = DRIVER_NAME, 212 + .of_match_table = clps711x_spi_dt_ids, 182 213 }, 183 214 .probe = spi_clps711x_probe, 184 215 };