Add Apple M1 support to PASemi i2c driver
v2 cover Add Apple M1 support to PASemi i2c driver
Hi,
v1: https://lore.kernel.org/linux-i2c/[email protected]/
Changes for v2:
- Added reviewed-by/acks
- Switched from ioport_map to pci_iomap as suggested by Arnd Bergmann
- Renamed i2c-pasemi-apple.c to i2c-pasemi-platform.c as suggested by Wolfram Sang
- Replaced the ioport number in the adapter name with dev_name to be able to identify separate busses in e.g. i2cdetect.
I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
And for those who didn't see v1 the (almost) unchanged original cover letter:
This series adds support for the I2C controller found on Apple Silicon Macs which has quite a bit of history:
Apple bought P.A. Semi in 2008 and it looks like a part of its legacy continues to live on in the M1. This controller has actually been used since at least the iPhone 4S and hasn't changed much since then.
Essentially, there are only a few differences that matter:
- The controller no longer is a PCI device
- Starting at some iPhone an additional bit in one register must be set in order to start transmissions.
- The reference clock and hence the clock dividers are different
In order to add support for a platform device I first replaced PCI-specific bits and split out the PCI driver to its own file. Then I added support to make the clock divider configurable and converted the driver to use managed device resources to make it a bit simpler.
The Apple and PASemi driver will never be compiled in the same kernel since the Apple one will run on arm64 while the original PASemi driver will only be useful on powerpc.
I've thus followed the octeon (mips)/thunderx(arm64) approach to do the
split: I created a -core.c file which contains the shared logic and just compile that one for both the PASemi and the new Apple driver.
Best,
Sven
Sven Peter (11):
dt-bindings: i2c: Add Apple I2C controller bindings
i2c: pasemi: Use io{read,write}32
i2c: pasemi: Use dev_name instead of port number
i2c: pasemi: Remove usage of pci_dev
i2c: pasemi: Split off common probing code
i2c: pasemi: Split pci driver to its own file
i2c: pasemi: Move common reset code to own function
i2c: pasemi: Allow to configure bus frequency
i2c: pasemi: Refactor _probe to use devm_*
i2c: pasemi: Add Apple platform driver
i2c: pasemi: Set enable bit for Apple variant
.../devicetree/bindings/i2c/apple,i2c.yaml | 61 +++++++++
MAINTAINERS | 2 +
drivers/i2c/busses/Kconfig | 11 ++
drivers/i2c/busses/Makefile | 3 +
.../{i2c-pasemi.c => i2c-pasemi-core.c} | 114 +++++-----------
drivers/i2c/busses/i2c-pasemi-core.h | 21 +++
drivers/i2c/busses/i2c-pasemi-pci.c | 85 ++++++++++++
drivers/i2c/busses/i2c-pasemi-platform.c | 122 ++++++++++++++++++
8 files changed, 334 insertions(+), 85 deletions(-)
create mode 100644 Documentation/devicetree/bindings/i2c/apple,i2c.yaml
rename drivers/i2c/busses/{i2c-pasemi.c => i2c-pasemi-core.c} (77%)
create mode 100644 drivers/i2c/busses/i2c-pasemi-core.h
create mode 100644 drivers/i2c/busses/i2c-pasemi-pci.c
create mode 100644 drivers/i2c/busses/i2c-pasemi-platform.cSignature · 1 line
2.25.1
PATCH v2 1/11 dt-bindings: i2c: Add Apple I2C controller bindings
The Apple I2C controller is based on the PASemi I2C controller. It is present on Apple SoCs such as the M1.
---
v1 -> v2: no changes
.../devicetree/bindings/i2c/apple,i2c.yaml | 61 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 62 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/apple,i2c.yaml
Documentation/devicetree/bindings/i2c/apple,i2c.yaml new file +61 -0
@@ -0,0 +1,61 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/i2c/apple,i2c.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Apple/PASemi I2C controller + +maintainers: + - Sven Peter <[email protected]> + +description: | + Apple SoCs such as the M1 come with a I2C controller based on the one found + in machines with P. A. Semi's PWRficient processors. + The bus is used to communicate with e.g. USB PD chips or the speaker + amp. + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +properties: + compatible: + enum: + - apple,t8103-i2c + - apple,i2c + + reg: + maxItems: 1 + + clocks: + items: + - description: I2C bus reference clock + + interrupts: + maxItems: 1 + + clock-frequency: + description: | + Desired I2C bus clock frequency in Hz. If not specified, 100 kHz will be + used. This frequency is generated by dividing the reference clock. + Allowed values are between ref_clk/(16*4) and ref_clk/(16*255). + +required: + - compatible + - reg + - clocks + - interrupts + +unevaluatedProperties: false + +examples: + - | + i2c@35010000 { + compatible = "apple,t8103-i2c"; + reg = <0x35010000 0x4000>; + interrupt-parent = <&aic>; + interrupts = <0 627 4>; + clocks = <&ref_clk>; + #address-cells = <1>; + #size-cells = <0>; + };
MAINTAINERS +1 -0
@@ -1735,6 +1735,7 @@ B: https://github.com/AsahiLinux/linux/issues C: irc://irc.oftc.net/asahi-dev T: git https://github.com/AsahiLinux/linux.git F: Documentation/devicetree/bindings/arm/apple.yaml +F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml F: Documentation/devicetree/bindings/interrupt-controller/apple,aic.yaml F: Documentation/devicetree/bindings/pci/apple,pcie.yaml F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
Signature · 1 line
2.25.1
PATCH v2 2/11 i2c: pasemi: Use io{read,write}32
In reply to Sven PeterIn preparation for splitting this driver up into a platform_driver and a pci_driver, replace outl/inl usage with pci_iomap and ioread32/iowrite32.
---
v1 -> v2: replaced ioport_map with pci_iomap
drivers/i2c/busses/i2c-pasemi.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-pasemi.c +13 -3
@@ -20,6 +20,7 @@ static struct pci_driver pasemi_smb_driver;struct pasemi_smbus {struct pci_dev *dev;struct i2c_adapter adapter; +void __iomem *ioaddr;unsigned long base;int size; };
@@ -53,13 +54,13 @@ static inline void reg_write(struct pasemi_smbus *smbus, int reg, int val) {dev_dbg (&smbus->dev->dev,"smbus write reg %lx val %08x\n" , smbus->base + reg, val); -outl (val, smbus->base + reg); +iowrite32 (val, smbus->ioaddr + reg); }static inline int reg_read (struct pasemi_smbus *smbus,int reg) {int ret; - ret =inl (smbus->base + reg); + ret =ioread32 (smbus->ioaddr + reg);dev_dbg (&smbus->dev->dev,"smbus read reg %lx val %08x\n" , smbus->base + reg, ret);return ret;
@@ -351,6 +352,12 @@ static int pasemi_smb_probe(struct pci_dev *dev, goto out_kfree; } + smbus->ioaddr =pci_iomap (dev,0 ,0 ); +if (!smbus->ioaddr) { + error = -EBUSY ; + goto out_release_region; + } + smbus->adapter.owner =THIS_MODULE ;snprintf (smbus->adapter.name,sizeof (smbus->adapter.name),"PA Semi SMBus adapter at 0x%lx" , smbus->base);
@@ -366,12 +373,14 @@ static int pasemi_smb_probe(struct pci_dev *dev, error =i2c_add_adapter (&smbus->adapter);if (error) - goto out_release_region; + goto out_ioport_unmap;pci_set_drvdata (dev, smbus);return 0 ; + out_ioport_unmap: +pci_iounmap (dev, smbus->ioaddr); out_release_region:release_region (smbus->base, smbus->size); out_kfree:
@@ -384,6 +393,7 @@ static void pasemi_smb_remove(struct pci_dev *dev)struct pasemi_smbus *smbus =pci_get_drvdata (dev);i2c_del_adapter (&smbus->adapter); +pci_iounmap (dev, smbus->ioaddr);release_region (smbus->base, smbus->size);kfree (smbus); }
Signature · 1 line
2.25.1
PATCH v2 3/11 i2c: pasemi: Use dev_name instead of port number
In reply to Sven PeterRight now the i2c adapter name includes the port number which can indirectly be used to identify the device. Replace that with dev_name to directly identify the device and to also allow this to work correctly once we add platform support.
---
v1 -> v2: new commit
drivers/i2c/busses/i2c-pasemi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-pasemi.c +1 -1
@@ -360,7 +360,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, smbus->adapter.owner =THIS_MODULE ;snprintf (smbus->adapter.name,sizeof (smbus->adapter.name), -"PA Semi SMBus adapter at 0x%lx" , smbus->base); +"PA Semi SMBus adapter (%s)" ,dev_name (smbus->dev)); smbus->adapter.class =I2C_CLASS_HWMON |I2C_CLASS_SPD ; smbus->adapter.algo = &smbus_algorithm; smbus->adapter.algo_data = smbus;
Signature · 1 line
2.25.1
PATCH v2 4/11 i2c: pasemi: Remove usage of pci_dev
In reply to Sven PeterPrepare to create a platform driver by removing all usages of pci_dev we can.
---
v1 -> v2: no changes
drivers/i2c/busses/i2c-pasemi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-pasemi.c +6 -6
@@ -18,7 +18,7 @@static struct pci_driver pasemi_smb_driver;struct pasemi_smbus { -struct pci_dev *dev; +struct device *dev;struct i2c_adapter adapter;void __iomem *ioaddr;unsigned long base;
@@ -52,7 +52,7 @@ struct pasemi_smbus {static inline void reg_write (struct pasemi_smbus *smbus,int reg,int val) { -dev_dbg (&smbus->dev->dev,"smbus write reg %lx val %08x\n" , +dev_dbg (smbus->dev,"smbus write reg %lx val %08x\n" , smbus->base + reg, val);iowrite32 (val, smbus->ioaddr + reg); }
@@ -61,7 +61,7 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg) {int ret; ret =ioread32 (smbus->ioaddr + reg); -dev_dbg (&smbus->dev->dev,"smbus read reg %lx val %08x\n" , +dev_dbg (smbus->dev,"smbus read reg %lx val %08x\n" , smbus->base + reg, ret);return ret; }
@@ -94,7 +94,7 @@ static int pasemi_smb_waitready(struct pasemi_smbus *smbus)return -ENXIO ;if (timeout <0 ) { -dev_warn (&smbus->dev->dev,"Timeout, status 0x%08x\n" , status); +dev_warn (smbus->dev,"Timeout, status 0x%08x\n" , status);reg_write (smbus,REG_SMSTA , status);return -ETIME ; }
@@ -342,7 +342,7 @@ static int pasemi_smb_probe(struct pci_dev *dev,if (!smbus)return -ENOMEM ; - smbus->dev = dev; + smbus->dev = &dev->dev; smbus->base =pci_resource_start (dev,0 ); smbus->size =pci_resource_len (dev,0 );
@@ -366,7 +366,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, smbus->adapter.algo_data = smbus;/* set up the sysfs linkage to our parent device */ - smbus->adapter.dev.parent = &dev->dev; + smbus->adapter.dev.parent = smbus->dev;reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | (CLK_100K_DIV &CTL_CLK_M )));
Signature · 1 line
2.25.1
PATCH v2 5/11 i2c: pasemi: Split off common probing code
In reply to Sven PeterSplit off common probing code that will be used by both the PCI and the platform device.
---
v1 -> v2: no changes
drivers/i2c/busses/i2c-pasemi.c | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-)
drivers/i2c/busses/i2c-pasemi.c +25 -14
@@ -329,6 +329,30 @@ static const struct i2c_algorithm smbus_algorithm = { .functionality = pasemi_smb_func, }; +static int pasemi_i2c_common_probe (struct pasemi_smbus *smbus) +{ +int error; + + smbus->adapter.owner =THIS_MODULE ; +snprintf (smbus->adapter.name,sizeof (smbus->adapter.name), +"PA Semi SMBus adapter (%s)" ,dev_name (smbus->dev)); + smbus->adapter.class =I2C_CLASS_HWMON |I2C_CLASS_SPD ; + smbus->adapter.algo = &smbus_algorithm; + smbus->adapter.algo_data = smbus; + +/* set up the sysfs linkage to our parent device */ + smbus->adapter.dev.parent = smbus->dev; + +reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | + (CLK_100K_DIV &CTL_CLK_M ))); + + error =i2c_add_adapter (&smbus->adapter); +if (error) +return error; + +return 0 ; +} +static int pasemi_smb_probe (struct pci_dev *dev,const struct pci_device_id *id) {
@@ -358,20 +382,7 @@ static int pasemi_smb_probe(struct pci_dev *dev, goto out_release_region; } - smbus->adapter.owner =THIS_MODULE ; -snprintf (smbus->adapter.name,sizeof (smbus->adapter.name), -"PA Semi SMBus adapter (%s)" ,dev_name (smbus->dev)); - smbus->adapter.class =I2C_CLASS_HWMON |I2C_CLASS_SPD ; - smbus->adapter.algo = &smbus_algorithm; - smbus->adapter.algo_data = smbus; - -/* set up the sysfs linkage to our parent device */ - smbus->adapter.dev.parent = smbus->dev; - -reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | - (CLK_100K_DIV &CTL_CLK_M ))); - - error =i2c_add_adapter (&smbus->adapter); +int error =pasemi_i2c_common_probe (smbus);if (error) goto out_ioport_unmap;
Signature · 1 line
2.25.1
PATCH v2 6/11 i2c: pasemi: Split pci driver to its own file
In reply to Sven PeterSplit off the PCI driver so that we can reuse common code for the platform driver.
---
v1 -> v2: no changes
drivers/i2c/busses/Makefile | 1 +
.../{i2c-pasemi.c => i2c-pasemi-core.c} | 88 +----------------
drivers/i2c/busses/i2c-pasemi-core.h | 19 ++++
drivers/i2c/busses/i2c-pasemi-pci.c | 96 +++++++++++++++++++
4 files changed, 118 insertions(+), 86 deletions(-)
rename drivers/i2c/busses/{i2c-pasemi.c => i2c-pasemi-core.c} (81%)
create mode 100644 drivers/i2c/busses/i2c-pasemi-core.h
create mode 100644 drivers/i2c/busses/i2c-pasemi-pci.cdrivers/i2c/busses/Makefile +1 -0
@@ -84,6 +84,7 @@ obj-$(CONFIG_I2C_NPCM7XX) += i2c-npcm7xx.o obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o obj-$(CONFIG_I2C_OMAP) += i2c-omap.o obj-$(CONFIG_I2C_OWL) += i2c-owl.o +i2c-pasemi-objs := i2c-pasemi-core.o i2c-pasemi-pci.o obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
drivers/i2c/busses/i2c-pasemi-core.c renamed from drivers/i2c/busses/i2c-pasemi.c +2 -86
103 lines not on this page · raw message
drivers/i2c/busses/i2c-pasemi-core.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/atomic.h> +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/i2c.h> +#include <linux/i2c-smbus.h> +#include <linux/io.h> +#include <linux/kernel.h> + +struct pasemi_smbus { +struct device *dev; +struct i2c_adapter adapter; +void __iomem *ioaddr; +unsigned long base; +int size; +}; + +int pasemi_i2c_common_probe (struct pasemi_smbus *smbus);
drivers/i2c/busses/i2c-pasemi-pci.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 7/11 i2c: pasemi: Move common reset code to own function
In reply to Sven PeterSplit out common reset call to its own function so that we can later add support for selecting the clock frequency and an additional enable bit found in newer revisions.
---
v1 -> v2: no changes
drivers/i2c/busses/i2c-pasemi-core.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-pasemi-core.c +9 -6
@@ -61,6 +61,12 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg)#define TXFIFO_WR (smbus, reg) reg_write((smbus), REG_MTXFIFO, (reg))#define RXFIFO_RD (smbus) reg_read((smbus), REG_MRXFIFO) +static void pasemi_reset (struct pasemi_smbus *smbus) +{ +reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | + (CLK_100K_DIV &CTL_CLK_M ))); +} +static void pasemi_smb_clear (struct pasemi_smbus *smbus) {unsigned int status;
@@ -135,8 +141,7 @@ static int pasemi_i2c_xfer_msg(struct i2c_adapter *adapter,return 0 ; reset_out: -reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | - (CLK_100K_DIV &CTL_CLK_M ))); +pasemi_reset (smbus);return err; }
@@ -302,8 +307,7 @@ static int pasemi_smb_xfer(struct i2c_adapter *adapter,return 0 ; reset_out: -reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | - (CLK_100K_DIV &CTL_CLK_M ))); +pasemi_reset (smbus);return err; }
@@ -335,8 +339,7 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus)/* set up the sysfs linkage to our parent device */ smbus->adapter.dev.parent = smbus->dev; -reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | - (CLK_100K_DIV &CTL_CLK_M ))); +pasemi_reset (smbus); error =i2c_add_adapter (&smbus->adapter);if (error)
Signature · 1 line
2.25.1
PATCH v2 8/11 i2c: pasemi: Allow to configure bus frequency
In reply to Sven PeterRight now the bus frequency has always been hardcoded as 100 KHz with the specific reference clock used in the PASemi PCI controllers. Make this configurable to prepare for the platform driver.
---
v1 -> v2: no changes
drivers/i2c/busses/i2c-pasemi-core.c | 8 +++----- drivers/i2c/busses/i2c-pasemi-core.h | 1 + drivers/i2c/busses/i2c-pasemi-pci.c | 4 ++++ 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-pasemi-core.c +3 -5
@@ -39,9 +39,6 @@#define CTL_MTR 0x00000200#define CTL_CLK_M 0x000000ff -#define CLK_100K_DIV 84 -#define CLK_400K_DIV 21 -static inline void reg_write (struct pasemi_smbus *smbus,int reg,int val) { dev_dbg(smbus->dev, "smbus write reg %lx val %08x\n",
@@ -63,8 +60,9 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg)static void pasemi_reset (struct pasemi_smbus *smbus) { -reg_write (smbus,REG_CTL , (CTL_MTR |CTL_MRR | - (CLK_100K_DIV &CTL_CLK_M ))); +u32 val = (CTL_MTR |CTL_MRR | (smbus->clk_div &CTL_CLK_M )); + +reg_write (smbus,REG_CTL , val); }static void pasemi_smb_clear (struct pasemi_smbus *smbus)
drivers/i2c/busses/i2c-pasemi-core.h +1 -0
@@ -14,6 +14,7 @@ struct pasemi_smbus {void __iomem *ioaddr;unsigned long base;int size; +unsigned int clk_div; };int pasemi_i2c_common_probe (struct pasemi_smbus *smbus);
drivers/i2c/busses/i2c-pasemi-pci.c +4 -0
@@ -17,6 +17,9 @@#include "i2c-pasemi-core.h" +#define CLK_100K_DIV 84 +#define CLK_400K_DIV 21 +static struct pci_driver pasemi_smb_pci_driver; static int pasemi_smb_pci_probe(struct pci_dev *dev,
@@ -35,6 +38,7 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, smbus->dev = &dev->dev; smbus->base =pci_resource_start (dev,0 ); smbus->size =pci_resource_len (dev,0 ); + smbus->clk_div =CLK_100K_DIV ;if (!request_region (smbus->base, smbus->size, pasemi_smb_pci_driver.name)) {
Signature · 1 line
2.25.1
PATCH v2 9/11 i2c: pasemi: Refactor _probe to use devm_*
In reply to Sven PeterUsing managed device resources means there's nothing left to be done in pasemi_smb_pci_remove and also allows to remove base and size from struct pasemi_smbus.
---
v1 -> v2: no changes
drivers/i2c/busses/i2c-pasemi-core.c | 8 ++--- drivers/i2c/busses/i2c-pasemi-core.h | 2 -- drivers/i2c/busses/i2c-pasemi-pci.c | 45 ++++++++-------------------- 3 files changed, 15 insertions(+), 40 deletions(-)
drivers/i2c/busses/i2c-pasemi-core.c +3 -5
@@ -41,8 +41,7 @@static inline void reg_write (struct pasemi_smbus *smbus,int reg,int val) { -dev_dbg (smbus->dev,"smbus write reg %lx val %08x\n" , - smbus->base + reg, val); +dev_dbg (smbus->dev,"smbus write reg %x val %08x\n" , reg, val);iowrite32 (val, smbus->ioaddr + reg); }
@@ -50,8 +49,7 @@ static inline int reg_read(struct pasemi_smbus *smbus, int reg) {int ret; ret =ioread32 (smbus->ioaddr + reg); -dev_dbg (smbus->dev,"smbus read reg %lx val %08x\n" , - smbus->base + reg, ret); +dev_dbg (smbus->dev,"smbus read reg %x val %08x\n" , reg, ret);return ret; }
@@ -339,7 +337,7 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus)pasemi_reset (smbus); - error =i2c_add_adapter (&smbus->adapter); + error =devm_i2c_add_adapter (smbus->dev, &smbus->adapter);if (error)return error;
drivers/i2c/busses/i2c-pasemi-core.h +0 -2
@@ -12,8 +12,6 @@ struct pasemi_smbus {struct device *dev;struct i2c_adapter adapter;void __iomem *ioaddr; -unsigned long base; -int size;unsigned int clk_div; };
drivers/i2c/busses/i2c-pasemi-pci.c +12 -33
76 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 10/11 i2c: pasemi: Add Apple platform driver
In reply to Sven PeterWith all the previous preparations we can now finally add the platform driver to support the PASemi-based controllers in Apple SoCs. This does not work on the M1 yet but should work on the early iPhones already.
---
v1 -> v2:
- renamed i2c-pasemi-apple.c to i2c-pasemi-platform.c and adjusted function names as well
- removed unused struct pinctrl *pctrl which snuck into v1
MAINTAINERS | 1 + drivers/i2c/busses/Kconfig | 11 ++ drivers/i2c/busses/Makefile | 2 + drivers/i2c/busses/i2c-pasemi-platform.c | 122 +++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 drivers/i2c/busses/i2c-pasemi-platform.c
MAINTAINERS +1 -0
@@ -1740,6 +1740,7 @@ F: Documentation/devicetree/bindings/interrupt-controller/apple,aic.yaml F: Documentation/devicetree/bindings/pci/apple,pcie.yaml F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml F: arch/arm64/boot/dts/apple/ +F: drivers/i2c/busses/i2c-pasemi-platform.c F: drivers/irqchip/irq-apple-aic.c F: include/dt-bindings/interrupt-controller/apple-aic.h F: include/dt-bindings/pinctrl/apple.h
drivers/i2c/busses/Kconfig +11 -0
@@ -859,6 +859,17 @@ config I2C_PASEMI help Supports the PA Semi PWRficient on-chip SMBus interfaces. +config I2C_APPLE + tristate "Apple SMBus platform driver" + depends on ARCH_APPLE || COMPILE_TEST + default ARCH_APPLE + help + Say Y here if you want to use the I2C controller present on Apple + Silicon chips such as the M1. + + This driver can also be built as a module. If so, the module + will be called i2c-apple. + config I2C_PCA_PLATFORM tristate "PCA9564/PCA9665 as platform device" select I2C_ALGOPCA
drivers/i2c/busses/Makefile +2 -0
@@ -86,6 +86,8 @@ obj-$(CONFIG_I2C_OMAP) += i2c-omap.o obj-$(CONFIG_I2C_OWL) += i2c-owl.o i2c-pasemi-objs := i2c-pasemi-core.o i2c-pasemi-pci.o obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o +i2c-apple-objs := i2c-pasemi-core.o i2c-pasemi-platform.o +obj-$(CONFIG_I2C_APPLE) += i2c-apple.o obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o obj-$(CONFIG_I2C_PNX) += i2c-pnx.o obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
drivers/i2c/busses/i2c-pasemi-platform.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 10/11] i2c: pasemi: Add Apple platform driver
Quoted 3 lines
F:
arch/arm64/boot/dts/apple/
+F:drivers/i2c/busses/i2c-pasemi-platform.c
We have no dedicated maintainer for PASEMI. Are maybe you or your project interested in maintaining the pasemi-core, too? I guess not many patches will show up and they will likely be for M1 anyhow.
If so, then no need to resend, I could add the extra line while applying.
Re: [PATCH v2 10/11] i2c: pasemi: Add Apple platform driver
Quoted 9 lines · Wolfram Sang
Quoted 2 lines
F:
arch/arm64/boot/dts/apple/
+F:drivers/i2c/busses/i2c-pasemi-platform.cWe have no dedicated maintainer for PASEMI. Are maybe you or your project interested in maintaining the pasemi-core, too? I guess not many patches will show up and they will likely be for M1 anyhow.
If so, then no need to resend, I could add the extra line while applying.
Sure, feel free to add the core to the entry as well.
Best,
Sven
PATCH v2 11/11 i2c: pasemi: Set enable bit for Apple variant
In reply to Sven PeterSome later revisions after the original PASemi I2C controller introduce what likely is an enable bit to the CTL register. Without setting it the actual i2c transmission is never started.
---
v1 -> v2: no changes
drivers/i2c/busses/i2c-pasemi-core.c | 8 ++++++++ drivers/i2c/busses/i2c-pasemi-core.h | 3 +++ drivers/i2c/busses/i2c-pasemi-pci.c | 6 ++++++ 3 files changed, 17 insertions(+)
drivers/i2c/busses/i2c-pasemi-core.c +8 -0
@@ -22,6 +22,7 @@#define REG_MRXFIFO 0x04#define REG_SMSTA 0x14#define REG_CTL 0x1c +#define REG_REV 0x28/* Register defs */ #define MTXFIFO_READ 0x00000400
@@ -37,6 +38,7 @@#define CTL_MRR 0x00000400#define CTL_MTR 0x00000200 +#define CTL_EN 0x00000800#define CTL_CLK_M 0x000000ffstatic inline void reg_write (struct pasemi_smbus *smbus,int reg,int val)
@@ -60,6 +62,9 @@ static void pasemi_reset(struct pasemi_smbus *smbus) {u32 val = (CTL_MTR |CTL_MRR | (smbus->clk_div &CTL_CLK_M )); +if (smbus->hw_rev >=6 ) + val |=CTL_EN ; +reg_write (smbus,REG_CTL , val); }
@@ -335,6 +340,9 @@ int pasemi_i2c_common_probe(struct pasemi_smbus *smbus)/* set up the sysfs linkage to our parent device */ smbus->adapter.dev.parent = smbus->dev; +if (smbus->hw_rev !=PASEMI_HW_REV_PCI ) + smbus->hw_rev =reg_read (smbus,REG_REV ); +pasemi_reset (smbus); error =devm_i2c_add_adapter (smbus->dev, &smbus->adapter);
drivers/i2c/busses/i2c-pasemi-core.h +3 -0
@@ -8,11 +8,14 @@#include <linux/io.h> #include <linux/kernel.h> +#define PASEMI_HW_REV_PCI -1 +struct pasemi_smbus {struct device *dev;struct i2c_adapter adapter;void __iomem *ioaddr;unsigned int clk_div; +int hw_rev; };int pasemi_i2c_common_probe (struct pasemi_smbus *smbus);
drivers/i2c/busses/i2c-pasemi-pci.c +6 -0
@@ -42,6 +42,12 @@ static int pasemi_smb_pci_probe(struct pci_dev *dev, size =pci_resource_len (dev,0 ); smbus->clk_div =CLK_100K_DIV ; +/* +* The original PASemi PCI controllers don't have a register for +* their HW revision. +*/ + smbus->hw_rev =PASEMI_HW_REV_PCI ; +if (!devm_request_region (&dev->dev, base, size, pasemi_smb_pci_driver.name))return -EBUSY ;
Signature · 1 line
2.25.1
Hi,
Quoted 38 lines · Sven Peter
Hi,
v1: https://lore.kernel.org/linux-i2c/[email protected]/
Changes for v2:
- Added reviewed-by/acks
- Switched fromioport_maptopci_iomapas suggested by Arnd Bergmann
- Renamedi2c-pasemi-apple.ctoi2c-pasemi-platform.cas suggested by Wolfram Sang
- Replaced the ioport number in the adapter name withdev_nameto be able to identify separate busses in e.g. i2cdetect.I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
And for those who didn't see v1 the (almost) unchanged original cover letter:
This series adds support for the I2C controller found on Apple Silicon Macs which has quite a bit of history:
Apple bought P.A. Semi in 2008 and it looks like a part of its legacy continues to live on in the M1. This controller has actually been used since at least the iPhone 4S and hasn't changed much since then.
Essentially, there are only a few differences that matter:- The controller no longer is a PCI device
- Starting at some iPhone an additional bit in one register must be set in order to start transmissions.
- The reference clock and hence the clock dividers are differentIn order to add support for a platform device I first replaced PCI-specific bits and split out the PCI driver to its own file. Then I added support to make the clock divider configurable and converted the driver to use managed device resources to make it a bit simpler.
Quoted 6 lines
The Apple and PASemi driver will never be compiled in the same kernel since the Apple one will run on arm64 while the original PASemi driver will only be useful on powerpc.
I've thus followed the octeon (mips)/thunderx(arm64) approach to do the
split: I created a-core.cfile which contains the shared logic and just compile that one for both the PASemi and the new Apple driver.
Series:
-Olof
Quoted 4 lines
I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
Looks good to me. I will wait a few more days so that people can report their tests. But it will be in the next merge window.
Quoted 6 lines · Wolfram Sang
Quoted 3 lines
I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
Looks good to me. I will wait a few more days so that people can report their tests. But it will be in the next merge window.
Sounds great, thanks!
Sven
Christian Zigotzky
Tested-byQuoted 6 lines · Wolfram Sang
Quoted 3 lines
I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
Looks good to me. I will wait a few more days so that people can report their tests. But it will be in the next merge window.
Series v2:
- Christian
[1] https://forum.hyperion-entertainment.com/viewtopic.php?p=54213#p54213
Quoted 10 lines · Christian Zigotzky
Quoted 6 lines · Wolfram Sang
Quoted 3 lines
I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
Looks good to me. I will wait a few more days so that people can report their tests. But it will be in the next merge window.
Series v2:
thanks a lot, glad to hear everything works on P.A Semi CPUs as well!
And regarding that git am issue you wrote about: I think I based this series on torvald's tree instead of 5.15-rc4 and there have been some changes to at least MAINTAINERS. It'll probably apply cleanly to 5.15-rc5 but if that happens again in the future you can try
git am -3 mbox
instead. It'll try to do a three way merge if the patch doesn't apply cleanly.
Sven
Quoted 1 line
MAINTAINERS. It'll probably apply cleanly to 5.15-rc5 but if that happens again
It doesn't because Linus' git doesn't have:
Documentation/devicetree/bindings/pci/apple,pcie.yaml
Because MAINTAINER dependencies can be a bit nasty, I suggest I drop the MAINTAINER additions for now and we add them later. Then, you can add the pasemi-core as well. D'accord?
Quoted 10 lines · Wolfram Sang
Quoted 1 line
MAINTAINERS. It'll probably apply cleanly to 5.15-rc5 but if that happens againIt doesn't because Linus' git doesn't have:
Documentation/devicetree/bindings/pci/apple,pcie.yamlBecause MAINTAINER dependencies can be a bit nasty, I suggest I drop the MAINTAINER additions for now and we add them later. Then, you can add the pasemi-core as well. D'accord?
We can just split the MAINTAINERS changes into a separate patch and I can push that one through the SoC tree, along with other MAINTAINERS updates. Does that work for everyone?
Signature · 2 lines
Hector Martin ([email protected]) Public Key: https://mrcn.st/pub
Quoted 9 lines
Quoted 5 lines
Because MAINTAINER dependencies can be a bit nasty, I suggest I drop the MAINTAINER additions for now and we add them later. Then, you can add the pasemi-core as well. D'accord?
We can just split the
MAINTAINERSchanges into a separate patch and I can push that one through the SoC tree, along with otherMAINTAINERSupdates. Does that work for everyone?
That would also work for me. Thank you!
Christian Zigotzky
Tested-by Damien Stewart (Hypex) [1]Quoted 7 lines · Christian Zigotzky
Quoted 6 lines · Wolfram Sang
Quoted 3 lines
I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
Looks good to me. I will wait a few more days so that people can report their tests. But it will be in the next merge window.
Quoted 7 lines
Series v2:
- Christian
[1] https://forum.hyperion-entertainment.com/viewtopic.php?p=54213#p54213
Series v2:
- Christian
[1] https://forum.hyperion-entertainment.com/viewtopic.php?p=54217#p54217
Wolfram Sang
AppliedQuoted 62 lines · Sven Peter
Hi,
v1: https://lore.kernel.org/linux-i2c/[email protected]/
Changes for v2:
- Added reviewed-by/acks
- Switched fromioport_maptopci_iomapas suggested by Arnd Bergmann
- Renamedi2c-pasemi-apple.ctoi2c-pasemi-platform.cas suggested by Wolfram Sang
- Replaced the ioport number in the adapter name withdev_nameto be able to identify separate busses in e.g. i2cdetect.I still don't have access to any old PASemi hardware but the changes from v1 are pretty small and I expect them to still work. Would still be nice if someone with access to such hardware could give this a quick test.
And for those who didn't see v1 the (almost) unchanged original cover letter:
This series adds support for the I2C controller found on Apple Silicon Macs which has quite a bit of history:
Apple bought P.A. Semi in 2008 and it looks like a part of its legacy continues to live on in the M1. This controller has actually been used since at least the iPhone 4S and hasn't changed much since then.
Essentially, there are only a few differences that matter:- The controller no longer is a PCI device
- Starting at some iPhone an additional bit in one register must be set in order to start transmissions.
- The reference clock and hence the clock dividers are differentIn order to add support for a platform device I first replaced PCI-specific bits and split out the PCI driver to its own file. Then I added support to make the clock divider configurable and converted the driver to use managed device resources to make it a bit simpler.
The Apple and PASemi driver will never be compiled in the same kernel since the Apple one will run on arm64 while the original PASemi driver will only be useful on powerpc.
I've thus followed the octeon (mips)/thunderx(arm64) approach to do the
split: I created a-core.cfile which contains the shared logic and just compile that one for both the PASemi and the new Apple driver.Best,
Sven
Sven Peter (11):
dt-bindings: i2c: Add Apple I2C controller bindings
i2c: pasemi: Use io{read,write}32
i2c: pasemi: Usedev_nameinstead of port number
i2c: pasemi: Remove usage ofpci_dev
i2c: pasemi: Split off common probing code
i2c: pasemi: Split pci driver to its own file
i2c: pasemi: Move common reset code to own function
i2c: pasemi: Allow to configure bus frequency
i2c: pasemi: Refactor_probeto use devm_*
i2c: pasemi: Add Apple platform driver
i2c: pasemi: Set enable bit for Apple variant
Quoted 4 lines
.../devicetree/bindings/i2c/apple,i2c.yaml | 61 +++++++++ MAINTAINERS | 2 + drivers/i2c/busses/Kconfig | 11 ++ drivers/i2c/busses/Makefile | 3 +
Applied to for-next with MAINTAINER bits dropped and added tags from Olof and Christian, thanks!