diff options
author | Peter Rosin <peda@axentia.se> | 2018-11-21 16:03:46 +0000 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2018-12-16 15:13:21 -0800 |
commit | 737c086eddab6fae699ad7fc6963a91837b62b51 (patch) | |
tree | 5a38783478d335313e33930e260240fc2a7d2d72 /drivers | |
parent | e056fe25d9f021d45c3fb6068d11e56e9579754b (diff) |
hwmon: (ntc_thermistor) use a table to lookup the thermistor type
Sort the entries while at it.
Signed-off-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/hwmon/ntc_thermistor.c | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index 7747c1ed1f02..56d83b2472c8 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -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)) { |