linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Przemyslaw Gaj <pgaj@cadence.com>
To: Boris Brezillon <boris.brezillon@bootlin.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>
Cc: Przemyslaw Sroka <psroka@cadence.com>,
	Arkadiusz Golec <agolec@cadence.com>,
	Alan Douglas <adouglas@cadence.com>,
	Bartosz Folta <bfolta@cadence.com>, Damian Kos <dkos@cadence.com>,
	Alicja Jurasik-Urbaniak <alicja@cadence.com>,
	Cyprian Wronka <cwronka@cadence.com>,
	Suresh Punnoose <sureshp@cadence.com>,
	Rafal Ciepiela <rafalc@cadence.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Nishanth Menon <nm@ti.com>, Rob Herring <robh+dt@kernel.org>,
	Pawel Moll <pawel.moll@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Kumar Gala <galak@codeaurora.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Vitor Soares <Vitor.Soares@synopsys.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Xiang Lin <Xiang.Lin@synaptics.com>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>
Subject: Re: [PATCH v4 07/10] i3c: master: Add driver for Cadence IP
Date: Mon, 4 Jun 2018 09:24:51 +0000	[thread overview]
Message-ID: <9613475C-ECAE-4AD6-9C02-55C9214A6489@cadence.com> (raw)
In-Reply-To: <20180330074751.25987-8-boris.brezillon@bootlin.com>

Hi Boris,

Few things regarding Cadence IP driver:

On 6/4/18, 9:31 AM, "Boris Brezillon" <boris.brezillon@bootlin.com> wrote:

    +static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master,
    +				       u32 ibir)
    +{
    +	struct cdns_i3c_i2c_dev_data *data;
    +	bool data_consumed = false;
    +	struct i3c_ibi_slot *slot;
    +	u32 id = IBIR_SLVID(ibir);
    +	struct i3c_device *dev;
    +	int len, i, j;
    +	u8 *buf;
    +
    +	/*
    +	 * FIXME: maybe we should report the FIFO OVF errors to the upper
    +	 * layer.
    +	 */
    +	if (id >= master->ibi.num_slots || (ibir & IBIR_ERROR))
    +		goto out;
    +
    +	dev = master->ibi.slots[id];
    +	spin_lock(&master->ibi.lock);
    +
    +	data = i3c_device_get_master_data(dev);
    +	slot = i3c_generic_ibi_get_free_slot(data->ibi_pool);
    +	if (!slot)
    +		goto out_unlock;
    +
    +	buf = slot->data;
    +
    +	len = IBIR_XFER_BYTES(ibir);
    +	for (i = 0; i < IBIR_XFER_BYTES(ibir); i += 4) {
    +		u32 tmp = readl(master->regs + IBI_DATA_FIFO);
    +
    +		for (j = 0; j < 4 && i + j < dev->ibi->max_payload_len; j++)
    +			buf[i + j] = tmp >> (j * 8);
    +
    +	}
    +	slot->len = min_t(unsigned int, IBIR_XFER_BYTES(ibir),
    +			  dev->ibi->max_payload_len);
    +	i3c_master_queue_ibi(dev, slot);
    +	data_consumed = true;
    +
    +out_unlock:
    +	spin_unlock(&master->ibi.lock);
    +
    +out:
    +	/* Consume data from the FIFO if it's not been done already. */
    +	if (!data_consumed) {
    +		for (i = 0; i < IBIR_XFER_BYTES(ibir); i += 4)
    +			readl(master->regs + IBI_DATA_FIFO);
    +	}
    +}
    
len variable is unneeded.

    +static int cdns_i3c_master_probe(struct platform_device *pdev)
    +{
    +	struct cdns_i3c_master *master;
    +	struct resource *res;
    +	int ret, irq;
    +	u32 val;
    +
    +	master = devm_kzalloc(&pdev->dev, sizeof(*master), GFP_KERNEL);
    +	if (!master)
    +		return -ENOMEM;
    +
    +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    +	master->regs = devm_ioremap_resource(&pdev->dev, res);
    +	if (IS_ERR(master->regs))
    +		return PTR_ERR(master->regs);
    +
    +	master->pclk = devm_clk_get(&pdev->dev, "pclk");
    +	if (IS_ERR(master->pclk))
    +		return PTR_ERR(master->pclk);
    +
    +	master->sysclk = devm_clk_get(&pdev->dev, "sysclk");
    +	if (IS_ERR(master->pclk))
    +		return PTR_ERR(master->pclk);
    +
    +	irq = platform_get_irq(pdev, 0);
    +	if (irq < 0)
    +		return irq;
    +
    +	ret = clk_prepare_enable(master->pclk);
    +	if (ret)
    +		return ret;
    +
    +	ret = clk_prepare_enable(master->sysclk);
    +	if (ret)
    +		goto err_disable_pclk;
    +
    +	if (readl(master->regs + DEV_ID) != DEV_ID_I3C_MASTER) {
    +		ret = -EINVAL;
    +		goto err_disable_sysclk;
    +	}
    +
    +	spin_lock_init(&master->xferqueue.lock);
    +	INIT_LIST_HEAD(&master->xferqueue.list);
    +
    +	INIT_WORK(&master->hj_work, cdns_i3c_master_hj);
    +	writel(0xffffffff, master->regs + MST_IDR);
    +	writel(0xffffffff, master->regs + SLV_IDR);
    +	ret = devm_request_irq(&pdev->dev, irq, cdns_i3c_master_interrupt, 0,
    +			       dev_name(&pdev->dev), master);
    +	if (ret)
    +		goto err_disable_sysclk;
    +
    +	platform_set_drvdata(pdev, master);
    +
    +	val = readl(master->regs + CONF_STATUS0);
    +
    +	/* Device ID0 is reserved to describe this master. */
    +	master->maxdevs = CONF_STATUS0_DEVS_NUM(val);
    +	master->free_rr_slots = GENMASK(master->maxdevs, 1);
    +
    +	val = readl(master->regs + CONF_STATUS1);
    +	master->caps.cmdfifodepth = CONF_STATUS1_CMD_DEPTH(val);
    +	master->caps.rxfifodepth = CONF_STATUS1_RX_DEPTH(val);
    +	master->caps.txfifodepth = CONF_STATUS1_TX_DEPTH(val);
    +	master->caps.ibirfifodepth = 16;

IBI fifo depth is hardcoded. You can read this value from CONF_STATUS0 register.

    +	master->caps.cmdrfifodepth = 16;

CMDR fifo depth is hardcoded. You can read this value from CONF_STATUS0 register also.

    +
    +	spin_lock_init(&master->ibi.lock);
    +	master->ibi.num_slots = CONF_STATUS1_IBI_HW_RES(val);
    +	master->ibi.slots = devm_kzalloc(&pdev->dev,
    +					 sizeof(*master->ibi.slots) *
    +					 master->ibi.num_slots,
    +					 GFP_KERNEL);
    +	if (!master->ibi.slots)
    +		goto err_disable_sysclk;
    +
    +	writel(IBIR_THR(1), master->regs + CMD_IBI_THR_CTRL);
    +	writel(MST_INT_IBIR_THR, master->regs + MST_IER);
    +	writel(DEVS_CTRL_DEV_CLR_ALL, master->regs + DEVS_CTRL);
    +
    +	ret = i3c_master_register(&master->base, &pdev->dev,
    +				  &cdns_i3c_master_ops, false);
    +	if (ret)
    +		goto err_disable_sysclk;
    +
    +	return 0;
    +
    +err_disable_sysclk:
    +	clk_disable_unprepare(master->sysclk);
    +
    +err_disable_pclk:
    +	clk_disable_unprepare(master->pclk);
    +
    +	return ret;
    +}
    
Regards,
Przemyslaw Gaj

  reply	other threads:[~2018-06-04  9:24 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30  7:47 [PATCH v4 00/10] Add the I3C subsystem Boris Brezillon
2018-03-30  7:47 ` [PATCH v4 01/10] i3c: Add core I3C infrastructure Boris Brezillon
2018-06-04  9:11   ` Przemyslaw Gaj
2018-06-04 11:24     ` Boris Brezillon
2018-06-14  4:19   ` Wolfram Sang
2018-06-14  7:07     ` Boris Brezillon
2018-06-14  8:15       ` Wolfram Sang
2018-06-20 11:37   ` Sekhar Nori
2018-06-20 12:47     ` Boris Brezillon
2018-07-11 14:01   ` Arnd Bergmann
2018-07-11 14:41     ` Boris Brezillon
2018-07-11 15:03       ` Boris Brezillon
2018-07-11 15:39       ` Arnd Bergmann
2018-07-11 17:12         ` Boris Brezillon
2018-07-11 20:10           ` Arnd Bergmann
2018-07-11 22:09             ` Boris Brezillon
2018-07-12  8:21               ` Arnd Bergmann
2018-07-12  8:46                 ` Boris Brezillon
2018-07-12 10:03                   ` Arnd Bergmann
2018-07-12 10:24                     ` Boris Brezillon
2018-07-12  4:41           ` Peter Rosin
2018-07-12  8:04             ` Boris Brezillon
2018-07-12  8:08             ` Arnd Bergmann
2018-07-12  8:44               ` Peter Rosin
2018-03-30  7:47 ` [PATCH v4 02/10] docs: driver-api: Add I3C documentation Boris Brezillon
2018-03-30  7:47 ` [PATCH v4 03/10] i3c: Add sysfs ABI spec Boris Brezillon
2018-04-29 13:37   ` Greg Kroah-Hartman
2018-04-30  9:10     ` Boris Brezillon
2018-05-02  9:47     ` Geert Uytterhoeven
2018-05-02 11:10       ` Greg Kroah-Hartman
2018-05-02 11:32         ` Geert Uytterhoeven
2018-03-30  7:47 ` [PATCH v4 04/10] dt-bindings: i3c: Document core bindings Boris Brezillon
2018-03-30  7:55   ` Geert Uytterhoeven
2018-03-30  7:59     ` Boris Brezillon
2018-04-09 20:24   ` Rob Herring
2018-03-30  7:47 ` [PATCH v4 05/10] dt-bindings: i3c: Add macros to help fill I3C/I2C device's reg property Boris Brezillon
2018-03-30  7:47 ` [PATCH v4 06/10] MAINTAINERS: Add myself as the I3C subsystem maintainer Boris Brezillon
2018-03-30  7:47 ` [PATCH v4 07/10] i3c: master: Add driver for Cadence IP Boris Brezillon
2018-06-04  9:24   ` Przemyslaw Gaj [this message]
2018-06-04 11:26     ` Boris Brezillon
2018-03-30  7:47 ` [PATCH v4 08/10] dt-bindings: i3c: Document Cadence I3C master bindings Boris Brezillon
2018-04-09 20:25   ` Rob Herring
2018-03-30  7:47 ` [PATCH v4 09/10] gpio: Add a driver for Cadence I3C GPIO expander Boris Brezillon
2018-04-26  8:44   ` Linus Walleij
2018-06-22  8:24     ` Boris Brezillon
2018-03-30  7:47 ` [PATCH v4 10/10] dt-bindings: gpio: Add bindings for Cadence I3C gpio expander Boris Brezillon
2018-04-09 20:26   ` Rob Herring
2018-04-23 17:38 ` [PATCH v4 00/10] Add the I3C subsystem Boris Brezillon
2018-04-23 17:56   ` Greg Kroah-Hartman
2018-04-29 13:36     ` Greg Kroah-Hartman
2018-04-30  9:37       ` Boris Brezillon

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=9613475C-ECAE-4AD6-9C02-55C9214A6489@cadence.com \
    --to=pgaj@cadence.com \
    --cc=Vitor.Soares@synopsys.com \
    --cc=Xiang.Lin@synaptics.com \
    --cc=adouglas@cadence.com \
    --cc=agolec@cadence.com \
    --cc=alicja@cadence.com \
    --cc=arnd@arndb.de \
    --cc=bfolta@cadence.com \
    --cc=boris.brezillon@bootlin.com \
    --cc=corbet@lwn.net \
    --cc=cwronka@cadence.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dkos@cadence.com \
    --cc=galak@codeaurora.org \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linus.walleij@linaro.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=nm@ti.com \
    --cc=pawel.moll@arm.com \
    --cc=psroka@cadence.com \
    --cc=rafalc@cadence.com \
    --cc=robh+dt@kernel.org \
    --cc=sureshp@cadence.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=wsa@the-dreams.de \
    /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;
as well as URLs for NNTP newsgroup(s).