{"id":811105,"url":"http://patchwork.ozlabs.org/api/patches/811105/?format=json","web_url":"http://patchwork.ozlabs.org/project/openbmc/patch/20170907183801.36535-2-cbostic@linux.vnet.ibm.com/","project":{"id":56,"url":"http://patchwork.ozlabs.org/api/projects/56/?format=json","name":"OpenBMC development","link_name":"openbmc","list_id":"openbmc.lists.ozlabs.org","list_email":"openbmc@lists.ozlabs.org","web_url":"http://github.com/openbmc/","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170907183801.36535-2-cbostic@linux.vnet.ibm.com>","list_archive_url":null,"date":"2017-09-07T18:38:00","name":"[linux,dev-4.10,v8,1/2] hwmon: (ucd9000) Add gpio chip interface","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"d50f66ea1c4dc9aad0a0325a4e130f6038315f1d","submitter":{"id":70879,"url":"http://patchwork.ozlabs.org/api/people/70879/?format=json","name":"Christopher Bostic","email":"cbostic@linux.vnet.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/openbmc/patch/20170907183801.36535-2-cbostic@linux.vnet.ibm.com/mbox/","series":[{"id":2039,"url":"http://patchwork.ozlabs.org/api/series/2039/?format=json","web_url":"http://patchwork.ozlabs.org/project/openbmc/list/?series=2039","date":"2017-09-07T18:37:59","name":"Add user space accessibility for ucd9000 stats","version":8,"mbox":"http://patchwork.ozlabs.org/series/2039/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811105/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811105/checks/","tags":{},"related":[],"headers":{"Return-Path":"<openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","openbmc@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","openbmc@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xp8Pt5H8Tz9s7C\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 04:39:46 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xp8Pt47wnzDrYZ\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri,  8 Sep 2017 04:39:46 +1000 (AEST)","from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com\n\t[148.163.158.5])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xp8N86cfHzDrWp\n\tfor <openbmc@lists.ozlabs.org>; Fri,  8 Sep 2017 04:38:16 +1000 (AEST)","from pps.filterd (m0098421.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv87IYibi060018\n\tfor <openbmc@lists.ozlabs.org>; Thu, 7 Sep 2017 14:38:13 -0400","from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2cubgy87dy-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <openbmc@lists.ozlabs.org>; Thu, 07 Sep 2017 14:38:13 -0400","from localhost\n\tby e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <openbmc@lists.ozlabs.org> from <cbostic@linux.vnet.ibm.com>;\n\tThu, 7 Sep 2017 14:38:12 -0400","from b01cxnp22036.gho.pok.ibm.com (9.57.198.26)\n\tby e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway:\n\tAuthorized Use Only! Violators will be prosecuted; \n\tThu, 7 Sep 2017 14:38:11 -0400","from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com\n\t[9.57.199.106])\n\tby b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP\n\tid v87IcBu249610958; Thu, 7 Sep 2017 18:38:11 GMT","from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 630712803F;\n\tThu,  7 Sep 2017 14:38:04 -0400 (EDT)","from christophersmbp.austin.ibm.com (unknown [9.83.1.167])\n\tby b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 19A6328048;\n\tThu,  7 Sep 2017 14:38:01 -0400 (EDT)"],"Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com\n\t(client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com;\n\tenvelope-from=cbostic@linux.vnet.ibm.com; receiver=<UNKNOWN>)","From":"Christopher Bostic <cbostic@linux.vnet.ibm.com>","To":"joel@jms.id.au","Subject":"[PATCH linux dev-4.10 v8 1/2] hwmon: (ucd9000) Add gpio chip\n\tinterface","Date":"Thu,  7 Sep 2017 13:38:00 -0500","X-Mailer":"git-send-email 2.10.1 (Apple Git-78)","In-Reply-To":"<20170907183801.36535-1-cbostic@linux.vnet.ibm.com>","References":"<20170907183801.36535-1-cbostic@linux.vnet.ibm.com>","X-TM-AS-GCONF":"00","x-cbid":"17090718-0008-0000-0000-0000027C1AE2","X-IBM-SpamModules-Scores":"","X-IBM-SpamModules-Versions":"BY=3.00007684; HX=3.00000241; KW=3.00000007;\n\tPH=3.00000004; SC=3.00000226; SDB=6.00913670; UDB=6.00458591;\n\tIPR=6.00693928; \n\tBA=6.00005576; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009;\n\tZB=6.00000000; \n\tZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017054;\n\tXFM=3.00000015; UTC=2017-09-07 18:38:12","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17090718-0009-0000-0000-000036A12C0C","Message-Id":"<20170907183801.36535-2-cbostic@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-07_11:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=1\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1709070275","X-BeenThere":"openbmc@lists.ozlabs.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"Development list for OpenBMC <openbmc.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/openbmc>,\n\t<mailto:openbmc-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/openbmc/>","List-Post":"<mailto:openbmc@lists.ozlabs.org>","List-Help":"<mailto:openbmc-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/openbmc>,\n\t<mailto:openbmc-request@lists.ozlabs.org?subject=subscribe>","Cc":"openbmc@lists.ozlabs.org, Christopher Bostic <cbostic@linux.vnet.ibm.com>","Errors-To":"openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org","Sender":"\"openbmc\"\n\t<openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"},"content":"Add a struct gpio_chip and define some methods so that this device's\nI/O can be accessed via /sys/class/gpio.\n\nPresent requirements only call for retrieving current state of pin\nvalues and their direction.  No requirement at this time to switch\nmodes between output and input within the device driver.\n\nSigned-off-by: Christopher Bostic <cbostic@linux.vnet.ibm.com>\n---\nv8 - Remove redundant ! ops for gpio get_direction method\nv7 - Reorder this patch from #2 in series to #1\nv6 - Break out sysfs clear logged faults into separate patch\n   - Fix logic bug that was bitwise inverting instead of !\n   - Add further comments about assumptions related to pin mux.\nv5 - Clean up remaining branch return statements to !! non\n     branching method.\n   - Clean up white space issues.\n   - Add return codes to error messages.\n   - Add comments describing assumptions of ucd90160 type.\n   - Define gpio direction set methods.\n   - Add unique id for each ucd9000 in system for gpio chip.\nv4 - Change status check from branch to a !! non branching method\n   - Remove usage comments on libgpiod for the struct gpio_chip\n     methods.\n   - Clean up some text formatting.\nv3 - Correct bug in gpio_chip get method.  Wasn't retrieving\n     gpio config information correctly.\n   - Remove old debugfs flag from previous pmbus core changes.\n   - Remove all sysfs files for mfr_status command.\n   - Add comments on direct i2c_smbus calls to clarify that no page\n     set is required.\nv2 - Remove clear_faults file - redundant since all other sysfs\n     core accesses result in an automatic clear fault.\n   - Removed local status_word and status_vout register dumps and\n     use the new pmbus core status facilities instead.\n   - Rename gpi<x>_fault to gpi<x>_alarm to better match core naming\n     conventions.\n   - Add full register dump for mfr_status.\n   - Add gpio chip to device structure and use gpio interfaces.\n---\n drivers/hwmon/pmbus/ucd9000.c | 206 ++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 206 insertions(+)","diff":"diff --git a/drivers/hwmon/pmbus/ucd9000.c b/drivers/hwmon/pmbus/ucd9000.c\nindex 3e3aa95..8c0d3d3 100644\n--- a/drivers/hwmon/pmbus/ucd9000.c\n+++ b/drivers/hwmon/pmbus/ucd9000.c\n@@ -26,6 +26,7 @@\n #include <linux/slab.h>\n #include <linux/i2c.h>\n #include <linux/i2c/pmbus.h>\n+#include <linux/gpio.h>\n #include \"pmbus.h\"\n \n enum chips { ucd9000, ucd90120, ucd90124, ucd90160, ucd9090, ucd90910 };\n@@ -34,8 +35,18 @@\n #define UCD9000_NUM_PAGES\t\t0xd6\n #define UCD9000_FAN_CONFIG_INDEX\t0xe7\n #define UCD9000_FAN_CONFIG\t\t0xe8\n+#define UCD9000_GPIO_SELECT\t\t0xfa\n+#define UCD9000_GPIO_CONFIG\t\t0xfb\n #define UCD9000_DEVICE_ID\t\t0xfd\n \n+/* GPIO CONFIG bits */\n+#define UCD9000_GPIO_CONFIG_ENABLE\tBIT(0)\n+#define UCD9000_GPIO_CONFIG_OUT_ENABLE\tBIT(1)\n+#define UCD9000_GPIO_CONFIG_OUT_VALUE\tBIT(2)\n+#define UCD9000_GPIO_CONFIG_STATUS\tBIT(3)\n+#define UCD9000_GPIO_INPUT\t\t0\n+#define UCD9000_GPIO_OUTPUT\t\t1\n+\n #define UCD9000_MON_TYPE(x)\t(((x) >> 5) & 0x07)\n #define UCD9000_MON_PAGE(x)\t((x) & 0x0f)\n \n@@ -46,9 +57,13 @@\n \n #define UCD9000_NUM_FAN\t\t4\n \n+#define UCD9000_GPIO_NAME_LEN\t16\n+#define UCD90160_NUM_GPIOS\t26\n+\n struct ucd9000_data {\n \tu8 fan_data[UCD9000_NUM_FAN][I2C_SMBUS_BLOCK_MAX];\n \tstruct pmbus_driver_info info;\n+\tstruct gpio_chip gpio;\n };\n #define to_ucd9000_data(_info) container_of(_info, struct ucd9000_data, info)\n \n@@ -119,6 +134,166 @@ static int ucd9000_read_byte_data(struct i2c_client *client, int page, int reg)\n };\n MODULE_DEVICE_TABLE(i2c, ucd9000_id);\n \n+static int ucd9000_gpio_read_config(struct i2c_client *client,\n+\t\t\t\tunsigned int offset)\n+{\n+\tint ret;\n+\n+\t/* No page set required */\n+\tret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_SELECT, offset);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"Failed to select GPIO %d: %d\\n\", offset,\n+\t\t\tret);\n+\n+\t\treturn ret;\n+\t}\n+\n+\treturn i2c_smbus_read_byte_data(client, UCD9000_GPIO_CONFIG);\n+}\n+\n+static int ucd9000_gpio_get(struct gpio_chip *gc, unsigned int offset)\n+{\n+\tstruct i2c_client *client  = gpiochip_get_data(gc);\n+\tint ret;\n+\n+\tret = ucd9000_gpio_read_config(client, offset);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"failed to read GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+\n+\t\treturn ret;\n+\t}\n+\n+\treturn !!(ret & UCD9000_GPIO_CONFIG_STATUS);\n+}\n+\n+static void ucd9000_gpio_set(struct gpio_chip *gc, unsigned int offset,\n+\t\t\tint value)\n+{\n+\tstruct i2c_client *client = gpiochip_get_data(gc);\n+\tint ret;\n+\n+\tret = ucd9000_gpio_read_config(client, offset);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"failed to read GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+\n+\t\treturn;\n+\t}\n+\n+\tif (value) {\n+\t\tif (ret & UCD9000_GPIO_CONFIG_STATUS)\n+\t\t\treturn;\n+\n+\t\tret |= UCD9000_GPIO_CONFIG_STATUS;\n+\t} else {\n+\t\tif (!(ret & UCD9000_GPIO_CONFIG_STATUS))\n+\t\t\treturn;\n+\n+\t\tret &= ~UCD9000_GPIO_CONFIG_STATUS;\n+\t}\n+\n+\tret |= UCD9000_GPIO_CONFIG_ENABLE;\n+\n+\t/* Page set not required */\n+\tret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, ret);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"Failed to write GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+\n+\t\treturn;\n+\t}\n+\n+\tret &= ~UCD9000_GPIO_CONFIG_ENABLE;\n+\n+\tret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, ret);\n+\tif (ret < 0)\n+\t\tdev_err(&client->dev, \"Failed to write GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+}\n+\n+static int ucd9000_gpio_get_direction(struct gpio_chip *gc,\n+\t\t\t\t\tunsigned int offset)\n+{\n+\tstruct i2c_client *client = gpiochip_get_data(gc);\n+\tint ret;\n+\n+\tret = ucd9000_gpio_read_config(client, offset);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"failed to read GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+\n+\t\treturn ret;\n+\t}\n+\n+\treturn !(ret & UCD9000_GPIO_CONFIG_OUT_ENABLE);\n+}\n+\n+static int ucd9000_gpio_set_direction(struct gpio_chip *gc, unsigned int offset,\n+\t\t\t\t\tbool direction_out, int requested_out)\n+{\n+\tstruct i2c_client *client = gpiochip_get_data(gc);\n+\tint ret, config, out_val;\n+\n+\n+\tret = ucd9000_gpio_read_config(client, offset);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"failed to read GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+\n+\t\treturn ret;\n+\t}\n+\n+\tif (direction_out) {\n+\t\tout_val = requested_out ? UCD9000_GPIO_CONFIG_OUT_VALUE : 0;\n+\n+\t\tif (ret & UCD9000_GPIO_CONFIG_OUT_ENABLE) {\n+\t\t\tif ((ret & UCD9000_GPIO_CONFIG_OUT_VALUE) == out_val)\n+\t\t\t\treturn 0;\n+\t\t} else\n+\t\t\tret |= UCD9000_GPIO_CONFIG_OUT_ENABLE;\n+\n+\t\tif (out_val)\n+\t\t\tret |= UCD9000_GPIO_CONFIG_OUT_VALUE;\n+\t\telse\n+\t\t\tret &= ~UCD9000_GPIO_CONFIG_OUT_VALUE;\n+\n+\t} else {\n+\t\tif (!(ret & UCD9000_GPIO_CONFIG_OUT_ENABLE))\n+\t\t\treturn 0;\n+\n+\t\tret &= ~UCD9000_GPIO_CONFIG_OUT_ENABLE;\n+\t}\n+\n+\tret |= UCD9000_GPIO_CONFIG_ENABLE;\n+\tconfig = ret;\n+\n+\t/* Page set not required */\n+\tret = i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, config);\n+\tif (ret < 0) {\n+\t\tdev_err(&client->dev, \"Failed to write GPIO %d config: %d\\n\",\n+\t\t\toffset, ret);\n+\n+\t\treturn ret;\n+\t}\n+\n+\tconfig &= ~UCD9000_GPIO_CONFIG_ENABLE;\n+\n+\treturn i2c_smbus_write_byte_data(client, UCD9000_GPIO_CONFIG, config);\n+}\n+\n+static int ucd9000_gpio_direction_input(struct gpio_chip *gc,\n+\t\t\t\t\tunsigned int offset)\n+{\n+\treturn ucd9000_gpio_set_direction(gc, offset, UCD9000_GPIO_INPUT, 0);\n+}\n+\n+static int ucd9000_gpio_direction_output(struct gpio_chip *gc,\n+\t\t\t\t\tunsigned int offset, int val)\n+{\n+\treturn ucd9000_gpio_set_direction(gc, offset, UCD9000_GPIO_OUTPUT, val);\n+}\n+\n static int ucd9000_probe(struct i2c_client *client,\n \t\t\t const struct i2c_device_id *id)\n {\n@@ -227,6 +402,37 @@ static int ucd9000_probe(struct i2c_client *client,\n \t\t  | PMBUS_HAVE_FAN34 | PMBUS_HAVE_STATUS_FAN34;\n \t}\n \n+\t/*\n+\t * Note:\n+\t *\n+\t * Pinmux support has not been added to the new gpio_chip.\n+\t * This support should be added when possible given the mux\n+\t * behavior of these IO devices.\n+\t */\n+\tdata->gpio.label = (const char *)&client->name;\n+\tdata->gpio.get_direction = ucd9000_gpio_get_direction;\n+\tdata->gpio.direction_input = ucd9000_gpio_direction_input;\n+\tdata->gpio.direction_output = ucd9000_gpio_direction_output;\n+\tdata->gpio.get = ucd9000_gpio_get;\n+\tdata->gpio.set = ucd9000_gpio_set;\n+\tdata->gpio.can_sleep = 1;\n+\tdata->gpio.base = -1;\n+\n+\t/*\n+\t * TODO: set ngpio for ucd9000 devs that aren't 90160 type\n+\t */\n+\tif (mid->driver_data == ucd90160)\n+\t\tdata->gpio.ngpio = UCD90160_NUM_GPIOS;\n+\tdata->gpio.parent = &client->dev;\n+\tdata->gpio.owner = THIS_MODULE;\n+\n+\tret = devm_gpiochip_add_data(&client->dev, &data->gpio, client);\n+\tif (ret) {\n+\t\tdata->gpio.parent = NULL;\n+\t\tdev_warn(&client->dev, \"Could not add gpiochip: %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n \treturn pmbus_do_probe(client, mid, info);\n }\n \n","prefixes":["linux","dev-4.10","v8","1/2"]}