2 * Copyright (C) ST-Ericsson SA 2010
4 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5 * License terms: GNU General Public License (GPL), version 2
8 #define pr_fmt(fmt) "mop500-uib: " fmt
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/i2c.h>
14 #include <mach/hardware.h>
15 #include "board-mop500.h"
28 static struct uib __initdata mop500_uibs[] = {
32 .init = mop500_stuib_init,
37 .init = mop500_u8500uib_init,
41 static struct uib *mop500_uib;
43 static int __init mop500_uib_setup(char *str)
47 for (i = 0; i < ARRAY_SIZE(mop500_uibs); i++) {
48 struct uib *uib = &mop500_uibs[i];
50 if (!strcmp(str, uib->option)) {
56 if (i == ARRAY_SIZE(mop500_uibs))
57 pr_err("invalid uib= option (%s)\n", str);
61 __setup("uib=", mop500_uib_setup);
64 * The UIBs are detected after the I2C host controllers are registered, so
65 * i2c_register_board_info() can't be used.
67 void mop500_uib_i2c_add(int busnum, struct i2c_board_info *info,
70 struct i2c_adapter *adap;
71 struct i2c_client *client;
74 adap = i2c_get_adapter(busnum);
76 pr_err("failed to get adapter i2c%d\n", busnum);
80 for (i = 0; i < n; i++) {
81 client = i2c_new_device(adap, &info[i]);
83 pr_err("failed to register %s to i2c%d\n",
84 info[i].type, busnum);
87 i2c_put_adapter(adap);
90 static void __init __mop500_uib_init(struct uib *uib, const char *why)
92 pr_info("%s (%s)\n", uib->name, why);
97 * Detect the UIB attached based on the presence or absence of i2c devices.
99 static int __init mop500_uib_init(void)
101 struct uib *uib = mop500_uib;
102 struct i2c_adapter *i2c0;
109 __mop500_uib_init(uib, "from uib= boot argument");
113 i2c0 = i2c_get_adapter(0);
115 __mop500_uib_init(&mop500_uibs[STUIB],
116 "fallback, could not get i2c0");
120 /* U8500-UIB has the TC35893 at 0x44 on I2C0, the ST-UIB doesn't. */
121 ret = i2c_smbus_xfer(i2c0, 0x44, 0, I2C_SMBUS_WRITE, 0,
122 I2C_SMBUS_QUICK, NULL);
123 i2c_put_adapter(i2c0);
126 uib = &mop500_uibs[U8500UIB];
128 uib = &mop500_uibs[STUIB];
130 __mop500_uib_init(uib, "detected");
135 module_init(mop500_uib_init);