2 * Helper module for board specific I2C bus registration
4 * Copyright (C) 2009 Nokia Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 #include <plat/omap_hwmod.h>
24 #include "omap_device.h"
29 /* In register I2C_CON, Bit 15 is the I2C enable bit */
30 #define I2C_EN BIT(15)
31 #define OMAP2_I2C_CON_OFFSET 0x24
32 #define OMAP4_I2C_CON_OFFSET 0xA4
34 /* Maximum microseconds to wait for OMAP module to softreset */
35 #define MAX_MODULE_SOFTRESET_WAIT 10000
37 #define MAX_OMAP_I2C_HWMOD_NAME_LEN 16
39 static void __init omap2_i2c_mux_pins(int bus_id)
41 char mux_name[sizeof("i2c2_scl.i2c2_scl")];
43 /* First I2C bus is not muxable */
47 sprintf(mux_name, "i2c%i_scl.i2c%i_scl", bus_id, bus_id);
48 omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);
49 sprintf(mux_name, "i2c%i_sda.i2c%i_sda", bus_id, bus_id);
50 omap_mux_init_signal(mux_name, OMAP_PIN_INPUT);
54 * omap_i2c_reset - reset the omap i2c module.
55 * @oh: struct omap_hwmod *
57 * The i2c moudle in omap2, omap3 had a special sequence to reset. The
60 * - Write to SOFTRESET bit.
62 * - Poll on the RESETDONE bit.
63 * The sequence is implemented in below function. This is called for 2420,
66 int omap_i2c_reset(struct omap_hwmod *oh)
72 if (oh->class->rev == OMAP_I2C_IP_VERSION_2) {
73 i2c_con = OMAP4_I2C_CON_OFFSET;
74 } else if (oh->class->rev == OMAP_I2C_IP_VERSION_1) {
75 i2c_con = OMAP2_I2C_CON_OFFSET;
77 WARN(1, "Cannot reset I2C block %s: unsupported revision\n",
83 v = omap_hwmod_read(oh, i2c_con);
85 omap_hwmod_write(v, oh, i2c_con);
87 /* Write to the SOFTRESET bit */
88 omap_hwmod_softreset(oh);
91 v = omap_hwmod_read(oh, i2c_con);
93 omap_hwmod_write(v, oh, i2c_con);
95 /* Poll on RESETDONE bit */
96 omap_test_timeout((omap_hwmod_read(oh,
97 oh->class->sysc->syss_offs)
98 & SYSS_RESETDONE_MASK),
99 MAX_MODULE_SOFTRESET_WAIT, c);
101 if (c == MAX_MODULE_SOFTRESET_WAIT)
102 pr_warning("%s: %s: softreset failed (waited %d usec)\n",
103 __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
105 pr_debug("%s: %s: softreset in %d usec\n", __func__,
111 static const char name[] = "omap_i2c";
113 int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata,
117 struct omap_hwmod *oh;
118 struct platform_device *pdev;
119 char oh_name[MAX_OMAP_I2C_HWMOD_NAME_LEN];
120 struct omap_i2c_bus_platform_data *pdata;
121 struct omap_i2c_dev_attr *dev_attr;
123 omap2_i2c_mux_pins(bus_id);
125 l = snprintf(oh_name, MAX_OMAP_I2C_HWMOD_NAME_LEN, "i2c%d", bus_id);
126 WARN(l >= MAX_OMAP_I2C_HWMOD_NAME_LEN,
127 "String buffer overflow in I2C%d device setup\n", bus_id);
128 oh = omap_hwmod_lookup(oh_name);
130 pr_err("Could not look up %s\n", oh_name);
136 * pass the hwmod class's CPU-specific knowledge of I2C IP revision in
137 * use, and functionality implementation flags, up to the OMAP I2C
138 * driver via platform data
140 pdata->rev = oh->class->rev;
142 dev_attr = (struct omap_i2c_dev_attr *)oh->dev_attr;
143 pdata->flags = dev_attr->flags;
145 pdev = omap_device_build(name, bus_id, oh, pdata,
146 sizeof(struct omap_i2c_bus_platform_data),
148 WARN(IS_ERR(pdev), "Could not build omap_device for %s\n", name);
150 return PTR_RET(pdev);