aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/i2c.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-12 14:45:16 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-12 14:45:16 -0500
commit8287361abca36504da813638310d2547469283eb (patch)
tree8d98e9a910885efdb09ae5390a3ae44040557e2f /arch/arm/mach-omap2/i2c.c
parent2989950cea13711f0cc573c26cde8fe08a36be03 (diff)
parent8556650dd3370a927217f16444aac5cc0c71e61b (diff)
Merge tag 'headers' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
Pull ARM SoC Header cleanups from Olof Johansson: "This is a collection of header file cleanups, mostly for OMAP and AT91, that keeps moving the platforms in the direction of multiplatform by removing the need for mach-dependent header files used in drivers and other places." Fix up mostly trivial conflicts as per Olof. * tag 'headers' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc: (106 commits) ARM: OMAP2+: Move iommu/iovmm headers to platform_data ARM: OMAP2+: Make some definitions local ARM: OMAP2+: Move iommu2 to drivers/iommu/omap-iommu2.c ARM: OMAP2+: Move plat/iovmm.h to include/linux/omap-iommu.h ARM: OMAP2+: Move iopgtable header to drivers/iommu/ ARM: OMAP: Merge iommu2.h into iommu.h atmel: move ATMEL_MAX_UART to platform_data/atmel.h ARM: OMAP: Remove omap_init_consistent_dma_size() arm: at91: move at91rm9200 rtc header in drivers/rtc arm: at91: move reset controller header to arm/arm/mach-at91 arm: at91: move pit define to the driver arm: at91: move at91_shdwc.h to arch/arm/mach-at91 arm: at91: move board header to arch/arm/mach-at91 arn: at91: move at91_tc.h to arch/arm/mach-at91 arm: at91 move at91_aic.h to arch/arm/mach-at91 arm: at91 move board.h to arch/arm/mach-at91 arm: at91: move platfarm_data to include/linux/platform_data/atmel.h arm: at91: drop machine defconfig ARM: OMAP: Remove NEED_MACH_GPIO_H ARM: OMAP: Remove unnecessary mach and plat includes ...
Diffstat (limited to 'arch/arm/mach-omap2/i2c.c')
-rw-r--r--arch/arm/mach-omap2/i2c.c69
1 files changed, 66 insertions, 3 deletions
diff --git a/arch/arm/mach-omap2/i2c.c b/arch/arm/mach-omap2/i2c.c
index fc57e67b321f..4e63097e3cd8 100644
--- a/arch/arm/mach-omap2/i2c.c
+++ b/arch/arm/mach-omap2/i2c.c
@@ -19,11 +19,13 @@
19 * 19 *
20 */ 20 */
21 21
22#include <plat/i2c.h> 22#include "soc.h"
23#include "common.h" 23#include "common.h"
24#include <plat/omap_hwmod.h> 24#include "omap_hwmod.h"
25#include "omap_device.h"
25 26
26#include "mux.h" 27#include "mux.h"
28#include "i2c.h"
27 29
28/* In register I2C_CON, Bit 15 is the I2C enable bit */ 30/* In register I2C_CON, Bit 15 is the I2C enable bit */
29#define I2C_EN BIT(15) 31#define I2C_EN BIT(15)
@@ -33,7 +35,9 @@
33/* Maximum microseconds to wait for OMAP module to softreset */ 35/* Maximum microseconds to wait for OMAP module to softreset */
34#define MAX_MODULE_SOFTRESET_WAIT 10000 36#define MAX_MODULE_SOFTRESET_WAIT 10000
35 37
36void __init omap2_i2c_mux_pins(int bus_id) 38#define MAX_OMAP_I2C_HWMOD_NAME_LEN 16
39
40static void __init omap2_i2c_mux_pins(int bus_id)
37{ 41{
38 char mux_name[sizeof("i2c2_scl.i2c2_scl")]; 42 char mux_name[sizeof("i2c2_scl.i2c2_scl")];
39 43
@@ -104,3 +108,62 @@ int omap_i2c_reset(struct omap_hwmod *oh)
104 108
105 return 0; 109 return 0;
106} 110}
111
112static int __init omap_i2c_nr_ports(void)
113{
114 int ports = 0;
115
116 if (cpu_is_omap24xx())
117 ports = 2;
118 else if (cpu_is_omap34xx())
119 ports = 3;
120 else if (cpu_is_omap44xx())
121 ports = 4;
122 return ports;
123}
124
125static const char name[] = "omap_i2c";
126
127int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata,
128 int bus_id)
129{
130 int l;
131 struct omap_hwmod *oh;
132 struct platform_device *pdev;
133 char oh_name[MAX_OMAP_I2C_HWMOD_NAME_LEN];
134 struct omap_i2c_bus_platform_data *pdata;
135 struct omap_i2c_dev_attr *dev_attr;
136
137 if (bus_id > omap_i2c_nr_ports())
138 return -EINVAL;
139
140 omap2_i2c_mux_pins(bus_id);
141
142 l = snprintf(oh_name, MAX_OMAP_I2C_HWMOD_NAME_LEN, "i2c%d", bus_id);
143 WARN(l >= MAX_OMAP_I2C_HWMOD_NAME_LEN,
144 "String buffer overflow in I2C%d device setup\n", bus_id);
145 oh = omap_hwmod_lookup(oh_name);
146 if (!oh) {
147 pr_err("Could not look up %s\n", oh_name);
148 return -EEXIST;
149 }
150
151 pdata = i2c_pdata;
152 /*
153 * pass the hwmod class's CPU-specific knowledge of I2C IP revision in
154 * use, and functionality implementation flags, up to the OMAP I2C
155 * driver via platform data
156 */
157 pdata->rev = oh->class->rev;
158
159 dev_attr = (struct omap_i2c_dev_attr *)oh->dev_attr;
160 pdata->flags = dev_attr->flags;
161
162 pdev = omap_device_build(name, bus_id, oh, pdata,
163 sizeof(struct omap_i2c_bus_platform_data),
164 NULL, 0, 0);
165 WARN(IS_ERR(pdev), "Could not build omap_device for %s\n", name);
166
167 return PTR_RET(pdev);
168}
169