2007-11-07 07:54:31 +03:00
/*
* linux / arch / arm / plat - omap / i2c . c
*
* Helper module for board specific I2C bus registration
*
* Copyright ( C ) 2007 Nokia Corporation .
*
2009-05-25 22:08:43 +04:00
* Contact : Jarkko Nikula < jhnikula @ gmail . com >
2007-11-07 07:54:31 +03:00
*
* 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>
2012-10-08 20:11:22 +04:00
# include <linux/i2c-omap.h>
2010-09-21 18:07:15 +04:00
# include <linux/slab.h>
# include <linux/err.h>
# include <linux/clk.h>
2010-05-11 22:35:08 +04:00
2012-10-30 21:33:24 +04:00
# include <plat/i2c.h>
2012-10-06 00:25:59 +04:00
2010-09-21 18:07:15 +04:00
# define OMAP_I2C_MAX_CONTROLLERS 4
static struct omap_i2c_bus_platform_data i2c_pdata [ OMAP_I2C_MAX_CONTROLLERS ] ;
2007-11-07 07:54:31 +03:00
2009-03-24 04:07:48 +03:00
# define OMAP_I2C_CMDLINE_SETUP (BIT(31))
2009-03-24 04:07:47 +03:00
/**
* 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 ints [ 3 ] ;
get_options ( str , 3 , ints ) ;
2012-10-30 03:17:59 +04:00
if ( ints [ 0 ] < 2 | | ints [ 1 ] < 1 | |
ints [ 1 ] > OMAP_I2C_MAX_CONTROLLERS )
2009-03-24 04:07:47 +03:00
return 0 ;
2010-05-11 22:35:08 +04:00
i2c_pdata [ ints [ 1 ] - 1 ] . clkrate = ints [ 2 ] ;
i2c_pdata [ ints [ 1 ] - 1 ] . clkrate | = OMAP_I2C_CMDLINE_SETUP ;
2009-03-24 04:07:47 +03:00
return 1 ;
}
__setup ( " i2c_bus= " , omap_i2c_bus_setup ) ;
2009-03-24 04:07:48 +03:00
/*
* 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 ;
2010-05-11 22:35:08 +04:00
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 ;
2012-10-08 20:11:22 +04:00
err = omap_i2c_add_bus ( & i2c_pdata [ i ] , i + 1 ) ;
2009-03-24 04:07:48 +03:00
if ( err )
goto out ;
}
out :
return err ;
}
subsys_initcall ( omap_register_i2c_bus_cmdline ) ;
2009-03-24 04:07:46 +03:00
/**
2010-02-22 23:29:36 +03:00
* omap_register_i2c_bus - register I2C bus with device descriptors
2009-03-24 04:07:46 +03:00
* @ 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 .
*/
2010-02-22 23:29:36 +03:00
int __init omap_register_i2c_bus ( int bus_id , u32 clkrate ,
2007-11-07 07:54:31 +03:00
struct i2c_board_info const * info ,
unsigned len )
{
2009-03-24 04:07:47 +03:00
int err ;
2007-11-07 07:54:31 +03:00
2012-10-30 03:17:59 +04:00
BUG_ON ( bus_id < 1 | | bus_id > OMAP_I2C_MAX_CONTROLLERS ) ;
2007-11-07 07:54:31 +03:00
if ( info ) {
err = i2c_register_board_info ( bus_id , info , len ) ;
if ( err )
return err ;
}
2010-05-11 22:35:08 +04:00
if ( ! i2c_pdata [ bus_id - 1 ] . clkrate )
i2c_pdata [ bus_id - 1 ] . clkrate = clkrate ;
i2c_pdata [ bus_id - 1 ] . clkrate & = ~ OMAP_I2C_CMDLINE_SETUP ;
2007-11-07 07:54:31 +03:00
2012-10-08 20:11:22 +04:00
return omap_i2c_add_bus ( & i2c_pdata [ bus_id - 1 ] , bus_id ) ;
2007-11-07 07:54:31 +03:00
}