Blackfin: Use 8bit spi transfers for the ad1836
PATCH 1/4 Blackfin: Use 8bit spi transfers for the ad1836
Currently there is a special case for the ad1836 in the ASoC generic spi write functions, which swaps the upper and the lower byte for 4/12 transfers. This was done, because the 4/12 spi write function was added for the ad1836 for which all of the users are configured to use use 16-bit transfers. In order to be able to get rid of this special casing switch all users of ad1836 to 8-bit transfers.
Since 8-bit, no-dma transfers is the default configuration we can remove the bfin5xx_spi_chip struct for the ad1836 altogether.
--- arch/blackfin/mach-bf527/boards/ad7160eval.c | 9 --------- arch/blackfin/mach-bf527/boards/cm_bf527.c | 9 --------- arch/blackfin/mach-bf527/boards/ezkit.c | 9 --------- arch/blackfin/mach-bf533/boards/H8606.c | 8 -------- arch/blackfin/mach-bf533/boards/cm_bf533.c | 8 -------- arch/blackfin/mach-bf533/boards/ezkit.c | 8 -------- arch/blackfin/mach-bf533/boards/stamp.c | 8 -------- arch/blackfin/mach-bf537/boards/cm_bf537e.c | 8 -------- arch/blackfin/mach-bf537/boards/cm_bf537u.c | 8 -------- arch/blackfin/mach-bf537/boards/pnav10.c | 9 --------- arch/blackfin/mach-bf537/boards/stamp.c | 9 --------- arch/blackfin/mach-bf537/boards/tcm_bf537.c | 8 -------- arch/blackfin/mach-bf548/boards/ezkit.c | 9 --------- arch/blackfin/mach-bf561/boards/cm_bf561.c | 8 -------- arch/blackfin/mach-bf561/boards/ezkit.c | 9 --------- 15 files changed, 0 insertions(+), 127 deletions(-)
arch/blackfin/mach-bf527/boards/ad7160eval.c +0 -9
@@ -269,14 +269,6 @@ static struct bfin5xx_spi_chip spi_flash_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -328,7 +320,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )
arch/blackfin/mach-bf527/boards/cm_bf527.c +0 -9
@@ -367,14 +367,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -452,7 +444,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )
arch/blackfin/mach-bf527/boards/ezkit.c +0 -9
@@ -460,14 +460,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -583,7 +575,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )
arch/blackfin/mach-bf533/boards/H8606.c +0 -8
@@ -171,13 +171,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -/* Notice: for blackfin, the speed_hz is the value of register * SPI_BAUD, not the real baudrate */ static struct spi_board_info bfin_spi_board_info[]__initdata = {
@@ -212,7 +205,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 16, .bus_num = 1, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif
arch/blackfin/mach-bf533/boards/cm_bf533.c +0 -8
@@ -71,13 +71,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -116,7 +109,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif
arch/blackfin/mach-bf533/boards/ezkit.c +0 -8
@@ -222,13 +222,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_SPI_SPIDEV ) || defined(CONFIG_SPI_SPIDEV_MODULE )static struct bfin5xx_spi_chip spidev_chip_info = { .enable_dma = 0,
@@ -267,7 +260,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_SPI_SPIDEV ) || defined(CONFIG_SPI_SPIDEV_MODULE )
arch/blackfin/mach-bf533/boards/stamp.c +0 -8
@@ -184,13 +184,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_SPI_SPIDEV ) || defined(CONFIG_SPI_SPIDEV_MODULE )static struct bfin5xx_spi_chip spidev_chip_info = { .enable_dma = 0,
@@ -258,7 +251,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .bus_num = 0, .chip_select = 4, .platform_data = "ad1836", /* only includes chip name for the moment */ - .controller_data = &ad1836_spi_chip_info, .mode = SPI_MODE_3, },#endif
arch/blackfin/mach-bf537/boards/cm_bf537e.c +0 -8
@@ -73,13 +73,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -118,7 +111,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif
arch/blackfin/mach-bf537/boards/cm_bf537u.c +0 -8
@@ -74,13 +74,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -119,7 +112,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif
arch/blackfin/mach-bf537/boards/pnav10.c +0 -9
@@ -197,14 +197,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -267,7 +259,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )
arch/blackfin/mach-bf537/boards/stamp.c +0 -9
@@ -549,14 +549,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD193X ) \ || defined(CONFIG_SND_BF5XX_SOC_AD193X_MODULE ) static struct bfin5xx_spi_chip ad1938_spi_chip_info = {
@@ -1076,7 +1068,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .bus_num = 0, .chip_select = 4, .platform_data = "ad1836", /* only includes chip name for the moment */ - .controller_data = &ad1836_spi_chip_info, .mode = SPI_MODE_3, },#endif
arch/blackfin/mach-bf537/boards/tcm_bf537.c +0 -8
@@ -74,13 +74,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -119,7 +112,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif
arch/blackfin/mach-bf548/boards/ezkit.c +0 -9
@@ -1013,14 +1013,6 @@ static struct bfin5xx_spi_chip spi_flash_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_TOUCHSCREEN_AD7877 ) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE )static struct bfin5xx_spi_chip spi_ad7877_chip_info = { .enable_dma = 0,
@@ -1077,7 +1069,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 1, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_TOUCHSCREEN_AD7877 ) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE )
arch/blackfin/mach-bf561/boards/cm_bf561.c +0 -8
@@ -72,13 +72,6 @@ static struct bfin5xx_spi_chip spi_adc_chip_info = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )static struct bfin5xx_spi_chip mmc_spi_chip_info = { .enable_dma = 0,
@@ -117,7 +110,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ .bus_num = 0, .chip_select = 4, - .controller_data = &ad1836_spi_chip_info, },#endif #if defined(CONFIG_MMC_SPI ) || defined(CONFIG_MMC_SPI_MODULE )
arch/blackfin/mach-bf561/boards/ezkit.c +0 -9
@@ -275,14 +275,6 @@ static struct platform_device ezkit_flash_device = { };#endif -#if defined(CONFIG_SND_BF5XX_SOC_AD183X ) \ - || defined(CONFIG_SND_BF5XX_SOC_AD183X_MODULE ) -static struct bfin5xx_spi_chip ad1836_spi_chip_info = { - .enable_dma =0 , - .bits_per_word =16 , -}; -#endif -#if defined(CONFIG_SPI_SPIDEV ) || defined(CONFIG_SPI_SPIDEV_MODULE )static struct bfin5xx_spi_chip spidev_chip_info = { .enable_dma = 0,
@@ -337,7 +329,6 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = { .bus_num = 0, .chip_select = 4, .platform_data = "ad1836", /* only includes chip name for the moment */ - .controller_data = &ad1836_spi_chip_info, .mode = SPI_MODE_3, },#endif
Signature · 1 line
1.7.2.5
PATCH 2/4 ASoC: Do not swap upper and lower byte in snd_soc_4_12_spi_write
snd_soc_4_12_spi_write swaps the upper and the lower byte of the to be transferred data. The function was added for the ad1836, which was used in 16bit mode on the blackfin boards. In this mode the blackfin SPI core swaps the upper and the lower byte before putting them on the wire (i.e interprets the word as litte-endian), so the data had to be passed in reversed, so it would appear in correct order on the wire.
Since this behaviour not necessarily applicable to other configurations remove the special case.
The blackfin boards using the ad1836 were changed to used 8-bit mode in the previous commit.
--- sound/soc/soc-cache.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
sound/soc/soc-cache.c +2 -2
@@ -115,8 +115,8 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data, {u8 msg[2 ]; - msg[0 ] = data[1 ]; - msg[1 ] = data[0 ]; + msg[0 ] = data[0 ]; + msg[1 ] = data[1 ];return do_spi_write (control_data, msg, len); }
Signature · 1 line
1.7.2.5
PATCH 3/4 ASoC: Get rid of snd_soc_*_*_spi_write wrapper functions
In reply to Lars-Peter ClausenAll the different snd_soc_*_*_spi_write functions are nothing but mere wrappers around do_spi_write().
This patch removes them and uses do_spi_write directly as the codecs hw_write callback instead.
--- sound/soc/soc-cache.c | 108 ++----------------------------------------------- 1 files changed, 4 insertions(+), 104 deletions(-)
sound/soc/soc-cache.c +4 -104
@@ -21,7 +21,7 @@#include <trace/events/asoc.h> #if defined(CONFIG_SPI_MASTER ) -static int do_spi_write (void *control_data,const void *msg, +static int do_spi_write (void *control_data,const char *msg,int len) {struct spi_device *spi = control_data;
@@ -42,6 +42,8 @@ static int do_spi_write(void *control_data, const void *msg,return len; } +#else +#define do_spi_write NULL#endif static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,
@@ -109,21 +111,6 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,return do_hw_write (codec, reg, value, data,2 ); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_4_12_spi_write (void *control_data,const char *data, -int len) -{ -u8 msg[2 ]; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -return do_spi_write (control_data, msg, len); -} -#else -#define snd_soc_4_12_spi_write NULL -#endif -static unsigned int snd_soc_7_9_read (struct snd_soc_codec *codec,unsigned int reg) {
@@ -141,21 +128,6 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,return do_hw_write (codec, reg, value, data,2 ); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_7_9_spi_write (void *control_data,const char *data, -int len) -{ -u8 msg[2 ]; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -return do_spi_write (control_data, msg, len); -} -#else -#define snd_soc_7_9_spi_write NULL -#endif -static int snd_soc_8_8_write (struct snd_soc_codec *codec,unsigned int reg,unsigned int value) {
@@ -174,21 +146,6 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,return do_hw_read (codec, reg); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_8_8_spi_write (void *control_data,const char *data, -int len) -{ -u8 msg[2 ]; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - -return do_spi_write (control_data, msg, len); -} -#else -#define snd_soc_8_8_spi_write NULL -#endif -static int snd_soc_8_16_write (struct snd_soc_codec *codec,unsigned int reg,unsigned int value) {
@@ -207,22 +164,6 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,return do_hw_read (codec, reg); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_8_16_spi_write (void *control_data,const char *data, -int len) -{ -u8 msg[3 ]; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - msg[2 ] = data[2 ]; - -return do_spi_write (control_data, msg, len); -} -#else -#define snd_soc_8_16_spi_write NULL -#endif -#if defined(CONFIG_I2C ) || (defined(CONFIG_I2C_MODULE ) && defined(MODULE )) static unsigned int do_i2c_read(struct snd_soc_codec *codec, void *reg, int reglen,
@@ -324,22 +265,6 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,return do_hw_write (codec, reg, value, data,3 ); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_16_8_spi_write (void *control_data,const char *data, -int len) -{ -u8 msg[3 ]; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - msg[2 ] = data[2 ]; - -return do_spi_write (control_data, msg, len); -} -#else -#define snd_soc_16_8_spi_write NULL -#endif -#if defined(CONFIG_I2C ) || (defined(CONFIG_I2C_MODULE ) && defined(MODULE ))static unsigned int snd_soc_16_16_read_i2c (struct snd_soc_codec *codec,unsigned int r)
@@ -376,23 +301,6 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,return do_hw_write (codec, reg, value, data,4 ); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_16_16_spi_write (void *control_data,const char *data, -int len) -{ -u8 msg[4 ]; - - msg[0 ] = data[0 ]; - msg[1 ] = data[1 ]; - msg[2 ] = data[2 ]; - msg[3 ] = data[3 ]; - -return do_spi_write (control_data, msg, len); -} -#else -#define snd_soc_16_16_spi_write NULL -#endif -/* Primitive bulk write support for soc-cache. The data pointed to by * `data' needs to already be in the form the hardware expects * including any leading register specific data. Any data written
@@ -440,43 +348,36 @@ static struct {int addr_bits;int data_bits;int (*write)(struct snd_soc_codec *codec,unsigned int ,unsigned int ); -int (*spi_write)(void *,const char *,int );unsigned int (*read)(struct snd_soc_codec *,unsigned int );unsigned int (*i2c_read)(struct snd_soc_codec *,unsigned int ); } io_types[] = { { .addr_bits = 4, .data_bits = 12, .write = snd_soc_4_12_write, .read = snd_soc_4_12_read, - .spi_write = snd_soc_4_12_spi_write, }, { .addr_bits = 7, .data_bits = 9, .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, - .spi_write = snd_soc_7_9_spi_write, }, { .addr_bits = 8, .data_bits = 8, .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, .i2c_read = snd_soc_8_8_read_i2c, - .spi_write = snd_soc_8_8_spi_write, }, { .addr_bits = 8, .data_bits = 16, .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, .i2c_read = snd_soc_8_16_read_i2c, - .spi_write = snd_soc_8_16_spi_write, }, { .addr_bits = 16, .data_bits = 8, .write = snd_soc_16_8_write, .read = snd_soc_16_8_read, .i2c_read = snd_soc_16_8_read_i2c, - .spi_write = snd_soc_16_8_spi_write, }, { .addr_bits = 16, .data_bits = 16, .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, .i2c_read = snd_soc_16_16_read_i2c, - .spi_write = snd_soc_16_16_spi_write, }, };
@@ -537,8 +438,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,break ;case SND_SOC_SPI : -if (io_types[i].spi_write) - codec->hw_write = io_types[i].spi_write; + codec->hw_write = do_spi_write; codec->control_data = container_of(codec->dev, struct spi_device,
Signature · 1 line
1.7.2.5
Re: [PATCH 3/4] ASoC: Get rid of snd_soc_*_*_spi_write wrapper functions
2011/5/6 Lars-Peter Clausen <[email protected]>:
Quoted 4 lines
All the different snd_soc_*_*_spi_write functions are nothing but mere wrappers around
do_spi_write().
This patch removes them and usesdo_spi_writedirectly as the codecshw_writecallback instead.
i don't know whether something has changed. i remember i once wrote some callbacks due to different hardware register layout or other hardware issues.
Quoted 221 lines
Signed-off-by Lars-Peter Clausen <[email protected]>---
sound/soc/soc-cache.c | 108 ++-----------------------------------------------1 files changed, 4 insertions(+), 104 deletions(-)sound/soc/soc-cache.c +3
-102@@ -21,7 +21,7 @@ #include <trace/events/asoc.h> #if defined(CONFIG_SPI_MASTER) -static int do_spi_write (void *control_data,const void *msg, +static int do_spi_write (void *control_data,const char *msg, int len) { struct spi_device *spi = control_data;@@ -42,6 +42,8 @@ static int do_spi_write(void *control_data, const void *msg, return len; } +#else +#define do_spi_write NULL #endif static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,@@ -109,21 +111,6 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, return do_hw_write(codec, reg, value, data, 2); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_4_12_spi_write (void *control_data,const char *data, - int len) -{ - u8 msg[2]; - - msg[0] = data[0]; - msg[1] = data[1]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_4_12_spi_write NULL -#endif - static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, unsigned int reg) {@@ -141,21 +128,6 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, return do_hw_write(codec, reg, value, data, 2); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_7_9_spi_write (void *control_data,const char *data, - int len) -{ - u8 msg[2]; - - msg[0] = data[0]; - msg[1] = data[1]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_7_9_spi_write NULL -#endif - static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) {@@ -174,21 +146,6 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, return do_hw_read(codec, reg); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_8_8_spi_write (void *control_data,const char *data, - int len) -{ - u8 msg[2]; - - msg[0] = data[0]; - msg[1] = data[1]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_8_8_spi_write NULL -#endif - static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value) {@@ -207,22 +164,6 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, return do_hw_read(codec, reg); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_8_16_spi_write (void *control_data,const char *data, - int len) -{ - u8 msg[3]; - - msg[0] = data[0]; - msg[1] = data[1]; - msg[2] = data[2]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_8_16_spi_write NULL -#endif - #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) static unsigned int do_i2c_read(struct snd_soc_codec *codec, void *reg, int reglen,@@ -324,22 +265,6 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, return do_hw_write(codec, reg, value, data, 3); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_16_8_spi_write (void *control_data,const char *data, - int len) -{ - u8 msg[3]; - - msg[0] = data[0]; - msg[1] = data[1]; - msg[2] = data[2]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_16_8_spi_write NULL -#endif - #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec, unsigned int r)@@ -376,23 +301,6 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, return do_hw_write(codec, reg, value, data, 4); } -#if defined(CONFIG_SPI_MASTER ) -static int snd_soc_16_16_spi_write (void *control_data,const char *data, - int len) -{ - u8 msg[4]; - - msg[0] = data[0]; - msg[1] = data[1]; - msg[2] = data[2]; - msg[3] = data[3]; - - return do_spi_write(control_data, msg, len); -} -#else -#define snd_soc_16_16_spi_write NULL -#endif - /* Primitive bulk write support for soc-cache. The data pointed to by* `data' needs to already be in the form the hardware expects * including any leading register specific data. Any data written @@ -440,43 +348,36 @@ static struct { int addr_bits; int data_bits; int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); - int (*spi_write)(void *, const char *, int); unsigned int (*read)(struct snd_soc_codec *, unsigned int); unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); } io_types[] = { { .addr_bits = 4, .data_bits = 12, .write = snd_soc_4_12_write, .read = snd_soc_4_12_read, - .spi_write = snd_soc_4_12_spi_write, }, { .addr_bits = 7, .data_bits = 9, .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, - .spi_write = snd_soc_7_9_spi_write, }, { .addr_bits = 8, .data_bits = 8, .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, .i2c_read = snd_soc_8_8_read_i2c, - .spi_write = snd_soc_8_8_spi_write, }, { .addr_bits = 8, .data_bits = 16, .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, .i2c_read = snd_soc_8_16_read_i2c, - .spi_write = snd_soc_8_16_spi_write, }, { .addr_bits = 16, .data_bits = 8, .write = snd_soc_16_8_write, .read = snd_soc_16_8_read, .i2c_read = snd_soc_16_8_read_i2c, - .spi_write = snd_soc_16_8_spi_write, }, { .addr_bits = 16, .data_bits = 16, .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, .i2c_read = snd_soc_16_16_read_i2c, - .spi_write = snd_soc_16_16_spi_write, }, };@@ -537,8 +438,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, break;case
SND_SOC_SPI:
- if (io_types[i].spi_write)
-codec->hw_write= io_types[i].spi_write;
+codec->hw_write=do_spi_write;codec->control_data = container_of(codec->dev, struct
spi_device, --
1.7.2.5
Quoted 5 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
PATCH 4/4 ASoC: Use spi_write in do_spi_write
In reply to Lars-Peter ClausenInstead of open-coding the spi transfer use spi_write.
--- sound/soc/soc-cache.c | 14 ++++---------- 1 files changed, 4 insertions(+), 10 deletions(-)
sound/soc/soc-cache.c +4 -10
@@ -25,20 +25,14 @@ static int do_spi_write(void *control_data, const char *msg, int len) {struct spi_device *spi = control_data; -struct spi_transfer t; -struct spi_message m; +int ret;if (len <=0 )return 0 ; -spi_message_init (&m); -memset (&t,0 ,sizeof t); - - t.tx_buf = msg; - t.len = len; - -spi_message_add_tail (&t, &m); -spi_sync (spi, &m); + ret =spi_write (spi, msg, len); +if (ret <0 ) +return ret;return len; }
Signature · 1 line
1.7.2.5
Quoted 6 lines · Lars-Peter Clausen
Currently there is a special case for the ad1836 in the ASoC generic spi write functions, which swaps the upper and the lower byte for 4/12 transfers. This was done, because the 4/12 spi write function was added for the ad1836 for which all of the users are configured to use use 16-bit transfers. In order to be able to get rid of this special casing switch all users of ad1836 to 8-bit transfers.
16bit spi transfers are inherently less overhead than 8bit transfers. so if the codec supports it, we should use it rather than drop 16bit support everywhere because 8bit is simpler. am i missing something obvious ?
-mike
Quoted 8 lines · Mike Frysinger
Quoted 6 lines · Lars-Peter Clausen
Currently there is a special case for the ad1836 in the ASoC generic spi write functions, which swaps the upper and the lower byte for 4/12 transfers. This was done, because the 4/12 spi write function was added for the ad1836 for which all of the users are configured to use use 16-bit transfers. In order to be able to get rid of this special casing switch all users of ad1836 to 8-bit transfers.
Quoted 5 lines
16bit spi transfers are inherently less overhead than 8bit transfers. so if the codec supports it, we should use it rather than drop 16bit support everywhere because 8bit is simpler. am i missing something obvious ?
-mike
At some point the codec driver used u16 for the type of the data to be transferred, so 16bit transfers where fine then.
But at some point the driver was updated to use the snd_soc_cache infrastructure, which uses a u8[2] array for the data to be transferred.
The snd_soc_cache infrastructure has several helper functions for writing spi on a spi bus. The one used by the ad1836 was specifically added for the ad1836 and is special compared to the other spi helper functions in the regard that it swaps the upper and the lower byte of the to be transferred data. While this works on blackfin which is litte-endian this scheme will obviously fail on big-endian machines. Also this might not work for other codecs which want to reuse the same helper function.
And furthermore it disallows more generalization of the spi write functions in snd_soc_cache, which is done in the follow-up patches.
If we wanted to use 16-bit spi transfers we would have to add something generic to the do_spi_write function, which swaps the upper and the lower byte of each short to be transferred if the host is little-endian.
- Lars
Quoted 7 lines · Lars-Peter Clausen
The
snd_soc_cacheinfrastructure has several helper functions for writing spi on a spi bus. The one used by the ad1836 was specifically added for the ad1836 and is special compared to the other spi helper functions in the regard that it swaps the upper and the lower byte of the to be transferred data. While this works on blackfin which is litte-endian this scheme will obviously fail on big-endian machines. Also this might not work for other codecs which want to reuse the same helper function.
So clearly the cache stuff ought to be using cpu_to_be16 for this stuff. At present we've been lazy about this as on most CPUs the swap boils down to a noop. If we do end up needing both swaps then we just add this as another parameter in the cache infrastructure.
Quoted 9 lines · Mark Brown
Quoted 7 lines · Lars-Peter Clausen
The
snd_soc_cacheinfrastructure has several helper functions for writing spi on a spi bus. The one used by the ad1836 was specifically added for the ad1836 and is special compared to the other spi helper functions in the regard that it swaps the upper and the lower byte of the to be transferred data. While this works on blackfin which is litte-endian this scheme will obviously fail on big-endian machines. Also this might not work for other codecs which want to reuse the same helper function.
Quoted 4 lines
So clearly the cache stuff ought to be using
cpu_to_be16for this stuff. At present we've been lazy about this as on most CPUs the swap boils down to a noop. If we do end up needing both swaps then we just add this as another parameter in the cache infrastructure.
indeed ... this is the direction i'd rather head rather than drop all the existing stuff down to 8bit only.
-mike
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 10 lines · Mark Brown
Quoted 7 lines · Lars-Peter Clausen
The
snd_soc_cacheinfrastructure has several helper functions for writing spi on a spi bus. The one used by the ad1836 was specifically added for the ad1836 and is special compared to the other spi helper functions in the regard that it swaps the upper and the lower byte of the to be transferred data. While this works on blackfin which is litte-endian this scheme will obviously fail on big-endian machines. Also this might not work for other codecs which want to reuse the same helper function.
Quoted 4 lines
So clearly the cache stuff ought to be using
cpu_to_be16for this stuff. At present we've been lazy about this as on most CPUs the swap boils down to a noop. If we do end up needing both swaps then we just add this as another parameter in the cache infrastructure.
Currently everything is stored as big endian.
The easiest way to support 16-bit spi writes on little endian systems, would be to add a do_spi_write16 which would be used for those devices. On big-endian systems it would be an alias to do_spi_write, on litte-endian systems it would perform a byte swap on the buffer.
An alternative would be to provide litte-endian versions of snd_soc_x_y_write. This would amount to more code, but less runtime overhead since we can store it in litte-endian format right away instead of having to swap the bytes.
- Lars
Quoted 8 lines · Lars-Peter Clausen
Quoted 4 lines · Mark Brown
So clearly the cache stuff ought to be using
cpu_to_be16for this stuff. At present we've been lazy about this as on most CPUs the swap boils down to a noop. If we do end up needing both swaps then we just add this as another parameter in the cache infrastructure.Currently everything is stored as big endian.
What do you mean? The cache is CPU native.
Quoted 8 lines
The easiest way to support 16-bit spi writes on little endian systems, would be to add a
do_spi_write16which would be used for those devices. On big-endian systems it would be an alias todo_spi_write, on litte-endian systems it would perform a byte swap on the buffer.An alternative would be to provide litte-endian versions of
snd_soc_x_y_write. This would amount to more code, but less runtime overhead since we can store it in litte-endian format right away instead of having to swap the bytes.
This would also support bulk operations direct from cache.
Either of these would be an example of using cpu_to_() as I suggested.
Quoted 12 lines · Mark Brown
Quoted 8 lines · Lars-Peter Clausen
Quoted 4 lines · Mark Brown
So clearly the cache stuff ought to be using
cpu_to_be16for this stuff. At present we've been lazy about this as on most CPUs the swap boils down to a noop. If we do end up needing both swaps then we just add this as another parameter in the cache infrastructure.Currently everything is stored as big endian.
What do you mean? The cache is CPU native.
Sorry, I meant the buffer which is transmitted not the cache it-self.
- Lars