All of lore.kernel.org
 help / color / mirror / Atom feed
* Coding style question
@ 2007-02-09 10:32 Pavel Pisa
  2007-02-09 11:18 ` Jesper Juhl
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Pavel Pisa @ 2007-02-09 10:32 UTC (permalink / raw)
  To: Russell King - ARM Linux, linux-kernel; +Cc: Sascha Hauer, Pierre Ossman

Hello All,

I have question if next style of macros definitions
for hardware registers is acceptable (tastefull for
maintainers) for Linux kernel.

/* Register offset against peripheral base */
#define SUBSYSTEM_REGISTER_o 0x00000

/* The register field mask */
#define REGISTER_FUNCTION_m 0x00000

/* The register field starting bit */
#define REGISTER_FUNCTION_b 0x00

I am used to use this over many of our embedded
targets mainly developed without operating system.
I would like to use this for Linux drivers as well.

The naming convention has advantage, that it
prevents mistakes, when mask value (*_m) is used
in bit set/clear function without notice instead
of bitnumber (*_b).

The SUBSYSTEM_REGISTER -> REGISTER_FUNCTION
prevents mistakes, when field defined for one register
is used with incorrect register by mistake.

I would like to use this style in i.MX SDHC to
allow support both controllers on MX21.
I would like to use it in other areas as well.

There are tightly copled two macros for preparation
and acquisition of muti-bit masked fields values

#define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask))

#define __mfld2val(mask,val) (((val)&(mask))/((mask)&~((mask)<<1)))

__raw_writel(REGISTER_SINGLEBIT_m |
             __val2mfld(REGISTER_MULTIBIT_m,value),
             periph_base + SUBSYSTEM_REGISTER_o)

x = __mfld2val(REGISTER_MULTIBIT_m,
           _raw_readl(periph_base + SUBSYSTEM_REGISTER_o))

The macros seems to be complicated, but they generate optimal
code for constant fields masks. I am not aware, that there
is some commonly available alternative in Linux kernel
header files.

Suggestions, names corrections etc. are welcomed.
If you think, that it is not good idea to introduce
yet another style, I would try to follow actual style
found in each source file. If you prefer some already
utilized style, direct me to right examples, please.

Best wishes

              Pavel Pisa

^ permalink raw reply	[flat|nested] 13+ messages in thread
* coding style question
@ 2004-02-25 18:16 Jay Denebeim
  2004-02-25 18:25 ` Matthew Wilcox
  0 siblings, 1 reply; 13+ messages in thread
From: Jay Denebeim @ 2004-02-25 18:16 UTC (permalink / raw)
  To: linux-scsi

I've noticed that in 2.6 many of the constructs like:

typedef struct foo { blah }

have been changed to 

struct foo { blah }

what was the reasoning for this?

Thanks
Jay
-- 
* Jay Denebeim  Moderator       rec.arts.sf.tv.babylon5.moderated *
* newsgroup submission address: b5mod@deepthot.org                *
* moderator contact address:    b5mod-request@deepthot.org        *
* personal contact address:     denebeim@deepthot.org             *

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

end of thread, other threads:[~2007-02-09 20:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-09 10:32 Coding style question Pavel Pisa
2007-02-09 11:18 ` Jesper Juhl
2007-02-09 16:02 ` Stefan Richter
2007-02-09 20:46 ` Haavard Skinnemoen
  -- strict thread matches above, loose matches on Subject: below --
2004-02-25 18:16 coding " Jay Denebeim
2004-02-25 18:25 ` Matthew Wilcox
2004-02-25 18:40   ` Jay Denebeim
2004-02-25 19:29     ` Randy.Dunlap
2004-02-25 19:37       ` Jay Denebeim
2004-02-26  0:02         ` Bryan Henderson
2004-02-25 22:40     ` Patrick Mansfield
2004-02-26 16:09       ` Clay Haapala
2004-02-26  1:28     ` Jeff Garzik

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.