lkml.org 
[lkml]   [2011]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2 02/11] msm: Generalize timer register mappings
Date
On Mon, Jan 24 2011, Daniel Walker wrote:

> On Mon, 2011-01-24 at 14:44 -0800, David Brown wrote:
>> On Mon, Jan 24 2011, Daniel Walker wrote:
>>
>> > On Wed, 2011-01-19 at 12:25 -0800, David Brown wrote:
>> >> + int global_offset = 0;
>> >> +
>> >> + if (cpu_is_msm7x01()) {
>> >> + msm_clocks[MSM_CLOCK_GPT].regbase = MSM_CSR_BASE;
>> >> + msm_clocks[MSM_CLOCK_DGT].regbase = MSM_CSR_BASE + 0x10;
>> >> + } else if (cpu_is_msm7x30()) {
>> >> + msm_clocks[MSM_CLOCK_GPT].regbase = MSM_CSR_BASE + 0x04;
>> >> + msm_clocks[MSM_CLOCK_DGT].regbase = MSM_CSR_BASE + 0x24;
>> >> + } else if (cpu_is_qsd8x50()) {
>> >> + msm_clocks[MSM_CLOCK_GPT].regbase = MSM_CSR_BASE;
>> >> + msm_clocks[MSM_CLOCK_DGT].regbase = MSM_CSR_BASE + 0x10;
>> >> + } else if (cpu_is_msm8x60()) {
>> >> + msm_clocks[MSM_CLOCK_GPT].regbase = MSM_TMR_BASE + 0x04;
>> >> + msm_clocks[MSM_CLOCK_DGT].regbase = MSM_TMR_BASE + 0x24;
>> >> +
>> >> + /* Use CPU0's timer as the global timer. */
>> >> + global_offset = MSM_TMR0_BASE - MSM_TMR_BASE;
>> >> + } else
>> >> + BUG();
>> >
>> > Ifdef's here would be OK I think, your already using the "runtime"
>> > checks ..
>>
>> The point of the change is to get rid of the ifdefs so that we can
>> dynamically detect which target we are on. Yes, there are other places
>> where it doesn't work, but we'll get there gradually.
>
> I'm not suggesting you do something you can't do right now ..
>
> For instance you could make,
>
> #define MSM_MSM7XXX_DGT_BASE (MSM_TMR_BASE + 0x10)
>
> and use that instead of what you have above.

I did it this way intentionally.

I don't see how adding an extra level of indirection to the name helps
make it any clearer. The register offsets are defined in only one
place, right in this block of code. It is obvious which target and
which register is which. Having an extra name defined somewhere else
just gives me another symbol I have to follow when I'm trying to read
the code later.

Avoiding magic numbers is fine in the code, when it actually helps.
Here, it doesn't do anything other than add a name that only gets used
once in a context that already describes what it is.

David

--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.


\
 
 \ /
  Last update: 2011-01-25 00:23    [W:0.107 / U:0.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site