linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Loic Poulain <loic.poulain@linaro.org>, johan@kernel.org
Cc: linux-usb@vger.kernel.org, daniel.thompson@linaro.org
Subject: USB: serial: ftdi_sio: Add MTP NVM support
Date: Wed, 20 Jun 2018 10:09:34 +0100	[thread overview]
Message-ID: <2af30d9e-c48a-0c69-2fee-df564b7d355c@linaro.org> (raw)

Overall nvmem side looks good!
Minor nits below.

On 14/06/18 21:08, Loic Poulain wrote:
> Most of FTDI's devices have an EEPROM which records FTDI devices
> configuration setting (e.g. the VID, PID, I/O config...) and user
> data. FT230R chip integrates a 128-byte eeprom, FT230X a 2048-byte
> eeprom...
> 
> This patch adds support for FTDI EEPROM read/write via USB control
> transfers and register a new nvm device to the nvmem core.
> 
> This permits to expose the eeprom as a sysfs file, allowing userspace
> to read/modify FTDI configuration and its user data without having to
> rely on a specific userspace USB driver.
> 
> Moreover, any upcoming new tentative to add CBUS GPIO support could
> integrate CBUS EEPROM configuration reading in order to determine
> which of the CBUS pins are available as GPIO.
> 
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
> ---
>   drivers/usb/serial/Kconfig    |  11 +++++
>   drivers/usb/serial/ftdi_sio.c | 108 ++++++++++++++++++++++++++++++++++++++++++
>   drivers/usb/serial/ftdi_sio.h |  28 +++++++++++
>   3 files changed, 147 insertions(+)
> 
> diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
> index 533f127..2dd2f5d 100644
> --- a/drivers/usb/serial/Kconfig
> +++ b/drivers/usb/serial/Kconfig
> @@ -181,6 +181,17 @@ config USB_SERIAL_FTDI_SIO
>   	  To compile this driver as a module, choose M here: the
>   	  module will be called ftdi_sio.
>   
> +config USB_SERIAL_FTDI_SIO_NVMEM
> +        bool "FTDI MTP non-volatile memory support"
> +	depends on USB_SERIAL_FTDI_SIO
Looks inconsistent tab and spaces here.

> +        select NVMEM
> +        default y
??

Does that mean all the FTDIs have EEPROM?

> +        help

> +	  Say yes here to add support for the MTP non-volatile memory
> +	  present on FTDI. Most of FTDI's devices have an EEPROM which
> +	  records FTDI device's configuration setting as well as user
> +	  data.
> +
>   config USB_SERIAL_VISOR
>   	tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver"
>   	help
> diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> index 7ea221d..03c9c75 100644
> --- a/drivers/usb/serial/ftdi_sio.c
> +++ b/drivers/usb/serial/ftdi_sio.c
> @@ -40,6 +40,7 @@
>   #include <linux/usb.h>
>   #include <linux/serial.h>
>   #include <linux/usb/serial.h>
> +#include <linux/nvmem-provider.h>
>   #include "ftdi_sio.h"
>   #include "ftdi_sio_ids.h"
>   
> @@ -73,6 +74,8 @@ struct ftdi_private {
>   	unsigned int latency;		/* latency setting in use */
>   	unsigned short max_packet_size;
>   	struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() and change_speed() */
> +
> +	struct nvmem_device *eeprom;
>   };
>   
>   /* struct ftdi_sio_quirk is used by devices requiring special attention. */
> @@ -1529,6 +1532,104 @@ static int get_lsr_info(struct usb_serial_port *port,
>   	return 0;
>   }
>   
> +#if IS_ENABLED(CONFIG_USB_SERIAL_FTDI_SIO_NVMEM)
I think only ifdef should be Okay here as this Kconfig is just bool
> +

...

> +static int register_eeprom(struct usb_serial_port *port)
> +{
> +	struct ftdi_private *priv = usb_get_serial_port_data(port);
> +	struct nvmem_config nvmconf = {};
> +
> +	switch (priv->chip_type) {
> +	case FTX:
> +		nvmconf.size = 2048;
> +		break;
> +	case FT232RL:
> +		nvmconf.size = 128;
> +		break;
> +	default:
> +		return 0;
> +	}
> +
> +	nvmconf.word_size = 2;
> +	nvmconf.stride = 2;
> +	nvmconf.read_only = false;
> +	nvmconf.priv = port;
> +	nvmconf.dev = &port->dev;
> +	nvmconf.reg_read = read_eeprom;
> +	nvmconf.reg_write = write_eeprom;
> +	nvmconf.owner = THIS_MODULE;
> +
> +	priv->eeprom = nvmem_register(&nvmconf);
> +	if (IS_ERR(priv->eeprom)) {
> +		priv->eeprom = NULL;
> +		return -ENOMEM;
> +	}
> +
> +	return 0;
> +}
> +
> +static void unregister_eeprom(struct usb_serial_port *port)
> +{
> +	struct ftdi_private *priv = usb_get_serial_port_data(port);
> +
> +	if (priv->eeprom)
> +		nvmem_unregister(priv->eeprom);
> +}
> +
> +#endif /* CONFIG_USB_SERIAL_FTDI_SIO_NVMEM */
>   
>   /* Determine type of FTDI chip based on USB config and descriptor. */
>   static void ftdi_determine_type(struct usb_serial_port *port)
> @@ -1814,6 +1915,10 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
>   		priv->latency = 16;
>   	write_latency_timer(port);
>   	create_sysfs_attrs(port);
> +#if IS_ENABLED(CONFIG_USB_SERIAL_FTDI_SIO_NVMEM)
> +	register_eeprom(port);

Users will be clueless if the register_eeprom fails here.



> +#endif
> +
>   	return 0;
>   }
>   
> @@ -1931,6 +2036,9 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
>   {
>   	struct ftdi_private *priv = usb_get_serial_port_data(port);
>   
> +#if IS_ENABLED(CONFIG_USB_SERIAL_FTDI_SIO_NVMEM)
> +	unregister_eeprom(port);
> +#endif
>   	remove_sysfs_attrs(port);
>   
>   	kfree(priv);

thanks,
srini
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2018-06-20  9:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20  9:09 Srinivas Kandagatla [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-06-20  8:52 USB: serial: ftdi_sio: Add MTP NVM support Loic Poulain
2018-06-19 13:06 Johan Hovold
2018-06-19 12:32 Loic Poulain
2018-06-18  9:47 Srinivas Kandagatla
2018-06-18  8:46 Johan Hovold
2018-06-14 20:08 Loic Poulain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2af30d9e-c48a-0c69-2fee-df564b7d355c@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=daniel.thompson@linaro.org \
    --cc=johan@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=loic.poulain@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).