From patchwork Thu May 3 15:08:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134908 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2048082lji; Thu, 3 May 2018 08:13:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpxuIAH/JSsX0bDroJWLJkJ3JLQ61h/hrNCpZHdVNy4ZUUfe6G/IMXiH3O1gOwiufF+8yAi X-Received: by 10.98.35.11 with SMTP id j11mr23364814pfj.177.1525360439199; Thu, 03 May 2018 08:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525360439; cv=none; d=google.com; s=arc-20160816; b=ZftIayiXp/qNjjbmkBaLk8aK3bsJyKy//4+Gd41f7X6ExM4t4eW5aIWtHMCkSUf2OC aeK1d1O7dysBWZX6iI3Y3Z86Ul59w8Eu734qWrsn34HYT0Zsdejh7n+SthtwQslOix5p j9wA6CPnzkYmB9TiGGwNceNYsA3hlJY4wrHGMe8WUChWJ8gXKRsUevg9WtGd5Zz12iNA KAAro7mi2wlqGKsvXs/7tI7lQ3uB+Dug4+QI+8XHBZ2x5jgo3/8a0T/KKia9dq1eiCsK +C+h0lhm6u+mTrO2JZ+bPex36vZM6nN0SsY111ejWwYu5o4PTw+LfJfkziEAhqkKeZCn YaTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=IKanCNNfei9smwN47CJ5tQO8LTg4vycDP1HiJ6dhx6Q=; b=BwB4zS4HrCoI0LiFb+y32MvLG4ZuZrgfQfqqi1Z4BkgU+lDfZGo2KuXHznngQDbVX6 RVha+qFRcykYCpVS5OsPqYuDjgpdlrLt5scLQ8OatG4fUvMHS+B1FOFhCYw3Hul3wb77 YpKrmo7J+VskHyAz3UOVmb8MHmVOHDlSL2HbAn/MKe3XnYErT//plPsq2UFda+50jh81 vzU42AL3HOJ4TNDS9vNvDBT0KttxqunfUlQ5IXef6QdLgpUl85oU3HApOW5QFxPNRS3c yjrTQMCL1aPw+mDdqD/uUWnsrCtULKzk7Ke8bjuAlWJOYMuUAvToLh8ioZUVkWvBsry1 YbAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si13713349plh.22.2018.05.03.08.13.58; Thu, 03 May 2018 08:13:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751499AbeECPN5 (ORCPT + 29 others); Thu, 3 May 2018 11:13:57 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7649 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750954AbeECPNs (ORCPT ); Thu, 3 May 2018 11:13:48 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D90A6BEB4D960; Thu, 3 May 2018 23:13:31 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Thu, 3 May 2018 23:13:24 +0800 From: John Garry To: , , , CC: , , , , , , , John Garry Subject: [PATCH 1/2] HISI LPC: Reference static MFD cells for ACPI support Date: Thu, 3 May 2018 23:08:38 +0800 Message-ID: <1525360119-102166-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525360119-102166-1-git-send-email-john.garry@huawei.com> References: <1525360119-102166-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently for ACPI support the driver models the host as an MFD. For a device connected to the LPC bus, we dynamically create an MFD cell for that device, configuring the cell name and ACPI match parameters manually. This makes supporting named devices and also special setup handling for certain devices awkward, as we would need to introduce some special ACPI device handling according to device HID. To avoid this, create reference static MFD cells for known child devices, so when adding an MFD cell we can fix the cell platform data as required. For this, a setup callback function is added. For now, only the IPMI cell is added. Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 89 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 36 deletions(-) -- 1.9.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 2d4611e..71693d77 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -341,15 +341,6 @@ static void hisi_lpc_comm_outs(void *hostdata, unsigned long pio, }; #ifdef CONFIG_ACPI -#define MFD_CHILD_NAME_PREFIX DRV_NAME"-" -#define MFD_CHILD_NAME_LEN (ACPI_ID_LEN + sizeof(MFD_CHILD_NAME_PREFIX) - 1) - -struct hisi_lpc_mfd_cell { - struct mfd_cell_acpi_match acpi_match; - char name[MFD_CHILD_NAME_LEN]; - char pnpid[ACPI_ID_LEN]; -}; - static int hisi_lpc_acpi_xlat_io_res(struct acpi_device *adev, struct acpi_device *host, struct resource *res) @@ -367,6 +358,40 @@ static int hisi_lpc_acpi_xlat_io_res(struct acpi_device *adev, return 0; } +static const struct mfd_cell_acpi_match hisi_lpc_acpi_mfd_match_ipmi = { + .pnpid = "IPI0001", +}; + +struct hisi_lpc_acpi_mfd_cell { + struct mfd_cell mfd_cell; + int (*setup)(struct device *hostdev, struct mfd_cell *mfd_cell); +} static const hisi_lpc_acpi_mfd_cells[] = { + /* ipmi */ + { + .mfd_cell = { + .name = "hisi-lpc-ipmi", + .acpi_match = &hisi_lpc_acpi_mfd_match_ipmi, + }, + }, + {} +}; + +static const struct mfd_cell *hisi_lpc_acpi_mfd_get_cell(const char *hid) +{ + const struct hisi_lpc_acpi_mfd_cell *cell = hisi_lpc_acpi_mfd_cells; + + for (; cell && cell->mfd_cell.name; cell++) { + const struct mfd_cell *mfd_cell = &cell->mfd_cell; + const struct mfd_cell_acpi_match *acpi_match; + + acpi_match = mfd_cell->acpi_match; + if (!strcmp(acpi_match->pnpid, hid)) + return mfd_cell; + } + + return NULL; +} + /* * hisi_lpc_acpi_set_io_res - set the resources for a child's MFD * @child: the device node to be updated the I/O resource @@ -464,7 +489,6 @@ static int hisi_lpc_acpi_set_io_res(struct device *child, static int hisi_lpc_acpi_probe(struct device *hostdev) { struct acpi_device *adev = ACPI_COMPANION(hostdev); - struct hisi_lpc_mfd_cell *hisi_lpc_mfd_cells; struct mfd_cell *mfd_cells; struct acpi_device *child; int size, ret, count = 0, cell_num = 0; @@ -472,39 +496,24 @@ static int hisi_lpc_acpi_probe(struct device *hostdev) list_for_each_entry(child, &adev->children, node) cell_num++; - /* allocate the mfd cell and companion ACPI info, one per child */ - size = sizeof(*mfd_cells) + sizeof(*hisi_lpc_mfd_cells); + /* allocate the mfd cells, one per child */ + size = sizeof(*mfd_cells); mfd_cells = devm_kcalloc(hostdev, cell_num, size, GFP_KERNEL); if (!mfd_cells) return -ENOMEM; - hisi_lpc_mfd_cells = (struct hisi_lpc_mfd_cell *)&mfd_cells[cell_num]; /* Only consider the children of the host */ list_for_each_entry(child, &adev->children, node) { struct mfd_cell *mfd_cell = &mfd_cells[count]; - struct hisi_lpc_mfd_cell *hisi_lpc_mfd_cell = - &hisi_lpc_mfd_cells[count]; - struct mfd_cell_acpi_match *acpi_match = - &hisi_lpc_mfd_cell->acpi_match; - char *name = hisi_lpc_mfd_cell[count].name; - char *pnpid = hisi_lpc_mfd_cell[count].pnpid; - struct mfd_cell_acpi_match match = { - .pnpid = pnpid, - }; - - /* - * For any instances of this host controller (Hip06 and Hip07 - * are the only chipsets), we would not have multiple slaves - * with the same HID. And in any system we would have just one - * controller active. So don't worrry about MFD name clashes. - */ - snprintf(name, MFD_CHILD_NAME_LEN, MFD_CHILD_NAME_PREFIX"%s", - acpi_device_hid(child)); - snprintf(pnpid, ACPI_ID_LEN, "%s", acpi_device_hid(child)); - - memcpy(acpi_match, &match, sizeof(*acpi_match)); - mfd_cell->name = name; - mfd_cell->acpi_match = acpi_match; + const struct mfd_cell *mfd_cell_ref; + const char *hid = acpi_device_hid(child); + struct hisi_lpc_acpi_mfd_cell *cell; + + mfd_cell_ref = hisi_lpc_acpi_mfd_get_cell(hid); + if (!mfd_cell_ref) + return -ENOENT; + + memcpy(mfd_cell, mfd_cell_ref, sizeof(*mfd_cell)); ret = hisi_lpc_acpi_set_io_res(&child->dev, &adev->dev, &mfd_cell->resources, @@ -513,6 +522,14 @@ static int hisi_lpc_acpi_probe(struct device *hostdev) dev_warn(&child->dev, "set resource fail (%d)\n", ret); return ret; } + + cell = container_of(mfd_cell_ref, typeof(*cell), mfd_cell); + if (cell->setup) { + ret = cell->setup(hostdev, mfd_cell); + if (ret) + return ret; + } + count++; } From patchwork Thu May 3 15:08:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 134909 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp2048135lji; Thu, 3 May 2018 08:14:02 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq1Keocg8p8raz9d+oMzz92nhYYjXkfLqB7CUk4eHuTkhNW9SGC84r9LEEAERsOdT1GVeJp X-Received: by 10.167.133.206 with SMTP id z14mr23313625pfn.2.1525360442530; Thu, 03 May 2018 08:14:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525360442; cv=none; d=google.com; s=arc-20160816; b=CP14aOCPeHlpNXF/Qy2nCcf2Otzw355a7wm4guq7y4bQFUlpzIMQmaeo1iT7YA8nCN 5tdy3z0/9sP2SmX9+f2Xsss335pRa4M8TYX2dZDYtj77Rt6wF4q59GHkOQFj3RvnSEcS qHecOvZ5NLjWvvefKxOn1jQiXJZI4MJOyFWbGPNHtoGQkSeQG/rjmGUOOe4ODAwe3yXD 8yJwkeeoX2si+F9cm8kI7l9Q7vCuM9lg8gP77gKFQVYuX0FwQg1kj3axkrVMX8lvsJFW zSdmcXXr6LdfL8pj7DuZa9W7T8NxoiNedqd2hVT+5T6XTeamh9btAf1WrP40+Gh4fISQ lXLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=E0nKsA8osTdPJ335/0o4K7vDAo3cslimdMcqG2E4FOw=; b=j9wwij+/iSg/vioq0jm72kKaZ0EZJQScgmIhEJs+lQ5xnu6Gtq1POsxuiP46Vqlgdp 3dYepH6c+GGRpB69Qj3ZKXW8lBjKRzkMMC39TWQNws17Bs17aOyg+P5Z78TQlGDISPmd fMdqKafa2mIiMdga45j1V5C+YncMOF4uiB2h2GwsiOzs2IZ0/qe5pTMIBBc/JOcI/Jby CicmVS6AzgfeLZyvQiLNS/dxbIcwXXkaLFzBF3BITFUDxjgmv57HZEwigYI/OTIYy1Pl 3EGZdrpvTV9C7HyA9UaPWykzvaAVaZacZZ459wGdeIhe+dmw//n/vUgiy/AM64LSVrUO qy9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j6si14126300pfb.25.2018.05.03.08.14.02; Thu, 03 May 2018 08:14:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbeECPOA (ORCPT + 29 others); Thu, 3 May 2018 11:14:00 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7650 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751140AbeECPNs (ORCPT ); Thu, 3 May 2018 11:13:48 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 03916595FF532; Thu, 3 May 2018 23:13:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Thu, 3 May 2018 23:13:24 +0800 From: John Garry To: , , , CC: , , , , , , , John Garry Subject: [PATCH 2/2] HISI LPC: Add ACPI UART support Date: Thu, 3 May 2018 23:08:39 +0800 Message-ID: <1525360119-102166-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1525360119-102166-1-git-send-email-john.garry@huawei.com> References: <1525360119-102166-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the Huawei D03 development board the system UART is the UART connected on the LPC bus. The profile for the device driver required for this HW would be as follows: - platform driver - supports 16550 - supports ACPI - supports polling mode - supports IO space In principle we should use the PNP driver (8250_dw.c) for 8250-devices with ACPI FW. However since this host driver does not support PNP devices, and modifying the PNP core code to support it is not worth the effort, use the generic 8250 isa driver. For this, we need to setup the MFD cell platform data for a serial 8250 Port. In addition to this change, we also make the following changes: - set child ACPI device as enumerated. This fixes a conflict in serdev setup for the UART - use platform device ID auto for creating the uart child platform device to avoid conflict with platform devices created for serial8250_isa_devs from 8250_core.c Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 71693d77..b0ee2fa 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #define DRV_NAME "hisi-lpc" @@ -362,6 +363,35 @@ static int hisi_lpc_acpi_xlat_io_res(struct acpi_device *adev, .pnpid = "IPI0001", }; +static const struct mfd_cell_acpi_match hisi_lpc_acpi_mfd_match_uart = { + .pnpid = "HISI1031", +}; + +static int hisi_lpc_acpi_uart_setup(struct device *hostdev, + struct mfd_cell *mfd_cell) +{ + const struct resource * const resource = mfd_cell->resources; + struct plat_serial8250_port ref_port[] = { + { + .iobase = resource->start, + .uartclk = 1843200, + .iotype = UPIO_PORT, + .flags = UPF_BOOT_AUTOCONF, + }, + {} + }; + + mfd_cell->platform_data = devm_kmemdup(hostdev, &ref_port, + sizeof(ref_port), GFP_KERNEL); + if (!mfd_cell->platform_data) + return -ENOMEM; + + mfd_cell->pdata_size = sizeof(ref_port); + + return 0; +} + + struct hisi_lpc_acpi_mfd_cell { struct mfd_cell mfd_cell; int (*setup)(struct device *hostdev, struct mfd_cell *mfd_cell); @@ -373,6 +403,14 @@ struct hisi_lpc_acpi_mfd_cell { .acpi_match = &hisi_lpc_acpi_mfd_match_ipmi, }, }, + /* 8250-compatible uart */ + { + .mfd_cell = { + .name = "serial8250", + .acpi_match = &hisi_lpc_acpi_mfd_match_uart, + }, + .setup = hisi_lpc_acpi_uart_setup, + }, {} }; @@ -530,10 +568,11 @@ static int hisi_lpc_acpi_probe(struct device *hostdev) return ret; } + acpi_device_set_enumerated(child); count++; } - ret = mfd_add_devices(hostdev, PLATFORM_DEVID_NONE, + ret = mfd_add_devices(hostdev, PLATFORM_DEVID_AUTO, mfd_cells, cell_num, NULL, 0, NULL); if (ret) { dev_err(hostdev, "failed to add mfd cells (%d)\n", ret);