Commit f6997e9b authored by Srinivas Goud's avatar Srinivas Goud Committed by Mark Brown

spi: spi-cadence: Switch to spi_controller structure

Replace spi_master structure with spi_controller structure.
spi_controller structure provides interface support for
both SPI master and slave controller.
Signed-off-by: default avatarSrinivas Goud <srinivas.goud@amd.com>
Link: https://lore.kernel.org/r/1681825625-10265-2-git-send-email-srinivas.goud@amd.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent ed5a25ac
...@@ -173,7 +173,7 @@ static void cdns_spi_init_hw(struct cdns_spi *xspi) ...@@ -173,7 +173,7 @@ static void cdns_spi_init_hw(struct cdns_spi *xspi)
*/ */
static void cdns_spi_chipselect(struct spi_device *spi, bool is_high) static void cdns_spi_chipselect(struct spi_device *spi, bool is_high)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(spi->master); struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller);
u32 ctrl_reg; u32 ctrl_reg;
ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
...@@ -204,7 +204,7 @@ static void cdns_spi_chipselect(struct spi_device *spi, bool is_high) ...@@ -204,7 +204,7 @@ static void cdns_spi_chipselect(struct spi_device *spi, bool is_high)
*/ */
static void cdns_spi_config_clock_mode(struct spi_device *spi) static void cdns_spi_config_clock_mode(struct spi_device *spi)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(spi->master); struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller);
u32 ctrl_reg, new_ctrl_reg; u32 ctrl_reg, new_ctrl_reg;
new_ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); new_ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
...@@ -247,7 +247,7 @@ static void cdns_spi_config_clock_mode(struct spi_device *spi) ...@@ -247,7 +247,7 @@ static void cdns_spi_config_clock_mode(struct spi_device *spi)
static void cdns_spi_config_clock_freq(struct spi_device *spi, static void cdns_spi_config_clock_freq(struct spi_device *spi,
struct spi_transfer *transfer) struct spi_transfer *transfer)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(spi->master); struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller);
u32 ctrl_reg, baud_rate_val; u32 ctrl_reg, baud_rate_val;
unsigned long frequency; unsigned long frequency;
...@@ -285,7 +285,7 @@ static void cdns_spi_config_clock_freq(struct spi_device *spi, ...@@ -285,7 +285,7 @@ static void cdns_spi_config_clock_freq(struct spi_device *spi,
static int cdns_spi_setup_transfer(struct spi_device *spi, static int cdns_spi_setup_transfer(struct spi_device *spi,
struct spi_transfer *transfer) struct spi_transfer *transfer)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(spi->master); struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller);
cdns_spi_config_clock_freq(spi, transfer); cdns_spi_config_clock_freq(spi, transfer);
...@@ -340,8 +340,8 @@ static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi) ...@@ -340,8 +340,8 @@ static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi)
*/ */
static irqreturn_t cdns_spi_irq(int irq, void *dev_id) static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
{ {
struct spi_master *master = dev_id; struct spi_controller *ctlr = dev_id;
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
irqreturn_t status; irqreturn_t status;
u32 intr_status; u32 intr_status;
...@@ -355,7 +355,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id) ...@@ -355,7 +355,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
* transferred is non-zero * transferred is non-zero
*/ */
cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_DEFAULT); cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_DEFAULT);
spi_finalize_current_transfer(master); spi_finalize_current_transfer(ctlr);
status = IRQ_HANDLED; status = IRQ_HANDLED;
} else if (intr_status & CDNS_SPI_IXR_TXOW) { } else if (intr_status & CDNS_SPI_IXR_TXOW) {
unsigned long trans_cnt; unsigned long trans_cnt;
...@@ -381,7 +381,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id) ...@@ -381,7 +381,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
/* Transfer is completed */ /* Transfer is completed */
cdns_spi_write(xspi, CDNS_SPI_IDR, cdns_spi_write(xspi, CDNS_SPI_IDR,
CDNS_SPI_IXR_DEFAULT); CDNS_SPI_IXR_DEFAULT);
spi_finalize_current_transfer(master); spi_finalize_current_transfer(ctlr);
} }
status = IRQ_HANDLED; status = IRQ_HANDLED;
} }
...@@ -389,7 +389,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id) ...@@ -389,7 +389,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
return status; return status;
} }
static int cdns_prepare_message(struct spi_master *master, static int cdns_prepare_message(struct spi_controller *ctlr,
struct spi_message *msg) struct spi_message *msg)
{ {
cdns_spi_config_clock_mode(msg->spi); cdns_spi_config_clock_mode(msg->spi);
...@@ -398,7 +398,7 @@ static int cdns_prepare_message(struct spi_master *master, ...@@ -398,7 +398,7 @@ static int cdns_prepare_message(struct spi_master *master,
/** /**
* cdns_transfer_one - Initiates the SPI transfer * cdns_transfer_one - Initiates the SPI transfer
* @master: Pointer to spi_master structure * @ctlr: Pointer to spi_controller structure
* @spi: Pointer to the spi_device structure * @spi: Pointer to the spi_device structure
* @transfer: Pointer to the spi_transfer structure which provides * @transfer: Pointer to the spi_transfer structure which provides
* information about next transfer parameters * information about next transfer parameters
...@@ -408,11 +408,11 @@ static int cdns_prepare_message(struct spi_master *master, ...@@ -408,11 +408,11 @@ static int cdns_prepare_message(struct spi_master *master,
* *
* Return: Number of bytes transferred in the last transfer * Return: Number of bytes transferred in the last transfer
*/ */
static int cdns_transfer_one(struct spi_master *master, static int cdns_transfer_one(struct spi_controller *ctlr,
struct spi_device *spi, struct spi_device *spi,
struct spi_transfer *transfer) struct spi_transfer *transfer)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
xspi->txbuf = transfer->tx_buf; xspi->txbuf = transfer->tx_buf;
xspi->rxbuf = transfer->rx_buf; xspi->rxbuf = transfer->rx_buf;
...@@ -429,16 +429,16 @@ static int cdns_transfer_one(struct spi_master *master, ...@@ -429,16 +429,16 @@ static int cdns_transfer_one(struct spi_master *master,
/** /**
* cdns_prepare_transfer_hardware - Prepares hardware for transfer. * cdns_prepare_transfer_hardware - Prepares hardware for transfer.
* @master: Pointer to the spi_master structure which provides * @ctlr: Pointer to the spi_controller structure which provides
* information about the controller. * information about the controller.
* *
* This function enables SPI master controller. * This function enables SPI master controller.
* *
* Return: 0 always * Return: 0 always
*/ */
static int cdns_prepare_transfer_hardware(struct spi_master *master) static int cdns_prepare_transfer_hardware(struct spi_controller *ctlr)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE);
...@@ -447,16 +447,16 @@ static int cdns_prepare_transfer_hardware(struct spi_master *master) ...@@ -447,16 +447,16 @@ static int cdns_prepare_transfer_hardware(struct spi_master *master)
/** /**
* cdns_unprepare_transfer_hardware - Relaxes hardware after transfer * cdns_unprepare_transfer_hardware - Relaxes hardware after transfer
* @master: Pointer to the spi_master structure which provides * @ctlr: Pointer to the spi_controller structure which provides
* information about the controller. * information about the controller.
* *
* This function disables the SPI master controller when no slave selected. * This function disables the SPI master controller when no slave selected.
* *
* Return: 0 always * Return: 0 always
*/ */
static int cdns_unprepare_transfer_hardware(struct spi_master *master) static int cdns_unprepare_transfer_hardware(struct spi_controller *ctlr)
{ {
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
u32 ctrl_reg; u32 ctrl_reg;
/* Disable the SPI if slave is deselected */ /* Disable the SPI if slave is deselected */
...@@ -497,42 +497,42 @@ static void cdns_spi_detect_fifo_depth(struct cdns_spi *xspi) ...@@ -497,42 +497,42 @@ static void cdns_spi_detect_fifo_depth(struct cdns_spi *xspi)
static int cdns_spi_probe(struct platform_device *pdev) static int cdns_spi_probe(struct platform_device *pdev)
{ {
int ret = 0, irq; int ret = 0, irq;
struct spi_master *master; struct spi_controller *ctlr;
struct cdns_spi *xspi; struct cdns_spi *xspi;
u32 num_cs; u32 num_cs;
master = spi_alloc_master(&pdev->dev, sizeof(*xspi)); ctlr = spi_alloc_master(&pdev->dev, sizeof(*xspi));
if (!master) if (!ctlr)
return -ENOMEM; return -ENOMEM;
xspi = spi_master_get_devdata(master); xspi = spi_controller_get_devdata(ctlr);
master->dev.of_node = pdev->dev.of_node; ctlr->dev.of_node = pdev->dev.of_node;
platform_set_drvdata(pdev, master); platform_set_drvdata(pdev, ctlr);
xspi->regs = devm_platform_ioremap_resource(pdev, 0); xspi->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(xspi->regs)) { if (IS_ERR(xspi->regs)) {
ret = PTR_ERR(xspi->regs); ret = PTR_ERR(xspi->regs);
goto remove_master; goto remove_ctlr;
} }
xspi->pclk = devm_clk_get(&pdev->dev, "pclk"); xspi->pclk = devm_clk_get(&pdev->dev, "pclk");
if (IS_ERR(xspi->pclk)) { if (IS_ERR(xspi->pclk)) {
dev_err(&pdev->dev, "pclk clock not found.\n"); dev_err(&pdev->dev, "pclk clock not found.\n");
ret = PTR_ERR(xspi->pclk); ret = PTR_ERR(xspi->pclk);
goto remove_master; goto remove_ctlr;
} }
xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk"); xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk");
if (IS_ERR(xspi->ref_clk)) { if (IS_ERR(xspi->ref_clk)) {
dev_err(&pdev->dev, "ref_clk clock not found.\n"); dev_err(&pdev->dev, "ref_clk clock not found.\n");
ret = PTR_ERR(xspi->ref_clk); ret = PTR_ERR(xspi->ref_clk);
goto remove_master; goto remove_ctlr;
} }
ret = clk_prepare_enable(xspi->pclk); ret = clk_prepare_enable(xspi->pclk);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Unable to enable APB clock.\n"); dev_err(&pdev->dev, "Unable to enable APB clock.\n");
goto remove_master; goto remove_ctlr;
} }
ret = clk_prepare_enable(xspi->ref_clk); ret = clk_prepare_enable(xspi->ref_clk);
...@@ -549,9 +549,9 @@ static int cdns_spi_probe(struct platform_device *pdev) ...@@ -549,9 +549,9 @@ static int cdns_spi_probe(struct platform_device *pdev)
ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs); ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs);
if (ret < 0) if (ret < 0)
master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS; ctlr->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS;
else else
master->num_chipselect = num_cs; ctlr->num_chipselect = num_cs;
ret = of_property_read_u32(pdev->dev.of_node, "is-decoded-cs", ret = of_property_read_u32(pdev->dev.of_node, "is-decoded-cs",
&xspi->is_decoded_cs); &xspi->is_decoded_cs);
...@@ -570,35 +570,35 @@ static int cdns_spi_probe(struct platform_device *pdev) ...@@ -570,35 +570,35 @@ static int cdns_spi_probe(struct platform_device *pdev)
} }
ret = devm_request_irq(&pdev->dev, irq, cdns_spi_irq, ret = devm_request_irq(&pdev->dev, irq, cdns_spi_irq,
0, pdev->name, master); 0, pdev->name, ctlr);
if (ret != 0) { if (ret != 0) {
ret = -ENXIO; ret = -ENXIO;
dev_err(&pdev->dev, "request_irq failed\n"); dev_err(&pdev->dev, "request_irq failed\n");
goto clk_dis_all; goto clk_dis_all;
} }
master->use_gpio_descriptors = true; ctlr->use_gpio_descriptors = true;
master->prepare_transfer_hardware = cdns_prepare_transfer_hardware; ctlr->prepare_transfer_hardware = cdns_prepare_transfer_hardware;
master->prepare_message = cdns_prepare_message; ctlr->prepare_message = cdns_prepare_message;
master->transfer_one = cdns_transfer_one; ctlr->transfer_one = cdns_transfer_one;
master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware; ctlr->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware;
master->set_cs = cdns_spi_chipselect; ctlr->set_cs = cdns_spi_chipselect;
master->auto_runtime_pm = true; ctlr->auto_runtime_pm = true;
master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
xspi->clk_rate = clk_get_rate(xspi->ref_clk); xspi->clk_rate = clk_get_rate(xspi->ref_clk);
/* Set to default valid value */ /* Set to default valid value */
master->max_speed_hz = xspi->clk_rate / 4; ctlr->max_speed_hz = xspi->clk_rate / 4;
xspi->speed_hz = master->max_speed_hz; xspi->speed_hz = ctlr->max_speed_hz;
master->bits_per_word_mask = SPI_BPW_MASK(8); ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
pm_runtime_mark_last_busy(&pdev->dev); pm_runtime_mark_last_busy(&pdev->dev);
pm_runtime_put_autosuspend(&pdev->dev); pm_runtime_put_autosuspend(&pdev->dev);
ret = spi_register_master(master); ret = spi_register_controller(ctlr);
if (ret) { if (ret) {
dev_err(&pdev->dev, "spi_register_master failed\n"); dev_err(&pdev->dev, "spi_register_controller failed\n");
goto clk_dis_all; goto clk_dis_all;
} }
...@@ -610,8 +610,8 @@ static int cdns_spi_probe(struct platform_device *pdev) ...@@ -610,8 +610,8 @@ static int cdns_spi_probe(struct platform_device *pdev)
clk_disable_unprepare(xspi->ref_clk); clk_disable_unprepare(xspi->ref_clk);
clk_dis_apb: clk_dis_apb:
clk_disable_unprepare(xspi->pclk); clk_disable_unprepare(xspi->pclk);
remove_master: remove_ctlr:
spi_master_put(master); spi_controller_put(ctlr);
return ret; return ret;
} }
...@@ -627,8 +627,8 @@ static int cdns_spi_probe(struct platform_device *pdev) ...@@ -627,8 +627,8 @@ static int cdns_spi_probe(struct platform_device *pdev)
*/ */
static void cdns_spi_remove(struct platform_device *pdev) static void cdns_spi_remove(struct platform_device *pdev)
{ {
struct spi_master *master = platform_get_drvdata(pdev); struct spi_controller *ctlr = platform_get_drvdata(pdev);
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
...@@ -637,7 +637,7 @@ static void cdns_spi_remove(struct platform_device *pdev) ...@@ -637,7 +637,7 @@ static void cdns_spi_remove(struct platform_device *pdev)
pm_runtime_set_suspended(&pdev->dev); pm_runtime_set_suspended(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
spi_unregister_master(master); spi_unregister_controller(ctlr);
} }
/** /**
...@@ -651,9 +651,9 @@ static void cdns_spi_remove(struct platform_device *pdev) ...@@ -651,9 +651,9 @@ static void cdns_spi_remove(struct platform_device *pdev)
*/ */
static int __maybe_unused cdns_spi_suspend(struct device *dev) static int __maybe_unused cdns_spi_suspend(struct device *dev)
{ {
struct spi_master *master = dev_get_drvdata(dev); struct spi_controller *ctlr = dev_get_drvdata(dev);
return spi_master_suspend(master); return spi_controller_suspend(ctlr);
} }
/** /**
...@@ -666,11 +666,11 @@ static int __maybe_unused cdns_spi_suspend(struct device *dev) ...@@ -666,11 +666,11 @@ static int __maybe_unused cdns_spi_suspend(struct device *dev)
*/ */
static int __maybe_unused cdns_spi_resume(struct device *dev) static int __maybe_unused cdns_spi_resume(struct device *dev)
{ {
struct spi_master *master = dev_get_drvdata(dev); struct spi_controller *ctlr = dev_get_drvdata(dev);
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
cdns_spi_init_hw(xspi); cdns_spi_init_hw(xspi);
return spi_master_resume(master); return spi_controller_resume(ctlr);
} }
/** /**
...@@ -683,8 +683,8 @@ static int __maybe_unused cdns_spi_resume(struct device *dev) ...@@ -683,8 +683,8 @@ static int __maybe_unused cdns_spi_resume(struct device *dev)
*/ */
static int __maybe_unused cdns_spi_runtime_resume(struct device *dev) static int __maybe_unused cdns_spi_runtime_resume(struct device *dev)
{ {
struct spi_master *master = dev_get_drvdata(dev); struct spi_controller *ctlr = dev_get_drvdata(dev);
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
int ret; int ret;
ret = clk_prepare_enable(xspi->pclk); ret = clk_prepare_enable(xspi->pclk);
...@@ -712,8 +712,8 @@ static int __maybe_unused cdns_spi_runtime_resume(struct device *dev) ...@@ -712,8 +712,8 @@ static int __maybe_unused cdns_spi_runtime_resume(struct device *dev)
*/ */
static int __maybe_unused cdns_spi_runtime_suspend(struct device *dev) static int __maybe_unused cdns_spi_runtime_suspend(struct device *dev)
{ {
struct spi_master *master = dev_get_drvdata(dev); struct spi_controller *ctlr = dev_get_drvdata(dev);
struct cdns_spi *xspi = spi_master_get_devdata(master); struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
clk_disable_unprepare(xspi->ref_clk); clk_disable_unprepare(xspi->ref_clk);
clk_disable_unprepare(xspi->pclk); clk_disable_unprepare(xspi->pclk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment