From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Cooper Date: Sun, 15 May 2011 22:23:26 -0400 Subject: [U-Boot] [PATCH v3 02/10] armv7: add miscellaneous utility macros In-Reply-To: References: <1299589658-30896-1-git-send-email-aneesh@ti.com> <1305202276-27784-3-git-send-email-aneesh@ti.com> <20110515184421.D7AB91491B06@gemini.denx.de> Message-ID: <20110516022326.GC6372@localhost> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Sun, May 15, 2011 at 03:15:46PM -0700, Simon Glass wrote: > I believe that this problem is getting worse - e.g. USB on Tegra2 writes > various fields of about 20 registers to get things up and running. I find > translating SOC datasheet register definitions into C code with shifts and > masks to be slow and error-prone work. Also we do need to maintain this > code, and it gets reused for new SOC variants, etc. So it is not as if it is > written once and then buried and forgotten. There is also a tendency to use > 'magic' constants rather than #define values or something with a sensible > name, then hopefully add a half-hearted comment. This requires constant > return looks at the datasheet to see what bits were chosen. I have nothing against helper functions like this (although I think they should be inline functions, not macros, to guard against bugs due to side-effects in arguments). But wouldn't it be even better to define the registers as C structures containing bitfields, so the C compiler can do the error-prone shifting and masking? Well-commented structure definitions for these registers also eliminate the need to refer back to the datasheet when working on the code. -- Eric Cooper e c c @ c m u . e d u