diff mbox series

[RESEND] gnss: get serial speed from subdrivers

Message ID 1557322788-10403-1-git-send-email-lollivier@baylibre.com
State Superseded
Headers show
Series [RESEND] gnss: get serial speed from subdrivers | expand

Commit Message

Loys Ollivier May 8, 2019, 1:39 p.m. UTC
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 <lollivier@baylibre.com>

---
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.

Cheers,
Loys

 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(-)

-- 
2.7.4

Comments

Corentin Labbe May 8, 2019, 3:53 p.m. UTC | #1
On Wed, May 08, 2019 at 03:39:48PM +0200, Loys Ollivier wrote:
> 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 <lollivier@baylibre.com>

> ---

> 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.

> 

> Cheers,

> Loys

> 

>  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);


Hello

of_property_read_u32 use u32, so no reason to use uint instead.

Regards
Loys Ollivier May 16, 2019, 4:39 p.m. UTC | #2
On Wed 08 May 2019 at 17:53, Corentin Labbe <clabbe.montjoie@gmail.com> wrote:
>> -/*

>> - * 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);

>

> Hello

>

> of_property_read_u32 use u32, so no reason to use uint instead.

>

> Regards


Hello Corentin,

Thank you for your review. A v2 has been sent:
https://lore.kernel.org/lkml/1558024626-19395-1-git-send-email-lollivier@baylibre.com/

Cheers,
Loys
diff mbox series

Patch

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 7b05bc40532e..26a278c7e2fd 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;