All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Cohen <david.a.cohen@linux.intel.com>
To: x86@kernel.org, hpa@zytor.com, mingo@redhat.com, tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org,
	sathyanarayanan.kuppuswamy@linux.intel.com,
	David Cohen <david.a.cohen@linux.intel.com>
Subject: [PATCH v5 06/12] intel_mid: Refactored sfi_parse_devs() function
Date: Tue, 15 Oct 2013 21:11:35 -0700	[thread overview]
Message-ID: <1381896701-23476-7-git-send-email-david.a.cohen@linux.intel.com> (raw)
In-Reply-To: <1381896701-23476-1-git-send-email-david.a.cohen@linux.intel.com>

From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>

SFI device_id[] table parsing code is duplicated in every SFI
device handler. This patch removes this code duplication, by
adding a seperate function get_device_id() to parse through the
device table. Also this patch moves the SPI, I2C, IPC info code from
sfi_parse_devs() to respective device handlers.

Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: David Cohen <david.a.cohen@linux.intel.com>
---
 arch/x86/platform/intel-mid/intel-mid.c | 141 ++++++++++++++++----------------
 1 file changed, 71 insertions(+), 70 deletions(-)

diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
index 742b7bf..f9c4be8 100644
--- a/arch/x86/platform/intel-mid/intel-mid.c
+++ b/arch/x86/platform/intel-mid/intel-mid.c
@@ -831,20 +831,15 @@ static void __init install_irq_resource(struct platform_device *pdev, int irq)
 	platform_device_add_resources(pdev, &res, 1);
 }
 
-static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
+static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *pentry,
+					struct devs_id *dev)
 {
-	const struct devs_id *dev = device_ids;
 	struct platform_device *pdev;
 	void *pdata = NULL;
 
-	while (dev->name[0]) {
-		if (dev->type == SFI_DEV_TYPE_IPC &&
-			!strncmp(dev->name, entry->name, SFI_NAME_LEN)) {
-			pdata = dev->get_platform_data(entry);
-			break;
-		}
-		dev++;
-	}
+	pr_debug("IPC bus, name = %16.16s, irq = 0x%2x\n",
+		pentry->name, pentry->irq);
+	pdata = dev->get_platform_data(pentry);
 
 	/*
 	 * On Medfield the platform device creation is handled by the MSIC
@@ -853,68 +848,94 @@ static void __init sfi_handle_ipc_dev(struct sfi_device_table_entry *entry)
 	if (intel_mid_has_msic())
 		return;
 
-	pdev = platform_device_alloc(entry->name, 0);
+	pdev = platform_device_alloc(pentry->name, 0);
 	if (pdev == NULL) {
 		pr_err("out of memory for SFI platform device '%s'.\n",
-			entry->name);
+			pentry->name);
 		return;
 	}
-	install_irq_resource(pdev, entry->irq);
+	install_irq_resource(pdev, pentry->irq);
 
 	pdev->dev.platform_data = pdata;
 	intel_scu_device_register(pdev);
 }
 
-static void __init sfi_handle_spi_dev(struct spi_board_info *spi_info)
+static void __init sfi_handle_spi_dev(struct sfi_device_table_entry *pentry,
+					struct devs_id *dev)
 {
-	const struct devs_id *dev = device_ids;
+	struct spi_board_info spi_info;
 	void *pdata = NULL;
 
-	while (dev->name[0]) {
-		if (dev->type == SFI_DEV_TYPE_SPI &&
-			!strncmp(dev->name, spi_info->modalias,
-						SFI_NAME_LEN)) {
-			pdata = dev->get_platform_data(spi_info);
-			break;
-		}
-		dev++;
-	}
-	spi_info->platform_data = pdata;
+	memset(&spi_info, 0, sizeof(spi_info));
+	strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
+	spi_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
+	spi_info.bus_num = pentry->host_num;
+	spi_info.chip_select = pentry->addr;
+	spi_info.max_speed_hz = pentry->max_freq;
+	pr_debug("SPI bus=%d, name=%16.16s, irq=0x%2x, max_freq=%d, cs=%d\n",
+		spi_info.bus_num,
+		spi_info.modalias,
+		spi_info.irq,
+		spi_info.max_speed_hz,
+		spi_info.chip_select);
+
+	pdata = dev->get_platform_data(&spi_info);
+
+	spi_info.platform_data = pdata;
 	if (dev->delay)
-		intel_scu_spi_device_register(spi_info);
+		intel_scu_spi_device_register(&spi_info);
 	else
-		spi_register_board_info(spi_info, 1);
+		spi_register_board_info(&spi_info, 1);
 }
 
-static void __init sfi_handle_i2c_dev(int bus, struct i2c_board_info *i2c_info)
+static void __init sfi_handle_i2c_dev(struct sfi_device_table_entry *pentry,
+					struct devs_id *dev)
 {
-	const struct devs_id *dev = device_ids;
+	struct i2c_board_info i2c_info;
 	void *pdata = NULL;
 
+	memset(&i2c_info, 0, sizeof(i2c_info));
+	strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
+	i2c_info.irq = ((pentry->irq == (u8)0xff) ? 0 : pentry->irq);
+	i2c_info.addr = pentry->addr;
+	pr_debug("I2C bus = %d, name = %16.16s, irq = 0x%2x, addr = 0x%x\n",
+		pentry->host_num,
+		i2c_info.type,
+		i2c_info.irq,
+		i2c_info.addr);
+	pdata = dev->get_platform_data(&i2c_info);
+	i2c_info.platform_data = pdata;
+
+	if (dev->delay)
+		intel_scu_i2c_device_register(pentry->host_num, &i2c_info);
+	else
+		i2c_register_board_info(pentry->host_num, &i2c_info, 1);
+}
+
+static struct devs_id __init *get_device_id(u8 type, char *name)
+{
+	struct devs_id *dev = device_ids;
+
+	if (device_ids == NULL)
+		return NULL;
+
 	while (dev->name[0]) {
-		if (dev->type == SFI_DEV_TYPE_I2C &&
-			!strncmp(dev->name, i2c_info->type, SFI_NAME_LEN)) {
-			pdata = dev->get_platform_data(i2c_info);
-			break;
+		if (dev->type == type &&
+			!strncmp(dev->name, name, SFI_NAME_LEN)) {
+			return dev;
 		}
 		dev++;
 	}
-	i2c_info->platform_data = pdata;
 
-	if (dev->delay)
-		intel_scu_i2c_device_register(bus, i2c_info);
-	else
-		i2c_register_board_info(bus, i2c_info, 1);
+	return NULL;
 }
 
-
 static int __init sfi_parse_devs(struct sfi_table_header *table)
 {
 	struct sfi_table_simple *sb;
 	struct sfi_device_table_entry *pentry;
-	struct spi_board_info spi_info;
-	struct i2c_board_info i2c_info;
-	int num, i, bus;
+	struct devs_id *dev = NULL;
+	int num, i;
 	int ioapic;
 	struct io_apic_irq_attr irq_attr;
 
@@ -939,40 +960,20 @@ static int __init sfi_parse_devs(struct sfi_table_header *table)
 		} else
 			irq = 0; /* No irq */
 
+		dev = get_device_id(pentry->type, pentry->name);
+
+		if ((dev == NULL) || (dev->get_platform_data == NULL))
+			continue;
+
 		switch (pentry->type) {
 		case SFI_DEV_TYPE_IPC:
-			pr_debug("info[%2d]: IPC bus, name = %16.16s, "
-				"irq = 0x%2x\n", i, pentry->name, pentry->irq);
-			sfi_handle_ipc_dev(pentry);
+			sfi_handle_ipc_dev(pentry, dev);
 			break;
 		case SFI_DEV_TYPE_SPI:
-			memset(&spi_info, 0, sizeof(spi_info));
-			strncpy(spi_info.modalias, pentry->name, SFI_NAME_LEN);
-			spi_info.irq = irq;
-			spi_info.bus_num = pentry->host_num;
-			spi_info.chip_select = pentry->addr;
-			spi_info.max_speed_hz = pentry->max_freq;
-			pr_debug("info[%2d]: SPI bus = %d, name = %16.16s, "
-				"irq = 0x%2x, max_freq = %d, cs = %d\n", i,
-				spi_info.bus_num,
-				spi_info.modalias,
-				spi_info.irq,
-				spi_info.max_speed_hz,
-				spi_info.chip_select);
-			sfi_handle_spi_dev(&spi_info);
+			sfi_handle_spi_dev(pentry, dev);
 			break;
 		case SFI_DEV_TYPE_I2C:
-			memset(&i2c_info, 0, sizeof(i2c_info));
-			bus = pentry->host_num;
-			strncpy(i2c_info.type, pentry->name, SFI_NAME_LEN);
-			i2c_info.irq = irq;
-			i2c_info.addr = pentry->addr;
-			pr_debug("info[%2d]: I2C bus = %d, name = %16.16s, "
-				"irq = 0x%2x, addr = 0x%x\n", i, bus,
-				i2c_info.type,
-				i2c_info.irq,
-				i2c_info.addr);
-			sfi_handle_i2c_dev(bus, &i2c_info);
+			sfi_handle_i2c_dev(pentry, dev);
 			break;
 		case SFI_DEV_TYPE_UART:
 		case SFI_DEV_TYPE_HSI:
-- 
1.8.4.rc3


  parent reply	other threads:[~2013-10-16  4:10 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16  4:11 [PATCH v5 00/12] rework arch/x86/platform/[mrst => intel-mid] David Cohen
2013-10-16  4:11 ` [PATCH v5 01/12] mrst: Fixed printk/pr_* related issues David Cohen
2013-10-17 18:18   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 02/12] mrst: Fixed indentation issues David Cohen
2013-10-17 18:18   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 03/12] mrst: Fixed checkpatch warnings David Cohen
2013-10-17 18:18   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 04/12] intel_mid: Renamed *mrst* to *intel_mid* David Cohen
2013-10-17 18:18   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 05/12] " David Cohen
2013-10-17 18:19   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` David Cohen [this message]
2013-10-17 18:19   ` [tip:x86/intel-mid] intel_mid: Refactored sfi_parse_devs() function tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 07/12] intel_mid: Added custom device_handler support David Cohen
2013-10-17 18:19   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 08/12] intel_mid: Added custom handler for ipc devices David Cohen
2013-10-17 18:19   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 09/12] intel_mid: Moved SFI related code to sfi.c David Cohen
2013-10-17 18:19   ` [tip:x86/intel-mid] " tip-bot for Kuppuswamy Sathyanarayanan
2013-10-16  4:11 ` [PATCH v5 10/12] intel-mid: sfi: allow struct devs_id.get_platform_data to be NULL David Cohen
2013-10-17 18:19   ` [tip:x86/intel-mid] " tip-bot for David Cohen
2013-10-16  4:11 ` [PATCH v5 11/12] x86: intel-mid: add section for sfi device table David Cohen
2013-10-17 18:20   ` [tip:x86/intel-mid] " tip-bot for David Cohen
2013-10-16  4:11 ` [PATCH v5 12/12] intel_mid: Moved board related code to a new file David Cohen
2013-10-16 23:13   ` [PATCH v6 " David Cohen
2013-10-16 23:45     ` [PATCH v7 12/12] intel_mid: move board related code to their own platform_<device>.* files David Cohen
2013-10-17  2:36       ` [PATCH v8 12/12] intel_mid: move board related codes " David Cohen
2013-10-17 18:20         ` [tip:x86/intel-mid] intel_mid: move platform device definitions " tip-bot for David Cohen

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=1381896701-23476-7-git-send-email-david.a.cohen@linux.intel.com \
    --to=david.a.cohen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sathyanarayanan.kuppuswamy@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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.