From patchwork Fri Oct 14 07:53:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 9376153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9486C60779 for ; Fri, 14 Oct 2016 07:56:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88B992A4D7 for ; Fri, 14 Oct 2016 07:56:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D01A2A4E6; Fri, 14 Oct 2016 07:56:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BADA12A4D7 for ; Fri, 14 Oct 2016 07:56:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1buxKc-0002go-HP; Fri, 14 Oct 2016 07:55:06 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1buxJo-0002CF-7p for linux-arm-kernel@lists.infradead.org; Fri, 14 Oct 2016 07:54:18 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9C00635C6; Fri, 14 Oct 2016 07:53:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-53.ams2.redhat.com [10.36.112.53]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9E7rdoM016706; Fri, 14 Oct 2016 03:53:55 -0400 From: Hans de Goede To: Rob Herring , Mark Rutland , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH 3/6] misc: q8-hardwaremgr: Add accelerometer detection Date: Fri, 14 Oct 2016 09:53:34 +0200 Message-Id: <20161014075337.10452-4-hdegoede@redhat.com> In-Reply-To: <20161014075337.10452-1-hdegoede@redhat.com> References: <20161014075337.10452-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 14 Oct 2016 07:53:59 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161014_005416_457854_0E114C11 X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree , Maxime Ripard , Chen-Yu Tsai , linux-arm-kernel@lists.infradead.org, Hans de Goede MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Extend the q8-hardwaremgr with accelerometer detection. Signed-off-by: Hans de Goede --- drivers/misc/Kconfig | 2 +- drivers/misc/q8-hardwaremgr.c | 219 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 220 insertions(+), 1 deletion(-) diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index d6c1529..11b05b0 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -801,7 +801,7 @@ config Q8_HARDWAREMGR default n help This option enables support for autodetecting the touchscreen - on Allwinner Q8 tablets. + and accelerometer on Allwinner Q8 tablets. If unsure, say N. diff --git a/drivers/misc/q8-hardwaremgr.c b/drivers/misc/q8-hardwaremgr.c index 346102d..8ed71a9 100644 --- a/drivers/misc/q8-hardwaremgr.c +++ b/drivers/misc/q8-hardwaremgr.c @@ -83,6 +83,48 @@ enum { zet6251, }; +#define DA280_REG_CHIP_ID 0x01 +#define DA280_CHIP_ID 0x13 +#define DA311_REG_CHIP_ID 0x0f +#define DA311_CHIP_ID 0x13 + +#define DMARD06_CHIP_ID_REG 0x0f +#define DMARD05_CHIP_ID 0x05 +#define DMARD06_CHIP_ID 0x06 +#define DMARD07_CHIP_ID 0x07 +#define DMARD09_REG_CHIPID 0x18 +#define DMARD09_CHIPID 0x95 +#define DMARD10_REG_STADR 0x12 +#define DMARD10_REG_STAINT 0x1c +#define DMARD10_VALUE_STADR 0x55 +#define DMARD10_VALUE_STAINT 0xaa + +#define MC3230_REG_CHIP_ID 0x18 +#define MC3230_CHIP_ID 0x01 +#define MMA7660_CHIP_ID 0x00 /* Factory reserved on MMA7660 */ +#define MC3230_REG_PRODUCT_CODE 0x3b +#define MMA7660_PRODUCT_CODE 0x00 /* Factory reserved on MMA7660 */ +#define MC3210_PRODUCT_CODE 0x90 +#define MC3230_PRODUCT_CODE 0x19 + +#define MXC6225_REG_CHIP_ID 0x08 +#define MXC6225_CHIP_ID 0x05 + +enum { + accel_unknown, + da280, + da311, + dmard05, + dmard06, + dmard07, + dmard09, + dmard10, + mc3210, + mc3230, + mma7660, + mxc6225, +}; + struct q8_hardwaremgr_device { int model; int addr; @@ -94,6 +136,7 @@ struct q8_hardwaremgr_data { struct device *dev; enum soc soc; struct q8_hardwaremgr_device touchscreen; + struct q8_hardwaremgr_device accelerometer; int touchscreen_variant; int touchscreen_width; int touchscreen_height; @@ -411,6 +454,175 @@ static void q8_hardwaremgr_apply_touchscreen(struct q8_hardwaremgr_data *data) of_node_put(np); } +static int q8_hardwaremgr_probe_mxc6225(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int id; + + id = i2c_smbus_read_byte_data(client, MXC6225_REG_CHIP_ID); + /* Bits 7 - 5 of the chip-id register are undefined */ + if (id >= 0 && (id & 0x1f) == MXC6225_CHIP_ID) { + data->accelerometer.compatible = "memsic,mxc6225"; + data->accelerometer.model = mxc6225; + return 0; + } + + return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_mc3230(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int id, pc = 0; + + /* First check chip-id, then product-id */ + id = i2c_smbus_read_byte_data(client, MC3230_REG_CHIP_ID); + if (id == MC3230_CHIP_ID || id == MMA7660_CHIP_ID) { + pc = i2c_smbus_read_byte_data(client, MC3230_REG_PRODUCT_CODE); + switch (pc) { + case MMA7660_PRODUCT_CODE: + data->accelerometer.compatible = "fsl,mma7660"; + data->accelerometer.model = mma7660; + return 0; + case MC3210_PRODUCT_CODE: + data->accelerometer.compatible = "mcube,mc3210"; + data->accelerometer.model = mc3210; + return 0; + case MC3230_PRODUCT_CODE: + data->accelerometer.compatible = "mcube,mc3230"; + data->accelerometer.model = mc3230; + return 0; + case -ETIMEDOUT: + return -ETIMEDOUT; /* Bus stuck bail immediately */ + } + } + + return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_dmard06(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int id; + + id = i2c_smbus_read_byte_data(client, DMARD06_CHIP_ID_REG); + switch (id) { + case DMARD05_CHIP_ID: + data->accelerometer.compatible = "domintech,dmard05"; + data->accelerometer.model = dmard05; + return 0; + case DMARD06_CHIP_ID: + data->accelerometer.compatible = "domintech,dmard06"; + data->accelerometer.model = dmard06; + return 0; + case DMARD07_CHIP_ID: + data->accelerometer.compatible = "domintech,dmard07"; + data->accelerometer.model = dmard07; + return 0; + } + + return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_dmard09(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int id; + + id = i2c_smbus_read_byte_data(client, DMARD09_REG_CHIPID); + if (id == DMARD09_CHIPID) { + data->accelerometer.compatible = "domintech,dmard09"; + data->accelerometer.model = dmard09; + return 0; + } + + return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_dmard10(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int stadr, staint = 0; + + /* These 2 registers have special POR reset values used for id */ + stadr = i2c_smbus_read_byte_data(client, DMARD10_REG_STADR); + if (stadr == DMARD10_VALUE_STADR) { + staint = i2c_smbus_read_byte_data(client, DMARD10_REG_STAINT); + switch (staint) { + case DMARD10_VALUE_STAINT: + data->accelerometer.compatible = "domintech,dmard10"; + data->accelerometer.model = dmard10; + return 0; + case -ETIMEDOUT: + return -ETIMEDOUT; /* Bus stuck bail immediately */ + } + } + + return stadr == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_da280(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int id; + + id = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID); + if (id == DA280_CHIP_ID) { + data->accelerometer.compatible = "miramems,da280"; + data->accelerometer.model = da280; + return 0; + } + + return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_da311(struct q8_hardwaremgr_data *data, + struct i2c_client *client) +{ + int id; + + id = i2c_smbus_read_byte_data(client, DA311_REG_CHIP_ID); + if (id == DA311_CHIP_ID) { + data->accelerometer.compatible = "miramems,da311"; + data->accelerometer.model = da311; + return 0; + } + + return id == -ETIMEDOUT ? -ETIMEDOUT : -ENODEV; +} + +static int q8_hardwaremgr_probe_accelerometer(struct q8_hardwaremgr_data *data, + struct i2c_adapter *adap) +{ + PROBE_CLIENT(&data->accelerometer, 0x15, q8_hardwaremgr_probe_mxc6225); + PROBE_CLIENT(&data->accelerometer, 0x4c, q8_hardwaremgr_probe_mc3230); + PROBE_CLIENT(&data->accelerometer, 0x1c, q8_hardwaremgr_probe_dmard06); + PROBE_CLIENT(&data->accelerometer, 0x1d, q8_hardwaremgr_probe_dmard09); + PROBE_CLIENT(&data->accelerometer, 0x18, q8_hardwaremgr_probe_dmard10); + PROBE_CLIENT(&data->accelerometer, 0x26, q8_hardwaremgr_probe_da280); + PROBE_CLIENT(&data->accelerometer, 0x27, q8_hardwaremgr_probe_da311); + + return -ENODEV; +} + +static void q8_hardwaremgr_apply_accelerometer(struct q8_hardwaremgr_data *data) +{ + struct of_changeset cset; + struct device_node *np; + + if (data->accelerometer.model == accel_unknown) + return; + + np = q8_hardware_mgr_apply_common(&data->accelerometer, &cset, + "accelerometer"); + if (!np) + return; + + of_changeset_apply(&cset); + + of_node_put(np); +} + static int q8_hardwaremgr_do_probe(struct q8_hardwaremgr_data *data, struct q8_hardwaremgr_device *dev, const char *prefix, bus_probe_func func) @@ -531,7 +743,14 @@ static int q8_hardwaremgr_probe(struct platform_device *pdev) if (ret) goto error; + ret = q8_hardwaremgr_do_probe(data, &data->accelerometer, + "accelerometer", + q8_hardwaremgr_probe_accelerometer); + if (ret) + goto error; + q8_hardwaremgr_apply_touchscreen(data); + q8_hardwaremgr_apply_accelerometer(data); error: kfree(data);