i2c: Driver to expose PowerNV platform i2c busses
Subsystems (3)
PATCH v4 1/1 i2c: Driver to expose PowerNV platform i2c busses
The patch exposes the available i2c busses on the PowerNV platform to the kernel and implements the bus driver to support i2c and smbus commands.
The driver uses the platform device infrastructure to probe the busses on the platform and registers them with the i2c driver framework.
Signed-off-by Neelesh Gupta <[email protected]>
Signed-off-by Benjamin Herrenschmidt <[email protected]>
---
v3 -> v4:
- Rebased to the latest tree.
- Exported the opal function 'opal_i2c_request' in opal.c to make the driver build as module.
v2 -> v3:
- Added the device tree binding documentation for the driver.
- Sorted the ordering of this new driver added in Makefile.
- Removed populating the superfluous .owner field in 'struct driver'.
Documentation/devicetree/bindings/i2c/i2c-opal.txt | 37 +++ arch/powerpc/include/asm/opal.h | 29 ++ arch/powerpc/platforms/powernv/opal-wrappers.S | 1 arch/powerpc/platforms/powernv/opal.c | 12 + drivers/i2c/busses/Kconfig | 11 + drivers/i2c/busses/Makefile | 1 drivers/i2c/busses/i2c-opal.c | 294 ++++++++++++++++++++ 7 files changed, 385 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-opal.txt create mode 100644 drivers/i2c/busses/i2c-opal.c
Documentation/devicetree/bindings/i2c/i2c-opal.txt new file +37 -0
@@ -0,0 +1,37 @@ +Device-tree bindings for I2C OPAL driver +---------------------------------------- + +Most of the device node and properties layout is specific to the firmware and +used by the firmware itself for configuring the port. From the linux +perspective, the properties of use are "ibm,port-name" and "ibm,opal-id". + +Required properties: + +- reg: Port-id within a given master +- compatible: must be "ibm,opal-i2c" +- ibm,opal-id: Refers to a specific bus and used to identify it when calling + the relevant OPAL functions. +- bus-frequency: Operating frequency of the i2c bus (in HZ). Informational for + linux, used by the FW though. + +Optional properties: +- ibm,port-name: Firmware provides this name that uniquely identifies the i2c + port. + +The node contains a number of other properties that are used by the FW itself +and depend on the specific hardware implementation. The example below depicts +a P8 on-chip bus. + +Example: + +i2c-bus@0 { + reg = <0x0>; + bus-frequency = <0x61a80>; + compatible = "ibm,power8-i2c-port", "ibm,opal-i2c"; + ibm,opal-id = <0x1>; + ibm,port-name = "p8_00000000_e1p0"; + #address-cells = <0x1>; + phandle = <0x10000006>; + #size-cells = <0x0>; + linux,phandle = <0x10000006>; +};
arch/powerpc/include/asm/opal.h +29 -0
@@ -56,6 +56,14 @@ struct opal_sg_list {#define OPAL_HARDWARE_FROZEN -13#define OPAL_WRONG_STATE -14#define OPAL_ASYNC_COMPLETION -15 +#define OPAL_I2C_TIMEOUT -17 +#define OPAL_I2C_INVALID_CMD -18 +#define OPAL_I2C_LBUS_PARITY -19 +#define OPAL_I2C_BKEND_OVERRUN -20 +#define OPAL_I2C_BKEND_ACCESS -21 +#define OPAL_I2C_ARBT_LOST -22 +#define OPAL_I2C_NACK_RCVD -23 +#define OPAL_I2C_STOP_ERR -24/* API Tokens (in r0) */ #define OPAL_INVALID_CALL -1
@@ -158,6 +166,7 @@ struct opal_sg_list {#define OPAL_READ_TPO 104#define OPAL_IPMI_SEND 107#define OPAL_IPMI_RECV 108 +#define OPAL_I2C_REQUEST 109#ifndef __ASSEMBLY__
@@ -712,6 +721,24 @@ typedef struct oppanel_line {uint64_t line_len; } oppanel_line_t; +/* OPAL I2C request */ +struct opal_i2c_request { +uint8_t type; +#define OPAL_I2C_RAW_READ 0 +#define OPAL_I2C_RAW_WRITE 1 +#define OPAL_I2C_SM_READ 2 +#define OPAL_I2C_SM_WRITE 3 +uint8_t flags; +#define OPAL_I2C_ADDR_10 0x01/* Not supported yet */ +uint8_t subaddr_sz;/* Max 4 */ +uint8_t reserved; +__be16 addr;/* 7 or 10 bit address */ +__be16 reserved2; +__be32 subaddr;/* Sub-address if any */ +__be32 size;/* Data size */ +__be64 buffer_ra;/* Buffer real address */ +}; +/* /sys/firmware/opal */ extern struct kobject *opal_kobj;
@@ -881,6 +908,8 @@ int64_t opal_ipmi_send(uint64_t interface, struct opal_ipmi_msg *msg, uint64_t msg_len);int64_t opal_ipmi_recv (uint64_t interface,struct opal_ipmi_msg *msg,uint64_t *msg_len); +int64_t opal_i2c_request (uint64_t async_token,uint32_t bus_id, +struct opal_i2c_request *oreq);/* Internal functions */ extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
@@ -254,3 +254,4 @@ OPAL_CALL(opal_tpo_write, OPAL_WRITE_TPO); OPAL_CALL(opal_tpo_read, OPAL_READ_TPO); OPAL_CALL(opal_ipmi_send, OPAL_IPMI_SEND); OPAL_CALL(opal_ipmi_recv, OPAL_IPMI_RECV); +OPAL_CALL(opal_i2c_request, OPAL_I2C_REQUEST);
arch/powerpc/platforms/powernv/opal.c +12 -0
@@ -653,6 +653,14 @@ static void opal_ipmi_init(struct device_node *opal_node)of_platform_device_create (np,NULL ,NULL ); } +static void opal_i2c_create_devs (void ) +{ +struct device_node *np; + +for_each_compatible_node (np,NULL ,"ibm,opal-i2c" ) +of_platform_device_create (np,NULL ,NULL ); +} +static int __init opal_init (void ) {struct device_node *np, *consoles;
@@ -679,6 +687,9 @@ static int __init opal_init(void)of_node_put (consoles); } +/* Create i2c platform devices */ +opal_i2c_create_devs (); +/* Find all OPAL interrupts and request them */ irqs =of_get_property (opal_node,"opal-interrupts" , &irqlen); pr_debug("opal: Found %d interrupts reserved for OPAL\n",
@@ -824,3 +835,4 @@ EXPORT_SYMBOL_GPL(opal_rtc_read);EXPORT_SYMBOL_GPL (opal_rtc_write);EXPORT_SYMBOL_GPL (opal_tpo_read);EXPORT_SYMBOL_GPL (opal_tpo_write); +EXPORT_SYMBOL_GPL (opal_i2c_request);
drivers/i2c/busses/Kconfig +11 -0
@@ -1054,4 +1054,15 @@ config SCx200_ACB This support is also available as a module. If so, the module will be called scx200_acb. +config I2C_OPAL + tristate "IBM OPAL I2C driver" + depends on PPC_POWERNV + default y + help + This exposes the PowerNV platform i2c busses to the linux i2c layer, + the driver is based on the OPAL interfaces. + + This driver can also be built as a module. If so, the module will be + called as i2c-opal. + endmenu
drivers/i2c/busses/Makefile +1 -0
@@ -100,6 +100,7 @@ obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o obj-$(CONFIG_I2C_BCM_KONA) += i2c-bcm-kona.o obj-$(CONFIG_I2C_CROS_EC_TUNNEL) += i2c-cros-ec-tunnel.o obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o +obj-$(CONFIG_I2C_OPAL) += i2c-opal.o obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
drivers/i2c/busses/i2c-opal.c new file +294 -0
294 lines not on this page · raw message