i2c: aspeed: added driver for Aspeed I2C
Subsystems (5)
v9 cover i2c: aspeed: added driver for Aspeed I2C
Addressed comments from:
- Ben in: http://www.spinics.net/lists/devicetree/msg179006.html
Changes since previous update:
- Fairly minimal changes in master support patch, all else is the same
As before, tested on Aspeed 2500 evaluation board and a real platform with an Aspeed 2520.
PATCH v9 1/5 irqchip/aspeed-i2c-ic: binding docs for Aspeed I2C Interrupt Controller
Added device tree binding documentation for Aspeed I2C Interrupt Controller.
---
Added in v6:
- Pulled "aspeed_i2c_controller" out into a interrupt controller since that is what it actually does.
Changes for v7:
- None
Changes for v8:
- None
Changes for v9:
- None
--- .../interrupt-controller/aspeed,ast2400-i2c-ic.txt | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2400-i2c-ic.txt
Documentation/devicetree/bindings/interrupt-controller/aspeed,ast2400-i2c-ic.txt new file +25 -0
@@ -0,0 +1,25 @@ +Device tree configuration for the I2C Interrupt Controller on the AST24XX and +AST25XX SoCs. + +Required Properties: +- #address-cells : should be 1 +- #size-cells : should be 1 +- #interrupt-cells : should be 1 +- compatible : should be "aspeed,ast2400-i2c-ic" + or "aspeed,ast2500-i2c-ic" +- reg : address start and range of controller +- interrupts : interrupt number +- interrupt-controller : denotes that the controller receives and fires + new interrupts for child busses + +Example: + +i2c_ic: interrupt-controller@0 { + #address-cells = <1>; + #size-cells = <1>; + #interrupt-cells = <1>; + compatible = "aspeed,ast2400-i2c-ic"; + reg = <0x0 0x40>; + interrupts = <12>; + interrupt-controller; +};
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH v9 2/5 irqchip/aspeed-i2c-ic: Add I2C IRQ controller for Aspeed
In reply to Brendan HigginsThe Aspeed 24XX/25XX chips share a single hardware interrupt across 14 separate I2C busses. This adds a dummy irqchip which maps the single hardware interrupt to software interrupts for each of the busses.
---
Added in v6:
- Pulled "aspeed_i2c_controller" out into a interrupt controller since that is what it actually does.
Changes for v7:
- Renamed irq domain for consistency
Changes for v8:
- None
Changes for v9:
- None
--- drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-aspeed-i2c-ic.c | 102 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 drivers/irqchip/irq-aspeed-i2c-ic.c
drivers/irqchip/Makefile +1 -1
@@ -73,6 +73,6 @@ obj-$(CONFIG_MVEBU_ODMI) += irq-mvebu-odmi.o obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o -obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o +obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.o
drivers/irqchip/irq-aspeed-i2c-ic.c new file +102 -0
102 lines not on this page · raw message
Signature · 6 lines
2.13.0.506.g27d5fe0cd-goog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v9 3/5 i2c: aspeed: added documentation for Aspeed I2C driver
In reply to Brendan HigginsAdded device tree binding documentation for Aspeed I2C busses.
---
Changes for v2:
- None
Changes for v3:
- Removed reference to "bus" device tree param
Changes for v4:
- None
Changes for v5:
- None
Changes for v6:
- Replaced the controller property with and interrupt controller, leaving only the busses in the I2C documentation.
Changes for v7:
- Changed clock-frequency to bus-frequency in device tree
Changes for v8:
- Added multi-master property to device tree
Changes for v9:
- None
--- .../devicetree/bindings/i2c/i2c-aspeed.txt | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-aspeed.txt
Documentation/devicetree/bindings/i2c/i2c-aspeed.txt new file +48 -0
@@ -0,0 +1,48 @@ +Device tree configuration for the I2C busses on the AST24XX and AST25XX SoCs. + +Required Properties: +- #address-cells : should be 1 +- #size-cells : should be 0 +- reg : address offset and range of bus +- compatible : should be "aspeed,ast2400-i2c-bus" + or "aspeed,ast2500-i2c-bus" +- clocks : root clock of bus, should reference the APB + clock +- interrupts : interrupt number +- interrupt-parent : interrupt controller for bus, should reference a + aspeed,ast2400-i2c-ic or aspeed,ast2500-i2c-ic + interrupt controller + +Optional Properties: +- bus-frequency : frequency of the bus clock in Hz defaults to 100 kHz when not + specified +- multi-master : states that there is another master active on this bus. + +Example: + +i2c { + compatible = "simple-bus"; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x1e78a000 0x1000>; + + i2c_ic: interrupt-controller@0 { + #interrupt-cells = <1>; + compatible = "aspeed,ast2400-i2c-ic"; + reg = <0x0 0x40>; + interrupts = <12>; + interrupt-controller; + }; + + i2c0: i2c-bus@40 { + #address-cells = <1>; + #size-cells = <0>; + #interrupt-cells = <1>; + reg = <0x40 0x40>; + compatible = "aspeed,ast2400-i2c-bus"; + clocks = <&clk_apb>; + bus-frequency = <100000>; + interrupts = <0>; + interrupt-parent = <&i2c_ic>; + }; +};
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
PATCH v9 4/5 i2c: aspeed: added driver for Aspeed I2C
In reply to Brendan HigginsAdded initial master support for Aspeed I2C controller. Supports fourteen busses present in AST24XX and AST25XX BMC SoCs by Aspeed.
---
Changes for v2:
- Added single module_init (multiple was breaking some builds).
Changes for v3:
- Removed "bus" device tree param; now extracted from bus address offset
Changes for v4:
- I2C adapter number is now generated dynamically unless specified in alias.
Changes for v5:
- Removed irq_chip used to multiplex IRQ and replaced it with dummy_irq_chip along with some other IRQ cleanup.
- Addressed comments from Cedric, and Vladimir, mostly stylistic things and using devm managed resources.
- Increased max clock frequency before the bus is put in HighSpeed mode, as per Kachalov's comment.
Changes for v6:
- No longer arbitrarily restrict bus to be slave xor master.
- Pulled out "struct aspeed_i2c_controller" as a interrupt controller.
- Pulled out slave support into its own commit.
- Rewrote code that sets clock divider register because the original version set it incorrectly.
- Rewrote the aspeed_i2c_master_irq handler because the old method of completing a completion in between restarts was too slow causing devices to misbehave.
- Added support for I2C_M_RECV_LEN which I had incorrectly said was supported before.
- Addressed other comments from Vladimir.
Changes for v7:
- Changed clock-frequency to bus-frequency
- Made some fixes to clock divider code
- Added hardware reset function
- Marked functions that need to be called with the lock held as "unlocked"
- Did a bunch of clean up
Changes for v8:
- ACK IRQ status bits before doing anything else
- Added multi-master device tree property
- Do not send STOP commands after interrupt errors
- Fix SMBUS_QUICK emulation handling
- Removed highspeed clock code (I will do it in a later patch set)
- Use the platform_device name for the adapter name
- Reset for all failed recoveries
- Removed the "__" prefix from all of the non-thread safe functions
Changes for v9:
- No longer debug log after every address NACK
- Clear errors after reset
- No longer access clock while holding lock
- Ack all interrupts durring bus reset and initialization
--- drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-aspeed.c | 683 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 694 insertions(+) create mode 100644 drivers/i2c/busses/i2c-aspeed.c
drivers/i2c/busses/Kconfig +10 -0
@@ -326,6 +326,16 @@ config I2C_POWERMAC comment "I2C system bus drivers (mostly embedded / system-on-chip)" +config I2C_ASPEED + tristate "Aspeed I2C Controller" + depends on ARCH_ASPEED + help + If you say yes to this option, support will be included for the + Aspeed I2C controller. + + This driver can also be built as a module. If so, the module + will be called i2c-aspeed. + config I2C_AT91 tristate "Atmel AT91 I2C Two-Wire interface (TWI)" depends on ARCH_AT91
drivers/i2c/busses/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o # Embedded system I2C/SMBus host controller drivers +obj-$(CONFIG_I2C_ASPEED) += i2c-aspeed.o obj-$(CONFIG_I2C_AT91) += i2c-at91.o obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o obj-$(CONFIG_I2C_AXXIA) += i2c-axxia.o
drivers/i2c/busses/i2c-aspeed.c new file +683 -0
683 lines not on this page · raw message
Signature · 6 lines
2.13.0.506.g27d5fe0cd-goog -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v9 5/5 i2c: aspeed: added slave support for Aspeed I2C driver
In reply to Brendan HigginsAdded slave support for Aspeed I2C controller. Supports fourteen busses present in AST24XX and AST25XX BMC SoCs by Aspeed.
---
Added in v6:
- Pulled slave support out of initial driver commit into its own commit.
- No longer arbitrarily restrict bus to be slave xor master.
Changes for v7:
- Added hardware reset function
- Marked functions that need to be called with the lock held as "unlocked"
- Did some cleanup
Changes for v8:
- None
Changes for v9:
- None
--- drivers/i2c/busses/i2c-aspeed.c | 202 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+)
drivers/i2c/busses/i2c-aspeed.c +202 -0
@@ -49,6 +49,7 @@#define ASPEED_I2CD_SDA_DRIVE_1T_EN BIT(8)#define ASPEED_I2CD_M_SDA_DRIVE_1T_EN BIT(7)#define ASPEED_I2CD_M_HIGH_SPEED_EN BIT(6) +#define ASPEED_I2CD_SLAVE_EN BIT(1)#define ASPEED_I2CD_MASTER_EN BIT(0)/* 0x04 : I2CD Clock and AC Timing Control Register #1 */
@@ -69,6 +70,7 @@*/ #define ASPEED_I2CD_INTR_SDA_DL_TIMEOUT BIT(14)#define ASPEED_I2CD_INTR_BUS_RECOVER_DONE BIT(13) +#define ASPEED_I2CD_INTR_SLAVE_MATCH BIT(7)#define ASPEED_I2CD_INTR_SCL_TIMEOUT BIT(6)#define ASPEED_I2CD_INTR_ABNORMAL BIT(5)#define ASPEED_I2CD_INTR_NORMAL_STOP BIT(4)
@@ -106,6 +108,9 @@#define ASPEED_I2CD_M_TX_CMD BIT(1)#define ASPEED_I2CD_M_START_CMD BIT(0) +/* 0x18 : I2CD Slave Device Address Register */ +#define ASPEED_I2CD_DEV_ADDR_MASK GENMASK(6, 0) +enum aspeed_i2c_master_state {ASPEED_I2C_MASTER_START ,ASPEED_I2C_MASTER_TX_FIRST ,
@@ -116,6 +121,15 @@ enum aspeed_i2c_master_state { ASPEED_I2C_MASTER_INACTIVE, }; +enum aspeed_i2c_slave_state { +ASPEED_I2C_SLAVE_START , +ASPEED_I2C_SLAVE_READ_REQUESTED , +ASPEED_I2C_SLAVE_READ_PROCESSED , +ASPEED_I2C_SLAVE_WRITE_REQUESTED , +ASPEED_I2C_SLAVE_WRITE_RECEIVED , +ASPEED_I2C_SLAVE_STOP , +}; +struct aspeed_i2c_bus {struct i2c_adapter adap;struct device *dev;
@@ -134,6 +148,10 @@ struct aspeed_i2c_bus {size_t msgs_count;bool send_stop;int cmd_err; +#if IS_ENABLED (CONFIG_I2C_SLAVE ) +struct i2c_client *slave; +enum aspeed_i2c_slave_state slave_state; +#endif /* CONFIG_I2C_SLAVE */ };static int aspeed_i2c_reset (struct aspeed_i2c_bus *bus);
@@ -205,6 +223,110 @@ static int aspeed_i2c_recover_bus(struct aspeed_i2c_bus *bus)return aspeed_i2c_reset (bus); } +#if IS_ENABLED (CONFIG_I2C_SLAVE ) +static bool aspeed_i2c_slave_irq (struct aspeed_i2c_bus *bus) +{ +u32 command, irq_status, status_ack =0 ; +struct i2c_client *slave = bus->slave; +bool irq_handled = true; +u8 value; + +spin_lock (&bus->lock); +if (!slave) { + irq_handled = false; + goto out; + } + + command =readl (bus->base +ASPEED_I2C_CMD_REG ); + irq_status =readl (bus->base +ASPEED_I2C_INTR_STS_REG ); + +/* Slave was requested, restart state machine. */ +if (irq_status &ASPEED_I2CD_INTR_SLAVE_MATCH ) { + status_ack |=ASPEED_I2CD_INTR_SLAVE_MATCH ; + bus->slave_state =ASPEED_I2C_SLAVE_START ; + } + +/* Slave is not currently active, irq was for someone else. */ +if (bus->slave_state ==ASPEED_I2C_SLAVE_STOP ) { + irq_handled = false; + goto out; + } + +dev_dbg (bus->dev,"slave irq status 0x%08x, cmd 0x%08x\n" , + irq_status, command); + +/* Slave was sent something. */ +if (irq_status &ASPEED_I2CD_INTR_RX_DONE ) { + value =readl (bus->base +ASPEED_I2C_BYTE_BUF_REG ) >>8 ; +/* Handle address frame. */ +if (bus->slave_state ==ASPEED_I2C_SLAVE_START ) { +if (value &0x1 ) + bus->slave_state = +ASPEED_I2C_SLAVE_READ_REQUESTED ; +else + bus->slave_state = +ASPEED_I2C_SLAVE_WRITE_REQUESTED ; + } + status_ack |=ASPEED_I2CD_INTR_RX_DONE ; + } + +/* Slave was asked to stop. */ +if (irq_status &ASPEED_I2CD_INTR_NORMAL_STOP ) { + status_ack |=ASPEED_I2CD_INTR_NORMAL_STOP ; + bus->slave_state =ASPEED_I2C_SLAVE_STOP ; + } +if (irq_status &ASPEED_I2CD_INTR_TX_NAK ) { + status_ack |=ASPEED_I2CD_INTR_TX_NAK ; + bus->slave_state =ASPEED_I2C_SLAVE_STOP ; + } + +switch (bus->slave_state) { +case ASPEED_I2C_SLAVE_READ_REQUESTED : +if (irq_status &ASPEED_I2CD_INTR_TX_ACK ) +dev_err (bus->dev,"Unexpected ACK on read request.\n" ); + bus->slave_state =ASPEED_I2C_SLAVE_READ_PROCESSED ; + +i2c_slave_event (slave,I2C_SLAVE_READ_REQUESTED , &value); +writel (value, bus->base +ASPEED_I2C_BYTE_BUF_REG ); +writel (ASPEED_I2CD_S_TX_CMD , bus->base +ASPEED_I2C_CMD_REG ); +break ; +case ASPEED_I2C_SLAVE_READ_PROCESSED : + status_ack |=ASPEED_I2CD_INTR_TX_ACK ; +if (!(irq_status &ASPEED_I2CD_INTR_TX_ACK )) +dev_err (bus->dev, +"Expected ACK after processed read.\n" ); +i2c_slave_event (slave,I2C_SLAVE_READ_PROCESSED , &value); +writel (value, bus->base +ASPEED_I2C_BYTE_BUF_REG ); +writel (ASPEED_I2CD_S_TX_CMD , bus->base +ASPEED_I2C_CMD_REG ); +break ; +case ASPEED_I2C_SLAVE_WRITE_REQUESTED : + bus->slave_state =ASPEED_I2C_SLAVE_WRITE_RECEIVED ; +i2c_slave_event (slave,I2C_SLAVE_WRITE_REQUESTED , &value); +break ; +case ASPEED_I2C_SLAVE_WRITE_RECEIVED : +i2c_slave_event (slave,I2C_SLAVE_WRITE_RECEIVED , &value); +break ; +case ASPEED_I2C_SLAVE_STOP : +i2c_slave_event (slave,I2C_SLAVE_STOP , &value); +break ; +default : +dev_err (bus->dev,"unhandled slave_state: %d\n" , + bus->slave_state); +break ; + } + +if (status_ack != irq_status) +dev_err (bus->dev, +"irq handled != irq. expected %x, but was %x\n" , + irq_status, status_ack); +writel (status_ack, bus->base +ASPEED_I2C_INTR_STS_REG ); + +out: +spin_unlock (&bus->lock); +return irq_handled; +} +#endif /* CONFIG_I2C_SLAVE */ +/* precondition: bus.lock has been acquired. */ static void aspeed_i2c_do_start (struct aspeed_i2c_bus *bus) {
@@ -408,6 +530,13 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id) {struct aspeed_i2c_bus *bus = dev_id; +#if IS_ENABLED (CONFIG_I2C_SLAVE ) +if (aspeed_i2c_slave_irq (bus)) { +dev_dbg (bus->dev,"irq handled by slave.\n" ); +return IRQ_HANDLED ; + } +#endif /* CONFIG_I2C_SLAVE */ +if (aspeed_i2c_master_irq (bus))return IRQ_HANDLED ;else
@@ -467,9 +596,76 @@ static u32 aspeed_i2c_functionality(struct i2c_adapter *adap)return I2C_FUNC_I2C |I2C_FUNC_SMBUS_EMUL |I2C_FUNC_SMBUS_BLOCK_DATA ; } +#if IS_ENABLED (CONFIG_I2C_SLAVE ) +/* precondition: bus.lock has been acquired. */ +static void __aspeed_i2c_reg_slave (struct aspeed_i2c_bus *bus,u16 slave_addr) +{ +u32 addr_reg_val, func_ctrl_reg_val; + +/* Set slave addr. */ + addr_reg_val =readl (bus->base +ASPEED_I2C_DEV_ADDR_REG ); + addr_reg_val &= ~ASPEED_I2CD_DEV_ADDR_MASK ; + addr_reg_val |= slave_addr &ASPEED_I2CD_DEV_ADDR_MASK ; +writel (addr_reg_val, bus->base +ASPEED_I2C_DEV_ADDR_REG ); + +/* Turn on slave mode. */ + func_ctrl_reg_val =readl (bus->base +ASPEED_I2C_FUN_CTRL_REG ); + func_ctrl_reg_val |=ASPEED_I2CD_SLAVE_EN ; +writel (func_ctrl_reg_val, bus->base +ASPEED_I2C_FUN_CTRL_REG ); +} + +static int aspeed_i2c_reg_slave (struct i2c_client *client) +{ +struct aspeed_i2c_bus *bus; +unsigned long flags; + + bus = client->adapter->algo_data; +spin_lock_irqsave (&bus->lock, flags); +if (bus->slave) { +spin_unlock_irqrestore (&bus->lock, flags); +return -EINVAL ; + } + +__aspeed_i2c_reg_slave (bus, client->addr); + + bus->slave = client; + bus->slave_state =ASPEED_I2C_SLAVE_STOP ; +spin_unlock_irqrestore (&bus->lock, flags); + +return 0 ; +} + +static int aspeed_i2c_unreg_slave (struct i2c_client *client) +{ +struct aspeed_i2c_bus *bus = client->adapter->algo_data; +u32 func_ctrl_reg_val; +unsigned long flags; + +spin_lock_irqsave (&bus->lock, flags); +if (!bus->slave) { +spin_unlock_irqrestore (&bus->lock, flags); +return -EINVAL ; + } + +/* Turn off slave mode. */ + func_ctrl_reg_val =readl (bus->base +ASPEED_I2C_FUN_CTRL_REG ); + func_ctrl_reg_val &= ~ASPEED_I2CD_SLAVE_EN ; +writel (func_ctrl_reg_val, bus->base +ASPEED_I2C_FUN_CTRL_REG ); + + bus->slave =NULL ; +spin_unlock_irqrestore (&bus->lock, flags); + +return 0 ; +} +#endif /* CONFIG_I2C_SLAVE */ +static const struct i2c_algorithm aspeed_i2c_algo = { .master_xfer = aspeed_i2c_master_xfer, .functionality = aspeed_i2c_functionality, +#if IS_ENABLED(CONFIG_I2C_SLAVE) + .reg_slave = aspeed_i2c_reg_slave, + .unreg_slave = aspeed_i2c_unreg_slave, +#endif /* CONFIG_I2C_SLAVE */ };static u32 aspeed_i2c_get_clk_reg_val (u32 divisor)
@@ -544,6 +740,12 @@ static int aspeed_i2c_init(struct aspeed_i2c_bus *bus,writel (readl (bus->base +ASPEED_I2C_FUN_CTRL_REG ) | fun_ctrl_reg, bus->base +ASPEED_I2C_FUN_CTRL_REG ); +#if IS_ENABLED (CONFIG_I2C_SLAVE ) +/* If slave has already been registered, re-enable it. */ +if (bus->slave) +__aspeed_i2c_reg_slave (bus, bus->slave->addr); +#endif /* CONFIG_I2C_SLAVE */ +/* Set interrupt generation of I2C controller */ writel (ASPEED_I2CD_INTR_ALL , bus->base +ASPEED_I2C_INTR_CTRL_REG );
Signature · 1 line
2.13.0.506.g27d5fe0cd-goog
Re: [PATCH v9 2/5] irqchip/aspeed-i2c-ic: Add I2C IRQ controller for Aspeed
In reply to Brendan HigginsQuoted 116 lines · Brendan Higgins
The Aspeed 24XX/25XX chips share a single hardware interrupt across 14 separate I2C busses. This adds a dummy irqchip which maps the single hardware interrupt to software interrupts for each of the busses.
Signed-off-by Brendan Higgins <[email protected]>---
Added in v6:
- Pulled "aspeed_i2c_controller" out into a interrupt controller since that is what it actually does.
Changes for v7:
- Renamed irq domain for consistency
Changes for v8:
- None
Changes for v9:
- None--- drivers/irqchip/Makefile | 2 +- drivers/irqchip/irq-aspeed-i2c-ic.c | 102 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 drivers/irqchip/irq-aspeed-i2c-ic.cdrivers/irqchip/Makefile +1
-1@@ -73,6 +73,6 @@ obj-$(CONFIG_MVEBU_ODMI) += irq-mvebu-odmi.o obj-$(CONFIG_MVEBU_PIC) += irq-mvebu-pic.o obj-$(CONFIG_LS_SCFG_MSI) += irq-ls-scfg-msi.o obj-$(CONFIG_EZNPS_GIC) += irq-eznps.o -obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o +obj-$(CONFIG_ARCH_ASPEED) += irq-aspeed-vic.o irq-aspeed-i2c-ic.o obj-$(CONFIG_STM32_EXTI) += irq-stm32-exti.o obj-$(CONFIG_QCOM_IRQ_COMBINER) += qcom-irq-combiner.odrivers/irqchip/irq-aspeed-i2c-ic.c new file +77
-0@@ -0,0 +1,102 @@ +/* +* Aspeed 24XX/25XX I2C Interrupt Controller. +* +* Copyright (C) 2012-2017 ASPEED Technology Inc. +* Copyright 2017 IBM Corporation +* Copyright 2017 Google, Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/irq.h> +#include <linux/irqchip.h> +#include <linux/irqchip/chained_irq.h> +#include <linux/irqdomain.h> +#include <linux/of_address.h> +#include <linux/of_irq.h> +#include <linux/io.h> + + +#define ASPEED_I2C_IC_NUM_BUS 14 + +struct aspeed_i2c_ic { +void __iomem *base; +int parent_irq; +struct irq_domain *irq_domain; +}; + +/* +* The aspeed chip provides a single hardware interrupt for all of the I2C +* busses, so we use a dummy interrupt chip to translate this single interrupt +* into multiple interrupts, each associated with a single I2C bus. +*/ +static void aspeed_i2c_ic_irq_handler (struct irq_desc *desc) +{ +struct aspeed_i2c_ic *i2c_ic =irq_desc_get_handler_data (desc); +struct irq_chip *chip =irq_desc_get_chip (desc); +unsigned long bit, status; +unsigned int bus_irq; + +chained_irq_enter (chip, desc); + status =readl (i2c_ic->base); +for_each_set_bit (bit, &status,ASPEED_I2C_IC_NUM_BUS ) { + bus_irq =irq_find_mapping (i2c_ic->irq_domain, bit); +generic_handle_irq (bus_irq); + } +chained_irq_exit (chip, desc); +} + +/* +* Set simple handler and mark IRQ as valid. Nothing interesting to do here +* since we are using a dummy interrupt chip. +*/ +static int aspeed_i2c_ic_map_irq_domain (struct irq_domain *domain, +unsigned int irq,irq_hw_number_t hwirq) +{ +irq_set_chip_and_handler (irq, &dummy_irq_chip, handle_simple_irq); +irq_set_chip_data (irq, domain->host_data); + +return 0 ; +} + +static const struct irq_domain_ops aspeed_i2c_ic_irq_domain_ops = { + .map = aspeed_i2c_ic_map_irq_domain, +}; + +static int __init aspeed_i2c_ic_of_init (struct device_node *node, +struct device_node *parent) +{ +struct aspeed_i2c_ic *i2c_ic; + + i2c_ic =kzalloc (sizeof (*i2c_ic),GFP_KERNEL ); +if (!i2c_ic) +return -ENOMEM ; + + i2c_ic->base =of_iomap (node,0 );
drivers/irqchip/irq-aspeed-i2c-ic.c line 87
Quoted 10 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +10
-0+if (IS_ERR (i2c_ic->base)) +return PTR_ERR (i2c_ic->base); + + i2c_ic->parent_irq =irq_of_parse_and_map (node,0 ); +if (i2c_ic->parent_irq <0 ) +return i2c_ic->parent_irq; + + i2c_ic->irq_domain =irq_domain_add_linear ( + node,ASPEED_I2C_IC_NUM_BUS , + &aspeed_i2c_ic_irq_domain_ops,NULL );
nit: can you have at least one argument following the function name? Even if checkpatch shouts out you?
drivers/irqchip/irq-aspeed-i2c-ic.c line 89
Quoted 2 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +2
-0+if (!i2c_ic->irq_domain) +return -ENOMEM ;
All these error paths are leaking the initial memory allocation.
Quoted 4 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +3
-0+ + i2c_ic->irq_domain->name ="aspeed-i2c-domain" ; +
drivers/irqchip/irq-aspeed-i2c-ic.c line 102
Quoted 10 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +10
-0+irq_set_chained_handler_and_data (i2c_ic->parent_irq, + aspeed_i2c_ic_irq_handler, i2c_ic); + +pr_info ("i2c controller registered, irq %d\n" , i2c_ic->parent_irq); + +return 0 ; +} + +IRQCHIP_DECLARE (ast2400_i2c_ic,"aspeed,ast2400-i2c-ic" , aspeed_i2c_ic_of_init); +IRQCHIP_DECLARE (ast2500_i2c_ic,"aspeed,ast2500-i2c-ic" , aspeed_i2c_ic_of_init);
Once you've fixed the trivial bug above, this should be good to go. What's the merging strategy? Can I take the initial two patches, and let someone else deal with the rest? Or do you want the whole series to be kept together?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 4 lines · Brendan Higgins
Added initial master support for Aspeed I2C controller. Supports fourteen busses present in AST24XX and AST25XX BMC SoCs by Aspeed.
Signed-off-by Brendan Higgins <[email protected]>
---
Just spotted a completely minor/tivial nit:
drivers/i2c/busses/i2c-aspeed.c line 425
Quoted 9 lines
drivers/i2c/busses/i2c-aspeed.c new file +9
-0+static int aspeed_i2c_master_xfer (struct i2c_adapter *adap, +struct i2c_msg *msgs,int num) +{ +struct aspeed_i2c_bus *bus = adap->algo_data; +unsigned long time_left, flags; +int ret =0 ; + +spin_lock_irqsave (&bus->lock, flags); + bus->cmd_err =0 ;
^^^^^^^^^^^^^^^^^
This is probably unnecessary now since it's initialized further down.
Quoted 5 lines
drivers/i2c/busses/i2c-aspeed.c new file +5
-0+/* If bus is busy, attempt recovery. We assume a single master +* environment. +*/ +if (readl (bus->base +ASPEED_I2C_CMD_REG ) &ASPEED_I2CD_BUS_BUSY_STS ) { +spin_unlock_irqrestore (&bus->lock, flags);
drivers/i2c/busses/i2c-aspeed.c line 441
Quoted 10 lines
drivers/i2c/busses/i2c-aspeed.c new file +10
-0+ ret =aspeed_i2c_recover_bus (bus); +if (ret) +return ret; +spin_lock_irqsave (&bus->lock, flags); + } + + bus->cmd_err =0 ; + bus->msgs = msgs; + bus->msgs_index =0 ; + bus->msgs_count = num;
Now I'd like Andrew to give it a spin as he's currently testing/debugging some i2c related stuff to be 100% certain it works fine on our systems.
Thanks !
Cheers,
Ben.
Benjamin Herrenschmidt
reviewerRe: [PATCH v9 5/5] i2c: aspeed: added slave support for Aspeed I2C driver
In reply to Brendan HigginsQuoted 2 lines · Brendan Higgins
Added slave support for Aspeed I2C controller. Supports fourteen busses present in AST24XX and AST25XX BMC SoCs by Aspeed.
(Not an issue for merging)
Have you looked at a "mode" by which you implement just enough of the slave support to decode smbus notifications ?
This looks like it could be useful when using pmbus devices, as some of them use smbus notifications fairly often.
Today only one driver calls i2c_handle_smbus_host_notify() (the Intel one of course).
Cheers,
Ben.
Re: [PATCH v9 2/5] irqchip/aspeed-i2c-ic: Add I2C IRQ controller for Aspeed
In reply to Marc ZyngierQuoted 6 lines
drivers/irqchip/irq-aspeed-i2c-ic.c line 87
Quoted 3 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +3
-0+ i2c_ic->irq_domain =irq_domain_add_linear ( + node,ASPEED_I2C_IC_NUM_BUS , + &aspeed_i2c_ic_irq_domain_ops,NULL );nit: can you have at least one argument following the function name? Even if checkpatch shouts out you?
Makes no difference to me.
Quoted 5 lines
drivers/irqchip/irq-aspeed-i2c-ic.c line 89
Quoted 3 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +2
-0+if (!i2c_ic->irq_domain) +return -ENOMEM ;All these error paths are leaking the initial memory allocation.
Whoops, forgot I am not using devm_*.
Quoted 12 lines
Quoted 12 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +11
-0+ + i2c_ic->irq_domain->name ="aspeed-i2c-domain" ; + +irq_set_chained_handler_and_data (i2c_ic->parent_irq, + aspeed_i2c_ic_irq_handler, i2c_ic); + +pr_info ("i2c controller registered, irq %d\n" , i2c_ic->parent_irq); + +return 0 ; +} +
Quoted 8 lines
drivers/irqchip/irq-aspeed-i2c-ic.c line 102
Quoted 3 lines
drivers/irqchip/irq-aspeed-i2c-ic.c new file +2
-0+IRQCHIP_DECLARE (ast2400_i2c_ic,"aspeed,ast2400-i2c-ic" , aspeed_i2c_ic_of_init); +IRQCHIP_DECLARE (ast2500_i2c_ic,"aspeed,ast2500-i2c-ic" , aspeed_i2c_ic_of_init);Once you've fixed the trivial bug above, this should be good to go. What's the merging strategy? Can I take the initial two patches, and let someone else deal with the rest? Or do you want the whole series to be kept together?
I think it makes most sense to keep it together and let Wolfram merge the whole thing since the I2C patches won't work without this and I would not want to make the merging process unnecessarily complicated.
Re: [PATCH v9 5/5] i2c: aspeed: added slave support for Aspeed I2C driver
In reply to Benjamin HerrenschmidtQuoted 6 lines · Benjamin Herrenschmidt
Quoted 2 lines · Brendan Higgins
Added slave support for Aspeed I2C controller. Supports fourteen busses present in AST24XX and AST25XX BMC SoCs by Aspeed.
(Not an issue for merging)
Quoted 9 lines
Have you looked at a "mode" by which you implement just enough of the slave support to decode smbus notifications ?
This looks like it could be useful when using pmbus devices, as some of them use smbus notifications fairly often.
Today only one driver calls
i2c_handle_smbus_host_notify()(the Intel one of course).
Although I have not thought about the exact thing you are mentioning, I want to implement a number of other features for the slave. The thing I am most interested in is adding support for smbus alert from the slave side. Nevertheless, I wanted to actually get the driver in before I start trying to do interesting things. As it is, the slave code satisfies our current purposes and I do not know of anyone else who wants this feature at this time.
Cheers
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 4 lines · Brendan Higgins
Added initial master support for Aspeed I2C controller. Supports fourteen busses present in AST24XX and AST25XX BMC SoCs by Aspeed.
Signed-off-by Brendan Higgins <[email protected]>Reviewed-by Benjamin Herrenschmidt <[email protected]>---
Just spotted a completely minor/tivial nit:
drivers/i2c/busses/i2c-aspeed.c line 425
Quoted 9 lines
drivers/i2c/busses/i2c-aspeed.c new file +9
-0+static int aspeed_i2c_master_xfer (struct i2c_adapter *adap, +struct i2c_msg *msgs,int num) +{ +struct aspeed_i2c_bus *bus = adap->algo_data; +unsigned long time_left, flags; +int ret =0 ; + +spin_lock_irqsave (&bus->lock, flags); + bus->cmd_err =0 ;^^^^^^^^^^^^^^^^^
Quoted 1 line
This is probably unnecessary now since it's initialized further down.
Nope, reset uses cmd_err as well. Maybe reset should initialize it? Not sure.
Quoted 17 lines
Quoted 6 lines
drivers/i2c/busses/i2c-aspeed.c new file +5
-0+/* If bus is busy, attempt recovery. We assume a single master +* environment. +*/ +if (readl (bus->base +ASPEED_I2C_CMD_REG ) &ASPEED_I2CD_BUS_BUSY_STS ) { +spin_unlock_irqrestore (&bus->lock, flags);drivers/i2c/busses/i2c-aspeed.c line 441
Quoted 10 lines
drivers/i2c/busses/i2c-aspeed.c new file +10
-0+ ret =aspeed_i2c_recover_bus (bus); +if (ret) +return ret; +spin_lock_irqsave (&bus->lock, flags); + } + + bus->cmd_err =0 ; + bus->msgs = msgs; + bus->msgs_index =0 ; + bus->msgs_count = num;
Quoted 3 lines
Now I'd like Andrew to give it a spin as he's currently testing/debugging some i2c related stuff to be 100% certain it works fine on our systems.
If you haven't done this yet, you should try version 10 instead.