Commit 3a853fb933ddf9c5ea8c9f7c665dd8def26bceae

Authored by Jarkko Nikula
Committed by Tony Lindgren
1 parent d4c58bf45a

ARM: OMAP: Add command line option for I2C bus speed, v2

This patch adds a new command line option "i2c_bus=bus_id,clkrate" into
I2C bus registration helper. Purpose of the option is to override the
default board specific bus speed which is supplied by the
omap_register_i2c_bus.

The default bus speed is typically set to speed of slowest I2C chip on the
bus and overriding allow to use some experimental configurations or updated
chip versions without any kernel modifications.

Cc: linux-i2c@vger.kernel.org
Signed-off-by: Jarkko Nikula <jarkko.nikula@nokia.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>

Showing 2 changed files with 48 additions and 10 deletions Side-by-side Diff

Documentation/kernel-parameters.txt
... ... @@ -830,6 +830,10 @@
830 830 hvc_iucv= [S390] Number of z/VM IUCV hypervisor console (HVC)
831 831 terminal devices. Valid values: 0..8
832 832  
  833 + i2c_bus= [HW] Override the default board specific I2C bus speed
  834 + Format:
  835 + <bus_id>,<clkrate>
  836 +
833 837 i8042.debug [HW] Toggle i8042 debug mode
834 838 i8042.direct [HW] Put keyboard port into non-translated mode
835 839 i8042.dumbkbd [HW] Pretend that controller can only read data from
arch/arm/plat-omap/i2c.c
... ... @@ -119,7 +119,47 @@
119 119 omap_cfg_reg(scl);
120 120 }
121 121  
  122 +static int __init omap_i2c_nr_ports(void)
  123 +{
  124 + int ports = 0;
  125 +
  126 + if (cpu_class_is_omap1())
  127 + ports = 1;
  128 + else if (cpu_is_omap24xx())
  129 + ports = 2;
  130 + else if (cpu_is_omap34xx())
  131 + ports = 3;
  132 +
  133 + return ports;
  134 +}
  135 +
122 136 /**
  137 + * omap_i2c_bus_setup - Process command line options for the I2C bus speed
  138 + * @str: String of options
  139 + *
  140 + * This function allow to override the default I2C bus speed for given I2C
  141 + * bus with a command line option.
  142 + *
  143 + * Format: i2c_bus=bus_id,clkrate (in kHz)
  144 + *
  145 + * Returns 1 on success, 0 otherwise.
  146 + */
  147 +static int __init omap_i2c_bus_setup(char *str)
  148 +{
  149 + int ports;
  150 + int ints[3];
  151 +
  152 + ports = omap_i2c_nr_ports();
  153 + get_options(str, 3, ints);
  154 + if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
  155 + return 0;
  156 + i2c_rate[ints[1] - 1] = ints[2];
  157 +
  158 + return 1;
  159 +}
  160 +__setup("i2c_bus=", omap_i2c_bus_setup);
  161 +
  162 +/**
123 163 * omap_register_i2c_bus - register I2C bus with device descriptors
124 164 * @bus_id: bus id counting from number 1
125 165 * @clkrate: clock rate of the bus in kHz
126 166  
127 167  
... ... @@ -132,20 +172,13 @@
132 172 struct i2c_board_info const *info,
133 173 unsigned len)
134 174 {
135   - int ports, err;
  175 + int err;
136 176 struct platform_device *pdev;
137 177 struct resource *res;
138 178 resource_size_t base, irq;
139 179  
140   - if (cpu_class_is_omap1())
141   - ports = 1;
142   - else if (cpu_is_omap24xx())
143   - ports = 2;
144   - else if (cpu_is_omap34xx())
145   - ports = 3;
  180 + BUG_ON(bus_id < 1 || bus_id > omap_i2c_nr_ports());
146 181  
147   - BUG_ON(bus_id < 1 || bus_id > ports);
148   -
149 182 if (info) {
150 183 err = i2c_register_board_info(bus_id, info, len);
151 184 if (err)
... ... @@ -153,7 +186,8 @@
153 186 }
154 187  
155 188 pdev = &omap_i2c_devices[bus_id - 1];
156   - *(u32 *)pdev->dev.platform_data = clkrate;
  189 + if (i2c_rate[bus_id - 1] == 0)
  190 + i2c_rate[bus_id - 1] = clkrate;
157 191  
158 192 if (bus_id == 1) {
159 193 res = pdev->resource;