libertas: if_spi: add ability to call board specific setup/teardown methods
Subsystems (2)
PATCH 1/1 libertas: if_spi: add ability to call board specific setup/teardown methods
In certain cases it is required to perform board specific actions before activating libertas G-SPI interface. These actions may include power up of the chip, GPIOs setup, proper pin-strapping and SPI controller config.
This patch adds ability to call board specific setup/teardown methods
--- drivers/net/wireless/libertas/if_spi.c | 15 +++++++++++++++ include/linux/spi/libertas_spi.h | 7 +++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
drivers/net/wireless/libertas/if_spi.c +15 -0
@@ -42,6 +42,7 @@ struct if_spi_packet {struct if_spi_card {struct spi_device *spi;struct lbs_private *priv; +struct libertas_spi_platform_data *pdata;char helper_fw_name[FIRMWARE_NAME_MAX ];char main_fw_name[FIRMWARE_NAME_MAX ];
@@ -1022,6 +1023,17 @@ static int __devinit if_spi_probe(struct spi_device *spi)lbs_deb_enter (LBS_DEB_SPI ); +if (!pdata) { + err = -EINVAL ; + goto out; + } + +if (pdata->setup) { + err = pdata->setup (spi); +if (err) + goto out; + } +/* Allocate card structure to represent this specific device */ card =kzalloc (sizeof (struct if_spi_card ),GFP_KERNEL );if (!card) {
@@ -1029,6 +1041,7 @@ static int __devinit if_spi_probe(struct spi_device *spi) goto out; }spi_set_drvdata (spi, card); + card->pdata = pdata; card->spi = spi; card->gpio_cs = pdata->gpio_cs; card->prev_xfer_time = jiffies;
@@ -1158,6 +1171,8 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)if_spi_terminate_spi_thread (card);lbs_remove_card (priv);/* will call free_netdev */ gpio_free (card->gpio_cs); +if (card->pdata->teardown) + card->pdata->teardown (spi);free_if_spi_card (card);lbs_deb_leave (LBS_DEB_SPI );return 0 ;
include/linux/spi/libertas_spi.h +7 -0
@@ -10,6 +10,9 @@*/ #ifndef _LIBERTAS_SPI_H_#define _LIBERTAS_SPI_H_ + +struct spi_device ; + struct libertas_spi_platform_data {/* There are two ways to read data from the WLAN module's SPI * interface. Setting 0 or 1 here controls which one is used.
@@ -21,5 +24,9 @@ struct libertas_spi_platform_data {/* GPIO number to use as chip select */ u16 gpio_cs; + +/* Board specific setup/teardown */ +int (*setup)(struct spi_device *spi); + int (*teardown)(struct spi_device *spi); };#endif
Signature · 6 lines
1.5.6.4 -- Sincerely yours, Mike.
Quoted 8 lines · Mike Rapoport
In certain cases it is required to perform board specific actions before activating libertas G-SPI interface. These actions may include power up of the chip, GPIOs setup, proper pin-strapping and SPI controller config.
This patch adds ability to call board specific setup/teardown methodsSigned-off-by Mike Rapoport <[email protected]>
Andrey, does this look OK to you? Seems fine to me, though what's the lifetime of the platform data 'pdata' in the probe function? Is that guaranteed to be valid for the entire lifetime of the libertas SPI device?
Dan
Quoted 80 lines
--- drivers/net/wireless/libertas/if_spi.c | 15 +++++++++++++++ include/linux/spi/libertas_spi.h | 7 +++++++ 2 files changed, 22 insertions(+), 0 deletions(-)drivers/net/wireless/libertas/if_spi.c +15
-0@@ -42,6 +42,7 @@ struct if_spi_packet {struct if_spi_card {struct spi_device *spi;struct lbs_private *priv; +struct libertas_spi_platform_data *pdata;char helper_fw_name[FIRMWARE_NAME_MAX ];char main_fw_name[FIRMWARE_NAME_MAX ];@@ -1022,6 +1023,17 @@ static int __devinit if_spi_probe(struct spi_device *spi)lbs_deb_enter (LBS_DEB_SPI ); +if (!pdata) { + err = -EINVAL ; + goto out; + } + +if (pdata->setup) { + err = pdata->setup (spi); +if (err) + goto out; + } +/* Allocate card structure to represent this specific device */ card =kzalloc (sizeof (struct if_spi_card ),GFP_KERNEL );if (!card) {@@ -1029,6 +1041,7 @@ static int __devinit if_spi_probe(struct spi_device *spi) goto out; }spi_set_drvdata (spi, card); + card->pdata = pdata; card->spi = spi; card->gpio_cs = pdata->gpio_cs; card->prev_xfer_time = jiffies;@@ -1158,6 +1171,8 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)if_spi_terminate_spi_thread (card);lbs_remove_card (priv);/* will call free_netdev */ gpio_free (card->gpio_cs); +if (card->pdata->teardown) + card->pdata->teardown (spi);free_if_spi_card (card);lbs_deb_leave (LBS_DEB_SPI );return 0 ;include/linux/spi/libertas_spi.h +7
-0@@ -10,6 +10,9 @@*/ #ifndef _LIBERTAS_SPI_H_#define _LIBERTAS_SPI_H_ + +struct spi_device ; + struct libertas_spi_platform_data {/* There are two ways to read data from the WLAN module's SPI * interface. Setting 0 or 1 here controls which one is used. @@ -21,5 +24,9 @@ struct libertas_spi_platform_data {/* GPIO number to use as chip select */ u16 gpio_cs; + +/* Board specific setup/teardown */ +int (*setup)(struct spi_device *spi); + int (*teardown)(struct spi_device *spi); };#endif Signature · 1 line
1.5.6.4
Andrey Yurovsky
Acked-byQuoted 8 lines · Dan Williams
Quoted 7 lines · Mike Rapoport
In certain cases it is required to perform board specific actions before activating libertas G-SPI interface. These actions may include power up of the chip, GPIOs setup, proper pin-strapping and SPI controller config.
This patch adds ability to call board specific setup/teardown methods
Quoted 8 lines
Quoted 1 line
Signed-off-by Mike Rapoport <[email protected]>Andrey, does this look OK to you? Seems fine to me, though what's the lifetime of the platform data 'pdata' in the probe function? Is that guaranteed to be valid for the entire lifetime of the libertas SPI device?
Dan
Yes, this looks good to me. 'pdata' will span the lifetime of the device as it's set up in if_spi_probe and stays around until libertas_spi_remove
Quoted 87 lines
Quoted 77 lines
--- drivers/net/wireless/libertas/if_spi.c | 15 +++++++++++++++ include/linux/spi/libertas_spi.h | 7 +++++++ 2 files changed, 22 insertions(+), 0 deletions(-)drivers/net/wireless/libertas/if_spi.c +15
-0@@ -42,6 +42,7 @@ struct if_spi_packet {struct if_spi_card {struct spi_device *spi;struct lbs_private *priv; +struct libertas_spi_platform_data *pdata;char helper_fw_name[FIRMWARE_NAME_MAX ];char main_fw_name[FIRMWARE_NAME_MAX ];@@ -1022,6 +1023,17 @@ static int __devinit if_spi_probe(struct spi_device *spi)lbs_deb_enter (LBS_DEB_SPI ); +if (!pdata) { + err = -EINVAL ; + goto out; + } + +if (pdata->setup) { + err = pdata->setup (spi); +if (err) + goto out; + } +/* Allocate card structure to represent this specific device */ card =kzalloc (sizeof (struct if_spi_card ),GFP_KERNEL );if (!card) {@@ -1029,6 +1041,7 @@ static int __devinit if_spi_probe(struct spi_device *spi) goto out; }spi_set_drvdata (spi, card); + card->pdata = pdata; card->spi = spi; card->gpio_cs = pdata->gpio_cs; card->prev_xfer_time = jiffies;@@ -1158,6 +1171,8 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)if_spi_terminate_spi_thread (card);lbs_remove_card (priv);/* will call free_netdev */ gpio_free (card->gpio_cs); +if (card->pdata->teardown) + card->pdata->teardown (spi);free_if_spi_card (card);lbs_deb_leave (LBS_DEB_SPI );return 0 ;include/linux/spi/libertas_spi.h +7
-1@@ -10,6 +10,9 @@*/ #ifndef _LIBERTAS_SPI_H_#define _LIBERTAS_SPI_H_ + +struct spi_device ; + struct libertas_spi_platform_data {/* There are two ways to read data from the WLAN module's SPI * interface. Setting 0 or 1 here controls which one is used. @@ -21,5 +24,9 @@ struct libertas_spi_platform_data {/* GPIO number to use as chip select */ u16 gpio_cs; + +/* Board specific setup/teardown */ +int (*setup)(struct spi_device *spi); + int (*teardown)(struct spi_device *spi); };#endif --Quoted 3 lines
1.5.6.4
_______________________________________________
libertas-dev mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/libertas-dev
Dan Williams
Acked-byQuoted 16 lines · Andrey Yurovsky
Quoted 15 lines · Dan Williams
Quoted 8 lines · Mike Rapoport
In certain cases it is required to perform board specific actions before activating libertas G-SPI interface. These actions may include power up of the chip, GPIOs setup, proper pin-strapping and SPI controller config.
This patch adds ability to call board specific setup/teardown methodsSigned-off-by Mike Rapoport <[email protected]>Andrey, does this look OK to you? Seems fine to me, though what's the lifetime of the platform data 'pdata' in the probe function? Is that guaranteed to be valid for the entire lifetime of the libertas SPI device?
Quoted 7 lines
Quoted 1 line
Dan
Yes, this looks good to me. 'pdata' will span the lifetime of the device as it's set up in
if_spi_probeand stays around untillibertas_spi_removeAcked-by Andrey Yurovsky <[email protected]>
Quoted 87 lines
Quoted 87 lines
Quoted 77 lines
--- drivers/net/wireless/libertas/if_spi.c | 15 +++++++++++++++ include/linux/spi/libertas_spi.h | 7 +++++++ 2 files changed, 22 insertions(+), 0 deletions(-)drivers/net/wireless/libertas/if_spi.c +15
-0@@ -42,6 +42,7 @@ struct if_spi_packet {struct if_spi_card {struct spi_device *spi;struct lbs_private *priv; +struct libertas_spi_platform_data *pdata;char helper_fw_name[FIRMWARE_NAME_MAX ];char main_fw_name[FIRMWARE_NAME_MAX ];@@ -1022,6 +1023,17 @@ static int __devinit if_spi_probe(struct spi_device *spi)lbs_deb_enter (LBS_DEB_SPI ); +if (!pdata) { + err = -EINVAL ; + goto out; + } + +if (pdata->setup) { + err = pdata->setup (spi); +if (err) + goto out; + } +/* Allocate card structure to represent this specific device */ card =kzalloc (sizeof (struct if_spi_card ),GFP_KERNEL );if (!card) {@@ -1029,6 +1041,7 @@ static int __devinit if_spi_probe(struct spi_device *spi) goto out; }spi_set_drvdata (spi, card); + card->pdata = pdata; card->spi = spi; card->gpio_cs = pdata->gpio_cs; card->prev_xfer_time = jiffies;@@ -1158,6 +1171,8 @@ static int __devexit libertas_spi_remove(struct spi_device *spi)if_spi_terminate_spi_thread (card);lbs_remove_card (priv);/* will call free_netdev */ gpio_free (card->gpio_cs); +if (card->pdata->teardown) + card->pdata->teardown (spi);free_if_spi_card (card);lbs_deb_leave (LBS_DEB_SPI );return 0 ;include/linux/spi/libertas_spi.h +7
-1@@ -10,6 +10,9 @@*/ #ifndef _LIBERTAS_SPI_H_#define _LIBERTAS_SPI_H_ + +struct spi_device ; + struct libertas_spi_platform_data {/* There are two ways to read data from the WLAN module's SPI * interface. Setting 0 or 1 here controls which one is used. @@ -21,5 +24,9 @@ struct libertas_spi_platform_data {/* GPIO number to use as chip select */ u16 gpio_cs; + +/* Board specific setup/teardown */ +int (*setup)(struct spi_device *spi); + int (*teardown)(struct spi_device *spi); };#endif --Quoted 3 lines
1.5.6.4
_______________________________________________
libertas-dev mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/libertas-dev