Skip to contentSkip to conversation

Add support for pcf8575

PATCH New Vignesh R 2 participants 9 messages Mar 10, 2015 – Mar 11, 2015 GPIO

lore
Share & tools
lore

Vignesh R

author
#0 lore raw

cover Add support for pcf8575

Hi,

This adds driver for pcf8575 in uboot. The driver supports basic read and write operations on pcf gpio pins.

The first patch adds the driver, second patch and third patch switches cpsw to use slave0 on DRA72 EVM.

Tested pcf driver on DRA72 EVM by probing pcf lines and cpsw by runnning tftp.

Vignesh R (3):
gpio: pcf8575: Add pcf8575 driver to control gpio lines
ARM: dra7xx_evm: Enable pcf driver
ARM: DRA7-EVM: switch cpsw to use slave0

 board/ti/dra7xx/evm.c        |  13 ++-
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/pcf8575.c       | 248 +++++++++++++++++++++++++++++++++++++++++++
 include/configs/dra7xx_evm.h |   4 +
 include/pcf8575.h            |  25 +++++
 5 files changed, 289 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpio/pcf8575.c
 create mode 100644 include/pcf8575.h
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/3 gpio: pcf8575: Add pcf8575 driver to control gpio lines

TI's pcf8575 is a 16-bit I2C based GPIO expander.The device features a 16-bit quasi-bidirectional I/O ports. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. The I/Os should be high before being used as inputs.

This driver is based on pcf857x driver available in Linux 4.0 kernel. It supports basic reading and writing of gpio pins.

---
 drivers/gpio/Makefile  |   1 +
 drivers/gpio/pcf8575.c | 248 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/pcf8575.h      |  25 +++++
 3 files changed, 274 insertions(+)
 create mode 100644 drivers/gpio/pcf8575.c
 create mode 100644 include/pcf8575.h
drivers/gpio/Makefile +1 -0
index aa11f15423a4..1e0e521b4d95 100644
@@ -9,6 +9,7 @@ ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
 endif
 
+obj-$(CONFIG_PCF8575)		+= pcf8575.o
 obj-$(CONFIG_AT91_GPIO)	+= at91_gpio.o
 obj-$(CONFIG_INTEL_ICH6_GPIO)	+= intel_ich6_gpio.o
 obj-$(CONFIG_KIRKWOOD_GPIO)	+= kw_gpio.o
drivers/gpio/pcf8575.c new file +248 -0

248 lines not on this page · raw message

include/pcf8575.h new file +25 -0
new file mode 100644
index 000000000000..a082554b4a5a
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __PCF8575_H_
+#define __PCF8575_H_
+
+#define PCF8575_OUT_LOW		0
+#define PCF8575_OUT_HIGH	1
+
+
+int pcf8575_input(uint8_t addr, unsigned offset);
+int pcf8575_get_val(uint8_t addr, unsigned offset);
+int pcf8575_output(uint8_t addr, unsigned offset, int value);
+
+#endif /* __PCF8575_H_ */
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/3 gpio: pcf8575: Add pcf8575 driver to control gpio lines

Quoted 7 lines · Vignesh R

TI's pcf8575 is a 16-bit I2C based GPIO expander.The device features a 16-bit quasi-bidirectional I/O ports. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. The I/Os should be high before being used as inputs.

This driver is based on pcf857x driver available in Linux 4.0 kernel. It supports basic reading and writing of gpio pins.

For attribution of stuff ported from the kernel please see
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

[snip]

Quoted 10 lines
drivers/gpio/pcf8575.c new file +4 -0
new file mode 100644
index 000000000000..1ee92a29760a
@@ -0,0 +1,248 @@
+/*
+ * PCF8575 I2C GPIO EXPANDER DRIVER
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/

drivers/gpio/pcf8575.c line 14

Quoted 10 lines
drivers/gpio/pcf8575.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

Please use SPDX tags for new files, thanks.

And right up front, this driver isn't using device model, please re-work and update to use that framework, thanks!

drivers/gpio/pcf8575.c line 39

Quoted 1 line
drivers/gpio/pcf8575.c new file +1 -0
+/* NOTE:  these chips have strange "quasi-bidirectional" I/O pins.

/*
* NOTE: ...

drivers/gpio/pcf8575.c line 170

Quoted 6 lines
drivers/gpio/pcf8575.c new file +6 -0
+cmd_tbl_t cmd_pcf8575[] = {
+	U_BOOT_CMD_MKENT(device, 3, 0, (void *)PCF8575_CMD_DEVICE, "", ""),
+	U_BOOT_CMD_MKENT(output, 4, 0, (void *)PCF8575_CMD_OUTPUT, "", ""),
+	U_BOOT_CMD_MKENT(input, 3, 0, (void *)PCF8575_CMD_INPUT, "", ""),
+	U_BOOT_CMD_MKENT(info, 2, 0, (void *)PCF8575_CMD_INFO, "", ""),
+};

Why isn't that just done with the normal gpio command?

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150310/cf256422/attachment.sig>
author
#3 lore raw

PATCH 1/3 gpio: pcf8575: Add pcf8575 driver to control gpio lines

Quoted 37 lines · Tom Rini
Quoted 7 lines · Vignesh R

TI's pcf8575 is a 16-bit I2C based GPIO expander.The device features a 16-bit quasi-bidirectional I/O ports. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. The I/Os should be high before being used as inputs.

This driver is based on pcf857x driver available in Linux 4.0 kernel. It supports basic reading and writing of gpio pins.

For attribution of stuff ported from the kernel please see
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

[snip]

Quoted 10 lines
drivers/gpio/pcf8575.c new file +4 -0
new file mode 100644
index 000000000000..1ee92a29760a
@@ -0,0 +1,248 @@
+/*
+ * PCF8575 I2C GPIO EXPANDER DRIVER
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/

drivers/gpio/pcf8575.c line 14

Quoted 10 lines
drivers/gpio/pcf8575.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

Please use SPDX tags for new files, thanks.

Quoted 2 lines

And right up front, this driver isn't using device model, please re-work and update to use that framework, thanks!

Thanks for reviewing.

I can switch to device model, but DRA72 does not support device tree and hence I will not be able use device model based pcf driver in my use-case.

One approach is that, I will re-write driver to support both deprecated gpio APIs (like gpio_get_value) and gpio device model APIs (dm_gpio_ops). Is this approach okay? But, somebody will have to test the dm_gpio_ops implementations as DRA72 does not support DT.

Regards
Vignesh

#4 lore raw

PATCH 1/3 gpio: pcf8575: Add pcf8575 driver to control gpio lines

Quoted 40 lines · Vignesh R
Quoted 37 lines · Tom Rini
Quoted 7 lines · Vignesh R

TI's pcf8575 is a 16-bit I2C based GPIO expander.The device features a 16-bit quasi-bidirectional I/O ports. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. The I/Os should be high before being used as inputs.

This driver is based on pcf857x driver available in Linux 4.0 kernel. It supports basic reading and writing of gpio pins.

For attribution of stuff ported from the kernel please see
http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Sign

[snip]

Quoted 10 lines
drivers/gpio/pcf8575.c new file +4 -0
new file mode 100644
index 000000000000..1ee92a29760a
@@ -0,0 +1,248 @@
+/*
+ * PCF8575 I2C GPIO EXPANDER DRIVER
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/

drivers/gpio/pcf8575.c line 14

Quoted 10 lines
drivers/gpio/pcf8575.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */

Please use SPDX tags for new files, thanks.

Quoted 7 lines
Quoted 2 lines

And right up front, this driver isn't using device model, please re-work and update to use that framework, thanks!

Thanks for reviewing.

I can switch to device model, but DRA72 does not support device tree and hence I will not be able use device model based pcf driver in my use-case.

Starting the move to DT is very easy, I would swear. For example, am335x_boneblack_vboot switches am335x over to DM and includes a device tree, but it's only used for the verified boot part now.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150311/ddb3d90a/attachment.sig>
author
#5 lore raw

PATCH 2/3 ARM: dra7xx_evm: Enable pcf driver

In reply to Vignesh R

Enable pcf driver to control the pcf chip present
at address 0x21 on i2c1.

---
 include/configs/dra7xx_evm.h | 4 ++++
 1 file changed, 4 insertions(+)
include/configs/dra7xx_evm.h +4 -0
index dee2b11056e7..0714f920efe6 100644
@@ -229,4 +229,8 @@
 #endif
 #endif  /* NOR support */
 
+/* pcf support */
+#define CONFIG_PCF8575
+#define CONFIG_SYS_I2C_PCF8575_CHIP { {0x21, 0xeaf7} }
+
 #endif /* __CONFIG_DRA7XX_EVM_H */
Signature · 1 line
1.9.1
#6 lore raw

PATCH 2/3 ARM: dra7xx_evm: Enable pcf driver

Quoted 13 lines · Vignesh R

Enable pcf driver to control the pcf chip present
at address 0x21 on i2c1.

---
 include/configs/dra7xx_evm.h | 4 ++++
 1 file changed, 4 insertions(+)
include/configs/dra7xx_evm.h +0 -0
index dee2b11056e7..0714f920efe6 100644

include/configs/dra7xx_evm.h line 234

Quoted 6 lines
include/configs/dra7xx_evm.h +3 -0
@@ -229,4 +229,8 @@
 #endif
 #endif  /* NOR support */
 
+/* pcf support */
+#define CONFIG_PCF8575
+#define CONFIG_SYS_I2C_PCF8575_CHIP { {0x21, 0xeaf7} }

As part of switching to DM this will also be done differently (via device tree).

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150310/f8c93660/attachment.sig>
author
#7 lore raw

PATCH 3/3 ARM: DRA7-EVM: switch cpsw to use slave0

In reply to Vignesh R

On DRA72 EVM cpsw slave1 is muxed with VIN, therefore switch cpsw to use slave0 using pcf driver.
DRA72 has only one cpsw phy(phy#3). Hence, set phy_id to 3 for slave0, in case of DRA72 EVM.

---
 board/ti/dra7xx/evm.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
board/ti/dra7xx/evm.c +11 -2
index 65222419ebbd..cc391cb0a065 100644
@@ -19,6 +19,7 @@
 #include <asm/arch/mmc_host_def.h>
 #include <asm/arch/sata.h>
 #include <environment.h>
+#include <pcf8575.h>
 
 #include "mux_data.h"
 
@@ -31,6 +32,10 @@ DECLARE_GLOBAL_DATA_PTR;
 /* GPIO 7_11 */
 #define GPIO_DDR_VTT_EN 203
 
+/* pcf chip address enet_mux_s0 */
+#define PCF_ENET_MUX_ADDR	0x21
+#define PCF_SEL_ENET_MUX_S0	4
+
 const struct omap_sysinfo sysinfo = {
 	"Board: DRA7xx\n"
 };
@@ -254,8 +259,12 @@ int board_eth_init(bd_t *bis)
 	ctrl_val |= 0x22;
 	writel(ctrl_val, (*ctrl)->control_core_control_io1);
 
-	if (*omap_si_rev == DRA722_ES1_0)
-		cpsw_data.active_slave = 1;
+	if (*omap_si_rev == DRA722_ES1_0) {
+		cpsw_data.active_slave = 0;
+		cpsw_data.slave_data[0].phy_addr = 3;
+		pcf8575_output(PCF_ENET_MUX_ADDR, PCF_SEL_ENET_MUX_S0,
+			       PCF8575_OUT_LOW);
+	}
 
 	ret = cpsw_register(&cpsw_data);
 	if (ret < 0)
Signature · 1 line
1.9.1
#8 lore raw

PATCH 3/3 ARM: DRA7-EVM: switch cpsw to use slave0

Quoted 6 lines · Vignesh R

On DRA72 EVM cpsw slave1 is muxed with VIN, therefore switch cpsw to use slave0 using pcf driver.
DRA72 has only one cpsw phy(phy#3). Hence, set phy_id to 3 for slave0, in case of DRA72 EVM.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150310/2544531f/attachment.sig>