* [PATCH] staging: sm750fb: Simplify M2XCLK divisor encoding
@ 2026-10-18 9:26 himanshu bakshi
2026-10-23 13:36 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: himanshu bakshi @ 2026-10-18 9:26 UTC (permalink / raw)
To: sudipm.mukherjee, teddy.wang
Cc: gregkh, linux-fbdev, linux-staging, linux-kernel, himanshu bakshi
Replace the switch statement with a macro to encode the M2XCLK
divisor in the corresponding register bits.
This is my first Linux kernel patch.
Signed-off-by: himanshu bakshi <himanshu.bakshi478@gmail.com>
---
drivers/staging/sm750fb/ddk750_chip.c | 18 +++---------------
drivers/staging/sm750fb/ddk750_reg.h | 5 +----
2 files changed, 4 insertions(+), 19 deletions(-)
diff --git a/drivers/staging/sm750fb/ddk750_chip.c b/drivers/staging/sm750fb/ddk750_chip.c
index aa78d0bc1..2cb849dea 100644
--- a/drivers/staging/sm750fb/ddk750_chip.c
+++ b/drivers/staging/sm750fb/ddk750_chip.c
@@ -109,21 +109,9 @@ static void set_memory_clock(unsigned int frequency)
/* Set the corresponding divisor in the register. */
reg = peek32(CURRENT_GATE) & ~CURRENT_GATE_M2XCLK_MASK;
- switch (divisor) {
- default:
- case 1:
- reg |= CURRENT_GATE_M2XCLK_DIV_1;
- break;
- case 2:
- reg |= CURRENT_GATE_M2XCLK_DIV_2;
- break;
- case 3:
- reg |= CURRENT_GATE_M2XCLK_DIV_3;
- break;
- case 4:
- reg |= CURRENT_GATE_M2XCLK_DIV_4;
- break;
- }
+ if (divisor == 0 || divisor > 4)
+ divisor = 1;
+ reg |= CURRENT_GATE_M2XCLK_DIV(divisor);
sm750_set_current_gate(reg);
}
diff --git a/drivers/staging/sm750fb/ddk750_reg.h b/drivers/staging/sm750fb/ddk750_reg.h
index fe412ead7..b796e32ab 100644
--- a/drivers/staging/sm750fb/ddk750_reg.h
+++ b/drivers/staging/sm750fb/ddk750_reg.h
@@ -312,10 +312,7 @@
#define CURRENT_GATE_M2XCLK_112MHZ (0x2 << 12)
#define CURRENT_GATE_M2XCLK_84MHZ (0x3 << 12)
#else
- #define CURRENT_GATE_M2XCLK_DIV_1 (0x0 << 12)
- #define CURRENT_GATE_M2XCLK_DIV_2 (0x1 << 12)
- #define CURRENT_GATE_M2XCLK_DIV_3 (0x2 << 12)
- #define CURRENT_GATE_M2XCLK_DIV_4 (0x3 << 12)
+ #define CURRENT_GATE_M2XCLK_DIV(divisor) (((divisor) - 1) << 12)
#endif
#define CURRENT_GATE_VGA BIT(10)
#define CURRENT_GATE_PWM BIT(9)
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] staging: sm750fb: Simplify M2XCLK divisor encoding
2026-10-18 9:26 [PATCH] staging: sm750fb: Simplify M2XCLK divisor encoding himanshu bakshi
@ 2026-10-23 13:36 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-10-23 13:36 UTC (permalink / raw)
To: himanshu bakshi
Cc: sudipm.mukherjee, teddy.wang, linux-fbdev, linux-staging,
linux-kernel
On Sun, Oct 18, 2026 at 02:56:51PM +0530, himanshu bakshi wrote:
> Replace the switch statement with a macro to encode the M2XCLK
> divisor in the corresponding register bits.
Why?
> This is my first Linux kernel patch.
Great, but that doesn't need to be in the changelog :)
> Signed-off-by: himanshu bakshi <himanshu.bakshi478@gmail.com>
Capital letters please.
> ---
> drivers/staging/sm750fb/ddk750_chip.c | 18 +++---------------
> drivers/staging/sm750fb/ddk750_reg.h | 5 +----
> 2 files changed, 4 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/staging/sm750fb/ddk750_chip.c b/drivers/staging/sm750fb/ddk750_chip.c
> index aa78d0bc1..2cb849dea 100644
> --- a/drivers/staging/sm750fb/ddk750_chip.c
> +++ b/drivers/staging/sm750fb/ddk750_chip.c
> @@ -109,21 +109,9 @@ static void set_memory_clock(unsigned int frequency)
>
> /* Set the corresponding divisor in the register. */
> reg = peek32(CURRENT_GATE) & ~CURRENT_GATE_M2XCLK_MASK;
> - switch (divisor) {
> - default:
> - case 1:
> - reg |= CURRENT_GATE_M2XCLK_DIV_1;
> - break;
> - case 2:
> - reg |= CURRENT_GATE_M2XCLK_DIV_2;
> - break;
> - case 3:
> - reg |= CURRENT_GATE_M2XCLK_DIV_3;
> - break;
> - case 4:
> - reg |= CURRENT_GATE_M2XCLK_DIV_4;
> - break;
> - }
> + if (divisor == 0 || divisor > 4)
> + divisor = 1;
> + reg |= CURRENT_GATE_M2XCLK_DIV(divisor);
>
> sm750_set_current_gate(reg);
> }
> diff --git a/drivers/staging/sm750fb/ddk750_reg.h b/drivers/staging/sm750fb/ddk750_reg.h
> index fe412ead7..b796e32ab 100644
> --- a/drivers/staging/sm750fb/ddk750_reg.h
> +++ b/drivers/staging/sm750fb/ddk750_reg.h
> @@ -312,10 +312,7 @@
> #define CURRENT_GATE_M2XCLK_112MHZ (0x2 << 12)
> #define CURRENT_GATE_M2XCLK_84MHZ (0x3 << 12)
> #else
> - #define CURRENT_GATE_M2XCLK_DIV_1 (0x0 << 12)
> - #define CURRENT_GATE_M2XCLK_DIV_2 (0x1 << 12)
> - #define CURRENT_GATE_M2XCLK_DIV_3 (0x2 << 12)
> - #define CURRENT_GATE_M2XCLK_DIV_4 (0x3 << 12)
> + #define CURRENT_GATE_M2XCLK_DIV(divisor) (((divisor) - 1) << 12)
The original is more descriptive of the hardware data sheet, right?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-23 15:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-18 9:26 [PATCH] staging: sm750fb: Simplify M2XCLK divisor encoding himanshu bakshi
2026-10-23 13:36 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox