Skip to content

Commit 265bd82

Browse files
andy-shevWolfram Sang
authored andcommitted
i2c: at91: Convert to use struct i2c_timings
Instead of using custom variables and parser, convert the driver to use the ones provided by I2C core. No functional change intended. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Ludovic Desroches <ludovic.desroches@microchip.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent 529766e commit 265bd82

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

drivers/i2c/busses/i2c-at91-master.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ void at91_init_twi_bus_master(struct at91_twi_dev *dev)
4343
* Calculate symmetric clock as stated in datasheet:
4444
* twi_clk = F_MAIN / (2 * (cdiv * (1 << ckdiv) + offset))
4545
*/
46-
static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
46+
static void at91_calc_twi_clock(struct at91_twi_dev *dev)
4747
{
4848
int ckdiv, cdiv, div, hold = 0;
4949
struct at91_twi_pdata *pdata = dev->pdata;
5050
int offset = pdata->clk_offset;
5151
int max_ckdiv = pdata->clk_max_div;
52-
u32 twd_hold_time_ns = 0;
52+
struct i2c_timings timings, *t = &timings;
53+
54+
i2c_parse_fw_timings(dev->dev, t, true);
5355

5456
div = max(0, (int)DIV_ROUND_UP(clk_get_rate(dev->clk),
55-
2 * twi_clk) - offset);
57+
2 * t->bus_freq_hz) - offset);
5658
ckdiv = fls(div >> 8);
5759
cdiv = div >> ckdiv;
5860

@@ -64,15 +66,12 @@ static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
6466
}
6567

6668
if (pdata->has_hold_field) {
67-
of_property_read_u32(dev->dev->of_node, "i2c-sda-hold-time-ns",
68-
&twd_hold_time_ns);
69-
7069
/*
7170
* hold time = HOLD + 3 x T_peripheral_clock
7271
* Use clk rate in kHz to prevent overflows when computing
7372
* hold.
7473
*/
75-
hold = DIV_ROUND_UP(twd_hold_time_ns
74+
hold = DIV_ROUND_UP(t->sda_hold_ns
7675
* (clk_get_rate(dev->clk) / 1000), 1000000);
7776
hold -= 3;
7877
if (hold < 0)
@@ -89,7 +88,7 @@ static void at91_calc_twi_clock(struct at91_twi_dev *dev, int twi_clk)
8988
| AT91_TWI_CWGR_HOLD(hold);
9089

9190
dev_dbg(dev->dev, "cdiv %d ckdiv %d hold %d (%d ns)\n",
92-
cdiv, ckdiv, hold, twd_hold_time_ns);
91+
cdiv, ckdiv, hold, t->sda_hold_ns);
9392
}
9493

9594
static void at91_twi_dma_cleanup(struct at91_twi_dev *dev)
@@ -772,7 +771,6 @@ int at91_twi_probe_master(struct platform_device *pdev,
772771
u32 phy_addr, struct at91_twi_dev *dev)
773772
{
774773
int rc;
775-
u32 bus_clk_rate;
776774

777775
init_completion(&dev->cmd_complete);
778776

@@ -794,12 +792,7 @@ int at91_twi_probe_master(struct platform_device *pdev,
794792
dev_info(dev->dev, "Using FIFO (%u data)\n", dev->fifo_size);
795793
}
796794

797-
rc = of_property_read_u32(dev->dev->of_node, "clock-frequency",
798-
&bus_clk_rate);
799-
if (rc)
800-
bus_clk_rate = DEFAULT_TWI_CLK_HZ;
801-
802-
at91_calc_twi_clock(dev, bus_clk_rate);
795+
at91_calc_twi_clock(dev);
803796

804797
dev->adapter.algo = &at91_twi_algorithm;
805798
dev->adapter.quirks = &at91_twi_quirks;

drivers/i2c/busses/i2c-at91.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <linux/platform_data/dma-atmel.h>
2222
#include <linux/platform_device.h>
2323

24-
#define DEFAULT_TWI_CLK_HZ 100000 /* max 400 Kbits/s */
2524
#define AT91_I2C_TIMEOUT msecs_to_jiffies(100) /* transfer timeout */
2625
#define AT91_I2C_DMA_THRESHOLD 8 /* enable DMA if transfer size is bigger than this threshold */
2726
#define AUTOSUSPEND_TIMEOUT 2000

0 commit comments

Comments
 (0)