summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSteffen Trumtrar <s.trumtrar@pengutronix.de>2019-05-03 11:33:52 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-05-08 10:52:51 +0200
commit812a9ddcdf211302a050cf8f61f7af577bc29a23 (patch)
tree430961178aa20b27359782cbec458bae105d1d5b /drivers
parent5085d2ef3fbfdf3a1834873d2655647ba46dbb03 (diff)
downloadbarebox-812a9ddcdf211302a050cf8f61f7af577bc29a23.tar.gz
spi: Generalize SPI "master" to "controller"
Sync with Linux v5.1-rc1. This is the barebox adoption of the commit commit 8caab75fd2c2a92667cbb1cd315720bede3feaa9 Author: Geert Uytterhoeven <geert+renesas@glider.be> Date: Tue Jun 13 13:23:52 2017 +0200 spi: Generalize SPI "master" to "controller" Now struct spi_master is used for both SPI master and slave controllers, it makes sense to rename it to struct spi_controller, and replace "master" by "controller" where appropriate. For now this conversion is done for SPI core infrastructure only. Wrappers are provided for backwards compatibility, until all SPI drivers have been converted. Noteworthy details: - SPI_MASTER_GPIO_SS is retained, as it only makes sense for SPI master controllers, - spi_busnum_to_master() is retained, as it looks up masters only, - A new field spi_device.controller is added, but spi_device.master is retained for compatibility (both are always initialized by spi_alloc_device()), - spi_flash_read() is used by SPI masters only. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/spi/spi.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 25bb988..7756304 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -54,22 +54,22 @@ static LIST_HEAD(board_list);
*
* Returns the new device, or NULL.
*/
-struct spi_device *spi_new_device(struct spi_master *master,
+struct spi_device *spi_new_device(struct spi_controller *ctrl,
struct spi_board_info *chip)
{
struct spi_device *proxy;
int status;
/* Chipselects are numbered 0..max; validate. */
- if (chip->chip_select >= master->num_chipselect) {
+ if (chip->chip_select >= ctrl->num_chipselect) {
debug("cs%d > max %d\n",
chip->chip_select,
- master->num_chipselect);
+ ctrl->num_chipselect);
return NULL;
}
proxy = xzalloc(sizeof *proxy);
- proxy->master = master;
+ proxy->master = ctrl;
proxy->chip_select = chip->chip_select;
proxy->max_speed_hz = chip->max_speed_hz;
proxy->mode = chip->mode;
@@ -81,10 +81,11 @@ struct spi_device *spi_new_device(struct spi_master *master,
proxy->dev.id = DEVICE_ID_DYNAMIC;
proxy->dev.type_data = proxy;
proxy->dev.device_node = chip->device_node;
- proxy->dev.parent = master->dev;
+ proxy->dev.parent = ctrl->dev;
+ proxy->master = proxy->controller = ctrl;
/* drivers may modify this initial i/o setup */
- status = master->setup(proxy);
+ status = ctrl->setup(proxy);
if (status < 0) {
printf("can't setup %s, status %d\n",
proxy->dev.name, status);
@@ -100,12 +101,12 @@ fail:
}
EXPORT_SYMBOL(spi_new_device);
-static void spi_of_register_slaves(struct spi_master *master)
+static void spi_of_register_slaves(struct spi_controller *ctrl)
{
struct device_node *n;
struct spi_board_info chip;
struct property *reg;
- struct device_node *node = master->dev->device_node;
+ struct device_node *node = ctrl->dev->device_node;
if (!IS_ENABLED(CONFIG_OFDEVICE))
return;
@@ -116,7 +117,7 @@ static void spi_of_register_slaves(struct spi_master *master)
for_each_available_child_of_node(node, n) {
memset(&chip, 0, sizeof(chip));
chip.name = xstrdup(n->name);
- chip.bus_num = master->bus_num;
+ chip.bus_num = ctrl->bus_num;
/* Mode (clock phase/polarity/etc.) */
if (of_property_read_bool(n, "spi-cpha"))
chip.mode |= SPI_CPHA;
@@ -171,7 +172,7 @@ spi_register_board_info(struct spi_board_info const *info, int n)
return 0;
}
-static void scan_boardinfo(struct spi_master *master)
+static void scan_boardinfo(struct spi_controller *ctrl)
{
struct boardinfo *bi;
@@ -180,27 +181,27 @@ static void scan_boardinfo(struct spi_master *master)
unsigned n;
for (n = bi->n_board_info; n > 0; n--, chip++) {
- debug("%s %d %d\n", __FUNCTION__, chip->bus_num, master->bus_num);
- if (chip->bus_num != master->bus_num)
+ debug("%s %d %d\n", __FUNCTION__, chip->bus_num, ctrl->bus_num);
+ if (chip->bus_num != ctrl->bus_num)
continue;
/* NOTE: this relies on spi_new_device to
* issue diagnostics when given bogus inputs
*/
- (void) spi_new_device(master, chip);
+ (void) spi_new_device(ctrl, chip);
}
}
}
-static LIST_HEAD(spi_master_list);
+static LIST_HEAD(spi_controller_list);
/**
- * spi_register_master - register SPI master controller
- * @master: initialized master, originally from spi_alloc_master()
+ * spi_register_ctrl - register SPI ctrl controller
+ * @ctrl: initialized ctrl, originally from spi_alloc_ctrl()
* Context: can sleep
*
- * SPI master controllers connect to their drivers using some non-SPI bus,
+ * SPI controllers connect to their drivers using some non-SPI bus,
* such as the platform bus. The final stage of probe() in that code
- * includes calling spi_register_master() to hook up to this SPI bus glue.
+ * includes calling spi_register_ctrl() to hook up to this SPI bus glue.
*
* SPI controllers use board specific (often SOC specific) bus numbers,
* and board-specific addressing for SPI devices combines those numbers
@@ -209,47 +210,47 @@ static LIST_HEAD(spi_master_list);
* chip is at which address.
*
* This must be called from context that can sleep. It returns zero on
- * success, else a negative error code (dropping the master's refcount).
+ * success, else a negative error code (dropping the ctrl's refcount).
* After a successful return, the caller is responsible for calling
- * spi_unregister_master().
+ * spi_unregister_ctrl().
*/
-int spi_register_master(struct spi_master *master)
+int spi_register_controller(struct spi_controller *ctrl)
{
static int dyn_bus_id = (1 << 15) - 1;
int status = -ENODEV;
- debug("%s: %s:%d\n", __func__, master->dev->name, master->dev->id);
+ debug("%s: %s:%d\n", __func__, ctrl->dev->name, ctrl->dev->id);
/* even if it's just one always-selected device, there must
* be at least one chipselect
*/
- if (master->num_chipselect == 0)
+ if (ctrl->num_chipselect == 0)
return -EINVAL;
- if ((master->bus_num < 0) && master->dev->device_node)
- master->bus_num = of_alias_get_id(master->dev->device_node, "spi");
+ if ((ctrl->bus_num < 0) && ctrl->dev->device_node)
+ ctrl->bus_num = of_alias_get_id(ctrl->dev->device_node, "spi");
/* convention: dynamically assigned bus IDs count down from the max */
- if (master->bus_num < 0)
- master->bus_num = dyn_bus_id--;
+ if (ctrl->bus_num < 0)
+ ctrl->bus_num = dyn_bus_id--;
- list_add_tail(&master->list, &spi_master_list);
+ list_add_tail(&ctrl->list, &spi_controller_list);
- spi_of_register_slaves(master);
+ spi_of_register_slaves(ctrl);
/* populate children from any spi device tables */
- scan_boardinfo(master);
+ scan_boardinfo(ctrl);
status = 0;
return status;
}
-EXPORT_SYMBOL(spi_register_master);
+EXPORT_SYMBOL(spi_register_ctrl);
-struct spi_master *spi_get_master(int bus)
+struct spi_controller *spi_get_controller(int bus)
{
- struct spi_master* m;
+ struct spi_controller* m;
- list_for_each_entry(m, &spi_master_list, list) {
+ list_for_each_entry(m, &spi_controller_list, list) {
if (m->bus_num == bus)
return m;
}
@@ -259,7 +260,7 @@ struct spi_master *spi_get_master(int bus)
int spi_sync(struct spi_device *spi, struct spi_message *message)
{
- return spi->master->transfer(spi, message);
+ return spi->controller->transfer(spi, message);
}
/**