mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
	UNGLinuxDriver@microchip.com
Subject: Re: [PATCH RFC SPI for-next 1/2] spi: microchip: pci1xxxx: Add driver for SPI controller of PCI1XXXX PCIe switch
Date: Wed, 28 Sep 2022 12:26:58 +0100	[thread overview]
Message-ID: <YzQvgmE9Hubx9mxN@sirena.org.uk> (raw)
In-Reply-To: <20220928034336.2939265-2-tharunkumar.pasumarthi@microchip.com>

[-- Attachment #1: Type: text/plain, Size: 2850 bytes --]

On Wed, Sep 28, 2022 at 09:13:35AM +0530, Tharun Kumar P wrote:

> @@ -0,0 +1,378 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * PCI1xxxx SPI driver
> + * Copyright (C) 2022 Microchip Technology Inc.
> + * Authors: Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
> + *          Kumaravel Thiagarajan <Kumaravel.Thiagarajan@microchip.com>
> + */

Please make the above a single C++ style comment block so things look
more intentional.

> +static void pci1xxxx_spi_set_cs(struct spi_device *spi, bool enable)
> +{
> +	struct pci1xxxx_spi_internal *p = spi_controller_get_devdata(spi->controller);
> +	struct pci1xxxx_spi *par = p->parent;
> +	u32 regval;
> +
> +	/* Set the DEV_SEL bits of the SPI_MST_CTL_REG */
> +	regval = readl(par->reg_base + SPI_MST_CTL_REG_OFFSET(p->hw_inst));
> +	if (enable) {
> +		regval &= ~SPI_MST_CTL_DEVSEL_MASK;
> +		regval |= (spi->chip_select << 25);
> +		writel(regval,
> +		       par->reg_base + SPI_MST_CTL_REG_OFFSET(p->hw_inst));
> +	}
> +}

This does nothing if the chip select is to be disabled, that's clearly
not going to work.

> +static int pci1xxxx_spi_transfer_one(struct spi_controller *spi_ctlr,
> +				     struct spi_device *spi, struct spi_transfer *xfer)
> +{

> +	if (tx_buf) {

> +			if (rx_buf) {

The driver should set SPI_CONTROLLER_MUST_TX since it needs to transmit
data in order to recieve.

> +static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> +{
> +	u8 hw_inst_cnt, iter, start, only_sec_inst;
> +	struct pci1xxxx_spi_internal *spi_sub_ptr;
> +	struct device *dev = &pdev->dev;
> +	struct pci1xxxx_spi *spi_bus;
> +	struct spi_master *spi_host;
> +	u32 regval;
> +	int ret;
> +
> +	hw_inst_cnt = ent->driver_data & 0x0f;
> +	start = (ent->driver_data & 0xf0) >> 4;
> +	(start == 1) ? (only_sec_inst = 1) : (only_sec_inst = 0);

Please write normal conditional statements to improve legibility.

> +
> +			ret = devm_request_irq(&pdev->dev, spi_sub_ptr->irq,
> +					       pci1xxxx_spi_isr, PCI1XXXX_IRQ_FLAGS,
> +					       pci_name(pdev), spi_sub_ptr);
> +			if (ret < 0) {
> +				dev_err(&pdev->dev, "Unable to request irq : %d",
> +					spi_sub_ptr->irq);
> +				ret = -ENODEV;
> +				goto error;
> +			}

Are you sure the device is fully set up and ready for interrupts at this
point, and that the freeing of the driver will work fine with devm?

> +		init_completion(&spi_sub_ptr->spi_xfer_done);

I note that the completion that the interrupt handler uses isn't
allocated yet for example...

> +		/* Initialize Interrupts - SPI_INT */
> +		regval = readl(spi_bus->reg_base +
> +			       SPI_MST_EVENT_MASK_REG_OFFSET(spi_sub_ptr->hw_inst));
> +		regval &= ~SPI_INTR;
> +		writel(regval, spi_bus->reg_base +
> +		       SPI_MST_EVENT_MASK_REG_OFFSET(spi_sub_ptr->hw_inst));

...and we do some interrupt mask management later.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-09-28 11:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28  3:43 [PATCH RFC SPI for-next 0/2] spi: microchip: pci1xxxx: Load SPI driver for SPI endpoint of PCI1XXXX switch Tharun Kumar P
2022-09-28  3:43 ` [PATCH RFC SPI for-next 1/2] spi: microchip: pci1xxxx: Add driver for SPI controller of PCI1XXXX PCIe switch Tharun Kumar P
2022-09-28 11:26   ` Mark Brown [this message]
2022-09-30  5:51     ` Tharunkumar.Pasumarthi
2022-09-28  3:43 ` [PATCH RFC SPI for-next 2/2] spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX SPI driver Tharun Kumar P
2022-09-28 11:30   ` Mark Brown
2022-09-30  5:56     ` Tharunkumar.Pasumarthi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YzQvgmE9Hubx9mxN@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=tharunkumar.pasumarthi@microchip.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®