]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/arm/plat-omap/i2c.c
Merge branch 'next-s3c64xx-regs' of git://aeryn.fluff.org.uk/bjdooks/linux into devel
[linux-2.6-omap-h63xx.git] / arch / arm / plat-omap / i2c.c
index 0e6d147ab6f82ed8158a3eec98be3981faa1ddbe..a303071d5e36bb7459aef8a59c0923efdb824e77 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
+#include <mach/irqs.h>
 #include <mach/mux.h>
 
 #define OMAP_I2C_SIZE          0x3f
@@ -79,36 +80,50 @@ static struct platform_device omap_i2c_devices[] = {
 #endif
 };
 
-static void __init omap_i2c_mux_pins(int bus_id)
+#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
+
+#define OMAP_I2C_CMDLINE_SETUP (BIT(31))
+
+static void __init omap_i2c_mux_pins(int bus)
 {
-       /* TODO: Muxing for OMAP3 */
-       switch (bus_id) {
-       case 1:
-               if (cpu_class_is_omap1()) {
-                       omap_cfg_reg(I2C_SCL);
-                       omap_cfg_reg(I2C_SDA);
-               } else if (cpu_is_omap24xx()) {
-                       omap_cfg_reg(M19_24XX_I2C1_SCL);
-                       omap_cfg_reg(L15_24XX_I2C1_SDA);
-               }
-               break;
-       case 2:
-               if (cpu_is_omap24xx()) {
-                       omap_cfg_reg(J15_24XX_I2C2_SCL);
-                       omap_cfg_reg(H19_24XX_I2C2_SDA);
-               }
-               break;
+       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;
        }
+
+       omap_cfg_reg(sda);
+       omap_cfg_reg(scl);
 }
 
-int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
-                         struct i2c_board_info const *info,
-                         unsigned len)
+static int __init omap_i2c_nr_ports(void)
 {
-       int ports, err;
-       struct platform_device *pdev;
-       struct resource *res;
-       resource_size_t base, irq;
+       int ports = 0;
 
        if (cpu_class_is_omap1())
                ports = 1;
@@ -117,17 +132,16 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
        else if (cpu_is_omap34xx())
                ports = 3;
 
-       BUG_ON(bus_id < 1 || bus_id > ports);
+       return ports;
+}
 
-       if (info) {
-               err = i2c_register_board_info(bus_id, info, len);
-               if (err)
-                       return err;
-       }
+static int __init omap_i2c_add_bus(int bus_id)
+{
+       struct platform_device *pdev;
+       struct resource *res;
+       resource_size_t base, irq;
 
        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()) {
@@ -142,6 +156,84 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
                res[1].start = irq;
        }
 
-       omap_i2c_mux_pins(bus_id);
+       omap_i2c_mux_pins(bus_id - 1);
        return platform_device_register(pdev);
 }
+
+/**
+ * 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_rate[ints[1] - 1] = ints[2];
+       i2c_rate[ints[1] - 1] |= 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_rate); i++)
+               if (i2c_rate[i] & OMAP_I2C_CMDLINE_SETUP) {
+                       i2c_rate[i] &= ~OMAP_I2C_CMDLINE_SETUP;
+                       err = omap_i2c_add_bus(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_rate[bus_id - 1])
+               i2c_rate[bus_id - 1] = clkrate;
+       i2c_rate[bus_id - 1] &= ~OMAP_I2C_CMDLINE_SETUP;
+
+       return omap_i2c_add_bus(bus_id);
+}