From patchwork Thu Mar 28 10:03:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loys Ollivier X-Patchwork-Id: 10874717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C448E1708 for ; Thu, 28 Mar 2019 10:03:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9EAD28BAE for ; Thu, 28 Mar 2019 10:03:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B6D21FF2D; Thu, 28 Mar 2019 10:03:42 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2BC791FF2D for ; Thu, 28 Mar 2019 10:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=DlT6CS022OlhO+CgAzDRlofBgt+BbcpyDxsqe9PNUzk=; b=BZoJY10IuabkKinW38IGLY8q41 5Ky4txXyCfR91Av9NeG2e1s4Nt/IQP5gjcDBrzOOWNvEdiSHa8lfvg+cexB/FCU/WGvNimLgWHgbD qV0iH2iWRL2E0rXJ67MVTPvd6jtWSBGC+Cw89U5xhBVm+2HbpV+MGRg9Ilq9inZNdclKy/yQ9piv4 2Eyj4pKm2IJJtvKN3yZl3hbn5O0xVARMNXkFWBlEScYKPfd9pdnGA3z3rUFP4DyZ15RjXunFfA1ob l6wwSJMAQmoQWpOBYJ4GV/ixd64L8dZipOFpkBbOQM9ZrjSX5SrjjM+vJwh8bZtFpjShgqW4lcHdq LQGWVorg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9Rsl-00076M-If; Thu, 28 Mar 2019 10:03:35 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9RsV-0006OT-Vx for linux-arm-kernel@lists.infradead.org; Thu, 28 Mar 2019 10:03:22 +0000 Received: by mail-wm1-x342.google.com with SMTP id a184so2906718wma.2 for ; Thu, 28 Mar 2019 03:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iMcUmb2WHKV3LTF1MhO/0BXJVjoQCZxXAEv5GKcE4aE=; b=mjb4IHc2fPA0QZH185mM2bIHAlqtvojzI3daWo5LcFl4Oq4mlJHMvFATWpmT7boOUr +wyqd24YBsfeyYGb/49dv75EoOZFcB+xW/9MFykZTNXNffJ62ROSh3kt5YCRcBazcC/2 nWKopJCdauxsnAAoHnp3jcEfP/Ba+oGa8RyNmEzCZ3Mb9F6OIdjKRVhnHoK9YFm1GzQe omCP+cMF7x7CbEecmisc4uUxlEenkmI6NCs56h+Ijx3ra9HJl3VGnyk4hy5Di7HwafHJ rLBHc4I4rxZk+CqEc8ct+LXyZ0d9p7wWuWo0wMq297WEpoZ5ICk6pNmasE99lJg2r1rt a0Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iMcUmb2WHKV3LTF1MhO/0BXJVjoQCZxXAEv5GKcE4aE=; b=G1WtVAI7mUqRv/zljTZQU6Y4bv88gSItCmj2xAaIbIpl92Uupq4iAmD8JvPWSkgZh/ NShV1L2mrHYYNiyG6rNG7ZT8uZ/k6m2Q/uwG1+jLExNZxW4hKDkMF3r7Wb4od8Kd1zL8 Yws9b329SQrPrj9tDXztDYGNbDiOeD2hHIhuykH+Dt1xCy4ccdpnxIpB/Sva1Iy1lKVx m8W9qatrRRJjWUqsuEMxN25gmNCcVitQI/ENVhnPMc8fNZepMQ+gJi3HpVhj3Itpah6o k0DMRizTfsbk+jS6eddNHhNzrTtk2rYdJdXNPfCMUcceyy+qkGTbEXHtwYtU5N/mQWOc FFZQ== X-Gm-Message-State: APjAAAW1tRv79TFMv/OlUL29im/BR56+ZY5lhkxxTDwNcissmOTyUKk4 Vn5C7s18U22VH/nBk62+2G1CHg== X-Google-Smtp-Source: APXvYqx0mDwIytnNsq0aFeqQWfzjous4m5oeHjWs8lmQ2XePnkGqFfxG5wsCGsYs1g6hufZyp+5YCw== X-Received: by 2002:a1c:4187:: with SMTP id o129mr11338896wma.57.1553767396985; Thu, 28 Mar 2019 03:03:16 -0700 (PDT) Received: from loys-ubuntu-BY1835A49200471.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id q8sm1230315wmq.35.2019.03.28.03.03.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Mar 2019 03:03:16 -0700 (PDT) From: Loys Ollivier To: Johan Hovold , Matthias Brugger Subject: [PATCH RFC 1/1] gnss: get serial speed from subdrivers Date: Thu, 28 Mar 2019 11:03:09 +0100 Message-Id: <1553767389-22857-2-git-send-email-lollivier@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1553767389-22857-1-git-send-email-lollivier@baylibre.com> References: <1553767389-22857-1-git-send-email-lollivier@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190328_030320_024560_4267CFAE X-CRM114-Status: GOOD ( 15.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Colin Ian King , Loys Ollivier , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 The default serial speed was hardcoded in the code. Rename current-speed to default-speed. Add a function parameter that lets the subdrivers specify their default speed. If not specified fallback to the device-tree default-speed. Signed-off-by: Loys Ollivier --- drivers/gnss/mtk.c | 6 +++++- drivers/gnss/serial.c | 21 +++++++++++++-------- drivers/gnss/serial.h | 3 ++- drivers/gnss/ubx.c | 3 ++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/drivers/gnss/mtk.c b/drivers/gnss/mtk.c index d1fc55560daf..a1a89f0cc75c 100644 --- a/drivers/gnss/mtk.c +++ b/drivers/gnss/mtk.c @@ -16,6 +16,10 @@ #include "serial.h" +static uint serial_speed = 9600; /* Serial speed (baud rate) */ +module_param(serial_speed, uint, 0644); +MODULE_PARM_DESC(serial_speed, "Serial baud rate (bit/s), (default = 9600)"); + struct mtk_data { struct regulator *vbackup; struct regulator *vcc; @@ -69,7 +73,7 @@ static int mtk_probe(struct serdev_device *serdev) struct mtk_data *data; int ret; - gserial = gnss_serial_allocate(serdev, sizeof(*data)); + gserial = gnss_serial_allocate(serdev, sizeof(*data), serial_speed); if (IS_ERR(gserial)) { ret = PTR_ERR(gserial); return ret; diff --git a/drivers/gnss/serial.c b/drivers/gnss/serial.c index def64b36d994..706fc5b46811 100644 --- a/drivers/gnss/serial.c +++ b/drivers/gnss/serial.c @@ -103,17 +103,13 @@ static int gnss_serial_set_power(struct gnss_serial *gserial, return gserial->ops->set_power(gserial, state); } -/* - * FIXME: need to provide subdriver defaults or separate dt parsing from - * allocation. - */ static int gnss_serial_parse_dt(struct serdev_device *serdev) { struct gnss_serial *gserial = serdev_device_get_drvdata(serdev); struct device_node *node = serdev->dev.of_node; - u32 speed = 4800; + uint speed; - of_property_read_u32(node, "current-speed", &speed); + of_property_read_u32(node, "default-speed", &speed); gserial->speed = speed; @@ -121,7 +117,8 @@ static int gnss_serial_parse_dt(struct serdev_device *serdev) } struct gnss_serial *gnss_serial_allocate(struct serdev_device *serdev, - size_t data_size) + size_t data_size, + uint serial_speed) { struct gnss_serial *gserial; struct gnss_device *gdev; @@ -146,10 +143,18 @@ struct gnss_serial *gnss_serial_allocate(struct serdev_device *serdev, serdev_device_set_drvdata(serdev, gserial); serdev_device_set_client_ops(serdev, &gnss_serial_serdev_ops); - ret = gnss_serial_parse_dt(serdev); + /* Serial speed provided by subdriver takes precedence over dt*/ + if (!serial_speed) + ret = gnss_serial_parse_dt(serdev); + else + gserial->speed = serial_speed; + if (ret) goto err_put_device; + if (!gserial->speed) + return -EINVAL; + return gserial; err_put_device: diff --git a/drivers/gnss/serial.h b/drivers/gnss/serial.h index 980ffdc86c2a..29212b57a739 100644 --- a/drivers/gnss/serial.h +++ b/drivers/gnss/serial.h @@ -33,7 +33,8 @@ struct gnss_serial_ops { extern const struct dev_pm_ops gnss_serial_pm_ops; struct gnss_serial *gnss_serial_allocate(struct serdev_device *gserial, - size_t data_size); + size_t data_size, + uint serial_speed); void gnss_serial_free(struct gnss_serial *gserial); int gnss_serial_register(struct gnss_serial *gserial); diff --git a/drivers/gnss/ubx.c b/drivers/gnss/ubx.c index 12568aebb7f6..6cfcb2eebdfd 100644 --- a/drivers/gnss/ubx.c +++ b/drivers/gnss/ubx.c @@ -68,8 +68,9 @@ static int ubx_probe(struct serdev_device *serdev) struct gnss_serial *gserial; struct ubx_data *data; int ret; + uint speed = 4800; - gserial = gnss_serial_allocate(serdev, sizeof(*data)); + gserial = gnss_serial_allocate(serdev, sizeof(*data), speed); if (IS_ERR(gserial)) { ret = PTR_ERR(gserial); return ret;