Skip to content

Commit

Permalink
fix many Linux kernel coding style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
notro committed Aug 11, 2013
1 parent f2e680d commit 3e99fae
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 272 deletions.
175 changes: 95 additions & 80 deletions fbtft-bus.c
Expand Up @@ -5,67 +5,67 @@



/**********************************************************************************
/*****************************************************************************
*
* void (*write_reg)(struct fbtft_par *par, int len, ...);
*
**********************************************************************************/

#define define_fbtft_write_reg(func, type, modifier) \
void func(struct fbtft_par *par, int len, ...) \
{ \
va_list args; \
int i, ret; \
int offset = 0; \
type *buf = (type *)par->buf; \
\
if (unlikely(par->debug & DEBUG_WRITE_DATA_COMMAND)) { \
va_start(args, len); \
for (i=0;i<len;i++) { \
buf[i] = (type)va_arg(args, unsigned int); \
} \
va_end(args); \
fbtft_par_dbg_hex(DEBUG_WRITE_DATA_COMMAND, par, par->info->device, type, buf, len, "%s: ", __func__); \
} \
\
va_start(args, len); \
\
if(par->startbyte) { \
*(u8 *)par->buf = par->startbyte; \
buf = (type *)(par->buf + 1); \
offset = 1; \
} \
\
*buf = modifier((type)va_arg(args, unsigned int)); \
if (par->gpio.dc != -1) \
gpio_set_value(par->gpio.dc, 0); \
ret = par->fbtftops.write(par, par->buf, sizeof(type)+offset); \
if (ret < 0) { \
va_end(args); \
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
return; \
} \
len--; \
\
if(par->startbyte) \
*(u8 *)par->buf = par->startbyte | 0x2; \
\
if (len) { \
i = len; \
while (i--) { \
*buf++ = modifier((type)va_arg(args, unsigned int)); \
} \
if (par->gpio.dc != -1) \
gpio_set_value(par->gpio.dc, 1); \
ret = par->fbtftops.write(par, par->buf, len * (sizeof(type)+offset)); \
if (ret < 0) { \
va_end(args); \
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
return; \
} \
} \
va_end(args); \
} \
*****************************************************************************/

#define define_fbtft_write_reg(func, type, modifier) \
void func(struct fbtft_par *par, int len, ...) \
{ \
va_list args; \
int i, ret; \
int offset = 0; \
type *buf = (type *)par->buf; \
\
if (unlikely(par->debug & DEBUG_WRITE_DATA_COMMAND)) { \
va_start(args, len); \
for (i = 0; i < len; i++) { \
buf[i] = (type)va_arg(args, unsigned int); \
} \
va_end(args); \
fbtft_par_dbg_hex(DEBUG_WRITE_DATA_COMMAND, par, par->info->device, type, buf, len, "%s: ", __func__); \
} \
\
va_start(args, len); \
\
if (par->startbyte) { \
*(u8 *)par->buf = par->startbyte; \
buf = (type *)(par->buf + 1); \
offset = 1; \
} \
\
*buf = modifier((type)va_arg(args, unsigned int)); \
if (par->gpio.dc != -1) \
gpio_set_value(par->gpio.dc, 0); \
ret = par->fbtftops.write(par, par->buf, sizeof(type)+offset); \
if (ret < 0) { \
va_end(args); \
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
return; \
} \
len--; \
\
if (par->startbyte) \
*(u8 *)par->buf = par->startbyte | 0x2; \
\
if (len) { \
i = len; \
while (i--) { \
*buf++ = modifier((type)va_arg(args, unsigned int)); \
} \
if (par->gpio.dc != -1) \
gpio_set_value(par->gpio.dc, 1); \
ret = par->fbtftops.write(par, par->buf, len * (sizeof(type)+offset)); \
if (ret < 0) { \
va_end(args); \
dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
return; \
} \
} \
va_end(args); \
} \
EXPORT_SYMBOL(func);

define_fbtft_write_reg(fbtft_write_reg8_bus8, u8, )
Expand Down Expand Up @@ -118,14 +118,15 @@ EXPORT_SYMBOL(fbtft_write_reg8_bus9);



/**********************************************************************************
/*****************************************************************************
*
* void (*write_data_command)(struct fbtft_par *par, unsigned dc, u32 val);
*
**********************************************************************************/
*****************************************************************************/

/* 8-bit register over 8-bit databus */
void fbtft_write_data_command8_bus8(struct fbtft_par *par, unsigned dc, u32 val)
void
fbtft_write_data_command8_bus8(struct fbtft_par *par, unsigned dc, u32 val)
{
int ret;

Expand All @@ -139,12 +140,15 @@ void fbtft_write_data_command8_bus8(struct fbtft_par *par, unsigned dc, u32 val)

ret = par->fbtftops.write(par, par->buf, 1);
if (ret < 0)
dev_err(par->info->device, "%s: dc=%d, val=0x%X, failed with status %d\n", __func__, dc, val, ret);
dev_err(par->info->device,
"%s: dc=%d, val=0x%X, failed with status %d\n",
__func__, dc, val, ret);
}
EXPORT_SYMBOL(fbtft_write_data_command8_bus8);

/* 8-bit register/data over 9-bit SPI: dc + 8-bit */
void fbtft_write_data_command8_bus9(struct fbtft_par *par, unsigned dc, u32 val)
void
fbtft_write_data_command8_bus9(struct fbtft_par *par, unsigned dc, u32 val)
{
int ret;

Expand All @@ -155,11 +159,14 @@ void fbtft_write_data_command8_bus9(struct fbtft_par *par, unsigned dc, u32 val)

ret = par->fbtftops.write(par, par->buf, 2);
if (ret < 0)
dev_err(par->info->device, "%s: dc=%d, val=0x%X, failed with status %d\n", __func__, dc, val, ret);
dev_err(par->info->device,
"%s: dc=%d, val=0x%X, failed with status %d\n",
__func__, dc, val, ret);
}
EXPORT_SYMBOL(fbtft_write_data_command8_bus9);

void fbtft_write_data_command16_bus16(struct fbtft_par *par, unsigned dc, u32 val)
void
fbtft_write_data_command16_bus16(struct fbtft_par *par, unsigned dc, u32 val)
{
int ret;

Expand All @@ -173,11 +180,14 @@ void fbtft_write_data_command16_bus16(struct fbtft_par *par, unsigned dc, u32 va

ret = par->fbtftops.write(par, par->buf, 2);
if (ret < 0)
dev_err(par->info->device, "%s: dc=%d, val=0x%X, failed with status %d\n", __func__, dc, val, ret);
dev_err(par->info->device,
"%s: dc=%d, val=0x%X, failed with status %d\n",
__func__, dc, val, ret);
}
EXPORT_SYMBOL(fbtft_write_data_command16_bus16);

void fbtft_write_data_command16_bus8(struct fbtft_par *par, unsigned dc, u32 val)
void
fbtft_write_data_command16_bus8(struct fbtft_par *par, unsigned dc, u32 val)
{
int ret;
unsigned offset = 0;
Expand All @@ -199,18 +209,20 @@ void fbtft_write_data_command16_bus8(struct fbtft_par *par, unsigned dc, u32 val
*(u16 *)(par->buf + offset) = cpu_to_be16((u16)val);
ret = par->fbtftops.write(par, par->buf, 2 + offset);
if (ret < 0)
dev_err(par->info->device, "%s: dc=%d, val=0x%X, failed with status %d\n", __func__, dc, val, ret);
dev_err(par->info->device,
"%s: dc=%d, val=0x%X, failed with status %d\n",
__func__, dc, val, ret);
}
EXPORT_SYMBOL(fbtft_write_data_command16_bus8);




/**********************************************************************************
/*****************************************************************************
*
* int (*write_vmem)(struct fbtft_par *par);
*
**********************************************************************************/
*****************************************************************************/

/* 16 bit pixel over 8-bit databus */
int fbtft_write_vmem16_bus8(struct fbtft_par *par)
Expand All @@ -236,11 +248,11 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par)
if (par->gpio.dc != -1)
gpio_set_value(par->gpio.dc, 1);

// non buffered write
/* non buffered write */
if (!par->txbuf.buf)
return par->fbtftops.write(par, vmem16, len);

// buffered write
/* buffered write */
tx_array_size = par->txbuf.len / 2;

if (par->startbyte) {
Expand All @@ -252,13 +264,15 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par)

while (remain) {
to_copy = remain > tx_array_size ? tx_array_size : remain;
dev_dbg(par->info->device, " to_copy=%d, remain=%d\n", to_copy, remain - to_copy);
dev_dbg(par->info->device, " to_copy=%d, remain=%d\n",
to_copy, remain - to_copy);

for (i=0;i<to_copy;i++)
for (i = 0; i < to_copy; i++)
txbuf16[i] = cpu_to_be16(vmem16[i]);

vmem16 = vmem16 + to_copy;
ret = par->fbtftops.write(par, par->txbuf.buf, startbyte_size + to_copy*2);
ret = par->fbtftops.write(par, par->txbuf.buf,
startbyte_size + to_copy * 2);
if (ret < 0)
return ret;
remain -= to_copy;
Expand All @@ -273,7 +287,7 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par)
{
u8 *vmem8;
u16 *txbuf16 = par->txbuf.buf;
size_t remain;
size_t remain;
size_t to_copy;
size_t tx_array_size;
int i;
Expand All @@ -297,15 +311,16 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par)

while (remain) {
to_copy = remain > tx_array_size ? tx_array_size : remain;
dev_dbg(par->info->device, " to_copy=%d, remain=%d\n", to_copy, remain - to_copy);
dev_dbg(par->info->device, " to_copy=%d, remain=%d\n",
to_copy, remain - to_copy);

#ifdef __LITTLE_ENDIAN
for (i=0;i<to_copy;i+=2) {
for (i = 0; i < to_copy; i += 2) {
txbuf16[i] = 0x0100 | vmem8[i+1];
txbuf16[i+1] = 0x0100 | vmem8[i];
}
#else
for (i=0;i<to_copy;i++)
for (i = 0; i < to_copy; i++)
txbuf16[i] = 0x0100 | vmem8[i];
#endif
vmem8 = vmem8 + to_copy;
Expand Down Expand Up @@ -342,7 +357,7 @@ int fbtft_write_vmem16_bus16(struct fbtft_par *par)
if (par->gpio.dc != -1)
gpio_set_value(par->gpio.dc, 1);

// no need for buffered write with 16-bit bus
/* no need for buffered write with 16-bit bus */
return par->fbtftops.write(par, vmem16, len);
}
EXPORT_SYMBOL(fbtft_write_vmem16_bus16);

0 comments on commit 3e99fae

Please sign in to comment.