Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(kernel-rolling) spi: qspi: Add Phytium spi/qspi controller support #210

Conversation

MingcongBai
Copy link
Contributor

@MingcongBai MingcongBai commented May 27, 2024

Picked and rebased from #136.

From original pull request:

These patches have added support for Phytium spi/qspi controllers and their related functions.

Builds tested

  • amd64
  • arm64
  • loong64

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign utsweetyfish for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link

deepin pr auto review

Make sure to include the new headers:

#include <linux/acpi.h>
#include <linux/hw.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/acpi/acpi.h>
#include <linux/acpi/of.h>
#include <linux/hwcap.h>

Here's the updated phytium_spi_add_host function:

int phytium_spi_add_host(struct device *dev, struct phytium_spi *fts) {
    struct spi_master *master;
    int ret;

    WARN_ON(fts == NULL);

    master = spi_alloc_master(dev, 0);
    if (!master)
        return -ENOMEM;

    fts->master = master;
    fts->dma_addr = (dma_addr_t)(fts->paddr + DR);
    snprintf(fts->name, sizeof(fts->name), "phytium_spi%d", fts->bus_num);

    ret = request_irq(fts->irq, phytium_spi_irq, IRQF_SHARED,
                      fts->name, master);
    if (ret < 0) {
        dev_err(dev, "can not get IRQ\n");
        goto err_free_master;
    }

    master->use_gpio_descriptors = true;
    master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
    master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
    master->bus_num = fts->bus_num;
    master->num_chipselect = fts->num_cs;
    master->setup = phytium_spi_setup;
    master->cleanup = phytium_spi_cleanup;
    master->set_cs = phytium_spi_set_cs;
    master->transfer_one = phytium_spi_transfer_one;
    master->handle_err = phytium_spi_handle_err;
    master->max_speed_hz = fts->max_freq;
    master->dev.of_node = dev->of_node;
    master->dev.fwnode = dev->fwnode;
    master->flags = SPI_CONTROLLER_GPIO_SS;

    spi_hw_init(dev, fts);

    if (fts->dma_ops && fts->dma_ops->dma_init) {
        ret = fts->dma_ops->dma_init(dev, fts);
        if (ret) {
            dev_warn(dev, "DMA init failed\n");
        } else {
            master->can_dma = fts->dma_ops->can_dma;
            master->flags |= SPI_CONTROLLER_MUST_TX;
        }
    }

    spi_master_set_devdata(master, fts);
    ret = spi_register_controller(master);
    if (ret) {
        dev_err(dev, "problem registering spi master\n");
        goto err_exit;
    }

    return 0;

err_exit:
    if (fts->dma_ops && fts->dma_ops->dma_exit)
        fts->dma_ops->dma_exit(fts);
    spi_enable_chip(fts, 0);
    free_irq(fts->irq, master);
err_free_master:
    spi_master_put(master);
    return ret;
}

yuanxia0927 and others added 10 commits May 29, 2024 08:40
Add binding documentation for Phytium SPI controller.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
Add support for the Phytium SPI controller driver.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Zhang Yiqun <[email protected]>
Signed-off-by: Peng Min <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
Add the device tree binding documentation for Phytium QuadSPI controller.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
This patch adds a new driver for Phytium QuadSPI (QSPI) controller,
which is used to access NOR Flash memory slaves. The driver implements
spi-mem framework and does not support generic SPI operations.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Zhou Yulin <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
The driver used devm_spi_register_controller() on bind. Therefore,
__device_release_driver() first invokes phytium_spi_remove_host()
before unregistering the SPI controller via devres_release_all() when
unbinding.

Since phytium_spi_remove_host() shuts down the chip, rendering the SPI
bus inaccessible even through the SPI controller is still registered.
When the SPI controller is subsequently unregistered, it unbinds all
its slave devices. Because their drivers cannot access the SPI bus,
the slave devices may be left in an improper state.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
Since the platform driver wraps the core phytium_spi into
phytium_spi_clk struct to include a platform clock, the pointer
extract from driver_data should also be 'struct phytium_spi_clk *'.

Signed-off-by: yuanxia <[email protected]>
Reported-by: Zhou Yulin <[email protected]>
Signed-off-by: Chen Baozi <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
The mask of sck_sel should be 0x7 instead of 0x3, otherwise the split
is set differently than expected.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Liu Tianyu <[email protected]>
Signed-off-by: Li Mingzhe <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
Code has been modified and added in the SPI driver section
to adapt to the DDMA controller.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Liu Tianyu <[email protected]>
Signed-off-by: Wang Hanmo <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
Add acpi table support for qspi/spi driver, supporting
parsing of ACPI tables.

Signed-off-by: yuanxia <[email protected]>
Signed-off-by: Wang Hanmo <[email protected]>
Signed-off-by: Wang Yinfeng <[email protected]>
There was an unused-variable 'adev' brings a warning.

Resolve following error when '-Werror' was enabled:

drivers/mtd/mtdpart.c: In function ‘mtd_part_acpi_parse’:
drivers/mtd/mtdpart.c:584:29: error: unused variable ‘adev’ [-Werror=unused-variable]
  584 |         struct acpi_device *adev;
      |                             ^~~~
cc1: all warnings being treated as errors

Reported-by: Mingcong Bai <[email protected]>
Signed-off-by: WangYuli <[email protected]>
@MingcongBai MingcongBai force-pushed the bai/kernel-rolling/phytium-spi branch from f65e651 to 3c6b717 Compare May 29, 2024 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants