Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp935821yba; Thu, 16 May 2019 11:15:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqztIgnrDw2VF9794VlBOjc8pZ9mIcQhfdEzOdvsztiof0pAA08zYkjyF6CPG3cvvN/tgmiO X-Received: by 2002:a17:902:324:: with SMTP id 33mr52152521pld.284.1558030531778; Thu, 16 May 2019 11:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558030531; cv=none; d=google.com; s=arc-20160816; b=N51g0toMcQAxT0S5gYji7o5bEyHr332IdK8Uk14PAriNw/ZboVgDmUWf2S5pLJfDeP VVC0a6Seokpk4SZ0dv52K6cE2uMKE7dOvo+u2lh/71J4K3lvGABcpTLMPH8r1L3nRhd1 v8Sh23Brl5nY5m/jGS9efhP880ukIBV5KxmzWpGm4FrdBr4kKU6Wh5Gci60VUfXjdtOJ cJnjbkBLCOVBJ1/1zJXNdCCwBax7F9ijBrrQxu5fu7a8WrsCxTUPbVe0DokJkchd6ZfE UlpHiRv95jmVtWIBoYlCwPiHVkzwv0TQrZ4AJsVgJacqKp1joK5VsgFjCFJJmRm1xnBJ +RHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=ThsUgCnRiH2xV7RaQ5eyyKQF0jGHePi2XouhM2DCtVc=; b=AVHT45UQFks5+qYtQTik10lOgYo/JfJMBHSzHZHv8yb/Dey9mDUbmdmuoa58T6Kg/K KMQB4BhGURizRu+aKAUuZvFydKAT4jM/QOKHp2qUaxKn4cA+5npmWAzh4MJudAltWzOJ dRSDOiIOTGXSNa8CC0uUe6MTCRcecuIoN6p7cJDnv2UUoCcEiZ2CbxcPuYpuSWPxE0TV AUS0oYz8rJPvNH/+c/DssDYws5AtdqqK12feq1GBYI6TjICM7x4DDDf4EAV275XMPIe0 aUCWBnnJFdpJm+7EJkKrBV2tAmHIvC7iXKJ8N1NFjrNmx3clWAKJeVuv9BKYng26ywoO Bulg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=qi6MyDpz; 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 a98si5648134pla.282.2019.05.16.11.15.16; Thu, 16 May 2019 11:15:31 -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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=qi6MyDpz; 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 S1727116AbfEPQhP (ORCPT + 99 others); Thu, 16 May 2019 12:37:15 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37546 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726342AbfEPQhP (ORCPT ); Thu, 16 May 2019 12:37:15 -0400 Received: by mail-wm1-f66.google.com with SMTP id 7so4154866wmo.2 for ; Thu, 16 May 2019 09:37:13 -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; bh=ThsUgCnRiH2xV7RaQ5eyyKQF0jGHePi2XouhM2DCtVc=; b=qi6MyDpzUBi/YhH3EIVRa9In2VP4i8/Rqo8r4u+l2ILm5g/G2aH1ZkO2/tkZJzAz+4 fP3htptmdBLOK1x23VJVUHtY2KnUbze/RsIZyaDFGvx7uSAOWifUSoQUrBeEOo6Z9JEx UJBXkkffA169xraI5y96uDyl+P+i1AqTKrqfqcXDZeVKHP44f4+RfHrbVPDj2EzMhBij bZCJ7Po/trm6o16eQHuuiwHfXslowAzpx7CsB1A1XWwMYZo348VaoFUGdTxC8RnlSsB+ /iCrhFXuRYx21k05rd3DgNt4GDVe4/Huxf5QAxwLlbuPQbm74I5EsNkyp3ap1yJF/89E OY7A== 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; bh=ThsUgCnRiH2xV7RaQ5eyyKQF0jGHePi2XouhM2DCtVc=; b=c3AbYEBH8DMRXJIBAbqhmii8kPNGNAWpg+GevE90LTxVkxXyPNYJyAfvcF+6sMOtn5 4qtgwxG/mSZvIrFrREhi4tX1G1hGWiO+1+58kQX9JmhB4EBBf3MqcMObhXwYdVmdXo+9 1caY1D896Vphy6F14rrv8brB1/klxmqIbz99TFM66Ra5VqZkaQCergpHi3mweQGvpfeA f/CDwBEkjSYGogRYPC65HN90qKgwHmJNh/OQG0PW1+0c+hz6ZRAlzYc+8bQ7khjiS2It EzTYoqaQRcBEyKMhsg5LwJGvPkFgD7lNUOKy3rc9Bg6lHGb8YIzoW28DwYOBajAuvfbt Yi+A== X-Gm-Message-State: APjAAAX0AE7Aq2cBdJxVTHd2PpMxWxq6rvY7ov6daFZrY04gNoO61AVB kVr3P3on9jaTZujwrRIaKdTbzA== X-Received: by 2002:a1c:1f47:: with SMTP id f68mr18234178wmf.57.1558024632927; Thu, 16 May 2019 09:37:12 -0700 (PDT) Received: from loys-ubuntu-BY1835A49200471.thefacebook.com ([2620:10d:c092:180::1:e504]) by smtp.googlemail.com with ESMTPSA id x68sm2112515wmf.13.2019.05.16.09.37.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 May 2019 09:37:12 -0700 (PDT) From: Loys Ollivier To: Johan Hovold , Matthias Brugger Cc: Loys Ollivier , Colin Ian King , Corentin Labbe , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, baylibre-upstreaming@groups.io Subject: [PATCH v2] gnss: get serial speed from subdrivers Date: Thu, 16 May 2019 18:37:06 +0200 Message-Id: <1558024626-19395-1-git-send-email-lollivier@baylibre.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Hello, This patch moves the currently hardcoded, default serial speed to the subdrivers. If the default speed is not specified by the subdriver then it is read from the device tree. Changes since v1[0] - Use u32 data types instead of uint [0]: https://lore.kernel.org/lkml/1557322788-10403-1-git-send-email-lollivier@baylibre.com/ Cheers, Loys drivers/gnss/mtk.c | 7 ++++++- drivers/gnss/serial.c | 21 +++++++++++++-------- drivers/gnss/serial.h | 3 ++- drivers/gnss/ubx.c | 3 ++- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/gnss/mtk.c b/drivers/gnss/mtk.c index d1fc55560daf..1d35bcb52072 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,8 @@ 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), + (u32)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..3be799702291 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; + u32 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, + u32 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..17df61e399e6 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, + u32 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 7b05bc40532e..52ae6e4987e0 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; + u32 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; -- 2.7.4