* [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller
@ 2014-09-30 10:04 Mika Westerberg
2014-09-30 10:04 ` [PATCH v2 3/3] " Mika Westerberg
[not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
0 siblings, 2 replies; 6+ messages in thread
From: Mika Westerberg @ 2014-09-30 10:04 UTC (permalink / raw)
To: Wolfram Sang
Cc: Carl Peng, Huang Rui, Christian Ruppert, Romain Baeriswyl,
linux-i2c, linux-kernel, Mika Westerberg
This is second iteration of the patch series. First version is here:
http://patchwork.ozlabs.org/patch/390694/
http://patchwork.ozlabs.org/patch/390695/
In order to get source clock to the core driver we need some way of
creating it in the first place. For Intel LPSS it is done in
drivers/acpi/acpi_lpss.c but that is not applicable for AMD I2C host
controller which is too different from private parts to the LPSS one.
We solve this by creating the clock in ACPI parts of the platform driver
when we detect the AMD I2C host controller. Doing this requires small
refactoring to be done to the probe() which is what patches [1-2/3] are
doing.
Changes to the previous version:
* Rebased on top of i2c/for-next branch
* New patch defaulting ACPI probe to fast mode
* Instead of direct dependency to COMMON_CLK we depend on (ACPI &&
COMMON_CLK) || ACPI. (suggested by Wolfram)
Carl, can you test that this still works on your machine?
Carl Peng (1):
i2c: designware: Add support for AMD I2C controller
Mika Westerberg (2):
i2c: designware: Default to fast mode in case of ACPI
i2c: designware: Rework probe() to get clock a bit later
drivers/i2c/busses/Kconfig | 1 +
drivers/i2c/busses/i2c-designware-platdrv.c | 71 +++++++++++++++++++----------
2 files changed, 48 insertions(+), 24 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v2 3/3] i2c: designware: Add support for AMD I2C controller 2014-09-30 10:04 [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller Mika Westerberg @ 2014-09-30 10:04 ` Mika Westerberg [not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 1 sibling, 0 replies; 6+ messages in thread From: Mika Westerberg @ 2014-09-30 10:04 UTC (permalink / raw) To: Wolfram Sang Cc: Carl Peng, Huang Rui, Christian Ruppert, Romain Baeriswyl, linux-i2c, linux-kernel, Mika Westerberg From: Carl Peng <carlpeng008@gmail.com> Add support for AMD version of the DW I2C host controller. The device is enumerated from ACPI namespace with ACPI ID AMD0010. Because the core driver needs an input source clock, and this is not an Intel LPSS device where clocks are provided through drivers/acpi/acpi_lpss.c, we register the clock ourselves if the clock rate is given in ->driver_data Signed-off-by: Carl Peng <carlpeng008@gmail.com> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> --- drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-designware-platdrv.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 2ac87fa3058d..0715a239c87f 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -423,6 +423,7 @@ config I2C_DESIGNWARE_CORE config I2C_DESIGNWARE_PLATFORM tristate "Synopsys DesignWare Platform" select I2C_DESIGNWARE_CORE + depends on (ACPI && COMMON_CLK) || !ACPI help If you say yes to this option, support will be included for the Synopsys DesignWare I2C adapter. Only master mode is supported. diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index e59c63ae4d41..a7431150acf7 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -30,6 +30,7 @@ #include <linux/delay.h> #include <linux/i2c.h> #include <linux/clk.h> +#include <linux/clk-provider.h> #include <linux/errno.h> #include <linux/sched.h> #include <linux/err.h> @@ -80,6 +81,7 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[], static int dw_i2c_acpi_configure(struct platform_device *pdev) { struct dw_i2c_dev *dev = platform_get_drvdata(pdev); + const struct acpi_device_id *id; dev->adapter.nr = -1; dev->tx_fifo_depth = 32; @@ -93,9 +95,29 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev) dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, &dev->sda_hold_time); + /* + * Provide a way for Designware I2C host controllers that are not + * based on Intel LPSS to specify their input clock frequency via + * id->driver_data. + */ + id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); + if (id && id->driver_data) + clk_register_fixed_rate(&pdev->dev, dev_name(&pdev->dev), NULL, + CLK_IS_ROOT, id->driver_data); + return 0; } +static void dw_i2c_acpi_unconfigure(struct platform_device *pdev) +{ + struct dw_i2c_dev *dev = platform_get_drvdata(pdev); + const struct acpi_device_id *id; + + id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); + if (id && id->driver_data) + clk_unregister(dev->clk); +} + static const struct acpi_device_id dw_i2c_acpi_match[] = { { "INT33C2", 0 }, { "INT33C3", 0 }, @@ -103,6 +125,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = { { "INT3433", 0 }, { "80860F41", 0 }, { "808622C1", 0 }, + { "AMD0010", 133 * 1000 * 1000 }, { } }; MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match); @@ -111,6 +134,7 @@ static inline int dw_i2c_acpi_configure(struct platform_device *pdev) { return -ENODEV; } +static inline void dw_i2c_acpi_unconfigure(struct platform_device *pdev) { } #endif static int dw_i2c_probe(struct platform_device *pdev) @@ -258,6 +282,9 @@ static int dw_i2c_remove(struct platform_device *pdev) pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); + if (ACPI_COMPANION(&pdev->dev)) + dw_i2c_acpi_unconfigure(pdev); + return 0; } -- 2.1.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
[parent not found: <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* [PATCH v2 1/3] i2c: designware: Default to fast mode in case of ACPI [not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> @ 2014-09-30 10:04 ` Mika Westerberg 2014-09-30 10:04 ` [PATCH v2 2/3] i2c: designware: Rework probe() to get clock a bit later Mika Westerberg ` (2 subsequent siblings) 3 siblings, 0 replies; 6+ messages in thread From: Mika Westerberg @ 2014-09-30 10:04 UTC (permalink / raw) To: Wolfram Sang Cc: Carl Peng, Huang Rui, Christian Ruppert, Romain Baeriswyl, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Mika Westerberg There is no way in ACPI to tell in which speed the host controller is supposed to run, so we default to fast mode (400KHz). Since this has been the default all the time there should be no functional changes with this change. This is the first step required to refactor the driver probe so that we can supply source clock from ACPI part of the driver to the core. Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/i2c/busses/i2c-designware-platdrv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 4d6a6b94e2fa..353adc4dc583 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -80,7 +80,6 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, char method[], static int dw_i2c_acpi_configure(struct platform_device *pdev) { struct dw_i2c_dev *dev = platform_get_drvdata(pdev); - bool fs_mode = dev->master_cfg & DW_IC_CON_SPEED_FAST; if (!ACPI_HANDLE(&pdev->dev)) return -ENODEV; @@ -93,10 +92,9 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev) * Try to get SDA hold time and *CNT values from an ACPI method if * it exists for both supported speed modes. */ - dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt, - fs_mode ? NULL : &dev->sda_hold_time); + dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt, NULL); dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt, - fs_mode ? &dev->sda_hold_time : NULL); + &dev->sda_hold_time); return 0; } -- 2.1.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] i2c: designware: Rework probe() to get clock a bit later [not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2014-09-30 10:04 ` [PATCH v2 1/3] i2c: designware: Default to fast mode in case of ACPI Mika Westerberg @ 2014-09-30 10:04 ` Mika Westerberg 2014-10-03 0:46 ` [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller Wolfram Sang 2014-10-06 17:51 ` Wolfram Sang 3 siblings, 0 replies; 6+ messages in thread From: Mika Westerberg @ 2014-09-30 10:04 UTC (permalink / raw) To: Wolfram Sang Cc: Carl Peng, Huang Rui, Christian Ruppert, Romain Baeriswyl, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Mika Westerberg In order to be able to create missing clock for AMD (and in future possibly others) we move getting clock for the device a bit later. Also make ACPI/DT configuration in the same place depending on from where the device was enumerated from. Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/i2c/busses/i2c-designware-platdrv.c | 38 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 353adc4dc583..e59c63ae4d41 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -81,9 +81,6 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev) { struct dw_i2c_dev *dev = platform_get_drvdata(pdev); - if (!ACPI_HANDLE(&pdev->dev)) - return -ENODEV; - dev->adapter.nr = -1; dev->tx_fifo_depth = 32; dev->rx_fifo_depth = 32; @@ -123,7 +120,7 @@ static int dw_i2c_probe(struct platform_device *pdev) struct resource *mem; struct dw_i2c_platform_data *pdata; int irq, r; - u32 clk_freq; + u32 clk_freq, ht = 0; irq = platform_get_irq(pdev, 0); if (irq < 0) { @@ -146,24 +143,14 @@ static int dw_i2c_probe(struct platform_device *pdev) dev->irq = irq; platform_set_drvdata(pdev, dev); - dev->clk = devm_clk_get(&pdev->dev, NULL); - dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; - - if (IS_ERR(dev->clk)) - return PTR_ERR(dev->clk); - clk_prepare_enable(dev->clk); - /* fast mode by default because of legacy reasons */ clk_freq = 400000; - if (pdev->dev.of_node) { - u32 ht = 0; - u32 ic_clk = dev->get_clk_rate_khz(dev); - + if (ACPI_COMPANION(&pdev->dev)) { + dw_i2c_acpi_configure(pdev); + } else if (pdev->dev.of_node) { of_property_read_u32(pdev->dev.of_node, "i2c-sda-hold-time-ns", &ht); - dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000, - 1000000); of_property_read_u32(pdev->dev.of_node, "i2c-sda-falling-time-ns", @@ -202,9 +189,20 @@ static int dw_i2c_probe(struct platform_device *pdev) dev->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; - /* Try first if we can configure the device from ACPI */ - r = dw_i2c_acpi_configure(pdev); - if (r) { + dev->clk = devm_clk_get(&pdev->dev, NULL); + dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz; + if (IS_ERR(dev->clk)) + return PTR_ERR(dev->clk); + clk_prepare_enable(dev->clk); + + if (!dev->sda_hold_time && ht) { + u32 ic_clk = dev->get_clk_rate_khz(dev); + + dev->sda_hold_time = div_u64((u64)ic_clk * ht + 500000, + 1000000); + } + + if (!dev->tx_fifo_depth) { u32 param1 = i2c_dw_read_comp_param(dev); dev->tx_fifo_depth = ((param1 >> 16) & 0xff) + 1; -- 2.1.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller [not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2014-09-30 10:04 ` [PATCH v2 1/3] i2c: designware: Default to fast mode in case of ACPI Mika Westerberg 2014-09-30 10:04 ` [PATCH v2 2/3] i2c: designware: Rework probe() to get clock a bit later Mika Westerberg @ 2014-10-03 0:46 ` Wolfram Sang 2014-10-06 17:51 ` Wolfram Sang 3 siblings, 0 replies; 6+ messages in thread From: Wolfram Sang @ 2014-10-03 0:46 UTC (permalink / raw) To: Mika Westerberg Cc: Carl Peng, Huang Rui, Christian Ruppert, Romain Baeriswyl, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 1154 bytes --] On Tue, Sep 30, 2014 at 01:04:52PM +0300, Mika Westerberg wrote: > This is second iteration of the patch series. First version is here: > > http://patchwork.ozlabs.org/patch/390694/ > http://patchwork.ozlabs.org/patch/390695/ > > In order to get source clock to the core driver we need some way of > creating it in the first place. For Intel LPSS it is done in > drivers/acpi/acpi_lpss.c but that is not applicable for AMD I2C host > controller which is too different from private parts to the LPSS one. > > We solve this by creating the clock in ACPI parts of the platform driver > when we detect the AMD I2C host controller. Doing this requires small > refactoring to be done to the probe() which is what patches [1-2/3] are > doing. > > Changes to the previous version: > * Rebased on top of i2c/for-next branch > * New patch defaulting ACPI probe to fast mode > * Instead of direct dependency to COMMON_CLK we depend on (ACPI && > COMMON_CLK) || ACPI. (suggested by Wolfram) > > Carl, can you test that this still works on your machine? Yes, Carl that would be helpful. Patches look good to me. Thanks! [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller [not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> ` (2 preceding siblings ...) 2014-10-03 0:46 ` [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller Wolfram Sang @ 2014-10-06 17:51 ` Wolfram Sang 3 siblings, 0 replies; 6+ messages in thread From: Wolfram Sang @ 2014-10-06 17:51 UTC (permalink / raw) To: Mika Westerberg Cc: Carl Peng, Huang Rui, Christian Ruppert, Romain Baeriswyl, linux-i2c-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 1398 bytes --] On Tue, Sep 30, 2014 at 01:04:52PM +0300, Mika Westerberg wrote: > This is second iteration of the patch series. First version is here: > > http://patchwork.ozlabs.org/patch/390694/ > http://patchwork.ozlabs.org/patch/390695/ > > In order to get source clock to the core driver we need some way of > creating it in the first place. For Intel LPSS it is done in > drivers/acpi/acpi_lpss.c but that is not applicable for AMD I2C host > controller which is too different from private parts to the LPSS one. > > We solve this by creating the clock in ACPI parts of the platform driver > when we detect the AMD I2C host controller. Doing this requires small > refactoring to be done to the probe() which is what patches [1-2/3] are > doing. > > Changes to the previous version: > * Rebased on top of i2c/for-next branch > * New patch defaulting ACPI probe to fast mode > * Instead of direct dependency to COMMON_CLK we depend on (ACPI && > COMMON_CLK) || ACPI. (suggested by Wolfram) > > Carl, can you test that this still works on your machine? > > Carl Peng (1): > i2c: designware: Add support for AMD I2C controller > > Mika Westerberg (2): > i2c: designware: Default to fast mode in case of ACPI > i2c: designware: Rework probe() to get clock a bit later > > drivers/i2c/busses/Kconfig | 1 + Applied to for-next, thanks! [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 819 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-10-06 17:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-30 10:04 [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller Mika Westerberg
2014-09-30 10:04 ` [PATCH v2 3/3] " Mika Westerberg
[not found] ` <1412071495-15323-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2014-09-30 10:04 ` [PATCH v2 1/3] i2c: designware: Default to fast mode in case of ACPI Mika Westerberg
2014-09-30 10:04 ` [PATCH v2 2/3] i2c: designware: Rework probe() to get clock a bit later Mika Westerberg
2014-10-03 0:46 ` [PATCH v2 0/3] i2c: designware: Add support for AMD I2C controller Wolfram Sang
2014-10-06 17:51 ` Wolfram Sang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).