Commit e3ea52b5 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Wolfram Sang

i2c: designware: 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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Tested-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 4717be73
...@@ -212,7 +212,8 @@ ...@@ -212,7 +212,8 @@
* @tx_fifo_depth: depth of the hardware tx fifo * @tx_fifo_depth: depth of the hardware tx fifo
* @rx_fifo_depth: depth of the hardware rx fifo * @rx_fifo_depth: depth of the hardware rx fifo
* @rx_outstanding: current master-rx elements in tx fifo * @rx_outstanding: current master-rx elements in tx fifo
* @clk_freq: bus clock frequency * @timings: bus clock frequency, SDA hold and other timings
* @sda_hold_time: SDA hold value
* @ss_hcnt: standard speed HCNT value * @ss_hcnt: standard speed HCNT value
* @ss_lcnt: standard speed LCNT value * @ss_lcnt: standard speed LCNT value
* @fs_hcnt: fast speed HCNT value * @fs_hcnt: fast speed HCNT value
...@@ -264,10 +265,8 @@ struct dw_i2c_dev { ...@@ -264,10 +265,8 @@ struct dw_i2c_dev {
unsigned int tx_fifo_depth; unsigned int tx_fifo_depth;
unsigned int rx_fifo_depth; unsigned int rx_fifo_depth;
int rx_outstanding; int rx_outstanding;
u32 clk_freq; struct i2c_timings timings;
u32 sda_hold_time; u32 sda_hold_time;
u32 sda_falling_time;
u32 scl_falling_time;
u16 ss_hcnt; u16 ss_hcnt;
u16 ss_lcnt; u16 ss_lcnt;
u16 fs_hcnt; u16 fs_hcnt;
......
...@@ -51,6 +51,7 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev) ...@@ -51,6 +51,7 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
const char *mode_str, *fp_str = ""; const char *mode_str, *fp_str = "";
u32 comp_param1; u32 comp_param1;
u32 sda_falling_time, scl_falling_time; u32 sda_falling_time, scl_falling_time;
struct i2c_timings *t = &dev->timings;
int ret; int ret;
ret = i2c_dw_acquire_lock(dev); ret = i2c_dw_acquire_lock(dev);
...@@ -60,8 +61,8 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev) ...@@ -60,8 +61,8 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
i2c_dw_release_lock(dev); i2c_dw_release_lock(dev);
/* Set standard and fast speed dividers for high/low periods */ /* Set standard and fast speed dividers for high/low periods */
sda_falling_time = dev->sda_falling_time ?: 300; /* ns */ sda_falling_time = t->sda_fall_ns ?: 300; /* ns */
scl_falling_time = dev->scl_falling_time ?: 300; /* ns */ scl_falling_time = t->scl_fall_ns ?: 300; /* ns */
/* Calculate SCL timing parameters for standard mode if not set */ /* Calculate SCL timing parameters for standard mode if not set */
if (!dev->ss_hcnt || !dev->ss_lcnt) { if (!dev->ss_hcnt || !dev->ss_lcnt) {
...@@ -85,7 +86,7 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev) ...@@ -85,7 +86,7 @@ static int i2c_dw_set_timings_master(struct dw_i2c_dev *dev)
* difference is the timing parameter values since the registers are * difference is the timing parameter values since the registers are
* the same. * the same.
*/ */
if (dev->clk_freq == 1000000) { if (t->bus_freq_hz == 1000000) {
/* /*
* Check are fast mode plus parameters available and use * Check are fast mode plus parameters available and use
* fast mode if not. * fast mode if not.
......
...@@ -96,6 +96,7 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[], ...@@ -96,6 +96,7 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[],
static int dw_i2c_acpi_configure(struct platform_device *pdev) static int dw_i2c_acpi_configure(struct platform_device *pdev)
{ {
struct dw_i2c_dev *dev = platform_get_drvdata(pdev); struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
struct i2c_timings *t = &dev->timings;
u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0; u32 ss_ht = 0, fp_ht = 0, hs_ht = 0, fs_ht = 0;
acpi_handle handle = ACPI_HANDLE(&pdev->dev); acpi_handle handle = ACPI_HANDLE(&pdev->dev);
const struct acpi_device_id *id; const struct acpi_device_id *id;
...@@ -115,7 +116,7 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev) ...@@ -115,7 +116,7 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt, &hs_ht); dw_i2c_acpi_params(pdev, "HSCN", &dev->hs_hcnt, &dev->hs_lcnt, &hs_ht);
dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht); dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &fs_ht);
switch (dev->clk_freq) { switch (t->bus_freq_hz) {
case 100000: case 100000:
dev->sda_hold_time = ss_ht; dev->sda_hold_time = ss_ht;
break; break;
...@@ -175,6 +176,8 @@ static inline int dw_i2c_acpi_configure(struct platform_device *pdev) ...@@ -175,6 +176,8 @@ static inline int dw_i2c_acpi_configure(struct platform_device *pdev)
static void i2c_dw_configure_master(struct dw_i2c_dev *dev) static void i2c_dw_configure_master(struct dw_i2c_dev *dev)
{ {
struct i2c_timings *t = &dev->timings;
dev->functionality = I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY; dev->functionality = I2C_FUNC_10BIT_ADDR | DW_IC_DEFAULT_FUNCTIONALITY;
dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
...@@ -182,7 +185,7 @@ static void i2c_dw_configure_master(struct dw_i2c_dev *dev) ...@@ -182,7 +185,7 @@ static void i2c_dw_configure_master(struct dw_i2c_dev *dev)
dev->mode = DW_IC_MASTER; dev->mode = DW_IC_MASTER;
switch (dev->clk_freq) { switch (t->bus_freq_hz) {
case 100000: case 100000:
dev->master_cfg |= DW_IC_CON_SPEED_STD; dev->master_cfg |= DW_IC_CON_SPEED_STD;
break; break;
...@@ -240,7 +243,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -240,7 +243,8 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev); struct dw_i2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
struct i2c_adapter *adap; struct i2c_adapter *adap;
struct dw_i2c_dev *dev; struct dw_i2c_dev *dev;
u32 acpi_speed, ht = 0; struct i2c_timings *t;
u32 acpi_speed;
struct resource *mem; struct resource *mem;
int i, irq, ret; int i, irq, ret;
static const int supported_speeds[] = { static const int supported_speeds[] = {
...@@ -272,18 +276,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -272,18 +276,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
reset_control_deassert(dev->rst); reset_control_deassert(dev->rst);
} }
if (pdata) { t = &dev->timings;
dev->clk_freq = pdata->i2c_scl_freq; if (pdata)
} else { t->bus_freq_hz = pdata->i2c_scl_freq;
device_property_read_u32(&pdev->dev, "i2c-sda-hold-time-ns", else
&ht); i2c_parse_fw_timings(&pdev->dev, t, false);
device_property_read_u32(&pdev->dev, "i2c-sda-falling-time-ns",
&dev->sda_falling_time);
device_property_read_u32(&pdev->dev, "i2c-scl-falling-time-ns",
&dev->scl_falling_time);
device_property_read_u32(&pdev->dev, "clock-frequency",
&dev->clk_freq);
}
acpi_speed = i2c_acpi_find_bus_speed(&pdev->dev); acpi_speed = i2c_acpi_find_bus_speed(&pdev->dev);
/* /*
...@@ -300,12 +297,12 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -300,12 +297,12 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
* Find bus speed from the "clock-frequency" device property, ACPI * Find bus speed from the "clock-frequency" device property, ACPI
* or by using fast mode if neither is set. * or by using fast mode if neither is set.
*/ */
if (acpi_speed && dev->clk_freq) if (acpi_speed && t->bus_freq_hz)
dev->clk_freq = min(dev->clk_freq, acpi_speed); t->bus_freq_hz = min(t->bus_freq_hz, acpi_speed);
else if (acpi_speed || dev->clk_freq) else if (acpi_speed || t->bus_freq_hz)
dev->clk_freq = max(dev->clk_freq, acpi_speed); t->bus_freq_hz = max(t->bus_freq_hz, acpi_speed);
else else
dev->clk_freq = 400000; t->bus_freq_hz = 400000;
if (has_acpi_companion(&pdev->dev)) if (has_acpi_companion(&pdev->dev))
dw_i2c_acpi_configure(pdev); dw_i2c_acpi_configure(pdev);
...@@ -314,11 +311,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -314,11 +311,11 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
* Only standard mode at 100kHz, fast mode at 400kHz, * Only standard mode at 100kHz, fast mode at 400kHz,
* fast mode plus at 1MHz and high speed mode at 3.4MHz are supported. * fast mode plus at 1MHz and high speed mode at 3.4MHz are supported.
*/ */
if (dev->clk_freq != 100000 && dev->clk_freq != 400000 if (t->bus_freq_hz != 100000 && t->bus_freq_hz != 400000 &&
&& dev->clk_freq != 1000000 && dev->clk_freq != 3400000) { t->bus_freq_hz != 1000000 && t->bus_freq_hz != 3400000) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n", "%d Hz is unsupported, only 100kHz, 400kHz, 1MHz and 3.4MHz are supported\n",
dev->clk_freq); t->bus_freq_hz);
ret = -EINVAL; ret = -EINVAL;
goto exit_reset; goto exit_reset;
} }
...@@ -334,12 +331,14 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) ...@@ -334,12 +331,14 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
dev->clk = devm_clk_get(&pdev->dev, NULL); dev->clk = devm_clk_get(&pdev->dev, NULL);
if (!i2c_dw_prepare_clk(dev, true)) { if (!i2c_dw_prepare_clk(dev, true)) {
u64 clk_khz;
dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz;
clk_khz = dev->get_clk_rate_khz(dev);
if (!dev->sda_hold_time && ht) if (!dev->sda_hold_time && t->sda_hold_ns)
dev->sda_hold_time = div_u64( dev->sda_hold_time =
(u64)dev->get_clk_rate_khz(dev) * ht + 500000, div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000);
1000000);
} }
dw_i2c_set_fifo_size(dev, pdev->id); dw_i2c_set_fifo_size(dev, pdev->id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment