blob: a6f465a446425cd4eb81c9fef3cfd9c268dac488 [file] [log] [blame]
Tony Lindgrenb63128e2009-12-11 16:16:32 -08001/*
2 * Helper module for board specific I2C bus registration
3 *
4 * Copyright (C) 2009 Nokia Corporation.
5 *
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.
9 *
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.
14 *
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
18 * 02110-1301 USA
19 *
20 */
21
Tony Lindgren3a8761c2012-10-08 09:11:22 -070022#include <linux/i2c-omap.h>
Tony Lindgren70c494c2012-09-19 10:46:56 -070023#include <mach/mux.h>
Cory Maccarronebf92a4072009-12-11 16:16:34 -080024#include <plat/cpu.h>
Tony Lindgrenb63128e2009-12-11 16:16:32 -080025
Tony Lindgren3a8761c2012-10-08 09:11:22 -070026#include "../plat-omap/i2c.h"
27
28#define OMAP_I2C_SIZE 0x3f
29#define OMAP1_I2C_BASE 0xfffb3800
30#define OMAP1_INT_I2C (32 + 4)
31
32static const char name[] = "omap_i2c";
33
34static struct resource i2c_resources[2] = {
35};
36
37static struct platform_device omap_i2c_devices[1] = {
38};
39
40static void __init omap1_i2c_mux_pins(int bus_id)
Tony Lindgrenb63128e2009-12-11 16:16:32 -080041{
Cory Maccarronebf92a4072009-12-11 16:16:34 -080042 if (cpu_is_omap7xx()) {
43 omap_cfg_reg(I2C_7XX_SDA);
44 omap_cfg_reg(I2C_7XX_SCL);
45 } else {
46 omap_cfg_reg(I2C_SDA);
47 omap_cfg_reg(I2C_SCL);
48 }
Tony Lindgrenb63128e2009-12-11 16:16:32 -080049}
Tony Lindgren3a8761c2012-10-08 09:11:22 -070050
51int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *pdata,
52 int bus_id)
53{
54 struct platform_device *pdev;
55 struct resource *res;
56
57 omap1_i2c_mux_pins(bus_id);
58
59 pdev = &omap_i2c_devices[bus_id - 1];
60 pdev->id = bus_id;
61 pdev->name = name;
62 pdev->num_resources = ARRAY_SIZE(i2c_resources);
63 res = i2c_resources;
64 res[0].start = OMAP1_I2C_BASE;
65 res[0].end = res[0].start + OMAP_I2C_SIZE;
66 res[0].flags = IORESOURCE_MEM;
67 res[1].start = OMAP1_INT_I2C;
68 res[1].flags = IORESOURCE_IRQ;
69 pdev->resource = res;
70
71 /* all OMAP1 have IP version 1 register set */
72 pdata->rev = OMAP_I2C_IP_VERSION_1;
73
74 /* all OMAP1 I2C are implemented like this */
75 pdata->flags = OMAP_I2C_FLAG_NO_FIFO |
76 OMAP_I2C_FLAG_SIMPLE_CLOCK |
77 OMAP_I2C_FLAG_16BIT_DATA_REG |
78 OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK;
79
80 /* how the cpu bus is wired up differs for 7xx only */
81
82 if (cpu_is_omap7xx())
83 pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_1;
84 else
85 pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2;
86
87 pdev->dev.platform_data = pdata;
88
89 return platform_device_register(pdev);
90}