Merge tag 'tomoyo-pr-20230903' of git://git.osdn.net/gitroot/tomoyo/tomoyo-test1
[linux-2.6-block.git] / drivers / spi / spi-stm32.c
index 7ddf9db776b06570c9014b4b17088aa6679774dd..b6d66caba4c02eb3e988ad9a5f76317a4244af32 100644 (file)
@@ -238,6 +238,7 @@ struct stm32_spi;
  * @baud_rate_div_min: minimum baud rate divisor
  * @baud_rate_div_max: maximum baud rate divisor
  * @has_fifo: boolean to know if fifo is used for driver
+ * @has_device_mode: is this compatible capable to switch on device mode
  * @flags: compatible specific SPI controller flags used at registration time
  */
 struct stm32_spi_cfg {
@@ -259,6 +260,7 @@ struct stm32_spi_cfg {
        unsigned int baud_rate_div_min;
        unsigned int baud_rate_div_max;
        bool has_fifo;
+       bool has_device_mode;
        u16 flags;
 };
 
@@ -1750,7 +1752,8 @@ static const struct stm32_spi_cfg stm32f4_spi_cfg = {
        .baud_rate_div_min = STM32F4_SPI_BR_DIV_MIN,
        .baud_rate_div_max = STM32F4_SPI_BR_DIV_MAX,
        .has_fifo = false,
-       .flags = SPI_MASTER_MUST_TX,
+       .has_device_mode = false,
+       .flags = SPI_CONTROLLER_MUST_TX,
 };
 
 static const struct stm32_spi_cfg stm32h7_spi_cfg = {
@@ -1774,6 +1777,7 @@ static const struct stm32_spi_cfg stm32h7_spi_cfg = {
        .baud_rate_div_min = STM32H7_SPI_MBR_DIV_MIN,
        .baud_rate_div_max = STM32H7_SPI_MBR_DIV_MAX,
        .has_fifo = true,
+       .has_device_mode = true,
 };
 
 static const struct of_device_id stm32_spi_of_match[] = {
@@ -1798,8 +1802,13 @@ static int stm32_spi_probe(struct platform_device *pdev)
        struct device_node *np = pdev->dev.of_node;
        bool device_mode;
        int ret;
+       const struct stm32_spi_cfg *cfg = of_device_get_match_data(&pdev->dev);
 
        device_mode = of_property_read_bool(np, "spi-slave");
+       if (!cfg->has_device_mode && device_mode) {
+               dev_err(&pdev->dev, "spi-slave not supported\n");
+               return -EPERM;
+       }
 
        if (device_mode)
                ctrl = devm_spi_alloc_slave(&pdev->dev, sizeof(struct stm32_spi));
@@ -1817,9 +1826,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
        spi->device_mode = device_mode;
        spin_lock_init(&spi->lock);
 
-       spi->cfg = (const struct stm32_spi_cfg *)
-               of_match_device(pdev->dev.driver->of_match_table,
-                               &pdev->dev)->data;
+       spi->cfg = cfg;
 
        spi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
        if (IS_ERR(spi->base))
@@ -1829,8 +1836,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
 
        spi->irq = platform_get_irq(pdev, 0);
        if (spi->irq <= 0)
-               return dev_err_probe(&pdev->dev, spi->irq,
-                                    "failed to get irq\n");
+               return spi->irq;
 
        ret = devm_request_threaded_irq(&pdev->dev, spi->irq,
                                        spi->cfg->irq_handler_event,