> Anyway, I have a different idea... completely abstract mailboxes from the
> caller. The mailbox content can be large and the caller is barely interested
> in all registers from the mailbox but this could be resolved this way:
> 
> The proposed API e.g for Ref mailbox:
> 
> int zl3073x_mb_ref_read(struct zl3073x_dev *zldev, u8 index,
>                         struct zl3073x_mb_ref *mb);
> int zl3073x_mb_ref_write(struct zl3073x_dev *zldev, u8 index,
>                          struct zl3073x_mb_ref *mb);
> 
> struct zl3073x_mb_ref {
>       u32     flags;
>       u16     freq_base;
>       u16     freq_mult;
>       u16     ratio_m;
>       u16     ratio_n;
>       u8      config;
>       u64     phase_offset_compensation;
>       u8      sync_ctrl;
>       u32     esync_div;
> }
> 
> #define ZL3073X_MB_REF_FREQ_BASE                      BIT(0)
> #define ZL3073X_MB_REF_FREQ_MULT                      BIT(1)
> #define ZL3073X_MB_REF_RATIO_M                                BIT(2)
> #define ZL3073X_MB_REF_RATIO_N                                BIT(3)
> #define ZL3073X_MB_REF_CONFIG                         BIT(4)
> #define ZL3073X_MB_REF_PHASE_OFFSET_COMPENSATION      BIT(5)
> #define ZL3073X_MB_REF_SYNC_CTRL                      BIT(6)
> #define ZL3073X_MB_REF_ESYNC_DIV                      BIT(7)
> 
> Then a reader can read this way (read freq and ratio of 3rd ref):
> {
>       struct zl3073x_mb_ref mb;
>       ...
>       mb.flags = ZL3073X_MB_REF_FREQ_BASE |
>                  ZL3073X_MB_REF_FREQ_MULT |
>                  ZL3073X_MB_REF_RATIO_M |
>                  ZL3073X_MB_REF_RATIO_N;
>       rc = zl3073x_mb_ref_read(zldev, 3, &mb);
>       if (rc)
>               return rc;
>       /* at this point mb fields requested via flags are filled */
> }
> A writer similarly (write config of 5th ref):
> {
>       struct zl3073x_mb_ref mb;
>       ...
>       mb.flags = ZL3073X_MB_REF_CONFIG;
>       mb.config = FIELD_PREP(SOME_MASK, SOME_VALUE);
>       rc = zl3073x_mb_ref_write(zldev, 5, &mb);
>       ...
>       /* config of 5th ref was commited */
> }
> 
> The advantages:
> * no explicit locking required from the callers
> * locking is done inside mailbox API
> * each mailbox type can have different mutex so multiple calls for
>   different mailbox types (e.g ref & output) can be done in parallel
> 
> WDYT about this approach?

I would say this is actually your next layer on top of the basic
mailbox API. This makes it more friendly to your sub driver and puts
all the locking in one place where it can easily be reviewed.

One question would be, where does this code belong. Is it in the MFD,
or in the subdrivers? I guess it is in the subdrivers.

        Andrew

Reply via email to