linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/7] i2c: designware: Get rid of PCI driver specifics in common code
@ 2020-05-19 12:50 Andy Shevchenko
  2020-05-19 12:50 ` [PATCH v2 2/7] i2c: designware: Include proper headers in i2c-desingware-core.h Andy Shevchenko
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Andy Shevchenko @ 2020-05-19 12:50 UTC (permalink / raw)
  To: Jarkko Nikula, Mika Westerberg, linux-i2c, Wolfram Sang; +Cc: Andy Shevchenko

Do not spread PCI specifics over common code. It seems to be a layering
violation which can be easily avoided. Refactor PCI driver and drop
PCI specifics from common code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: new patch
 drivers/i2c/busses/i2c-designware-core.h   |  1 -
 drivers/i2c/busses/i2c-designware-pcidrv.c | 24 +++++++++++++---------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 1674caf27745..6202f9ee953d 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -232,7 +232,6 @@ struct dw_i2c_dev {
 	struct reset_control	*rst;
 	struct i2c_client		*slave;
 	u32			(*get_clk_rate_khz) (struct dw_i2c_dev *dev);
-	struct dw_pci_controller *controller;
 	int			cmd_err;
 	struct i2c_msg		*msgs;
 	int			msgs_num;
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index c762e5a11e44..c8808e5855b4 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -48,10 +48,10 @@ struct dw_pci_controller {
 	u32 bus_num;
 	u32 tx_fifo_depth;
 	u32 rx_fifo_depth;
-	u32 clk_khz;
 	u32 flags;
 	struct dw_scl_sda_cfg *scl_sda_cfg;
 	int (*setup)(struct pci_dev *pdev, struct dw_pci_controller *c);
+	u32 (*get_clk_rate_khz)(struct dw_i2c_dev *dev);
 };
 
 /* Merrifield HCNT/LCNT/SDA hold time */
@@ -80,6 +80,11 @@ static struct dw_scl_sda_cfg hsw_config = {
 	.sda_hold = 0x9,
 };
 
+static u32 mfld_get_clk_rate_khz(struct dw_i2c_dev *dev)
+{
+	return 25000;
+}
+
 static int mfld_setup(struct pci_dev *pdev, struct dw_pci_controller *c)
 {
 	struct dw_i2c_dev *dev = dev_get_drvdata(&pdev->dev);
@@ -120,13 +125,18 @@ static int mrfld_setup(struct pci_dev *pdev, struct dw_pci_controller *c)
 	return -ENODEV;
 }
 
+static u32 ehl_get_clk_rate_khz(struct dw_i2c_dev *dev)
+{
+	return 100000;
+}
+
 static struct dw_pci_controller dw_pci_controllers[] = {
 	[medfield] = {
 		.bus_num = -1,
 		.tx_fifo_depth = 32,
 		.rx_fifo_depth = 32,
-		.clk_khz      = 25000,
 		.setup = mfld_setup,
+		.get_clk_rate_khz = mfld_get_clk_rate_khz,
 	},
 	[merrifield] = {
 		.bus_num = -1,
@@ -158,7 +168,7 @@ static struct dw_pci_controller dw_pci_controllers[] = {
 		.bus_num = -1,
 		.tx_fifo_depth = 32,
 		.rx_fifo_depth = 32,
-		.clk_khz = 100000,
+		.get_clk_rate_khz = ehl_get_clk_rate_khz,
 	},
 };
 
@@ -188,11 +198,6 @@ static int i2c_dw_pci_resume(struct device *dev)
 static UNIVERSAL_DEV_PM_OPS(i2c_dw_pm_ops, i2c_dw_pci_suspend,
 			    i2c_dw_pci_resume, NULL);
 
-static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
-{
-	return dev->controller->clk_khz;
-}
-
 static int i2c_dw_pci_probe(struct pci_dev *pdev,
 			    const struct pci_device_id *id)
 {
@@ -233,8 +238,7 @@ static int i2c_dw_pci_probe(struct pci_dev *pdev,
 	if (r < 0)
 		return r;
 
-	dev->controller = controller;
-	dev->get_clk_rate_khz = i2c_dw_get_clk_rate_khz;
+	dev->get_clk_rate_khz = controller->get_clk_rate_khz;
 	dev->timings.bus_freq_hz = I2C_MAX_FAST_MODE_FREQ;
 	dev->base = pcim_iomap_table(pdev)[0];
 	dev->dev = &pdev->dev;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-22 14:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 12:50 [PATCH v2 1/7] i2c: designware: Get rid of PCI driver specifics in common code Andy Shevchenko
2020-05-19 12:50 ` [PATCH v2 2/7] i2c: designware: Include proper headers in i2c-desingware-core.h Andy Shevchenko
2020-05-19 12:50 ` [PATCH v2 3/7] i2c: designware: Move i2c_dw_validate_speed() helper to a common code Andy Shevchenko
2020-05-19 12:50 ` [PATCH v2 4/7] i2c: designware: Drop unneeded condition in i2c_dw_validate_speed() Andy Shevchenko
2020-05-19 12:50 ` [PATCH v2 5/7] i2c: designware: Move ACPI parts into common module Andy Shevchenko
2020-05-19 12:50 ` [PATCH v2 6/7] i2c: designware: Read counters from ACPI for PCI driver Andy Shevchenko
2020-05-19 12:50 ` [PATCH v2 7/7] i2c: designware: Drop hard coded FIFO depth assignment Andy Shevchenko
2020-05-20 13:55 ` [PATCH v2 1/7] i2c: designware: Get rid of PCI driver specifics in common code Jarkko Nikula
2020-05-22 10:58   ` Andy Shevchenko
2020-05-22 14:18     ` Wolfram Sang
2020-05-22 14:55 ` 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).