mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] MCI patches
@ 2013-05-27  8:52 Sascha Hauer
  2013-05-27  8:52 ` [PATCH 1/7] driver: Attach info callback to device, not to driver Sascha Hauer
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

Some time ago we introduced the possibility to register the
SD/MMC device files with specific names to get persistent
names for them. The devices needed to probe/info the cards are
still named mcix though and still have dynamic numbers. This
series renames the devices to the same name as the device files.

Also for the i.MX ESDHC controller on i.MX51 we allow to specify
aliases for the controllers. The devices are now registered
using the aliases making it possible to have persistent names for
devicetree based boards.

Sascha

----------------------------------------------------------------
Sascha Hauer (7):
      driver: Attach info callback to device, not to driver
      mci: make mci device a pure device
      mci: embed mci device into struct mci
      mci: set name of mci device to same name as the filename
      of: Add of_alias_get function
      mci: imx-esdhc: allow to specify devicename via OF alias
      ARM: i.MX51: Add aliases for MMC controllers

 arch/arm/boards/freescale-mx51-pdk/board.c |   6 +-
 arch/arm/dts/imx51.dtsi                    |   4 +
 arch/sandbox/board/hostfile.c              |   5 +-
 drivers/ata/ahci.c                         |   2 +-
 drivers/ata/sata-imx.c                     |   2 +-
 drivers/base/driver.c                      |  18 +--
 drivers/mci/atmel_mci.c                    |   8 +-
 drivers/mci/imx-esdhc.c                    |   7 +-
 drivers/mci/mci-core.c                     | 235 ++++++++++++++---------------
 drivers/mci/mxs.c                          |  14 +-
 drivers/mci/s3c.c                          |   8 +-
 drivers/misc/jtag.c                        |  40 ++---
 drivers/mtd/nor/cfi_flash.c                |   3 +-
 drivers/net/cs8900.c                       |   3 +-
 drivers/of/base.c                          |  13 ++
 drivers/video/fb.c                         |   3 +-
 drivers/video/s3c24xx.c                    |   8 +-
 drivers/video/stm.c                        |   3 +-
 include/driver.h                           |   5 +-
 include/mci.h                              |   2 +-
 include/of.h                               |   6 +
 21 files changed, 196 insertions(+), 199 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/7] driver: Attach info callback to device, not to driver
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  2013-05-27  8:52 ` [PATCH 2/7] mci: make mci device a pure device Sascha Hauer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

Since the info is device specific and not driver specific, attach
the callback to the device. This makes it possible to have a info
callback for a device which does not have a driver attached.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/sandbox/board/hostfile.c |  5 +++--
 drivers/ata/ahci.c            |  2 +-
 drivers/ata/sata-imx.c        |  2 +-
 drivers/base/driver.c         | 18 ++----------------
 drivers/mci/atmel_mci.c       |  8 +++-----
 drivers/mci/mci-core.c        |  8 +++-----
 drivers/mci/mxs.c             | 14 +++++---------
 drivers/mci/s3c.c             |  8 +++-----
 drivers/misc/jtag.c           | 40 ++++++++++++++++++++--------------------
 drivers/mtd/nor/cfi_flash.c   |  3 ++-
 drivers/net/cs8900.c          |  3 ++-
 drivers/video/fb.c            |  3 ++-
 drivers/video/s3c24xx.c       |  8 +++-----
 drivers/video/stm.c           |  3 ++-
 include/driver.h              |  5 ++---
 15 files changed, 54 insertions(+), 76 deletions(-)

diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 48c6ea3..ac29cfa 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -77,6 +77,9 @@ static int hf_probe(struct device_d *dev)
 	priv->cdev.size = hf->size;
 	priv->cdev.ops = &hf_fops;
 	priv->cdev.priv = hf;
+
+	dev->info = hf_info;
+
 #ifdef CONFIG_FS_DEVFS
 	devfs_create(&priv->cdev);
 #endif
@@ -87,7 +90,6 @@ static int hf_probe(struct device_d *dev)
 static struct driver_d hf_drv = {
 	.name  = "hostfile",
 	.probe = hf_probe,
-	.info  = hf_info,
 };
 device_platform_driver(hf_drv);
 
@@ -111,4 +113,3 @@ int barebox_register_filedev(struct hf_platform_data *hf)
 
 	return sandbox_add_device(dev);
 }
-
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 37419f2..7def9a0 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -635,6 +635,7 @@ static int ahci_probe(struct device_d *dev)
 	ahci->dev = dev;
 	ahci->mmio_base = regs;
 	dev->priv = ahci;
+	dev->info = ahci_info;
 
 	ret = ahci_add_host(ahci);
 	if (ret)
@@ -654,7 +655,6 @@ static __maybe_unused struct of_device_id ahci_dt_ids[] = {
 static struct driver_d ahci_driver = {
 	.name   = "ahci",
 	.probe  = ahci_probe,
-	.info	= ahci_info,
 	.of_compatible = DRV_OF_COMPAT(ahci_dt_ids),
 };
 device_platform_driver(ahci_driver);
diff --git a/drivers/ata/sata-imx.c b/drivers/ata/sata-imx.c
index bd48fae..13bf116 100644
--- a/drivers/ata/sata-imx.c
+++ b/drivers/ata/sata-imx.c
@@ -107,6 +107,7 @@ static int imx_sata_probe(struct device_d *dev)
 
 	imx_ahci->ahci.dev = dev;
 	dev->priv = &imx_ahci->ahci;
+	dev->info = ahci_info,
 
 	ret = ahci_add_host(&imx_ahci->ahci);
 	if (ret)
@@ -143,7 +144,6 @@ static struct platform_device_id imx_sata_ids[] = {
 static struct driver_d imx_sata_driver = {
 	.name   = "imx-sata",
 	.probe  = imx_sata_probe,
-	.info	= ahci_info,
 	.id_table = imx_sata_ids,
 };
 device_platform_driver(imx_sata_driver);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 30a4bc5..c885630 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -201,15 +201,6 @@ struct driver_d *get_driver_by_name(const char *name)
 	return NULL;
 }
 
-static void noinfo(struct device_d *dev)
-{
-	printf("no info available for %s\n", dev_name(dev));
-}
-
-static void noshortinfo(struct device_d *dev)
-{
-}
-
 int register_driver(struct driver_d *drv)
 {
 	struct device_d *dev = NULL;
@@ -221,11 +212,6 @@ int register_driver(struct driver_d *drv)
 	list_add_tail(&drv->list, &driver_list);
 	list_add_tail(&drv->bus_list, &drv->bus->driver_list);
 
-	if (!drv->info)
-		drv->info = noinfo;
-	if (!drv->shortinfo)
-		drv->shortinfo = noshortinfo;
-
 	bus_for_each_device(drv->bus, dev)
 		match(drv, dev);
 
@@ -489,8 +475,8 @@ static int do_devinfo(int argc, char *argv[])
 		printf("bus: %s\n\n", dev->bus ?
 				dev->bus->name : "none");
 
-		if (dev->driver)
-			dev->driver->info(dev);
+		if (dev->info)
+			dev->info(dev);
 
 		printf("%s\n", list_empty(&dev->parameters) ?
 				"no parameters available" : "Parameters:");
diff --git a/drivers/mci/atmel_mci.c b/drivers/mci/atmel_mci.c
index c5fd306..b5873f9 100644
--- a/drivers/mci/atmel_mci.c
+++ b/drivers/mci/atmel_mci.c
@@ -470,7 +470,6 @@ static int atmci_request(struct mci_host *mci, struct mci_cmd *cmd, struct mci_d
 	return atmci_cmd_done(host, stat);
 }
 
-#ifdef CONFIG_MCI_INFO
 static void atmci_info(struct device_d *mci_dev)
 {
 	struct atmel_mci *host = mci_dev->priv;
@@ -493,7 +492,6 @@ static void atmci_info(struct device_d *mci_dev)
 		gpio_is_valid(pd->detect_pin) ? "yes" : "no");
 
 }
-#endif /* CONFIG_MCI_INFO */
 /*
  * HSMCI (High Speed MCI) module is not fully compatible with MCI module.
  * HSMCI provides DMA support and a new config register but no more supports
@@ -603,6 +601,9 @@ static int atmci_probe(struct device_d *hw_dev)
 	else
 		host->sdc_reg = ATMCI_SDCSEL_SLOT_A;
 
+	if (IS_ENABLED(CONFIG_MCI_INFO))
+		hw_dev->info = atmci_info;
+
 	mci_register(&host->mci);
 
 	return 0;
@@ -617,8 +618,5 @@ err_gpio_cd_request:
 static struct driver_d atmci_driver = {
 	.name	= "atmel_mci",
 	.probe	= atmci_probe,
-#ifdef CONFIG_MCI_INFO
-	.info	= atmci_info,
-#endif
 };
 device_platform_driver(atmci_driver);
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 5367b4f..5c00018 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1281,7 +1281,6 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 
 /* ------------------ attach to the device API --------------------------- */
 
-#ifdef CONFIG_MCI_INFO
 /**
  * Extract the Manufacturer ID from the CID
  * @param mci Instance data
@@ -1407,7 +1406,6 @@ static void mci_info(struct device_d *mci_dev)
 	printf("  Manufacturing date: %u.%u\n", extract_mtd_month(mci),
 		extract_mtd_year(mci));
 }
-#endif
 
 /**
  * Check if the MCI card is already probed
@@ -1616,6 +1614,9 @@ static int mci_probe(struct device_d *mci_dev)
 		goto on_error;
 	}
 
+	if (IS_ENABLED(CONFIG_MCI_INFO))
+		mci->dev.info = mci_info;
+
 #ifdef CONFIG_MCI_STARTUP
 	/* if enabled, probe the attached card immediately */
 	mci_card_probe(mci);
@@ -1631,9 +1632,6 @@ on_error:
 static struct driver_d mci_driver = {
 	.name	= "mci",
 	.probe	= mci_probe,
-#ifdef CONFIG_MCI_INFO
-	.info	= mci_info,
-#endif
 };
 
 static int mci_init(void)
diff --git a/drivers/mci/mxs.c b/drivers/mci/mxs.c
index 9dee863..e6f40eb 100644
--- a/drivers/mci/mxs.c
+++ b/drivers/mci/mxs.c
@@ -536,7 +536,6 @@ static void mxs_mci_set_ios(struct mci_host *host, struct mci_ios *ios)
 
 /* ----------------------------------------------------------------------- */
 
-#ifdef CONFIG_MCI_INFO
 const unsigned char bus_width[3] = { 1, 4, 8 };
 
 static void mxs_mci_info(struct device_d *hw_dev)
@@ -550,7 +549,6 @@ static void mxs_mci_info(struct device_d *hw_dev)
 	printf("  Bus width: %u bit\n", bus_width[mxs_mci->bus_width]);
 	printf("\n");
 }
-#endif
 
 static int mxs_mci_probe(struct device_d *hw_dev)
 {
@@ -617,10 +615,11 @@ static int mxs_mci_probe(struct device_d *hw_dev)
 			host->f_max, mxs_mci_get_unit_clock(mxs_mci) / 2 / 1);
 	}
 
-#ifdef CONFIG_MCI_INFO
-	mxs_mci->f_min = host->f_min;
-	mxs_mci->f_max = host->f_max;
-#endif
+	if (IS_ENABLED(CONFIG_MCI_INFO)) {
+		mxs_mci->f_min = host->f_min;
+		mxs_mci->f_max = host->f_max;
+		hw_dev->info = mxs_mci_info;
+	}
 
 	return mci_register(host);
 }
@@ -628,8 +627,5 @@ static int mxs_mci_probe(struct device_d *hw_dev)
 static struct driver_d mxs_mci_driver = {
         .name  = "mxs_mci",
         .probe = mxs_mci_probe,
-#ifdef CONFIG_MCI_INFO
-	.info = mxs_mci_info,
-#endif
 };
 device_platform_driver(mxs_mci_driver);
diff --git a/drivers/mci/s3c.c b/drivers/mci/s3c.c
index 4e7345c..773c84a 100644
--- a/drivers/mci/s3c.c
+++ b/drivers/mci/s3c.c
@@ -700,7 +700,6 @@ static void mci_set_ios(struct mci_host *host, struct mci_ios *ios)
 
 /* ----------------------------------------------------------------------- */
 
-#ifdef CONFIG_MCI_INFO
 static void s3c_info(struct device_d *hw_dev)
 {
 	struct s3c_mci_host *host = hw_dev->priv;
@@ -720,7 +719,6 @@ static void s3c_info(struct device_d *hw_dev)
 	printf("\n  Card detection support: %s\n",
 		pd->gpio_detect != 0 ? "yes" : "no");
 }
-#endif
 
 static int s3c_mci_probe(struct device_d *hw_dev)
 {
@@ -751,6 +749,9 @@ static int s3c_mci_probe(struct device_d *hw_dev)
 	s3c_host->host.f_min = pd->f_min == 0 ? s3c_get_pclk() / 256 : pd->f_min;
 	s3c_host->host.f_max = pd->f_max == 0 ? s3c_get_pclk() / 2 : pd->f_max;
 
+	if (IS_ENABLED(iCONFIG_MCI_INFO))
+		hw_dev->info = s3c_info;
+
 	/*
 	 * Start the clock to let the engine and the card finishes its startup
 	 */
@@ -763,8 +764,5 @@ static int s3c_mci_probe(struct device_d *hw_dev)
 static struct driver_d s3c_mci_driver = {
         .name  = "s3c_mci",
         .probe = s3c_mci_probe,
-#ifdef CONFIG_MCI_INFO
-	.info = s3c_info,
-#endif
 };
 device_platform_driver(s3c_mci_driver);
diff --git a/drivers/misc/jtag.c b/drivers/misc/jtag.c
index d302237..310da81 100644
--- a/drivers/misc/jtag.c
+++ b/drivers/misc/jtag.c
@@ -269,6 +269,25 @@ static struct file_operations jtag_operations = {
 	.ioctl = jtag_ioctl,
 };
 
+static void jtag_info(struct device_d *pdev)
+{
+	int dn, ret;
+	struct jtag_rd_id jid;
+	struct jtag_info *info = pdev->priv;
+
+	printf(" JTAG:\n");
+	printf("  Devices found: %d\n", info->devices);
+	for (dn = 0; dn < info->devices; dn++) {
+		jid.device = dn;
+		ret = jtag_ioctl(&info->cdev, JTAG_GET_ID, &jid);
+		printf("  Device number: %d\n", dn);
+		if (ret == -1)
+			printf("   JTAG_GET_ID failed: %s\n", strerror(errno));
+		else
+			printf("   ID: 0x%lX\n", jid.id);
+	}
+}
+
 static int jtag_probe(struct device_d *pdev)
 {
 	int i, ret;
@@ -323,6 +342,7 @@ static int jtag_probe(struct device_d *pdev)
 	info->devices = i;
 	info->pdata = pdata;
 	pdev->priv = info;
+	pdev->info = jtag_info;
 
 	info->cdev.name = JTAG_NAME;
 	info->cdev.dev = pdev;
@@ -341,25 +361,6 @@ fail_devfs_create:
 	return ret;
 }
 
-static void jtag_info(struct device_d *pdev)
-{
-	int dn, ret;
-	struct jtag_rd_id jid;
-	struct jtag_info *info = pdev->priv;
-
-	printf(" JTAG:\n");
-	printf("  Devices found: %d\n", info->devices);
-	for (dn = 0; dn < info->devices; dn++) {
-		jid.device = dn;
-		ret = jtag_ioctl(&info->cdev, JTAG_GET_ID, &jid);
-		printf("  Device number: %d\n", dn);
-		if (ret == -1)
-			printf("   JTAG_GET_ID failed: %s\n", strerror(errno));
-		else
-			printf("   ID: 0x%lX\n", jid.id);
-	}
-}
-
 static void jtag_remove(struct device_d *pdev)
 {
 	struct jtag_info *info = (struct jtag_info *) pdev->priv;
@@ -374,7 +375,6 @@ static struct driver_d jtag_driver = {
 	.name = JTAG_NAME,
 	.probe = jtag_probe,
 	.remove = jtag_remove,
-	.info = jtag_info,
 };
 device_platform_driver(jtag_driver);
 
diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c
index 4b4e29d..bcc125c 100644
--- a/drivers/mtd/nor/cfi_flash.c
+++ b/drivers/mtd/nor/cfi_flash.c
@@ -987,6 +987,8 @@ static int cfi_probe (struct device_d *dev)
 	dev_info(dev, "found cfi flash at %p, size %ld\n",
 			info->base, info->size);
 
+	dev->info = cfi_info;
+
 	cfi_init_mtd(info);
 
 	return 0;
@@ -1003,7 +1005,6 @@ static __maybe_unused struct of_device_id cfi_dt_ids[] = {
 static struct driver_d cfi_driver = {
 	.name    = "cfi_flash",
 	.probe   = cfi_probe,
-	.info    = cfi_info,
 	.of_compatible = DRV_OF_COMPAT(cfi_dt_ids),
 };
 device_platform_driver(cfi_driver);
diff --git a/drivers/net/cs8900.c b/drivers/net/cs8900.c
index b0d045a..aa9d9a0 100644
--- a/drivers/net/cs8900.c
+++ b/drivers/net/cs8900.c
@@ -459,6 +459,8 @@ static int cs8900_probe(struct device_d *dev)
 	edev->set_ethaddr = cs8900_set_ethaddr;
 	edev->parent = dev;
 
+	dev->info = cs8900_info;
+
 	eth_register(edev);
 	return 0;
 }
@@ -466,6 +468,5 @@ static int cs8900_probe(struct device_d *dev)
 static struct driver_d cs8900_driver = {
 	.name = "cs8900",
 	.probe = cs8900_probe,
-	.info = cs8900_info,
 };
 device_platform_driver(cs8900_driver);
diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 0e00cb7..a4a8b00 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -144,7 +144,6 @@ static void fb_info(struct device_d *dev)
 
 static struct driver_d fb_driver = {
 	.name  = "fb",
-	.info = fb_info,
 };
 
 static int fb_match(struct device_d *dev, struct driver_d *drv)
@@ -165,6 +164,8 @@ static int fb_probe(struct device_d *dev)
 		dev_set_param(dev, "mode_name", info->mode_list[0].name);
 	}
 
+	dev->info = fb_info;
+
 	return devfs_create(&info->cdev);
 }
 
diff --git a/drivers/video/s3c24xx.c b/drivers/video/s3c24xx.c
index d641cfa..c3e05c6 100644
--- a/drivers/video/s3c24xx.c
+++ b/drivers/video/s3c24xx.c
@@ -321,7 +321,6 @@ static int s3cfb_activate_var(struct fb_info *fb_info)
  * Print some information about the current hardware state
  * @param hw_dev S3C video device
  */
-#ifdef CONFIG_DRIVER_VIDEO_S3C_VERBOSE
 static void s3cfb_info(struct device_d *hw_dev)
 {
 	uint32_t con1, addr1, addr2, addr3;
@@ -340,7 +339,6 @@ static void s3cfb_info(struct device_d *hw_dev)
 	printf("  Virtual screen offset size: %u half words\n", GET_OFFSIZE(addr3));
 	printf("  Virtual screen page width: %u half words\n", GET_PAGE_WIDTH(addr3));
 }
-#endif
 
 /*
  * There is only one video hardware instance available.
@@ -390,6 +388,9 @@ static int s3cfb_probe(struct device_d *hw_dev)
 	fbi.passive_display = pdata->passive_display;
 	fbi.enable = pdata->enable;
 
+	if (IS_ENABLED(CONFIG_DRIVER_VIDEO_S3C_VERBOSE))
+		hw_dev->info = s3cfb_info;
+
 	ret = register_framebuffer(&fbi.info);
 	if (ret != 0) {
 		dev_err(hw_dev, "Failed to register framebuffer\n");
@@ -402,9 +403,6 @@ static int s3cfb_probe(struct device_d *hw_dev)
 static struct driver_d s3cfb_driver = {
 	.name	= "s3c_fb",
 	.probe	= s3cfb_probe,
-#ifdef CONFIG_DRIVER_VIDEO_S3C_VERBOSE
-	.info	= s3cfb_info,
-#endif
 };
 device_platform_driver(s3cfb_driver);
 
diff --git a/drivers/video/stm.c b/drivers/video/stm.c
index cefdef2..606e39a 100644
--- a/drivers/video/stm.c
+++ b/drivers/video/stm.c
@@ -502,6 +502,8 @@ static int stmfb_probe(struct device_d *hw_dev)
 	else
 		fbi.info.bits_per_pixel = 16;
 
+	hw_dev->info = stmfb_info;
+
 	ret = register_framebuffer(&fbi.info);
 	if (ret != 0) {
 		dev_err(hw_dev, "Failed to register framebuffer\n");
@@ -514,7 +516,6 @@ static int stmfb_probe(struct device_d *hw_dev)
 static struct driver_d stmfb_driver = {
 	.name	= "stmfb",
 	.probe	= stmfb_probe,
-	.info	= stmfb_info,
 };
 device_platform_driver(stmfb_driver);
 
diff --git a/include/driver.h b/include/driver.h
index 7d5f65e..3e6c36f 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -107,6 +107,8 @@ struct device_d {
 	struct device_node *device_node;
 
 	const struct of_device_id *of_id_entry;
+
+	void    (*info) (struct device_d *);
 };
 
 /** @brief Describes a driver present in the system */
@@ -124,9 +126,6 @@ struct driver_d {
 	/*! Called if an instance of a device is gone. */
 	void     (*remove)(struct device_d *);
 
-	void    (*info) (struct device_d *);
-	void    (*shortinfo) (struct device_d *);
-
 	struct bus_type *bus;
 
 	struct platform_device_id *id_table;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/7] mci: make mci device a pure device
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
  2013-05-27  8:52 ` [PATCH 1/7] driver: Attach info callback to device, not to driver Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  2013-05-27  8:52 ` [PATCH 3/7] mci: embed mci device into struct mci Sascha Hauer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

No need to match and probe the device if all that we want is a logical
deivice for the mci.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 5c00018..9cc6cfb 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1629,15 +1629,11 @@ on_error:
 	return rc;
 }
 
-static struct driver_d mci_driver = {
-	.name	= "mci",
-	.probe	= mci_probe,
-};
-
 static int mci_init(void)
 {
 	sector_buf = xmemalign(32, 512);
-	return platform_driver_register(&mci_driver);
+
+	return 0;
 }
 
 device_initcall(mci_init);
@@ -1649,12 +1645,28 @@ device_initcall(mci_init);
  */
 int mci_register(struct mci_host *host)
 {
+	int ret;
 	struct device_d *mci_dev = xzalloc(sizeof(struct device_d));
 
+	strcpy(mci_dev->name, "mci");
 	mci_dev->id = DEVICE_ID_DYNAMIC;
-	strcpy(mci_dev->name, mci_driver.name);
 	mci_dev->platform_data = host;
 	mci_dev->parent = host->hw_dev;
 
-	return platform_device_register(mci_dev);
+	ret = register_device(mci_dev);
+	if (ret)
+		goto err_free;
+
+	ret = mci_probe(mci_dev);
+	if (ret)
+		goto err_unregister;
+
+	return 0;
+
+err_unregister:
+	unregister_device(mci_dev);
+err_free:
+	free(mci_dev);
+
+	return ret;
 }
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/7] mci: embed mci device into struct mci
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
  2013-05-27  8:52 ` [PATCH 1/7] driver: Attach info callback to device, not to driver Sascha Hauer
  2013-05-27  8:52 ` [PATCH 2/7] mci: make mci device a pure device Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  2013-05-27  8:52 ` [PATCH 4/7] mci: set name of mci device to same name as the filename Sascha Hauer
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

To safe a separate allocation and to make the code simpler.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c | 217 ++++++++++++++++++++++---------------------------
 include/mci.h          |   2 +-
 2 files changed, 96 insertions(+), 123 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 9cc6cfb..1aa98db 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -215,7 +215,7 @@ static int mci_go_idle(struct mci *mci)
 	err = mci_send_cmd(mci, &cmd, NULL);
 
 	if (err) {
-		dev_dbg(mci->mci_dev, "Activating IDLE state failed: %d\n", err);
+		dev_dbg(&mci->dev, "Activating IDLE state failed: %d\n", err);
 		return err;
 	}
 
@@ -252,7 +252,7 @@ static int sd_send_op_cond(struct mci *mci)
 		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, 0, MMC_RSP_R1);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			dev_dbg(mci->mci_dev, "Preparing SD for operating conditions failed: %d\n", err);
+			dev_dbg(&mci->dev, "Preparing SD for operating conditions failed: %d\n", err);
 			return err;
 		}
 
@@ -264,7 +264,7 @@ static int sd_send_op_cond(struct mci *mci)
 		mci_setup_cmd(&cmd, SD_CMD_APP_SEND_OP_COND, arg, MMC_RSP_R3);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			dev_dbg(mci->mci_dev, "SD operation condition set failed: %d\n", err);
+			dev_dbg(&mci->dev, "SD operation condition set failed: %d\n", err);
 			return err;
 		}
 		udelay(1000);
@@ -277,7 +277,7 @@ static int sd_send_op_cond(struct mci *mci)
 	} while (busy && timeout--);
 
 	if (timeout <= 0) {
-		dev_dbg(mci->mci_dev, "SD operation condition set timed out\n");
+		dev_dbg(&mci->dev, "SD operation condition set timed out\n");
 		return -ENODEV;
 	}
 
@@ -320,7 +320,7 @@ static int mmc_send_op_cond(struct mci *mci)
 		err = mci_send_cmd(mci, &cmd, NULL);
 
 		if (err) {
-			dev_dbg(mci->mci_dev, "Preparing MMC for operating conditions failed: %d\n", err);
+			dev_dbg(&mci->dev, "Preparing MMC for operating conditions failed: %d\n", err);
 			return err;
 		}
 
@@ -328,7 +328,7 @@ static int mmc_send_op_cond(struct mci *mci)
 	} while (!(cmd.response[0] & OCR_BUSY) && timeout--);
 
 	if (timeout <= 0) {
-		dev_dbg(mci->mci_dev, "SD operation condition set timed out\n");
+		dev_dbg(&mci->dev, "SD operation condition set timed out\n");
 		return -ENODEV;
 	}
 
@@ -438,7 +438,7 @@ static int mmc_change_freq(struct mci *mci)
 
 	err = mci_send_ext_csd(mci, mci->ext_csd);
 	if (err) {
-		dev_dbg(mci->mci_dev, "Preparing for frequency setup failed: %d\n", err);
+		dev_dbg(&mci->dev, "Preparing for frequency setup failed: %d\n", err);
 		return err;
 	}
 
@@ -447,7 +447,7 @@ static int mmc_change_freq(struct mci *mci)
 	err = mci_switch(mci, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
 
 	if (err) {
-		dev_dbg(mci->mci_dev, "MMC frequency changing failed: %d\n", err);
+		dev_dbg(&mci->dev, "MMC frequency changing failed: %d\n", err);
 		return err;
 	}
 
@@ -455,13 +455,13 @@ static int mmc_change_freq(struct mci *mci)
 	err = mci_send_ext_csd(mci, mci->ext_csd);
 
 	if (err) {
-		dev_dbg(mci->mci_dev, "Verifying frequency change failed: %d\n", err);
+		dev_dbg(&mci->dev, "Verifying frequency change failed: %d\n", err);
 		return err;
 	}
 
 	/* No high-speed support */
 	if (!mci->ext_csd[EXT_CSD_HS_TIMING]) {
-		dev_dbg(mci->mci_dev, "No high-speed support\n");
+		dev_dbg(&mci->dev, "No high-speed support\n");
 		return 0;
 	}
 
@@ -544,14 +544,14 @@ static int sd_change_freq(struct mci *mci)
 	if (mmc_host_is_spi(host))
 		return 0;
 
-	dev_dbg(mci->mci_dev, "Changing transfer frequency\n");
+	dev_dbg(&mci->dev, "Changing transfer frequency\n");
 	mci->card_caps = 0;
 
 	/* Read the SCR to find out if this card supports higher speeds */
 	mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		dev_dbg(mci->mci_dev, "Query SD card capabilities failed: %d\n", err);
+		dev_dbg(&mci->dev, "Query SD card capabilities failed: %d\n", err);
 		return err;
 	}
 
@@ -560,7 +560,7 @@ static int sd_change_freq(struct mci *mci)
 	timeout = 3;
 
 retry_scr:
-	dev_dbg(mci->mci_dev, "Trying to read the SCR (try %d of %d)\n", 4 - timeout, 3);
+	dev_dbg(&mci->dev, "Trying to read the SCR (try %d of %d)\n", 4 - timeout, 3);
 	data.dest = (char *)scr;
 	data.blocksize = 8;
 	data.blocks = 1;
@@ -568,12 +568,12 @@ retry_scr:
 
 	err = mci_send_cmd(mci, &cmd, &data);
 	if (err) {
-		dev_dbg(mci->mci_dev, " Catch error (%d)", err);
+		dev_dbg(&mci->dev, " Catch error (%d)", err);
 		if (timeout--) {
-			dev_dbg(mci->mci_dev, "-- retrying\n");
+			dev_dbg(&mci->dev, "-- retrying\n");
 			goto retry_scr;
 		}
-		dev_dbg(mci->mci_dev, "-- giving up\n");
+		dev_dbg(&mci->dev, "-- giving up\n");
 		return err;
 	}
 
@@ -604,7 +604,7 @@ retry_scr:
 		err = sd_switch(mci, SD_SWITCH_CHECK, 0, 1,
 				(uint8_t*)switch_status);
 		if (err) {
-			dev_dbg(mci->mci_dev, "Checking SD transfer switch frequency feature failed: %d\n", err);
+			dev_dbg(&mci->dev, "Checking SD transfer switch frequency feature failed: %d\n", err);
 			return err;
 		}
 
@@ -622,7 +622,7 @@ retry_scr:
 
 	err = sd_switch(mci, SD_SWITCH_SWITCH, 0, 1, (uint8_t*)switch_status);
 	if (err) {
-		dev_dbg(mci->mci_dev, "Switching SD transfer frequency failed: %d\n", err);
+		dev_dbg(&mci->dev, "Switching SD transfer frequency failed: %d\n", err);
 		return err;
 	}
 
@@ -725,7 +725,7 @@ static void mci_detect_version_from_csd(struct mci *mci)
 			break;
 		}
 
-		dev_info(mci->mci_dev, "detected card version %s\n", vstr);
+		dev_info(&mci->dev, "detected card version %s\n", vstr);
 	}
 }
 
@@ -777,13 +777,13 @@ static void mci_extract_max_tran_speed_from_csd(struct mci *mci)
 	unit = tran_speed_unit[(mci->csd[0] & 0x7)];
 	time = tran_speed_time[((mci->csd[0] >> 3) & 0xf)];
 	if ((unit == 0) || (time == 0)) {
-		dev_dbg(mci->mci_dev, "Unsupported 'TRAN_SPEED' unit/time value."
+		dev_dbg(&mci->dev, "Unsupported 'TRAN_SPEED' unit/time value."
 				" Can't calculate card's max. transfer speed\n");
 		return;
 	}
 
 	mci->tran_speed = time * unit;
-	dev_dbg(mci->mci_dev, "Transfer speed: %u\n", mci->tran_speed);
+	dev_dbg(&mci->dev, "Transfer speed: %u\n", mci->tran_speed);
 }
 
 /**
@@ -801,7 +801,7 @@ static void mci_extract_block_lengths_from_csd(struct mci *mci)
 	else
 		mci->write_bl_len = 1 << ((mci->csd[3] >> 22) & 0xf);
 
-	dev_dbg(mci->mci_dev, "Max. block length are: Write=%u, Read=%u Bytes\n",
+	dev_dbg(&mci->dev, "Max. block length are: Write=%u, Read=%u Bytes\n",
 		mci->write_bl_len, mci->read_bl_len);
 }
 
@@ -830,7 +830,7 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
 	}
 
 	mci->capacity *= 1 << UNSTUFF_BITS(mci->csd, 80, 4);;
-	dev_dbg(mci->mci_dev, "Capacity: %u MiB\n", (unsigned)(mci->capacity >> 20));
+	dev_dbg(&mci->dev, "Capacity: %u MiB\n", (unsigned)(mci->capacity >> 20));
 }
 
 static int mmc_compare_ext_csds(struct mci *mci, unsigned bus_width)
@@ -844,7 +844,7 @@ static int mmc_compare_ext_csds(struct mci *mci, unsigned bus_width)
 	bw_ext_csd = xmalloc(512);
 	err = mci_send_ext_csd(mci, bw_ext_csd);
 	if (err) {
-		dev_info(mci->mci_dev, "mci_send_ext_csd failed with %d\n", err);
+		dev_info(&mci->dev, "mci_send_ext_csd failed with %d\n", err);
 		if (bus_width != MMC_BUS_WIDTH_1)
 			err = -EINVAL;
 		goto out;
@@ -900,19 +900,19 @@ static int mci_startup_sd(struct mci *mci)
 	int err;
 
 	if (mci->card_caps & MMC_MODE_4BIT) {
-		dev_dbg(mci->mci_dev, "Prepare for bus width change\n");
+		dev_dbg(&mci->dev, "Prepare for bus width change\n");
 		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			dev_dbg(mci->mci_dev, "Preparing SD for bus width change failed: %d\n", err);
+			dev_dbg(&mci->dev, "Preparing SD for bus width change failed: %d\n", err);
 			return err;
 		}
 
-		dev_dbg(mci->mci_dev, "Set SD bus width to 4 bit\n");
+		dev_dbg(&mci->dev, "Set SD bus width to 4 bit\n");
 		mci_setup_cmd(&cmd, SD_CMD_APP_SET_BUS_WIDTH, 2, MMC_RSP_R1);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			dev_dbg(mci->mci_dev, "Changing SD bus width failed: %d\n", err);
+			dev_dbg(&mci->dev, "Changing SD bus width failed: %d\n", err);
 			/* TODO continue with 1 bit? */
 			return err;
 		}
@@ -1003,25 +1003,25 @@ static int mci_startup(struct mci *mci)
 		err = mci_send_cmd(mci, &cmd, NULL);
 
 		if (err) {
-			dev_dbg(mci->mci_dev, "Can't enable CRC check : %d\n", err);
+			dev_dbg(&mci->dev, "Can't enable CRC check : %d\n", err);
 			return err;
 		}
 	}
 #endif
 
-	dev_dbg(mci->mci_dev, "Put the Card in Identify Mode\n");
+	dev_dbg(&mci->dev, "Put the Card in Identify Mode\n");
 
 	/* Put the Card in Identify Mode */
 	mci_setup_cmd(&cmd, mmc_host_is_spi(host) ? MMC_CMD_SEND_CID : MMC_CMD_ALL_SEND_CID, 0, MMC_RSP_R2);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		dev_dbg(mci->mci_dev, "Can't bring card into identify mode: %d\n", err);
+		dev_dbg(&mci->dev, "Can't bring card into identify mode: %d\n", err);
 		return err;
 	}
 
 	memcpy(mci->cid, cmd.response, 16);
 
-	dev_dbg(mci->mci_dev, "Card's identification data is: %08X-%08X-%08X-%08X\n",
+	dev_dbg(&mci->dev, "Card's identification data is: %08X-%08X-%08X-%08X\n",
 		mci->cid[0], mci->cid[1], mci->cid[2], mci->cid[3]);
 
 	/*
@@ -1030,11 +1030,11 @@ static int mci_startup(struct mci *mci)
 	 * This also puts the cards into Standby State
 	 */
 	if (!mmc_host_is_spi(host)) { /* cmd not supported in spi */
-		dev_dbg(mci->mci_dev, "Get/Set relative address\n");
+		dev_dbg(&mci->dev, "Get/Set relative address\n");
 		mci_setup_cmd(&cmd, SD_CMD_SEND_RELATIVE_ADDR, mci->rca << 16, MMC_RSP_R6);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			dev_dbg(mci->mci_dev, "Get/Set relative address failed: %d\n", err);
+			dev_dbg(&mci->dev, "Get/Set relative address failed: %d\n", err);
 			return err;
 		}
 	}
@@ -1042,19 +1042,19 @@ static int mci_startup(struct mci *mci)
 	if (IS_SD(mci))
 		mci->rca = (cmd.response[0] >> 16) & 0xffff;
 
-	dev_dbg(mci->mci_dev, "Get card's specific data\n");
+	dev_dbg(&mci->dev, "Get card's specific data\n");
 	/* Get the Card-Specific Data */
 	mci_setup_cmd(&cmd, MMC_CMD_SEND_CSD, mci->rca << 16, MMC_RSP_R2);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		dev_dbg(mci->mci_dev, "Getting card's specific data failed: %d\n", err);
+		dev_dbg(&mci->dev, "Getting card's specific data failed: %d\n", err);
 		return err;
 	}
 
 	/* CSD is of 128 bit */
 	memcpy(mci->csd, cmd.response, 16);
 
-	dev_dbg(mci->mci_dev, "Card's specific data is: %08X-%08X-%08X-%08X\n",
+	dev_dbg(&mci->dev, "Card's specific data is: %08X-%08X-%08X-%08X\n",
 		mci->csd[0], mci->csd[1], mci->csd[2], mci->csd[3]);
 
 	mci_detect_version_from_csd(mci);
@@ -1064,25 +1064,25 @@ static int mci_startup(struct mci *mci)
 	/* sanitiy? */
 	if (mci->read_bl_len > SECTOR_SIZE) {
 		mci->read_bl_len = SECTOR_SIZE;
-		dev_dbg(mci->mci_dev, "Limiting max. read block size down to %u\n",
+		dev_dbg(&mci->dev, "Limiting max. read block size down to %u\n",
 				mci->read_bl_len);
 	}
 
 	if (mci->write_bl_len > SECTOR_SIZE) {
 		mci->write_bl_len = SECTOR_SIZE;
-		dev_dbg(mci->mci_dev, "Limiting max. write block size down to %u\n",
+		dev_dbg(&mci->dev, "Limiting max. write block size down to %u\n",
 				mci->read_bl_len);
 	}
-	dev_dbg(mci->mci_dev, "Read block length: %u, Write block length: %u\n",
+	dev_dbg(&mci->dev, "Read block length: %u, Write block length: %u\n",
 		mci->read_bl_len, mci->write_bl_len);
 
 	if (!mmc_host_is_spi(host)) { /* cmd not supported in spi */
-		dev_dbg(mci->mci_dev, "Select the card, and put it into Transfer Mode\n");
+		dev_dbg(&mci->dev, "Select the card, and put it into Transfer Mode\n");
 		/* Select the card, and put it into Transfer Mode */
 		mci_setup_cmd(&cmd, MMC_CMD_SELECT_CARD, mci->rca << 16, MMC_RSP_R1b);
 		err = mci_send_cmd(mci, &cmd, NULL);
 		if (err) {
-			dev_dbg(mci->mci_dev, "Putting in transfer mode failed: %d\n", err);
+			dev_dbg(&mci->dev, "Putting in transfer mode failed: %d\n", err);
 			return err;
 		}
 	}
@@ -1141,15 +1141,15 @@ static int sd_send_if_cond(struct mci *mci)
 		MMC_RSP_R7);
 	err = mci_send_cmd(mci, &cmd, NULL);
 	if (err) {
-		dev_dbg(mci->mci_dev, "Query interface conditions failed: %d\n", err);
+		dev_dbg(&mci->dev, "Query interface conditions failed: %d\n", err);
 		return err;
 	}
 
 	if ((cmd.response[0] & 0xff) != 0xaa) {
-		dev_dbg(mci->mci_dev, "Card cannot work with hosts supply voltages\n");
+		dev_dbg(&mci->dev, "Card cannot work with hosts supply voltages\n");
 		return -EINVAL;
 	} else {
-		dev_dbg(mci->mci_dev, "SD Card Rev. 2.00 or later detected\n");
+		dev_dbg(&mci->dev, "SD Card Rev. 2.00 or later detected\n");
 		mci->version = SD_VERSION_2;
 	}
 
@@ -1209,28 +1209,28 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 	mci_blk_part_switch(part);
 
 	if (host->card_write_protected && host->card_write_protected(host)) {
-		dev_err(mci->mci_dev, "card write protected\n");
+		dev_err(&mci->dev, "card write protected\n");
 		return -EPERM;
 	}
 
-	dev_dbg(mci->mci_dev, "%s: Write %d block(s), starting at %d\n",
+	dev_dbg(&mci->dev, "%s: Write %d block(s), starting at %d\n",
 		__func__, num_blocks, block);
 
 	if (mci->write_bl_len != SECTOR_SIZE) {
-		dev_dbg(mci->mci_dev, "MMC/SD block size is not %d bytes (its %u bytes instead)\n",
+		dev_dbg(&mci->dev, "MMC/SD block size is not %d bytes (its %u bytes instead)\n",
 				SECTOR_SIZE, mci->read_bl_len);
 		return -EINVAL;
 	}
 
 	/* size of the block number field in the MMC/SD command is 32 bit only */
 	if (block > MAX_BUFFER_NUMBER) {
-		dev_dbg(mci->mci_dev, "Cannot handle block number %d. Too large!\n", block);
+		dev_dbg(&mci->dev, "Cannot handle block number %d. Too large!\n", block);
 		return -EINVAL;
 	}
 
 	rc = mci_block_write(mci, buffer, block, num_blocks);
 	if (rc != 0) {
-		dev_dbg(mci->mci_dev, "Writing block %d failed with %d\n", block, rc);
+		dev_dbg(&mci->dev, "Writing block %d failed with %d\n", block, rc);
 		return rc;
 	}
 
@@ -1256,23 +1256,23 @@ static int mci_sd_read(struct block_device *blk, void *buffer, int block,
 
 	mci_blk_part_switch(part);
 
-	dev_dbg(mci->mci_dev, "%s: Read %d block(s), starting at %d\n",
+	dev_dbg(&mci->dev, "%s: Read %d block(s), starting at %d\n",
 		__func__, num_blocks, block);
 
 	if (mci->read_bl_len != 512) {
-		dev_dbg(mci->mci_dev, "MMC/SD block size is not 512 bytes (its %u bytes instead)\n",
+		dev_dbg(&mci->dev, "MMC/SD block size is not 512 bytes (its %u bytes instead)\n",
 				mci->read_bl_len);
 		return -EINVAL;
 	}
 
 	if (block > MAX_BUFFER_NUMBER) {
-		dev_err(mci->mci_dev, "Cannot handle block number %d. Too large!\n", block);
+		dev_err(&mci->dev, "Cannot handle block number %d. Too large!\n", block);
 		return -EINVAL;
 	}
 
 	rc = mci_read_block(mci, buffer, block, num_blocks);
 	if (rc != 0) {
-		dev_dbg(mci->mci_dev, "Reading block %d failed with %d\n", block, rc);
+		dev_dbg(&mci->dev, "Reading block %d failed with %d\n", block, rc);
 		return rc;
 	}
 
@@ -1369,9 +1369,9 @@ static unsigned extract_mtd_year(struct mci *mci)
  * Output some valuable information when the user runs 'devinfo' on an MCI device
  * @param mci MCI device instance
  */
-static void mci_info(struct device_d *mci_dev)
+static void mci_info(struct device_d *dev)
 {
-	struct mci *mci = mci_dev->priv;
+	struct mci *mci = container_of(dev, struct mci, dev);
 
 	if (mci->ready_for_use == 0) {
 		printf(" No information available:\n  MCI card not probed yet\n");
@@ -1464,14 +1464,14 @@ static int mci_card_probe(struct mci *mci)
 	int i, rc, disknum;
 
 	if (host->card_present && !host->card_present(host)) {
-		dev_err(mci->mci_dev, "no card inserted\n");
+		dev_err(&mci->dev, "no card inserted\n");
 		return -ENODEV;
 	}
 
 	/* start with a host interface reset */
-	rc = (host->init)(host, mci->mci_dev);
+	rc = (host->init)(host, &mci->dev);
 	if (rc) {
-		dev_err(mci->mci_dev, "Cannot reset the SD/MMC interface\n");
+		dev_err(&mci->dev, "Cannot reset the SD/MMC interface\n");
 		return rc;
 	}
 
@@ -1482,7 +1482,7 @@ static int mci_card_probe(struct mci *mci)
 	/* reset the card */
 	rc = mci_go_idle(mci);
 	if (rc) {
-		dev_warn(mci->mci_dev, "Cannot reset the SD/MMC card\n");
+		dev_warn(&mci->dev, "Cannot reset the SD/MMC card\n");
 		goto on_error;
 	}
 
@@ -1491,7 +1491,7 @@ static int mci_card_probe(struct mci *mci)
 	rc = sd_send_op_cond(mci);
 	if (rc && rc == -ETIMEDOUT) {
 		/* If the command timed out, we check for an MMC card */
-		dev_dbg(mci->mci_dev, "Card seems to be a MultiMediaCard\n");
+		dev_dbg(&mci->dev, "Card seems to be a MultiMediaCard\n");
 		rc = mmc_send_op_cond(mci);
 	}
 
@@ -1507,11 +1507,11 @@ static int mci_card_probe(struct mci *mci)
 
 	rc = mci_startup(mci);
 	if (rc) {
-		dev_dbg(mci->mci_dev, "Card's startup fails with %d\n", rc);
+		dev_dbg(&mci->dev, "Card's startup fails with %d\n", rc);
 		goto on_error;
 	}
 
-	dev_dbg(mci->mci_dev, "Card is up and running now, registering as a disk\n");
+	dev_dbg(&mci->dev, "Card is up and running now, registering as a disk\n");
 	mci->ready_for_use = 1;	/* TODO now or later? */
 
 	for (i = 0; i < mci->nr_parts; i++) {
@@ -1521,21 +1521,21 @@ static int mci_card_probe(struct mci *mci)
 		 * An MMC/SD card acts like an ordinary disk.
 		 * So, re-use the disk driver to gain access to this media
 		 */
-		part->blk.dev = mci->mci_dev;
+		part->blk.dev = &mci->dev;
 		part->blk.ops = &mci_ops;
 
 		rc = blockdevice_register(&part->blk);
 		if (rc != 0) {
-			dev_err(mci->mci_dev, "Failed to register MCI/SD blockdevice\n");
+			dev_err(&mci->dev, "Failed to register MCI/SD blockdevice\n");
 			goto on_error;
 		}
-		dev_info(mci->mci_dev, "registered %s\n", part->blk.cdev.name);
+		dev_info(&mci->dev, "registered %s\n", part->blk.cdev.name);
 
 		/* create partitions on demand */
 		if (part->area_type == MMC_BLK_DATA_AREA_MAIN) {
 			rc = parse_partition_table(&part->blk);
 			if (rc != 0) {
-				dev_warn(mci->mci_dev, "No partition table found\n");
+				dev_warn(&mci->dev, "No partition table found\n");
 				rc = 0; /* it's not a failure */
 			}
 		}
@@ -1543,13 +1543,13 @@ static int mci_card_probe(struct mci *mci)
 		if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
 				part->area_type == MMC_BLK_DATA_AREA_BOOT &&
 				!mci->param_boot) {
-			mci->param_boot = dev_add_param_enum(mci->mci_dev, "boot",
+			mci->param_boot = dev_add_param_enum(&mci->dev, "boot",
 					mci_set_boot, NULL, &mci->bootpart,
 					mci_boot_names, ARRAY_SIZE(mci_boot_names), mci);
 		}
 	}
 
-	dev_dbg(mci->mci_dev, "SD Card successfully added\n");
+	dev_dbg(&mci->dev, "SD Card successfully added\n");
 
 on_error:
 	if (rc != 0) {
@@ -1586,49 +1586,6 @@ static int mci_set_probe(struct param_d *param, void *priv)
 	return 0;
 }
 
-/**
- * Prepare for MCI card's usage
- * @param mci_dev MCI device instance
- * @return 0 on success
- *
- * This routine will probe an attached MCI card immediately or provide
- * a parameter to do it later on user's demand.
- */
-static int mci_probe(struct device_d *mci_dev)
-{
-	struct mci *mci;
-	int rc;
-
-	mci = xzalloc(sizeof(struct mci));
-	mci_dev->priv = mci;
-	mci->mci_dev = mci_dev;
-	mci->host = mci_dev->platform_data;
-
-	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(mci_dev));
-
-	mci->param_probe = dev_add_param_bool(mci_dev, "probe",
-			mci_set_probe, NULL, &mci->probe, mci);
-
-	if (IS_ERR(mci->param_probe)) {
-		dev_dbg(mci->mci_dev, "Failed to add 'probe' parameter to the MCI device\n");
-		goto on_error;
-	}
-
-	if (IS_ENABLED(CONFIG_MCI_INFO))
-		mci->dev.info = mci_info;
-
-#ifdef CONFIG_MCI_STARTUP
-	/* if enabled, probe the attached card immediately */
-	mci_card_probe(mci);
-#endif
-
-	return 0;
-
-on_error:
-	free(mci);
-	return rc;
-}
-
 static int mci_init(void)
 {
 	sector_buf = xmemalign(32, 512);
@@ -1645,28 +1602,44 @@ device_initcall(mci_init);
  */
 int mci_register(struct mci_host *host)
 {
+	struct mci *mci;
 	int ret;
-	struct device_d *mci_dev = xzalloc(sizeof(struct device_d));
 
-	strcpy(mci_dev->name, "mci");
-	mci_dev->id = DEVICE_ID_DYNAMIC;
-	mci_dev->platform_data = host;
-	mci_dev->parent = host->hw_dev;
+	mci = xzalloc(sizeof(*mci));
+	mci->host = host;
 
-	ret = register_device(mci_dev);
+	strcpy(mci->dev.name, "mci");
+	mci->dev.id = DEVICE_ID_DYNAMIC;
+	mci->dev.platform_data = host;
+	mci->dev.parent = host->hw_dev;
+
+	ret = register_device(&mci->dev);
 	if (ret)
 		goto err_free;
 
-	ret = mci_probe(mci_dev);
-	if (ret)
+	dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(&mci->dev));
+
+	mci->param_probe = dev_add_param_bool(&mci->dev, "probe",
+			mci_set_probe, NULL, &mci->probe, mci);
+
+	if (IS_ERR(mci->param_probe)) {
+		dev_dbg(&mci->dev, "Failed to add 'probe' parameter to the MCI device\n");
 		goto err_unregister;
+	}
+
+	if (IS_ENABLED(CONFIG_MCI_INFO))
+		mci->dev.info = mci_info;
+
+	/* if enabled, probe the attached card immediately */
+	if (IS_ENABLED(CONFIG_MCI_STARTUP))
+		mci_card_probe(mci);
 
 	return 0;
 
 err_unregister:
-	unregister_device(mci_dev);
+	unregister_device(&mci->dev);
 err_free:
-	free(mci_dev);
+	free(mci);
 
 	return ret;
 }
diff --git a/include/mci.h b/include/mci.h
index 1735986..1eb967d 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -330,7 +330,7 @@ struct mci_part {
 /** MMC/SD and interface instance information */
 struct mci {
 	struct mci_host *host;		/**< the host for this card */
-	struct device_d *mci_dev;	/**< the device for our disk (mcix) */
+	struct device_d dev;		/**< the device for our disk (mcix) */
 	unsigned version;
 	/** != 0 when a high capacity card is connected (OCR -> OCR_HCS) */
 	int high_capacity;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/7] mci: set name of mci device to same name as the filename
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-05-27  8:52 ` [PATCH 3/7] mci: embed mci device into struct mci Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  2013-05-27  8:52 ` [PATCH 5/7] of: Add of_alias_get function Sascha Hauer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

We already have the possibility to register a mci with a certain
filename to get persistent names. However, the device needed to
find the probe parameter still has the name 'mcix'. This patch
changes this by registering the mci device with the same name
as the filename.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 1aa98db..4a463d5 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1608,8 +1608,14 @@ int mci_register(struct mci_host *host)
 	mci = xzalloc(sizeof(*mci));
 	mci->host = host;
 
-	strcpy(mci->dev.name, "mci");
-	mci->dev.id = DEVICE_ID_DYNAMIC;
+	if (host->devname) {
+		strcpy(mci->dev.name, host->devname);
+		mci->dev.id = DEVICE_ID_SINGLE;
+	} else {
+		strcpy(mci->dev.name, "mci");
+		mci->dev.id = DEVICE_ID_DYNAMIC;
+	}
+
 	mci->dev.platform_data = host;
 	mci->dev.parent = host->hw_dev;
 
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/7] of: Add of_alias_get function
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-05-27  8:52 ` [PATCH 4/7] mci: set name of mci device to same name as the filename Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  2013-05-27  8:52 ` [PATCH 6/7] mci: imx-esdhc: allow to specify devicename via OF alias Sascha Hauer
  2013-05-27  8:52 ` [PATCH 7/7] ARM: i.MX51: Add aliases for MMC controllers Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

This is used to retrieve the name of the alias for a given
devicenode.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/base.c | 13 +++++++++++++
 include/of.h      |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index e2a8bb5..b58a19b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -212,6 +212,19 @@ int of_alias_get_id(struct device_node *np, const char *stem)
 }
 EXPORT_SYMBOL_GPL(of_alias_get_id);
 
+const char *of_alias_get(struct device_node *np)
+{
+	struct property *pp;
+
+	list_for_each_entry(pp, &of_aliases->properties, list) {
+		if (!strcmp(np->full_name, pp->value))
+			return pp->name;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(of_alias_get);
+
 u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
 {
 	struct property *p;
diff --git a/include/of.h b/include/of.h
index a804ec4..6c75cbd 100644
--- a/include/of.h
+++ b/include/of.h
@@ -178,6 +178,7 @@ struct cdev;
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 
 int of_alias_get_id(struct device_node *np, const char *stem);
+const char *of_alias_get(struct device_node *np);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
@@ -197,6 +198,11 @@ static inline int of_alias_get_id(struct device_node *np, const char *stem)
 	return -ENOENT;
 }
 
+static inline const char *of_alias_get(struct device_node *np)
+{
+	return NULL;
+}
+
 static inline int of_device_is_stdout_path(struct device_d *dev)
 {
 	return 0;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 6/7] mci: imx-esdhc: allow to specify devicename via OF alias
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-05-27  8:52 ` [PATCH 5/7] of: Add of_alias_get function Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  2013-05-27  8:52 ` [PATCH 7/7] ARM: i.MX51: Add aliases for MMC controllers Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/imx-esdhc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 46bd6d2..1e3b307 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -535,8 +535,13 @@ static int fsl_esdhc_probe(struct device_d *dev)
 	else
 		mci->host_caps = MMC_MODE_4BIT;
 
-	if (pdata && pdata->devname)
+	if (pdata && pdata->devname) {
 		mci->devname = pdata->devname;
+	} else if (dev->device_node) {
+		const char *alias = of_alias_get(dev->device_node);
+		if (alias)
+			mci->devname = xstrdup(alias);
+	}
 
 	if (caps & ESDHC_HOSTCAPBLT_HSS)
 		mci->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 7/7] ARM: i.MX51: Add aliases for MMC controllers
  2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-05-27  8:52 ` [PATCH 6/7] mci: imx-esdhc: allow to specify devicename via OF alias Sascha Hauer
@ 2013-05-27  8:52 ` Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-27  8:52 UTC (permalink / raw)
  To: barebox

To get persistent names for the MMC controllers add aliases to
them

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/freescale-mx51-pdk/board.c | 6 +++---
 arch/arm/dts/imx51.dtsi                    | 4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index 2c934b5..6807796 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -170,7 +170,7 @@ static int f3s_devices_init(void)
 	armlinux_set_bootparams((void *)0x90000100);
 	armlinux_set_architecture(MACH_TYPE_MX51_BABBAGE);
 
-	imx51_bbu_internal_mmc_register_handler("mmc", "/dev/disk0",
+	imx51_bbu_internal_mmc_register_handler("mmc", "/dev/mmc0",
 		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start,
 		flash_header_end - flash_header_start, 0);
 
@@ -181,8 +181,8 @@ device_initcall(f3s_devices_init);
 
 static int f3s_part_init(void)
 {
-	devfs_add_partition("disk0", 0x00000, 0x40000, DEVFS_PARTITION_FIXED, "self0");
-	devfs_add_partition("disk0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
+	devfs_add_partition("mmc0", 0x00000, 0x40000, DEVFS_PARTITION_FIXED, "self0");
+	devfs_add_partition("mmc0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
 
 	return 0;
 }
diff --git a/arch/arm/dts/imx51.dtsi b/arch/arm/dts/imx51.dtsi
index 02c132d..a900287 100644
--- a/arch/arm/dts/imx51.dtsi
+++ b/arch/arm/dts/imx51.dtsi
@@ -22,6 +22,10 @@
 		gpio1 = &gpio2;
 		gpio2 = &gpio3;
 		gpio3 = &gpio4;
+		mmc0 = &esdhc1;
+		mmc1 = &esdhc2;
+		mmc2 = &esdhc3;
+		mmc3 = &esdhc4;
 	};
 
 	tzic: tz-interrupt-controller@e0000000 {
-- 
1.8.2.rc2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-05-27  8:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-27  8:52 [PATCH] MCI patches Sascha Hauer
2013-05-27  8:52 ` [PATCH 1/7] driver: Attach info callback to device, not to driver Sascha Hauer
2013-05-27  8:52 ` [PATCH 2/7] mci: make mci device a pure device Sascha Hauer
2013-05-27  8:52 ` [PATCH 3/7] mci: embed mci device into struct mci Sascha Hauer
2013-05-27  8:52 ` [PATCH 4/7] mci: set name of mci device to same name as the filename Sascha Hauer
2013-05-27  8:52 ` [PATCH 5/7] of: Add of_alias_get function Sascha Hauer
2013-05-27  8:52 ` [PATCH 6/7] mci: imx-esdhc: allow to specify devicename via OF alias Sascha Hauer
2013-05-27  8:52 ` [PATCH 7/7] ARM: i.MX51: Add aliases for MMC controllers Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox