aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/i2c/busses/i2c-stm32.h20
-rw-r--r--drivers/i2c/busses/i2c-stm32f4.c18
2 files changed, 27 insertions, 11 deletions
diff --git a/drivers/i2c/busses/i2c-stm32.h b/drivers/i2c/busses/i2c-stm32.h
new file mode 100644
index 000000000000..dab51761f8c5
--- /dev/null
+++ b/drivers/i2c/busses/i2c-stm32.h
@@ -0,0 +1,20 @@
1/*
2 * i2c-stm32.h
3 *
4 * Copyright (C) M'boumba Cedric Madianga 2017
5 * Author: M'boumba Cedric Madianga <cedric.madianga@gmail.com>
6 *
7 * License terms: GNU General Public License (GPL), version 2
8 */
9
10#ifndef _I2C_STM32_H
11#define _I2C_STM32_H
12
13enum stm32_i2c_speed {
14 STM32_I2C_SPEED_STANDARD, /* 100 kHz */
15 STM32_I2C_SPEED_FAST, /* 400 kHz */
16 STM32_I2C_SPEED_FAST_PLUS, /* 1 MHz */
17 STM32_I2C_SPEED_END,
18};
19
20#endif /* _I2C_STM32_H */
diff --git a/drivers/i2c/busses/i2c-stm32f4.c b/drivers/i2c/busses/i2c-stm32f4.c
index aceb6f788564..4ec108496f15 100644
--- a/drivers/i2c/busses/i2c-stm32f4.c
+++ b/drivers/i2c/busses/i2c-stm32f4.c
@@ -27,6 +27,8 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/reset.h> 28#include <linux/reset.h>
29 29
30#include "i2c-stm32.h"
31
30/* STM32F4 I2C offset registers */ 32/* STM32F4 I2C offset registers */
31#define STM32F4_I2C_CR1 0x00 33#define STM32F4_I2C_CR1 0x00
32#define STM32F4_I2C_CR2 0x04 34#define STM32F4_I2C_CR2 0x04
@@ -90,12 +92,6 @@
90#define STM32F4_I2C_MAX_FREQ 46U 92#define STM32F4_I2C_MAX_FREQ 46U
91#define HZ_TO_MHZ 1000000 93#define HZ_TO_MHZ 1000000
92 94
93enum stm32f4_i2c_speed {
94 STM32F4_I2C_SPEED_STANDARD, /* 100 kHz */
95 STM32F4_I2C_SPEED_FAST, /* 400 kHz */
96 STM32F4_I2C_SPEED_END,
97};
98
99/** 95/**
100 * struct stm32f4_i2c_msg - client specific data 96 * struct stm32f4_i2c_msg - client specific data
101 * @addr: 8-bit slave addr, including r/w bit 97 * @addr: 8-bit slave addr, including r/w bit
@@ -159,7 +155,7 @@ static int stm32f4_i2c_set_periph_clk_freq(struct stm32f4_i2c_dev *i2c_dev)
159 i2c_dev->parent_rate = clk_get_rate(i2c_dev->clk); 155 i2c_dev->parent_rate = clk_get_rate(i2c_dev->clk);
160 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ); 156 freq = DIV_ROUND_UP(i2c_dev->parent_rate, HZ_TO_MHZ);
161 157
162 if (i2c_dev->speed == STM32F4_I2C_SPEED_STANDARD) { 158 if (i2c_dev->speed == STM32_I2C_SPEED_STANDARD) {
163 /* 159 /*
164 * To reach 100 kHz, the parent clk frequency should be between 160 * To reach 100 kHz, the parent clk frequency should be between
165 * a minimum value of 2 MHz and a maximum value of 46 MHz due 161 * a minimum value of 2 MHz and a maximum value of 46 MHz due
@@ -216,7 +212,7 @@ static void stm32f4_i2c_set_rise_time(struct stm32f4_i2c_dev *i2c_dev)
216 * is not higher than 46 MHz . As a result trise is at most 4 bits wide 212 * is not higher than 46 MHz . As a result trise is at most 4 bits wide
217 * and so fits into the TRISE bits [5:0]. 213 * and so fits into the TRISE bits [5:0].
218 */ 214 */
219 if (i2c_dev->speed == STM32F4_I2C_SPEED_STANDARD) 215 if (i2c_dev->speed == STM32_I2C_SPEED_STANDARD)
220 trise = freq + 1; 216 trise = freq + 1;
221 else 217 else
222 trise = freq * 3 / 10 + 1; 218 trise = freq * 3 / 10 + 1;
@@ -230,7 +226,7 @@ static void stm32f4_i2c_set_speed_mode(struct stm32f4_i2c_dev *i2c_dev)
230 u32 val; 226 u32 val;
231 u32 ccr = 0; 227 u32 ccr = 0;
232 228
233 if (i2c_dev->speed == STM32F4_I2C_SPEED_STANDARD) { 229 if (i2c_dev->speed == STM32_I2C_SPEED_STANDARD) {
234 /* 230 /*
235 * In standard mode: 231 * In standard mode:
236 * t_scl_high = t_scl_low = CCR * I2C parent clk period 232 * t_scl_high = t_scl_low = CCR * I2C parent clk period
@@ -808,10 +804,10 @@ static int stm32f4_i2c_probe(struct platform_device *pdev)
808 udelay(2); 804 udelay(2);
809 reset_control_deassert(rst); 805 reset_control_deassert(rst);
810 806
811 i2c_dev->speed = STM32F4_I2C_SPEED_STANDARD; 807 i2c_dev->speed = STM32_I2C_SPEED_STANDARD;
812 ret = of_property_read_u32(np, "clock-frequency", &clk_rate); 808 ret = of_property_read_u32(np, "clock-frequency", &clk_rate);
813 if (!ret && clk_rate >= 400000) 809 if (!ret && clk_rate >= 400000)
814 i2c_dev->speed = STM32F4_I2C_SPEED_FAST; 810 i2c_dev->speed = STM32_I2C_SPEED_FAST;
815 811
816 i2c_dev->dev = &pdev->dev; 812 i2c_dev->dev = &pdev->dev;
817 813