]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
hwmon: (ntc_thermistor) use a table to lookup the thermistor type
authorPeter Rosin <peda@axentia.se>
Wed, 21 Nov 2018 16:03:46 +0000 (16:03 +0000)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 16 Dec 2018 23:13:21 +0000 (15:13 -0800)
Sort the entries while at it.

Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/ntc_thermistor.c
include/linux/platform_data/ntc_thermistor.h

index 7747c1ed1f020443fab85186c6751a1b8d5fc86c..56d83b2472c8835aa94555a335a9b4fe91817498 100644 (file)
@@ -315,6 +315,23 @@ static const struct ntc_compensation b57891s0103[] = {
        { .temp_c       = 155.0, .ohm   = 168 },
 };
 
+struct ntc_type {
+       const struct ntc_compensation *comp;
+       int n_comp;
+};
+
+#define NTC_TYPE(ntc, compensation) \
+[(ntc)] = { .comp = (compensation), .n_comp = ARRAY_SIZE(compensation) }
+
+static const struct ntc_type ntc_type[] = {
+       NTC_TYPE(TYPE_B57330V2103, b57330v2103),
+       NTC_TYPE(TYPE_B57891S0103, b57891s0103),
+       NTC_TYPE(TYPE_NCPXXWB473,  ncpXXwb473),
+       NTC_TYPE(TYPE_NCPXXWF104,  ncpXXwf104),
+       NTC_TYPE(TYPE_NCPXXWL333,  ncpXXwl333),
+       NTC_TYPE(TYPE_NCPXXXH103,  ncpXXxh103),
+};
+
 struct ntc_data {
        struct ntc_thermistor_platform_data *pdata;
        const struct ntc_compensation *comp;
@@ -671,37 +688,15 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
 
        data->pdata = pdata;
 
-       switch (pdev_id->driver_data) {
-       case TYPE_NCPXXWB473:
-               data->comp = ncpXXwb473;
-               data->n_comp = ARRAY_SIZE(ncpXXwb473);
-               break;
-       case TYPE_NCPXXWL333:
-               data->comp = ncpXXwl333;
-               data->n_comp = ARRAY_SIZE(ncpXXwl333);
-               break;
-       case TYPE_B57330V2103:
-               data->comp = b57330v2103;
-               data->n_comp = ARRAY_SIZE(b57330v2103);
-               break;
-       case TYPE_NCPXXWF104:
-               data->comp = ncpXXwf104;
-               data->n_comp = ARRAY_SIZE(ncpXXwf104);
-               break;
-       case TYPE_NCPXXXH103:
-               data->comp = ncpXXxh103;
-               data->n_comp = ARRAY_SIZE(ncpXXxh103);
-               break;
-       case TYPE_B57891S0103:
-               data->comp = b57891s0103;
-               data->n_comp = ARRAY_SIZE(b57891s0103);
-               break;
-       default:
+       if (pdev_id->driver_data >= ARRAY_SIZE(ntc_type)) {
                dev_err(dev, "Unknown device type: %lu(%s)\n",
                                pdev_id->driver_data, pdev_id->name);
                return -EINVAL;
        }
 
+       data->comp   = ntc_type[pdev_id->driver_data].comp;
+       data->n_comp = ntc_type[pdev_id->driver_data].n_comp;
+
        hwmon_dev = devm_hwmon_device_register_with_groups(dev, pdev_id->name,
                                                           data, ntc_groups);
        if (IS_ERR(hwmon_dev)) {
index 231a27c302ec525827b05cc6edf18211ca0e2688..ee03d429742bb8513c04a4a48e7603f67c37d249 100644 (file)
 struct iio_channel;
 
 enum ntc_thermistor_type {
-       TYPE_NCPXXWB473,
-       TYPE_NCPXXWL333,
        TYPE_B57330V2103,
+       TYPE_B57891S0103,
+       TYPE_NCPXXWB473,
        TYPE_NCPXXWF104,
+       TYPE_NCPXXWL333,
        TYPE_NCPXXXH103,
-       TYPE_B57891S0103,
 };
 
 struct ntc_thermistor_platform_data {