Tony Lindgren | b63128e | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1 | /* |
| 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 Lindgren | 3a8761c | 2012-10-08 09:11:22 -0700 | [diff] [blame] | 22 | #include <linux/i2c-omap.h> |
Tony Lindgren | 70c494c | 2012-09-19 10:46:56 -0700 | [diff] [blame] | 23 | #include <mach/mux.h> |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame] | 24 | #include "soc.h" |
Tony Lindgren | b63128e | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 25 | |
Tony Lindgren | 01480bad | 2012-10-30 10:33:24 -0700 | [diff] [blame] | 26 | #include <plat/i2c.h> |
Tony Lindgren | 3a8761c | 2012-10-08 09:11:22 -0700 | [diff] [blame] | 27 | |
| 28 | #define OMAP_I2C_SIZE 0x3f |
| 29 | #define OMAP1_I2C_BASE 0xfffb3800 |
Tony Lindgren | 3a8761c | 2012-10-08 09:11:22 -0700 | [diff] [blame] | 30 | |
| 31 | static const char name[] = "omap_i2c"; |
| 32 | |
| 33 | static struct resource i2c_resources[2] = { |
| 34 | }; |
| 35 | |
| 36 | static struct platform_device omap_i2c_devices[1] = { |
| 37 | }; |
| 38 | |
| 39 | static void __init omap1_i2c_mux_pins(int bus_id) |
Tony Lindgren | b63128e | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 40 | { |
Cory Maccarrone | bf92a40 | 2009-12-11 16:16:34 -0800 | [diff] [blame] | 41 | if (cpu_is_omap7xx()) { |
| 42 | omap_cfg_reg(I2C_7XX_SDA); |
| 43 | omap_cfg_reg(I2C_7XX_SCL); |
| 44 | } else { |
| 45 | omap_cfg_reg(I2C_SDA); |
| 46 | omap_cfg_reg(I2C_SCL); |
| 47 | } |
Tony Lindgren | b63128e | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 48 | } |
Tony Lindgren | 3a8761c | 2012-10-08 09:11:22 -0700 | [diff] [blame] | 49 | |
| 50 | int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *pdata, |
| 51 | int bus_id) |
| 52 | { |
| 53 | struct platform_device *pdev; |
| 54 | struct resource *res; |
| 55 | |
Tony Lindgren | c34f7c6 | 2012-10-29 16:17:59 -0700 | [diff] [blame] | 56 | if (bus_id > 1) |
| 57 | return -EINVAL; |
| 58 | |
Tony Lindgren | 3a8761c | 2012-10-08 09:11:22 -0700 | [diff] [blame] | 59 | omap1_i2c_mux_pins(bus_id); |
| 60 | |
| 61 | pdev = &omap_i2c_devices[bus_id - 1]; |
| 62 | pdev->id = bus_id; |
| 63 | pdev->name = name; |
| 64 | pdev->num_resources = ARRAY_SIZE(i2c_resources); |
| 65 | res = i2c_resources; |
| 66 | res[0].start = OMAP1_I2C_BASE; |
| 67 | res[0].end = res[0].start + OMAP_I2C_SIZE; |
| 68 | res[0].flags = IORESOURCE_MEM; |
Tony Lindgren | 685e2d0 | 2015-05-20 09:01:21 -0700 | [diff] [blame] | 69 | res[1].start = INT_I2C; |
Tony Lindgren | 3a8761c | 2012-10-08 09:11:22 -0700 | [diff] [blame] | 70 | res[1].flags = IORESOURCE_IRQ; |
| 71 | pdev->resource = res; |
| 72 | |
| 73 | /* all OMAP1 have IP version 1 register set */ |
| 74 | pdata->rev = OMAP_I2C_IP_VERSION_1; |
| 75 | |
| 76 | /* all OMAP1 I2C are implemented like this */ |
| 77 | pdata->flags = OMAP_I2C_FLAG_NO_FIFO | |
| 78 | OMAP_I2C_FLAG_SIMPLE_CLOCK | |
| 79 | OMAP_I2C_FLAG_16BIT_DATA_REG | |
| 80 | OMAP_I2C_FLAG_ALWAYS_ARMXOR_CLK; |
| 81 | |
| 82 | /* how the cpu bus is wired up differs for 7xx only */ |
| 83 | |
| 84 | if (cpu_is_omap7xx()) |
| 85 | pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_1; |
| 86 | else |
| 87 | pdata->flags |= OMAP_I2C_FLAG_BUS_SHIFT_2; |
| 88 | |
| 89 | pdev->dev.platform_data = pdata; |
| 90 | |
| 91 | return platform_device_register(pdev); |
| 92 | } |
Tony Lindgren | a6cf912 | 2013-01-11 11:24:19 -0800 | [diff] [blame] | 93 | |
| 94 | static int __init omap_i2c_cmdline(void) |
| 95 | { |
| 96 | return omap_register_i2c_bus_cmdline(); |
| 97 | } |
| 98 | subsys_initcall(omap_i2c_cmdline); |