Lines Matching full:spi
3 // General Purpose SPI multiplexer
10 #include <linux/spi/spi.h>
17 * This driver supports a MUX on an SPI bus. This can be useful when you need
21 * The driver will create an additional SPI controller. Devices added under the
27 * @spi: pointer to the device struct attached to the parent
28 * spi controller
36 * downstream spi devices
39 struct spi_device *spi; member
49 static int spi_mux_select(struct spi_device *spi) in spi_mux_select() argument
51 struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller); in spi_mux_select()
54 ret = mux_control_select(priv->mux, spi_get_chipselect(spi, 0)); in spi_mux_select()
58 if (priv->current_cs == spi_get_chipselect(spi, 0)) in spi_mux_select()
61 dev_dbg(&priv->spi->dev, "setting up the mux for cs %d\n", in spi_mux_select()
62 spi_get_chipselect(spi, 0)); in spi_mux_select()
65 priv->spi->max_speed_hz = spi->max_speed_hz; in spi_mux_select()
66 priv->spi->mode = spi->mode; in spi_mux_select()
67 priv->spi->bits_per_word = spi->bits_per_word; in spi_mux_select()
69 priv->current_cs = spi_get_chipselect(spi, 0); in spi_mux_select()
74 static int spi_mux_setup(struct spi_device *spi) in spi_mux_setup() argument
76 struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller); in spi_mux_setup()
83 return spi_setup(priv->spi); in spi_mux_setup()
89 struct spi_controller *ctlr = spi_get_drvdata(priv->spi); in spi_mux_complete_cb()
94 m->spi = priv->child_msg_dev; in spi_mux_complete_cb()
103 struct spi_device *spi = m->spi; in spi_mux_transfer_one_message() local
106 ret = spi_mux_select(spi); in spi_mux_transfer_one_message()
116 priv->child_msg_dev = m->spi; in spi_mux_transfer_one_message()
120 m->spi = priv->spi; in spi_mux_transfer_one_message()
123 return spi_async(priv->spi, m); in spi_mux_transfer_one_message()
126 static int spi_mux_probe(struct spi_device *spi) in spi_mux_probe() argument
132 ctlr = spi_alloc_master(&spi->dev, sizeof(*priv)); in spi_mux_probe()
136 spi_set_drvdata(spi, ctlr); in spi_mux_probe()
138 priv->spi = spi; in spi_mux_probe()
147 priv->mux = devm_mux_control_get(&spi->dev, NULL); in spi_mux_probe()
149 ret = dev_err_probe(&spi->dev, PTR_ERR(priv->mux), in spi_mux_probe()
157 ctlr->mode_bits = spi->controller->mode_bits; in spi_mux_probe()
158 ctlr->flags = spi->controller->flags; in spi_mux_probe()
159 ctlr->bits_per_word_mask = spi->controller->bits_per_word_mask; in spi_mux_probe()
164 ctlr->dev.of_node = spi->dev.of_node; in spi_mux_probe()
167 ret = devm_spi_register_controller(&spi->dev, ctlr); in spi_mux_probe()
180 { "spi-mux" },
183 MODULE_DEVICE_TABLE(spi, spi_mux_id);
186 { .compatible = "spi-mux" },
194 .name = "spi-mux",
202 MODULE_DESCRIPTION("SPI multiplexer");