All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
To: u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>, Stefan Roese <sr@denx.de>,
	Tom Rini <trini@konsulko.com>,
	Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Subject: [PATCH 3/6] pci: msc01: convert to driver model
Date: Tue,  6 Jul 2021 16:22:19 +0200	[thread overview]
Message-ID: <20210706142222.497569-4-daniel.schwierzeck@gmail.com> (raw)
In-Reply-To: <20210706142222.497569-1-daniel.schwierzeck@gmail.com>

This driver is currently only used on MIPS Malta boards.

Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
---

 drivers/pci/pci_msc01.c | 70 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 69 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci_msc01.c b/drivers/pci/pci_msc01.c
index 04838200a8..ad203c86d0 100644
--- a/drivers/pci/pci_msc01.c
+++ b/drivers/pci/pci_msc01.c
@@ -4,7 +4,7 @@
  * Author: Paul Burton <paul.burton@mips.com>
  */
 
-#include <common.h>
+#include <dm.h>
 #include <init.h>
 #include <msc01.h>
 #include <pci.h>
@@ -62,6 +62,7 @@ static int msc01_config_access(struct msc01_pci_controller *msc01,
 	return 0;
 }
 
+#if !IS_ENABLED(CONFIG_DM_PCI)
 static int msc01_read_config_dword(struct pci_controller *hose, pci_dev_t dev,
 				   int where, u32 *value)
 {
@@ -123,3 +124,70 @@ void msc01_pci_init(void *base, unsigned long sys_bus, unsigned long sys_phys,
 	pci_register_hose(hose);
 	hose->last_busno = pci_hose_scan(hose);
 }
+#else
+static int msc01_pci_read_config(const struct udevice *dev, pci_dev_t bdf,
+				 uint where, ulong *val, enum pci_size_t size)
+{
+	struct msc01_pci_controller *msc01 = dev_get_priv(dev);
+	u32 data = 0;
+
+	if (msc01_config_access(msc01, PCI_ACCESS_READ, bdf, where, &data)) {
+		*val = pci_get_ff(size);
+		return 0;
+	}
+
+	*val = pci_conv_32_to_size(data, where, size);
+	return 0;
+}
+
+static int msc01_pci_write_config(struct udevice *dev, pci_dev_t bdf,
+				  uint where, ulong val, enum pci_size_t size)
+{
+	struct msc01_pci_controller *msc01 = dev_get_priv(dev);
+	u32 data = 0;
+
+	if (size == PCI_SIZE_32) {
+		data = val;
+	} else {
+		u32 old;
+
+		if (msc01_config_access(msc01, PCI_ACCESS_READ, bdf, where, &old))
+			return 0;
+
+		data = pci_conv_size_to_32(old, val, where, size);
+	}
+
+	msc01_config_access(msc01, PCI_ACCESS_WRITE, bdf, where, &data);
+	return 0;
+}
+
+static int msc01_pci_probe(struct udevice *dev)
+{
+	struct msc01_pci_controller *msc01 = dev_get_priv(dev);
+
+	msc01->base = dev_remap_addr(dev);
+	if (!msc01->base)
+		return -EINVAL;
+
+	return 0;
+}
+
+static const struct dm_pci_ops msc01_pci_ops = {
+	.read_config	= msc01_pci_read_config,
+	.write_config	= msc01_pci_write_config,
+};
+
+static const struct udevice_id msc01_pci_ids[] = {
+	{ .compatible = "mips,pci-msc01" },
+	{ }
+};
+
+U_BOOT_DRIVER(msc01_pci) = {
+	.name		= "msc01_pci",
+	.id		= UCLASS_PCI,
+	.of_match	= msc01_pci_ids,
+	.ops		= &msc01_pci_ops,
+	.probe		= msc01_pci_probe,
+	.priv_auto	= sizeof(struct msc01_pci_controller),
+};
+#endif
-- 
2.32.0


  parent reply	other threads:[~2021-07-06 14:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-06 14:22 [PATCH 0/6] Convert MIPS Malta boards to PCI DM Daniel Schwierzeck
2021-07-06 14:22 ` [PATCH 1/6] dm: pci: add option to map virtual system memory base address Daniel Schwierzeck
2021-07-09  7:11   ` Stefan Roese
2021-07-06 14:22 ` [PATCH 2/6] pci: gt64120: convert to driver model Daniel Schwierzeck
2021-07-08 22:31   ` Simon Glass
2021-07-06 14:22 ` Daniel Schwierzeck [this message]
2021-07-08 22:31   ` [PATCH 3/6] pci: msc01: " Simon Glass
2021-07-06 14:22 ` [PATCH 4/6] MIPS: malta: add DT bindings for PCI host controller Daniel Schwierzeck
2021-07-06 14:22 ` [PATCH 5/6] MIPS: malta: add support for PCI driver model Daniel Schwierzeck
2021-07-11  0:00   ` Simon Glass
2021-07-13  1:17     ` Daniel Schwierzeck
2021-07-13 20:17       ` Simon Glass
2021-07-06 14:22 ` [PATCH 6/6] MIPS: malta: enable " Daniel Schwierzeck
2021-07-15 18:53 ` [PATCH v2 0/6] Convert MIPS Malta boards to PCI DM Daniel Schwierzeck
2021-07-15 18:53   ` [PATCH v2 1/6] dm: pci: add option to map virtual system memory base address Daniel Schwierzeck
2021-07-20 18:33     ` Simon Glass
2021-07-15 18:53   ` [PATCH v2 2/6] pci: gt64120: convert to driver model Daniel Schwierzeck
2021-07-15 18:53   ` [PATCH v2 3/6] pci: msc01: " Daniel Schwierzeck
2021-07-15 18:53   ` [PATCH v2 4/6] MIPS: malta: add DT bindings for PCI host controller Daniel Schwierzeck
2021-07-15 18:54   ` [PATCH v2 5/6] MIPS: malta: add support for PCI driver model Daniel Schwierzeck
2021-07-15 18:54   ` [PATCH v2 6/6] MIPS: malta: enable " Daniel Schwierzeck
2021-07-18 18:42   ` [PATCH v2 0/6] Convert MIPS Malta boards to PCI DM Daniel Schwierzeck

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=20210706142222.497569-4-daniel.schwierzeck@gmail.com \
    --to=daniel.schwierzeck@gmail.com \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.