All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave
@ 2015-02-20 16:17 Axel Lin
  2015-02-20 16:19 ` [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions Axel Lin
  2015-03-29 20:14 ` [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Jagan Teki
  0 siblings, 2 replies; 4+ messages in thread
From: Axel Lin @ 2015-02-20 16:17 UTC (permalink / raw)
  To: u-boot

Don't assume slave is always the first member of struct cf_spi_slave.
Use container_of instead of casting first structure member.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/spi/cf_spi.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c
index 879a809..7453538 100644
--- a/drivers/spi/cf_spi.c
+++ b/drivers/spi/cf_spi.c
@@ -46,6 +46,11 @@ DECLARE_GLOBAL_DATA_PTR;
 #define SPI_MODE_MOD	0x00200000
 #define SPI_DBLRATE	0x00100000
 
+static inline struct cf_spi_slave *to_cf_spi_slave(struct spi_slave *slave)
+{
+	return container_of(slave, struct cf_spi_slave, slave);
+}
+
 void cfspi_init(void)
 {
 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
@@ -105,7 +110,7 @@ u16 cfspi_rx(void)
 int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
 	       void *din, ulong flags)
 {
-	struct cf_spi_slave *cfslave = (struct cf_spi_slave *)slave;
+	struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
 	u16 *spi_rd16 = NULL, *spi_wr16 = NULL;
 	u8 *spi_rd = NULL, *spi_wr = NULL;
 	static u32 ctrl = 0;
@@ -326,7 +331,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 
 void spi_free_slave(struct spi_slave *slave)
 {
-	free(slave);
+	struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
+
+	free(cfslave);
 }
 
 int spi_claim_bus(struct spi_slave *slave)
-- 
1.9.1

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

* [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions
  2015-02-20 16:17 [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Axel Lin
@ 2015-02-20 16:19 ` Axel Lin
  2015-03-29 20:14   ` Jagan Teki
  2015-03-29 20:14 ` [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Jagan Teki
  1 sibling, 1 reply; 4+ messages in thread
From: Axel Lin @ 2015-02-20 16:19 UTC (permalink / raw)
  To: u-boot

Make local functions static and remove unneeded forward declarations.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/spi/cf_spi.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c
index 7453538..6ce1101 100644
--- a/drivers/spi/cf_spi.c
+++ b/drivers/spi/cf_spi.c
@@ -20,13 +20,6 @@ struct cf_spi_slave {
 	int charbit;
 };
 
-int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
-	       void *din, ulong flags);
-struct spi_slave *cfspi_setup_slave(struct cf_spi_slave *cfslave, uint mode);
-void cfspi_init(void);
-void cfspi_tx(u32 ctrl, u16 data);
-u16 cfspi_rx(void);
-
 extern void cfspi_port_conf(void);
 extern int cfspi_claim_bus(uint bus, uint cs);
 extern void cfspi_release_bus(uint bus, uint cs);
@@ -51,7 +44,7 @@ static inline struct cf_spi_slave *to_cf_spi_slave(struct spi_slave *slave)
 	return container_of(slave, struct cf_spi_slave, slave);
 }
 
-void cfspi_init(void)
+static void cfspi_init(void)
 {
 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
 
@@ -89,7 +82,7 @@ void cfspi_init(void)
 #endif
 }
 
-void cfspi_tx(u32 ctrl, u16 data)
+static void cfspi_tx(u32 ctrl, u16 data)
 {
 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
 
@@ -98,7 +91,7 @@ void cfspi_tx(u32 ctrl, u16 data)
 	dspi->tfr = (ctrl | data);
 }
 
-u16 cfspi_rx(void)
+static u16 cfspi_rx(void)
 {
 	volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
 
@@ -107,8 +100,8 @@ u16 cfspi_rx(void)
 	return (dspi->rfr & 0xFFFF);
 }
 
-int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
-	       void *din, ulong flags)
+static int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
+		      void *din, ulong flags)
 {
 	struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
 	u16 *spi_rd16 = NULL, *spi_wr16 = NULL;
@@ -181,7 +174,8 @@ int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
 	return 0;
 }
 
-struct spi_slave *cfspi_setup_slave(struct cf_spi_slave *cfslave, uint mode)
+static struct spi_slave *cfspi_setup_slave(struct cf_spi_slave *cfslave,
+					   uint mode)
 {
 	/*
 	 * bit definition for mode:
-- 
1.9.1

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

* [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave
  2015-02-20 16:17 [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Axel Lin
  2015-02-20 16:19 ` [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions Axel Lin
@ 2015-03-29 20:14 ` Jagan Teki
  1 sibling, 0 replies; 4+ messages in thread
From: Jagan Teki @ 2015-03-29 20:14 UTC (permalink / raw)
  To: u-boot

On 20 February 2015 at 21:47, Axel Lin <axel.lin@ingics.com> wrote:
> Don't assume slave is always the first member of struct cf_spi_slave.
> Use container_of instead of casting first structure member.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/spi/cf_spi.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c
> index 879a809..7453538 100644
> --- a/drivers/spi/cf_spi.c
> +++ b/drivers/spi/cf_spi.c
> @@ -46,6 +46,11 @@ DECLARE_GLOBAL_DATA_PTR;
>  #define SPI_MODE_MOD   0x00200000
>  #define SPI_DBLRATE    0x00100000
>
> +static inline struct cf_spi_slave *to_cf_spi_slave(struct spi_slave *slave)
> +{
> +       return container_of(slave, struct cf_spi_slave, slave);
> +}
> +
>  void cfspi_init(void)
>  {
>         volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
> @@ -105,7 +110,7 @@ u16 cfspi_rx(void)
>  int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
>                void *din, ulong flags)
>  {
> -       struct cf_spi_slave *cfslave = (struct cf_spi_slave *)slave;
> +       struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
>         u16 *spi_rd16 = NULL, *spi_wr16 = NULL;
>         u8 *spi_rd = NULL, *spi_wr = NULL;
>         static u32 ctrl = 0;
> @@ -326,7 +331,9 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>
>  void spi_free_slave(struct spi_slave *slave)
>  {
> -       free(slave);
> +       struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
> +
> +       free(cfslave);
>  }
>
>  int spi_claim_bus(struct spi_slave *slave)
> --
> 1.9.1
>
>
>

Applied to u-boot-spi/master

thanks!
-- 
Jagan.

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

* [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions
  2015-02-20 16:19 ` [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions Axel Lin
@ 2015-03-29 20:14   ` Jagan Teki
  0 siblings, 0 replies; 4+ messages in thread
From: Jagan Teki @ 2015-03-29 20:14 UTC (permalink / raw)
  To: u-boot

On 20 February 2015 at 21:49, Axel Lin <axel.lin@ingics.com> wrote:
> Make local functions static and remove unneeded forward declarations.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>  drivers/spi/cf_spi.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c
> index 7453538..6ce1101 100644
> --- a/drivers/spi/cf_spi.c
> +++ b/drivers/spi/cf_spi.c
> @@ -20,13 +20,6 @@ struct cf_spi_slave {
>         int charbit;
>  };
>
> -int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
> -              void *din, ulong flags);
> -struct spi_slave *cfspi_setup_slave(struct cf_spi_slave *cfslave, uint mode);
> -void cfspi_init(void);
> -void cfspi_tx(u32 ctrl, u16 data);
> -u16 cfspi_rx(void);
> -
>  extern void cfspi_port_conf(void);
>  extern int cfspi_claim_bus(uint bus, uint cs);
>  extern void cfspi_release_bus(uint bus, uint cs);
> @@ -51,7 +44,7 @@ static inline struct cf_spi_slave *to_cf_spi_slave(struct spi_slave *slave)
>         return container_of(slave, struct cf_spi_slave, slave);
>  }
>
> -void cfspi_init(void)
> +static void cfspi_init(void)
>  {
>         volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
>
> @@ -89,7 +82,7 @@ void cfspi_init(void)
>  #endif
>  }
>
> -void cfspi_tx(u32 ctrl, u16 data)
> +static void cfspi_tx(u32 ctrl, u16 data)
>  {
>         volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
>
> @@ -98,7 +91,7 @@ void cfspi_tx(u32 ctrl, u16 data)
>         dspi->tfr = (ctrl | data);
>  }
>
> -u16 cfspi_rx(void)
> +static u16 cfspi_rx(void)
>  {
>         volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
>
> @@ -107,8 +100,8 @@ u16 cfspi_rx(void)
>         return (dspi->rfr & 0xFFFF);
>  }
>
> -int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
> -              void *din, ulong flags)
> +static int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
> +                     void *din, ulong flags)
>  {
>         struct cf_spi_slave *cfslave = to_cf_spi_slave(slave);
>         u16 *spi_rd16 = NULL, *spi_wr16 = NULL;
> @@ -181,7 +174,8 @@ int cfspi_xfer(struct spi_slave *slave, uint bitlen, const void *dout,
>         return 0;
>  }
>
> -struct spi_slave *cfspi_setup_slave(struct cf_spi_slave *cfslave, uint mode)
> +static struct spi_slave *cfspi_setup_slave(struct cf_spi_slave *cfslave,
> +                                          uint mode)
>  {
>         /*
>          * bit definition for mode:
> --
> 1.9.1
>
>
>

Applied to u-boot-spi/master

thanks!
-- 
Jagan.

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

end of thread, other threads:[~2015-03-29 20:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-20 16:17 [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Axel Lin
2015-02-20 16:19 ` [U-Boot] [PATCH 2/2] spi: cf_spi: Staticize local functions Axel Lin
2015-03-29 20:14   ` Jagan Teki
2015-03-29 20:14 ` [U-Boot] [PATCH 1/2] spi: cf_spi: Use to_cf_spi_slave to resolve cfslave from slave Jagan Teki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.