aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/i2c-core.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 21:10:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 21:10:45 -0400
commitc3a416a669eb83cfa9ccb52db030e72d654bd105 (patch)
tree518d00dc803fbb7d3772fc26a78b6bf3b797baf3 /drivers/i2c/i2c-core.c
parent8c194f3bd322a8bd44d079092d870549b8ae62d1 (diff)
parent2bbd681ba2bfa0f3805fb541b0840b96893c5727 (diff)
Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "Most notable: - introducing the i2c_quirk infrastructure. Now, flaws of I2C controllers can be described and the core will check if the flaws collide with the messages to be sent - wait_for_completion return type cleanup series - new drivers for Digicolor, Netlogic XLP, Ingenic JZ4780 - updates to the I2C slave framework which include API changes. Its only user was updated, too. Documentation was finally added - changed dynamic bus numbering for the DT case. This could change bus numbers for users. However, it fixes a collision where dynamic and static busses request the same id. - driver bugfixes, cleanups" * 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (52 commits) i2c: xlp9xx: Driver for Netlogic XLP9XX/5XX I2C controller of: Add vendor prefix 'netlogic' i2c: davinci: use ICPFUNC to toggle I2C as gpio for bus recovery i2c: davinci: use bus recovery infrastructure i2c: change input parameter to i2c_adapter for prepare/unprepare_recovery i2c: i2c-mux-gpio: remove error messages for probe deferrals i2c: jz4780: Add i2c bus controller driver for Ingenic JZ4780 i2c: dln2: set the device tree node of the adapter i2c: davinci: fixup wait_for_completion_timeout handling i2c: mpc: Fix ISR return value i2c: slave-eeprom: add more info when to increase the pointer i2c: slave: add documentation for i2c-slave-eeprom Documentation: i2c: describe the new slave mode i2c: slave: rework the slave API i2c: add support for the Digicolor I2C controller i2c: busses with dynamic ids should start after fixed ids for DT of: base: add function to get highest id of an alias stem i2c: designware: Suppress error message if platform_get_irq() < 0 i2c: mpc: assign the correct prescaler from SVR i2c: img-scb: fixup of wait_for_completion_timeout return handling ...
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r--drivers/i2c/i2c-core.c73
1 files changed, 71 insertions, 2 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index edf274cabe81..68f687733379 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -561,7 +561,7 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
561 int i = 0, val = 1, ret = 0; 561 int i = 0, val = 1, ret = 0;
562 562
563 if (bri->prepare_recovery) 563 if (bri->prepare_recovery)
564 bri->prepare_recovery(bri); 564 bri->prepare_recovery(adap);
565 565
566 /* 566 /*
567 * By this time SCL is high, as we need to give 9 falling-rising edges 567 * By this time SCL is high, as we need to give 9 falling-rising edges
@@ -586,7 +586,7 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
586 } 586 }
587 587
588 if (bri->unprepare_recovery) 588 if (bri->unprepare_recovery)
589 bri->unprepare_recovery(bri); 589 bri->unprepare_recovery(adap);
590 590
591 return ret; 591 return ret;
592} 592}
@@ -1875,6 +1875,13 @@ static int __init i2c_init(void)
1875{ 1875{
1876 int retval; 1876 int retval;
1877 1877
1878 retval = of_alias_get_highest_id("i2c");
1879
1880 down_write(&__i2c_board_lock);
1881 if (retval >= __i2c_first_dynamic_bus_num)
1882 __i2c_first_dynamic_bus_num = retval + 1;
1883 up_write(&__i2c_board_lock);
1884
1878 retval = bus_register(&i2c_bus_type); 1885 retval = bus_register(&i2c_bus_type);
1879 if (retval) 1886 if (retval)
1880 return retval; 1887 return retval;
@@ -1926,6 +1933,65 @@ module_exit(i2c_exit);
1926 * ---------------------------------------------------- 1933 * ----------------------------------------------------
1927 */ 1934 */
1928 1935
1936/* Check if val is exceeding the quirk IFF quirk is non 0 */
1937#define i2c_quirk_exceeded(val, quirk) ((quirk) && ((val) > (quirk)))
1938
1939static int i2c_quirk_error(struct i2c_adapter *adap, struct i2c_msg *msg, char *err_msg)
1940{
1941 dev_err_ratelimited(&adap->dev, "adapter quirk: %s (addr 0x%04x, size %u, %s)\n",
1942 err_msg, msg->addr, msg->len,
1943 msg->flags & I2C_M_RD ? "read" : "write");
1944 return -EOPNOTSUPP;
1945}
1946
1947static int i2c_check_for_quirks(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1948{
1949 const struct i2c_adapter_quirks *q = adap->quirks;
1950 int max_num = q->max_num_msgs, i;
1951 bool do_len_check = true;
1952
1953 if (q->flags & I2C_AQ_COMB) {
1954 max_num = 2;
1955
1956 /* special checks for combined messages */
1957 if (num == 2) {
1958 if (q->flags & I2C_AQ_COMB_WRITE_FIRST && msgs[0].flags & I2C_M_RD)
1959 return i2c_quirk_error(adap, &msgs[0], "1st comb msg must be write");
1960
1961 if (q->flags & I2C_AQ_COMB_READ_SECOND && !(msgs[1].flags & I2C_M_RD))
1962 return i2c_quirk_error(adap, &msgs[1], "2nd comb msg must be read");
1963
1964 if (q->flags & I2C_AQ_COMB_SAME_ADDR && msgs[0].addr != msgs[1].addr)
1965 return i2c_quirk_error(adap, &msgs[0], "comb msg only to same addr");
1966
1967 if (i2c_quirk_exceeded(msgs[0].len, q->max_comb_1st_msg_len))
1968 return i2c_quirk_error(adap, &msgs[0], "msg too long");
1969
1970 if (i2c_quirk_exceeded(msgs[1].len, q->max_comb_2nd_msg_len))
1971 return i2c_quirk_error(adap, &msgs[1], "msg too long");
1972
1973 do_len_check = false;
1974 }
1975 }
1976
1977 if (i2c_quirk_exceeded(num, max_num))
1978 return i2c_quirk_error(adap, &msgs[0], "too many messages");
1979
1980 for (i = 0; i < num; i++) {
1981 u16 len = msgs[i].len;
1982
1983 if (msgs[i].flags & I2C_M_RD) {
1984 if (do_len_check && i2c_quirk_exceeded(len, q->max_read_len))
1985 return i2c_quirk_error(adap, &msgs[i], "msg too long");
1986 } else {
1987 if (do_len_check && i2c_quirk_exceeded(len, q->max_write_len))
1988 return i2c_quirk_error(adap, &msgs[i], "msg too long");
1989 }
1990 }
1991
1992 return 0;
1993}
1994
1929/** 1995/**
1930 * __i2c_transfer - unlocked flavor of i2c_transfer 1996 * __i2c_transfer - unlocked flavor of i2c_transfer
1931 * @adap: Handle to I2C bus 1997 * @adap: Handle to I2C bus
@@ -1943,6 +2009,9 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1943 unsigned long orig_jiffies; 2009 unsigned long orig_jiffies;
1944 int ret, try; 2010 int ret, try;
1945 2011
2012 if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
2013 return -EOPNOTSUPP;
2014
1946 /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets 2015 /* i2c_trace_msg gets enabled when tracepoint i2c_transfer gets
1947 * enabled. This is an efficient way of keeping the for-loop from 2016 * enabled. This is an efficient way of keeping the for-loop from
1948 * being executed when not needed. 2017 * being executed when not needed.