mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask
@ 2018-12-10 14:48 Lucas Stach
  2018-12-10 14:48 ` [PATCH 2/2] backlight: rave-sp: init all brightness to default level Lucas Stach
  2018-12-13  6:50 ` [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Lucas Stach @ 2018-12-10 14:48 UTC (permalink / raw)
  To: barebox

From: Andrey Smirnov <andrew.smirnov@gmail.com>

Unlike LCD type information, IP address as well as netmaks are not
stored in an easily usable format in RAVE SP EEPROM. In order to obtain
them we need to issue a special command to RAVE SP. For that purpose add
device "sp" and expose that data as a device parameters (sp.ipaddr and
sp.netmask, correspondingly)

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/mfd/rave-sp.c       | 72 +++++++++++++++++++++++++++++++++++++
 include/linux/mfd/rave-sp.h |  1 +
 2 files changed, 73 insertions(+)

diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
index 469ce4cc0d08..b7efb62617dc 100644
--- a/drivers/mfd/rave-sp.c
+++ b/drivers/mfd/rave-sp.c
@@ -57,6 +57,8 @@
 #define RAVE_SP_TX_BUFFER_SIZE				\
 	(RAVE_SP_STX_ETX_SIZE + 2 * RAVE_SP_RX_BUFFER_SIZE)
 
+#define RAVE_SP_IPADDR_INVALID		U32_MAX
+
 /**
  * enum rave_sp_deframer_state - Possible state for de-framer
  *
@@ -183,6 +185,7 @@ struct rave_sp_variant {
  * @part_number_bootloader:	Bootloader version
  */
 struct rave_sp {
+	struct device_d dev;
 	struct serdev_device *serdev;
 	struct rave_sp_deframer deframer;
 	unsigned int ackid;
@@ -192,6 +195,9 @@ struct rave_sp {
 
 	const char *part_number_firmware;
 	const char *part_number_bootloader;
+
+	IPaddr_t ipaddr;
+	IPaddr_t netmask;
 };
 
 static bool rave_sp_id_is_event(u8 code)
@@ -718,6 +724,65 @@ static const struct of_device_id __maybe_unused rave_sp_dt_ids[] = {
 	{ /* sentinel */ }
 };
 
+static int rave_sp_req_ip_addr(struct param_d *p, void *context)
+{
+	struct rave_sp *sp = context;
+	u8 cmd[] = {
+		[0] = RAVE_SP_CMD_REQ_IP_ADDR,
+		[1] = 0,
+		[2] = 0, 	/* FIXME: Support for RJU? */
+		[3] = 0,	/* Add support for IPs other than "self" */
+	};
+	struct {
+		__le32 ipaddr;
+		__le32 netmask;
+	} __packed rsp;
+	int ret;
+
+	/*
+	 * We only query RAVE SP device for IP/Netmask once, after
+	 * that we just "serve" cached data.
+	 */
+	if (sp->ipaddr != RAVE_SP_IPADDR_INVALID)
+		return 0;
+
+	ret = rave_sp_exec(sp, &cmd, sizeof(cmd), &rsp, sizeof(rsp));
+	if (ret < 0)
+		return ret;
+
+	sp->ipaddr  = le32_to_cpu(rsp.ipaddr);
+	sp->netmask = le32_to_cpu(rsp.netmask);
+
+	return 0;
+}
+
+static int rave_sp_add_params(struct rave_sp *sp)
+{
+	struct device_d *dev = &sp->dev;
+	struct param_d *p;
+	int ret;
+
+	dev->parent = sp->serdev->dev;
+	dev_set_name(dev, "sp");
+	dev->id = DEVICE_ID_SINGLE;
+
+	ret = register_device(dev);
+	if (ret)
+		return ret;
+
+	p = dev_add_param_ip(dev, "ipaddr", NULL, rave_sp_req_ip_addr,
+			     &sp->ipaddr, sp);
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	p = dev_add_param_ip(dev, "netmask", NULL, rave_sp_req_ip_addr,
+			     &sp->netmask, sp);
+	if (IS_ERR(p))
+		return PTR_ERR(p);
+
+	return 0;
+}
+
 static int rave_sp_probe(struct device_d *dev)
 {
 	struct serdev_device *serdev = to_serdev_device(dev->parent);
@@ -733,6 +798,7 @@ static int rave_sp_probe(struct device_d *dev)
 
 	sp = xzalloc(sizeof(*sp));
 	sp->serdev = serdev;
+	sp->ipaddr = RAVE_SP_IPADDR_INVALID;
 	dev->priv = sp;
 	serdev->dev = dev;
 	serdev->receive_buf = rave_sp_receive_buf;
@@ -773,6 +839,12 @@ static int rave_sp_probe(struct device_d *dev)
 	dev_info(dev, "Firmware version: %s",   sp->part_number_firmware);
 	dev_info(dev, "Bootloader version: %s", sp->part_number_bootloader);
 
+	ret = rave_sp_add_params(sp);
+	if (ret) {
+		dev_err(dev, "Failed to add parameters to RAVE SP\n");
+		return ret;
+	}
+
 	return of_platform_populate(dev->device_node, NULL, dev);
 }
 
diff --git a/include/linux/mfd/rave-sp.h b/include/linux/mfd/rave-sp.h
index 50c9865c00da..37a37788d885 100644
--- a/include/linux/mfd/rave-sp.h
+++ b/include/linux/mfd/rave-sp.h
@@ -28,6 +28,7 @@ enum rave_sp_command {
 
 	RAVE_SP_CMD_JUMP_TO_BOOTLOADER		= 0xB0,
 	RAVE_SP_CMD_BOOTLOADER			= 0xB1,
+	RAVE_SP_CMD_REQ_IP_ADDR			= 0xB2,
 	RAVE_SP_CMD_REQ_COPPER_REV		= 0xB6,
 	RAVE_SP_CMD_GET_I2C_DEVICE_STATUS	= 0xBA,
 	RAVE_SP_CMD_GET_SP_SILICON_REV		= 0xB9,
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] backlight: rave-sp: init all brightness to default level
  2018-12-10 14:48 [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask Lucas Stach
@ 2018-12-10 14:48 ` Lucas Stach
  2018-12-13  6:50 ` [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Lucas Stach @ 2018-12-10 14:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/video/rave-sp-backlight.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/rave-sp-backlight.c b/drivers/video/rave-sp-backlight.c
index 3a20def661ce..877a5feeb627 100644
--- a/drivers/video/rave-sp-backlight.c
+++ b/drivers/video/rave-sp-backlight.c
@@ -47,7 +47,7 @@ static int rave_sp_backlight_probe(struct device_d *dev)
 	bd = xzalloc(sizeof(*bd));
 	bd->dev.priv = dev->parent->priv;
 	bd->dev.parent = dev;
-	bd->brightness_default = 50;
+	bd->brightness = bd->brightness_cur = bd->brightness_default = 50;
 	bd->brightness_max = 100;
 	bd->brightness_set = rave_sp_backlight_set;
 
-- 
2.19.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask
  2018-12-10 14:48 [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask Lucas Stach
  2018-12-10 14:48 ` [PATCH 2/2] backlight: rave-sp: init all brightness to default level Lucas Stach
@ 2018-12-13  6:50 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2018-12-13  6:50 UTC (permalink / raw)
  To: Lucas Stach; +Cc: barebox

On Mon, Dec 10, 2018 at 03:48:23PM +0100, Lucas Stach wrote:
> From: Andrey Smirnov <andrew.smirnov@gmail.com>
> 
> Unlike LCD type information, IP address as well as netmaks are not
> stored in an easily usable format in RAVE SP EEPROM. In order to obtain
> them we need to issue a special command to RAVE SP. For that purpose add
> device "sp" and expose that data as a device parameters (sp.ipaddr and
> sp.netmask, correspondingly)
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> ---

Applied, thanks

Sascha

>  drivers/mfd/rave-sp.c       | 72 +++++++++++++++++++++++++++++++++++++
>  include/linux/mfd/rave-sp.h |  1 +
>  2 files changed, 73 insertions(+)
> 
> diff --git a/drivers/mfd/rave-sp.c b/drivers/mfd/rave-sp.c
> index 469ce4cc0d08..b7efb62617dc 100644
> --- a/drivers/mfd/rave-sp.c
> +++ b/drivers/mfd/rave-sp.c
> @@ -57,6 +57,8 @@
>  #define RAVE_SP_TX_BUFFER_SIZE				\
>  	(RAVE_SP_STX_ETX_SIZE + 2 * RAVE_SP_RX_BUFFER_SIZE)
>  
> +#define RAVE_SP_IPADDR_INVALID		U32_MAX
> +
>  /**
>   * enum rave_sp_deframer_state - Possible state for de-framer
>   *
> @@ -183,6 +185,7 @@ struct rave_sp_variant {
>   * @part_number_bootloader:	Bootloader version
>   */
>  struct rave_sp {
> +	struct device_d dev;
>  	struct serdev_device *serdev;
>  	struct rave_sp_deframer deframer;
>  	unsigned int ackid;
> @@ -192,6 +195,9 @@ struct rave_sp {
>  
>  	const char *part_number_firmware;
>  	const char *part_number_bootloader;
> +
> +	IPaddr_t ipaddr;
> +	IPaddr_t netmask;
>  };
>  
>  static bool rave_sp_id_is_event(u8 code)
> @@ -718,6 +724,65 @@ static const struct of_device_id __maybe_unused rave_sp_dt_ids[] = {
>  	{ /* sentinel */ }
>  };
>  
> +static int rave_sp_req_ip_addr(struct param_d *p, void *context)
> +{
> +	struct rave_sp *sp = context;
> +	u8 cmd[] = {
> +		[0] = RAVE_SP_CMD_REQ_IP_ADDR,
> +		[1] = 0,
> +		[2] = 0, 	/* FIXME: Support for RJU? */
> +		[3] = 0,	/* Add support for IPs other than "self" */
> +	};
> +	struct {
> +		__le32 ipaddr;
> +		__le32 netmask;
> +	} __packed rsp;
> +	int ret;
> +
> +	/*
> +	 * We only query RAVE SP device for IP/Netmask once, after
> +	 * that we just "serve" cached data.
> +	 */
> +	if (sp->ipaddr != RAVE_SP_IPADDR_INVALID)
> +		return 0;
> +
> +	ret = rave_sp_exec(sp, &cmd, sizeof(cmd), &rsp, sizeof(rsp));
> +	if (ret < 0)
> +		return ret;
> +
> +	sp->ipaddr  = le32_to_cpu(rsp.ipaddr);
> +	sp->netmask = le32_to_cpu(rsp.netmask);
> +
> +	return 0;
> +}
> +
> +static int rave_sp_add_params(struct rave_sp *sp)
> +{
> +	struct device_d *dev = &sp->dev;
> +	struct param_d *p;
> +	int ret;
> +
> +	dev->parent = sp->serdev->dev;
> +	dev_set_name(dev, "sp");
> +	dev->id = DEVICE_ID_SINGLE;
> +
> +	ret = register_device(dev);
> +	if (ret)
> +		return ret;
> +
> +	p = dev_add_param_ip(dev, "ipaddr", NULL, rave_sp_req_ip_addr,
> +			     &sp->ipaddr, sp);
> +	if (IS_ERR(p))
> +		return PTR_ERR(p);
> +
> +	p = dev_add_param_ip(dev, "netmask", NULL, rave_sp_req_ip_addr,
> +			     &sp->netmask, sp);
> +	if (IS_ERR(p))
> +		return PTR_ERR(p);
> +
> +	return 0;
> +}
> +
>  static int rave_sp_probe(struct device_d *dev)
>  {
>  	struct serdev_device *serdev = to_serdev_device(dev->parent);
> @@ -733,6 +798,7 @@ static int rave_sp_probe(struct device_d *dev)
>  
>  	sp = xzalloc(sizeof(*sp));
>  	sp->serdev = serdev;
> +	sp->ipaddr = RAVE_SP_IPADDR_INVALID;
>  	dev->priv = sp;
>  	serdev->dev = dev;
>  	serdev->receive_buf = rave_sp_receive_buf;
> @@ -773,6 +839,12 @@ static int rave_sp_probe(struct device_d *dev)
>  	dev_info(dev, "Firmware version: %s",   sp->part_number_firmware);
>  	dev_info(dev, "Bootloader version: %s", sp->part_number_bootloader);
>  
> +	ret = rave_sp_add_params(sp);
> +	if (ret) {
> +		dev_err(dev, "Failed to add parameters to RAVE SP\n");
> +		return ret;
> +	}
> +
>  	return of_platform_populate(dev->device_node, NULL, dev);
>  }
>  
> diff --git a/include/linux/mfd/rave-sp.h b/include/linux/mfd/rave-sp.h
> index 50c9865c00da..37a37788d885 100644
> --- a/include/linux/mfd/rave-sp.h
> +++ b/include/linux/mfd/rave-sp.h
> @@ -28,6 +28,7 @@ enum rave_sp_command {
>  
>  	RAVE_SP_CMD_JUMP_TO_BOOTLOADER		= 0xB0,
>  	RAVE_SP_CMD_BOOTLOADER			= 0xB1,
> +	RAVE_SP_CMD_REQ_IP_ADDR			= 0xB2,
>  	RAVE_SP_CMD_REQ_COPPER_REV		= 0xB6,
>  	RAVE_SP_CMD_GET_I2C_DEVICE_STATUS	= 0xBA,
>  	RAVE_SP_CMD_GET_SP_SILICON_REV		= 0xB9,
> -- 
> 2.19.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-13  6:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-10 14:48 [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask Lucas Stach
2018-12-10 14:48 ` [PATCH 2/2] backlight: rave-sp: init all brightness to default level Lucas Stach
2018-12-13  6:50 ` [PATCH 1/2] mfd: rave-sp: Add parameters to query IP address/netmask Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox