Skip to contentSkip to conversation

drivers: PMC MSP71xx LED driver

PATCH Marc St-Jean 2 participants 2 messages Mar 9, 2007 – Mar 10, 2007 MIPS

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · Andrew Morton
Quoted 1 line

On Mon, 26 Feb 2007 17:48:55 -0600 Marc St-Jean

Quoted 6 lines · <[email protected]> wrote:

[PATCH] drivers: PMC MSP71xx LED driver

Patch to add LED driver for the PMC-Sierra MSP71xx devices.

This patch references some platform support files previously submitted to the [email protected] list.

Thanks for the feedback Andrew, I've implemented your recommendations. A few comments/answers below.

[...]

Quoted 6 lines
Quoted 1 line

+ /* determine the progress into the current cycle, relative to

the POLL_PERIOD */

Review

Quoted 4 lines
(quoted diff) +4 -0
+     initialPeriod = (u8)(*ledRegPtr >> MSP_LED_INITIALPERIOD_SHIFT);
+     finalPeriod = (u8)(*ledRegPtr >> MSP_LED_FINALPERIOD_SHIFT);
+     ledTimeOut = (u8)(*ledRegPtr >> MSP_LED_WATCHDOG_SHIFT);
+     timer = (u8)(private_msp_led_register[ledId] >> 
Quoted 7 lines

MSP_LED_WATCHDOG_SHIFT);

I assume all these (u8) casts are unneeded.

Quoted 1 line

+ totalPeriod = (u16)initialPeriod + (u16)finalPeriod;

And here.

I assume the author didn't expect the integer promotion to occur until after the addition.

[...]

Quoted 10 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+{
+     int pin;
+     u8 currDirectionBits, currDataBits, prevDataBits, 

prevDirectionBits;

Quoted 1 line

+ currDirectionBits = currDataBits = prevDataBits =

prevDirectionBits = 0;

The unneeded initialisations here are just to suppress the incorrect gcc warning, yes?

No, initialization is needed as they are passed by reference to functions setting/clearing bits.

Quoted 10 lines

If so, that should at least be comented. And try to avoid declarations o this form as well as multiple assignments. So you want:

        u8 curr_direction_bits = 0;     /* Suppress gcc warning */
        u8 curr_data_bits = 0;          /* Suppress gcc warning */
        u8 prev_data_bits = 0;          /* Suppress gcc warning */
        u8 prev_direction_bits = 0;     /* Suppress gcc warning */

the initialisation does cause extra ode to be generated and we usually just let te warning come out. I think later gcc's fixed it.

OK, I've split them on to separate line but without the comment.

[...]

Quoted 11 lines

Review

Quoted 9 lines
(quoted diff) +8 -0
+void __init pmctwiled_setup(void)
+{
+     static int called;
+     int dev;
+
+     /* check if already initialized */
+     if( called )
+             return;

This cannot happen (can it?)

Yes it can happen. Platform code can call pmctwiled_setup (that's why the function was written) before the pmctwiled_init function runs. This is so various sub-system init functions can ensure initialization has occurred before setting start-up values.

If you have an idea on a better way to accomplish this I'm all ears.

Quoted 29 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+     /* initialize LEDs to default state */
+     for( dev = 0; dev < MSP_LED_NUM_DEVICES; dev++ ) {
+             int pin;
+             pmctwiled_device[dev] = NULL;
+            
+             for( pin = 0; pin < 8; pin++ ) {
+                     int led = MSP_LED_DEVPIN(dev,pin);
+                     if (mspLedInitialInputState[dev] & (1 << pin)) 

{

Review

Quoted 4 lines
(quoted diff) +4 -0
+                             msp_led_disable(led);
+                     } else {
+                             msp_led_enable(led);
+                             if (mspLedInitialPinState[dev] & (1 << 

pin))

Quoted 14 lines
(quoted diff) +13 -0
+                                     msp_led_turn_on(led);           
 
+                             else                   
+                                     msp_led_turn_off(led);
+                     }
+                    
+                     /* Initialize the private led register memory */
+                     private_msp_led_register[led] = 0;
+             }
+     }
+    
+     /* indicate initialised */
+     called++;
+}

[...]

Quoted 10 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+typedef enum {
+     MSP_LED_INPUT = 0,
+     MSP_LED_OUTPUT,
+} msp_led_direction_t;

No typedefs, please. Convert this to

enum msp_led_direction {
        ...
};

Alright I'll change it but it wasn't mentioned in the review of the previous drivers and they've been resubmitted with some. A quick search shows several drivers typedef'ing enums with and without *_t suffixes.

Is there a new style rule or are only core kernel types allowed to use _t?

Quoted 12 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+/* Output modes */
+typedef enum {
+     MSP_LED_OFF = 0,                /* Off steady */
+     MSP_LED_ON,                             /* On steady */
+     MSP_LED_BLINK,                  /* On for initialPeriod, off 

for finalPeriod */

Quoted 1 line

+ MSP_LED_BLINK_INVERT, /* Off for initialPeriod, on for

finalPeriod */

Quoted 1 line

+} msp_led_mode_t;

Ditto.

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+/* For non-LED pins, these macros set HI and LO accordingly */
+#define msp_led_pin_hi       msp_led_turn_off
+#define msp_led_pin_lo       msp_led_turn_on

eww.

static inline wrapper functions are preferred. Write code in C, not cpp where possible.

I agree the wrappers are cleaner but don't understand how this relates to C++.

Marc

#1 lore raw
Quoted 10 lines · On Fri, 9 Mar 2007 14:20:56 -0800 Marc St-Jean <[email protected]>…
Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +4 -0
+typedef enum {
+     MSP_LED_INPUT = 0,
+     MSP_LED_OUTPUT,
+} msp_led_direction_t;

No typedefs, please. Convert this to

Quoted 8 lines
Quoted 3 lines
enum msp_led_direction {
        ...
};

Alright I'll change it but it wasn't mentioned in the review of the previous drivers and they've been resubmitted with some. A quick search shows several drivers typedef'ing enums with and without *_t suffixes.

Poeple do bad things, and it sometimes gets missed.

Quoted 2 lines

Is there a new style rule or are only core kernel types allowed to use _t?

The general rule is: no typedefs.

typedefs make sense when the underlying type can change: u64, size_t, resource_size_t, etc. We also use them for really hairy definitions like filler_t. Nothing else. Please don't use them just to save typing.

Quoted 17 lines
Quoted 17 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+/* Output modes */
+typedef enum {
+     MSP_LED_OFF = 0,                /* Off steady */
+     MSP_LED_ON,                             /* On steady */
+     MSP_LED_BLINK,                  /* On for initialPeriod, off 

for finalPeriod */

Quoted 1 line

+ MSP_LED_BLINK_INVERT, /* Off for initialPeriod, on for

finalPeriod */

Quoted 1 line

+} msp_led_mode_t;

Ditto.

Quoted 3 lines
(quoted diff) +3 -0
+/* For non-LED pins, these macros set HI and LO accordingly */
+#define msp_led_pin_hi       msp_led_turn_off
+#define msp_led_pin_lo       msp_led_turn_on
Quoted 7 lines
Quoted 4 lines

eww.

static inline wrapper functions are preferred. Write code in C, not cpp where possible.

I agree the wrappers are cleaner but don't understand how this relates to C++.

cpp == C preprocessor.

It would be better to do

/*
* nice comment goes here
*/
static inline void msp_led_pin_hi(...)

{
	msp_led_turn_off(...);
}