forked from Minki/linux
e4c060db2c
We want to remove plat/cpu.h. To do this, let's first split it to private soc.h to mach-omap1 and mach-omap2. We have to keep plat/cpu.h around until the remaining drivers are fixed, so let's include the local soc.h in plat/cpu.h and for drivers still including plat/cpu.h. Once the drivers are fixed not to include plat/cpu.h, we can remove the file. This is needed for the ARM common zImage support. [tony@atomide.com: updated to not print a warning] Signed-off-by: Tony Lindgren <tony@atomide.com>
140 lines
3.4 KiB
C
140 lines
3.4 KiB
C
/*
|
|
* linux/arch/arm/plat-omap/i2c.c
|
|
*
|
|
* Helper module for board specific I2C bus registration
|
|
*
|
|
* Copyright (C) 2007 Nokia Corporation.
|
|
*
|
|
* Contact: Jarkko Nikula <jhnikula@gmail.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>
|
|
#include <linux/i2c-omap.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/err.h>
|
|
#include <linux/clk.h>
|
|
|
|
#include <mach/irqs.h>
|
|
|
|
#include "../mach-omap1/soc.h"
|
|
#include "../mach-omap2/soc.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#define OMAP_I2C_MAX_CONTROLLERS 4
|
|
static struct omap_i2c_bus_platform_data i2c_pdata[OMAP_I2C_MAX_CONTROLLERS];
|
|
|
|
#define OMAP_I2C_CMDLINE_SETUP (BIT(31))
|
|
|
|
static int __init omap_i2c_nr_ports(void)
|
|
{
|
|
int ports = 0;
|
|
|
|
if (cpu_class_is_omap1())
|
|
ports = 1;
|
|
else if (cpu_is_omap24xx())
|
|
ports = 2;
|
|
else if (cpu_is_omap34xx())
|
|
ports = 3;
|
|
else if (cpu_is_omap44xx())
|
|
ports = 4;
|
|
|
|
return ports;
|
|
}
|
|
|
|
/**
|
|
* omap_i2c_bus_setup - Process command line options for the I2C bus speed
|
|
* @str: String of options
|
|
*
|
|
* This function allow to override the default I2C bus speed for given I2C
|
|
* bus with a command line option.
|
|
*
|
|
* Format: i2c_bus=bus_id,clkrate (in kHz)
|
|
*
|
|
* Returns 1 on success, 0 otherwise.
|
|
*/
|
|
static int __init omap_i2c_bus_setup(char *str)
|
|
{
|
|
int ports;
|
|
int ints[3];
|
|
|
|
ports = omap_i2c_nr_ports();
|
|
get_options(str, 3, ints);
|
|
if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
|
|
return 0;
|
|
i2c_pdata[ints[1] - 1].clkrate = ints[2];
|
|
i2c_pdata[ints[1] - 1].clkrate |= OMAP_I2C_CMDLINE_SETUP;
|
|
|
|
return 1;
|
|
}
|
|
__setup("i2c_bus=", omap_i2c_bus_setup);
|
|
|
|
/*
|
|
* Register busses defined in command line but that are not registered with
|
|
* omap_register_i2c_bus from board initialization code.
|
|
*/
|
|
static int __init omap_register_i2c_bus_cmdline(void)
|
|
{
|
|
int i, err = 0;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(i2c_pdata); i++)
|
|
if (i2c_pdata[i].clkrate & OMAP_I2C_CMDLINE_SETUP) {
|
|
i2c_pdata[i].clkrate &= ~OMAP_I2C_CMDLINE_SETUP;
|
|
err = omap_i2c_add_bus(&i2c_pdata[i], i + 1);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
|
|
out:
|
|
return err;
|
|
}
|
|
subsys_initcall(omap_register_i2c_bus_cmdline);
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
|
|
struct i2c_board_info const *info,
|
|
unsigned len)
|
|
{
|
|
int err;
|
|
|
|
BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
|
|
|
|
if (info) {
|
|
err = i2c_register_board_info(bus_id, info, len);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
if (!i2c_pdata[bus_id - 1].clkrate)
|
|
i2c_pdata[bus_id - 1].clkrate = clkrate;
|
|
|
|
i2c_pdata[bus_id - 1].clkrate &= ~OMAP_I2C_CMDLINE_SETUP;
|
|
|
|
return omap_i2c_add_bus(&i2c_pdata[bus_id - 1], bus_id);
|
|
}
|