diff options
| author | Pierre-Yves MORDRET <pierre-yves.mordret@st.com> | 2018-11-19 06:03:32 -0500 |
|---|---|---|
| committer | Wolfram Sang <wsa@the-dreams.de> | 2018-11-27 07:08:17 -0500 |
| commit | cb944fb973bcd326bc99a5381f5fb109c0b9de95 (patch) | |
| tree | bb8982c27c797877ed55da9aa946813be28a8114 /drivers/i2c | |
| parent | 9d9aa7ec7baf62640cd4e1a869746b2356731e93 (diff) | |
i2c: stm32f7: SYSCFG Fast Mode Plus support for I2C STM32F7
Read SYSCFG bindings to set Fast Mode Plus bits if Fast Mode Plus
speed is selected.
Signed-off-by: Pierre-Yves MORDRET <pierre-yves.mordret@st.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
| -rw-r--r-- | drivers/i2c/busses/i2c-stm32f7.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c index 62d023e737d9..e9f0c0bd774d 100644 --- a/drivers/i2c/busses/i2c-stm32f7.c +++ b/drivers/i2c/busses/i2c-stm32f7.c | |||
| @@ -21,12 +21,14 @@ | |||
| 21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
| 23 | #include <linux/iopoll.h> | 23 | #include <linux/iopoll.h> |
| 24 | #include <linux/mfd/syscon.h> | ||
| 24 | #include <linux/module.h> | 25 | #include <linux/module.h> |
| 25 | #include <linux/of.h> | 26 | #include <linux/of.h> |
| 26 | #include <linux/of_address.h> | 27 | #include <linux/of_address.h> |
| 27 | #include <linux/of_irq.h> | 28 | #include <linux/of_irq.h> |
| 28 | #include <linux/of_platform.h> | 29 | #include <linux/of_platform.h> |
| 29 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
| 31 | #include <linux/regmap.h> | ||
| 30 | #include <linux/reset.h> | 32 | #include <linux/reset.h> |
| 31 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
| 32 | 34 | ||
| @@ -276,6 +278,7 @@ struct stm32f7_i2c_msg { | |||
| 276 | * slave) | 278 | * slave) |
| 277 | * @dma: dma data | 279 | * @dma: dma data |
| 278 | * @use_dma: boolean to know if dma is used in the current transfer | 280 | * @use_dma: boolean to know if dma is used in the current transfer |
| 281 | * @regmap: holds SYSCFG phandle for Fast Mode Plus bits | ||
| 279 | */ | 282 | */ |
| 280 | struct stm32f7_i2c_dev { | 283 | struct stm32f7_i2c_dev { |
| 281 | struct i2c_adapter adap; | 284 | struct i2c_adapter adap; |
| @@ -296,6 +299,7 @@ struct stm32f7_i2c_dev { | |||
| 296 | bool master_mode; | 299 | bool master_mode; |
| 297 | struct stm32_i2c_dma *dma; | 300 | struct stm32_i2c_dma *dma; |
| 298 | bool use_dma; | 301 | bool use_dma; |
| 302 | struct regmap *regmap; | ||
| 299 | }; | 303 | }; |
| 300 | 304 | ||
| 301 | /** | 305 | /** |
| @@ -1763,6 +1767,30 @@ static int stm32f7_i2c_unreg_slave(struct i2c_client *slave) | |||
| 1763 | return 0; | 1767 | return 0; |
| 1764 | } | 1768 | } |
| 1765 | 1769 | ||
| 1770 | static int stm32f7_i2c_setup_fm_plus_bits(struct platform_device *pdev, | ||
| 1771 | struct stm32f7_i2c_dev *i2c_dev) | ||
| 1772 | { | ||
| 1773 | struct device_node *np = pdev->dev.of_node; | ||
| 1774 | int ret; | ||
| 1775 | u32 reg, mask; | ||
| 1776 | |||
| 1777 | i2c_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg-fmp"); | ||
| 1778 | if (IS_ERR(i2c_dev->regmap)) { | ||
| 1779 | /* Optional */ | ||
| 1780 | return 0; | ||
| 1781 | } | ||
| 1782 | |||
| 1783 | ret = of_property_read_u32_index(np, "st,syscfg-fmp", 1, ®); | ||
| 1784 | if (ret) | ||
| 1785 | return ret; | ||
| 1786 | |||
| 1787 | ret = of_property_read_u32_index(np, "st,syscfg-fmp", 2, &mask); | ||
| 1788 | if (ret) | ||
| 1789 | return ret; | ||
| 1790 | |||
| 1791 | return regmap_update_bits(i2c_dev->regmap, reg, mask, mask); | ||
| 1792 | } | ||
| 1793 | |||
| 1766 | static u32 stm32f7_i2c_func(struct i2c_adapter *adap) | 1794 | static u32 stm32f7_i2c_func(struct i2c_adapter *adap) |
| 1767 | { | 1795 | { |
| 1768 | return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SLAVE | | 1796 | return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR | I2C_FUNC_SLAVE | |
| @@ -1828,12 +1856,16 @@ static int stm32f7_i2c_probe(struct platform_device *pdev) | |||
| 1828 | i2c_dev->speed = STM32_I2C_SPEED_STANDARD; | 1856 | i2c_dev->speed = STM32_I2C_SPEED_STANDARD; |
| 1829 | ret = device_property_read_u32(&pdev->dev, "clock-frequency", | 1857 | ret = device_property_read_u32(&pdev->dev, "clock-frequency", |
| 1830 | &clk_rate); | 1858 | &clk_rate); |
| 1831 | if (!ret && clk_rate >= 1000000) | 1859 | if (!ret && clk_rate >= 1000000) { |
| 1832 | i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS; | 1860 | i2c_dev->speed = STM32_I2C_SPEED_FAST_PLUS; |
| 1833 | else if (!ret && clk_rate >= 400000) | 1861 | ret = stm32f7_i2c_setup_fm_plus_bits(pdev, i2c_dev); |
| 1862 | if (ret) | ||
| 1863 | goto clk_free; | ||
| 1864 | } else if (!ret && clk_rate >= 400000) { | ||
| 1834 | i2c_dev->speed = STM32_I2C_SPEED_FAST; | 1865 | i2c_dev->speed = STM32_I2C_SPEED_FAST; |
| 1835 | else if (!ret && clk_rate >= 100000) | 1866 | } else if (!ret && clk_rate >= 100000) { |
| 1836 | i2c_dev->speed = STM32_I2C_SPEED_STANDARD; | 1867 | i2c_dev->speed = STM32_I2C_SPEED_STANDARD; |
| 1868 | } | ||
| 1837 | 1869 | ||
| 1838 | rst = devm_reset_control_get(&pdev->dev, NULL); | 1870 | rst = devm_reset_control_get(&pdev->dev, NULL); |
| 1839 | if (IS_ERR(rst)) { | 1871 | if (IS_ERR(rst)) { |
