2007-11-07 12:54:31 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/plat-omap/i2c.c
|
|
|
|
*
|
|
|
|
* Helper module for board specific I2C bus registration
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Nokia Corporation.
|
|
|
|
*
|
|
|
|
* Contact: Jarkko Nikula <jarkko.nikula@nokia.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/i2c.h>
|
[ARM] fix AT91, davinci, h720x, ks8695, msm, mx2, mx3, netx, omap1, omap2, pxa, s3c
arch/arm/mach-at91/at91cap9.c:337: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91rm9200.c:301: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9260.c:351: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9261.c:287: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9263.c:312: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-at91/at91sam9rl.c:304: error: 'NR_AIC_IRQS' undeclared here (not in a function)
arch/arm/mach-h720x/h7202-eval.c:38: error: implicit declaration of function 'IRQ_CHAINED_GPIOB'
arch/arm/mach-ks8695/devices.c:46: error: 'KS8695_IRQ_WAN_RX_STATUS' undeclared here (not in a function)
arch/arm/mach-msm/devices.c:28: error: 'INT_UART1' undeclared here (not in a function)
arch/arm/mach-mx2/devices.c:233: error: 'MXC_GPIO_IRQ_START' undeclared here (not in a function)
arch/arm/mach-mx3/devices.c:128: error: 'MXC_GPIO_IRQ_START' undeclared here (not in a function)
arch/arm/mach-omap1/mcbsp.c:140: error: 'INT_730_McBSP1RX' undeclared here (not in a function)
arch/arm/mach-omap1/mcbsp.c:165: error: 'INT_McBSP1RX' undeclared here (not in a function)
arch/arm/mach-omap1/mcbsp.c:200: error: 'INT_McBSP1RX' undeclared here (not in a function)
arch/arm/mach-omap2/board-apollon.c:286: error: implicit declaration of function 'omap_set_gpio_direction'
arch/arm/mach-omap2/mcbsp.c:154: error: 'INT_24XX_MCBSP1_IRQ_RX' undeclared here (not in a function)
arch/arm/mach-omap2/mcbsp.c:181: error: 'INT_24XX_MCBSP1_IRQ_RX' undeclared here (not in a function)
arch/arm/mach-pxa/e350.c:36: error: 'IRQ_BOARD_START' undeclared here (not in a function)
arch/arm/plat-s3c/dev-i2c0.c:32: error: 'IRQ_IIC' undeclared here (not in a function)
...
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-01-08 18:01:47 +08:00
|
|
|
#include <mach/irqs.h>
|
2008-08-05 23:14:15 +08:00
|
|
|
#include <mach/mux.h>
|
2007-11-07 12:54:31 +08:00
|
|
|
|
|
|
|
#define OMAP_I2C_SIZE 0x3f
|
|
|
|
#define OMAP1_I2C_BASE 0xfffb3800
|
|
|
|
#define OMAP2_I2C_BASE1 0x48070000
|
|
|
|
#define OMAP2_I2C_BASE2 0x48072000
|
|
|
|
#define OMAP2_I2C_BASE3 0x48060000
|
|
|
|
|
|
|
|
static const char name[] = "i2c_omap";
|
|
|
|
|
|
|
|
#define I2C_RESOURCE_BUILDER(base, irq) \
|
|
|
|
{ \
|
|
|
|
.start = (base), \
|
|
|
|
.end = (base) + OMAP_I2C_SIZE, \
|
|
|
|
.flags = IORESOURCE_MEM, \
|
|
|
|
}, \
|
|
|
|
{ \
|
|
|
|
.start = (irq), \
|
|
|
|
.flags = IORESOURCE_IRQ, \
|
|
|
|
},
|
|
|
|
|
|
|
|
static struct resource i2c_resources[][2] = {
|
|
|
|
{ I2C_RESOURCE_BUILDER(0, 0) },
|
|
|
|
#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
|
|
|
|
{ I2C_RESOURCE_BUILDER(OMAP2_I2C_BASE2, INT_24XX_I2C2_IRQ) },
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_OMAP34XX)
|
|
|
|
{ I2C_RESOURCE_BUILDER(OMAP2_I2C_BASE3, INT_34XX_I2C3_IRQ) },
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#define I2C_DEV_BUILDER(bus_id, res, data) \
|
|
|
|
{ \
|
|
|
|
.id = (bus_id), \
|
|
|
|
.name = name, \
|
|
|
|
.num_resources = ARRAY_SIZE(res), \
|
|
|
|
.resource = (res), \
|
|
|
|
.dev = { \
|
|
|
|
.platform_data = (data), \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 i2c_rate[ARRAY_SIZE(i2c_resources)];
|
|
|
|
static struct platform_device omap_i2c_devices[] = {
|
|
|
|
I2C_DEV_BUILDER(1, i2c_resources[0], &i2c_rate[0]),
|
|
|
|
#if defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
|
|
|
|
I2C_DEV_BUILDER(2, i2c_resources[1], &i2c_rate[1]),
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_OMAP34XX)
|
|
|
|
I2C_DEV_BUILDER(3, i2c_resources[2], &i2c_rate[2]),
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2008-12-11 09:36:52 +08:00
|
|
|
#if defined(CONFIG_ARCH_OMAP24XX)
|
|
|
|
static const int omap24xx_pins[][2] = {
|
|
|
|
{ M19_24XX_I2C1_SCL, L15_24XX_I2C1_SDA },
|
|
|
|
{ J15_24XX_I2C2_SCL, H19_24XX_I2C2_SDA },
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
static const int omap24xx_pins[][2] = {};
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_ARCH_OMAP34XX)
|
|
|
|
static const int omap34xx_pins[][2] = {
|
|
|
|
{ K21_34XX_I2C1_SCL, J21_34XX_I2C1_SDA},
|
|
|
|
{ AF15_34XX_I2C2_SCL, AE15_34XX_I2C2_SDA},
|
|
|
|
{ AF14_34XX_I2C3_SCL, AG14_34XX_I2C3_SDA},
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
static const int omap34xx_pins[][2] = {};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void __init omap_i2c_mux_pins(int bus)
|
2007-11-07 12:54:31 +08:00
|
|
|
{
|
2008-12-11 09:36:52 +08:00
|
|
|
int scl, sda;
|
|
|
|
|
|
|
|
if (cpu_class_is_omap1()) {
|
|
|
|
scl = I2C_SCL;
|
|
|
|
sda = I2C_SDA;
|
|
|
|
} else if (cpu_is_omap24xx()) {
|
|
|
|
scl = omap24xx_pins[bus][0];
|
|
|
|
sda = omap24xx_pins[bus][1];
|
|
|
|
} else if (cpu_is_omap34xx()) {
|
|
|
|
scl = omap34xx_pins[bus][0];
|
|
|
|
sda = omap34xx_pins[bus][1];
|
|
|
|
} else {
|
|
|
|
return;
|
2007-11-07 12:54:31 +08:00
|
|
|
}
|
2008-12-11 09:36:52 +08:00
|
|
|
|
|
|
|
omap_cfg_reg(sda);
|
|
|
|
omap_cfg_reg(scl);
|
2007-11-07 12:54:31 +08:00
|
|
|
}
|
|
|
|
|
2009-03-24 09:07:46 +08:00
|
|
|
/**
|
|
|
|
* omap_register_i2c_bus - register I2C bus with device descriptors
|
|
|
|
* @bus_id: bus id counting from number 1
|
|
|
|
* @clkrate: clock rate of the bus in kHz
|
|
|
|
* @info: pointer into I2C device descriptor table or NULL
|
|
|
|
* @len: number of descriptors in the table
|
|
|
|
*
|
|
|
|
* Returns 0 on success or an error code.
|
|
|
|
*/
|
2007-11-07 12:54:31 +08:00
|
|
|
int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
|
|
|
|
struct i2c_board_info const *info,
|
|
|
|
unsigned len)
|
|
|
|
{
|
|
|
|
int ports, err;
|
|
|
|
struct platform_device *pdev;
|
|
|
|
struct resource *res;
|
|
|
|
resource_size_t base, irq;
|
|
|
|
|
|
|
|
if (cpu_class_is_omap1())
|
|
|
|
ports = 1;
|
|
|
|
else if (cpu_is_omap24xx())
|
|
|
|
ports = 2;
|
|
|
|
else if (cpu_is_omap34xx())
|
|
|
|
ports = 3;
|
|
|
|
|
|
|
|
BUG_ON(bus_id < 1 || bus_id > ports);
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
err = i2c_register_board_info(bus_id, info, len);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = &omap_i2c_devices[bus_id - 1];
|
|
|
|
*(u32 *)pdev->dev.platform_data = clkrate;
|
|
|
|
|
|
|
|
if (bus_id == 1) {
|
|
|
|
res = pdev->resource;
|
|
|
|
if (cpu_class_is_omap1()) {
|
|
|
|
base = OMAP1_I2C_BASE;
|
|
|
|
irq = INT_I2C;
|
|
|
|
} else {
|
|
|
|
base = OMAP2_I2C_BASE1;
|
|
|
|
irq = INT_24XX_I2C1_IRQ;
|
|
|
|
}
|
|
|
|
res[0].start = base;
|
|
|
|
res[0].end = base + OMAP_I2C_SIZE;
|
|
|
|
res[1].start = irq;
|
|
|
|
}
|
|
|
|
|
2008-12-11 09:36:52 +08:00
|
|
|
omap_i2c_mux_pins(bus_id - 1);
|
2007-11-07 12:54:31 +08:00
|
|
|
return platform_device_register(pdev);
|
|
|
|
}
|