Skip to contentSkip to conversation

ARM: sa11x0: Implement autoloading of codec and codec pdata for mcp bus.

RFC New Jochen Friedrich 1 participant 1 message Apr 23, 2011

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 ARM: sa11x0: Implement autoloading of codec and codec pdata for mcp bus.

---
 arch/arm/mach-sa1100/assabet.c          |    1 +
 arch/arm/mach-sa1100/cerf.c             |    1 +
 arch/arm/mach-sa1100/collie.c           |    8 ++++-
 arch/arm/mach-sa1100/include/mach/mcp.h |    2 +
 arch/arm/mach-sa1100/lart.c             |    1 +
 arch/arm/mach-sa1100/shannon.c          |    1 +
 arch/arm/mach-sa1100/simpad.c           |    8 ++++-
 drivers/mfd/mcp-core.c                  |   22 +++++++++++++-
 drivers/mfd/mcp-sa11x0.c                |    3 +-
 drivers/mfd/ucb1x00-core.c              |   47 +++++++++++++++++++++++-------
 include/linux/mfd/mcp.h                 |    7 +++-
 include/linux/mfd/ucb1x00.h             |    5 ++-
 include/linux/mod_devicetable.h         |   11 +++++++
 scripts/mod/file2alias.c                |   13 ++++++++
 14 files changed, 111 insertions(+), 19 deletions(-)
arch/arm/mach-sa1100/assabet.c +1 -0
index 5778274..b3eded1 100644
@@ -202,6 +202,7 @@ static struct irda_platform_data assabet_irda_data = {
 static struct mcp_plat_data assabet_mcp_data = {
 	.mccr0		= MCCR0_ADM,
 	.sclk_rate	= 11981000,
+	.codec		= "ucb1x00",
 };
 
 static void __init assabet_init(void)
arch/arm/mach-sa1100/cerf.c +1 -0
index 7f3da4b..b7db7cd 100644
@@ -124,6 +124,7 @@ static void __init cerf_map_io(void)
 static struct mcp_plat_data cerf_mcp_data = {
 	.mccr0		= MCCR0_ADM,
 	.sclk_rate	= 11981000,
+	.codec		= "ucb1x00",
 };
 
 static void __init cerf_init(void)
arch/arm/mach-sa1100/collie.c +7 -1
index bd3e1bf..d607026 100644
@@ -27,6 +27,7 @@
 #include <linux/timer.h>
 #include <linux/gpio.h>
 #include <linux/pda_power.h>
+#include <linux/mfd/ucb1x00.h>
 
 #include <mach/hardware.h>
 #include <asm/mach-types.h>
@@ -84,10 +85,15 @@ static struct scoop_pcmcia_config collie_pcmcia_config = {
 	.num_devs	= 1,
 };
 
+static struct ucb1x00_plat_data collie_ucb1x00_data = {
+	.gpio_base	= COLLIE_TC35143_GPIO_BASE,
+};
+
 static struct mcp_plat_data collie_mcp_data = {
 	.mccr0		= MCCR0_ADM | MCCR0_ExtClk,
 	.sclk_rate	= 9216000,
-	.gpio_base	= COLLIE_TC35143_GPIO_BASE,
+	.codec		= "ucb1x00",
+	.codec_data	= &collie_ucb1x00_data;
 };
 
 /*
arch/arm/mach-sa1100/include/mach/mcp.h +2 -0
index ed1a331..b42fbd7 100644
@@ -17,6 +17,8 @@ struct mcp_plat_data {
 	u32 mccr1;
 	unsigned int sclk_rate;
 	int gpio_base;
+	const char *codec;
+	void *codec_data;
 };
 
 #endif
arch/arm/mach-sa1100/lart.c +1 -0
index 7b9556b..97be52c 100644
@@ -24,6 +24,7 @@
 static struct mcp_plat_data lart_mcp_data = {
 	.mccr0		= MCCR0_ADM,
 	.sclk_rate	= 11981000,
+	.codec		= "ucb1x00",
 };
 
 static void __init lart_init(void)
arch/arm/mach-sa1100/shannon.c +1 -0
index 7917b24..9ffa70f 100644
@@ -55,6 +55,7 @@ static struct resource shannon_flash_resource = {
 static struct mcp_plat_data shannon_mcp_data = {
 	.mccr0		= MCCR0_ADM,
 	.sclk_rate	= 11981000,
+	.codec		= "ucb1x00",
 };
 
 static void __init shannon_init(void)
arch/arm/mach-sa1100/simpad.c +7 -1
index cf3a68a..e1357d3 100644
@@ -14,6 +14,7 @@
 #include <linux/mtd/partitions.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/mfd/ucb1x00.h>
 
 #include <asm/irq.h>
 #include <mach/hardware.h>
@@ -187,10 +188,15 @@ static struct resource simpad_flash_resources [] = {
 	}
 };
 
+static struct ucb1x00_plat_data simpad_ucb1x00_data = {
+	.gpio_base	= SIMPAD_UCB1X00_GPIO_BASE,
+};
+
 static struct mcp_plat_data simpad_mcp_data = {
 	.mccr0		= MCCR0_ADM,
 	.sclk_rate	= 11981000,
-	.gpio_base	= SIMPAD_UCB1X00_GPIO_BASE,
+	.codec		= "ucb1300",
+	.codec_data	= &simpad_ucb1x00_data,
 };
 
 
drivers/mfd/mcp-core.c +20 -2
index 84815f9..4f05a87 100644
@@ -26,9 +26,26 @@
 #define to_mcp(d)		container_of(d, struct mcp, attached_device)
 #define to_mcp_driver(d)	container_of(d, struct mcp_driver, drv)
 
+static const struct mcp_device_id *mcp_match_id(const struct mcp_device_id *id,
+						const char *codec)
+{
+	while (id->name[0]) {
+		if (strcmp(codec, id->name) == 0)
+			return id;
+		id++;
+	}
+	return NULL;
+}
+
 static int mcp_bus_match(struct device *dev, struct device_driver *drv)
 {
-	return 1;
+	struct mcp *mcp = to_mcp(dev);
+	struct mcp_driver *driver = to_mcp_driver(drv);
+
+	if (driver->id_table)
+		return mcp_match_id(driver->id_table, mcp->codec) != NULL;
+
+	return 0;
 }
 
 static int mcp_bus_probe(struct device *dev)
@@ -36,7 +53,7 @@ static int mcp_bus_probe(struct device *dev)
 	struct mcp *mcp = to_mcp(dev);
 	struct mcp_driver *drv = to_mcp_driver(dev->driver);
 
-	return drv->probe(mcp);
+	return drv->probe(mcp, mcp_match_id(drv->id_table, mcp->codec));
 }
 
 static int mcp_bus_remove(struct device *dev)
@@ -215,6 +232,7 @@ EXPORT_SYMBOL(mcp_host_alloc);
 int mcp_host_register(struct mcp *mcp)
 {
 	dev_set_name(&mcp->attached_device, "mcp0");
+	request_module("%s%s", MCP_MODULE_PREFIX, mcp->codec);
 	return device_register(&mcp->attached_device);
 }
 EXPORT_SYMBOL(mcp_host_register);
drivers/mfd/mcp-sa11x0.c +2 -1
index 2dab02d..a0e0da2 100644
@@ -162,7 +162,8 @@ static int mcp_sa11x0_probe(struct platform_device *pdev)
 	mcp->dma_audio_wr	= DMA_Ser4MCP0Wr;
 	mcp->dma_telco_rd	= DMA_Ser4MCP1Rd;
 	mcp->dma_telco_wr	= DMA_Ser4MCP1Wr;
-	mcp->gpio_base		= data->gpio_base;
+	mcp->codec		= data->codec;
+	mcp->codec_data		= data->codec_data;
 
 	platform_set_drvdata(pdev, mcp);
 
drivers/mfd/ucb1x00-core.c +36 -11

103 lines not on this page · raw message

include/linux/mfd/mcp.h +5 -2
index ee496708..7578e24 100644
@@ -10,6 +10,7 @@
 #ifndef MCP_H
 #define MCP_H
 
+#include <linux/mod_devicetable.h>
 #include <mach/dma.h>
 
 struct mcp_ops;
@@ -26,7 +27,8 @@ struct mcp {
 	dma_device_t	dma_telco_rd;
 	dma_device_t	dma_telco_wr;
 	struct device	attached_device;
-	int		gpio_base;
+	const char	*codec;
+	void		*codec_data;
 };
 
 struct mcp_ops {
@@ -52,10 +54,11 @@ void mcp_host_unregister(struct mcp *);
 
 struct mcp_driver {
 	struct device_driver drv;
-	int (*probe)(struct mcp *);
+	int (*probe)(struct mcp *, const struct mcp_device_id *);
 	void (*remove)(struct mcp *);
 	int (*suspend)(struct mcp *, pm_message_t);
 	int (*resume)(struct mcp *);
+	const struct mcp_device_id *id_table;
 };
 
 int mcp_driver_register(struct mcp_driver *);
include/linux/mfd/ucb1x00.h +4 -1
index 4321f04..bc19e5f 100644
@@ -104,6 +104,9 @@
 #define UCB_MODE_DYN_VFLAG_ENA	(1 << 12)
 #define UCB_MODE_AUD_OFF_CAN	(1 << 13)
 
+struct ucb1x00_plat_data {
+	int		gpio_base;
+};
 
 struct ucb1x00_irq {
 	void *devid;
@@ -116,7 +119,7 @@ struct ucb1x00 {
 	unsigned int		irq;
 	struct semaphore	adc_sem;
 	spinlock_t		io_lock;
-	u16			id;
+	const struct mcp_device_id *id;
 	u16			io_dir;
 	u16			io_out;
 	u16			adc_cr;
include/linux/mod_devicetable.h +11 -0
index 48c007d..df8c8e6 100644
@@ -410,6 +410,17 @@ struct spi_device_id {
 			__attribute__((aligned(sizeof(kernel_ulong_t))));
 };
 
+/* mcp */
+
+#define MCP_NAME_SIZE	20
+#define MCP_MODULE_PREFIX "mcp:"
+
+struct mcp_device_id {
+	char name[MCP_NAME_SIZE];
+	kernel_ulong_t driver_data	/* Data private to the driver */
+			__attribute__((aligned(sizeof(kernel_ulong_t))));
+};
+
 /* dmi */
 enum dmi_field {
 	DMI_NONE,
scripts/mod/file2alias.c +13 -0
index 88f3f07..1f2c971 100644
@@ -735,6 +735,15 @@ static int do_spi_entry(const char *filename, struct spi_device_id *id,
 	return 1;
 }
 
+/* Looks like: mcp:S */
+static int do_mcp_entry(const char *filename, struct mcp_device_id *id,
+			char *alias)
+{
+	sprintf(alias, MCP_MODULE_PREFIX "%s", id->name);
+
+	return 1;
+}
+
 static const struct dmifield {
 	const char *prefix;
 	int field;
@@ -980,6 +989,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
 		do_table(symval, sym->st_size,
 			 sizeof(struct spi_device_id), "spi",
 			 do_spi_entry, mod);
+	else if (sym_is(symname, "__mod_mcp_device_table"))
+		do_table(symval, sym->st_size,
+			 sizeof(struct mcp_device_id), "mcp",
+			 do_mcp_entry, mod);
 	else if (sym_is(symname, "__mod_dmi_device_table"))
 		do_table(symval, sym->st_size,
 			 sizeof(struct dmi_system_id), "dmi",
Signature · 1 line
1.7.5.rc3