Re: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 30, 2016 at 12:41 PM, Joe Perches <joe@xxxxxxxxxxx> wrote:
> On Fri, 2016-09-30 at 12:06 -0700, Guenter Roeck wrote:
>> On Thu, Sep 29, 2016 at 11:37 PM, Jun Li <jun.li@xxxxxxx> wrote:
> []
>> > diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> []
>> > +#define PDO_VAR(min_mv, max_mv, max_ma)                                      \
>> > +     ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) |                             \
>> > +      ((((min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) <<                  \
>> > +       PDO_VAR_MIN_VOLT_SHIFT) |                                     \
>> > +      ((((max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) <<                  \
>> > +       PDO_VAR_MAX_VOLT_SHIFT) |                                     \
>> > +      ((((max_ma) / 50) & PDO_VAR_MAX_CURR_MASK) <<                  \
>>
>>
>> ((((max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) <<                  \
>
> This would be easier to read if laid out differently.
>
> #define PDO_VAR(min_mv, max_mv, max_ma)                                                 \
>         ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) |                                             \
>          ((((min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) << PDO_VAR_MIN_VOLT_SHIFT) |        \
>          ((((max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) << PDO_VAR_MAX_VOLT_SHIFT) |        \
>          ((((max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) << PDO_VAR_MAX_CURR_SHIFT))
>

Code now looks as follows.

#define PDO_VAR_MIN_VOLT(mv) ((((mv) / 50) & PDO_VAR_MIN_VOLT_MASK) << \
                              PDO_VAR_MIN_VOLT_SHIFT)
#define PDO_VAR_MAX_VOLT(mv) ((((mv) / 50) & PDO_VAR_MAX_VOLT_MASK) << \
                              PDO_VAR_MAX_VOLT_SHIFT)
#define PDO_VAR_MAX_CURR(ma) ((((ma) / 10) & PDO_VAR_MAX_CURR_MASK) << \
                              PDO_VAR_MAX_CURR_SHIFT)

#define PDO_VAR(min_mv, max_mv, max_ma)                         \
        (PDO_TYPE(PDO_TYPE_VAR) | PDO_VAR_MIN_VOLT(min_mv) |    \
         PDO_VAR_MAX_VOLT(max_mv) | PDO_VAR_MAX_CURR(max_ma))

Though maybe I should just ignore line length limits or use shorter defines.

Guenter
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux