Re: [DO NOT MERGE v6 23/37] mfd: sm501: Convert platform_data to OF property

2024-01-11 Thread Lee Jones
On Tue, 09 Jan 2024, Yoshinori Sato wrote:

> Various parameters of SM501 can be set using platform_data,
> so parameters cannot be passed in the DeviceTree target.
> Expands the parameters set in platform_data so that they can be
> specified using DeviceTree properties.
> 
> Signed-off-by: Yoshinori Sato 
> ---
>  drivers/mfd/sm501.c   | 436 ++

How has this grown from 99 lines to 436 lines?

Most of it almost certainly needs moving (back?) out to the leaf
drivers.  A great deal of the properties parsed in here are only
relevant to a single device (display for instance).  Please move all
non-generic handling out to the relevant subsystems.

>  drivers/video/fbdev/sm501fb.c | 106 +
>  2 files changed, 542 insertions(+)

-- 
Lee Jones [李琼斯]


[DO NOT MERGE v6 23/37] mfd: sm501: Convert platform_data to OF property

2024-01-09 Thread Yoshinori Sato
Various parameters of SM501 can be set using platform_data,
so parameters cannot be passed in the DeviceTree target.
Expands the parameters set in platform_data so that they can be
specified using DeviceTree properties.

Signed-off-by: Yoshinori Sato 
---
 drivers/mfd/sm501.c   | 436 ++
 drivers/video/fbdev/sm501fb.c | 106 +
 2 files changed, 542 insertions(+)

diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 28027982cf69..3408778e0048 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -82,6 +82,23 @@ struct sm501_devdata {
unsigned int rev;
 };
 
+enum prop_type {
+   PROP_NUM, PROP_STR,
+};
+
+enum val_type {
+   ENDIS, MT_EX, MT_XC, MT_SSM, MT_SM, MT_DEBUG, MT_DIV, MT_USB, MT_DELAY,
+   MC_PAD, MC_USBCLK, MC_SSP, MC_FP, MC_FREQ, MC_REFRESH, MC_HOLD, MC_SH,
+   MC_II, MC_GAP, MC_DAC, MC_MC, MC_BL, MC_USB, MC_LB, MC_VR,
+};
+
+struct sm501_config_props {
+   char *name;
+   u32 shift;
+   u32 width;
+   enum prop_type prop_type;
+   enum val_type val_type;
+};
 
 #define MHZ (1000 * 1000)
 
@@ -1370,6 +1387,419 @@ static int sm501_init_dev(struct sm501_devdata *sm)
return 0;
 }
 
+static u32 lookup_str(const char *val, const char * const *list)
+{
+   u32 ret = 0;
+
+   while (*list) {
+   if (strcmp(val, *list) == 0)
+   return ret;
+   list++;
+   ret++;
+   }
+   return ~0;
+}
+
+static u32 lookup_num(u32 val, const u32 *list)
+{
+   u32 ret = 0;
+
+   while (*list != ~0) {
+   if (val == *list)
+   return ret;
+   list++;
+   ret++;
+   }
+   return ~0;
+}
+
+static const struct sm501_config_props misc_timming[] = {
+   {"ex",  28, 4, PROP_NUM, MT_EX},
+   {"xc",  24, 2, PROP_STR, MT_XC},
+   {"us",  23, 1, PROP_STR, ENDIS},
+   {"ssm1",20, 1, PROP_STR, MT_SSM},
+   {"sm1", 16, 4, PROP_NUM, MT_SM},
+   {"ssm0",12, 1, PROP_STR, MT_SSM},
+   {"sm0",  8, 4, PROP_NUM, MT_SM},
+   {"deb",  7, 1, PROP_STR, MT_DEBUG},
+   {"acpi", 6, 1, PROP_STR, ENDIS},
+   {"divider",  4, 2, PROP_NUM, MT_DIV},
+   {"usb-mode", 3, 1, PROP_STR, MT_USB},
+   {"delay",0, 3, PROP_NUM, MT_DELAY},
+   {},
+};
+
+static const struct sm501_config_props misc_control[] = {
+   {"pad",  30, 2, PROP_NUM, MC_PAD},
+   {"usbclk",   28, 2, PROP_STR, MC_USBCLK},
+   {"uart-ssp", 27, 1, PROP_STR, MC_SSP},
+   {"lat",  26, 1, PROP_STR, ENDIS},
+   {"fp",   25, 1, PROP_NUM, MC_FP},
+   {"freq", 24, 1, PROP_NUM, MC_FREQ},
+   {"refresh",  21, 2, PROP_NUM, MC_REFRESH},
+   {"hold", 18, 3, PROP_NUM, MC_HOLD},
+   {"sh",   17, 1, PROP_STR, MC_SH},
+   {"ii",   16, 1, PROP_STR, MC_II},
+   {"pll",  15, 1, PROP_STR, ENDIS},
+   {"gap",  13, 2, PROP_STR, MC_GAP},
+   {"dac",  12, 1, PROP_STR, MC_DAC},
+   {"mc",   11, 1, PROP_STR, MC_MC},
+   {"bl",   10, 1, PROP_NUM, MC_BL},
+   {"usb",   9, 1, PROP_STR, MC_USB},
+   {"lb",8, 1, PROP_STR, MC_LB},
+   {"vr",4, 1, PROP_NUM, MC_VR},
+   {},
+};
+
+/* Read configuration values */
+static void sm501_of_read_config(struct device *dev, struct device_node *np,
+const char *prefix,
+const struct sm501_config_props *props,
+struct sm501_reg_init *ret)
+{
+   static const char * const endis[] = { "disable", "enable", NULL };
+   static const char * const xc[] = { "internal-pll", "hclk", "gpio33", 
NULL };
+   static const char * const ssm[] = { "288mhz", "div", NULL };
+   static const char * const debmode[] = { "input-reference", "output", 
NULL };
+   static const char * const usbmode[] = { "normal", "simulation", NULL };
+   static const char * const usbclk[] = { "crystal", "-", "96mhz", 
"48mhz", NULL };
+   static const char * const ssp[] = { "uart1", "ssp1", NULL };
+   static const char * const sh_ready[] = { "active-low", "active-high", 
NULL };
+   static const char * const int_invert[] = { "normal", "invert", NULL };
+   static const char * const slave[] = { "cpu", "8051", NULL };
+   static const char * const usbport[] = { "master", "slave", NULL };
+   static const char * const usbloop[] = { "normal", "loopback", NULL };
+
+   static const u32 divrate[] = { 336, 288, 240, 192, ~0 };
+   static const u32 fpdata[] = { 18, 24, ~0 };
+   static const u32 cfreq[] = { 24, 12, ~0 };
+   static const u32 bushold[] = { 0, 8, 16, 24, 32, ~0 };
+   static const u32 burst[] = { 8, 1, ~0 };
+   static const u32 vrmem[] = { 30, 62, ~0 };
+
+   struct device_node *child;
+   const char *sval;
+   u32 mask;
+   u32 val;