mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c-omap: Remove cpu_is functions completely
@ 2013-06-21 12:50 Teresa Gámez
  2013-06-21 12:50 ` [PATCH 2/2] ARCH: OMAP: Apply i2c-omap id_tables to device register functions Teresa Gámez
  2013-06-23 18:37 ` [PATCH 1/2] i2c-omap: Remove cpu_is functions completely Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Teresa Gámez @ 2013-06-21 12:50 UTC (permalink / raw)
  To: barebox

This patch removes the call of the cpu_is_* functions completely
and uses id_tables instead.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
---
 drivers/i2c/busses/i2c-omap.c |   89 +++++++++++++++++++++++++++++++----------
 1 files changed, 67 insertions(+), 22 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 19d54ee..b2a74c0 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -131,10 +131,17 @@
 #define SYSC_IDLEMODE_SMART		0x2
 #define SYSC_CLOCKACTIVITY_FCLK		0x2
 
+/* i2c driver flags from kernel */
+#define OMAP_I2C_FLAG_RESET_REGS_POSTIDLE	BIT(3)
+#define OMAP_I2C_FLAG_BUS_SHIFT_NONE		0
+#define OMAP_I2C_FLAG_BUS_SHIFT_1		BIT(7)
+#define OMAP_I2C_FLAG_BUS_SHIFT_2		BIT(8)
+#define OMAP_I2C_FLAG_BUS_SHIFT__SHIFT		7
+
 struct omap_i2c_struct {
 	void 			*base;
-	u8			*regs;
 	u8			reg_shift;
+	struct omap_i2c_driver_data	*data;
 	struct resource		*ioarea;
 	u32			speed;		/* Speed of bus in Khz */
 	u16			cmd_err;
@@ -230,22 +237,50 @@ static const u8 omap4_reg_map[] = {
 	[OMAP_I2C_IRQENABLE_CLR] = 0x30,
 };
 
+struct omap_i2c_driver_data {
+	u32		flags;
+	u32		fclk_rate;
+	u8		*regs;
+};
+
+static struct omap_i2c_driver_data omap3_data = {
+	.flags =	OMAP_I2C_FLAG_RESET_REGS_POSTIDLE |
+			OMAP_I2C_FLAG_BUS_SHIFT_2,
+	.fclk_rate =	48000,
+	.regs =		(u8 *) reg_map,
+};
+
+static struct omap_i2c_driver_data omap4_data = {
+	.flags =	OMAP_I2C_FLAG_BUS_SHIFT_NONE,
+	.fclk_rate =	96000,
+	.regs =		(u8 *) omap4_reg_map,
+};
+
+static struct omap_i2c_driver_data am33xx_data = {
+	.flags =	OMAP_I2C_FLAG_RESET_REGS_POSTIDLE |
+			OMAP_I2C_FLAG_BUS_SHIFT_NONE,
+	.fclk_rate =	96000,
+	.regs =		(u8 *) omap4_reg_map,
+};
+
 static inline void omap_i2c_write_reg(struct omap_i2c_struct *i2c_omap,
 				      int reg, u16 val)
 {
 	__raw_writew(val, i2c_omap->base +
-			(i2c_omap->regs[reg] << i2c_omap->reg_shift));
+			(i2c_omap->data->regs[reg] << i2c_omap->reg_shift));
 }
 
 static inline u16 omap_i2c_read_reg(struct omap_i2c_struct *i2c_omap, int reg)
 {
 	return __raw_readw(i2c_omap->base +
-			(i2c_omap->regs[reg] << i2c_omap->reg_shift));
+			(i2c_omap->data->regs[reg] << i2c_omap->reg_shift));
 }
 
 static void omap_i2c_unidle(struct omap_i2c_struct *i2c_omap)
 {
-	if (cpu_is_omap34xx() || cpu_is_am33xx()) {
+	struct omap_i2c_driver_data *i2c_data = i2c_omap->data;
+
+	if (i2c_data->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_CON_REG, 0);
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_PSC_REG, i2c_omap->pscstate);
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_SCLL_REG, i2c_omap->scllstate);
@@ -288,9 +323,8 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 	u16 psc = 0, scll = 0, sclh = 0, buf = 0;
 	u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0;
 	uint64_t start;
-
-	unsigned long fclk_rate = 12000000;
 	unsigned long internal_clk = 0;
+	struct omap_i2c_driver_data *i2c_data = i2c_omap->data;
 
 	if (i2c_omap->rev >= OMAP_I2C_REV_2) {
 		/* Disable I2C controller before soft reset */
@@ -354,13 +388,8 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 	else
 		internal_clk = 4000;
 
-	if (cpu_is_am33xx())
-		fclk_rate = 48000;
-	else
-		fclk_rate = 96000;
-
 	/* Compute prescaler divisor */
-	psc = fclk_rate / internal_clk;
+	psc = i2c_data->fclk_rate / internal_clk;
 	psc = psc - 1;
 
 	/* If configured for High Speed */
@@ -373,7 +402,7 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 		fssclh = (scl / 3) - 5;
 
 		/* For second phase of HS mode */
-		scl = fclk_rate / i2c_omap->speed;
+		scl = i2c_data->fclk_rate / i2c_omap->speed;
 		hsscll = scl - (scl / 3) - 7;
 		hssclh = (scl / 3) - 5;
 	} else if (i2c_omap->speed > 100) {
@@ -414,7 +443,7 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 			OMAP_I2C_IE_AL)  | ((i2c_omap->fifo_size) ?
 				(OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
 	omap_i2c_write_reg(i2c_omap, OMAP_I2C_IE_REG, i2c_omap->iestate);
-	if (cpu_is_omap34xx() || cpu_is_am33xx()) {
+	if (i2c_data->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
 		i2c_omap->pscstate = psc;
 		i2c_omap->scllstate = scll;
 		i2c_omap->sclhstate = sclh;
@@ -736,7 +765,7 @@ static int __init
 i2c_omap_probe(struct device_d *pdev)
 {
 	struct omap_i2c_struct	*i2c_omap;
-	/* struct i2c_platform_data *pdata; */
+	struct omap_i2c_driver_data *i2c_data;
 	int r;
 	u32 speed = 0;
 	u16 s;
@@ -747,13 +776,13 @@ i2c_omap_probe(struct device_d *pdev)
 		goto err_free_mem;
 	}
 
-	if (cpu_is_omap4xxx() || cpu_is_am33xx()) {
-		i2c_omap->regs = (u8 *)omap4_reg_map;
-		i2c_omap->reg_shift = 0;
-	} else {
-		i2c_omap->regs = (u8 *)reg_map;
-		i2c_omap->reg_shift = 2;
-	}
+	r = dev_get_drvdata(pdev, (unsigned long *)&i2c_data);
+	if (r)
+		return r;
+
+	i2c_omap->data = i2c_data;
+	i2c_omap->reg_shift = (i2c_data->flags >>
+					OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3;
 
 	if (pdev->platform_data != NULL)
 		speed = *(u32 *)pdev->platform_data;
@@ -815,9 +844,25 @@ err_free_mem:
 	return r;
 }
 
+static struct platform_device_id omap_i2c_ids[] = {
+	 {
+		.name = "i2c-omap3",
+		.driver_data = (unsigned long)&omap3_data,
+	}, {
+		.name = "i2c-omap4",
+		.driver_data = (unsigned long)&omap4_data,
+	}, {
+		.name = "i2c-am33xx",
+		.driver_data = (unsigned long)&am33xx_data,
+	}, {
+		/* sentinel */
+	},
+};
+
 static struct driver_d omap_i2c_driver = {
 	.probe		= i2c_omap_probe,
 	.name		= DRIVER_NAME,
+	.id_table	= omap_i2c_ids,
 };
 device_platform_driver(omap_i2c_driver);
 
-- 
1.7.0.4


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

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

* [PATCH 2/2] ARCH: OMAP: Apply i2c-omap id_tables to device register functions
  2013-06-21 12:50 [PATCH 1/2] i2c-omap: Remove cpu_is functions completely Teresa Gámez
@ 2013-06-21 12:50 ` Teresa Gámez
  2013-06-23 18:37 ` [PATCH 1/2] i2c-omap: Remove cpu_is functions completely Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Teresa Gámez @ 2013-06-21 12:50 UTC (permalink / raw)
  To: barebox

Remove omap_add_i2c() and use the id_table names to register the
devices.

Signed-off-by: Teresa Gámez <t.gamez@phytec.de>
---
 arch/arm/mach-omap/include/mach/am33xx-devices.h |    9 ++++++---
 arch/arm/mach-omap/include/mach/devices.h        |    2 --
 arch/arm/mach-omap/include/mach/omap3-devices.h  |    9 ++++++---
 arch/arm/mach-omap/include/mach/omap4-devices.h  |   12 ++++++++----
 arch/arm/mach-omap/omap_devices.c                |    6 ------
 5 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
index 822caab..6a4d901 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
@@ -55,17 +55,20 @@ static inline struct device_d *am33xx_add_spi1(void)
 
 static inline struct device_d *am33xx_add_i2c0(void *pdata)
 {
-	return omap_add_i2c(0, AM33XX_I2C0_BASE, pdata);
+	return add_generic_device("i2c-am33xx", 0, NULL, AM33XX_I2C0_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *am33xx_add_i2c1(void *pdata)
 {
-	return omap_add_i2c(1, AM33XX_I2C1_BASE, pdata);
+	return add_generic_device("i2c-am33xx", 1, NULL, AM33XX_I2C1_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *am33xx_add_i2c2(void *pdata)
 {
-	return omap_add_i2c(2, AM33XX_I2C2_BASE, pdata);
+	return add_generic_device("i2c-am33xx", 2, NULL, AM33XX_I2C2_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 #endif /* __MACH_OMAP3_DEVICES_H */
diff --git a/arch/arm/mach-omap/include/mach/devices.h b/arch/arm/mach-omap/include/mach/devices.h
index adae01b..537213f 100644
--- a/arch/arm/mach-omap/include/mach/devices.h
+++ b/arch/arm/mach-omap/include/mach/devices.h
@@ -9,6 +9,4 @@ void omap_add_sram0(resource_size_t base, resource_size_t size);
 
 struct device_d *omap_add_uart(int id, unsigned long base);
 
-struct device_d *omap_add_i2c(int id, unsigned long base, void *pdata);
-
 #endif /* __MACH_OMAP_DEVICES_H */
diff --git a/arch/arm/mach-omap/include/mach/omap3-devices.h b/arch/arm/mach-omap/include/mach/omap3-devices.h
index de67ea0..0809e95 100644
--- a/arch/arm/mach-omap/include/mach/omap3-devices.h
+++ b/arch/arm/mach-omap/include/mach/omap3-devices.h
@@ -77,17 +77,20 @@ static inline struct device_d *omap3_add_mmc3(struct omap_hsmmc_platform_data *p
 
 static inline struct device_d *omap3_add_i2c1(void *pdata)
 {
-	return omap_add_i2c(0, OMAP3_I2C1_BASE, pdata);
+	return add_generic_device("i2c-omap3", 0, NULL, OMAP3_I2C1_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap3_add_i2c2(void *pdata)
 {
-	return omap_add_i2c(1, OMAP3_I2C2_BASE, pdata);
+	return add_generic_device("i2c-omap3", 1, NULL, OMAP3_I2C2_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap3_add_i2c3(void *pdata)
 {
-	return omap_add_i2c(2, OMAP3_I2C3_BASE, pdata);
+	return add_generic_device("i2c-omap3", 2, NULL, OMAP3_I2C3_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap3_add_ehci(void *pdata)
diff --git a/arch/arm/mach-omap/include/mach/omap4-devices.h b/arch/arm/mach-omap/include/mach/omap4-devices.h
index 561d9ce..76c9789 100644
--- a/arch/arm/mach-omap/include/mach/omap4-devices.h
+++ b/arch/arm/mach-omap/include/mach/omap4-devices.h
@@ -60,22 +60,26 @@ static inline struct device_d *omap44xx_add_mmc5(struct omap_hsmmc_platform_data
 
 static inline struct device_d *omap44xx_add_i2c1(void *pdata)
 {
-	return omap_add_i2c(0, OMAP44XX_I2C1_BASE, pdata);
+	return add_generic_device("i2c-omap4", 0, NULL, OMAP44XX_I2C1_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_i2c2(void *pdata)
 {
-	return omap_add_i2c(1, OMAP44XX_I2C2_BASE, pdata);
+	return add_generic_device("i2c-omap4", 1, NULL, OMAP44XX_I2C2_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_i2c3(void *pdata)
 {
-	return omap_add_i2c(2, OMAP44XX_I2C3_BASE, pdata);
+	return add_generic_device("i2c-omap4", 2, NULL, OMAP44XX_I2C3_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_i2c4(void *pdata)
 {
-	return omap_add_i2c(3, OMAP44XX_I2C4_BASE, pdata);
+	return add_generic_device("i2c-omap4", 3, NULL, OMAP44XX_I2C4_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_ehci(void *pdata)
diff --git a/arch/arm/mach-omap/omap_devices.c b/arch/arm/mach-omap/omap_devices.c
index 056cba5..30cfdd0 100644
--- a/arch/arm/mach-omap/omap_devices.c
+++ b/arch/arm/mach-omap/omap_devices.c
@@ -24,9 +24,3 @@ struct device_d *omap_add_uart(int id, unsigned long base)
 	return add_ns16550_device(id, base, 1024,
 			IORESOURCE_MEM_8BIT, &serial_plat);
 }
-
-struct device_d *omap_add_i2c(int id, unsigned long base, void *pdata)
-{
-	return add_generic_device("i2c-omap", id, NULL, base, SZ_4K,
-			   IORESOURCE_MEM, pdata);
-}
-- 
1.7.0.4


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

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

* Re: [PATCH 1/2] i2c-omap: Remove cpu_is functions completely
  2013-06-21 12:50 [PATCH 1/2] i2c-omap: Remove cpu_is functions completely Teresa Gámez
  2013-06-21 12:50 ` [PATCH 2/2] ARCH: OMAP: Apply i2c-omap id_tables to device register functions Teresa Gámez
@ 2013-06-23 18:37 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-06-23 18:37 UTC (permalink / raw)
  To: Teresa Gámez; +Cc: barebox

On Fri, Jun 21, 2013 at 02:50:18PM +0200, Teresa Gámez wrote:
> This patch removes the call of the cpu_is_* functions completely
> and uses id_tables instead.
> 
> Signed-off-by: Teresa Gámez <t.gamez@phytec.de>

Nice, thanks ;)

Applied both and squashed into a single commit. Otherwise we don't have
i2c support after the first patch.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2013-06-23 18:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-21 12:50 [PATCH 1/2] i2c-omap: Remove cpu_is functions completely Teresa Gámez
2013-06-21 12:50 ` [PATCH 2/2] ARCH: OMAP: Apply i2c-omap id_tables to device register functions Teresa Gámez
2013-06-23 18:37 ` [PATCH 1/2] i2c-omap: Remove cpu_is functions completely Sascha Hauer

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