[PATCH] watchdog: aspeed: fix hardware timeout calculation

2021-04-16 Thread rentao . bupt
From: Tao Ren 

Fix hardware timeout calculation in aspeed_wdt_set_timeout function to
ensure the reload value does not exceed the hardware limit.

Fixes: efa859f7d786 ("watchdog: Add Aspeed watchdog driver")
Reported-by: Amithash Prasad 
Signed-off-by: Tao Ren 
---
 drivers/watchdog/aspeed_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c
index 7e00960651fa..507fd815d767 100644
--- a/drivers/watchdog/aspeed_wdt.c
+++ b/drivers/watchdog/aspeed_wdt.c
@@ -147,7 +147,7 @@ static int aspeed_wdt_set_timeout(struct watchdog_device 
*wdd,
 
wdd->timeout = timeout;
 
-   actual = min(timeout, wdd->max_hw_heartbeat_ms * 1000);
+   actual = min(timeout, wdd->max_hw_heartbeat_ms / 1000);
 
writel(actual * WDT_RATE_1MHZ, wdt->base + WDT_RELOAD_VALUE);
writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
-- 
2.17.1



[PATCH v2] watchdog: aspeed: fix integer overflow in set_timeout handler

2021-04-15 Thread rentao . bupt
From: Tao Ren 

Fix the time comparison (timeout vs. max_hw_heartbeat_ms) in set_timeout
handler to avoid potential integer overflow when the supplied timeout is
greater than aspeed's maximum allowed timeout (4294 seconds).

Fixes: efa859f7d786 ("watchdog: Add Aspeed watchdog driver")
Reported-by: Amithash Prasad 
Signed-off-by: Tao Ren 
---
 Changes in v2:
   - do not touch "wdd->timeout": only "max_hw_heartbeat_ms * 1000" is
 updated to "max_hw_heartbeat_ms / 1000".

 drivers/watchdog/aspeed_wdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c
index 7e00960651fa..507fd815d767 100644
--- a/drivers/watchdog/aspeed_wdt.c
+++ b/drivers/watchdog/aspeed_wdt.c
@@ -147,7 +147,7 @@ static int aspeed_wdt_set_timeout(struct watchdog_device 
*wdd,
 
wdd->timeout = timeout;
 
-   actual = min(timeout, wdd->max_hw_heartbeat_ms * 1000);
+   actual = min(timeout, wdd->max_hw_heartbeat_ms / 1000);
 
writel(actual * WDT_RATE_1MHZ, wdt->base + WDT_RELOAD_VALUE);
writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
-- 
2.17.1



[PATCH] watchdog: aspeed: fix integer overflow in set_timeout handler

2021-04-15 Thread rentao . bupt
From: Tao Ren 

Fix the time comparison (timeout vs. max_hw_heartbeat_ms) in set_timeout
handler to avoid potential integer overflow when the supplied timeout is
greater than aspeed's maximum allowed timeout (4294 seconds).

Fixes: efa859f7d786 ("watchdog: Add Aspeed watchdog driver")
Reported-by: Amithash Prasad 
Signed-off-by: Tao Ren 
---
 drivers/watchdog/aspeed_wdt.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c
index 7e00960651fa..9f77272dc906 100644
--- a/drivers/watchdog/aspeed_wdt.c
+++ b/drivers/watchdog/aspeed_wdt.c
@@ -145,9 +145,8 @@ static int aspeed_wdt_set_timeout(struct watchdog_device 
*wdd,
struct aspeed_wdt *wdt = to_aspeed_wdt(wdd);
u32 actual;
 
-   wdd->timeout = timeout;
-
-   actual = min(timeout, wdd->max_hw_heartbeat_ms * 1000);
+   actual = min(timeout, wdd->max_hw_heartbeat_ms / 1000);
+   wdd->timeout = actual;
 
writel(actual * WDT_RATE_1MHZ, wdt->base + WDT_RELOAD_VALUE);
writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
-- 
2.17.1



[PATCH] usb: gadget: aspeed: fix dma map failure

2021-03-30 Thread rentao . bupt
From: Tao Ren 

Currently the virtual port_dev device is passed to DMA API, and this is
wrong because the device passed to DMA API calls must be the actual
hardware device performing the DMA.

The patch replaces usb_gadget_map_request/usb_gadget_unmap_request APIs
with usb_gadget_map_request_by_dev/usb_gadget_unmap_request_by_dev APIs
so the DMA capable platform device can be passed to the DMA APIs.

The patch fixes below backtrace detected on Facebook AST2500 OpenBMC
platforms:

[<80106550>] show_stack+0x20/0x24
[<80106868>] dump_stack+0x28/0x30
[<80823540>] __warn+0xfc/0x110
[<8011ac30>] warn_slowpath_fmt+0xb0/0xc0
[<8011ad44>] dma_map_page_attrs+0x24c/0x314
[<8016a27c>] usb_gadget_map_request_by_dev+0x100/0x1e4
[<805cedd8>] usb_gadget_map_request+0x1c/0x20
[<805cefbc>] ast_vhub_epn_queue+0xa0/0x1d8
[<7f02f710>] usb_ep_queue+0x48/0xc4
[<805cd3e8>] ecm_do_notify+0xf8/0x248
[<7f145920>] ecm_set_alt+0xc8/0x1d0
[<7f145c34>] composite_setup+0x680/0x1d30
[<7f00deb8>] ast_vhub_ep0_handle_setup+0xa4/0x1bc
[<7f02ee94>] ast_vhub_dev_irq+0x58/0x84
[<7f0309e0>] ast_vhub_irq+0xb0/0x1c8
[<7f02e118>] __handle_irq_event_percpu+0x50/0x19c
[<8015e5bc>] handle_irq_event_percpu+0x38/0x8c
[<8015e758>] handle_irq_event+0x38/0x4c

Signed-off-by: Tao Ren 
---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 3 ++-
 drivers/usb/gadget/udc/aspeed-vhub/epn.c  | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/core.c 
b/drivers/usb/gadget/udc/aspeed-vhub/core.c
index be7bb64e3594..d11d3d14313f 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/core.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/core.c
@@ -36,6 +36,7 @@ void ast_vhub_done(struct ast_vhub_ep *ep, struct 
ast_vhub_req *req,
   int status)
 {
bool internal = req->internal;
+   struct ast_vhub *vhub = ep->vhub;
 
EPVDBG(ep, "completing request @%p, status %d\n", req, status);
 
@@ -46,7 +47,7 @@ void ast_vhub_done(struct ast_vhub_ep *ep, struct 
ast_vhub_req *req,
 
if (req->req.dma) {
if (!WARN_ON(!ep->dev))
-   usb_gadget_unmap_request(>dev->gadget,
+   usb_gadget_unmap_request_by_dev(>pdev->dev,
 >req, ep->epn.is_in);
req->req.dma = 0;
}
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c 
b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
index 02d8bfae58fb..cb164c615e6f 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c
@@ -376,7 +376,7 @@ static int ast_vhub_epn_queue(struct usb_ep* u_ep, struct 
usb_request *u_req,
if (ep->epn.desc_mode ||
unsigned long)u_req->buf & 7) == 0) &&
 (ep->epn.is_in || !(u_req->length & (u_ep->maxpacket - 1) {
-   rc = usb_gadget_map_request(>dev->gadget, u_req,
+   rc = usb_gadget_map_request_by_dev(>pdev->dev, u_req,
ep->epn.is_in);
if (rc) {
dev_warn(>pdev->dev,
-- 
2.17.1



[PATCH] usb: gadget: aspeed: set port_dev dma mask

2021-03-26 Thread rentao . bupt
From: Tao Ren 

Set aspeed-usb vhub port_dev's dma mask to pass the dma_mask test in
"dma_map_page_attrs" function, and the dma_mask test was added in
'commit f959dcd6ddfd ("dma-direct: Fix potential NULL pointer
dereference")'.

Below is the backtrace without the patch:
[<80106550>] show_stack+0x20/0x24
[<80106868>] dump_stack+0x28/0x30
[<80823540>] __warn+0xfc/0x110
[<8011ac30>] warn_slowpath_fmt+0xb0/0xc0
[<8011ad44>] dma_map_page_attrs+0x24c/0x314
[<8016a27c>] usb_gadget_map_request_by_dev+0x100/0x1e4
[<805cedd8>] usb_gadget_map_request+0x1c/0x20
[<805cefbc>] ast_vhub_epn_queue+0xa0/0x1d8
[<7f02f710>] usb_ep_queue+0x48/0xc4
[<805cd3e8>] ecm_do_notify+0xf8/0x248
[<7f145920>] ecm_set_alt+0xc8/0x1d0
[<7f145c34>] composite_setup+0x680/0x1d30
[<7f00deb8>] ast_vhub_ep0_handle_setup+0xa4/0x1bc
[<7f02ee94>] ast_vhub_dev_irq+0x58/0x84
[<7f0309e0>] ast_vhub_irq+0xb0/0x1c8
[<7f02e118>] __handle_irq_event_percpu+0x50/0x19c
[<8015e5bc>] handle_irq_event_percpu+0x38/0x8c
[<8015e758>] handle_irq_event+0x38/0x4c

Signed-off-by: Tao Ren 
---
 drivers/usb/gadget/udc/aspeed-vhub/dev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/dev.c 
b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
index d268306a7bfe..9eb3904a6ff9 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/dev.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
@@ -569,6 +569,7 @@ int ast_vhub_init_dev(struct ast_vhub *vhub, unsigned int 
idx)
device_initialize(d->port_dev);
d->port_dev->release = ast_vhub_dev_release;
d->port_dev->parent = parent;
+   d->port_dev->dma_mask = parent->dma_mask;
dev_set_name(d->port_dev, "%s:p%d", dev_name(parent), idx + 1);
rc = device_add(d->port_dev);
if (rc)
-- 
2.17.1



[PATCH v5 1/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring driver

2020-11-23 Thread rentao . bupt
From: Tao Ren 

Add hardware monitoring driver for the Maxim MAX127 chip.

MAX127 min/max range handling code is inspired by the max197 driver.

Signed-off-by: Tao Ren 
---
 Changes in v5:
   - fix i2c_transfer() error handling.
 Changes in v4:
   - delete unnecessary "#include" lines.
   - simplify i2c_transfer() error handling.
   - add mutex to protect ctrl_byte in write_min|max() functions.
 Changes in v3:
   - no code change. xdp maintainers were removed from to/cc list.
 Changes in v2:
   - replace devm_hwmon_device_register_with_groups() with
 devm_hwmon_device_register_with_info() API.
   - divide min/max read and write methods to separate functions.
   - fix raw-to-vin conversion logic.
   - refine ctrl_byte handling so mutex is not needed to protect the
 byte.
   - improve i2c_transfer() error handling.
   - a few other improvements (comments, variable naming, and etc.).

 drivers/hwmon/Kconfig  |   9 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 352 +
 3 files changed, 362 insertions(+)
 create mode 100644 drivers/hwmon/max127.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9d600e0c5584..716df51edc87 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -950,6 +950,15 @@ config SENSORS_MAX
  This driver can also be built as a module. If so, the module
  will be called max.
 
+config SENSORS_MAX127
+   tristate "Maxim MAX127 12-bit 8-channel Data Acquisition System"
+   depends on I2C
+   help
+ Say y here to support Maxim's MAX127 DAS chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called max127.
+
 config SENSORS_MAX16065
tristate "Maxim MAX16065 System Manager and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1083bbfac779..01ca5d3fbad4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_SENSORS_LTC4260)   += ltc4260.o
 obj-$(CONFIG_SENSORS_LTC4261)  += ltc4261.o
 obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
 obj-$(CONFIG_SENSORS_MAX)  += max.o
+obj-$(CONFIG_SENSORS_MAX127)   += max127.o
 obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
 obj-$(CONFIG_SENSORS_MAX1619)  += max1619.o
 obj-$(CONFIG_SENSORS_MAX1668)  += max1668.o
diff --git a/drivers/hwmon/max127.c b/drivers/hwmon/max127.c
new file mode 100644
index ..402ffdc2f425
--- /dev/null
+++ b/drivers/hwmon/max127.c
@@ -0,0 +1,352 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for MAX127.
+ *
+ * Copyright (c) 2020 Facebook Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * MAX127 Control Byte. Refer to MAX127 datasheet, Table 1 "Control-Byte
+ * Format" for details.
+ */
+#define MAX127_CTRL_START  BIT(7)
+#define MAX127_CTRL_SEL_SHIFT  4
+#define MAX127_CTRL_RNGBIT(3)
+#define MAX127_CTRL_BIPBIT(2)
+#define MAX127_CTRL_PD1BIT(1)
+#define MAX127_CTRL_PD0BIT(0)
+
+#define MAX127_NUM_CHANNELS8
+#define MAX127_SET_CHANNEL(ch) (((ch) & 7) << MAX127_CTRL_SEL_SHIFT)
+
+/*
+ * MAX127 channel input ranges. Refer to MAX127 datasheet, Table 3 "Range
+ * and Polarity Selection" for details.
+ */
+#define MAX127_FULL_RANGE  1   /* 10V */
+#define MAX127_HALF_RANGE  5000/* 5V */
+
+/*
+ * MAX127 returns 2 bytes at read:
+ *   - the first byte contains data[11:4].
+ *   - the second byte contains data[3:0] (MSB) and 4 dummy 0s (LSB).
+ * Refer to MAX127 datasheet, "Read a Conversion (Read Cycle)" section
+ * for details.
+ */
+#define MAX127_DATA_LEN2
+#define MAX127_DATA_SHIFT  4
+
+#define MAX127_SIGN_BITBIT(11)
+
+struct max127_data {
+   struct mutex lock;
+   struct i2c_client *client;
+   u8 ctrl_byte[MAX127_NUM_CHANNELS];
+};
+
+static int max127_select_channel(struct i2c_client *client, u8 ctrl_byte)
+{
+   int status;
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = 0,
+   .len = sizeof(ctrl_byte),
+   .buf = _byte,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status < 0)
+   return status;
+   if (status != 1)
+   return -EIO;
+
+   return 0;
+}
+
+static int max127_read_channel(struct i2c_client *client, long *val)
+{
+   int status;
+   u8 i2c_data[MAX127_DATA_LEN];
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = sizeof(i2c_data),
+   .buf = i2c_data,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status < 0)
+   return status;
+   if (status != 1)
+   return -EIO;
+
+   *val = (i2c_data[1] >> MAX127_DATA_SHIFT) |
+   

[PATCH v5 0/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring

2020-11-23 Thread rentao . bupt
From: Tao Ren 

The patch series adds hardware monitoring driver for the Maxim MAX127
chip.

Patch #1 adds the max127 hardware monitoring driver, and patch #2 adds
documentation for the driver.

Tao Ren (2):
  hwmon: (max127) Add Maxim MAX127 hardware monitoring driver
  docs: hwmon: Document max127 driver

 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/max127.rst |  45 +
 drivers/hwmon/Kconfig  |   9 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 352 +
 5 files changed, 408 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst
 create mode 100644 drivers/hwmon/max127.c

-- 
2.17.1



[PATCH v5 2/2] docs: hwmon: Document max127 driver

2020-11-23 Thread rentao . bupt
From: Tao Ren 

Add documentation for the max127 hardware monitoring driver.

Signed-off-by: Tao Ren 
Reviewed-by: Guenter Roeck 
---
 Changes in v5:
   - None.
 Changes in v4:
   - None.
 Changes in v3:
   - no code change. xdp maintainers were removed from to/cc list.
 Changes in v2:
   - add more description for min/max sysfs nodes.
   - convert values from volt to millivolt in the document.

 Documentation/hwmon/index.rst  |  1 +
 Documentation/hwmon/max127.rst | 45 ++
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 408760d13813..0a07b6000c20 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -111,6 +111,7 @@ Hardware Monitoring Kernel Drivers
ltc4245
ltc4260
ltc4261
+   max127
max16064
max16065
max1619
diff --git a/Documentation/hwmon/max127.rst b/Documentation/hwmon/max127.rst
new file mode 100644
index ..dc192dd9c37c
--- /dev/null
+++ b/Documentation/hwmon/max127.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver max127
+
+
+Author:
+
+  * Tao Ren 
+
+Supported chips:
+
+  * Maxim MAX127
+
+Prefix: 'max127'
+
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX127-MAX128.pdf
+
+Description
+---
+
+The MAX127 is a multirange, 12-bit data acquisition system (DAS) providing
+8 analog input channels that are independently software programmable for
+a variety of ranges. The available ranges are {0,5V}, {0,10V}, {-5,5V}
+and {-10,10V}.
+
+The MAX127 features a 2-wire, I2C-compatible serial interface that allows
+communication among multiple devices using SDA and SCL lines.
+
+Sysfs interface
+---
+
+  == ==
+  in[0-7]_input  The input voltage (in mV) of the corresponding channel.
+RO
+
+  in[0-7]_minThe lower input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to -1, -5000, or 0.
+RW
+
+  in[0-7]_maxThe higher input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to 0, 5000, or 1.
+RW
+  == ==
-- 
2.17.1



[PATCH v4 1/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring driver

2020-11-22 Thread rentao . bupt
From: Tao Ren 

Add hardware monitoring driver for the Maxim MAX127 chip.

MAX127 min/max range handling code is inspired by the max197 driver.

Signed-off-by: Tao Ren 
---
 Changes in v4:
   - delete unnecessary "#include" lines.
   - simplify i2c_transfer() error handling.
   - add mutex to protect ctrl_byte in write_min|max() functions.
 Changes in v3:
   - no code change. xdp maintainers were removed from to/cc list.
 Changes in v2:
   - replace devm_hwmon_device_register_with_groups() with
 devm_hwmon_device_register_with_info() API.
   - divide min/max read and write methods to separate functions.
   - fix raw-to-vin conversion logic.
   - refine ctrl_byte handling so mutex is not needed to protect the
 byte.
   - improve i2c_transfer() error handling.
   - a few other improvements (comments, variable naming, and etc.).

 drivers/hwmon/Kconfig  |   9 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 346 +
 3 files changed, 356 insertions(+)
 create mode 100644 drivers/hwmon/max127.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9d600e0c5584..716df51edc87 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -950,6 +950,15 @@ config SENSORS_MAX
  This driver can also be built as a module. If so, the module
  will be called max.
 
+config SENSORS_MAX127
+   tristate "Maxim MAX127 12-bit 8-channel Data Acquisition System"
+   depends on I2C
+   help
+ Say y here to support Maxim's MAX127 DAS chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called max127.
+
 config SENSORS_MAX16065
tristate "Maxim MAX16065 System Manager and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1083bbfac779..01ca5d3fbad4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_SENSORS_LTC4260)   += ltc4260.o
 obj-$(CONFIG_SENSORS_LTC4261)  += ltc4261.o
 obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
 obj-$(CONFIG_SENSORS_MAX)  += max.o
+obj-$(CONFIG_SENSORS_MAX127)   += max127.o
 obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
 obj-$(CONFIG_SENSORS_MAX1619)  += max1619.o
 obj-$(CONFIG_SENSORS_MAX1668)  += max1668.o
diff --git a/drivers/hwmon/max127.c b/drivers/hwmon/max127.c
new file mode 100644
index ..1c54146b6086
--- /dev/null
+++ b/drivers/hwmon/max127.c
@@ -0,0 +1,346 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for MAX127.
+ *
+ * Copyright (c) 2020 Facebook Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * MAX127 Control Byte. Refer to MAX127 datasheet, Table 1 "Control-Byte
+ * Format" for details.
+ */
+#define MAX127_CTRL_START  BIT(7)
+#define MAX127_CTRL_SEL_SHIFT  4
+#define MAX127_CTRL_RNGBIT(3)
+#define MAX127_CTRL_BIPBIT(2)
+#define MAX127_CTRL_PD1BIT(1)
+#define MAX127_CTRL_PD0BIT(0)
+
+#define MAX127_NUM_CHANNELS8
+#define MAX127_SET_CHANNEL(ch) (((ch) & 7) << MAX127_CTRL_SEL_SHIFT)
+
+/*
+ * MAX127 channel input ranges. Refer to MAX127 datasheet, Table 3 "Range
+ * and Polarity Selection" for details.
+ */
+#define MAX127_FULL_RANGE  1   /* 10V */
+#define MAX127_HALF_RANGE  5000/* 5V */
+
+/*
+ * MAX127 returns 2 bytes at read:
+ *   - the first byte contains data[11:4].
+ *   - the second byte contains data[3:0] (MSB) and 4 dummy 0s (LSB).
+ * Refer to MAX127 datasheet, "Read a Conversion (Read Cycle)" section
+ * for details.
+ */
+#define MAX127_DATA_LEN2
+#define MAX127_DATA_SHIFT  4
+
+#define MAX127_SIGN_BITBIT(11)
+
+struct max127_data {
+   struct mutex lock;
+   struct i2c_client *client;
+   u8 ctrl_byte[MAX127_NUM_CHANNELS];
+};
+
+static int max127_select_channel(struct i2c_client *client, u8 ctrl_byte)
+{
+   int status;
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = 0,
+   .len = sizeof(ctrl_byte),
+   .buf = _byte,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+
+   return (status == 1) ? 0 : -EIO;
+}
+
+static int max127_read_channel(struct i2c_client *client, long *val)
+{
+   int status;
+   u8 i2c_data[MAX127_DATA_LEN];
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = sizeof(i2c_data),
+   .buf = i2c_data,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status != 1)
+   return -EIO;
+
+   *val = (i2c_data[1] >> MAX127_DATA_SHIFT) |
+   ((u16)i2c_data[0] << MAX127_DATA_SHIFT);
+   return 0;
+}
+
+static long max127_process_raw(u8 ctrl_byte, long raw)
+{
+   long scale, weight;
+
+   /*
+* MAX127's data coding is binary in 

[PATCH v4 2/2] docs: hwmon: Document max127 driver

2020-11-22 Thread rentao . bupt
From: Tao Ren 

Add documentation for the max127 hardware monitoring driver.

Signed-off-by: Tao Ren 
Reviewed-by: Guenter Roeck 
---
 Changes in v4:
   - None.
 Changes in v3:
   - no code change. xdp maintainers were removed from to/cc list.
 Changes in v2:
   - add more description for min/max sysfs nodes.
   - convert values from volt to millivolt in the document.

 Documentation/hwmon/index.rst  |  1 +
 Documentation/hwmon/max127.rst | 45 ++
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 408760d13813..0a07b6000c20 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -111,6 +111,7 @@ Hardware Monitoring Kernel Drivers
ltc4245
ltc4260
ltc4261
+   max127
max16064
max16065
max1619
diff --git a/Documentation/hwmon/max127.rst b/Documentation/hwmon/max127.rst
new file mode 100644
index ..dc192dd9c37c
--- /dev/null
+++ b/Documentation/hwmon/max127.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver max127
+
+
+Author:
+
+  * Tao Ren 
+
+Supported chips:
+
+  * Maxim MAX127
+
+Prefix: 'max127'
+
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX127-MAX128.pdf
+
+Description
+---
+
+The MAX127 is a multirange, 12-bit data acquisition system (DAS) providing
+8 analog input channels that are independently software programmable for
+a variety of ranges. The available ranges are {0,5V}, {0,10V}, {-5,5V}
+and {-10,10V}.
+
+The MAX127 features a 2-wire, I2C-compatible serial interface that allows
+communication among multiple devices using SDA and SCL lines.
+
+Sysfs interface
+---
+
+  == ==
+  in[0-7]_input  The input voltage (in mV) of the corresponding channel.
+RO
+
+  in[0-7]_minThe lower input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to -1, -5000, or 0.
+RW
+
+  in[0-7]_maxThe higher input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to 0, 5000, or 1.
+RW
+  == ==
-- 
2.17.1



[PATCH v4 0/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring

2020-11-22 Thread rentao . bupt
From: Tao Ren 

The patch series adds hardware monitoring driver for the Maxim MAX127
chip.

Patch #1 adds the max127 hardware monitoring driver, and patch #2 adds
documentation for the driver.

Tao Ren (2):
  hwmon: (max127) Add Maxim MAX127 hardware monitoring driver
  docs: hwmon: Document max127 driver

 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/max127.rst |  45 +
 drivers/hwmon/Kconfig  |   9 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 346 +
 5 files changed, 402 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst
 create mode 100644 drivers/hwmon/max127.c

-- 
2.17.1



[PATCH v3 2/2] docs: hwmon: Document max127 driver

2020-11-19 Thread rentao . bupt
From: Tao Ren 

Add documentation for the max127 hardware monitoring driver.

Signed-off-by: Tao Ren 
---
 Changes in v3:
   - no code change. xdp maintainers were removed from to/cc list.
 Changes in v2:
   - add more description for min/max sysfs nodes.
   - convert values from volt to millivolt in the document.

 Documentation/hwmon/index.rst  |  1 +
 Documentation/hwmon/max127.rst | 45 ++
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 408760d13813..0a07b6000c20 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -111,6 +111,7 @@ Hardware Monitoring Kernel Drivers
ltc4245
ltc4260
ltc4261
+   max127
max16064
max16065
max1619
diff --git a/Documentation/hwmon/max127.rst b/Documentation/hwmon/max127.rst
new file mode 100644
index ..dc192dd9c37c
--- /dev/null
+++ b/Documentation/hwmon/max127.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver max127
+
+
+Author:
+
+  * Tao Ren 
+
+Supported chips:
+
+  * Maxim MAX127
+
+Prefix: 'max127'
+
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX127-MAX128.pdf
+
+Description
+---
+
+The MAX127 is a multirange, 12-bit data acquisition system (DAS) providing
+8 analog input channels that are independently software programmable for
+a variety of ranges. The available ranges are {0,5V}, {0,10V}, {-5,5V}
+and {-10,10V}.
+
+The MAX127 features a 2-wire, I2C-compatible serial interface that allows
+communication among multiple devices using SDA and SCL lines.
+
+Sysfs interface
+---
+
+  == ==
+  in[0-7]_input  The input voltage (in mV) of the corresponding channel.
+RO
+
+  in[0-7]_minThe lower input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to -1, -5000, or 0.
+RW
+
+  in[0-7]_maxThe higher input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to 0, 5000, or 1.
+RW
+  == ==
-- 
2.17.1



[PATCH v3 1/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring driver

2020-11-19 Thread rentao . bupt
From: Tao Ren 

Add hardware monitoring driver for the Maxim MAX127 chip.

MAX127 min/max range handling code is inspired by the max197 driver.

Signed-off-by: Tao Ren 
---
 Changes in v3:
   - no code change. xdp maintainers were removed from to/cc list.
 Changes in v2:
   - replace devm_hwmon_device_register_with_groups() with
 devm_hwmon_device_register_with_info() API.
   - divide min/max read and write methods to separate functions.
   - fix raw-to-vin conversion logic.
   - refine ctrl_byte handling so mutex is not needed to protect the
 byte.
   - improve i2c_transfer() error handling.
   - a few other improvements (comments, variable naming, and etc.).

 drivers/hwmon/Kconfig  |   9 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 346 +
 3 files changed, 356 insertions(+)
 create mode 100644 drivers/hwmon/max127.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9d600e0c5584..716df51edc87 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -950,6 +950,15 @@ config SENSORS_MAX
  This driver can also be built as a module. If so, the module
  will be called max.
 
+config SENSORS_MAX127
+   tristate "Maxim MAX127 12-bit 8-channel Data Acquisition System"
+   depends on I2C
+   help
+ Say y here to support Maxim's MAX127 DAS chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called max127.
+
 config SENSORS_MAX16065
tristate "Maxim MAX16065 System Manager and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1083bbfac779..01ca5d3fbad4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_SENSORS_LTC4260)   += ltc4260.o
 obj-$(CONFIG_SENSORS_LTC4261)  += ltc4261.o
 obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
 obj-$(CONFIG_SENSORS_MAX)  += max.o
+obj-$(CONFIG_SENSORS_MAX127)   += max127.o
 obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
 obj-$(CONFIG_SENSORS_MAX1619)  += max1619.o
 obj-$(CONFIG_SENSORS_MAX1668)  += max1668.o
diff --git a/drivers/hwmon/max127.c b/drivers/hwmon/max127.c
new file mode 100644
index ..3df4c225a6a2
--- /dev/null
+++ b/drivers/hwmon/max127.c
@@ -0,0 +1,346 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for MAX127.
+ *
+ * Copyright (c) 2020 Facebook Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * MAX127 Control Byte. Refer to MAX127 datasheet, Table 1 "Control-Byte
+ * Format" for details.
+ */
+#define MAX127_CTRL_START  BIT(7)
+#define MAX127_CTRL_SEL_SHIFT  4
+#define MAX127_CTRL_RNGBIT(3)
+#define MAX127_CTRL_BIPBIT(2)
+#define MAX127_CTRL_PD1BIT(1)
+#define MAX127_CTRL_PD0BIT(0)
+
+#define MAX127_NUM_CHANNELS8
+#define MAX127_SET_CHANNEL(ch) (((ch) & 7) << MAX127_CTRL_SEL_SHIFT)
+
+/*
+ * MAX127 channel input ranges. Refer to MAX127 datasheet, Table 3 "Range
+ * and Polarity Selection" for details.
+ */
+#define MAX127_FULL_RANGE  1   /* 10V */
+#define MAX127_HALF_RANGE  5000/* 5V */
+
+/*
+ * MAX127 returns 2 bytes at read:
+ *   - the first byte contains data[11:4].
+ *   - the second byte contains data[3:0] (MSB) and 4 dummy 0s (LSB).
+ * Refer to MAX127 datasheet, "Read a Conversion (Read Cycle)" section
+ * for details.
+ */
+#define MAX127_DATA_LEN2
+#define MAX127_DATA_SHIFT  4
+
+#define MAX127_SIGN_BITBIT(11)
+
+struct max127_data {
+   struct mutex lock;
+   struct i2c_client *client;
+   u8 ctrl_byte[MAX127_NUM_CHANNELS];
+};
+
+static int max127_select_channel(struct i2c_client *client, u8 ctrl_byte)
+{
+   int status;
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = 0,
+   .len = sizeof(ctrl_byte),
+   .buf = _byte,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status < 0)
+   return status;
+   else if (status != 1)
+   return -EIO;
+
+   return 0;
+}
+
+static int max127_read_channel(struct i2c_client *client, long *val)
+{
+   int status;
+   u8 i2c_data[MAX127_DATA_LEN];
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = sizeof(i2c_data),
+   .buf = i2c_data,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status < 0)
+   return status;
+   else if (status != 1)
+   return -EIO;
+
+   *val = (i2c_data[1] >> MAX127_DATA_SHIFT) |
+   ((u16)i2c_data[0] << MAX127_DATA_SHIFT);
+   return 0;
+}
+
+static long max127_process_raw(u8 ctrl_byte, long raw)
+{
+   long scale, weight;
+
+   /*
+* MAX127's data coding is 

[PATCH v3 0/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring

2020-11-19 Thread rentao . bupt
From: Tao Ren 

The patch series adds hardware monitoring driver for the Maxim MAX127
chip.

Patch #1 adds the max127 hardware monitoring driver, and patch #2 adds
documentation for the driver.

Resending the patch series (v3) with XDP maintainers removed from to/cc
list to reduce noise.

Tao Ren (2):
  hwmon: (max127) Add Maxim MAX127 hardware monitoring driver
  docs: hwmon: Document max127 driver

 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/max127.rst |  45 +
 drivers/hwmon/Kconfig  |   9 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 346 +
 5 files changed, 402 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst
 create mode 100644 drivers/hwmon/max127.c

-- 
2.17.1



[PATCH v2 2/2] docs: hwmon: Document max127 driver

2020-11-18 Thread rentao . bupt
From: Tao Ren 

Add documentation for the max127 hardware monitoring driver.

Signed-off-by: Tao Ren 
---
 Changes in v2:
   - add more description for min/max sysfs nodes.
   - convert values from volt to millivolt in the document.

 Documentation/hwmon/index.rst  |  1 +
 Documentation/hwmon/max127.rst | 45 ++
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 408760d13813..0a07b6000c20 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -111,6 +111,7 @@ Hardware Monitoring Kernel Drivers
ltc4245
ltc4260
ltc4261
+   max127
max16064
max16065
max1619
diff --git a/Documentation/hwmon/max127.rst b/Documentation/hwmon/max127.rst
new file mode 100644
index ..dc192dd9c37c
--- /dev/null
+++ b/Documentation/hwmon/max127.rst
@@ -0,0 +1,45 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver max127
+
+
+Author:
+
+  * Tao Ren 
+
+Supported chips:
+
+  * Maxim MAX127
+
+Prefix: 'max127'
+
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX127-MAX128.pdf
+
+Description
+---
+
+The MAX127 is a multirange, 12-bit data acquisition system (DAS) providing
+8 analog input channels that are independently software programmable for
+a variety of ranges. The available ranges are {0,5V}, {0,10V}, {-5,5V}
+and {-10,10V}.
+
+The MAX127 features a 2-wire, I2C-compatible serial interface that allows
+communication among multiple devices using SDA and SCL lines.
+
+Sysfs interface
+---
+
+  == ==
+  in[0-7]_input  The input voltage (in mV) of the corresponding channel.
+RO
+
+  in[0-7]_minThe lower input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to -1, -5000, or 0.
+RW
+
+  in[0-7]_maxThe higher input limit (in mV) for the corresponding channel.
+ADC range and LSB will be updated when the limit is changed.
+For the MAX127, it will be adjusted to 0, 5000, or 1.
+RW
+  == ==
-- 
2.17.1



[PATCH v2 1/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring driver

2020-11-18 Thread rentao . bupt
From: Tao Ren 

Add hardware monitoring driver for the Maxim MAX127 chip.

MAX127 min/max range handling code is inspired by the max197 driver.

Signed-off-by: Tao Ren 
---
 Changes in v2:
   - replace devm_hwmon_device_register_with_groups() with
 devm_hwmon_device_register_with_info() API.
   - divide min/max read and write methods to separate functions.
   - fix raw-to-vin conversion logic.
   - refine ctrl_byte handling so mutex is not needed to protect the
 byte.
   - improve i2c_transfer() error handling.
   - a few other improvements (comments, variable naming, and etc.).

 drivers/hwmon/Kconfig  |   9 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 346 +
 3 files changed, 356 insertions(+)
 create mode 100644 drivers/hwmon/max127.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9d600e0c5584..716df51edc87 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -950,6 +950,15 @@ config SENSORS_MAX
  This driver can also be built as a module. If so, the module
  will be called max.
 
+config SENSORS_MAX127
+   tristate "Maxim MAX127 12-bit 8-channel Data Acquisition System"
+   depends on I2C
+   help
+ Say y here to support Maxim's MAX127 DAS chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called max127.
+
 config SENSORS_MAX16065
tristate "Maxim MAX16065 System Manager and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1083bbfac779..01ca5d3fbad4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_SENSORS_LTC4260)   += ltc4260.o
 obj-$(CONFIG_SENSORS_LTC4261)  += ltc4261.o
 obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
 obj-$(CONFIG_SENSORS_MAX)  += max.o
+obj-$(CONFIG_SENSORS_MAX127)   += max127.o
 obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
 obj-$(CONFIG_SENSORS_MAX1619)  += max1619.o
 obj-$(CONFIG_SENSORS_MAX1668)  += max1668.o
diff --git a/drivers/hwmon/max127.c b/drivers/hwmon/max127.c
new file mode 100644
index ..3df4c225a6a2
--- /dev/null
+++ b/drivers/hwmon/max127.c
@@ -0,0 +1,346 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for MAX127.
+ *
+ * Copyright (c) 2020 Facebook Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * MAX127 Control Byte. Refer to MAX127 datasheet, Table 1 "Control-Byte
+ * Format" for details.
+ */
+#define MAX127_CTRL_START  BIT(7)
+#define MAX127_CTRL_SEL_SHIFT  4
+#define MAX127_CTRL_RNGBIT(3)
+#define MAX127_CTRL_BIPBIT(2)
+#define MAX127_CTRL_PD1BIT(1)
+#define MAX127_CTRL_PD0BIT(0)
+
+#define MAX127_NUM_CHANNELS8
+#define MAX127_SET_CHANNEL(ch) (((ch) & 7) << MAX127_CTRL_SEL_SHIFT)
+
+/*
+ * MAX127 channel input ranges. Refer to MAX127 datasheet, Table 3 "Range
+ * and Polarity Selection" for details.
+ */
+#define MAX127_FULL_RANGE  1   /* 10V */
+#define MAX127_HALF_RANGE  5000/* 5V */
+
+/*
+ * MAX127 returns 2 bytes at read:
+ *   - the first byte contains data[11:4].
+ *   - the second byte contains data[3:0] (MSB) and 4 dummy 0s (LSB).
+ * Refer to MAX127 datasheet, "Read a Conversion (Read Cycle)" section
+ * for details.
+ */
+#define MAX127_DATA_LEN2
+#define MAX127_DATA_SHIFT  4
+
+#define MAX127_SIGN_BITBIT(11)
+
+struct max127_data {
+   struct mutex lock;
+   struct i2c_client *client;
+   u8 ctrl_byte[MAX127_NUM_CHANNELS];
+};
+
+static int max127_select_channel(struct i2c_client *client, u8 ctrl_byte)
+{
+   int status;
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = 0,
+   .len = sizeof(ctrl_byte),
+   .buf = _byte,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status < 0)
+   return status;
+   else if (status != 1)
+   return -EIO;
+
+   return 0;
+}
+
+static int max127_read_channel(struct i2c_client *client, long *val)
+{
+   int status;
+   u8 i2c_data[MAX127_DATA_LEN];
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = sizeof(i2c_data),
+   .buf = i2c_data,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status < 0)
+   return status;
+   else if (status != 1)
+   return -EIO;
+
+   *val = (i2c_data[1] >> MAX127_DATA_SHIFT) |
+   ((u16)i2c_data[0] << MAX127_DATA_SHIFT);
+   return 0;
+}
+
+static long max127_process_raw(u8 ctrl_byte, long raw)
+{
+   long scale, weight;
+
+   /*
+* MAX127's data coding is binary in unipolar mode with 1 LSB =
+* (Full-Scale/4096) and two’s complement 

[PATCH v2 0/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring

2020-11-18 Thread rentao . bupt
From: Tao Ren 

The patch series adds hardware monitoring driver for the Maxim MAX127
chip.

Patch #1 adds the max127 hardware monitoring driver, and patch #2 adds
documentation for the driver.

Tao Ren (2):
  hwmon: (max127) Add Maxim MAX127 hardware monitoring driver
  docs: hwmon: Document max127 driver

 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/max127.rst |  45 +
 drivers/hwmon/Kconfig  |   9 +
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 346 +
 5 files changed, 402 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst
 create mode 100644 drivers/hwmon/max127.c

-- 
2.17.1



[PATCH 2/2] docs: hwmon: Document max127 driver

2020-11-16 Thread rentao . bupt
From: Tao Ren 

Add documentation for max127 hardware monitoring driver.

Signed-off-by: Tao Ren 
---
 Documentation/hwmon/index.rst  |  1 +
 Documentation/hwmon/max127.rst | 43 ++
 2 files changed, 44 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 408760d13813..0a07b6000c20 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -111,6 +111,7 @@ Hardware Monitoring Kernel Drivers
ltc4245
ltc4260
ltc4261
+   max127
max16064
max16065
max1619
diff --git a/Documentation/hwmon/max127.rst b/Documentation/hwmon/max127.rst
new file mode 100644
index ..e50225a61c1a
--- /dev/null
+++ b/Documentation/hwmon/max127.rst
@@ -0,0 +1,43 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Kernel driver max127
+
+
+Author:
+
+  * Tao Ren 
+
+Supported chips:
+
+  * Maxim MAX127
+
+Prefix: 'max127'
+
+Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX127-MAX128.pdf
+
+Description
+---
+
+The MAX127 is a multirange, 12-bit data acquisition system (DAS) providing
+8 analog input channels that are independently software programmable for
+a variety of ranges. The available ranges are {0,5V}, {0,10V}, {-5,5V}
+and {-10,10V}.
+
+The MAX127 features a 2-wire, I2C-compatible serial interface that allows
+communication among multiple devices using SDA and SCL lines.
+
+Sysfs interface
+---
+
+  == ==
+  in[0-7]_input  The conversion value for the corresponding channel.
+RO
+
+  in[0-7]_minThe lower limit (in Volt) for the corresponding channel.
+For the MAX127, it will be adjusted to -10, -5, or 0.
+RW
+
+  in[0-7]_maxThe higher limit (in Volt) for the corresponding channel.
+For the MAX127, it will be adjusted to 0, 5, or 10.
+RW
+  == ==
-- 
2.17.1



[PATCH 0/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring

2020-11-16 Thread rentao . bupt
From: Tao Ren 

The patch series adds hardware monitoring driver for the Maxim MAX127
chip.

Patch #1 adds the max127 hardware monitoring driver, and patch #2 adds
documentation for the driver.

Tao Ren (2):
  hwmon: (max127) Add Maxim MAX127 hardware monitoring driver
  docs: hwmon: Document max127 driver

 Documentation/hwmon/index.rst  |   1 +
 Documentation/hwmon/max127.rst |  43 +
 drivers/hwmon/Kconfig  |   9 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 286 +
 5 files changed, 340 insertions(+)
 create mode 100644 Documentation/hwmon/max127.rst
 create mode 100644 drivers/hwmon/max127.c

-- 
2.17.1



[PATCH 1/2] hwmon: (max127) Add Maxim MAX127 hardware monitoring driver

2020-11-16 Thread rentao . bupt
From: Tao Ren 

Add hardware monitoring driver for the Maxim MAX127 chip.

MAX127 min/max range handling code is inspired by the max197 driver.

Signed-off-by: Tao Ren 
---
 drivers/hwmon/Kconfig  |   9 ++
 drivers/hwmon/Makefile |   1 +
 drivers/hwmon/max127.c | 286 +
 3 files changed, 296 insertions(+)
 create mode 100644 drivers/hwmon/max127.c

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9d600e0c5584..716df51edc87 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -950,6 +950,15 @@ config SENSORS_MAX
  This driver can also be built as a module. If so, the module
  will be called max.
 
+config SENSORS_MAX127
+   tristate "Maxim MAX127 12-bit 8-channel Data Acquisition System"
+   depends on I2C
+   help
+ Say y here to support Maxim's MAX127 DAS chips.
+
+ This driver can also be built as a module. If so, the module
+ will be called max127.
+
 config SENSORS_MAX16065
tristate "Maxim MAX16065 System Manager and compatibles"
depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 1083bbfac779..01ca5d3fbad4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -127,6 +127,7 @@ obj-$(CONFIG_SENSORS_LTC4260)   += ltc4260.o
 obj-$(CONFIG_SENSORS_LTC4261)  += ltc4261.o
 obj-$(CONFIG_SENSORS_LTQ_CPUTEMP) += ltq-cputemp.o
 obj-$(CONFIG_SENSORS_MAX)  += max.o
+obj-$(CONFIG_SENSORS_MAX127)   += max127.o
 obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
 obj-$(CONFIG_SENSORS_MAX1619)  += max1619.o
 obj-$(CONFIG_SENSORS_MAX1668)  += max1668.o
diff --git a/drivers/hwmon/max127.c b/drivers/hwmon/max127.c
new file mode 100644
index ..df74a95bcf28
--- /dev/null
+++ b/drivers/hwmon/max127.c
@@ -0,0 +1,286 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Hardware monitoring driver for MAX127.
+ *
+ * Copyright (c) 2020 Facebook Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* MAX127 Control Byte. */
+#define MAX127_CTRL_START  BIT(7)
+#define MAX127_CTRL_SEL_OFFSET 4
+#define MAX127_CTRL_RNGBIT(3)
+#define MAX127_CTRL_BIPBIT(2)
+#define MAX127_CTRL_PD1BIT(1)
+#define MAX127_CTRL_PD0BIT(0)
+
+#define MAX127_NUM_CHANNELS8
+#define MAX127_SET_CHANNEL(ch) (((ch) & 7) << (MAX127_CTRL_SEL_OFFSET))
+
+#define MAX127_INPUT_LIMIT 10  /* 10V */
+
+/*
+ * MAX127 returns 2 bytes at read:
+ *   - the first byte contains data[11:4].
+ *   - the second byte contains data[3:0] (MSB) and 4 dummy 0s (LSB).
+ */
+#define MAX127_DATA1_SHIFT 4
+
+struct max127_data {
+   struct mutex lock;
+   struct i2c_client *client;
+   int input_limit;
+   u8 ctrl_byte[MAX127_NUM_CHANNELS];
+};
+
+static int max127_select_channel(struct max127_data *data, int channel)
+{
+   int status;
+   struct i2c_client *client = data->client;
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = 0,
+   .len = 1,
+   .buf = >ctrl_byte[channel],
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status != 1)
+   return status;
+
+   return 0;
+}
+
+static int max127_read_channel(struct max127_data *data, int channel, u16 *vin)
+{
+   int status;
+   u8 i2c_data[2];
+   struct i2c_client *client = data->client;
+   struct i2c_msg msg = {
+   .addr = client->addr,
+   .flags = I2C_M_RD,
+   .len = 2,
+   .buf = i2c_data,
+   };
+
+   status = i2c_transfer(client->adapter, , 1);
+   if (status != 1)
+   return status;
+
+   *vin = ((i2c_data[0] << 8) | i2c_data[1]) >> MAX127_DATA1_SHIFT;
+   return 0;
+}
+
+static ssize_t max127_input_show(struct device *dev,
+struct device_attribute *dev_attr,
+char *buf)
+{
+   u16 vin;
+   int status;
+   struct max127_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute *attr = to_sensor_dev_attr(dev_attr);
+
+   if (mutex_lock_interruptible(>lock))
+   return -ERESTARTSYS;
+
+   status = max127_select_channel(data, attr->index);
+   if (status)
+   goto exit;
+
+   status = max127_read_channel(data, attr->index, );
+   if (status)
+   goto exit;
+
+   status = sprintf(buf, "%u", vin);
+
+exit:
+   mutex_unlock(>lock);
+   return status;
+}
+
+static ssize_t max127_range_show(struct device *dev,
+struct device_attribute *dev_attr,
+char *buf)
+{
+   u8 ctrl, rng_bip;
+   struct max127_data *data = dev_get_drvdata(dev);
+   struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(dev_attr);
+   int rng_type = attr->nr;/* 

[PATCH 2/4] ARM: dts: aspeed: wedge40: Use common dtsi

2020-11-11 Thread rentao . bupt
From: Tao Ren 

Simplify the Wedge40 device tree by using the common dtsi.

Signed-off-by: Tao Ren 
---
 .../boot/dts/aspeed-bmc-facebook-wedge40.dts  | 112 +-
 1 file changed, 1 insertion(+), 111 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 8c426ba2f8ab..2dcfeae3c92a 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -2,137 +2,27 @@
 // Copyright (c) 2018 Facebook Inc.
 /dts-v1/;
 
-#include "aspeed-g4.dtsi"
+#include "ast2400-facebook-netbmc-common.dtsi"
 
 / {
model = "Facebook Wedge 40 BMC";
compatible = "facebook,wedge40-bmc", "aspeed,ast2400";
 
-   aliases {
-   /*
-* Override the default uart aliases to avoid breaking
-* the legacy applications.
-*/
-   serial0 = 
-   serial1 = 
-   serial2 = 
-   serial3 = 
-   };
-
chosen {
stdout-path = 
bootargs = "console=ttyS2,9600n8 root=/dev/ram rw";
};
 
-   memory@4000 {
-   reg = <0x4000 0x2000>;
-   };
-
ast-adc-hwmon {
compatible = "iio-hwmon";
io-channels = < 5>, < 6>, < 7>, < 8>, < 9>;
};
 };
 
- {
-   status = "okay";
-   aspeed,reset-type = "system";
-};
-
  {
status = "disabled";
 };
 
- {
-   status = "okay";
-   flash@0 {
-   status = "okay";
-   m25p,fast-read;
-   label = "spi0.0";
-#include "facebook-bmc-flash-layout.dtsi"
-   };
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_txd1_default
-_rxd1_default>;
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_txd3_default
-_rxd3_default>;
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_txd4_default
-_rxd4_default
-_ndts4_default>;
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_rgmii2_default _mdio2_default>;
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
  {
status = "okay";
 };
-- 
2.17.1



[PATCH 3/4] ARM: dts: aspeed: wedge100: Use common dtsi

2020-11-11 Thread rentao . bupt
From: Tao Ren 

Simplify the Wedge100 device tree by using the common dtsi.

In addition this enables the second firmware flash, and turns on the
"i2c-mux-idle-disconnect" flag for I2C switch 7-0070.

Signed-off-by: Tao Ren 
---
 .../boot/dts/aspeed-bmc-facebook-wedge100.dts | 120 +++---
 1 file changed, 15 insertions(+), 105 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge100.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge100.dts
index 322587b7b67d..39c6be91d53f 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge100.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge100.dts
@@ -2,36 +2,16 @@
 // Copyright (c) 2018 Facebook Inc.
 /dts-v1/;
 
-#include "aspeed-g4.dtsi"
+#include "ast2400-facebook-netbmc-common.dtsi"
 
 / {
model = "Facebook Wedge 100 BMC";
compatible = "facebook,wedge100-bmc", "aspeed,ast2400";
 
-   aliases {
-   /*
-* Override the default uart aliases to avoid breaking
-* the legacy applications.
-*/
-   serial0 = 
-   serial1 = 
-   serial2 = 
-   serial3 = 
-   };
-
chosen {
stdout-path = 
bootargs = "console=ttyS2,9600n8 root=/dev/ram rw";
};
-
-   memory@4000 {
-   reg = <0x4000 0x2000>;
-   };
-};
-
- {
-   status = "okay";
-   aspeed,reset-type = "system";
 };
 
  {
@@ -40,108 +20,38 @@
 };
 
  {
-   status = "okay";
-   flash@0 {
+   flash@1 {
status = "okay";
m25p,fast-read;
-   label = "fmc0";
-#include "facebook-bmc-flash-layout.dtsi"
+   label = "spi0.1";
+
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   flash1@0 {
+   reg = <0x0 0x200>;
+   label = "flash1";
+   };
+   };
};
 };
 
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_txd1_default
-_rxd1_default>;
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_txd3_default
-_rxd3_default>;
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_txd4_default
-_rxd4_default>;
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-   pinctrl-names = "default";
-   pinctrl-0 = <_rgmii2_default _mdio2_default>;
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
  {
-   status = "okay";
-
i2c-switch@70 {
compatible = "nxp,pca9548";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x70>;
+   i2c-mux-idle-disconnect;
};
 };
 
- {
-   status = "okay";
-};
-
  {
status = "okay";
 };
 
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
 
  {
status = "okay";
-- 
2.17.1



[PATCH 1/4] ARM: dts: aspeed: Common dtsi for Facebook AST2400 Network BMCs

2020-11-11 Thread rentao . bupt
From: Tao Ren 

This common descirption is included by all Facebook AST2400 Network BMC
platforms to minimize duplicated device entries across Facebook Network
BMC device trees.

Signed-off-by: Tao Ren 
---
 .../dts/ast2400-facebook-netbmc-common.dtsi   | 117 ++
 1 file changed, 117 insertions(+)
 create mode 100644 arch/arm/boot/dts/ast2400-facebook-netbmc-common.dtsi

diff --git a/arch/arm/boot/dts/ast2400-facebook-netbmc-common.dtsi 
b/arch/arm/boot/dts/ast2400-facebook-netbmc-common.dtsi
new file mode 100644
index ..73a5503be78c
--- /dev/null
+++ b/arch/arm/boot/dts/ast2400-facebook-netbmc-common.dtsi
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (c) 2020 Facebook Inc.
+/dts-v1/;
+
+#include "aspeed-g4.dtsi"
+
+/ {
+   aliases {
+   /*
+* Override the default uart aliases to avoid breaking
+* the legacy applications.
+*/
+   serial0 = 
+   serial1 = 
+   serial2 = 
+   serial3 = 
+   };
+
+   memory@4000 {
+   reg = <0x4000 0x2000>;
+   };
+};
+
+ {
+   status = "okay";
+   aspeed,reset-type = "system";
+};
+
+ {
+   status = "okay";
+   flash@0 {
+   status = "okay";
+   m25p,fast-read;
+   label = "spi0.0";
+#include "facebook-bmc-flash-layout.dtsi"
+   };
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_txd1_default
+_rxd1_default>;
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_txd3_default
+_rxd3_default>;
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_txd4_default
+_rxd4_default
+_ndts4_default>;
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii2_default _mdio2_default>;
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
-- 
2.17.1



[PATCH 4/4] ARM: dts: aspeed: Add Facebook Galaxy100 (AST2400) BMC

2020-11-11 Thread rentao . bupt
From: Tao Ren 

Add initial version of device tree for Facebook Galaxy100 (AST2400) BMC.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/Makefile|  1 +
 .../dts/aspeed-bmc-facebook-galaxy100.dts | 57 +++
 2 files changed, 58 insertions(+)
 create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-galaxy100.dts

diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 21477ef5c5c9..1917cd47204a 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -1383,6 +1383,7 @@ dtb-$(CONFIG_ARCH_ASPEED) += \
aspeed-bmc-arm-stardragon4800-rep2.dtb \
aspeed-bmc-bytedance-g220a.dtb \
aspeed-bmc-facebook-cmm.dtb \
+   aspeed-bmc-facebook-galaxy100.dtb \
aspeed-bmc-facebook-minipack.dtb \
aspeed-bmc-facebook-tiogapass.dtb \
aspeed-bmc-facebook-wedge40.dtb \
diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-galaxy100.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-galaxy100.dts
new file mode 100644
index ..dcf213472749
--- /dev/null
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-galaxy100.dts
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (c) 2020 Facebook Inc.
+/dts-v1/;
+
+#include "ast2400-facebook-netbmc-common.dtsi"
+
+/ {
+   model = "Facebook Galaxy 100 BMC";
+   compatible = "facebook,galaxy100-bmc", "aspeed,ast2400";
+
+   chosen {
+   stdout-path = 
+   bootargs = "console=ttyS0,9600n8 root=/dev/ram rw";
+   };
+
+   ast-adc-hwmon {
+   compatible = "iio-hwmon";
+   io-channels = < 3>, < 4>, < 8>, < 9>;
+   };
+};
+
+ {
+   status = "okay";
+   aspeed,reset-type = "system";
+};
+
+ {
+   flash@1 {
+   status = "okay";
+   m25p,fast-read;
+   label = "spi0.1";
+
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   flash1@0 {
+   reg = <0x0 0x200>;
+   label = "flash1";
+   };
+   };
+   };
+};
+
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
-- 
2.17.1



[PATCH 0/4] ARM: dts: aspeed: Add Facebook Galaxy100 BMC

2020-11-11 Thread rentao . bupt
From: Tao Ren 

The patch series adds the initial version of device tree for Facebook
Galaxy100 (AST2400) BMC.

Patch #1 adds common dtsi to minimize duplicated device entries across
Facebook Network AST2400 BMC device trees.

Patch #2 simplfies Wedge40 device tree by using the common dtsi.

Patch #3 simplfies Wedge100 device tree by using the common dtsi.

Patch #4 adds the initial version of device tree for Facebook Galaxy100
BMC.

Tao Ren (4):
  ARM: dts: aspeed: Common dtsi for Facebook AST2400 Network BMCs
  ARM: dts: aspeed: wedge40: Use common dtsi
  ARM: dts: aspeed: wedge100: Use common dtsi
  ARM: dts: aspeed: Add Facebook Galaxy100 (AST2400) BMC

 arch/arm/boot/dts/Makefile|   1 +
 .../dts/aspeed-bmc-facebook-galaxy100.dts |  57 +
 .../boot/dts/aspeed-bmc-facebook-wedge100.dts | 120 +++---
 .../boot/dts/aspeed-bmc-facebook-wedge40.dts  | 112 +---
 .../dts/ast2400-facebook-netbmc-common.dtsi   | 117 +
 5 files changed, 191 insertions(+), 216 deletions(-)
 create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-galaxy100.dts
 create mode 100644 arch/arm/boot/dts/ast2400-facebook-netbmc-common.dtsi

-- 
2.17.1



[PATCH] ARM: dts: aspeed: minipack: Fixup I2C tree

2020-11-09 Thread rentao . bupt
From: Tao Ren 

Create all the i2c switches in device tree and use aliases to assign
child channels with consistent bus numbers.

Besides, "i2c-mux-idle-disconnect" is set for all the i2c switches to
avoid potential conflicts when multiple devices (beind the switches) use
the same device address.

Signed-off-by: Tao Ren 
---
 .../boot/dts/aspeed-bmc-facebook-minipack.dts | 888 ++
 1 file changed, 888 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts
index c34741dbd268..9eb23e874f19 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts
@@ -70,6 +70,162 @@
i2c45 = 
i2c46 = 
i2c47 = 
+
+   /*
+* I2C Switch 24-0071 (channel #0 of 8-0070): 8 channels for
+* connecting to left PDB (Power Distribution Board).
+*/
+   i2c48 = 
+   i2c49 = 
+   i2c50 = 
+   i2c51 = 
+   i2c52 = 
+   i2c53 = 
+   i2c54 = 
+   i2c55 = 
+
+   /*
+* I2C Switch 25-0072 (channel #1 of 8-0070): 8 channels for
+* connecting to right PDB (Power Distribution Board).
+*/
+   i2c56 = 
+   i2c57 = 
+   i2c58 = 
+   i2c59 = 
+   i2c60 = 
+   i2c61 = 
+   i2c62 = 
+   i2c63 = 
+
+   /*
+* I2C Switch 26-0076 (channel #2 of 8-0070): 8 channels for
+* connecting to top FCM (Fan Control Module).
+*/
+   i2c64 = 
+   i2c65 = 
+   i2c66 = 
+   i2c67 = 
+   i2c68 = 
+   i2c69 = 
+   i2c70 = 
+   i2c71 = 
+
+   /*
+* I2C Switch 27-0076 (channel #3 of 8-0070): 8 channels for
+* connecting to bottom FCM (Fan Control Module).
+*/
+   i2c72 = 
+   i2c73 = 
+   i2c74 = 
+   i2c75 = 
+   i2c76 = 
+   i2c77 = 
+   i2c78 = 
+   i2c79 = 
+
+   /*
+* I2C Switch 40-0073 (channel #0 of 11-0070): connecting
+* to PIM (Port Interface Module) #1 (1-based).
+*/
+   i2c80 = 
+   i2c81 = 
+   i2c82 = 
+   i2c83 = 
+   i2c84 = 
+   i2c85 = 
+   i2c86 = 
+   i2c87 = 
+
+   /*
+* I2C Switch 41-0073 (channel #1 of 11-0070): connecting
+* to PIM (Port Interface Module) #2 (1-based).
+*/
+   i2c88 = 
+   i2c89 = 
+   i2c90 = 
+   i2c91 = 
+   i2c92 = 
+   i2c93 = 
+   i2c94 = 
+   i2c95 = 
+
+   /*
+* I2C Switch 42-0073 (channel #2 of 11-0070): connecting
+* to PIM (Port Interface Module) #3 (1-based).
+*/
+   i2c96 = 
+   i2c97 = 
+   i2c98 = 
+   i2c99 = 
+   i2c100 = 
+   i2c101 = 
+   i2c102 = 
+   i2c103 = 
+
+   /*
+* I2C Switch 43-0073 (channel #3 of 11-0070): connecting
+* to PIM (Port Interface Module) #4 (1-based).
+*/
+   i2c104 = 
+   i2c105 = 
+   i2c106 = 
+   i2c107 = 
+   i2c108 = 
+   i2c109 = 
+   i2c110 = 
+   i2c111 = 
+
+   /*
+* I2C Switch 44-0073 (channel #4 of 11-0070): connecting
+* to PIM (Port Interface Module) #5 (1-based).
+*/
+   i2c112 = 
+   i2c113 = 
+   i2c114 = 
+   i2c115 = 
+   i2c116 = 
+   i2c117 = 
+   i2c118 = 
+   i2c119 = 
+
+   /*
+* I2C Switch 45-0073 (channel #5 of 11-0070): connecting
+* to PIM (Port Interface Module) #6 (1-based).
+*/
+   i2c120 = 
+   i2c121 = 
+   i2c122 = 
+   i2c123 = 
+   i2c124 = 
+   i2c125 = 
+   i2c126 = 
+   i2c127 = 
+
+   /*
+* I2C Switch 46-0073 (channel #6 of 11-0070): connecting
+* to PIM (Port Interface Module) #7 (1-based).
+*/
+   i2c128 = 
+   i2c129 = 
+   i2c130 = 
+   i2c131 = 
+   i2c132 = 
+   i2c133 = 
+   

[PATCH] ARM: dts: aspeed: wedge400: Fix FMC flash0 layout

2020-11-09 Thread rentao . bupt
From: Tao Ren 

Update "data0" partition's size from 8MB to 4MB to fix "partition data0
extends beyond the end of device" warning at bootup time.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
index ad1fcad3676c..63a3dd548f30 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
@@ -124,8 +124,8 @@
 * "data0" partition (4MB) is reserved for persistent
 * data store.
 */
-   data0@380 {
-   reg = <0x7c0 0x80>;
+   data0@7c0 {
+   reg = <0x7c0 0x40>;
label = "data0";
};
 
-- 
2.17.1



[PATCH] gpio: aspeed: fix ast2600 bank properties

2020-09-16 Thread rentao . bupt
From: Tao Ren 

GPIO_U is mapped to the least significant byte of input/output mask, and
the byte in "output" mask should be 0 because GPIO_U is input only. All
the other bits need to be 1 because GPIO_V/W/X support both input and
output modes.

Similarly, GPIO_Y/Z are mapped to the 2 least significant bytes, and the
according bits need to be 1 because GPIO_Y/Z support both input and
output modes.

Fixes: ab4a85534c3e ("gpio: aspeed: Add in ast2600 details to Aspeed driver")
Signed-off-by: Tao Ren 
---
 drivers/gpio/gpio-aspeed.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index 879db23d8454..d07bf2c3f136 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -1114,8 +1114,8 @@ static const struct aspeed_gpio_config ast2500_config =
 
 static const struct aspeed_bank_props ast2600_bank_props[] = {
/* input  output   */
-   {5, 0x,  0x}, /* U/V/W/X */
-   {6, 0x,  0x0fff}, /* Y/Z */
+   {5, 0x,  0xff00}, /* U/V/W/X */
+   {6, 0x,  0x}, /* Y/Z */
{ },
 };
 
-- 
2.17.1



[PATCH 1/5] ARM: dts: aspeed: Remove flash layout from Facebook AST2500 Common dtsi

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Remove FMC flash layout from ast2500-facebook-netbmc-common.dtsi because
flash size and layout varies across different Facebook AST2500 OpenBMC
platforms.

Signed-off-by: Tao Ren 
---
 .../boot/dts/ast2500-facebook-netbmc-common.dtsi| 13 -
 1 file changed, 13 deletions(-)

diff --git a/arch/arm/boot/dts/ast2500-facebook-netbmc-common.dtsi 
b/arch/arm/boot/dts/ast2500-facebook-netbmc-common.dtsi
index 7468f102bd76..c0c43b8644ee 100644
--- a/arch/arm/boot/dts/ast2500-facebook-netbmc-common.dtsi
+++ b/arch/arm/boot/dts/ast2500-facebook-netbmc-common.dtsi
@@ -47,25 +47,12 @@
status = "okay";
m25p,fast-read;
label = "spi0.0";
-
-#include "facebook-bmc-flash-layout.dtsi"
};
 
fmc_flash1: flash@1 {
status = "okay";
m25p,fast-read;
label = "spi0.1";
-
-   partitions {
-   compatible = "fixed-partitions";
-   #address-cells = <1>;
-   #size-cells = <1>;
-
-   flash1@0 {
-   reg = <0x0 0x200>;
-   label = "flash1";
-   };
-   };
};
 };
 
-- 
2.17.1



[PATCH 2/5] ARM: dts: aspeed: cmm: Set 32MB FMC flash layout

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Set 32MB FMC flash layout in CMM device tree explicitly because the flash
layout settings were removed from "ast2500-facebook-netbmc-common.dtsi".

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
index 7bc7df7ed428..2fb8b147f489 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
@@ -1571,3 +1571,20 @@
  {
status = "disabled";
 };
+
+_flash0 {
+#include "facebook-bmc-flash-layout.dtsi"
+};
+
+_flash1 {
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   flash1@0 {
+   reg = <0x0 0x200>;
+   label = "flash1";
+   };
+   };
+};
-- 
2.17.1



[PATCH 0/5] ARM: dts: aspeed: Add Facebook Wedge400 (AST2500) BMC

2020-08-24 Thread rentao . bupt
From: Tao Ren 

The patch series adds Facebook Wedge400 (AST2500) BMC device tree, and
FMC flash layout is re-structured because flash size and layout varies
across different Facebook AST2500 OpenBMC platforms.

Patch #1 removes flash layout from ast2500-facebook-netbmc-common.dtsi
because now we have 32MB, 64MB an 128MB flashes on different Facebook
AST2500 OpenBMC platforms.

Patch #2, #3 and #4 sets FMC flash layout in CMM, Yamp and Minipack
device tree explicitly because the original layout settings were removed
from ast2500-facebook-netbmc-common.dtsi (in patch #1).

Patch #5 adds Facebook Wedge400 AST2500 BMC device tree.


Tao Ren (5):
  ARM: dts: aspeed: Remove flash layout from Facebook AST2500 Common
dtsi
  ARM: dts: aspeed: cmm: Set 32MB FMC flash layout
  ARM: dts: aspeed: yamp: Set 32MB FMC flash layout
  ARM: dts: aspeed: minipack: Update 64MB FMC flash layout
  ARM: dts: aspeed: Add Facebook Wedge400 BMC

 arch/arm/boot/dts/Makefile|   1 +
 arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts |  17 +
 .../boot/dts/aspeed-bmc-facebook-minipack.dts |  47 +-
 .../boot/dts/aspeed-bmc-facebook-wedge400.dts | 420 ++
 .../arm/boot/dts/aspeed-bmc-facebook-yamp.dts |  17 +
 .../dts/ast2500-facebook-netbmc-common.dtsi   |  13 -
 6 files changed, 500 insertions(+), 15 deletions(-)
 create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts

-- 
2.17.1



[PATCH 4/5] ARM: dts: aspeed: minipack: Update 64MB FMC flash layout

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Set 64Mb FMC flash layout in Minipack device tree explicitly because the
flash layout was removed from "ast2500-facebook-netbmc-common.dtsi".

Please note "data0" partition' size is updated to 4MB to be consistent
with other Facebook OpenBMC platforms.

Signed-off-by: Tao Ren 
---
 .../boot/dts/aspeed-bmc-facebook-minipack.dts | 47 ++-
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts
index 88ce4ff9f47e..c34741dbd268 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-minipack.dts
@@ -88,17 +88,60 @@
  */
 _flash0 {
partitions {
-   data0@1c0 {
-   reg = <0x1c0 0x240>;
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   /*
+* u-boot partition: 384KB.
+*/
+   u-boot@0 {
+   reg = <0x0 0x6>;
+   label = "u-boot";
};
+
+   /*
+* u-boot environment variables: 128KB.
+*/
+   u-boot-env@6 {
+   reg = <0x6 0x2>;
+   label = "env";
+   };
+
+   /*
+* FIT image: 59.5 MB.
+*/
+   fit@8 {
+   reg = <0x8 0x3b8>;
+   label = "fit";
+   };
+
+   /*
+* "data0" partition (4MB) is reserved for persistent
+* data store.
+*/
+   data0@380 {
+   reg = <0x3c0 0x40>;
+   label = "data0";
+   };
+
+   /*
+* "flash0" partition (covering the entire flash) is
+* explicitly created to avoid breaking legacy applications.
+*/
flash0@0 {
reg = <0x0 0x400>;
+   label = "flash0";
};
};
 };
 
 _flash1 {
partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
flash1@0 {
reg = <0x0 0x400>;
};
-- 
2.17.1



[PATCH 3/5] ARM: dts: aspeed: yamp: Set 32MB FMC flash layout

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Set 32MB FMC flash layout in Yamp device tree explicitly because flash
layout settings were removed from "ast2500-facebook-netbmc-common.dtsi".

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
index fe2e11c2da15..5e6105874217 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
@@ -108,3 +108,20 @@
  {
status = "okay";
 };
+
+_flash0 {
+#include "facebook-bmc-flash-layout.dtsi"
+};
+
+_flash1 {
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   flash1@0 {
+   reg = <0x0 0x200>;
+   label = "flash1";
+   };
+   };
+};
-- 
2.17.1



[PATCH 5/5] ARM: dts: aspeed: Add Facebook Wedge400 BMC

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Add initial version of device tree for Facebook Wedge400 (AST2500) BMC.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/Makefile|   1 +
 .../boot/dts/aspeed-bmc-facebook-wedge400.dts | 420 ++
 2 files changed, 421 insertions(+)
 create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts

diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 77f1c95c4e1c..24f7acc0e2ee 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -1354,6 +1354,7 @@ dtb-$(CONFIG_ARCH_ASPEED) += \
aspeed-bmc-facebook-tiogapass.dtb \
aspeed-bmc-facebook-wedge40.dtb \
aspeed-bmc-facebook-wedge100.dtb \
+   aspeed-bmc-facebook-wedge400.dtb \
aspeed-bmc-facebook-yamp.dtb \
aspeed-bmc-facebook-yosemitev2.dtb \
aspeed-bmc-ibm-rainier.dtb \
diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
new file mode 100644
index ..ad1fcad3676c
--- /dev/null
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge400.dts
@@ -0,0 +1,420 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (c) 2019 Facebook Inc.
+/dts-v1/;
+
+#include 
+#include "ast2500-facebook-netbmc-common.dtsi"
+
+/ {
+   model = "Facebook Wedge 400 BMC";
+   compatible = "facebook,wedge400-bmc", "aspeed,ast2500";
+
+   aliases {
+   /*
+* PCA9548 (2-0070) provides 8 channels connecting to
+* SCM (System Controller Module).
+*/
+   i2c16 = 
+   i2c17 = 
+   i2c18 = 
+   i2c19 = 
+   i2c20 = 
+   i2c21 = 
+   i2c22 = 
+   i2c23 = 
+
+   /*
+* PCA9548 (8-0070) provides 8 channels connecting to
+* SMB (Switch Main Board).
+*/
+   i2c24 = 
+   i2c25 = 
+   i2c26 = 
+   i2c27 = 
+   i2c28 = 
+   i2c29 = 
+   i2c30 = 
+   i2c31 = 
+
+   /*
+* PCA9548 (11-0076) provides 8 channels connecting to
+* FCM (Fan Controller Module).
+*/
+   i2c32 = 
+   i2c33 = 
+   i2c34 = 
+   i2c35 = 
+   i2c36 = 
+   i2c37 = 
+   i2c38 = 
+   i2c39 = 
+
+   spi2 = _gpio;
+   };
+
+   chosen {
+   stdout-path = 
+   bootargs = "console=ttyS0,9600n8 root=/dev/ram rw";
+   };
+
+   ast-adc-hwmon {
+   compatible = "iio-hwmon";
+   io-channels = < 0>, < 1>, < 2>, < 3>, < 4>;
+   };
+
+   /*
+* GPIO-based SPI Master is required to access SPI TPM, because
+* full-duplex SPI transactions are not supported by ASPEED SPI
+* Controllers.
+*/
+   spi_gpio: spi-gpio {
+   status = "okay";
+   compatible = "spi-gpio";
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   cs-gpios = < ASPEED_GPIO(R, 2) GPIO_ACTIVE_LOW>;
+   gpio-sck = < ASPEED_GPIO(R, 3) GPIO_ACTIVE_HIGH>;
+   gpio-mosi = < ASPEED_GPIO(R, 4) GPIO_ACTIVE_HIGH>;
+   gpio-miso = < ASPEED_GPIO(R, 5) GPIO_ACTIVE_HIGH>;
+   num-chipselects = <1>;
+
+   tpmdev@0 {
+   compatible = "tcg,tpm_tis-spi";
+   spi-max-frequency = <3300>;
+   reg = <0>;
+   };
+   };
+};
+
+/*
+ * Both firmware flashes are 128MB on Wedge400 BMC.
+ */
+_flash0 {
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   /*
+* u-boot partition: 384KB.
+*/
+   u-boot@0 {
+   reg = <0x0 0x6>;
+   label = "u-boot";
+   };
+
+   /*
+* u-boot environment variables: 128KB.
+*/
+   u-boot-env@6 {
+   reg = <0x6 0x2>;
+   label = "env";
+   };
+
+   /*
+* FIT image: 123.5 MB.
+*/
+   fit@8 {
+   reg = <0x8 0x7b8>;
+   label = "fit";
+   };
+
+   /*
+* "data0" partition (4MB) is reserved for persistent
+* data store.
+*/
+   data0@380 {
+   reg = <0x7c0 0x80>;
+   label = "data0";
+   };
+
+   /*
+* "flash0" partition (covering the entire flash) is
+* explicitly created to 

[PATCH 1/2] ARM: dts: aspeed: wedge40: Update FMC flash0 label

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Update FMC flash0's label to "spi0.0" so it's consistent with all the
other Facebook OpenBMC platforms.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 8ac23ff6b09e..3f2a48fa77b3 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -48,7 +48,7 @@
flash@0 {
status = "okay";
m25p,fast-read;
-   label = "fmc0";
+   label = "spi0.0";
 #include "facebook-bmc-flash-layout.dtsi"
};
 };
-- 
2.17.1



[PATCH 2/2] ARM: dts: aspeed: wedge40: Update UART4 pin settings

2020-08-24 Thread rentao . bupt
From: Tao Ren 

Enable UART4's NRTS4 (A19) pin because the pin is used for RS485
software emulation.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 3f2a48fa77b3..8c426ba2f8ab 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -71,7 +71,8 @@
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <_txd4_default
-_rxd4_default>;
+_rxd4_default
+_ndts4_default>;
 };
 
  {
-- 
2.17.1



[PATCH 0/2] ARM: dts: aspeed: wedge40: fix a few nits

2020-08-24 Thread rentao . bupt
From: Tao Ren 

This patch series fixes a few nits in wedge40 device tree.

Patch #1 updates FMC flash label so it's consistent with other Facebook
OpenBMC platforms.

Patch #2 updates UART4 pin settings for the purpose of RS485 software
emulation.

Tao Ren (2):
  ARM: dts: aspeed: wedge40: Update FMC flash0 label
  ARM: dts: aspeed: wedge40: Update UART4 pin settings

 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

-- 
2.17.1



[PATCH v2] ARM: dts: aspeed: cmm: fixup i2c tree

2020-07-23 Thread rentao . bupt
From: Tao Ren 

Create all the i2c switches in device tree and use aliases to assign
child channels with consistent bus numbers.

Besides, "i2c-mux-idle-disconnect" is set for all the i2c switches to
avoid potential conflicts when multiple devices (beind the switches)
use the same device address.

Signed-off-by: Tao Ren 
---
 Changes in v2:
   - Nothing changed. Resending the patch just in case the previous
 email was not delivered.

 arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts | 1231 -
 1 file changed, 1228 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
index 016bbcb99bb6..7bc7df7ed428 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
@@ -19,8 +19,8 @@
serial3 = 
 
/*
-* Hardcode the bus number of i2c switches' channels to
-* avoid breaking the legacy applications.
+* PCA9548 (1-0077) provides 8 channels for connecting to
+* 4 Line Cards and 4 Fabric Cards.
 */
i2c16 = 
i2c17 = 
@@ -30,6 +30,11 @@
i2c21 = 
i2c22 = 
i2c23 = 
+
+   /*
+* PCA9548 (2-0071) provides 8 channels for connecting to
+* Power Distribution Board.
+*/
i2c24 = 
i2c25 = 
i2c26 = 
@@ -38,6 +43,11 @@
i2c29 = 
i2c30 = 
i2c31 = 
+
+   /*
+* PCA9548 (8-0077) provides 8 channels and the first 4
+* channels are connecting to 4 Fan Control Boards.
+*/
i2c32 = 
i2c33 = 
i2c34 = 
@@ -46,6 +56,226 @@
i2c37 = 
i2c38 = 
i2c39 = 
+
+   /*
+* 2 PCA9548 (18-0070 & 18-0073), 16 channels connecting
+* to Line Card #1.
+*/
+   i2c40 = 
+   i2c41 = 
+   i2c42 = 
+   i2c43 = 
+   i2c44 = 
+   i2c45 = 
+   i2c46 = 
+   i2c47 = 
+   i2c48 = 
+   i2c49 = 
+   i2c50 = 
+   i2c51 = 
+   i2c52 = 
+   i2c53 = 
+   i2c54 = 
+   i2c55 = 
+
+   /*
+* 2 PCA9548 (19-0070 & 19-0073), 16 channels connecting
+* to Line Card #2.
+*/
+   i2c56 = 
+   i2c57 = 
+   i2c58 = 
+   i2c59 = 
+   i2c60 = 
+   i2c61 = 
+   i2c62 = 
+   i2c63 = 
+   i2c64 = 
+   i2c65 = 
+   i2c66 = 
+   i2c67 = 
+   i2c68 = 
+   i2c69 = 
+   i2c70 = 
+   i2c71 = 
+
+   /*
+* 2 PCA9548 (20-0070 & 20-0073), 16 channels connecting
+* to Line Card #3.
+*/
+   i2c72 = 
+   i2c73 = 
+   i2c74 = 
+   i2c75 = 
+   i2c76 = 
+   i2c77 = 
+   i2c78 = 
+   i2c79 = 
+   i2c80 = 
+   i2c81 = 
+   i2c82 = 
+   i2c83 = 
+   i2c84 = 
+   i2c85 = 
+   i2c86 = 
+   i2c87 = 
+
+   /*
+* 2 PCA9548 (21-0070 & 21-0073), 16 channels connecting
+* to Line Card #4.
+*/
+   i2c88 = 
+   i2c89 = 
+   i2c90 = 
+   i2c91 = 
+   i2c92 = 
+   i2c93 = 
+   i2c94 = 
+   i2c95 = 
+   i2c96 = 
+   i2c97 = 
+   i2c98 = 
+   i2c99 = 
+   i2c100 = 
+   i2c101 = 
+   i2c102 = 
+   i2c103 = 
+
+   /*
+* 2 PCA9548 (16-0070 & 16-0073), 16 channels connecting
+* to Fabric Card #1.
+*/
+   i2c104 = 
+   i2c105 = 
+   i2c106 = 
+   i2c107 = 
+   i2c108 = 
+   i2c109 = 
+   i2c110 = 
+   i2c111 = 
+   i2c112 = 
+   i2c113 = 
+   i2c114 = 
+   i2c115 = 
+   i2c116 = 
+   i2c117 = 
+   i2c118 = 
+   i2c119 = 
+
+   /*
+* 2 PCA9548 (17-0070 & 17-0073), 16 channels connecting
+* to Fabric Card #2.
+*/
+   i2c120 = 
+   i2c121 = 
+   i2c122 = 
+  

[PATCH v2 0/3] ARM: dts: aspeed: fixup wedge40 device tree

2020-07-23 Thread rentao . bupt
From: Tao Ren 

The patch series update several devices' settings in Facebook Wedge40
device tree.

Patch #1 disables a few i2c controllers as they are not being used at
present.

Patch #2 enables adc device for voltage monitoring.

Patch #3 enables pwm_tacho device for fan control and monitoring.

Tao Ren (3):
  ARM: dts: aspeed: wedge40: disable a few i2c controllers
  ARM: dts: aspeed: wedge40: enable adc device
  ARM: dts: aspeed: wedge40: enable pwm_tacho device

 .../boot/dts/aspeed-bmc-facebook-wedge40.dts  | 42 +++
 1 file changed, 34 insertions(+), 8 deletions(-)

-- 
2.17.1



[PATCH v2 3/3] ARM: dts: aspeed: wedge40: enable pwm_tacho device

2020-07-23 Thread rentao . bupt
From: Tao Ren 

Enable pwm_tacho device for fan control and monitoring in Wedge40.

Signed-off-by: Tao Ren 
---
 Changes in v2:
   - Nothing changed. Resending the patch just in case the previous
 email was not delivered.

 .../boot/dts/aspeed-bmc-facebook-wedge40.dts  | 29 +++
 1 file changed, 29 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 1049cfa80ac2..8ac23ff6b09e 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -135,3 +135,32 @@
  {
status = "okay";
 };
+
+_tacho {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pwm0_default
+_pwm1_default
+_pwm6_default
+_pwm7_default>;
+
+   fan@0 {
+   reg = <0x00>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x00 0x01>;
+   };
+
+   fan@1 {
+   reg = <0x01>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x02 0x03>;
+   };
+
+   fan@6 {
+   reg = <0x06>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x04 0x05>;
+   };
+
+   fan@7 {
+   reg = <0x07>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x06 0x07>;
+   };
+};
-- 
2.17.1



[PATCH v2 1/3] ARM: dts: aspeed: wedge40: disable a few i2c controllers

2020-07-23 Thread rentao . bupt
From: Tao Ren 

Disable i2c bus #9, #10 and #13 as these i2c controllers are not used on
Wedge40.

Signed-off-by: Tao Ren 
---
 Changes in v2:
   - Nothing changed. Resending the patch just in case the previous
 email was not delivered.

 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 12 
 1 file changed, 12 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 54e508530dce..aea23c313088 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -115,14 +115,6 @@
status = "okay";
 };
 
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
  {
status = "okay";
 };
@@ -131,10 +123,6 @@
status = "okay";
 };
 
- {
-   status = "okay";
-};
-
  {
status = "okay";
 };
-- 
2.17.1



[PATCH v2 2/3] ARM: dts: aspeed: wedge40: enable adc device

2020-07-23 Thread rentao . bupt
From: Tao Ren 

Enable adc controller and corresponding voltage sensoring channels for
Wedge40.

Signed-off-by: Tao Ren 
---
 Changes in v2:
   - Nothing changed. Resending the patch just in case the previous
 email was not delivered.

 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index aea23c313088..1049cfa80ac2 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -27,6 +27,11 @@
memory@4000 {
reg = <0x4000 0x2000>;
};
+
+   ast-adc-hwmon {
+   compatible = "iio-hwmon";
+   io-channels = < 5>, < 6>, < 7>, < 8>, < 9>;
+   };
 };
 
  {
@@ -126,3 +131,7 @@
  {
status = "okay";
 };
+
+ {
+   status = "okay";
+};
-- 
2.17.1



[PATCH] hwmon: (pmbus) fix a typo in Kconfig SENSORS_IR35221 option

2020-07-02 Thread rentao . bupt
From: Tao Ren 

Fix a typo in SENSORS_IR35221 option: module name should be "ir35221"
instead of "ir35521".

Fixes: 8991ebd9c9a6 ("hwmon: (pmbus) Add client driver for IR35221")

Cc: Samuel Mendoza-Jonas 
Signed-off-by: Tao Ren 
---
 drivers/hwmon/pmbus/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 3ad97fd5ce03..e35db489b76f 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -71,7 +71,7 @@ config SENSORS_IR35221
  Infineon IR35221 controller.
 
  This driver can also be built as a module. If so, the module will
- be called ir35521.
+ be called ir35221.
 
 config SENSORS_IR38064
tristate "Infineon IR38064"
-- 
2.17.1



[PATCH] ARM: dts: aspeed: cmm: fixup i2c tree

2020-07-01 Thread rentao . bupt
From: Tao Ren 

Create all the i2c switches in device tree and use aliases to assign
child channels with consistent bus numbers.

Besides, "i2c-mux-idle-disconnect" is set for all the i2c switches to
avoid potential conflicts when multiple devices (beind the switches)
use the same device address.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts | 1231 -
 1 file changed, 1228 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
index 016bbcb99bb6..7bc7df7ed428 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
@@ -19,8 +19,8 @@
serial3 = 
 
/*
-* Hardcode the bus number of i2c switches' channels to
-* avoid breaking the legacy applications.
+* PCA9548 (1-0077) provides 8 channels for connecting to
+* 4 Line Cards and 4 Fabric Cards.
 */
i2c16 = 
i2c17 = 
@@ -30,6 +30,11 @@
i2c21 = 
i2c22 = 
i2c23 = 
+
+   /*
+* PCA9548 (2-0071) provides 8 channels for connecting to
+* Power Distribution Board.
+*/
i2c24 = 
i2c25 = 
i2c26 = 
@@ -38,6 +43,11 @@
i2c29 = 
i2c30 = 
i2c31 = 
+
+   /*
+* PCA9548 (8-0077) provides 8 channels and the first 4
+* channels are connecting to 4 Fan Control Boards.
+*/
i2c32 = 
i2c33 = 
i2c34 = 
@@ -46,6 +56,226 @@
i2c37 = 
i2c38 = 
i2c39 = 
+
+   /*
+* 2 PCA9548 (18-0070 & 18-0073), 16 channels connecting
+* to Line Card #1.
+*/
+   i2c40 = 
+   i2c41 = 
+   i2c42 = 
+   i2c43 = 
+   i2c44 = 
+   i2c45 = 
+   i2c46 = 
+   i2c47 = 
+   i2c48 = 
+   i2c49 = 
+   i2c50 = 
+   i2c51 = 
+   i2c52 = 
+   i2c53 = 
+   i2c54 = 
+   i2c55 = 
+
+   /*
+* 2 PCA9548 (19-0070 & 19-0073), 16 channels connecting
+* to Line Card #2.
+*/
+   i2c56 = 
+   i2c57 = 
+   i2c58 = 
+   i2c59 = 
+   i2c60 = 
+   i2c61 = 
+   i2c62 = 
+   i2c63 = 
+   i2c64 = 
+   i2c65 = 
+   i2c66 = 
+   i2c67 = 
+   i2c68 = 
+   i2c69 = 
+   i2c70 = 
+   i2c71 = 
+
+   /*
+* 2 PCA9548 (20-0070 & 20-0073), 16 channels connecting
+* to Line Card #3.
+*/
+   i2c72 = 
+   i2c73 = 
+   i2c74 = 
+   i2c75 = 
+   i2c76 = 
+   i2c77 = 
+   i2c78 = 
+   i2c79 = 
+   i2c80 = 
+   i2c81 = 
+   i2c82 = 
+   i2c83 = 
+   i2c84 = 
+   i2c85 = 
+   i2c86 = 
+   i2c87 = 
+
+   /*
+* 2 PCA9548 (21-0070 & 21-0073), 16 channels connecting
+* to Line Card #4.
+*/
+   i2c88 = 
+   i2c89 = 
+   i2c90 = 
+   i2c91 = 
+   i2c92 = 
+   i2c93 = 
+   i2c94 = 
+   i2c95 = 
+   i2c96 = 
+   i2c97 = 
+   i2c98 = 
+   i2c99 = 
+   i2c100 = 
+   i2c101 = 
+   i2c102 = 
+   i2c103 = 
+
+   /*
+* 2 PCA9548 (16-0070 & 16-0073), 16 channels connecting
+* to Fabric Card #1.
+*/
+   i2c104 = 
+   i2c105 = 
+   i2c106 = 
+   i2c107 = 
+   i2c108 = 
+   i2c109 = 
+   i2c110 = 
+   i2c111 = 
+   i2c112 = 
+   i2c113 = 
+   i2c114 = 
+   i2c115 = 
+   i2c116 = 
+   i2c117 = 
+   i2c118 = 
+   i2c119 = 
+
+   /*
+* 2 PCA9548 (17-0070 & 17-0073), 16 channels connecting
+* to Fabric Card #2.
+*/
+   i2c120 = 
+   i2c121 = 
+   i2c122 = 
+   i2c123 = 
+   i2c124 = 
+   i2c125 = 
+   i2c126 = 
+   

[PATCH 2/3] ARM: dts: aspeed: wedge40: enable adc device

2020-06-29 Thread rentao . bupt
From: Tao Ren 

Enable adc controller and corresponding voltage sensoring channels for
Wedge40.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 9 +
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index aea23c313088..1049cfa80ac2 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -27,6 +27,11 @@
memory@4000 {
reg = <0x4000 0x2000>;
};
+
+   ast-adc-hwmon {
+   compatible = "iio-hwmon";
+   io-channels = < 5>, < 6>, < 7>, < 8>, < 9>;
+   };
 };
 
  {
@@ -126,3 +131,7 @@
  {
status = "okay";
 };
+
+ {
+   status = "okay";
+};
-- 
2.17.1



[PATCH 1/3] ARM: dts: aspeed: wedge40: disable a few i2c controllers

2020-06-29 Thread rentao . bupt
From: Tao Ren 

Disable i2c bus #9, #10 and #13 as these i2c controllers are not used on
Wedge40.

Signed-off-by: Tao Ren 
---
 arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts | 12 
 1 file changed, 12 deletions(-)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 54e508530dce..aea23c313088 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -115,14 +115,6 @@
status = "okay";
 };
 
- {
-   status = "okay";
-};
-
- {
-   status = "okay";
-};
-
  {
status = "okay";
 };
@@ -131,10 +123,6 @@
status = "okay";
 };
 
- {
-   status = "okay";
-};
-
  {
status = "okay";
 };
-- 
2.17.1



[PATCH 3/3] ARM: dts: aspeed: wedge40: enable pwm_tacho device

2020-06-29 Thread rentao . bupt
From: Tao Ren 

Enable pwm_tacho device for fan control and monitoring in Wedge40.

Signed-off-by: Tao Ren 
---
 .../boot/dts/aspeed-bmc-facebook-wedge40.dts  | 29 +++
 1 file changed, 29 insertions(+)

diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts 
b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
index 1049cfa80ac2..8ac23ff6b09e 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-wedge40.dts
@@ -135,3 +135,32 @@
  {
status = "okay";
 };
+
+_tacho {
+   status = "okay";
+   pinctrl-names = "default";
+   pinctrl-0 = <_pwm0_default
+_pwm1_default
+_pwm6_default
+_pwm7_default>;
+
+   fan@0 {
+   reg = <0x00>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x00 0x01>;
+   };
+
+   fan@1 {
+   reg = <0x01>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x02 0x03>;
+   };
+
+   fan@6 {
+   reg = <0x06>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x04 0x05>;
+   };
+
+   fan@7 {
+   reg = <0x07>;
+   aspeed,fan-tach-ch = /bits/ 8 <0x06 0x07>;
+   };
+};
-- 
2.17.1



[PATCH 0/3] ARM: dts: aspeed: fixup wedge40 device tree

2020-06-29 Thread rentao . bupt
From: Tao Ren 

The patch series update several devices' settings in Facebook Wedge40
device tree.

Patch #1 disables a few i2c controllers as they are not being used at
present.

Patch #2 enables adc device for voltage monitoring.

Patch #3 enables pwm_tacho device for fan control and monitoring.

Tao Ren (3):
  ARM: dts: aspeed: wedge40: disable a few i2c controllers
  ARM: dts: aspeed: wedge40: enable adc device
  ARM: dts: aspeed: wedge40: enable pwm_tacho device

 .../boot/dts/aspeed-bmc-facebook-wedge40.dts  | 42 +++
 1 file changed, 34 insertions(+), 8 deletions(-)

-- 
2.17.1



[PATCH net-next] of: mdio: preserve phy dev_flags in of_phy_connect()

2020-06-18 Thread rentao . bupt
From: Tao Ren 

Replace assignment "=" with OR "|=" for "phy->dev_flags" so "dev_flags"
configured in phy probe() function can be preserved.

The idea is similar to commit e7312efbd5de ("net: phy: modify assignment
to OR for dev_flags in phy_attach_direct").

Signed-off-by: Tao Ren 
---
 drivers/of/of_mdio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index a04afe79529c..f5c46c72f4d3 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -380,7 +380,7 @@ struct phy_device *of_phy_connect(struct net_device *dev,
if (!phy)
return NULL;
 
-   phy->dev_flags = flags;
+   phy->dev_flags |= flags;
 
ret = phy_connect_direct(dev, phy, hndlr, iface);
 
-- 
2.17.1



[PATCH] usb: gadget: aspeed: fixup vhub port irq handling

2020-05-27 Thread rentao . bupt
From: Tao Ren 

This is a follow-on patch for commit a23be4ed8f48 ("usb: gadget: aspeed:
improve vhub port irq handling"): for_each_set_bit() is replaced with
simple for() loop because for() loop runs faster on ASPEED BMC.

Signed-off-by: Tao Ren 
---
 drivers/usb/gadget/udc/aspeed-vhub/core.c | 10 +++---
 drivers/usb/gadget/udc/aspeed-vhub/vhub.h |  3 +++
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/core.c 
b/drivers/usb/gadget/udc/aspeed-vhub/core.c
index cdf96911e4b1..be7bb64e3594 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/core.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/core.c
@@ -135,13 +135,9 @@ static irqreturn_t ast_vhub_irq(int irq, void *data)
 
/* Handle device interrupts */
if (istat & vhub->port_irq_mask) {
-   unsigned long bitmap = istat;
-   int offset = VHUB_IRQ_DEV1_BIT;
-   int size = VHUB_IRQ_DEV1_BIT + vhub->max_ports;
-
-   for_each_set_bit_from(offset, , size) {
-   i = offset - VHUB_IRQ_DEV1_BIT;
-   ast_vhub_dev_irq(>ports[i].dev);
+   for (i = 0; i < vhub->max_ports; i++) {
+   if (istat & VHUB_DEV_IRQ(i))
+   ast_vhub_dev_irq(>ports[i].dev);
}
}
 
diff --git a/drivers/usb/gadget/udc/aspeed-vhub/vhub.h 
b/drivers/usb/gadget/udc/aspeed-vhub/vhub.h
index 2e5a1ef14a75..87a5dea12d3c 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/vhub.h
+++ b/drivers/usb/gadget/udc/aspeed-vhub/vhub.h
@@ -67,6 +67,9 @@
 #define VHUB_IRQ_HUB_EP0_SETUP (1 << 0)
 #define VHUB_IRQ_ACK_ALL   0x1ff
 
+/* Downstream device IRQ mask. */
+#define VHUB_DEV_IRQ(n)(VHUB_IRQ_DEVICE1 << 
(n))
+
 /* SW reset reg */
 #define VHUB_SW_RESET_EP_POOL  (1 << 9)
 #define VHUB_SW_RESET_DMA_CONTROLLER   (1 << 8)
-- 
2.17.1



[PATCH net-next v10 2/3] net: phy: add support for clause 37 auto-negotiation

2019-10-22 Thread rentao . bupt
From: Heiner Kallweit 

This patch adds support for clause 37 1000Base-X auto-negotiation.

Signed-off-by: Heiner Kallweit 
Signed-off-by: Tao Ren 
Tested-by: René van Dorst 
Reviewed-by: Andrew Lunn 
---
 No change in v9/v10.
 Changes in v8:
  - Rebased the patch on top of net-next HEAD.
 Changes in v7:
  - Update "if (AUTONEG_ENABLE != phydev->autoneg)" to
"if (phydev->autoneg != AUTONEG_ENABLE)" so checkpatch.pl is happy.
 Changes in v6:
  - add "Signed-off-by: Tao Ren "
 Changes in v1-v5:
  - nothing changed. It's given v5 just to align with the version of
patch series.

 drivers/net/phy/phy_device.c | 139 +++
 include/linux/phy.h  |   4 +
 2 files changed, 143 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f1f60bd4865a..fa71998fea51 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1607,6 +1607,40 @@ static int genphy_config_advert(struct phy_device 
*phydev)
return changed;
 }
 
+/**
+ * genphy_c37_config_advert - sanitize and advertise auto-negotiation 
parameters
+ * @phydev: target phy_device struct
+ *
+ * Description: Writes MII_ADVERTISE with the appropriate values,
+ *   after sanitizing the values to make sure we only advertise
+ *   what is supported.  Returns < 0 on error, 0 if the PHY's advertisement
+ *   hasn't changed, and > 0 if it has changed. This function is intended
+ *   for Clause 37 1000Base-X mode.
+ */
+static int genphy_c37_config_advert(struct phy_device *phydev)
+{
+   u16 adv = 0;
+
+   /* Only allow advertising what this PHY supports */
+   linkmode_and(phydev->advertising, phydev->advertising,
+phydev->supported);
+
+   if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
+ phydev->advertising))
+   adv |= ADVERTISE_1000XFULL;
+   if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT,
+ phydev->advertising))
+   adv |= ADVERTISE_1000XPAUSE;
+   if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT,
+ phydev->advertising))
+   adv |= ADVERTISE_1000XPSE_ASYM;
+
+   return phy_modify_changed(phydev, MII_ADVERTISE,
+ ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
+ ADVERTISE_1000XHALF | ADVERTISE_1000XPSE_ASYM,
+ adv);
+}
+
 /**
  * genphy_config_eee_advert - disable unwanted eee mode advertisement
  * @phydev: target phy_device struct
@@ -1715,6 +1749,54 @@ int __genphy_config_aneg(struct phy_device *phydev, bool 
changed)
 }
 EXPORT_SYMBOL(__genphy_config_aneg);
 
+/**
+ * genphy_c37_config_aneg - restart auto-negotiation or write BMCR
+ * @phydev: target phy_device struct
+ *
+ * Description: If auto-negotiation is enabled, we configure the
+ *   advertising, and then restart auto-negotiation.  If it is not
+ *   enabled, then we write the BMCR. This function is intended
+ *   for use with Clause 37 1000Base-X mode.
+ */
+int genphy_c37_config_aneg(struct phy_device *phydev)
+{
+   int err, changed;
+
+   if (phydev->autoneg != AUTONEG_ENABLE)
+   return genphy_setup_forced(phydev);
+
+   err = phy_modify(phydev, MII_BMCR, BMCR_SPEED1000 | BMCR_SPEED100,
+BMCR_SPEED1000);
+   if (err)
+   return err;
+
+   changed = genphy_c37_config_advert(phydev);
+   if (changed < 0) /* error */
+   return changed;
+
+   if (!changed) {
+   /* Advertisement hasn't changed, but maybe aneg was never on to
+* begin with?  Or maybe phy was isolated?
+*/
+   int ctl = phy_read(phydev, MII_BMCR);
+
+   if (ctl < 0)
+   return ctl;
+
+   if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE))
+   changed = 1; /* do restart aneg */
+   }
+
+   /* Only restart aneg if we are advertising something different
+* than we were before.
+*/
+   if (changed > 0)
+   return genphy_restart_aneg(phydev);
+
+   return 0;
+}
+EXPORT_SYMBOL(genphy_c37_config_aneg);
+
 /**
  * genphy_aneg_done - return auto-negotiation status
  * @phydev: target phy_device struct
@@ -1886,6 +1968,63 @@ int genphy_read_status(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_read_status);
 
+/**
+ * genphy_c37_read_status - check the link status and update current link state
+ * @phydev: target phy_device struct
+ *
+ * Description: Check the link, then figure out the current state
+ *   by comparing what we advertise with what the link partner
+ *   advertises. This function is for Clause 37 1000Base-X mode.
+ */
+int genphy_c37_read_status(struct phy_device *phydev)
+{
+   int lpa, err, old_link = phydev->link;
+
+   /* Update the link, but return if there was an error */
+  

[PATCH net-next v10 1/3] net: phy: modify assignment to OR for dev_flags in phy_attach_direct

2019-10-22 Thread rentao . bupt
From: Tao Ren 

Modify the assignment to OR when dealing with phydev->dev_flags in
phy_attach_direct function, and this is to make sure dev_flags set in
driver's probe callback won't be lost.

Suggested-by: Andrew Lunn 
CC: Heiner Kallweit 
CC: Vladimir Oltean 
Signed-off-by: Tao Ren 
Reviewed-by: Andrew Lunn 
Reviewed-by: Florian Fainelli 
---
 Changes:
  - nothing is changed in v1-v9: it's given v10 to align with the version
of patch series.

 drivers/net/phy/phy_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index adb66a2fae18..f1f60bd4865a 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1270,7 +1270,7 @@ int phy_attach_direct(struct net_device *dev, struct 
phy_device *phydev,
phydev_err(phydev, "error creating 'phy_standalone' 
sysfs entry\n");
}
 
-   phydev->dev_flags = flags;
+   phydev->dev_flags |= flags;
 
phydev->interface = interface;
 
-- 
2.17.1



[PATCH net-next v10 3/3] net: phy: broadcom: add 1000Base-X support for BCM54616S

2019-10-22 Thread rentao . bupt
From: Tao Ren 

The BCM54616S PHY cannot work properly in RGMII->1000Base-X mode, mainly
because genphy functions are designed for copper links, and 1000Base-X
(clause 37) auto negotiation needs to be handled differently.

This patch enables 1000Base-X support for BCM54616S by customizing 3
driver callbacks, and it's verified to be working on Facebook CMM BMC
platform (RGMII->1000Base-KX):

  - probe: probe callback detects PHY's operation mode based on
INTERF_SEL[1:0] pins and 1000X/100FX selection bit in SerDES 100-FX
Control register.

  - config_aneg: calls genphy_c37_config_aneg when the PHY is running in
1000Base-X mode; otherwise, genphy_config_aneg will be called.

  - read_status: calls genphy_c37_read_status when the PHY is running in
1000Base-X mode; otherwise, genphy_read_status will be called.

Note: BCM54616S PHY can also be configured in RGMII->100Base-FX mode, and
100Base-FX support is not available as of now.

Signed-off-by: Tao Ren 
Acked-by: Vladimir Oltean 
Reviewed-by: Florian Fainelli 
---
 No changes in v8/v9/v10.
 Changes in v7:
  - Add comment "BCM54616S 100Base-FX is not supported".
 Changes in v6:
  - nothing changed.
 Changes in v5:
  - include Heiner's patch "net: phy: add support for clause 37
auto-negotiation" into the series.
  - use genphy_c37_config_aneg and genphy_c37_read_status in BCM54616S
PHY driver's callback when the PHY is running in 1000Base-X mode.
 Changes in v4:
  - add bcm54616s_config_aneg_1000bx() to deal with auto negotiation in
1000Base-X mode.
 Changes in v3:
  - rename bcm5482_read_status to bcm54xx_read_status so the callback can
be shared by BCM5482 and BCM54616S.
 Changes in v2:
  - Auto-detect PHY operation mode instead of passing DT node.
  - move PHY mode auto-detect logic from config_init to probe callback.
  - only set speed (not including duplex) in read_status callback.
  - update patch description with more background to avoid confusion.
  - patch #1 in the series ("net: phy: broadcom: set features explicitly
for BCM54616") is dropped.

 drivers/net/phy/broadcom.c | 57 +++---
 include/linux/brcmphy.h| 10 +--
 2 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c
index 4313c74b4fd8..7d68b28bb893 100644
--- a/drivers/net/phy/broadcom.c
+++ b/drivers/net/phy/broadcom.c
@@ -359,9 +359,9 @@ static int bcm5482_config_init(struct phy_device *phydev)
/*
 * Select 1000BASE-X register set (primary SerDes)
 */
-   reg = bcm_phy_read_shadow(phydev, BCM5482_SHD_MODE);
-   bcm_phy_write_shadow(phydev, BCM5482_SHD_MODE,
-reg | BCM5482_SHD_MODE_1000BX);
+   reg = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE);
+   bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE,
+reg | BCM54XX_SHD_MODE_1000BX);
 
/*
 * LED1=ACTIVITYLED, LED3=LINKSPD[2]
@@ -427,12 +427,47 @@ static int bcm5481_config_aneg(struct phy_device *phydev)
return ret;
 }
 
+static int bcm54616s_probe(struct phy_device *phydev)
+{
+   int val, intf_sel;
+
+   val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE);
+   if (val < 0)
+   return val;
+
+   /* The PHY is strapped in RGMII-fiber mode when INTERF_SEL[1:0]
+* is 01b, and the link between PHY and its link partner can be
+* either 1000Base-X or 100Base-FX.
+* RGMII-1000Base-X is properly supported, but RGMII-100Base-FX
+* support is still missing as of now.
+*/
+   intf_sel = (val & BCM54XX_SHD_INTF_SEL_MASK) >> 1;
+   if (intf_sel == 1) {
+   val = bcm_phy_read_shadow(phydev, BCM54616S_SHD_100FX_CTRL);
+   if (val < 0)
+   return val;
+
+   /* Bit 0 of the SerDes 100-FX Control register, when set
+* to 1, sets the MII/RGMII -> 100BASE-FX configuration.
+* When this bit is set to 0, it sets the GMII/RGMII ->
+* 1000BASE-X configuration.
+*/
+   if (!(val & BCM54616S_100FX_MODE))
+   phydev->dev_flags |= PHY_BCM_FLAGS_MODE_1000BX;
+   }
+
+   return 0;
+}
+
 static int bcm54616s_config_aneg(struct phy_device *phydev)
 {
int ret;
 
/* Aneg firsly. */
-   ret = genphy_config_aneg(phydev);
+   if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX)
+   ret = genphy_c37_config_aneg(phydev);
+   else
+   ret = genphy_config_aneg(phydev);
 
/* Then we can set up the delay. */
bcm54xx_config_clock_delay(phydev);
@@ -440,6 +475,18 @@ static int bcm54616s_config_aneg(struct phy_device *phydev)
return ret;
 }
 
+static int bcm54616s_read_status(struct phy_device *phydev)
+{
+   int err;
+
+   if 

[PATCH net-next v10 0/3] net: phy: support 1000Base-X auto-negotiation for BCM54616S

2019-10-22 Thread rentao . bupt
From: Tao Ren 

This patch series aims at supporting auto negotiation when BCM54616S is
running in 1000Base-X mode: without the patch series, BCM54616S PHY driver
would report incorrect link speed in 1000Base-X mode.

Patch #1 (of 3) modifies assignment to OR when dealing with dev_flags in
phy_attach_direct function, so that dev_flags updated in BCM54616S PHY's
probe callback won't be lost.

Patch #2 (of 3) adds several genphy_c37_* functions to support clause 37
1000Base-X auto-negotiation, and these functions are called in BCM54616S
PHY driver.

Patch #3 (of 3) detects BCM54616S PHY's operation mode and calls according
genphy_c37_* functions to configure auto-negotiation and parse link
attributes (speed, duplex, and etc.) in 1000Base-X mode.

Heiner Kallweit (1):
  net: phy: add support for clause 37 auto-negotiation

Tao Ren (2):
  net: phy: modify assignment to OR for dev_flags in phy_attach_direct
  net: phy: broadcom: add 1000Base-X support for BCM54616S

 drivers/net/phy/broadcom.c   |  57 +-
 drivers/net/phy/phy_device.c | 141 ++-
 include/linux/brcmphy.h  |  10 ++-
 include/linux/phy.h  |   4 +
 4 files changed, 205 insertions(+), 7 deletions(-)

-- 
2.17.1