diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-04 13:57:43 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-04 13:57:43 -0500 |
| commit | 4141cf676b9e345d3ddeb1710dd3156a09c50244 (patch) | |
| tree | 4b2b6249e99efdd47eafa5780f106d593f64708b /drivers/i2c | |
| parent | 3462ac57033e79a87dbae2497773f22b9c536fbc (diff) | |
| parent | e38c85644e11c6dc5a39305c96b617f63403423d (diff) | |
Merge branch 'i2c/for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang:
"I2C has the following changes for you:
- new flag to mark DMA safe buffers in i2c_msg. Also, some
infrastructure around it. And docs.
- huge refactoring of the at24 driver led by the new maintainer
Bartosz
- update I2C bus recovery to send STOP after recovery
- conversion from gpio to gpiod for I2C bus recovery
- adding a fault-injector to the i2c-gpio driver
- lots of small driver improvements, and bigger ones to
i2c-sh_mobile"
* 'i2c/for-4.16' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (99 commits)
i2c: mv64xxx: Add myself as maintainer for this driver
i2c: mv64xxx: Fix clock resource by adding an optional bus clock
i2c: mv64xxx: Remove useless test before clk_disable_unprepare
i2c: mxs: use true and false for boolean values
i2c: meson: update doc description to fix build warnings
i2c: meson: add configurable divider factors
dt-bindings: i2c: update documentation for the Meson-AXG
i2c: imx-lpi2c: add runtime pm support
i2c: rcar: fix some trivial typos in comments
i2c: davinci: fix the cpufreq transition
i2c: rk3x: add proper kerneldoc header
i2c: rk3x: account for const type of of_device_id.data
i2c: acorn: remove outdated path from file header
i2c: acorn: add MODULE_LICENSE tag
i2c: rcar: implement bus recovery
i2c: send STOP after successful bus recovery
i2c: ensure SDA is released in recovery if SDA is controllable
i2c: add 'set_sda' to bus_recovery_info
i2c: add identifier in declarations for i2c_bus_recovery
i2c: make kerneldoc about bus recovery more precise
...
Diffstat (limited to 'drivers/i2c')
28 files changed, 761 insertions, 454 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index 1147bddb8b2c..3df0efd69ae3 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
| @@ -649,6 +649,11 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap, | |||
| 649 | if (bit_adap->getscl == NULL) | 649 | if (bit_adap->getscl == NULL) |
| 650 | adap->quirks = &i2c_bit_quirk_no_clk_stretch; | 650 | adap->quirks = &i2c_bit_quirk_no_clk_stretch; |
| 651 | 651 | ||
| 652 | /* Bring bus to a known state. Looks like STOP if bus is not free yet */ | ||
| 653 | setscl(bit_adap, 1); | ||
| 654 | udelay(bit_adap->udelay); | ||
| 655 | setsda(bit_adap, 1); | ||
| 656 | |||
| 652 | ret = add_adapter(adap); | 657 | ret = add_adapter(adap); |
| 653 | if (ret < 0) | 658 | if (ret < 0) |
| 654 | return ret; | 659 | return ret; |
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 009345d8f49d..a9805c7cb305 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
| @@ -603,6 +603,14 @@ config I2C_GPIO | |||
| 603 | This is a very simple bitbanging I2C driver utilizing the | 603 | This is a very simple bitbanging I2C driver utilizing the |
| 604 | arch-neutral GPIO API to control the SCL and SDA lines. | 604 | arch-neutral GPIO API to control the SCL and SDA lines. |
| 605 | 605 | ||
| 606 | config I2C_GPIO_FAULT_INJECTOR | ||
| 607 | bool "GPIO-based fault injector" | ||
| 608 | depends on I2C_GPIO | ||
| 609 | help | ||
| 610 | This adds some functionality to the i2c-gpio driver which can inject | ||
| 611 | faults to an I2C bus, so another bus master can be stress-tested. | ||
| 612 | This is for debugging. If unsure, say 'no'. | ||
| 613 | |||
| 606 | config I2C_HIGHLANDER | 614 | config I2C_HIGHLANDER |
| 607 | tristate "Highlander FPGA SMBus interface" | 615 | tristate "Highlander FPGA SMBus interface" |
| 608 | depends on SH_HIGHLANDER | 616 | depends on SH_HIGHLANDER |
diff --git a/drivers/i2c/busses/i2c-acorn.c b/drivers/i2c/busses/i2c-acorn.c index 9d7be5af2bf2..f4a5ae69bf6a 100644 --- a/drivers/i2c/busses/i2c-acorn.c +++ b/drivers/i2c/busses/i2c-acorn.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * linux/drivers/acorn/char/i2c.c | 2 | * ARM IOC/IOMD i2c driver. |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2000 Russell King | 4 | * Copyright (C) 2000 Russell King |
| 5 | * | 5 | * |
| @@ -7,8 +7,6 @@ | |||
| 7 | * it under the terms of the GNU General Public License version 2 as | 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
| 9 | * | 9 | * |
| 10 | * ARM IOC/IOMD i2c driver. | ||
| 11 | * | ||
| 12 | * On Acorn machines, the following i2c devices are on the bus: | 10 | * On Acorn machines, the following i2c devices are on the bus: |
| 13 | * - PCF8583 real time clock & static RAM | 11 | * - PCF8583 real time clock & static RAM |
| 14 | */ | 12 | */ |
| @@ -94,3 +92,7 @@ static int __init i2c_ioc_init(void) | |||
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | module_init(i2c_ioc_init); | 94 | module_init(i2c_ioc_init); |
| 95 | |||
| 96 | MODULE_AUTHOR("Russell King <linux@armlinux.org.uk>"); | ||
| 97 | MODULE_DESCRIPTION("ARM IOC/IOMD i2c driver"); | ||
| 98 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 2ead9b9eebb7..75d6ab177055 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c | |||
| @@ -33,7 +33,7 @@ | |||
| 33 | #include <linux/io.h> | 33 | #include <linux/io.h> |
| 34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
| 35 | #include <linux/cpufreq.h> | 35 | #include <linux/cpufreq.h> |
| 36 | #include <linux/gpio.h> | 36 | #include <linux/gpio/consumer.h> |
| 37 | #include <linux/of_device.h> | 37 | #include <linux/of_device.h> |
| 38 | #include <linux/platform_data/i2c-davinci.h> | 38 | #include <linux/platform_data/i2c-davinci.h> |
| 39 | #include <linux/pm_runtime.h> | 39 | #include <linux/pm_runtime.h> |
| @@ -139,7 +139,6 @@ struct davinci_i2c_dev { | |||
| 139 | u8 terminate; | 139 | u8 terminate; |
| 140 | struct i2c_adapter adapter; | 140 | struct i2c_adapter adapter; |
| 141 | #ifdef CONFIG_CPU_FREQ | 141 | #ifdef CONFIG_CPU_FREQ |
| 142 | struct completion xfr_complete; | ||
| 143 | struct notifier_block freq_transition; | 142 | struct notifier_block freq_transition; |
| 144 | #endif | 143 | #endif |
| 145 | struct davinci_i2c_platform_data *pdata; | 144 | struct davinci_i2c_platform_data *pdata; |
| @@ -294,7 +293,7 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev) | |||
| 294 | } | 293 | } |
| 295 | 294 | ||
| 296 | /* | 295 | /* |
| 297 | * This routine does i2c bus recovery by using i2c_generic_gpio_recovery | 296 | * This routine does i2c bus recovery by using i2c_generic_scl_recovery |
| 298 | * which is provided by I2C Bus recovery infrastructure. | 297 | * which is provided by I2C Bus recovery infrastructure. |
| 299 | */ | 298 | */ |
| 300 | static void davinci_i2c_prepare_recovery(struct i2c_adapter *adap) | 299 | static void davinci_i2c_prepare_recovery(struct i2c_adapter *adap) |
| @@ -316,7 +315,7 @@ static void davinci_i2c_unprepare_recovery(struct i2c_adapter *adap) | |||
| 316 | } | 315 | } |
| 317 | 316 | ||
| 318 | static struct i2c_bus_recovery_info davinci_i2c_gpio_recovery_info = { | 317 | static struct i2c_bus_recovery_info davinci_i2c_gpio_recovery_info = { |
| 319 | .recover_bus = i2c_generic_gpio_recovery, | 318 | .recover_bus = i2c_generic_scl_recovery, |
| 320 | .prepare_recovery = davinci_i2c_prepare_recovery, | 319 | .prepare_recovery = davinci_i2c_prepare_recovery, |
| 321 | .unprepare_recovery = davinci_i2c_unprepare_recovery, | 320 | .unprepare_recovery = davinci_i2c_unprepare_recovery, |
| 322 | }; | 321 | }; |
| @@ -567,9 +566,6 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
| 567 | } | 566 | } |
| 568 | 567 | ||
| 569 | ret = num; | 568 | ret = num; |
| 570 | #ifdef CONFIG_CPU_FREQ | ||
| 571 | complete(&dev->xfr_complete); | ||
| 572 | #endif | ||
| 573 | 569 | ||
| 574 | out: | 570 | out: |
| 575 | pm_runtime_mark_last_busy(dev->dev); | 571 | pm_runtime_mark_last_busy(dev->dev); |
| @@ -717,13 +713,15 @@ static int i2c_davinci_cpufreq_transition(struct notifier_block *nb, | |||
| 717 | struct davinci_i2c_dev *dev; | 713 | struct davinci_i2c_dev *dev; |
| 718 | 714 | ||
| 719 | dev = container_of(nb, struct davinci_i2c_dev, freq_transition); | 715 | dev = container_of(nb, struct davinci_i2c_dev, freq_transition); |
| 716 | |||
| 717 | i2c_lock_adapter(&dev->adapter); | ||
| 720 | if (val == CPUFREQ_PRECHANGE) { | 718 | if (val == CPUFREQ_PRECHANGE) { |
| 721 | wait_for_completion(&dev->xfr_complete); | ||
| 722 | davinci_i2c_reset_ctrl(dev, 0); | 719 | davinci_i2c_reset_ctrl(dev, 0); |
| 723 | } else if (val == CPUFREQ_POSTCHANGE) { | 720 | } else if (val == CPUFREQ_POSTCHANGE) { |
| 724 | i2c_davinci_calc_clk_dividers(dev); | 721 | i2c_davinci_calc_clk_dividers(dev); |
| 725 | davinci_i2c_reset_ctrl(dev, 1); | 722 | davinci_i2c_reset_ctrl(dev, 1); |
| 726 | } | 723 | } |
| 724 | i2c_unlock_adapter(&dev->adapter); | ||
| 727 | 725 | ||
| 728 | return 0; | 726 | return 0; |
| 729 | } | 727 | } |
| @@ -769,6 +767,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
| 769 | struct davinci_i2c_dev *dev; | 767 | struct davinci_i2c_dev *dev; |
| 770 | struct i2c_adapter *adap; | 768 | struct i2c_adapter *adap; |
| 771 | struct resource *mem; | 769 | struct resource *mem; |
| 770 | struct i2c_bus_recovery_info *rinfo; | ||
| 772 | int r, irq; | 771 | int r, irq; |
| 773 | 772 | ||
| 774 | irq = platform_get_irq(pdev, 0); | 773 | irq = platform_get_irq(pdev, 0); |
| @@ -789,9 +788,7 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
| 789 | } | 788 | } |
| 790 | 789 | ||
| 791 | init_completion(&dev->cmd_complete); | 790 | init_completion(&dev->cmd_complete); |
| 792 | #ifdef CONFIG_CPU_FREQ | 791 | |
| 793 | init_completion(&dev->xfr_complete); | ||
| 794 | #endif | ||
| 795 | dev->dev = &pdev->dev; | 792 | dev->dev = &pdev->dev; |
| 796 | dev->irq = irq; | 793 | dev->irq = irq; |
| 797 | dev->pdata = dev_get_platdata(&pdev->dev); | 794 | dev->pdata = dev_get_platdata(&pdev->dev); |
| @@ -868,10 +865,20 @@ static int davinci_i2c_probe(struct platform_device *pdev) | |||
| 868 | 865 | ||
| 869 | if (dev->pdata->has_pfunc) | 866 | if (dev->pdata->has_pfunc) |
| 870 | adap->bus_recovery_info = &davinci_i2c_scl_recovery_info; | 867 | adap->bus_recovery_info = &davinci_i2c_scl_recovery_info; |
| 871 | else if (dev->pdata->scl_pin) { | 868 | else if (dev->pdata->gpio_recovery) { |
| 872 | adap->bus_recovery_info = &davinci_i2c_gpio_recovery_info; | 869 | rinfo = &davinci_i2c_gpio_recovery_info; |
| 873 | adap->bus_recovery_info->scl_gpio = dev->pdata->scl_pin; | 870 | adap->bus_recovery_info = rinfo; |
| 874 | adap->bus_recovery_info->sda_gpio = dev->pdata->sda_pin; | 871 | rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", |
| 872 | GPIOD_OUT_HIGH_OPEN_DRAIN); | ||
| 873 | if (IS_ERR(rinfo->scl_gpiod)) { | ||
| 874 | r = PTR_ERR(rinfo->scl_gpiod); | ||
| 875 | goto err_unuse_clocks; | ||
| 876 | } | ||
| 877 | rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); | ||
| 878 | if (IS_ERR(rinfo->sda_gpiod)) { | ||
| 879 | r = PTR_ERR(rinfo->sda_gpiod); | ||
| 880 | goto err_unuse_clocks; | ||
| 881 | } | ||
| 875 | } | 882 | } |
| 876 | 883 | ||
| 877 | adap->nr = pdev->id; | 884 | adap->nr = pdev->id; |
diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c index d1a69372432f..27ebd90de43b 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | * ---------------------------------------------------------------------------- | 21 | * ---------------------------------------------------------------------------- |
| 22 | * | 22 | * |
| 23 | */ | 23 | */ |
| 24 | #include <linux/clk.h> | ||
| 24 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
| 25 | #include <linux/export.h> | 26 | #include <linux/export.h> |
| 26 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
| @@ -185,6 +186,19 @@ unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev) | |||
| 185 | return dev->get_clk_rate_khz(dev); | 186 | return dev->get_clk_rate_khz(dev); |
| 186 | } | 187 | } |
| 187 | 188 | ||
| 189 | int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare) | ||
| 190 | { | ||
| 191 | if (IS_ERR(dev->clk)) | ||
| 192 | return PTR_ERR(dev->clk); | ||
| 193 | |||
| 194 | if (prepare) | ||
| 195 | return clk_prepare_enable(dev->clk); | ||
| 196 | |||
| 197 | clk_disable_unprepare(dev->clk); | ||
| 198 | return 0; | ||
| 199 | } | ||
| 200 | EXPORT_SYMBOL_GPL(i2c_dw_prepare_clk); | ||
| 201 | |||
| 188 | int i2c_dw_acquire_lock(struct dw_i2c_dev *dev) | 202 | int i2c_dw_acquire_lock(struct dw_i2c_dev *dev) |
| 189 | { | 203 | { |
| 190 | int ret; | 204 | int ret; |
| @@ -217,7 +231,11 @@ int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev) | |||
| 217 | while (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { | 231 | while (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { |
| 218 | if (timeout <= 0) { | 232 | if (timeout <= 0) { |
| 219 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); | 233 | dev_warn(dev->dev, "timeout waiting for bus ready\n"); |
| 220 | return -ETIMEDOUT; | 234 | i2c_recover_bus(&dev->adapter); |
| 235 | |||
| 236 | if (dw_readl(dev, DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) | ||
| 237 | return -ETIMEDOUT; | ||
| 238 | return 0; | ||
| 221 | } | 239 | } |
| 222 | timeout--; | 240 | timeout--; |
| 223 | usleep_range(1000, 1100); | 241 | usleep_range(1000, 1100); |
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h index 9fee4c054d3d..8707c76b2fee 100644 --- a/drivers/i2c/busses/i2c-designware-core.h +++ b/drivers/i2c/busses/i2c-designware-core.h | |||
| @@ -284,6 +284,7 @@ struct dw_i2c_dev { | |||
| 284 | void (*disable_int)(struct dw_i2c_dev *dev); | 284 | void (*disable_int)(struct dw_i2c_dev *dev); |
| 285 | int (*init)(struct dw_i2c_dev *dev); | 285 | int (*init)(struct dw_i2c_dev *dev); |
| 286 | int mode; | 286 | int mode; |
| 287 | struct i2c_bus_recovery_info rinfo; | ||
| 287 | }; | 288 | }; |
| 288 | 289 | ||
| 289 | #define ACCESS_SWAP 0x00000001 | 290 | #define ACCESS_SWAP 0x00000001 |
| @@ -299,6 +300,7 @@ u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset); | |||
| 299 | void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable); | 300 | void __i2c_dw_enable(struct dw_i2c_dev *dev, bool enable); |
| 300 | void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable); | 301 | void __i2c_dw_enable_and_wait(struct dw_i2c_dev *dev, bool enable); |
| 301 | unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev); | 302 | unsigned long i2c_dw_clk_rate(struct dw_i2c_dev *dev); |
| 303 | int i2c_dw_prepare_clk(struct dw_i2c_dev *dev, bool prepare); | ||
| 302 | int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); | 304 | int i2c_dw_acquire_lock(struct dw_i2c_dev *dev); |
| 303 | void i2c_dw_release_lock(struct dw_i2c_dev *dev); | 305 | void i2c_dw_release_lock(struct dw_i2c_dev *dev); |
| 304 | int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev); | 306 | int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev); |
diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index 418c233075d3..ae691884d071 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c | |||
| @@ -25,11 +25,13 @@ | |||
| 25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
| 26 | #include <linux/errno.h> | 26 | #include <linux/errno.h> |
| 27 | #include <linux/export.h> | 27 | #include <linux/export.h> |
| 28 | #include <linux/gpio/consumer.h> | ||
| 28 | #include <linux/i2c.h> | 29 | #include <linux/i2c.h> |
| 29 | #include <linux/interrupt.h> | 30 | #include <linux/interrupt.h> |
| 30 | #include <linux/io.h> | 31 | #include <linux/io.h> |
| 31 | #include <linux/module.h> | 32 | #include <linux/module.h> |
| 32 | #include <linux/pm_runtime.h> | 33 | #include <linux/pm_runtime.h> |
| 34 | #include <linux/reset.h> | ||
| 33 | 35 | ||
| 34 | #include "i2c-designware-core.h" | 36 | #include "i2c-designware-core.h" |
| 35 | 37 | ||
| @@ -443,6 +445,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) | |||
| 443 | if (!wait_for_completion_timeout(&dev->cmd_complete, adap->timeout)) { | 445 | if (!wait_for_completion_timeout(&dev->cmd_complete, adap->timeout)) { |
| 444 | dev_err(dev->dev, "controller timed out\n"); | 446 | dev_err(dev->dev, "controller timed out\n"); |
| 445 | /* i2c_dw_init implicitly disables the adapter */ | 447 | /* i2c_dw_init implicitly disables the adapter */ |
| 448 | i2c_recover_bus(&dev->adapter); | ||
| 446 | i2c_dw_init_master(dev); | 449 | i2c_dw_init_master(dev); |
| 447 | ret = -ETIMEDOUT; | 450 | ret = -ETIMEDOUT; |
| 448 | goto done; | 451 | goto done; |
| @@ -613,6 +616,56 @@ static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) | |||
| 613 | return IRQ_HANDLED; | 616 | return IRQ_HANDLED; |
| 614 | } | 617 | } |
| 615 | 618 | ||
| 619 | static void i2c_dw_prepare_recovery(struct i2c_adapter *adap) | ||
| 620 | { | ||
| 621 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); | ||
| 622 | |||
| 623 | i2c_dw_disable(dev); | ||
| 624 | reset_control_assert(dev->rst); | ||
| 625 | i2c_dw_prepare_clk(dev, false); | ||
| 626 | } | ||
| 627 | |||
| 628 | static void i2c_dw_unprepare_recovery(struct i2c_adapter *adap) | ||
| 629 | { | ||
| 630 | struct dw_i2c_dev *dev = i2c_get_adapdata(adap); | ||
| 631 | |||
| 632 | i2c_dw_prepare_clk(dev, true); | ||
| 633 | reset_control_deassert(dev->rst); | ||
| 634 | i2c_dw_init_master(dev); | ||
| 635 | } | ||
| 636 | |||
| 637 | static int i2c_dw_init_recovery_info(struct dw_i2c_dev *dev) | ||
| 638 | { | ||
| 639 | struct i2c_bus_recovery_info *rinfo = &dev->rinfo; | ||
| 640 | struct i2c_adapter *adap = &dev->adapter; | ||
| 641 | struct gpio_desc *gpio; | ||
| 642 | int r; | ||
| 643 | |||
| 644 | gpio = devm_gpiod_get(dev->dev, "scl", GPIOD_OUT_HIGH); | ||
| 645 | if (IS_ERR(gpio)) { | ||
| 646 | r = PTR_ERR(gpio); | ||
| 647 | if (r == -ENOENT) | ||
| 648 | return 0; | ||
| 649 | return r; | ||
| 650 | } | ||
| 651 | rinfo->scl_gpiod = gpio; | ||
| 652 | |||
| 653 | gpio = devm_gpiod_get_optional(dev->dev, "sda", GPIOD_IN); | ||
| 654 | if (IS_ERR(gpio)) | ||
| 655 | return PTR_ERR(gpio); | ||
| 656 | rinfo->sda_gpiod = gpio; | ||
| 657 | |||
| 658 | rinfo->recover_bus = i2c_generic_scl_recovery; | ||
| 659 | rinfo->prepare_recovery = i2c_dw_prepare_recovery; | ||
| 660 | rinfo->unprepare_recovery = i2c_dw_unprepare_recovery; | ||
| 661 | adap->bus_recovery_info = rinfo; | ||
| 662 | |||
| 663 | dev_info(dev->dev, "running with gpio recovery mode! scl%s", | ||
| 664 | rinfo->sda_gpiod ? ",sda" : ""); | ||
| 665 | |||
| 666 | return 0; | ||
| 667 | } | ||
| 668 | |||
| 616 | int i2c_dw_probe(struct dw_i2c_dev *dev) | 669 | int i2c_dw_probe(struct dw_i2c_dev *dev) |
| 617 | { | 670 | { |
| 618 | struct i2c_adapter *adap = &dev->adapter; | 671 | struct i2c_adapter *adap = &dev->adapter; |
| @@ -652,6 +705,10 @@ int i2c_dw_probe(struct dw_i2c_dev *dev) | |||
| 652 | return ret; | 705 | return ret; |
| 653 | } | 706 | } |
| 654 | 707 | ||
| 708 | ret = i2c_dw_init_recovery_info(dev); | ||
| 709 | if (ret) | ||
| 710 | return ret; | ||
| 711 | |||
| 655 | /* | 712 | /* |
| 656 | * Increment PM usage count during adapter registration in order to | 713 | * Increment PM usage count during adapter registration in order to |
| 657 | * avoid possible spurious runtime suspend when adapter device is | 714 | * avoid possible spurious runtime suspend when adapter device is |
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 153b947702c5..5660daf6c92e 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c | |||
| @@ -202,29 +202,6 @@ static void i2c_dw_configure_slave(struct dw_i2c_dev *dev) | |||
| 202 | DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED; | 202 | DW_IC_CON_RESTART_EN | DW_IC_CON_STOP_DET_IFADDRESSED; |
| 203 | 203 | ||
| 204 | dev->mode = DW_IC_SLAVE; | 204 | dev->mode = DW_IC_SLAVE; |
| 205 | |||
| 206 | switch (dev->clk_freq) { | ||
| 207 | case 100000: | ||
| 208 | dev->slave_cfg |= DW_IC_CON_SPEED_STD; | ||
| 209 | break; | ||
| 210 | case 3400000: | ||
| 211 | dev->slave_cfg |= DW_IC_CON_SPEED_HIGH; | ||
| 212 | break; | ||
| 213 | default: | ||
| 214 | dev->slave_cfg |= DW_IC_CON_SPEED_FAST; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | static int i2c_dw_plat_prepare_clk(struct dw_i2c_dev *i_dev, bool prepare) | ||
| 219 | { | ||
| 220 | if (IS_ERR(i_dev->clk)) | ||
| 221 | return PTR_ERR(i_dev->clk); | ||
| 222 | |||
| 223 | if (prepare) | ||
| 224 | return clk_prepare_enable(i_dev->clk); | ||
| 225 | |||
| 226 | clk_disable_unprepare(i_dev->clk); | ||
| 227 | return 0; | ||
| 228 | } | 205 | } |
| 229 | 206 | ||
| 230 | static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id) | 207 | static void dw_i2c_set_fifo_size(struct dw_i2c_dev *dev, int id) |
| @@ -356,7 +333,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) | |||
| 356 | i2c_dw_configure_master(dev); | 333 | i2c_dw_configure_master(dev); |
| 357 | 334 | ||
| 358 | dev->clk = devm_clk_get(&pdev->dev, NULL); | 335 | dev->clk = devm_clk_get(&pdev->dev, NULL); |
| 359 | if (!i2c_dw_plat_prepare_clk(dev, true)) { | 336 | if (!i2c_dw_prepare_clk(dev, true)) { |
| 360 | dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; | 337 | dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; |
| 361 | 338 | ||
| 362 | if (!dev->sda_hold_time && ht) | 339 | if (!dev->sda_hold_time && ht) |
| @@ -472,7 +449,7 @@ static int dw_i2c_plat_suspend(struct device *dev) | |||
| 472 | struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); | 449 | struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); |
| 473 | 450 | ||
| 474 | i_dev->disable(i_dev); | 451 | i_dev->disable(i_dev); |
| 475 | i2c_dw_plat_prepare_clk(i_dev, false); | 452 | i2c_dw_prepare_clk(i_dev, false); |
| 476 | 453 | ||
| 477 | return 0; | 454 | return 0; |
| 478 | } | 455 | } |
| @@ -481,7 +458,7 @@ static int dw_i2c_plat_resume(struct device *dev) | |||
| 481 | { | 458 | { |
| 482 | struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); | 459 | struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); |
| 483 | 460 | ||
| 484 | i2c_dw_plat_prepare_clk(i_dev, true); | 461 | i2c_dw_prepare_clk(i_dev, true); |
| 485 | i_dev->init(i_dev); | 462 | i_dev->init(i_dev); |
| 486 | 463 | ||
| 487 | return 0; | 464 | return 0; |
diff --git a/drivers/i2c/busses/i2c-designware-slave.c b/drivers/i2c/busses/i2c-designware-slave.c index ea9578ab19a1..d42558d1b002 100644 --- a/drivers/i2c/busses/i2c-designware-slave.c +++ b/drivers/i2c/busses/i2c-designware-slave.c | |||
| @@ -51,9 +51,7 @@ static void i2c_dw_configure_fifo_slave(struct dw_i2c_dev *dev) | |||
| 51 | */ | 51 | */ |
| 52 | static int i2c_dw_init_slave(struct dw_i2c_dev *dev) | 52 | static int i2c_dw_init_slave(struct dw_i2c_dev *dev) |
| 53 | { | 53 | { |
| 54 | u32 sda_falling_time, scl_falling_time; | ||
| 55 | u32 reg, comp_param1; | 54 | u32 reg, comp_param1; |
| 56 | u32 hcnt, lcnt; | ||
| 57 | int ret; | 55 | int ret; |
| 58 | 56 | ||
| 59 | ret = i2c_dw_acquire_lock(dev); | 57 | ret = i2c_dw_acquire_lock(dev); |
| @@ -79,68 +77,6 @@ static int i2c_dw_init_slave(struct dw_i2c_dev *dev) | |||
| 79 | /* Disable the adapter. */ | 77 | /* Disable the adapter. */ |
| 80 | __i2c_dw_enable_and_wait(dev, false); | 78 | __i2c_dw_enable_and_wait(dev, false); |
| 81 | 79 | ||
| 82 | /* Set standard and fast speed deviders for high/low periods. */ | ||
| 83 | sda_falling_time = dev->sda_falling_time ?: 300; /* ns */ | ||
| 84 | scl_falling_time = dev->scl_falling_time ?: 300; /* ns */ | ||
| 85 | |||
| 86 | /* Set SCL timing parameters for standard-mode. */ | ||
| 87 | if (dev->ss_hcnt && dev->ss_lcnt) { | ||
| 88 | hcnt = dev->ss_hcnt; | ||
| 89 | lcnt = dev->ss_lcnt; | ||
| 90 | } else { | ||
| 91 | hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), | ||
| 92 | 4000, /* tHD;STA = tHIGH = 4.0 us */ | ||
| 93 | sda_falling_time, | ||
| 94 | 0, /* 0: DW default, 1: Ideal */ | ||
| 95 | 0); /* No offset */ | ||
| 96 | lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), | ||
| 97 | 4700, /* tLOW = 4.7 us */ | ||
| 98 | scl_falling_time, | ||
| 99 | 0); /* No offset */ | ||
| 100 | } | ||
| 101 | dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT); | ||
| 102 | dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT); | ||
| 103 | dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); | ||
| 104 | |||
| 105 | /* Set SCL timing parameters for fast-mode or fast-mode plus. */ | ||
| 106 | if ((dev->clk_freq == 1000000) && dev->fp_hcnt && dev->fp_lcnt) { | ||
| 107 | hcnt = dev->fp_hcnt; | ||
| 108 | lcnt = dev->fp_lcnt; | ||
| 109 | } else if (dev->fs_hcnt && dev->fs_lcnt) { | ||
| 110 | hcnt = dev->fs_hcnt; | ||
| 111 | lcnt = dev->fs_lcnt; | ||
| 112 | } else { | ||
| 113 | hcnt = i2c_dw_scl_hcnt(i2c_dw_clk_rate(dev), | ||
| 114 | 600, /* tHD;STA = tHIGH = 0.6 us */ | ||
| 115 | sda_falling_time, | ||
| 116 | 0, /* 0: DW default, 1: Ideal */ | ||
| 117 | 0); /* No offset */ | ||
| 118 | lcnt = i2c_dw_scl_lcnt(i2c_dw_clk_rate(dev), | ||
| 119 | 1300, /* tLOW = 1.3 us */ | ||
| 120 | scl_falling_time, | ||
| 121 | 0); /* No offset */ | ||
| 122 | } | ||
| 123 | dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT); | ||
| 124 | dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT); | ||
| 125 | dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); | ||
| 126 | |||
| 127 | if ((dev->slave_cfg & DW_IC_CON_SPEED_MASK) == | ||
| 128 | DW_IC_CON_SPEED_HIGH) { | ||
| 129 | if ((comp_param1 & DW_IC_COMP_PARAM_1_SPEED_MODE_MASK) | ||
| 130 | != DW_IC_COMP_PARAM_1_SPEED_MODE_HIGH) { | ||
| 131 | dev_err(dev->dev, "High Speed not supported!\n"); | ||
| 132 | dev->slave_cfg &= ~DW_IC_CON_SPEED_MASK; | ||
| 133 | dev->slave_cfg |= DW_IC_CON_SPEED_FAST; | ||
| 134 | } else if (dev->hs_hcnt && dev->hs_lcnt) { | ||
| 135 | hcnt = dev->hs_hcnt; | ||
| 136 | lcnt = dev->hs_lcnt; | ||
| 137 | dw_writel(dev, hcnt, DW_IC_HS_SCL_HCNT); | ||
| 138 | dw_writel(dev, lcnt, DW_IC_HS_SCL_LCNT); | ||
| 139 | dev_dbg(dev->dev, "HighSpeed-mode HCNT:LCNT = %d:%d\n", | ||
| 140 | hcnt, lcnt); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | /* Configure SDA Hold Time if required. */ | 80 | /* Configure SDA Hold Time if required. */ |
| 145 | reg = dw_readl(dev, DW_IC_COMP_VERSION); | 81 | reg = dw_readl(dev, DW_IC_COMP_VERSION); |
| 146 | if (reg >= DW_IC_SDA_HOLD_MIN_VERS) { | 82 | if (reg >= DW_IC_SDA_HOLD_MIN_VERS) { |
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c index 3855e0b11877..b02428498f6d 100644 --- a/drivers/i2c/busses/i2c-exynos5.c +++ b/drivers/i2c/busses/i2c-exynos5.c | |||
| @@ -170,7 +170,7 @@ | |||
| 170 | #define HSI2C_HS_TX_CLOCK 1000000 | 170 | #define HSI2C_HS_TX_CLOCK 1000000 |
| 171 | #define HSI2C_FS_TX_CLOCK 100000 | 171 | #define HSI2C_FS_TX_CLOCK 100000 |
| 172 | 172 | ||
| 173 | #define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000)) | 173 | #define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(100)) |
| 174 | 174 | ||
| 175 | #define HSI2C_EXYNOS7 BIT(0) | 175 | #define HSI2C_EXYNOS7 BIT(0) |
| 176 | 176 | ||
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index d80ea6ce91bb..58abb3eced58 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c | |||
| @@ -7,6 +7,8 @@ | |||
| 7 | * it under the terms of the GNU General Public License version 2 as | 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. | 8 | * published by the Free Software Foundation. |
| 9 | */ | 9 | */ |
| 10 | #include <linux/debugfs.h> | ||
| 11 | #include <linux/delay.h> | ||
| 10 | #include <linux/i2c.h> | 12 | #include <linux/i2c.h> |
| 11 | #include <linux/i2c-algo-bit.h> | 13 | #include <linux/i2c-algo-bit.h> |
| 12 | #include <linux/i2c-gpio.h> | 14 | #include <linux/i2c-gpio.h> |
| @@ -23,6 +25,9 @@ struct i2c_gpio_private_data { | |||
| 23 | struct i2c_adapter adap; | 25 | struct i2c_adapter adap; |
| 24 | struct i2c_algo_bit_data bit_data; | 26 | struct i2c_algo_bit_data bit_data; |
| 25 | struct i2c_gpio_platform_data pdata; | 27 | struct i2c_gpio_platform_data pdata; |
| 28 | #ifdef CONFIG_I2C_GPIO_FAULT_INJECTOR | ||
| 29 | struct dentry *debug_dir; | ||
| 30 | #endif | ||
| 26 | }; | 31 | }; |
| 27 | 32 | ||
| 28 | /* | 33 | /* |
| @@ -34,7 +39,7 @@ static void i2c_gpio_setsda_val(void *data, int state) | |||
| 34 | { | 39 | { |
| 35 | struct i2c_gpio_private_data *priv = data; | 40 | struct i2c_gpio_private_data *priv = data; |
| 36 | 41 | ||
| 37 | gpiod_set_value(priv->sda, state); | 42 | gpiod_set_value_cansleep(priv->sda, state); |
| 38 | } | 43 | } |
| 39 | 44 | ||
| 40 | /* | 45 | /* |
| @@ -47,23 +52,125 @@ static void i2c_gpio_setscl_val(void *data, int state) | |||
| 47 | { | 52 | { |
| 48 | struct i2c_gpio_private_data *priv = data; | 53 | struct i2c_gpio_private_data *priv = data; |
| 49 | 54 | ||
| 50 | gpiod_set_value(priv->scl, state); | 55 | gpiod_set_value_cansleep(priv->scl, state); |
| 51 | } | 56 | } |
| 52 | 57 | ||
| 53 | static int i2c_gpio_getsda(void *data) | 58 | static int i2c_gpio_getsda(void *data) |
| 54 | { | 59 | { |
| 55 | struct i2c_gpio_private_data *priv = data; | 60 | struct i2c_gpio_private_data *priv = data; |
| 56 | 61 | ||
| 57 | return gpiod_get_value(priv->sda); | 62 | return gpiod_get_value_cansleep(priv->sda); |
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | static int i2c_gpio_getscl(void *data) | 65 | static int i2c_gpio_getscl(void *data) |
| 61 | { | 66 | { |
| 62 | struct i2c_gpio_private_data *priv = data; | 67 | struct i2c_gpio_private_data *priv = data; |
| 63 | 68 | ||
| 64 | return gpiod_get_value(priv->scl); | 69 | return gpiod_get_value_cansleep(priv->scl); |
| 70 | } | ||
| 71 | |||
| 72 | #ifdef CONFIG_I2C_GPIO_FAULT_INJECTOR | ||
| 73 | static struct dentry *i2c_gpio_debug_dir; | ||
| 74 | |||
| 75 | #define setsda(bd, val) ((bd)->setsda((bd)->data, val)) | ||
| 76 | #define setscl(bd, val) ((bd)->setscl((bd)->data, val)) | ||
| 77 | #define getsda(bd) ((bd)->getsda((bd)->data)) | ||
| 78 | #define getscl(bd) ((bd)->getscl((bd)->data)) | ||
| 79 | |||
| 80 | #define WIRE_ATTRIBUTE(wire) \ | ||
| 81 | static int fops_##wire##_get(void *data, u64 *val) \ | ||
| 82 | { \ | ||
| 83 | struct i2c_gpio_private_data *priv = data; \ | ||
| 84 | \ | ||
| 85 | i2c_lock_adapter(&priv->adap); \ | ||
| 86 | *val = get##wire(&priv->bit_data); \ | ||
| 87 | i2c_unlock_adapter(&priv->adap); \ | ||
| 88 | return 0; \ | ||
| 89 | } \ | ||
| 90 | static int fops_##wire##_set(void *data, u64 val) \ | ||
| 91 | { \ | ||
| 92 | struct i2c_gpio_private_data *priv = data; \ | ||
| 93 | \ | ||
| 94 | i2c_lock_adapter(&priv->adap); \ | ||
| 95 | set##wire(&priv->bit_data, val); \ | ||
| 96 | i2c_unlock_adapter(&priv->adap); \ | ||
| 97 | return 0; \ | ||
| 98 | } \ | ||
| 99 | DEFINE_DEBUGFS_ATTRIBUTE(fops_##wire, fops_##wire##_get, fops_##wire##_set, "%llu\n") | ||
| 100 | |||
| 101 | WIRE_ATTRIBUTE(scl); | ||
| 102 | WIRE_ATTRIBUTE(sda); | ||
| 103 | |||
| 104 | static int fops_incomplete_transfer_set(void *data, u64 addr) | ||
| 105 | { | ||
| 106 | struct i2c_gpio_private_data *priv = data; | ||
| 107 | struct i2c_algo_bit_data *bit_data = &priv->bit_data; | ||
| 108 | int i, pattern; | ||
| 109 | |||
| 110 | if (addr > 0x7f) | ||
| 111 | return -EINVAL; | ||
| 112 | |||
| 113 | /* ADDR (7 bit) + RD (1 bit) + SDA hi (1 bit) */ | ||
| 114 | pattern = (addr << 2) | 3; | ||
| 115 | |||
| 116 | i2c_lock_adapter(&priv->adap); | ||
| 117 | |||
| 118 | /* START condition */ | ||
| 119 | setsda(bit_data, 0); | ||
| 120 | udelay(bit_data->udelay); | ||
| 121 | |||
| 122 | /* Send ADDR+RD, request ACK, don't send STOP */ | ||
| 123 | for (i = 8; i >= 0; i--) { | ||
| 124 | setscl(bit_data, 0); | ||
| 125 | udelay(bit_data->udelay / 2); | ||
| 126 | setsda(bit_data, (pattern >> i) & 1); | ||
| 127 | udelay((bit_data->udelay + 1) / 2); | ||
| 128 | setscl(bit_data, 1); | ||
| 129 | udelay(bit_data->udelay); | ||
| 130 | } | ||
| 131 | |||
| 132 | i2c_unlock_adapter(&priv->adap); | ||
| 133 | |||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | DEFINE_DEBUGFS_ATTRIBUTE(fops_incomplete_transfer, NULL, fops_incomplete_transfer_set, "%llu\n"); | ||
| 137 | |||
| 138 | static void i2c_gpio_fault_injector_init(struct platform_device *pdev) | ||
| 139 | { | ||
| 140 | struct i2c_gpio_private_data *priv = platform_get_drvdata(pdev); | ||
| 141 | |||
| 142 | /* | ||
| 143 | * If there will be a debugfs-dir per i2c adapter somewhen, put the | ||
| 144 | * 'fault-injector' dir there. Until then, we have a global dir with | ||
| 145 | * all adapters as subdirs. | ||
| 146 | */ | ||
| 147 | if (!i2c_gpio_debug_dir) { | ||
| 148 | i2c_gpio_debug_dir = debugfs_create_dir("i2c-fault-injector", NULL); | ||
| 149 | if (!i2c_gpio_debug_dir) | ||
| 150 | return; | ||
| 151 | } | ||
| 152 | |||
| 153 | priv->debug_dir = debugfs_create_dir(pdev->name, i2c_gpio_debug_dir); | ||
| 154 | if (!priv->debug_dir) | ||
| 155 | return; | ||
| 156 | |||
| 157 | debugfs_create_file_unsafe("scl", 0600, priv->debug_dir, priv, &fops_scl); | ||
| 158 | debugfs_create_file_unsafe("sda", 0600, priv->debug_dir, priv, &fops_sda); | ||
| 159 | debugfs_create_file_unsafe("incomplete_transfer", 0200, priv->debug_dir, | ||
| 160 | priv, &fops_incomplete_transfer); | ||
| 65 | } | 161 | } |
| 66 | 162 | ||
| 163 | static void i2c_gpio_fault_injector_exit(struct platform_device *pdev) | ||
| 164 | { | ||
| 165 | struct i2c_gpio_private_data *priv = platform_get_drvdata(pdev); | ||
| 166 | |||
| 167 | debugfs_remove_recursive(priv->debug_dir); | ||
| 168 | } | ||
| 169 | #else | ||
| 170 | static inline void i2c_gpio_fault_injector_init(struct platform_device *pdev) {} | ||
| 171 | static inline void i2c_gpio_fault_injector_exit(struct platform_device *pdev) {} | ||
| 172 | #endif /* CONFIG_I2C_GPIO_FAULT_INJECTOR*/ | ||
| 173 | |||
| 67 | static void of_i2c_gpio_get_props(struct device_node *np, | 174 | static void of_i2c_gpio_get_props(struct device_node *np, |
| 68 | struct i2c_gpio_platform_data *pdata) | 175 | struct i2c_gpio_platform_data *pdata) |
| 69 | { | 176 | { |
| @@ -179,6 +286,9 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
| 179 | if (IS_ERR(priv->scl)) | 286 | if (IS_ERR(priv->scl)) |
| 180 | return PTR_ERR(priv->scl); | 287 | return PTR_ERR(priv->scl); |
| 181 | 288 | ||
| 289 | if (gpiod_cansleep(priv->sda) || gpiod_cansleep(priv->scl)) | ||
| 290 | dev_warn(dev, "Slow GPIO pins might wreak havoc into I2C/SMBus bus timing"); | ||
| 291 | |||
| 182 | bit_data->setsda = i2c_gpio_setsda_val; | 292 | bit_data->setsda = i2c_gpio_setsda_val; |
| 183 | bit_data->setscl = i2c_gpio_setscl_val; | 293 | bit_data->setscl = i2c_gpio_setscl_val; |
| 184 | 294 | ||
| @@ -228,6 +338,8 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
| 228 | pdata->scl_is_output_only | 338 | pdata->scl_is_output_only |
| 229 | ? ", no clock stretching" : ""); | 339 | ? ", no clock stretching" : ""); |
| 230 | 340 | ||
| 341 | i2c_gpio_fault_injector_init(pdev); | ||
| 342 | |||
| 231 | return 0; | 343 | return 0; |
| 232 | } | 344 | } |
| 233 | 345 | ||
| @@ -236,6 +348,8 @@ static int i2c_gpio_remove(struct platform_device *pdev) | |||
| 236 | struct i2c_gpio_private_data *priv; | 348 | struct i2c_gpio_private_data *priv; |
| 237 | struct i2c_adapter *adap; | 349 | struct i2c_adapter *adap; |
| 238 | 350 | ||
| 351 | i2c_gpio_fault_injector_exit(pdev); | ||
| 352 | |||
| 239 | priv = platform_get_drvdata(pdev); | 353 | priv = platform_get_drvdata(pdev); |
| 240 | adap = &priv->adap; | 354 | adap = &priv->adap; |
| 241 | 355 | ||
diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c index e86801a63120..e6da2c7a9a3e 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c | |||
| @@ -30,6 +30,7 @@ | |||
| 30 | #include <linux/of_device.h> | 30 | #include <linux/of_device.h> |
| 31 | #include <linux/pinctrl/consumer.h> | 31 | #include <linux/pinctrl/consumer.h> |
| 32 | #include <linux/platform_device.h> | 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/pm_runtime.h> | ||
| 33 | #include <linux/sched.h> | 34 | #include <linux/sched.h> |
| 34 | #include <linux/slab.h> | 35 | #include <linux/slab.h> |
| 35 | 36 | ||
| @@ -90,6 +91,8 @@ | |||
| 90 | #define FAST_PLUS_MAX_BITRATE 3400000 | 91 | #define FAST_PLUS_MAX_BITRATE 3400000 |
| 91 | #define HIGHSPEED_MAX_BITRATE 5000000 | 92 | #define HIGHSPEED_MAX_BITRATE 5000000 |
| 92 | 93 | ||
| 94 | #define I2C_PM_TIMEOUT 10 /* ms */ | ||
| 95 | |||
| 93 | enum lpi2c_imx_mode { | 96 | enum lpi2c_imx_mode { |
| 94 | STANDARD, /* 100+Kbps */ | 97 | STANDARD, /* 100+Kbps */ |
| 95 | FAST, /* 400+Kbps */ | 98 | FAST, /* 400+Kbps */ |
| @@ -274,8 +277,8 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx) | |||
| 274 | unsigned int temp; | 277 | unsigned int temp; |
| 275 | int ret; | 278 | int ret; |
| 276 | 279 | ||
| 277 | ret = clk_enable(lpi2c_imx->clk); | 280 | ret = pm_runtime_get_sync(lpi2c_imx->adapter.dev.parent); |
| 278 | if (ret) | 281 | if (ret < 0) |
| 279 | return ret; | 282 | return ret; |
| 280 | 283 | ||
| 281 | temp = MCR_RST; | 284 | temp = MCR_RST; |
| @@ -284,7 +287,7 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx) | |||
| 284 | 287 | ||
| 285 | ret = lpi2c_imx_config(lpi2c_imx); | 288 | ret = lpi2c_imx_config(lpi2c_imx); |
| 286 | if (ret) | 289 | if (ret) |
| 287 | goto clk_disable; | 290 | goto rpm_put; |
| 288 | 291 | ||
| 289 | temp = readl(lpi2c_imx->base + LPI2C_MCR); | 292 | temp = readl(lpi2c_imx->base + LPI2C_MCR); |
| 290 | temp |= MCR_MEN; | 293 | temp |= MCR_MEN; |
| @@ -292,8 +295,9 @@ static int lpi2c_imx_master_enable(struct lpi2c_imx_struct *lpi2c_imx) | |||
| 292 | 295 | ||
| 293 | return 0; | 296 | return 0; |
| 294 | 297 | ||
| 295 | clk_disable: | 298 | rpm_put: |
| 296 | clk_disable(lpi2c_imx->clk); | 299 | pm_runtime_mark_last_busy(lpi2c_imx->adapter.dev.parent); |
| 300 | pm_runtime_put_autosuspend(lpi2c_imx->adapter.dev.parent); | ||
| 297 | 301 | ||
| 298 | return ret; | 302 | return ret; |
| 299 | } | 303 | } |
| @@ -306,7 +310,8 @@ static int lpi2c_imx_master_disable(struct lpi2c_imx_struct *lpi2c_imx) | |||
| 306 | temp &= ~MCR_MEN; | 310 | temp &= ~MCR_MEN; |
| 307 | writel(temp, lpi2c_imx->base + LPI2C_MCR); | 311 | writel(temp, lpi2c_imx->base + LPI2C_MCR); |
| 308 | 312 | ||
| 309 | clk_disable(lpi2c_imx->clk); | 313 | pm_runtime_mark_last_busy(lpi2c_imx->adapter.dev.parent); |
| 314 | pm_runtime_put_autosuspend(lpi2c_imx->adapter.dev.parent); | ||
| 310 | 315 | ||
| 311 | return 0; | 316 | return 0; |
| 312 | } | 317 | } |
| @@ -606,22 +611,31 @@ static int lpi2c_imx_probe(struct platform_device *pdev) | |||
| 606 | return ret; | 611 | return ret; |
| 607 | } | 612 | } |
| 608 | 613 | ||
| 614 | pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); | ||
| 615 | pm_runtime_use_autosuspend(&pdev->dev); | ||
| 616 | pm_runtime_get_noresume(&pdev->dev); | ||
| 617 | pm_runtime_set_active(&pdev->dev); | ||
| 618 | pm_runtime_enable(&pdev->dev); | ||
| 619 | |||
| 609 | temp = readl(lpi2c_imx->base + LPI2C_PARAM); | 620 | temp = readl(lpi2c_imx->base + LPI2C_PARAM); |
| 610 | lpi2c_imx->txfifosize = 1 << (temp & 0x0f); | 621 | lpi2c_imx->txfifosize = 1 << (temp & 0x0f); |
| 611 | lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f); | 622 | lpi2c_imx->rxfifosize = 1 << ((temp >> 8) & 0x0f); |
| 612 | 623 | ||
| 613 | clk_disable(lpi2c_imx->clk); | ||
| 614 | |||
| 615 | ret = i2c_add_adapter(&lpi2c_imx->adapter); | 624 | ret = i2c_add_adapter(&lpi2c_imx->adapter); |
| 616 | if (ret) | 625 | if (ret) |
| 617 | goto clk_unprepare; | 626 | goto rpm_disable; |
| 627 | |||
| 628 | pm_runtime_mark_last_busy(&pdev->dev); | ||
| 629 | pm_runtime_put_autosuspend(&pdev->dev); | ||
| 618 | 630 | ||
| 619 | dev_info(&lpi2c_imx->adapter.dev, "LPI2C adapter registered\n"); | 631 | dev_info(&lpi2c_imx->adapter.dev, "LPI2C adapter registered\n"); |
| 620 | 632 | ||
| 621 | return 0; | 633 | return 0; |
| 622 | 634 | ||
| 623 | clk_unprepare: | 635 | rpm_disable: |
| 624 | clk_unprepare(lpi2c_imx->clk); | 636 | pm_runtime_put(&pdev->dev); |
| 637 | pm_runtime_disable(&pdev->dev); | ||
| 638 | pm_runtime_dont_use_autosuspend(&pdev->dev); | ||
| 625 | 639 | ||
| 626 | return ret; | 640 | return ret; |
| 627 | } | 641 | } |
| @@ -632,28 +646,48 @@ static int lpi2c_imx_remove(struct platform_device *pdev) | |||
| 632 | 646 | ||
| 633 | i2c_del_adapter(&lpi2c_imx->adapter); | 647 | i2c_del_adapter(&lpi2c_imx->adapter); |
| 634 | 648 | ||
| 635 | clk_unprepare(lpi2c_imx->clk); | 649 | pm_runtime_disable(&pdev->dev); |
| 650 | pm_runtime_dont_use_autosuspend(&pdev->dev); | ||
| 636 | 651 | ||
| 637 | return 0; | 652 | return 0; |
| 638 | } | 653 | } |
| 639 | 654 | ||
| 640 | #ifdef CONFIG_PM_SLEEP | 655 | #ifdef CONFIG_PM_SLEEP |
| 641 | static int lpi2c_imx_suspend(struct device *dev) | 656 | static int lpi2c_runtime_suspend(struct device *dev) |
| 642 | { | 657 | { |
| 658 | struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev); | ||
| 659 | |||
| 660 | clk_disable_unprepare(lpi2c_imx->clk); | ||
| 643 | pinctrl_pm_select_sleep_state(dev); | 661 | pinctrl_pm_select_sleep_state(dev); |
| 644 | 662 | ||
| 645 | return 0; | 663 | return 0; |
| 646 | } | 664 | } |
| 647 | 665 | ||
| 648 | static int lpi2c_imx_resume(struct device *dev) | 666 | static int lpi2c_runtime_resume(struct device *dev) |
| 649 | { | 667 | { |
| 668 | struct lpi2c_imx_struct *lpi2c_imx = dev_get_drvdata(dev); | ||
| 669 | int ret; | ||
| 670 | |||
| 650 | pinctrl_pm_select_default_state(dev); | 671 | pinctrl_pm_select_default_state(dev); |
| 672 | ret = clk_prepare_enable(lpi2c_imx->clk); | ||
| 673 | if (ret) { | ||
| 674 | dev_err(dev, "failed to enable I2C clock, ret=%d\n", ret); | ||
| 675 | return ret; | ||
| 676 | } | ||
| 651 | 677 | ||
| 652 | return 0; | 678 | return 0; |
| 653 | } | 679 | } |
| 654 | #endif | ||
| 655 | 680 | ||
| 656 | static SIMPLE_DEV_PM_OPS(imx_lpi2c_pm, lpi2c_imx_suspend, lpi2c_imx_resume); | 681 | static const struct dev_pm_ops lpi2c_pm_ops = { |
| 682 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, | ||
| 683 | pm_runtime_force_resume) | ||
| 684 | SET_RUNTIME_PM_OPS(lpi2c_runtime_suspend, | ||
| 685 | lpi2c_runtime_resume, NULL) | ||
| 686 | }; | ||
| 687 | #define IMX_LPI2C_PM (&lpi2c_pm_ops) | ||
| 688 | #else | ||
| 689 | #define IMX_LPI2C_PM NULL | ||
| 690 | #endif | ||
| 657 | 691 | ||
| 658 | static struct platform_driver lpi2c_imx_driver = { | 692 | static struct platform_driver lpi2c_imx_driver = { |
| 659 | .probe = lpi2c_imx_probe, | 693 | .probe = lpi2c_imx_probe, |
| @@ -661,7 +695,7 @@ static struct platform_driver lpi2c_imx_driver = { | |||
| 661 | .driver = { | 695 | .driver = { |
| 662 | .name = DRIVER_NAME, | 696 | .name = DRIVER_NAME, |
| 663 | .of_match_table = lpi2c_imx_of_match, | 697 | .of_match_table = lpi2c_imx_of_match, |
| 664 | .pm = &imx_lpi2c_pm, | 698 | .pm = IMX_LPI2C_PM, |
| 665 | }, | 699 | }, |
| 666 | }; | 700 | }; |
| 667 | 701 | ||
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index f96830ffd9f1..999557729ad2 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c | |||
| @@ -37,6 +37,7 @@ | |||
| 37 | #include <linux/dmapool.h> | 37 | #include <linux/dmapool.h> |
| 38 | #include <linux/err.h> | 38 | #include <linux/err.h> |
| 39 | #include <linux/errno.h> | 39 | #include <linux/errno.h> |
| 40 | #include <linux/gpio/consumer.h> | ||
| 40 | #include <linux/i2c.h> | 41 | #include <linux/i2c.h> |
| 41 | #include <linux/init.h> | 42 | #include <linux/init.h> |
| 42 | #include <linux/interrupt.h> | 43 | #include <linux/interrupt.h> |
| @@ -46,7 +47,6 @@ | |||
| 46 | #include <linux/of.h> | 47 | #include <linux/of.h> |
| 47 | #include <linux/of_device.h> | 48 | #include <linux/of_device.h> |
| 48 | #include <linux/of_dma.h> | 49 | #include <linux/of_dma.h> |
| 49 | #include <linux/of_gpio.h> | ||
| 50 | #include <linux/pinctrl/consumer.h> | 50 | #include <linux/pinctrl/consumer.h> |
| 51 | #include <linux/platform_data/i2c-imx.h> | 51 | #include <linux/platform_data/i2c-imx.h> |
| 52 | #include <linux/platform_device.h> | 52 | #include <linux/platform_device.h> |
| @@ -1006,26 +1006,26 @@ static int i2c_imx_init_recovery_info(struct imx_i2c_struct *i2c_imx, | |||
| 1006 | PINCTRL_STATE_DEFAULT); | 1006 | PINCTRL_STATE_DEFAULT); |
| 1007 | i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, | 1007 | i2c_imx->pinctrl_pins_gpio = pinctrl_lookup_state(i2c_imx->pinctrl, |
| 1008 | "gpio"); | 1008 | "gpio"); |
| 1009 | rinfo->sda_gpio = of_get_named_gpio(pdev->dev.of_node, "sda-gpios", 0); | 1009 | rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); |
| 1010 | rinfo->scl_gpio = of_get_named_gpio(pdev->dev.of_node, "scl-gpios", 0); | 1010 | rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", GPIOD_OUT_HIGH); |
| 1011 | 1011 | ||
| 1012 | if (rinfo->sda_gpio == -EPROBE_DEFER || | 1012 | if (PTR_ERR(rinfo->sda_gpiod) == -EPROBE_DEFER || |
| 1013 | rinfo->scl_gpio == -EPROBE_DEFER) { | 1013 | PTR_ERR(rinfo->scl_gpiod) == -EPROBE_DEFER) { |
| 1014 | return -EPROBE_DEFER; | 1014 | return -EPROBE_DEFER; |
| 1015 | } else if (!gpio_is_valid(rinfo->sda_gpio) || | 1015 | } else if (IS_ERR(rinfo->sda_gpiod) || |
| 1016 | !gpio_is_valid(rinfo->scl_gpio) || | 1016 | IS_ERR(rinfo->scl_gpiod) || |
| 1017 | IS_ERR(i2c_imx->pinctrl_pins_default) || | 1017 | IS_ERR(i2c_imx->pinctrl_pins_default) || |
| 1018 | IS_ERR(i2c_imx->pinctrl_pins_gpio)) { | 1018 | IS_ERR(i2c_imx->pinctrl_pins_gpio)) { |
| 1019 | dev_dbg(&pdev->dev, "recovery information incomplete\n"); | 1019 | dev_dbg(&pdev->dev, "recovery information incomplete\n"); |
| 1020 | return 0; | 1020 | return 0; |
| 1021 | } | 1021 | } |
| 1022 | 1022 | ||
| 1023 | dev_dbg(&pdev->dev, "using scl-gpio %d and sda-gpio %d for recovery\n", | 1023 | dev_dbg(&pdev->dev, "using scl%s for recovery\n", |
| 1024 | rinfo->scl_gpio, rinfo->sda_gpio); | 1024 | rinfo->sda_gpiod ? ",sda" : ""); |
| 1025 | 1025 | ||
| 1026 | rinfo->prepare_recovery = i2c_imx_prepare_recovery; | 1026 | rinfo->prepare_recovery = i2c_imx_prepare_recovery; |
| 1027 | rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; | 1027 | rinfo->unprepare_recovery = i2c_imx_unprepare_recovery; |
| 1028 | rinfo->recover_bus = i2c_generic_gpio_recovery; | 1028 | rinfo->recover_bus = i2c_generic_scl_recovery; |
| 1029 | i2c_imx->adapter.bus_recovery_info = rinfo; | 1029 | i2c_imx->adapter.bus_recovery_info = rinfo; |
| 1030 | 1030 | ||
| 1031 | return 0; | 1031 | return 0; |
diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c index b51adffa4841..0d1c3ec8cb40 100644 --- a/drivers/i2c/busses/i2c-ismt.c +++ b/drivers/i2c/busses/i2c-ismt.c | |||
| @@ -172,7 +172,7 @@ struct ismt_priv { | |||
| 172 | dma_addr_t io_rng_dma; /* descriptor HW base addr */ | 172 | dma_addr_t io_rng_dma; /* descriptor HW base addr */ |
| 173 | u8 head; /* ring buffer head pointer */ | 173 | u8 head; /* ring buffer head pointer */ |
| 174 | struct completion cmp; /* interrupt completion */ | 174 | struct completion cmp; /* interrupt completion */ |
| 175 | u8 dma_buffer[I2C_SMBUS_BLOCK_MAX + 1]; /* temp R/W data buffer */ | 175 | u8 buffer[I2C_SMBUS_BLOCK_MAX + 16]; /* temp R/W data buffer */ |
| 176 | }; | 176 | }; |
| 177 | 177 | ||
| 178 | /** | 178 | /** |
| @@ -320,10 +320,12 @@ static int ismt_process_desc(const struct ismt_desc *desc, | |||
| 320 | struct ismt_priv *priv, int size, | 320 | struct ismt_priv *priv, int size, |
| 321 | char read_write) | 321 | char read_write) |
| 322 | { | 322 | { |
| 323 | u8 *dma_buffer = priv->dma_buffer; | 323 | u8 *dma_buffer = PTR_ALIGN(&priv->buffer[0], 16); |
| 324 | 324 | ||
| 325 | dev_dbg(&priv->pci_dev->dev, "Processing completed descriptor\n"); | 325 | dev_dbg(&priv->pci_dev->dev, "Processing completed descriptor\n"); |
| 326 | __ismt_desc_dump(&priv->pci_dev->dev, desc); | 326 | __ismt_desc_dump(&priv->pci_dev->dev, desc); |
| 327 | ismt_gen_reg_dump(priv); | ||
| 328 | ismt_mstr_reg_dump(priv); | ||
| 327 | 329 | ||
| 328 | if (desc->status & ISMT_DESC_SCS) { | 330 | if (desc->status & ISMT_DESC_SCS) { |
| 329 | if (read_write == I2C_SMBUS_WRITE && | 331 | if (read_write == I2C_SMBUS_WRITE && |
| @@ -393,11 +395,12 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 393 | struct ismt_desc *desc; | 395 | struct ismt_desc *desc; |
| 394 | struct ismt_priv *priv = i2c_get_adapdata(adap); | 396 | struct ismt_priv *priv = i2c_get_adapdata(adap); |
| 395 | struct device *dev = &priv->pci_dev->dev; | 397 | struct device *dev = &priv->pci_dev->dev; |
| 398 | u8 *dma_buffer = PTR_ALIGN(&priv->buffer[0], 16); | ||
| 396 | 399 | ||
| 397 | desc = &priv->hw[priv->head]; | 400 | desc = &priv->hw[priv->head]; |
| 398 | 401 | ||
| 399 | /* Initialize the DMA buffer */ | 402 | /* Initialize the DMA buffer */ |
| 400 | memset(priv->dma_buffer, 0, sizeof(priv->dma_buffer)); | 403 | memset(priv->buffer, 0, sizeof(priv->buffer)); |
| 401 | 404 | ||
| 402 | /* Initialize the descriptor */ | 405 | /* Initialize the descriptor */ |
| 403 | memset(desc, 0, sizeof(struct ismt_desc)); | 406 | memset(desc, 0, sizeof(struct ismt_desc)); |
| @@ -446,8 +449,8 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 446 | desc->wr_len_cmd = 2; | 449 | desc->wr_len_cmd = 2; |
| 447 | dma_size = 2; | 450 | dma_size = 2; |
| 448 | dma_direction = DMA_TO_DEVICE; | 451 | dma_direction = DMA_TO_DEVICE; |
| 449 | priv->dma_buffer[0] = command; | 452 | dma_buffer[0] = command; |
| 450 | priv->dma_buffer[1] = data->byte; | 453 | dma_buffer[1] = data->byte; |
| 451 | } else { | 454 | } else { |
| 452 | /* Read Byte */ | 455 | /* Read Byte */ |
| 453 | dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: READ\n"); | 456 | dev_dbg(dev, "I2C_SMBUS_BYTE_DATA: READ\n"); |
| @@ -466,9 +469,9 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 466 | desc->wr_len_cmd = 3; | 469 | desc->wr_len_cmd = 3; |
| 467 | dma_size = 3; | 470 | dma_size = 3; |
| 468 | dma_direction = DMA_TO_DEVICE; | 471 | dma_direction = DMA_TO_DEVICE; |
| 469 | priv->dma_buffer[0] = command; | 472 | dma_buffer[0] = command; |
| 470 | priv->dma_buffer[1] = data->word & 0xff; | 473 | dma_buffer[1] = data->word & 0xff; |
| 471 | priv->dma_buffer[2] = data->word >> 8; | 474 | dma_buffer[2] = data->word >> 8; |
| 472 | } else { | 475 | } else { |
| 473 | /* Read Word */ | 476 | /* Read Word */ |
| 474 | dev_dbg(dev, "I2C_SMBUS_WORD_DATA: READ\n"); | 477 | dev_dbg(dev, "I2C_SMBUS_WORD_DATA: READ\n"); |
| @@ -486,9 +489,9 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 486 | desc->rd_len = 2; | 489 | desc->rd_len = 2; |
| 487 | dma_size = 3; | 490 | dma_size = 3; |
| 488 | dma_direction = DMA_BIDIRECTIONAL; | 491 | dma_direction = DMA_BIDIRECTIONAL; |
| 489 | priv->dma_buffer[0] = command; | 492 | dma_buffer[0] = command; |
| 490 | priv->dma_buffer[1] = data->word & 0xff; | 493 | dma_buffer[1] = data->word & 0xff; |
| 491 | priv->dma_buffer[2] = data->word >> 8; | 494 | dma_buffer[2] = data->word >> 8; |
| 492 | break; | 495 | break; |
| 493 | 496 | ||
| 494 | case I2C_SMBUS_BLOCK_DATA: | 497 | case I2C_SMBUS_BLOCK_DATA: |
| @@ -499,8 +502,8 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 499 | dma_direction = DMA_TO_DEVICE; | 502 | dma_direction = DMA_TO_DEVICE; |
| 500 | desc->wr_len_cmd = dma_size; | 503 | desc->wr_len_cmd = dma_size; |
| 501 | desc->control |= ISMT_DESC_BLK; | 504 | desc->control |= ISMT_DESC_BLK; |
| 502 | priv->dma_buffer[0] = command; | 505 | dma_buffer[0] = command; |
| 503 | memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1); | 506 | memcpy(&dma_buffer[1], &data->block[1], dma_size - 1); |
| 504 | } else { | 507 | } else { |
| 505 | /* Block Read */ | 508 | /* Block Read */ |
| 506 | dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: READ\n"); | 509 | dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: READ\n"); |
| @@ -527,8 +530,8 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 527 | dma_direction = DMA_TO_DEVICE; | 530 | dma_direction = DMA_TO_DEVICE; |
| 528 | desc->wr_len_cmd = dma_size; | 531 | desc->wr_len_cmd = dma_size; |
| 529 | desc->control |= ISMT_DESC_I2C; | 532 | desc->control |= ISMT_DESC_I2C; |
| 530 | priv->dma_buffer[0] = command; | 533 | dma_buffer[0] = command; |
| 531 | memcpy(&priv->dma_buffer[1], &data->block[1], dma_size - 1); | 534 | memcpy(&dma_buffer[1], &data->block[1], dma_size - 1); |
| 532 | } else { | 535 | } else { |
| 533 | /* i2c Block Read */ | 536 | /* i2c Block Read */ |
| 534 | dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA: READ\n"); | 537 | dev_dbg(dev, "I2C_SMBUS_I2C_BLOCK_DATA: READ\n"); |
| @@ -557,23 +560,22 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr, | |||
| 557 | if (dma_size != 0) { | 560 | if (dma_size != 0) { |
| 558 | dev_dbg(dev, " dev=%p\n", dev); | 561 | dev_dbg(dev, " dev=%p\n", dev); |
| 559 | dev_dbg(dev, " data=%p\n", data); | 562 | dev_dbg(dev, " data=%p\n", data); |
| 560 | dev_dbg(dev, " dma_buffer=%p\n", priv->dma_buffer); | 563 | dev_dbg(dev, " dma_buffer=%p\n", dma_buffer); |
| 561 | dev_dbg(dev, " dma_size=%d\n", dma_size); | 564 | dev_dbg(dev, " dma_size=%d\n", dma_size); |
| 562 | dev_dbg(dev, " dma_direction=%d\n", dma_direction); | 565 | dev_dbg(dev, " dma_direction=%d\n", dma_direction); |
| 563 | 566 | ||
| 564 | dma_addr = dma_map_single(dev, | 567 | dma_addr = dma_map_single(dev, |
| 565 | priv->dma_buffer, | 568 | dma_buffer, |
| 566 | dma_size, | 569 | dma_size, |
| 567 | dma_direction); | 570 | dma_direction); |
| 568 | 571 | ||
| 569 | if (dma_mapping_error(dev, dma_addr)) { | 572 | if (dma_mapping_error(dev, dma_addr)) { |
| 570 | dev_err(dev, "Error in mapping dma buffer %p\n", | 573 | dev_err(dev, "Error in mapping dma buffer %p\n", |
| 571 | priv->dma_buffer); | 574 | dma_buffer); |
| 572 | return -EIO; | 575 | return -EIO; |
| 573 | } | 576 | } |
| 574 | 577 | ||
| 575 | dev_dbg(dev, " dma_addr = 0x%016llX\n", | 578 | dev_dbg(dev, " dma_addr = %pad\n", &dma_addr); |
| 576 | (unsigned long long)dma_addr); | ||
| 577 | 579 | ||
| 578 | desc->dptr_low = lower_32_bits(dma_addr); | 580 | desc->dptr_low = lower_32_bits(dma_addr); |
| 579 | desc->dptr_high = upper_32_bits(dma_addr); | 581 | desc->dptr_high = upper_32_bits(dma_addr); |
diff --git a/drivers/i2c/busses/i2c-meson.c b/drivers/i2c/busses/i2c-meson.c index 88d15b92ec35..90f5d0407d73 100644 --- a/drivers/i2c/busses/i2c-meson.c +++ b/drivers/i2c/busses/i2c-meson.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/kernel.h> | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
| 18 | #include <linux/of.h> | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_device.h> | ||
| 19 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
| 20 | #include <linux/types.h> | 21 | #include <linux/types.h> |
| 21 | 22 | ||
| @@ -57,6 +58,10 @@ enum { | |||
| 57 | STATE_WRITE, | 58 | STATE_WRITE, |
| 58 | }; | 59 | }; |
| 59 | 60 | ||
| 61 | struct meson_i2c_data { | ||
| 62 | unsigned char div_factor; | ||
| 63 | }; | ||
| 64 | |||
| 60 | /** | 65 | /** |
| 61 | * struct meson_i2c - Meson I2C device private data | 66 | * struct meson_i2c - Meson I2C device private data |
| 62 | * | 67 | * |
| @@ -64,7 +69,6 @@ enum { | |||
| 64 | * @dev: Pointer to device structure | 69 | * @dev: Pointer to device structure |
| 65 | * @regs: Base address of the device memory mapped registers | 70 | * @regs: Base address of the device memory mapped registers |
| 66 | * @clk: Pointer to clock structure | 71 | * @clk: Pointer to clock structure |
| 67 | * @irq: IRQ number | ||
| 68 | * @msg: Pointer to the current I2C message | 72 | * @msg: Pointer to the current I2C message |
| 69 | * @state: Current state in the driver state machine | 73 | * @state: Current state in the driver state machine |
| 70 | * @last: Flag set for the last message in the transfer | 74 | * @last: Flag set for the last message in the transfer |
| @@ -75,6 +79,7 @@ enum { | |||
| 75 | * @done: Completion used to wait for transfer termination | 79 | * @done: Completion used to wait for transfer termination |
| 76 | * @tokens: Sequence of tokens to be written to the device | 80 | * @tokens: Sequence of tokens to be written to the device |
| 77 | * @num_tokens: Number of tokens | 81 | * @num_tokens: Number of tokens |
| 82 | * @data: Pointer to the controlller's platform data | ||
| 78 | */ | 83 | */ |
| 79 | struct meson_i2c { | 84 | struct meson_i2c { |
| 80 | struct i2c_adapter adap; | 85 | struct i2c_adapter adap; |
| @@ -93,6 +98,8 @@ struct meson_i2c { | |||
| 93 | struct completion done; | 98 | struct completion done; |
| 94 | u32 tokens[2]; | 99 | u32 tokens[2]; |
| 95 | int num_tokens; | 100 | int num_tokens; |
| 101 | |||
| 102 | const struct meson_i2c_data *data; | ||
| 96 | }; | 103 | }; |
| 97 | 104 | ||
| 98 | static void meson_i2c_set_mask(struct meson_i2c *i2c, int reg, u32 mask, | 105 | static void meson_i2c_set_mask(struct meson_i2c *i2c, int reg, u32 mask, |
| @@ -128,7 +135,7 @@ static void meson_i2c_set_clk_div(struct meson_i2c *i2c, unsigned int freq) | |||
| 128 | unsigned long clk_rate = clk_get_rate(i2c->clk); | 135 | unsigned long clk_rate = clk_get_rate(i2c->clk); |
| 129 | unsigned int div; | 136 | unsigned int div; |
| 130 | 137 | ||
| 131 | div = DIV_ROUND_UP(clk_rate, freq * 4); | 138 | div = DIV_ROUND_UP(clk_rate, freq * i2c->data->div_factor); |
| 132 | 139 | ||
| 133 | /* clock divider has 12 bits */ | 140 | /* clock divider has 12 bits */ |
| 134 | if (div >= (1 << 12)) { | 141 | if (div >= (1 << 12)) { |
| @@ -376,6 +383,9 @@ static int meson_i2c_probe(struct platform_device *pdev) | |||
| 376 | spin_lock_init(&i2c->lock); | 383 | spin_lock_init(&i2c->lock); |
| 377 | init_completion(&i2c->done); | 384 | init_completion(&i2c->done); |
| 378 | 385 | ||
| 386 | i2c->data = (const struct meson_i2c_data *) | ||
| 387 | of_device_get_match_data(&pdev->dev); | ||
| 388 | |||
| 379 | i2c->clk = devm_clk_get(&pdev->dev, NULL); | 389 | i2c->clk = devm_clk_get(&pdev->dev, NULL); |
| 380 | if (IS_ERR(i2c->clk)) { | 390 | if (IS_ERR(i2c->clk)) { |
| 381 | dev_err(&pdev->dev, "can't get device clock\n"); | 391 | dev_err(&pdev->dev, "can't get device clock\n"); |
| @@ -440,11 +450,25 @@ static int meson_i2c_remove(struct platform_device *pdev) | |||
| 440 | return 0; | 450 | return 0; |
| 441 | } | 451 | } |
| 442 | 452 | ||
| 453 | static const struct meson_i2c_data i2c_meson6_data = { | ||
| 454 | .div_factor = 4, | ||
| 455 | }; | ||
| 456 | |||
| 457 | static const struct meson_i2c_data i2c_gxbb_data = { | ||
| 458 | .div_factor = 4, | ||
| 459 | }; | ||
| 460 | |||
| 461 | static const struct meson_i2c_data i2c_axg_data = { | ||
| 462 | .div_factor = 3, | ||
| 463 | }; | ||
| 464 | |||
| 443 | static const struct of_device_id meson_i2c_match[] = { | 465 | static const struct of_device_id meson_i2c_match[] = { |
| 444 | { .compatible = "amlogic,meson6-i2c" }, | 466 | { .compatible = "amlogic,meson6-i2c", .data = &i2c_meson6_data }, |
| 445 | { .compatible = "amlogic,meson-gxbb-i2c" }, | 467 | { .compatible = "amlogic,meson-gxbb-i2c", .data = &i2c_gxbb_data }, |
| 446 | { }, | 468 | { .compatible = "amlogic,meson-axg-i2c", .data = &i2c_axg_data }, |
| 469 | {}, | ||
| 447 | }; | 470 | }; |
| 471 | |||
| 448 | MODULE_DEVICE_TABLE(of, meson_i2c_match); | 472 | MODULE_DEVICE_TABLE(of, meson_i2c_match); |
| 449 | 473 | ||
| 450 | static struct platform_driver meson_i2c_driver = { | 474 | static struct platform_driver meson_i2c_driver = { |
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c index 950a9d74f54d..d94f05c8b8b7 100644 --- a/drivers/i2c/busses/i2c-mpc.c +++ b/drivers/i2c/busses/i2c-mpc.c | |||
| @@ -78,9 +78,7 @@ struct mpc_i2c_divider { | |||
| 78 | }; | 78 | }; |
| 79 | 79 | ||
| 80 | struct mpc_i2c_data { | 80 | struct mpc_i2c_data { |
| 81 | void (*setup)(struct device_node *node, struct mpc_i2c *i2c, | 81 | void (*setup)(struct device_node *node, struct mpc_i2c *i2c, u32 clock); |
| 82 | u32 clock, u32 prescaler); | ||
| 83 | u32 prescaler; | ||
| 84 | }; | 82 | }; |
| 85 | 83 | ||
| 86 | static inline void writeccr(struct mpc_i2c *i2c, u32 x) | 84 | static inline void writeccr(struct mpc_i2c *i2c, u32 x) |
| @@ -201,7 +199,7 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { | |||
| 201 | }; | 199 | }; |
| 202 | 200 | ||
| 203 | static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, | 201 | static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, |
| 204 | int prescaler, u32 *real_clk) | 202 | u32 *real_clk) |
| 205 | { | 203 | { |
| 206 | const struct mpc_i2c_divider *div = NULL; | 204 | const struct mpc_i2c_divider *div = NULL; |
| 207 | unsigned int pvr = mfspr(SPRN_PVR); | 205 | unsigned int pvr = mfspr(SPRN_PVR); |
| @@ -236,7 +234,7 @@ static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, | |||
| 236 | 234 | ||
| 237 | static void mpc_i2c_setup_52xx(struct device_node *node, | 235 | static void mpc_i2c_setup_52xx(struct device_node *node, |
| 238 | struct mpc_i2c *i2c, | 236 | struct mpc_i2c *i2c, |
| 239 | u32 clock, u32 prescaler) | 237 | u32 clock) |
| 240 | { | 238 | { |
| 241 | int ret, fdr; | 239 | int ret, fdr; |
| 242 | 240 | ||
| @@ -246,7 +244,7 @@ static void mpc_i2c_setup_52xx(struct device_node *node, | |||
| 246 | return; | 244 | return; |
| 247 | } | 245 | } |
| 248 | 246 | ||
| 249 | ret = mpc_i2c_get_fdr_52xx(node, clock, prescaler, &i2c->real_clk); | 247 | ret = mpc_i2c_get_fdr_52xx(node, clock, &i2c->real_clk); |
| 250 | fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ | 248 | fdr = (ret >= 0) ? ret : 0x3f; /* backward compatibility */ |
| 251 | 249 | ||
| 252 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); | 250 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); |
| @@ -258,7 +256,7 @@ static void mpc_i2c_setup_52xx(struct device_node *node, | |||
| 258 | #else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ | 256 | #else /* !(CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x) */ |
| 259 | static void mpc_i2c_setup_52xx(struct device_node *node, | 257 | static void mpc_i2c_setup_52xx(struct device_node *node, |
| 260 | struct mpc_i2c *i2c, | 258 | struct mpc_i2c *i2c, |
| 261 | u32 clock, u32 prescaler) | 259 | u32 clock) |
| 262 | { | 260 | { |
| 263 | } | 261 | } |
| 264 | #endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ | 262 | #endif /* CONFIG_PPC_MPC52xx || CONFIG_PPC_MPC512x */ |
| @@ -266,7 +264,7 @@ static void mpc_i2c_setup_52xx(struct device_node *node, | |||
| 266 | #ifdef CONFIG_PPC_MPC512x | 264 | #ifdef CONFIG_PPC_MPC512x |
| 267 | static void mpc_i2c_setup_512x(struct device_node *node, | 265 | static void mpc_i2c_setup_512x(struct device_node *node, |
| 268 | struct mpc_i2c *i2c, | 266 | struct mpc_i2c *i2c, |
| 269 | u32 clock, u32 prescaler) | 267 | u32 clock) |
| 270 | { | 268 | { |
| 271 | struct device_node *node_ctrl; | 269 | struct device_node *node_ctrl; |
| 272 | void __iomem *ctrl; | 270 | void __iomem *ctrl; |
| @@ -289,12 +287,12 @@ static void mpc_i2c_setup_512x(struct device_node *node, | |||
| 289 | } | 287 | } |
| 290 | 288 | ||
| 291 | /* The clock setup for the 52xx works also fine for the 512x */ | 289 | /* The clock setup for the 52xx works also fine for the 512x */ |
| 292 | mpc_i2c_setup_52xx(node, i2c, clock, prescaler); | 290 | mpc_i2c_setup_52xx(node, i2c, clock); |
| 293 | } | 291 | } |
| 294 | #else /* CONFIG_PPC_MPC512x */ | 292 | #else /* CONFIG_PPC_MPC512x */ |
| 295 | static void mpc_i2c_setup_512x(struct device_node *node, | 293 | static void mpc_i2c_setup_512x(struct device_node *node, |
| 296 | struct mpc_i2c *i2c, | 294 | struct mpc_i2c *i2c, |
| 297 | u32 clock, u32 prescaler) | 295 | u32 clock) |
| 298 | { | 296 | { |
| 299 | } | 297 | } |
| 300 | #endif /* CONFIG_PPC_MPC512x */ | 298 | #endif /* CONFIG_PPC_MPC512x */ |
| @@ -332,14 +330,18 @@ static u32 mpc_i2c_get_sec_cfg_8xxx(void) | |||
| 332 | if (prop) { | 330 | if (prop) { |
| 333 | /* | 331 | /* |
| 334 | * Map and check POR Device Status Register 2 | 332 | * Map and check POR Device Status Register 2 |
| 335 | * (PORDEVSR2) at 0xE0014 | 333 | * (PORDEVSR2) at 0xE0014. Note than while MPC8533 |
| 334 | * and MPC8544 indicate SEC frequency ratio | ||
| 335 | * configuration as bit 26 in PORDEVSR2, other MPC8xxx | ||
| 336 | * parts may store it differently or may not have it | ||
| 337 | * at all. | ||
| 336 | */ | 338 | */ |
| 337 | reg = ioremap(get_immrbase() + *prop + 0x14, 0x4); | 339 | reg = ioremap(get_immrbase() + *prop + 0x14, 0x4); |
| 338 | if (!reg) | 340 | if (!reg) |
| 339 | printk(KERN_ERR | 341 | printk(KERN_ERR |
| 340 | "Error: couldn't map PORDEVSR2\n"); | 342 | "Error: couldn't map PORDEVSR2\n"); |
| 341 | else | 343 | else |
| 342 | val = in_be32(reg) & 0x00000080; /* sec-cfg */ | 344 | val = in_be32(reg) & 0x00000020; /* sec-cfg */ |
| 343 | iounmap(reg); | 345 | iounmap(reg); |
| 344 | } | 346 | } |
| 345 | } | 347 | } |
| @@ -350,7 +352,11 @@ static u32 mpc_i2c_get_sec_cfg_8xxx(void) | |||
| 350 | 352 | ||
| 351 | static u32 mpc_i2c_get_prescaler_8xxx(void) | 353 | static u32 mpc_i2c_get_prescaler_8xxx(void) |
| 352 | { | 354 | { |
| 353 | /* mpc83xx and mpc82xx all have prescaler 1 */ | 355 | /* |
| 356 | * According to the AN2919 all MPC824x have prescaler 1, while MPC83xx | ||
| 357 | * may have prescaler 1, 2, or 3, depending on the power-on | ||
| 358 | * configuration. | ||
| 359 | */ | ||
| 354 | u32 prescaler = 1; | 360 | u32 prescaler = 1; |
| 355 | 361 | ||
| 356 | /* mpc85xx */ | 362 | /* mpc85xx */ |
| @@ -367,6 +373,10 @@ static u32 mpc_i2c_get_prescaler_8xxx(void) | |||
| 367 | || (SVR_SOC_VER(svr) == SVR_8610)) | 373 | || (SVR_SOC_VER(svr) == SVR_8610)) |
| 368 | /* the above 85xx SoCs have prescaler 1 */ | 374 | /* the above 85xx SoCs have prescaler 1 */ |
| 369 | prescaler = 1; | 375 | prescaler = 1; |
| 376 | else if ((SVR_SOC_VER(svr) == SVR_8533) | ||
| 377 | || (SVR_SOC_VER(svr) == SVR_8544)) | ||
| 378 | /* the above 85xx SoCs have prescaler 3 or 2 */ | ||
| 379 | prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2; | ||
| 370 | else | 380 | else |
| 371 | /* all the other 85xx have prescaler 2 */ | 381 | /* all the other 85xx have prescaler 2 */ |
| 372 | prescaler = 2; | 382 | prescaler = 2; |
| @@ -376,9 +386,10 @@ static u32 mpc_i2c_get_prescaler_8xxx(void) | |||
| 376 | } | 386 | } |
| 377 | 387 | ||
| 378 | static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, | 388 | static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, |
| 379 | u32 prescaler, u32 *real_clk) | 389 | u32 *real_clk) |
| 380 | { | 390 | { |
| 381 | const struct mpc_i2c_divider *div = NULL; | 391 | const struct mpc_i2c_divider *div = NULL; |
| 392 | u32 prescaler = mpc_i2c_get_prescaler_8xxx(); | ||
| 382 | u32 divider; | 393 | u32 divider; |
| 383 | int i; | 394 | int i; |
| 384 | 395 | ||
| @@ -388,12 +399,6 @@ static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, | |||
| 388 | return -EINVAL; | 399 | return -EINVAL; |
| 389 | } | 400 | } |
| 390 | 401 | ||
| 391 | /* Determine proper divider value */ | ||
| 392 | if (of_device_is_compatible(node, "fsl,mpc8544-i2c")) | ||
| 393 | prescaler = mpc_i2c_get_sec_cfg_8xxx() ? 3 : 2; | ||
| 394 | if (!prescaler) | ||
| 395 | prescaler = mpc_i2c_get_prescaler_8xxx(); | ||
| 396 | |||
| 397 | divider = fsl_get_sys_freq() / clock / prescaler; | 402 | divider = fsl_get_sys_freq() / clock / prescaler; |
| 398 | 403 | ||
| 399 | pr_debug("I2C: src_clock=%d clock=%d divider=%d\n", | 404 | pr_debug("I2C: src_clock=%d clock=%d divider=%d\n", |
| @@ -415,7 +420,7 @@ static int mpc_i2c_get_fdr_8xxx(struct device_node *node, u32 clock, | |||
| 415 | 420 | ||
| 416 | static void mpc_i2c_setup_8xxx(struct device_node *node, | 421 | static void mpc_i2c_setup_8xxx(struct device_node *node, |
| 417 | struct mpc_i2c *i2c, | 422 | struct mpc_i2c *i2c, |
| 418 | u32 clock, u32 prescaler) | 423 | u32 clock) |
| 419 | { | 424 | { |
| 420 | int ret, fdr; | 425 | int ret, fdr; |
| 421 | 426 | ||
| @@ -426,7 +431,7 @@ static void mpc_i2c_setup_8xxx(struct device_node *node, | |||
| 426 | return; | 431 | return; |
| 427 | } | 432 | } |
| 428 | 433 | ||
| 429 | ret = mpc_i2c_get_fdr_8xxx(node, clock, prescaler, &i2c->real_clk); | 434 | ret = mpc_i2c_get_fdr_8xxx(node, clock, &i2c->real_clk); |
| 430 | fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ | 435 | fdr = (ret >= 0) ? ret : 0x1031; /* backward compatibility */ |
| 431 | 436 | ||
| 432 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); | 437 | writeb(fdr & 0xff, i2c->base + MPC_I2C_FDR); |
| @@ -440,7 +445,7 @@ static void mpc_i2c_setup_8xxx(struct device_node *node, | |||
| 440 | #else /* !CONFIG_FSL_SOC */ | 445 | #else /* !CONFIG_FSL_SOC */ |
| 441 | static void mpc_i2c_setup_8xxx(struct device_node *node, | 446 | static void mpc_i2c_setup_8xxx(struct device_node *node, |
| 442 | struct mpc_i2c *i2c, | 447 | struct mpc_i2c *i2c, |
| 443 | u32 clock, u32 prescaler) | 448 | u32 clock) |
| 444 | { | 449 | { |
| 445 | } | 450 | } |
| 446 | #endif /* CONFIG_FSL_SOC */ | 451 | #endif /* CONFIG_FSL_SOC */ |
| @@ -711,11 +716,11 @@ static int fsl_i2c_probe(struct platform_device *op) | |||
| 711 | 716 | ||
| 712 | if (match->data) { | 717 | if (match->data) { |
| 713 | const struct mpc_i2c_data *data = match->data; | 718 | const struct mpc_i2c_data *data = match->data; |
| 714 | data->setup(op->dev.of_node, i2c, clock, data->prescaler); | 719 | data->setup(op->dev.of_node, i2c, clock); |
| 715 | } else { | 720 | } else { |
| 716 | /* Backwards compatibility */ | 721 | /* Backwards compatibility */ |
| 717 | if (of_get_property(op->dev.of_node, "dfsrr", NULL)) | 722 | if (of_get_property(op->dev.of_node, "dfsrr", NULL)) |
| 718 | mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock, 0); | 723 | mpc_i2c_setup_8xxx(op->dev.of_node, i2c, clock); |
| 719 | } | 724 | } |
| 720 | 725 | ||
| 721 | prop = of_get_property(op->dev.of_node, "fsl,timeout", &plen); | 726 | prop = of_get_property(op->dev.of_node, "fsl,timeout", &plen); |
| @@ -813,12 +818,10 @@ static const struct mpc_i2c_data mpc_i2c_data_8313 = { | |||
| 813 | 818 | ||
| 814 | static const struct mpc_i2c_data mpc_i2c_data_8543 = { | 819 | static const struct mpc_i2c_data mpc_i2c_data_8543 = { |
| 815 | .setup = mpc_i2c_setup_8xxx, | 820 | .setup = mpc_i2c_setup_8xxx, |
| 816 | .prescaler = 2, | ||
| 817 | }; | 821 | }; |
| 818 | 822 | ||
| 819 | static const struct mpc_i2c_data mpc_i2c_data_8544 = { | 823 | static const struct mpc_i2c_data mpc_i2c_data_8544 = { |
| 820 | .setup = mpc_i2c_setup_8xxx, | 824 | .setup = mpc_i2c_setup_8xxx, |
| 821 | .prescaler = 3, | ||
| 822 | }; | 825 | }; |
| 823 | 826 | ||
| 824 | static const struct of_device_id mpc_i2c_of_match[] = { | 827 | static const struct of_device_id mpc_i2c_of_match[] = { |
diff --git a/drivers/i2c/busses/i2c-mt65xx.c b/drivers/i2c/busses/i2c-mt65xx.c index 09d288ce0ddb..cf23a746cc17 100644 --- a/drivers/i2c/busses/i2c-mt65xx.c +++ b/drivers/i2c/busses/i2c-mt65xx.c | |||
| @@ -61,6 +61,7 @@ | |||
| 61 | #define I2C_DMA_HARD_RST 0x0002 | 61 | #define I2C_DMA_HARD_RST 0x0002 |
| 62 | #define I2C_DMA_4G_MODE 0x0001 | 62 | #define I2C_DMA_4G_MODE 0x0001 |
| 63 | 63 | ||
| 64 | #define I2C_DEFAULT_CLK_DIV 5 | ||
| 64 | #define I2C_DEFAULT_SPEED 100000 /* hz */ | 65 | #define I2C_DEFAULT_SPEED 100000 /* hz */ |
| 65 | #define MAX_FS_MODE_SPEED 400000 | 66 | #define MAX_FS_MODE_SPEED 400000 |
| 66 | #define MAX_HS_MODE_SPEED 3400000 | 67 | #define MAX_HS_MODE_SPEED 3400000 |
| @@ -127,6 +128,7 @@ enum I2C_REGS_OFFSET { | |||
| 127 | OFFSET_DEBUGSTAT = 0x64, | 128 | OFFSET_DEBUGSTAT = 0x64, |
| 128 | OFFSET_DEBUGCTRL = 0x68, | 129 | OFFSET_DEBUGCTRL = 0x68, |
| 129 | OFFSET_TRANSFER_LEN_AUX = 0x6c, | 130 | OFFSET_TRANSFER_LEN_AUX = 0x6c, |
| 131 | OFFSET_CLOCK_DIV = 0x70, | ||
| 130 | }; | 132 | }; |
| 131 | 133 | ||
| 132 | struct mtk_i2c_compatible { | 134 | struct mtk_i2c_compatible { |
| @@ -136,6 +138,7 @@ struct mtk_i2c_compatible { | |||
| 136 | unsigned char auto_restart: 1; | 138 | unsigned char auto_restart: 1; |
| 137 | unsigned char aux_len_reg: 1; | 139 | unsigned char aux_len_reg: 1; |
| 138 | unsigned char support_33bits: 1; | 140 | unsigned char support_33bits: 1; |
| 141 | unsigned char timing_adjust: 1; | ||
| 139 | }; | 142 | }; |
| 140 | 143 | ||
| 141 | struct mtk_i2c { | 144 | struct mtk_i2c { |
| @@ -176,6 +179,15 @@ static const struct i2c_adapter_quirks mt7622_i2c_quirks = { | |||
| 176 | .max_num_msgs = 255, | 179 | .max_num_msgs = 255, |
| 177 | }; | 180 | }; |
| 178 | 181 | ||
| 182 | static const struct mtk_i2c_compatible mt2712_compat = { | ||
| 183 | .pmic_i2c = 0, | ||
| 184 | .dcm = 1, | ||
| 185 | .auto_restart = 1, | ||
| 186 | .aux_len_reg = 1, | ||
| 187 | .support_33bits = 1, | ||
| 188 | .timing_adjust = 1, | ||
| 189 | }; | ||
| 190 | |||
| 179 | static const struct mtk_i2c_compatible mt6577_compat = { | 191 | static const struct mtk_i2c_compatible mt6577_compat = { |
| 180 | .quirks = &mt6577_i2c_quirks, | 192 | .quirks = &mt6577_i2c_quirks, |
| 181 | .pmic_i2c = 0, | 193 | .pmic_i2c = 0, |
| @@ -183,6 +195,7 @@ static const struct mtk_i2c_compatible mt6577_compat = { | |||
| 183 | .auto_restart = 0, | 195 | .auto_restart = 0, |
| 184 | .aux_len_reg = 0, | 196 | .aux_len_reg = 0, |
| 185 | .support_33bits = 0, | 197 | .support_33bits = 0, |
| 198 | .timing_adjust = 0, | ||
| 186 | }; | 199 | }; |
| 187 | 200 | ||
| 188 | static const struct mtk_i2c_compatible mt6589_compat = { | 201 | static const struct mtk_i2c_compatible mt6589_compat = { |
| @@ -192,6 +205,7 @@ static const struct mtk_i2c_compatible mt6589_compat = { | |||
| 192 | .auto_restart = 0, | 205 | .auto_restart = 0, |
| 193 | .aux_len_reg = 0, | 206 | .aux_len_reg = 0, |
| 194 | .support_33bits = 0, | 207 | .support_33bits = 0, |
| 208 | .timing_adjust = 0, | ||
| 195 | }; | 209 | }; |
| 196 | 210 | ||
| 197 | static const struct mtk_i2c_compatible mt7622_compat = { | 211 | static const struct mtk_i2c_compatible mt7622_compat = { |
| @@ -201,6 +215,7 @@ static const struct mtk_i2c_compatible mt7622_compat = { | |||
| 201 | .auto_restart = 1, | 215 | .auto_restart = 1, |
| 202 | .aux_len_reg = 1, | 216 | .aux_len_reg = 1, |
| 203 | .support_33bits = 0, | 217 | .support_33bits = 0, |
| 218 | .timing_adjust = 0, | ||
| 204 | }; | 219 | }; |
| 205 | 220 | ||
| 206 | static const struct mtk_i2c_compatible mt8173_compat = { | 221 | static const struct mtk_i2c_compatible mt8173_compat = { |
| @@ -209,9 +224,11 @@ static const struct mtk_i2c_compatible mt8173_compat = { | |||
| 209 | .auto_restart = 1, | 224 | .auto_restart = 1, |
| 210 | .aux_len_reg = 1, | 225 | .aux_len_reg = 1, |
| 211 | .support_33bits = 1, | 226 | .support_33bits = 1, |
| 227 | .timing_adjust = 0, | ||
| 212 | }; | 228 | }; |
| 213 | 229 | ||
| 214 | static const struct of_device_id mtk_i2c_of_match[] = { | 230 | static const struct of_device_id mtk_i2c_of_match[] = { |
| 231 | { .compatible = "mediatek,mt2712-i2c", .data = &mt2712_compat }, | ||
| 215 | { .compatible = "mediatek,mt6577-i2c", .data = &mt6577_compat }, | 232 | { .compatible = "mediatek,mt6577-i2c", .data = &mt6577_compat }, |
| 216 | { .compatible = "mediatek,mt6589-i2c", .data = &mt6589_compat }, | 233 | { .compatible = "mediatek,mt6589-i2c", .data = &mt6589_compat }, |
| 217 | { .compatible = "mediatek,mt7622-i2c", .data = &mt7622_compat }, | 234 | { .compatible = "mediatek,mt7622-i2c", .data = &mt7622_compat }, |
| @@ -271,6 +288,9 @@ static void mtk_i2c_init_hw(struct mtk_i2c *i2c) | |||
| 271 | if (i2c->dev_comp->dcm) | 288 | if (i2c->dev_comp->dcm) |
| 272 | writew(I2C_DCM_DISABLE, i2c->base + OFFSET_DCM_EN); | 289 | writew(I2C_DCM_DISABLE, i2c->base + OFFSET_DCM_EN); |
| 273 | 290 | ||
| 291 | if (i2c->dev_comp->timing_adjust) | ||
| 292 | writew(I2C_DEFAULT_CLK_DIV - 1, i2c->base + OFFSET_CLOCK_DIV); | ||
| 293 | |||
| 274 | writew(i2c->timing_reg, i2c->base + OFFSET_TIMING); | 294 | writew(i2c->timing_reg, i2c->base + OFFSET_TIMING); |
| 275 | writew(i2c->high_speed_reg, i2c->base + OFFSET_HS); | 295 | writew(i2c->high_speed_reg, i2c->base + OFFSET_HS); |
| 276 | 296 | ||
| @@ -725,10 +745,6 @@ static int mtk_i2c_probe(struct platform_device *pdev) | |||
| 725 | if (!i2c) | 745 | if (!i2c) |
| 726 | return -ENOMEM; | 746 | return -ENOMEM; |
| 727 | 747 | ||
| 728 | ret = mtk_i2c_parse_dt(pdev->dev.of_node, i2c); | ||
| 729 | if (ret) | ||
| 730 | return -EINVAL; | ||
| 731 | |||
| 732 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 748 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 733 | i2c->base = devm_ioremap_resource(&pdev->dev, res); | 749 | i2c->base = devm_ioremap_resource(&pdev->dev, res); |
| 734 | if (IS_ERR(i2c->base)) | 750 | if (IS_ERR(i2c->base)) |
| @@ -759,6 +775,13 @@ static int mtk_i2c_probe(struct platform_device *pdev) | |||
| 759 | i2c->adap.timeout = 2 * HZ; | 775 | i2c->adap.timeout = 2 * HZ; |
| 760 | i2c->adap.retries = 1; | 776 | i2c->adap.retries = 1; |
| 761 | 777 | ||
| 778 | ret = mtk_i2c_parse_dt(pdev->dev.of_node, i2c); | ||
| 779 | if (ret) | ||
| 780 | return -EINVAL; | ||
| 781 | |||
| 782 | if (i2c->dev_comp->timing_adjust) | ||
| 783 | i2c->clk_src_div *= I2C_DEFAULT_CLK_DIV; | ||
| 784 | |||
| 762 | if (i2c->have_pmic && !i2c->dev_comp->pmic_i2c) | 785 | if (i2c->have_pmic && !i2c->dev_comp->pmic_i2c) |
| 763 | return -EINVAL; | 786 | return -EINVAL; |
| 764 | 787 | ||
| @@ -838,10 +861,19 @@ static int mtk_i2c_remove(struct platform_device *pdev) | |||
| 838 | #ifdef CONFIG_PM_SLEEP | 861 | #ifdef CONFIG_PM_SLEEP |
| 839 | static int mtk_i2c_resume(struct device *dev) | 862 | static int mtk_i2c_resume(struct device *dev) |
| 840 | { | 863 | { |
| 864 | int ret; | ||
| 841 | struct mtk_i2c *i2c = dev_get_drvdata(dev); | 865 | struct mtk_i2c *i2c = dev_get_drvdata(dev); |
| 842 | 866 | ||
| 867 | ret = mtk_i2c_clock_enable(i2c); | ||
| 868 | if (ret) { | ||
| 869 | dev_err(dev, "clock enable failed!\n"); | ||
| 870 | return ret; | ||
| 871 | } | ||
| 872 | |||
| 843 | mtk_i2c_init_hw(i2c); | 873 | mtk_i2c_init_hw(i2c); |
| 844 | 874 | ||
| 875 | mtk_i2c_clock_disable(i2c); | ||
| 876 | |||
| 845 | return 0; | 877 | return 0; |
| 846 | } | 878 | } |
| 847 | #endif | 879 | #endif |
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c index a832c45276a4..440fe4a96e68 100644 --- a/drivers/i2c/busses/i2c-mv64xxx.c +++ b/drivers/i2c/busses/i2c-mv64xxx.c | |||
| @@ -135,6 +135,7 @@ struct mv64xxx_i2c_data { | |||
| 135 | u32 freq_m; | 135 | u32 freq_m; |
| 136 | u32 freq_n; | 136 | u32 freq_n; |
| 137 | struct clk *clk; | 137 | struct clk *clk; |
| 138 | struct clk *reg_clk; | ||
| 138 | wait_queue_head_t waitq; | 139 | wait_queue_head_t waitq; |
| 139 | spinlock_t lock; | 140 | spinlock_t lock; |
| 140 | struct i2c_msg *msg; | 141 | struct i2c_msg *msg; |
| @@ -894,13 +895,20 @@ mv64xxx_i2c_probe(struct platform_device *pd) | |||
| 894 | init_waitqueue_head(&drv_data->waitq); | 895 | init_waitqueue_head(&drv_data->waitq); |
| 895 | spin_lock_init(&drv_data->lock); | 896 | spin_lock_init(&drv_data->lock); |
| 896 | 897 | ||
| 897 | /* Not all platforms have a clk */ | 898 | /* Not all platforms have clocks */ |
| 898 | drv_data->clk = devm_clk_get(&pd->dev, NULL); | 899 | drv_data->clk = devm_clk_get(&pd->dev, NULL); |
| 899 | if (IS_ERR(drv_data->clk) && PTR_ERR(drv_data->clk) == -EPROBE_DEFER) | 900 | if (IS_ERR(drv_data->clk) && PTR_ERR(drv_data->clk) == -EPROBE_DEFER) |
| 900 | return -EPROBE_DEFER; | 901 | return -EPROBE_DEFER; |
| 901 | if (!IS_ERR(drv_data->clk)) | 902 | if (!IS_ERR(drv_data->clk)) |
| 902 | clk_prepare_enable(drv_data->clk); | 903 | clk_prepare_enable(drv_data->clk); |
| 903 | 904 | ||
| 905 | drv_data->reg_clk = devm_clk_get(&pd->dev, "reg"); | ||
| 906 | if (IS_ERR(drv_data->reg_clk) && | ||
| 907 | PTR_ERR(drv_data->reg_clk) == -EPROBE_DEFER) | ||
| 908 | return -EPROBE_DEFER; | ||
| 909 | if (!IS_ERR(drv_data->reg_clk)) | ||
| 910 | clk_prepare_enable(drv_data->reg_clk); | ||
| 911 | |||
| 904 | drv_data->irq = platform_get_irq(pd, 0); | 912 | drv_data->irq = platform_get_irq(pd, 0); |
| 905 | 913 | ||
| 906 | if (pdata) { | 914 | if (pdata) { |
| @@ -950,9 +958,8 @@ exit_free_irq: | |||
| 950 | exit_reset: | 958 | exit_reset: |
| 951 | reset_control_assert(drv_data->rstc); | 959 | reset_control_assert(drv_data->rstc); |
| 952 | exit_clk: | 960 | exit_clk: |
| 953 | /* Not all platforms have a clk */ | 961 | clk_disable_unprepare(drv_data->reg_clk); |
| 954 | if (!IS_ERR(drv_data->clk)) | 962 | clk_disable_unprepare(drv_data->clk); |
| 955 | clk_disable_unprepare(drv_data->clk); | ||
| 956 | 963 | ||
| 957 | return rc; | 964 | return rc; |
| 958 | } | 965 | } |
| @@ -965,9 +972,8 @@ mv64xxx_i2c_remove(struct platform_device *dev) | |||
| 965 | i2c_del_adapter(&drv_data->adapter); | 972 | i2c_del_adapter(&drv_data->adapter); |
| 966 | free_irq(drv_data->irq, drv_data); | 973 | free_irq(drv_data->irq, drv_data); |
| 967 | reset_control_assert(drv_data->rstc); | 974 | reset_control_assert(drv_data->rstc); |
| 968 | /* Not all platforms have a clk */ | 975 | clk_disable_unprepare(drv_data->reg_clk); |
| 969 | if (!IS_ERR(drv_data->clk)) | 976 | clk_disable_unprepare(drv_data->clk); |
| 970 | clk_disable_unprepare(drv_data->clk); | ||
| 971 | 977 | ||
| 972 | return 0; | 978 | return 0; |
| 973 | } | 979 | } |
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c index d4e8f1954f23..e617bd600794 100644 --- a/drivers/i2c/busses/i2c-mxs.c +++ b/drivers/i2c/busses/i2c-mxs.c | |||
| @@ -181,7 +181,7 @@ static int mxs_i2c_dma_setup_xfer(struct i2c_adapter *adap, | |||
| 181 | struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); | 181 | struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); |
| 182 | 182 | ||
| 183 | if (msg->flags & I2C_M_RD) { | 183 | if (msg->flags & I2C_M_RD) { |
| 184 | i2c->dma_read = 1; | 184 | i2c->dma_read = true; |
| 185 | i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_READ; | 185 | i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_READ; |
| 186 | 186 | ||
| 187 | /* | 187 | /* |
| @@ -239,7 +239,7 @@ static int mxs_i2c_dma_setup_xfer(struct i2c_adapter *adap, | |||
| 239 | goto read_init_dma_fail; | 239 | goto read_init_dma_fail; |
| 240 | } | 240 | } |
| 241 | } else { | 241 | } else { |
| 242 | i2c->dma_read = 0; | 242 | i2c->dma_read = false; |
| 243 | i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_WRITE; | 243 | i2c->addr_data = (msg->addr << 1) | I2C_SMBUS_WRITE; |
| 244 | 244 | ||
| 245 | /* | 245 | /* |
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 15d764afec3b..4159ebcec2bb 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c | |||
| @@ -62,7 +62,7 @@ | |||
| 62 | #define MIE (1 << 3) /* master if enable */ | 62 | #define MIE (1 << 3) /* master if enable */ |
| 63 | #define TSBE (1 << 2) | 63 | #define TSBE (1 << 2) |
| 64 | #define FSB (1 << 1) /* force stop bit */ | 64 | #define FSB (1 << 1) /* force stop bit */ |
| 65 | #define ESG (1 << 0) /* en startbit gen */ | 65 | #define ESG (1 << 0) /* enable start bit gen */ |
| 66 | 66 | ||
| 67 | /* ICSSR (also for ICSIER) */ | 67 | /* ICSSR (also for ICSIER) */ |
| 68 | #define GCAR (1 << 6) /* general call received */ | 68 | #define GCAR (1 << 6) /* general call received */ |
| @@ -132,6 +132,7 @@ struct rcar_i2c_priv { | |||
| 132 | int pos; | 132 | int pos; |
| 133 | u32 icccr; | 133 | u32 icccr; |
| 134 | u32 flags; | 134 | u32 flags; |
| 135 | u8 recovery_icmcr; /* protected by adapter lock */ | ||
| 135 | enum rcar_i2c_type devtype; | 136 | enum rcar_i2c_type devtype; |
| 136 | struct i2c_client *slave; | 137 | struct i2c_client *slave; |
| 137 | 138 | ||
| @@ -158,6 +159,46 @@ static u32 rcar_i2c_read(struct rcar_i2c_priv *priv, int reg) | |||
| 158 | return readl(priv->io + reg); | 159 | return readl(priv->io + reg); |
| 159 | } | 160 | } |
| 160 | 161 | ||
| 162 | static int rcar_i2c_get_scl(struct i2c_adapter *adap) | ||
| 163 | { | ||
| 164 | struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); | ||
| 165 | |||
| 166 | return !!(rcar_i2c_read(priv, ICMCR) & FSCL); | ||
| 167 | |||
| 168 | }; | ||
| 169 | |||
| 170 | static void rcar_i2c_set_scl(struct i2c_adapter *adap, int val) | ||
| 171 | { | ||
| 172 | struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); | ||
| 173 | |||
| 174 | if (val) | ||
| 175 | priv->recovery_icmcr |= FSCL; | ||
| 176 | else | ||
| 177 | priv->recovery_icmcr &= ~FSCL; | ||
| 178 | |||
| 179 | rcar_i2c_write(priv, ICMCR, priv->recovery_icmcr); | ||
| 180 | }; | ||
| 181 | |||
| 182 | /* No get_sda, because the HW only reports its bus free logic, not SDA itself */ | ||
| 183 | |||
| 184 | static void rcar_i2c_set_sda(struct i2c_adapter *adap, int val) | ||
| 185 | { | ||
| 186 | struct rcar_i2c_priv *priv = i2c_get_adapdata(adap); | ||
| 187 | |||
| 188 | if (val) | ||
| 189 | priv->recovery_icmcr |= FSDA; | ||
| 190 | else | ||
| 191 | priv->recovery_icmcr &= ~FSDA; | ||
| 192 | |||
| 193 | rcar_i2c_write(priv, ICMCR, priv->recovery_icmcr); | ||
| 194 | }; | ||
| 195 | |||
| 196 | static struct i2c_bus_recovery_info rcar_i2c_bri = { | ||
| 197 | .get_scl = rcar_i2c_get_scl, | ||
| 198 | .set_scl = rcar_i2c_set_scl, | ||
| 199 | .set_sda = rcar_i2c_set_sda, | ||
| 200 | .recover_bus = i2c_generic_scl_recovery, | ||
| 201 | }; | ||
| 161 | static void rcar_i2c_init(struct rcar_i2c_priv *priv) | 202 | static void rcar_i2c_init(struct rcar_i2c_priv *priv) |
| 162 | { | 203 | { |
| 163 | /* reset master mode */ | 204 | /* reset master mode */ |
| @@ -170,7 +211,7 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv) | |||
| 170 | 211 | ||
| 171 | static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) | 212 | static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) |
| 172 | { | 213 | { |
| 173 | int i; | 214 | int i, ret; |
| 174 | 215 | ||
| 175 | for (i = 0; i < LOOP_TIMEOUT; i++) { | 216 | for (i = 0; i < LOOP_TIMEOUT; i++) { |
| 176 | /* make sure that bus is not busy */ | 217 | /* make sure that bus is not busy */ |
| @@ -179,7 +220,15 @@ static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) | |||
| 179 | udelay(1); | 220 | udelay(1); |
| 180 | } | 221 | } |
| 181 | 222 | ||
| 182 | return -EBUSY; | 223 | /* Waiting did not help, try to recover */ |
| 224 | priv->recovery_icmcr = MDBS | OBPC | FSDA | FSCL; | ||
| 225 | ret = i2c_recover_bus(&priv->adap); | ||
| 226 | |||
| 227 | /* No failure when recovering, so check bus busy bit again */ | ||
| 228 | if (ret == 0) | ||
| 229 | ret = (rcar_i2c_read(priv, ICMCR) & FSDA) ? -EBUSY : 0; | ||
| 230 | |||
| 231 | return ret; | ||
| 183 | } | 232 | } |
| 184 | 233 | ||
| 185 | static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timings *t) | 234 | static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv, struct i2c_timings *t) |
| @@ -282,7 +331,7 @@ static void rcar_i2c_prepare_msg(struct rcar_i2c_priv *priv) | |||
| 282 | 331 | ||
| 283 | rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); | 332 | rcar_i2c_write(priv, ICMAR, (priv->msg->addr << 1) | read); |
| 284 | /* | 333 | /* |
| 285 | * We don't have a testcase but the HW engineers say that the write order | 334 | * We don't have a test case but the HW engineers say that the write order |
| 286 | * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since | 335 | * of ICMSR and ICMCR depends on whether we issue START or REP_START. Since |
| 287 | * it didn't cause a drawback for me, let's rather be safe than sorry. | 336 | * it didn't cause a drawback for me, let's rather be safe than sorry. |
| 288 | */ | 337 | */ |
| @@ -359,7 +408,7 @@ static void rcar_i2c_dma(struct rcar_i2c_priv *priv) | |||
| 359 | int len; | 408 | int len; |
| 360 | 409 | ||
| 361 | /* Do not use DMA if it's not available or for messages < 8 bytes */ | 410 | /* Do not use DMA if it's not available or for messages < 8 bytes */ |
| 362 | if (IS_ERR(chan) || msg->len < 8) | 411 | if (IS_ERR(chan) || msg->len < 8 || !(msg->flags & I2C_M_DMA_SAFE)) |
| 363 | return; | 412 | return; |
| 364 | 413 | ||
| 365 | if (read) { | 414 | if (read) { |
| @@ -440,7 +489,7 @@ static void rcar_i2c_irq_send(struct rcar_i2c_priv *priv, u32 msr) | |||
| 440 | 489 | ||
| 441 | /* | 490 | /* |
| 442 | * Try to use DMA to transmit the rest of the data if | 491 | * Try to use DMA to transmit the rest of the data if |
| 443 | * address transfer pashe just finished. | 492 | * address transfer phase just finished. |
| 444 | */ | 493 | */ |
| 445 | if (msr & MAT) | 494 | if (msr & MAT) |
| 446 | rcar_i2c_dma(priv); | 495 | rcar_i2c_dma(priv); |
| @@ -851,6 +900,7 @@ static int rcar_i2c_probe(struct platform_device *pdev) | |||
| 851 | adap->retries = 3; | 900 | adap->retries = 3; |
| 852 | adap->dev.parent = dev; | 901 | adap->dev.parent = dev; |
| 853 | adap->dev.of_node = dev->of_node; | 902 | adap->dev.of_node = dev->of_node; |
| 903 | adap->bus_recovery_info = &rcar_i2c_bri; | ||
| 854 | i2c_set_adapdata(adap, priv); | 904 | i2c_set_adapdata(adap, priv); |
| 855 | strlcpy(adap->name, pdev->name, sizeof(adap->name)); | 905 | strlcpy(adap->name, pdev->name, sizeof(adap->name)); |
| 856 | 906 | ||
diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c index fe234578380a..e1a18d989f83 100644 --- a/drivers/i2c/busses/i2c-rk3x.c +++ b/drivers/i2c/busses/i2c-rk3x.c | |||
| @@ -161,6 +161,7 @@ enum rk3x_i2c_state { | |||
| 161 | }; | 161 | }; |
| 162 | 162 | ||
| 163 | /** | 163 | /** |
| 164 | * struct rk3x_i2c_soc_data: | ||
| 164 | * @grf_offset: offset inside the grf regmap for setting the i2c type | 165 | * @grf_offset: offset inside the grf regmap for setting the i2c type |
| 165 | * @calc_timings: Callback function for i2c timing information calculated | 166 | * @calc_timings: Callback function for i2c timing information calculated |
| 166 | */ | 167 | */ |
| @@ -194,7 +195,7 @@ struct rk3x_i2c_soc_data { | |||
| 194 | struct rk3x_i2c { | 195 | struct rk3x_i2c { |
| 195 | struct i2c_adapter adap; | 196 | struct i2c_adapter adap; |
| 196 | struct device *dev; | 197 | struct device *dev; |
| 197 | struct rk3x_i2c_soc_data *soc_data; | 198 | const struct rk3x_i2c_soc_data *soc_data; |
| 198 | 199 | ||
| 199 | /* Hardware resources */ | 200 | /* Hardware resources */ |
| 200 | void __iomem *regs; | 201 | void __iomem *regs; |
| @@ -1164,27 +1165,27 @@ static const struct rk3x_i2c_soc_data rk3399_soc_data = { | |||
| 1164 | static const struct of_device_id rk3x_i2c_match[] = { | 1165 | static const struct of_device_id rk3x_i2c_match[] = { |
| 1165 | { | 1166 | { |
| 1166 | .compatible = "rockchip,rv1108-i2c", | 1167 | .compatible = "rockchip,rv1108-i2c", |
| 1167 | .data = (void *)&rv1108_soc_data | 1168 | .data = &rv1108_soc_data |
| 1168 | }, | 1169 | }, |
| 1169 | { | 1170 | { |
| 1170 | .compatible = "rockchip,rk3066-i2c", | 1171 | .compatible = "rockchip,rk3066-i2c", |
| 1171 | .data = (void *)&rk3066_soc_data | 1172 | .data = &rk3066_soc_data |
| 1172 | }, | 1173 | }, |
| 1173 | { | 1174 | { |
| 1174 | .compatible = "rockchip,rk3188-i2c", | 1175 | .compatible = "rockchip,rk3188-i2c", |
| 1175 | .data = (void *)&rk3188_soc_data | 1176 | .data = &rk3188_soc_data |
| 1176 | }, | 1177 | }, |
| 1177 | { | 1178 | { |
| 1178 | .compatible = "rockchip,rk3228-i2c", | 1179 | .compatible = "rockchip,rk3228-i2c", |
| 1179 | .data = (void *)&rk3228_soc_data | 1180 | .data = &rk3228_soc_data |
| 1180 | }, | 1181 | }, |
| 1181 | { | 1182 | { |
| 1182 | .compatible = "rockchip,rk3288-i2c", | 1183 | .compatible = "rockchip,rk3288-i2c", |
| 1183 | .data = (void *)&rk3288_soc_data | 1184 | .data = &rk3288_soc_data |
| 1184 | }, | 1185 | }, |
| 1185 | { | 1186 | { |
| 1186 | .compatible = "rockchip,rk3399-i2c", | 1187 | .compatible = "rockchip,rk3399-i2c", |
| 1187 | .data = (void *)&rk3399_soc_data | 1188 | .data = &rk3399_soc_data |
| 1188 | }, | 1189 | }, |
| 1189 | {}, | 1190 | {}, |
| 1190 | }; | 1191 | }; |
| @@ -1207,7 +1208,7 @@ static int rk3x_i2c_probe(struct platform_device *pdev) | |||
| 1207 | return -ENOMEM; | 1208 | return -ENOMEM; |
| 1208 | 1209 | ||
| 1209 | match = of_match_node(rk3x_i2c_match, np); | 1210 | match = of_match_node(rk3x_i2c_match, np); |
| 1210 | i2c->soc_data = (struct rk3x_i2c_soc_data *)match->data; | 1211 | i2c->soc_data = match->data; |
| 1211 | 1212 | ||
| 1212 | /* use common interface to get I2C timing properties */ | 1213 | /* use common interface to get I2C timing properties */ |
| 1213 | i2c_parse_fw_timings(&pdev->dev, &i2c->t, true); | 1214 | i2c_parse_fw_timings(&pdev->dev, &i2c->t, true); |
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c index c03acdf71397..d856bc211715 100644 --- a/drivers/i2c/busses/i2c-sh_mobile.c +++ b/drivers/i2c/busses/i2c-sh_mobile.c | |||
| @@ -40,21 +40,21 @@ | |||
| 40 | /* BUS: S A8 ACK P(*) */ | 40 | /* BUS: S A8 ACK P(*) */ |
| 41 | /* IRQ: DTE WAIT */ | 41 | /* IRQ: DTE WAIT */ |
| 42 | /* ICIC: */ | 42 | /* ICIC: */ |
| 43 | /* ICCR: 0x94 0x90 */ | 43 | /* ICCR: 0x94 0x90 */ |
| 44 | /* ICDR: A8 */ | 44 | /* ICDR: A8 */ |
| 45 | /* */ | 45 | /* */ |
| 46 | /* 1 byte transmit */ | 46 | /* 1 byte transmit */ |
| 47 | /* BUS: S A8 ACK D8(1) ACK P(*) */ | 47 | /* BUS: S A8 ACK D8(1) ACK P(*) */ |
| 48 | /* IRQ: DTE WAIT WAIT */ | 48 | /* IRQ: DTE WAIT WAIT */ |
| 49 | /* ICIC: -DTE */ | 49 | /* ICIC: -DTE */ |
| 50 | /* ICCR: 0x94 0x90 */ | 50 | /* ICCR: 0x94 0x90 */ |
| 51 | /* ICDR: A8 D8(1) */ | 51 | /* ICDR: A8 D8(1) */ |
| 52 | /* */ | 52 | /* */ |
| 53 | /* 2 byte transmit */ | 53 | /* 2 byte transmit */ |
| 54 | /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P(*) */ | 54 | /* BUS: S A8 ACK D8(1) ACK D8(2) ACK P(*) */ |
| 55 | /* IRQ: DTE WAIT WAIT WAIT */ | 55 | /* IRQ: DTE WAIT WAIT WAIT */ |
| 56 | /* ICIC: -DTE */ | 56 | /* ICIC: -DTE */ |
| 57 | /* ICCR: 0x94 0x90 */ | 57 | /* ICCR: 0x94 0x90 */ |
| 58 | /* ICDR: A8 D8(1) D8(2) */ | 58 | /* ICDR: A8 D8(1) D8(2) */ |
| 59 | /* */ | 59 | /* */ |
| 60 | /* 3 bytes or more, +---------+ gets repeated */ | 60 | /* 3 bytes or more, +---------+ gets repeated */ |
| @@ -113,7 +113,6 @@ enum sh_mobile_i2c_op { | |||
| 113 | OP_TX_FIRST, | 113 | OP_TX_FIRST, |
| 114 | OP_TX, | 114 | OP_TX, |
| 115 | OP_TX_STOP, | 115 | OP_TX_STOP, |
| 116 | OP_TX_STOP_DATA, | ||
| 117 | OP_TX_TO_RX, | 116 | OP_TX_TO_RX, |
| 118 | OP_RX, | 117 | OP_RX, |
| 119 | OP_RX_STOP, | 118 | OP_RX_STOP, |
| @@ -145,11 +144,12 @@ struct sh_mobile_i2c_data { | |||
| 145 | struct dma_chan *dma_rx; | 144 | struct dma_chan *dma_rx; |
| 146 | struct scatterlist sg; | 145 | struct scatterlist sg; |
| 147 | enum dma_data_direction dma_direction; | 146 | enum dma_data_direction dma_direction; |
| 147 | u8 *dma_buf; | ||
| 148 | }; | 148 | }; |
| 149 | 149 | ||
| 150 | struct sh_mobile_dt_config { | 150 | struct sh_mobile_dt_config { |
| 151 | int clks_per_count; | 151 | int clks_per_count; |
| 152 | void (*setup)(struct sh_mobile_i2c_data *pd); | 152 | int (*setup)(struct sh_mobile_i2c_data *pd); |
| 153 | }; | 153 | }; |
| 154 | 154 | ||
| 155 | #define IIC_FLAG_HAS_ICIC67 (1 << 0) | 155 | #define IIC_FLAG_HAS_ICIC67 (1 << 0) |
| @@ -246,36 +246,10 @@ static u32 sh_mobile_i2c_icch(unsigned long count_khz, u32 tHIGH, u32 tf) | |||
| 246 | return (((count_khz * (tHIGH + tf)) + 5000) / 10000); | 246 | return (((count_khz * (tHIGH + tf)) + 5000) / 10000); |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) | 249 | static int sh_mobile_i2c_check_timing(struct sh_mobile_i2c_data *pd) |
| 250 | { | 250 | { |
| 251 | unsigned long i2c_clk_khz; | 251 | u16 max_val = pd->flags & IIC_FLAG_HAS_ICIC67 ? 0x1ff : 0xff; |
| 252 | u32 tHIGH, tLOW, tf; | ||
| 253 | uint16_t max_val; | ||
| 254 | |||
| 255 | /* Get clock rate after clock is enabled */ | ||
| 256 | clk_prepare_enable(pd->clk); | ||
| 257 | i2c_clk_khz = clk_get_rate(pd->clk) / 1000; | ||
| 258 | clk_disable_unprepare(pd->clk); | ||
| 259 | i2c_clk_khz /= pd->clks_per_count; | ||
| 260 | |||
| 261 | if (pd->bus_speed == STANDARD_MODE) { | ||
| 262 | tLOW = 47; /* tLOW = 4.7 us */ | ||
| 263 | tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ | ||
| 264 | tf = 3; /* tf = 0.3 us */ | ||
| 265 | } else if (pd->bus_speed == FAST_MODE) { | ||
| 266 | tLOW = 13; /* tLOW = 1.3 us */ | ||
| 267 | tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ | ||
| 268 | tf = 3; /* tf = 0.3 us */ | ||
| 269 | } else { | ||
| 270 | dev_err(pd->dev, "unrecognized bus speed %lu Hz\n", | ||
| 271 | pd->bus_speed); | ||
| 272 | return -EINVAL; | ||
| 273 | } | ||
| 274 | |||
| 275 | pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf); | ||
| 276 | pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf); | ||
| 277 | 252 | ||
| 278 | max_val = pd->flags & IIC_FLAG_HAS_ICIC67 ? 0x1ff : 0xff; | ||
| 279 | if (pd->iccl > max_val || pd->icch > max_val) { | 253 | if (pd->iccl > max_val || pd->icch > max_val) { |
| 280 | dev_err(pd->dev, "timing values out of range: L/H=0x%x/0x%x\n", | 254 | dev_err(pd->dev, "timing values out of range: L/H=0x%x/0x%x\n", |
| 281 | pd->iccl, pd->icch); | 255 | pd->iccl, pd->icch); |
| @@ -298,35 +272,43 @@ static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) | |||
| 298 | return 0; | 272 | return 0; |
| 299 | } | 273 | } |
| 300 | 274 | ||
| 301 | static void activate_ch(struct sh_mobile_i2c_data *pd) | 275 | static int sh_mobile_i2c_init(struct sh_mobile_i2c_data *pd) |
| 302 | { | 276 | { |
| 303 | /* Wake up device and enable clock */ | 277 | unsigned long i2c_clk_khz; |
| 304 | pm_runtime_get_sync(pd->dev); | 278 | u32 tHIGH, tLOW, tf; |
| 305 | clk_prepare_enable(pd->clk); | ||
| 306 | 279 | ||
| 307 | /* Enable channel and configure rx ack */ | 280 | i2c_clk_khz = clk_get_rate(pd->clk) / 1000 / pd->clks_per_count; |
| 308 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); | ||
| 309 | 281 | ||
| 310 | /* Mask all interrupts */ | 282 | if (pd->bus_speed == STANDARD_MODE) { |
| 311 | iic_wr(pd, ICIC, 0); | 283 | tLOW = 47; /* tLOW = 4.7 us */ |
| 284 | tHIGH = 40; /* tHD;STA = tHIGH = 4.0 us */ | ||
| 285 | tf = 3; /* tf = 0.3 us */ | ||
| 286 | } else if (pd->bus_speed == FAST_MODE) { | ||
| 287 | tLOW = 13; /* tLOW = 1.3 us */ | ||
| 288 | tHIGH = 6; /* tHD;STA = tHIGH = 0.6 us */ | ||
| 289 | tf = 3; /* tf = 0.3 us */ | ||
| 290 | } else { | ||
| 291 | dev_err(pd->dev, "unrecognized bus speed %lu Hz\n", | ||
| 292 | pd->bus_speed); | ||
| 293 | return -EINVAL; | ||
| 294 | } | ||
| 312 | 295 | ||
| 313 | /* Set the clock */ | 296 | pd->iccl = sh_mobile_i2c_iccl(i2c_clk_khz, tLOW, tf); |
| 314 | iic_wr(pd, ICCL, pd->iccl & 0xff); | 297 | pd->icch = sh_mobile_i2c_icch(i2c_clk_khz, tHIGH, tf); |
| 315 | iic_wr(pd, ICCH, pd->icch & 0xff); | 298 | |
| 299 | return sh_mobile_i2c_check_timing(pd); | ||
| 316 | } | 300 | } |
| 317 | 301 | ||
| 318 | static void deactivate_ch(struct sh_mobile_i2c_data *pd) | 302 | static int sh_mobile_i2c_v2_init(struct sh_mobile_i2c_data *pd) |
| 319 | { | 303 | { |
| 320 | /* Clear/disable interrupts */ | 304 | unsigned long clks_per_cycle; |
| 321 | iic_wr(pd, ICSR, 0); | ||
| 322 | iic_wr(pd, ICIC, 0); | ||
| 323 | 305 | ||
| 324 | /* Disable channel */ | 306 | /* L = 5, H = 4, L + H = 9 */ |
| 325 | iic_set_clr(pd, ICCR, 0, ICCR_ICE); | 307 | clks_per_cycle = clk_get_rate(pd->clk) / pd->bus_speed; |
| 308 | pd->iccl = DIV_ROUND_UP(clks_per_cycle * 5 / 9 - 1, pd->clks_per_count); | ||
| 309 | pd->icch = DIV_ROUND_UP(clks_per_cycle * 4 / 9 - 5, pd->clks_per_count); | ||
| 326 | 310 | ||
| 327 | /* Disable clock and mark device as idle */ | 311 | return sh_mobile_i2c_check_timing(pd); |
| 328 | clk_disable_unprepare(pd->clk); | ||
| 329 | pm_runtime_put_sync(pd->dev); | ||
| 330 | } | 312 | } |
| 331 | 313 | ||
| 332 | static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, | 314 | static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, |
| @@ -350,10 +332,7 @@ static unsigned char i2c_op(struct sh_mobile_i2c_data *pd, | |||
| 350 | case OP_TX: /* write data */ | 332 | case OP_TX: /* write data */ |
| 351 | iic_wr(pd, ICDR, data); | 333 | iic_wr(pd, ICDR, data); |
| 352 | break; | 334 | break; |
| 353 | case OP_TX_STOP_DATA: /* write data and issue a stop afterwards */ | 335 | case OP_TX_STOP: /* issue a stop (or rep_start) */ |
| 354 | iic_wr(pd, ICDR, data); | ||
| 355 | /* fallthrough */ | ||
| 356 | case OP_TX_STOP: /* issue a stop */ | ||
| 357 | iic_wr(pd, ICCR, pd->send_stop ? ICCR_ICE | ICCR_TRS | 336 | iic_wr(pd, ICCR, pd->send_stop ? ICCR_ICE | ICCR_TRS |
| 358 | : ICCR_ICE | ICCR_TRS | ICCR_BBSY); | 337 | : ICCR_ICE | ICCR_TRS | ICCR_BBSY); |
| 359 | break; | 338 | break; |
| @@ -387,11 +366,6 @@ static bool sh_mobile_i2c_is_first_byte(struct sh_mobile_i2c_data *pd) | |||
| 387 | return pd->pos == -1; | 366 | return pd->pos == -1; |
| 388 | } | 367 | } |
| 389 | 368 | ||
| 390 | static bool sh_mobile_i2c_is_last_byte(struct sh_mobile_i2c_data *pd) | ||
| 391 | { | ||
| 392 | return pd->pos == pd->msg->len - 1; | ||
| 393 | } | ||
| 394 | |||
| 395 | static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd, | 369 | static void sh_mobile_i2c_get_data(struct sh_mobile_i2c_data *pd, |
| 396 | unsigned char *buf) | 370 | unsigned char *buf) |
| 397 | { | 371 | { |
| @@ -409,20 +383,12 @@ static int sh_mobile_i2c_isr_tx(struct sh_mobile_i2c_data *pd) | |||
| 409 | unsigned char data; | 383 | unsigned char data; |
| 410 | 384 | ||
| 411 | if (pd->pos == pd->msg->len) { | 385 | if (pd->pos == pd->msg->len) { |
| 412 | /* Send stop if we haven't yet (DMA case) */ | 386 | i2c_op(pd, OP_TX_STOP, 0); |
| 413 | if (pd->send_stop && pd->stop_after_dma) | ||
| 414 | i2c_op(pd, OP_TX_STOP, 0); | ||
| 415 | return 1; | 387 | return 1; |
| 416 | } | 388 | } |
| 417 | 389 | ||
| 418 | sh_mobile_i2c_get_data(pd, &data); | 390 | sh_mobile_i2c_get_data(pd, &data); |
| 419 | 391 | i2c_op(pd, sh_mobile_i2c_is_first_byte(pd) ? OP_TX_FIRST : OP_TX, data); | |
| 420 | if (sh_mobile_i2c_is_last_byte(pd)) | ||
| 421 | i2c_op(pd, OP_TX_STOP_DATA, data); | ||
| 422 | else if (sh_mobile_i2c_is_first_byte(pd)) | ||
| 423 | i2c_op(pd, OP_TX_FIRST, data); | ||
| 424 | else | ||
| 425 | i2c_op(pd, OP_TX, data); | ||
| 426 | 392 | ||
| 427 | pd->pos++; | 393 | pd->pos++; |
| 428 | return 0; | 394 | return 0; |
| @@ -464,8 +430,9 @@ static int sh_mobile_i2c_isr_rx(struct sh_mobile_i2c_data *pd) | |||
| 464 | break; | 430 | break; |
| 465 | } | 431 | } |
| 466 | data = i2c_op(pd, OP_RX_STOP_DATA, 0); | 432 | data = i2c_op(pd, OP_RX_STOP_DATA, 0); |
| 467 | } else | 433 | } else if (real_pos >= 0) { |
| 468 | data = i2c_op(pd, OP_RX, 0); | 434 | data = i2c_op(pd, OP_RX, 0); |
| 435 | } | ||
| 469 | 436 | ||
| 470 | if (real_pos >= 0) | 437 | if (real_pos >= 0) |
| 471 | pd->msg->buf[real_pos] = data; | 438 | pd->msg->buf[real_pos] = data; |
| @@ -548,6 +515,8 @@ static void sh_mobile_i2c_dma_callback(void *data) | |||
| 548 | pd->pos = pd->msg->len; | 515 | pd->pos = pd->msg->len; |
| 549 | pd->stop_after_dma = true; | 516 | pd->stop_after_dma = true; |
| 550 | 517 | ||
| 518 | i2c_release_dma_safe_msg_buf(pd->msg, pd->dma_buf); | ||
| 519 | |||
| 551 | iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE); | 520 | iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE); |
| 552 | } | 521 | } |
| 553 | 522 | ||
| @@ -608,7 +577,7 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd) | |||
| 608 | if (IS_ERR(chan)) | 577 | if (IS_ERR(chan)) |
| 609 | return; | 578 | return; |
| 610 | 579 | ||
| 611 | dma_addr = dma_map_single(chan->device->dev, pd->msg->buf, pd->msg->len, dir); | 580 | dma_addr = dma_map_single(chan->device->dev, pd->dma_buf, pd->msg->len, dir); |
| 612 | if (dma_mapping_error(chan->device->dev, dma_addr)) { | 581 | if (dma_mapping_error(chan->device->dev, dma_addr)) { |
| 613 | dev_dbg(pd->dev, "dma map failed, using PIO\n"); | 582 | dev_dbg(pd->dev, "dma map failed, using PIO\n"); |
| 614 | return; | 583 | return; |
| @@ -651,10 +620,10 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg, | |||
| 651 | 620 | ||
| 652 | if (do_init) { | 621 | if (do_init) { |
| 653 | /* Initialize channel registers */ | 622 | /* Initialize channel registers */ |
| 654 | iic_set_clr(pd, ICCR, 0, ICCR_ICE); | 623 | iic_wr(pd, ICCR, ICCR_SCP); |
| 655 | 624 | ||
| 656 | /* Enable channel and configure rx ack */ | 625 | /* Enable channel and configure rx ack */ |
| 657 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); | 626 | iic_wr(pd, ICCR, ICCR_ICE | ICCR_SCP); |
| 658 | 627 | ||
| 659 | /* Set the clock */ | 628 | /* Set the clock */ |
| 660 | iic_wr(pd, ICCL, pd->iccl & 0xff); | 629 | iic_wr(pd, ICCL, pd->iccl & 0xff); |
| @@ -665,7 +634,8 @@ static int start_ch(struct sh_mobile_i2c_data *pd, struct i2c_msg *usr_msg, | |||
| 665 | pd->pos = -1; | 634 | pd->pos = -1; |
| 666 | pd->sr = 0; | 635 | pd->sr = 0; |
| 667 | 636 | ||
| 668 | if (pd->msg->len > 8) | 637 | pd->dma_buf = i2c_get_dma_safe_msg_buf(pd->msg, 8); |
| 638 | if (pd->dma_buf) | ||
| 669 | sh_mobile_i2c_xfer_dma(pd); | 639 | sh_mobile_i2c_xfer_dma(pd); |
| 670 | 640 | ||
| 671 | /* Enable all interrupts to begin with */ | 641 | /* Enable all interrupts to begin with */ |
| @@ -731,7 +701,8 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, | |||
| 731 | int i; | 701 | int i; |
| 732 | long timeout; | 702 | long timeout; |
| 733 | 703 | ||
| 734 | activate_ch(pd); | 704 | /* Wake up device and enable clock */ |
| 705 | pm_runtime_get_sync(pd->dev); | ||
| 735 | 706 | ||
| 736 | /* Process all messages */ | 707 | /* Process all messages */ |
| 737 | for (i = 0; i < num; i++) { | 708 | for (i = 0; i < num; i++) { |
| @@ -768,11 +739,13 @@ static int sh_mobile_i2c_xfer(struct i2c_adapter *adapter, | |||
| 768 | break; | 739 | break; |
| 769 | } | 740 | } |
| 770 | 741 | ||
| 771 | deactivate_ch(pd); | 742 | /* Disable channel */ |
| 743 | iic_wr(pd, ICCR, ICCR_SCP); | ||
| 772 | 744 | ||
| 773 | if (!err) | 745 | /* Disable clock and mark device as idle */ |
| 774 | err = num; | 746 | pm_runtime_put_sync(pd->dev); |
| 775 | return err; | 747 | |
| 748 | return err ?: num; | ||
| 776 | } | 749 | } |
| 777 | 750 | ||
| 778 | static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter) | 751 | static u32 sh_mobile_i2c_func(struct i2c_adapter *adapter) |
| @@ -789,7 +762,7 @@ static const struct i2c_algorithm sh_mobile_i2c_algorithm = { | |||
| 789 | * r8a7740 chip has lasting errata on I2C I/O pad reset. | 762 | * r8a7740 chip has lasting errata on I2C I/O pad reset. |
| 790 | * this is work-around for it. | 763 | * this is work-around for it. |
| 791 | */ | 764 | */ |
| 792 | static void sh_mobile_i2c_r8a7740_workaround(struct sh_mobile_i2c_data *pd) | 765 | static int sh_mobile_i2c_r8a7740_workaround(struct sh_mobile_i2c_data *pd) |
| 793 | { | 766 | { |
| 794 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); | 767 | iic_set_clr(pd, ICCR, ICCR_ICE, 0); |
| 795 | iic_rd(pd, ICCR); /* dummy read */ | 768 | iic_rd(pd, ICCR); /* dummy read */ |
| @@ -810,14 +783,23 @@ static void sh_mobile_i2c_r8a7740_workaround(struct sh_mobile_i2c_data *pd) | |||
| 810 | udelay(10); | 783 | udelay(10); |
| 811 | iic_wr(pd, ICCR, ICCR_TRS); | 784 | iic_wr(pd, ICCR, ICCR_TRS); |
| 812 | udelay(10); | 785 | udelay(10); |
| 786 | |||
| 787 | return sh_mobile_i2c_init(pd); | ||
| 813 | } | 788 | } |
| 814 | 789 | ||
| 815 | static const struct sh_mobile_dt_config default_dt_config = { | 790 | static const struct sh_mobile_dt_config default_dt_config = { |
| 816 | .clks_per_count = 1, | 791 | .clks_per_count = 1, |
| 792 | .setup = sh_mobile_i2c_init, | ||
| 817 | }; | 793 | }; |
| 818 | 794 | ||
| 819 | static const struct sh_mobile_dt_config fast_clock_dt_config = { | 795 | static const struct sh_mobile_dt_config fast_clock_dt_config = { |
| 820 | .clks_per_count = 2, | 796 | .clks_per_count = 2, |
| 797 | .setup = sh_mobile_i2c_init, | ||
| 798 | }; | ||
| 799 | |||
| 800 | static const struct sh_mobile_dt_config v2_freq_calc_dt_config = { | ||
| 801 | .clks_per_count = 2, | ||
| 802 | .setup = sh_mobile_i2c_v2_init, | ||
| 821 | }; | 803 | }; |
| 822 | 804 | ||
| 823 | static const struct sh_mobile_dt_config r8a7740_dt_config = { | 805 | static const struct sh_mobile_dt_config r8a7740_dt_config = { |
| @@ -828,7 +810,7 @@ static const struct sh_mobile_dt_config r8a7740_dt_config = { | |||
| 828 | static const struct of_device_id sh_mobile_i2c_dt_ids[] = { | 810 | static const struct of_device_id sh_mobile_i2c_dt_ids[] = { |
| 829 | { .compatible = "renesas,iic-r8a73a4", .data = &fast_clock_dt_config }, | 811 | { .compatible = "renesas,iic-r8a73a4", .data = &fast_clock_dt_config }, |
| 830 | { .compatible = "renesas,iic-r8a7740", .data = &r8a7740_dt_config }, | 812 | { .compatible = "renesas,iic-r8a7740", .data = &r8a7740_dt_config }, |
| 831 | { .compatible = "renesas,iic-r8a7790", .data = &fast_clock_dt_config }, | 813 | { .compatible = "renesas,iic-r8a7790", .data = &v2_freq_calc_dt_config }, |
| 832 | { .compatible = "renesas,iic-r8a7791", .data = &fast_clock_dt_config }, | 814 | { .compatible = "renesas,iic-r8a7791", .data = &fast_clock_dt_config }, |
| 833 | { .compatible = "renesas,iic-r8a7792", .data = &fast_clock_dt_config }, | 815 | { .compatible = "renesas,iic-r8a7792", .data = &fast_clock_dt_config }, |
| 834 | { .compatible = "renesas,iic-r8a7793", .data = &fast_clock_dt_config }, | 816 | { .compatible = "renesas,iic-r8a7793", .data = &fast_clock_dt_config }, |
| @@ -910,32 +892,13 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
| 910 | return PTR_ERR(pd->reg); | 892 | return PTR_ERR(pd->reg); |
| 911 | 893 | ||
| 912 | ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); | 894 | ret = of_property_read_u32(dev->dev.of_node, "clock-frequency", &bus_speed); |
| 913 | pd->bus_speed = ret ? STANDARD_MODE : bus_speed; | 895 | pd->bus_speed = (ret || !bus_speed) ? STANDARD_MODE : bus_speed; |
| 914 | pd->clks_per_count = 1; | 896 | pd->clks_per_count = 1; |
| 915 | 897 | ||
| 916 | config = of_device_get_match_data(&dev->dev); | 898 | /* Newer variants come with two new bits in ICIC */ |
| 917 | if (config) { | ||
| 918 | pd->clks_per_count = config->clks_per_count; | ||
| 919 | |||
| 920 | if (config->setup) | ||
| 921 | config->setup(pd); | ||
| 922 | } | ||
| 923 | |||
| 924 | /* The IIC blocks on SH-Mobile ARM processors | ||
| 925 | * come with two new bits in ICIC. | ||
| 926 | */ | ||
| 927 | if (resource_size(res) > 0x17) | 899 | if (resource_size(res) > 0x17) |
| 928 | pd->flags |= IIC_FLAG_HAS_ICIC67; | 900 | pd->flags |= IIC_FLAG_HAS_ICIC67; |
| 929 | 901 | ||
| 930 | ret = sh_mobile_i2c_init(pd); | ||
| 931 | if (ret) | ||
| 932 | return ret; | ||
| 933 | |||
| 934 | /* Init DMA */ | ||
| 935 | sg_init_table(&pd->sg, 1); | ||
| 936 | pd->dma_direction = DMA_NONE; | ||
| 937 | pd->dma_rx = pd->dma_tx = ERR_PTR(-EPROBE_DEFER); | ||
| 938 | |||
| 939 | /* Enable Runtime PM for this device. | 902 | /* Enable Runtime PM for this device. |
| 940 | * | 903 | * |
| 941 | * Also tell the Runtime PM core to ignore children | 904 | * Also tell the Runtime PM core to ignore children |
| @@ -948,6 +911,24 @@ static int sh_mobile_i2c_probe(struct platform_device *dev) | |||
| 948 | */ | 911 | */ |
| 949 | pm_suspend_ignore_children(&dev->dev, true); | 912 | pm_suspend_ignore_children(&dev->dev, true); |
| 950 | pm_runtime_enable(&dev->dev); | 913 | pm_runtime_enable(&dev->dev); |
| 914 | pm_runtime_get_sync(&dev->dev); | ||
| 915 | |||
| 916 | config = of_device_get_match_data(&dev->dev); | ||
| 917 | if (config) { | ||
| 918 | pd->clks_per_count = config->clks_per_count; | ||
| 919 | ret = config->setup(pd); | ||
| 920 | } else { | ||
| 921 | ret = sh_mobile_i2c_init(pd); | ||
| 922 | } | ||
| 923 | |||
| 924 | pm_runtime_put_sync(&dev->dev); | ||
| 925 | if (ret) | ||
| 926 | return ret; | ||
| 927 | |||
| 928 | /* Init DMA */ | ||
| 929 | sg_init_table(&pd->sg, 1); | ||
| 930 | pd->dma_direction = DMA_NONE; | ||
| 931 | pd->dma_rx = pd->dma_tx = ERR_PTR(-EPROBE_DEFER); | ||
| 951 | 932 | ||
| 952 | /* setup the private data */ | 933 | /* setup the private data */ |
| 953 | adap = &pd->adap; | 934 | adap = &pd->adap; |
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index f7829a74140c..5a00bf443d06 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c | |||
| @@ -27,7 +27,7 @@ | |||
| 27 | #include <linux/delay.h> | 27 | #include <linux/delay.h> |
| 28 | #include <linux/err.h> | 28 | #include <linux/err.h> |
| 29 | #include <linux/errno.h> | 29 | #include <linux/errno.h> |
| 30 | #include <linux/gpio.h> | 30 | #include <linux/gpio/consumer.h> |
| 31 | #include <linux/i2c.h> | 31 | #include <linux/i2c.h> |
| 32 | #include <linux/i2c-smbus.h> | 32 | #include <linux/i2c-smbus.h> |
| 33 | #include <linux/idr.h> | 33 | #include <linux/idr.h> |
| @@ -134,52 +134,22 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
| 134 | /* i2c bus recovery routines */ | 134 | /* i2c bus recovery routines */ |
| 135 | static int get_scl_gpio_value(struct i2c_adapter *adap) | 135 | static int get_scl_gpio_value(struct i2c_adapter *adap) |
| 136 | { | 136 | { |
| 137 | return gpio_get_value(adap->bus_recovery_info->scl_gpio); | 137 | return gpiod_get_value_cansleep(adap->bus_recovery_info->scl_gpiod); |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | static void set_scl_gpio_value(struct i2c_adapter *adap, int val) | 140 | static void set_scl_gpio_value(struct i2c_adapter *adap, int val) |
| 141 | { | 141 | { |
| 142 | gpio_set_value(adap->bus_recovery_info->scl_gpio, val); | 142 | gpiod_set_value_cansleep(adap->bus_recovery_info->scl_gpiod, val); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | static int get_sda_gpio_value(struct i2c_adapter *adap) | 145 | static int get_sda_gpio_value(struct i2c_adapter *adap) |
| 146 | { | 146 | { |
| 147 | return gpio_get_value(adap->bus_recovery_info->sda_gpio); | 147 | return gpiod_get_value_cansleep(adap->bus_recovery_info->sda_gpiod); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap) | 150 | static void set_sda_gpio_value(struct i2c_adapter *adap, int val) |
| 151 | { | 151 | { |
| 152 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | 152 | gpiod_set_value_cansleep(adap->bus_recovery_info->sda_gpiod, val); |
| 153 | struct device *dev = &adap->dev; | ||
| 154 | int ret = 0; | ||
| 155 | |||
| 156 | ret = gpio_request_one(bri->scl_gpio, GPIOF_OPEN_DRAIN | | ||
| 157 | GPIOF_OUT_INIT_HIGH, "i2c-scl"); | ||
| 158 | if (ret) { | ||
| 159 | dev_warn(dev, "Can't get SCL gpio: %d\n", bri->scl_gpio); | ||
| 160 | return ret; | ||
| 161 | } | ||
| 162 | |||
| 163 | if (bri->get_sda) { | ||
| 164 | if (gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda")) { | ||
| 165 | /* work without SDA polling */ | ||
| 166 | dev_warn(dev, "Can't get SDA gpio: %d. Not using SDA polling\n", | ||
| 167 | bri->sda_gpio); | ||
| 168 | bri->get_sda = NULL; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | return ret; | ||
| 173 | } | ||
| 174 | |||
| 175 | static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap) | ||
| 176 | { | ||
| 177 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | ||
| 178 | |||
| 179 | if (bri->get_sda) | ||
| 180 | gpio_free(bri->sda_gpio); | ||
| 181 | |||
| 182 | gpio_free(bri->scl_gpio); | ||
| 183 | } | 153 | } |
| 184 | 154 | ||
| 185 | /* | 155 | /* |
| @@ -190,7 +160,7 @@ static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap) | |||
| 190 | #define RECOVERY_NDELAY 5000 | 160 | #define RECOVERY_NDELAY 5000 |
| 191 | #define RECOVERY_CLK_CNT 9 | 161 | #define RECOVERY_CLK_CNT 9 |
| 192 | 162 | ||
| 193 | static int i2c_generic_recovery(struct i2c_adapter *adap) | 163 | int i2c_generic_scl_recovery(struct i2c_adapter *adap) |
| 194 | { | 164 | { |
| 195 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; | 165 | struct i2c_bus_recovery_info *bri = adap->bus_recovery_info; |
| 196 | int i = 0, val = 1, ret = 0; | 166 | int i = 0, val = 1, ret = 0; |
| @@ -199,6 +169,8 @@ static int i2c_generic_recovery(struct i2c_adapter *adap) | |||
| 199 | bri->prepare_recovery(adap); | 169 | bri->prepare_recovery(adap); |
| 200 | 170 | ||
| 201 | bri->set_scl(adap, val); | 171 | bri->set_scl(adap, val); |
| 172 | if (bri->set_sda) | ||
| 173 | bri->set_sda(adap, 1); | ||
| 202 | ndelay(RECOVERY_NDELAY); | 174 | ndelay(RECOVERY_NDELAY); |
| 203 | 175 | ||
| 204 | /* | 176 | /* |
| @@ -227,33 +199,25 @@ static int i2c_generic_recovery(struct i2c_adapter *adap) | |||
| 227 | if (bri->get_sda && !bri->get_sda(adap)) | 199 | if (bri->get_sda && !bri->get_sda(adap)) |
| 228 | ret = -EBUSY; | 200 | ret = -EBUSY; |
| 229 | 201 | ||
| 202 | /* If all went well, send STOP for a sane bus state. */ | ||
| 203 | if (ret == 0 && bri->set_sda) { | ||
| 204 | bri->set_scl(adap, 0); | ||
| 205 | ndelay(RECOVERY_NDELAY / 2); | ||
| 206 | bri->set_sda(adap, 0); | ||
| 207 | ndelay(RECOVERY_NDELAY / 2); | ||
| 208 | bri->set_scl(adap, 1); | ||
| 209 | ndelay(RECOVERY_NDELAY / 2); | ||
| 210 | bri->set_sda(adap, 1); | ||
| 211 | ndelay(RECOVERY_NDELAY / 2); | ||
| 212 | } | ||
| 213 | |||
| 230 | if (bri->unprepare_recovery) | 214 | if (bri->unprepare_recovery) |
| 231 | bri->unprepare_recovery(adap); | 215 | bri->unprepare_recovery(adap); |
| 232 | 216 | ||
| 233 | return ret; | 217 | return ret; |
| 234 | } | 218 | } |
| 235 | |||
| 236 | int i2c_generic_scl_recovery(struct i2c_adapter *adap) | ||
| 237 | { | ||
| 238 | return i2c_generic_recovery(adap); | ||
| 239 | } | ||
| 240 | EXPORT_SYMBOL_GPL(i2c_generic_scl_recovery); | 219 | EXPORT_SYMBOL_GPL(i2c_generic_scl_recovery); |
| 241 | 220 | ||
| 242 | int i2c_generic_gpio_recovery(struct i2c_adapter *adap) | ||
| 243 | { | ||
| 244 | int ret; | ||
| 245 | |||
| 246 | ret = i2c_get_gpios_for_recovery(adap); | ||
| 247 | if (ret) | ||
| 248 | return ret; | ||
| 249 | |||
| 250 | ret = i2c_generic_recovery(adap); | ||
| 251 | i2c_put_gpios_for_recovery(adap); | ||
| 252 | |||
| 253 | return ret; | ||
| 254 | } | ||
| 255 | EXPORT_SYMBOL_GPL(i2c_generic_gpio_recovery); | ||
| 256 | |||
| 257 | int i2c_recover_bus(struct i2c_adapter *adap) | 221 | int i2c_recover_bus(struct i2c_adapter *adap) |
| 258 | { | 222 | { |
| 259 | if (!adap->bus_recovery_info) | 223 | if (!adap->bus_recovery_info) |
| @@ -277,21 +241,19 @@ static void i2c_init_recovery(struct i2c_adapter *adap) | |||
| 277 | goto err; | 241 | goto err; |
| 278 | } | 242 | } |
| 279 | 243 | ||
| 280 | /* Generic GPIO recovery */ | 244 | if (bri->scl_gpiod && bri->recover_bus == i2c_generic_scl_recovery) { |
| 281 | if (bri->recover_bus == i2c_generic_gpio_recovery) { | ||
| 282 | if (!gpio_is_valid(bri->scl_gpio)) { | ||
| 283 | err_str = "invalid SCL gpio"; | ||
| 284 | goto err; | ||
| 285 | } | ||
| 286 | |||
| 287 | if (gpio_is_valid(bri->sda_gpio)) | ||
| 288 | bri->get_sda = get_sda_gpio_value; | ||
| 289 | else | ||
| 290 | bri->get_sda = NULL; | ||
| 291 | |||
| 292 | bri->get_scl = get_scl_gpio_value; | 245 | bri->get_scl = get_scl_gpio_value; |
| 293 | bri->set_scl = set_scl_gpio_value; | 246 | bri->set_scl = set_scl_gpio_value; |
| 294 | } else if (bri->recover_bus == i2c_generic_scl_recovery) { | 247 | if (bri->sda_gpiod) { |
| 248 | bri->get_sda = get_sda_gpio_value; | ||
| 249 | /* FIXME: add proper flag instead of '0' once available */ | ||
| 250 | if (gpiod_get_direction(bri->sda_gpiod) == 0) | ||
| 251 | bri->set_sda = set_sda_gpio_value; | ||
| 252 | } | ||
| 253 | return; | ||
| 254 | } | ||
| 255 | |||
| 256 | if (bri->recover_bus == i2c_generic_scl_recovery) { | ||
| 295 | /* Generic SCL recovery */ | 257 | /* Generic SCL recovery */ |
| 296 | if (!bri->set_scl || !bri->get_scl) { | 258 | if (!bri->set_scl || !bri->get_scl) { |
| 297 | err_str = "no {get|set}_scl() found"; | 259 | err_str = "no {get|set}_scl() found"; |
| @@ -1976,63 +1938,35 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) | |||
| 1976 | EXPORT_SYMBOL(i2c_transfer); | 1938 | EXPORT_SYMBOL(i2c_transfer); |
| 1977 | 1939 | ||
| 1978 | /** | 1940 | /** |
| 1979 | * i2c_master_send - issue a single I2C message in master transmit mode | 1941 | * i2c_transfer_buffer_flags - issue a single I2C message transferring data |
| 1980 | * @client: Handle to slave device | 1942 | * to/from a buffer |
| 1981 | * @buf: Data that will be written to the slave | ||
| 1982 | * @count: How many bytes to write, must be less than 64k since msg.len is u16 | ||
| 1983 | * | ||
| 1984 | * Returns negative errno, or else the number of bytes written. | ||
| 1985 | */ | ||
| 1986 | int i2c_master_send(const struct i2c_client *client, const char *buf, int count) | ||
| 1987 | { | ||
| 1988 | int ret; | ||
| 1989 | struct i2c_adapter *adap = client->adapter; | ||
| 1990 | struct i2c_msg msg; | ||
| 1991 | |||
| 1992 | msg.addr = client->addr; | ||
| 1993 | msg.flags = client->flags & I2C_M_TEN; | ||
| 1994 | msg.len = count; | ||
| 1995 | msg.buf = (char *)buf; | ||
| 1996 | |||
| 1997 | ret = i2c_transfer(adap, &msg, 1); | ||
| 1998 | |||
| 1999 | /* | ||
| 2000 | * If everything went ok (i.e. 1 msg transmitted), return #bytes | ||
| 2001 | * transmitted, else error code. | ||
| 2002 | */ | ||
| 2003 | return (ret == 1) ? count : ret; | ||
| 2004 | } | ||
| 2005 | EXPORT_SYMBOL(i2c_master_send); | ||
| 2006 | |||
| 2007 | /** | ||
| 2008 | * i2c_master_recv - issue a single I2C message in master receive mode | ||
| 2009 | * @client: Handle to slave device | 1943 | * @client: Handle to slave device |
| 2010 | * @buf: Where to store data read from slave | 1944 | * @buf: Where the data is stored |
| 2011 | * @count: How many bytes to read, must be less than 64k since msg.len is u16 | 1945 | * @count: How many bytes to transfer, must be less than 64k since msg.len is u16 |
| 1946 | * @flags: The flags to be used for the message, e.g. I2C_M_RD for reads | ||
| 2012 | * | 1947 | * |
| 2013 | * Returns negative errno, or else the number of bytes read. | 1948 | * Returns negative errno, or else the number of bytes transferred. |
| 2014 | */ | 1949 | */ |
| 2015 | int i2c_master_recv(const struct i2c_client *client, char *buf, int count) | 1950 | int i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf, |
| 1951 | int count, u16 flags) | ||
| 2016 | { | 1952 | { |
| 2017 | struct i2c_adapter *adap = client->adapter; | ||
| 2018 | struct i2c_msg msg; | ||
| 2019 | int ret; | 1953 | int ret; |
| 1954 | struct i2c_msg msg = { | ||
| 1955 | .addr = client->addr, | ||
| 1956 | .flags = flags | (client->flags & I2C_M_TEN), | ||
| 1957 | .len = count, | ||
| 1958 | .buf = buf, | ||
| 1959 | }; | ||
| 2020 | 1960 | ||
| 2021 | msg.addr = client->addr; | 1961 | ret = i2c_transfer(client->adapter, &msg, 1); |
| 2022 | msg.flags = client->flags & I2C_M_TEN; | ||
| 2023 | msg.flags |= I2C_M_RD; | ||
| 2024 | msg.len = count; | ||
| 2025 | msg.buf = buf; | ||
| 2026 | |||
| 2027 | ret = i2c_transfer(adap, &msg, 1); | ||
| 2028 | 1962 | ||
| 2029 | /* | 1963 | /* |
| 2030 | * If everything went ok (i.e. 1 msg received), return #bytes received, | 1964 | * If everything went ok (i.e. 1 msg transferred), return #bytes |
| 2031 | * else error code. | 1965 | * transferred, else error code. |
| 2032 | */ | 1966 | */ |
| 2033 | return (ret == 1) ? count : ret; | 1967 | return (ret == 1) ? count : ret; |
| 2034 | } | 1968 | } |
| 2035 | EXPORT_SYMBOL(i2c_master_recv); | 1969 | EXPORT_SYMBOL(i2c_transfer_buffer_flags); |
| 2036 | 1970 | ||
| 2037 | /* ---------------------------------------------------- | 1971 | /* ---------------------------------------------------- |
| 2038 | * the i2c address scanning function | 1972 | * the i2c address scanning function |
| @@ -2265,6 +2199,52 @@ void i2c_put_adapter(struct i2c_adapter *adap) | |||
| 2265 | } | 2199 | } |
| 2266 | EXPORT_SYMBOL(i2c_put_adapter); | 2200 | EXPORT_SYMBOL(i2c_put_adapter); |
| 2267 | 2201 | ||
| 2202 | /** | ||
| 2203 | * i2c_get_dma_safe_msg_buf() - get a DMA safe buffer for the given i2c_msg | ||
| 2204 | * @msg: the message to be checked | ||
| 2205 | * @threshold: the minimum number of bytes for which using DMA makes sense | ||
| 2206 | * | ||
| 2207 | * Return: NULL if a DMA safe buffer was not obtained. Use msg->buf with PIO. | ||
| 2208 | * Or a valid pointer to be used with DMA. After use, release it by | ||
| 2209 | * calling i2c_release_dma_safe_msg_buf(). | ||
| 2210 | * | ||
| 2211 | * This function must only be called from process context! | ||
| 2212 | */ | ||
| 2213 | u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold) | ||
| 2214 | { | ||
| 2215 | if (msg->len < threshold) | ||
| 2216 | return NULL; | ||
| 2217 | |||
| 2218 | if (msg->flags & I2C_M_DMA_SAFE) | ||
| 2219 | return msg->buf; | ||
| 2220 | |||
| 2221 | pr_debug("using bounce buffer for addr=0x%02x, len=%d\n", | ||
| 2222 | msg->addr, msg->len); | ||
| 2223 | |||
| 2224 | if (msg->flags & I2C_M_RD) | ||
| 2225 | return kzalloc(msg->len, GFP_KERNEL); | ||
| 2226 | else | ||
| 2227 | return kmemdup(msg->buf, msg->len, GFP_KERNEL); | ||
| 2228 | } | ||
| 2229 | EXPORT_SYMBOL_GPL(i2c_get_dma_safe_msg_buf); | ||
| 2230 | |||
| 2231 | /** | ||
| 2232 | * i2c_release_dma_safe_msg_buf - release DMA safe buffer and sync with i2c_msg | ||
| 2233 | * @msg: the message to be synced with | ||
| 2234 | * @buf: the buffer obtained from i2c_get_dma_safe_msg_buf(). May be NULL. | ||
| 2235 | */ | ||
| 2236 | void i2c_release_dma_safe_msg_buf(struct i2c_msg *msg, u8 *buf) | ||
| 2237 | { | ||
| 2238 | if (!buf || buf == msg->buf) | ||
| 2239 | return; | ||
| 2240 | |||
| 2241 | if (msg->flags & I2C_M_RD) | ||
| 2242 | memcpy(msg->buf, buf, msg->len); | ||
| 2243 | |||
| 2244 | kfree(buf); | ||
| 2245 | } | ||
| 2246 | EXPORT_SYMBOL_GPL(i2c_release_dma_safe_msg_buf); | ||
| 2247 | |||
| 2268 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); | 2248 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); |
| 2269 | MODULE_DESCRIPTION("I2C-Bus main module"); | 2249 | MODULE_DESCRIPTION("I2C-Bus main module"); |
| 2270 | MODULE_LICENSE("GPL"); | 2250 | MODULE_LICENSE("GPL"); |
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c index a1082c04ac5c..59d5cf376f6a 100644 --- a/drivers/i2c/i2c-core-smbus.c +++ b/drivers/i2c/i2c-core-smbus.c | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include <linux/err.h> | 18 | #include <linux/err.h> |
| 19 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
| 20 | #include <linux/i2c-smbus.h> | 20 | #include <linux/i2c-smbus.h> |
| 21 | #include <linux/slab.h> | ||
| 21 | 22 | ||
| 22 | #define CREATE_TRACE_POINTS | 23 | #define CREATE_TRACE_POINTS |
| 23 | #include <trace/events/smbus.h> | 24 | #include <trace/events/smbus.h> |
| @@ -291,6 +292,22 @@ s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command, | |||
| 291 | } | 292 | } |
| 292 | EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); | 293 | EXPORT_SYMBOL(i2c_smbus_write_i2c_block_data); |
| 293 | 294 | ||
| 295 | static void i2c_smbus_try_get_dmabuf(struct i2c_msg *msg, u8 init_val) | ||
| 296 | { | ||
| 297 | bool is_read = msg->flags & I2C_M_RD; | ||
| 298 | unsigned char *dma_buf; | ||
| 299 | |||
| 300 | dma_buf = kzalloc(I2C_SMBUS_BLOCK_MAX + (is_read ? 2 : 3), GFP_KERNEL); | ||
| 301 | if (!dma_buf) | ||
| 302 | return; | ||
| 303 | |||
| 304 | msg->buf = dma_buf; | ||
| 305 | msg->flags |= I2C_M_DMA_SAFE; | ||
| 306 | |||
| 307 | if (init_val) | ||
| 308 | msg->buf[0] = init_val; | ||
| 309 | } | ||
| 310 | |||
| 294 | /* Simulate a SMBus command using the i2c protocol | 311 | /* Simulate a SMBus command using the i2c protocol |
| 295 | No checking of parameters is done! */ | 312 | No checking of parameters is done! */ |
| 296 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, | 313 | static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, |
| @@ -368,6 +385,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, | |||
| 368 | msg[1].flags |= I2C_M_RECV_LEN; | 385 | msg[1].flags |= I2C_M_RECV_LEN; |
| 369 | msg[1].len = 1; /* block length will be added by | 386 | msg[1].len = 1; /* block length will be added by |
| 370 | the underlying bus driver */ | 387 | the underlying bus driver */ |
| 388 | i2c_smbus_try_get_dmabuf(&msg[1], 0); | ||
| 371 | } else { | 389 | } else { |
| 372 | msg[0].len = data->block[0] + 2; | 390 | msg[0].len = data->block[0] + 2; |
| 373 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { | 391 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { |
| @@ -376,8 +394,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, | |||
| 376 | data->block[0]); | 394 | data->block[0]); |
| 377 | return -EINVAL; | 395 | return -EINVAL; |
| 378 | } | 396 | } |
| 397 | |||
| 398 | i2c_smbus_try_get_dmabuf(&msg[0], command); | ||
| 379 | for (i = 1; i < msg[0].len; i++) | 399 | for (i = 1; i < msg[0].len; i++) |
| 380 | msgbuf0[i] = data->block[i-1]; | 400 | msg[0].buf[i] = data->block[i - 1]; |
| 381 | } | 401 | } |
| 382 | break; | 402 | break; |
| 383 | case I2C_SMBUS_BLOCK_PROC_CALL: | 403 | case I2C_SMBUS_BLOCK_PROC_CALL: |
| @@ -389,12 +409,16 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, | |||
| 389 | data->block[0]); | 409 | data->block[0]); |
| 390 | return -EINVAL; | 410 | return -EINVAL; |
| 391 | } | 411 | } |
| 412 | |||
| 392 | msg[0].len = data->block[0] + 2; | 413 | msg[0].len = data->block[0] + 2; |
| 414 | i2c_smbus_try_get_dmabuf(&msg[0], command); | ||
| 393 | for (i = 1; i < msg[0].len; i++) | 415 | for (i = 1; i < msg[0].len; i++) |
| 394 | msgbuf0[i] = data->block[i-1]; | 416 | msg[0].buf[i] = data->block[i - 1]; |
| 417 | |||
| 395 | msg[1].flags |= I2C_M_RECV_LEN; | 418 | msg[1].flags |= I2C_M_RECV_LEN; |
| 396 | msg[1].len = 1; /* block length will be added by | 419 | msg[1].len = 1; /* block length will be added by |
| 397 | the underlying bus driver */ | 420 | the underlying bus driver */ |
| 421 | i2c_smbus_try_get_dmabuf(&msg[1], 0); | ||
| 398 | break; | 422 | break; |
| 399 | case I2C_SMBUS_I2C_BLOCK_DATA: | 423 | case I2C_SMBUS_I2C_BLOCK_DATA: |
| 400 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { | 424 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { |
| @@ -406,10 +430,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, | |||
| 406 | 430 | ||
| 407 | if (read_write == I2C_SMBUS_READ) { | 431 | if (read_write == I2C_SMBUS_READ) { |
| 408 | msg[1].len = data->block[0]; | 432 | msg[1].len = data->block[0]; |
| 433 | i2c_smbus_try_get_dmabuf(&msg[1], 0); | ||
| 409 | } else { | 434 | } else { |
| 410 | msg[0].len = data->block[0] + 1; | 435 | msg[0].len = data->block[0] + 1; |
| 436 | |||
| 437 | i2c_smbus_try_get_dmabuf(&msg[0], command); | ||
| 411 | for (i = 1; i <= data->block[0]; i++) | 438 | for (i = 1; i <= data->block[0]; i++) |
| 412 | msgbuf0[i] = data->block[i]; | 439 | msg[0].buf[i] = data->block[i]; |
| 413 | } | 440 | } |
| 414 | break; | 441 | break; |
| 415 | default: | 442 | default: |
| @@ -457,14 +484,20 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr, | |||
| 457 | break; | 484 | break; |
| 458 | case I2C_SMBUS_I2C_BLOCK_DATA: | 485 | case I2C_SMBUS_I2C_BLOCK_DATA: |
| 459 | for (i = 0; i < data->block[0]; i++) | 486 | for (i = 0; i < data->block[0]; i++) |
| 460 | data->block[i+1] = msgbuf1[i]; | 487 | data->block[i + 1] = msg[1].buf[i]; |
| 461 | break; | 488 | break; |
| 462 | case I2C_SMBUS_BLOCK_DATA: | 489 | case I2C_SMBUS_BLOCK_DATA: |
| 463 | case I2C_SMBUS_BLOCK_PROC_CALL: | 490 | case I2C_SMBUS_BLOCK_PROC_CALL: |
| 464 | for (i = 0; i < msgbuf1[0] + 1; i++) | 491 | for (i = 0; i < msg[1].buf[0] + 1; i++) |
| 465 | data->block[i] = msgbuf1[i]; | 492 | data->block[i] = msg[1].buf[i]; |
| 466 | break; | 493 | break; |
| 467 | } | 494 | } |
| 495 | |||
| 496 | if (msg[0].flags & I2C_M_DMA_SAFE) | ||
| 497 | kfree(msg[0].buf); | ||
| 498 | if (msg[1].flags & I2C_M_DMA_SAFE) | ||
| 499 | kfree(msg[1].buf); | ||
| 500 | |||
| 468 | return 0; | 501 | return 0; |
| 469 | } | 502 | } |
| 470 | 503 | ||
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 2cab27a68479..036a03f0d0a6 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
| @@ -264,6 +264,8 @@ static noinline int i2cdev_ioctl_rdwr(struct i2c_client *client, | |||
| 264 | res = PTR_ERR(msgs[i].buf); | 264 | res = PTR_ERR(msgs[i].buf); |
| 265 | break; | 265 | break; |
| 266 | } | 266 | } |
| 267 | /* memdup_user allocates with GFP_KERNEL, so DMA is ok */ | ||
| 268 | msgs[i].flags |= I2C_M_DMA_SAFE; | ||
| 267 | 269 | ||
| 268 | /* | 270 | /* |
| 269 | * If the message length is received from the slave (similar | 271 | * If the message length is received from the slave (similar |
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index 0f5c8fc36625..52a4a922e7e6 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig | |||
| @@ -64,11 +64,11 @@ config I2C_MUX_PCA9541 | |||
| 64 | will be called i2c-mux-pca9541. | 64 | will be called i2c-mux-pca9541. |
| 65 | 65 | ||
| 66 | config I2C_MUX_PCA954x | 66 | config I2C_MUX_PCA954x |
| 67 | tristate "Philips PCA954x I2C Mux/switches" | 67 | tristate "NXP PCA954x and PCA984x I2C Mux/switches" |
| 68 | depends on GPIOLIB || COMPILE_TEST | 68 | depends on GPIOLIB || COMPILE_TEST |
| 69 | help | 69 | help |
| 70 | If you say yes here you get support for the Philips PCA954x | 70 | If you say yes here you get support for the NXP PCA954x |
| 71 | I2C mux/switch devices. | 71 | and PCA984x I2C mux/switch devices. |
| 72 | 72 | ||
| 73 | This driver can also be built as a module. If so, the module | 73 | This driver can also be built as a module. If so, the module |
| 74 | will be called i2c-mux-pca954x. | 74 | will be called i2c-mux-pca954x. |
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 2ca068d8b92d..fbb84c7ef282 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c | |||
| @@ -4,11 +4,11 @@ | |||
| 4 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> | 4 | * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it> |
| 5 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> | 5 | * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it> |
| 6 | * | 6 | * |
| 7 | * This module supports the PCA954x series of I2C multiplexer/switch chips | 7 | * This module supports the PCA954x and PCA954x series of I2C multiplexer/switch |
| 8 | * made by Philips Semiconductors. | 8 | * chips made by NXP Semiconductors. |
| 9 | * This includes the: | 9 | * This includes the: |
| 10 | * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547 | 10 | * PCA9540, PCA9542, PCA9543, PCA9544, PCA9545, PCA9546, PCA9547, |
| 11 | * and PCA9548. | 11 | * PCA9548, PCA9846, PCA9847, PCA9848 and PCA9849. |
| 12 | * | 12 | * |
| 13 | * These chips are all controlled via the I2C bus itself, and all have a | 13 | * These chips are all controlled via the I2C bus itself, and all have a |
| 14 | * single 8-bit register. The upstream "parent" bus fans out to two, | 14 | * single 8-bit register. The upstream "parent" bus fans out to two, |
| @@ -63,6 +63,10 @@ enum pca_type { | |||
| 63 | pca_9546, | 63 | pca_9546, |
| 64 | pca_9547, | 64 | pca_9547, |
| 65 | pca_9548, | 65 | pca_9548, |
| 66 | pca_9846, | ||
| 67 | pca_9847, | ||
| 68 | pca_9848, | ||
| 69 | pca_9849, | ||
| 66 | }; | 70 | }; |
| 67 | 71 | ||
| 68 | struct chip_desc { | 72 | struct chip_desc { |
| @@ -129,6 +133,24 @@ static const struct chip_desc chips[] = { | |||
| 129 | .nchans = 8, | 133 | .nchans = 8, |
| 130 | .muxtype = pca954x_isswi, | 134 | .muxtype = pca954x_isswi, |
| 131 | }, | 135 | }, |
| 136 | [pca_9846] = { | ||
| 137 | .nchans = 4, | ||
| 138 | .muxtype = pca954x_isswi, | ||
| 139 | }, | ||
| 140 | [pca_9847] = { | ||
| 141 | .nchans = 8, | ||
| 142 | .enable = 0x8, | ||
| 143 | .muxtype = pca954x_ismux, | ||
| 144 | }, | ||
| 145 | [pca_9848] = { | ||
| 146 | .nchans = 8, | ||
| 147 | .muxtype = pca954x_isswi, | ||
| 148 | }, | ||
| 149 | [pca_9849] = { | ||
| 150 | .nchans = 4, | ||
| 151 | .enable = 0x4, | ||
| 152 | .muxtype = pca954x_ismux, | ||
| 153 | }, | ||
| 132 | }; | 154 | }; |
| 133 | 155 | ||
| 134 | static const struct i2c_device_id pca954x_id[] = { | 156 | static const struct i2c_device_id pca954x_id[] = { |
| @@ -140,6 +162,10 @@ static const struct i2c_device_id pca954x_id[] = { | |||
| 140 | { "pca9546", pca_9546 }, | 162 | { "pca9546", pca_9546 }, |
| 141 | { "pca9547", pca_9547 }, | 163 | { "pca9547", pca_9547 }, |
| 142 | { "pca9548", pca_9548 }, | 164 | { "pca9548", pca_9548 }, |
| 165 | { "pca9846", pca_9846 }, | ||
| 166 | { "pca9847", pca_9847 }, | ||
| 167 | { "pca9848", pca_9848 }, | ||
| 168 | { "pca9849", pca_9849 }, | ||
| 143 | { } | 169 | { } |
| 144 | }; | 170 | }; |
| 145 | MODULE_DEVICE_TABLE(i2c, pca954x_id); | 171 | MODULE_DEVICE_TABLE(i2c, pca954x_id); |
| @@ -154,6 +180,10 @@ static const struct of_device_id pca954x_of_match[] = { | |||
| 154 | { .compatible = "nxp,pca9546", .data = &chips[pca_9546] }, | 180 | { .compatible = "nxp,pca9546", .data = &chips[pca_9546] }, |
| 155 | { .compatible = "nxp,pca9547", .data = &chips[pca_9547] }, | 181 | { .compatible = "nxp,pca9547", .data = &chips[pca_9547] }, |
| 156 | { .compatible = "nxp,pca9548", .data = &chips[pca_9548] }, | 182 | { .compatible = "nxp,pca9548", .data = &chips[pca_9548] }, |
| 183 | { .compatible = "nxp,pca9846", .data = &chips[pca_9846] }, | ||
| 184 | { .compatible = "nxp,pca9847", .data = &chips[pca_9847] }, | ||
| 185 | { .compatible = "nxp,pca9848", .data = &chips[pca_9848] }, | ||
| 186 | { .compatible = "nxp,pca9849", .data = &chips[pca_9849] }, | ||
| 157 | {} | 187 | {} |
| 158 | }; | 188 | }; |
| 159 | MODULE_DEVICE_TABLE(of, pca954x_of_match); | 189 | MODULE_DEVICE_TABLE(of, pca954x_of_match); |
diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c index f6c9c3dc6cad..c948e5a4cb04 100644 --- a/drivers/i2c/muxes/i2c-mux-reg.c +++ b/drivers/i2c/muxes/i2c-mux-reg.c | |||
| @@ -177,6 +177,9 @@ static int i2c_mux_reg_probe(struct platform_device *pdev) | |||
| 177 | sizeof(mux->data)); | 177 | sizeof(mux->data)); |
| 178 | } else { | 178 | } else { |
| 179 | ret = i2c_mux_reg_probe_dt(mux, pdev); | 179 | ret = i2c_mux_reg_probe_dt(mux, pdev); |
| 180 | if (ret == -EPROBE_DEFER) | ||
| 181 | return ret; | ||
| 182 | |||
| 180 | if (ret < 0) { | 183 | if (ret < 0) { |
| 181 | dev_err(&pdev->dev, "Error parsing device tree"); | 184 | dev_err(&pdev->dev, "Error parsing device tree"); |
| 182 | return ret; | 185 | return ret; |
