Thank you for your comment. Jonathan Cameron <jic23@xxxxxxxxxx> 於 2024年11月9日 週六 下午9:45寫道: > > On Thu, 7 Nov 2024 08:41:21 +0800 > Yu-Hsian Yang <j2anfernee@xxxxxxxxx> wrote: > > > Dear Krzysztof Kozlowski, > > > > Thank you for your response. > > > > Krzysztof Kozlowski <krzk@xxxxxxxxxx> 於 2024年11月6日 週三 下午9:41寫道: > > > > > > On 06/11/2024 03:39, Eason Yang wrote: > > > > Add Nuvoton NCT7201/NCT7202 system voltage monitor 12-bit ADC driver > > > > > > > > NCT7201/NCT7202 supports up to 12 analog voltage monitor inputs and up to > > > > 4 SMBus addresses by ADDR pin. Meanwhile, ALERT# hardware event pins for > > > > independent alarm signals, and the all threshold values could be set for > > > > system protection without any timing delay. It also supports reset input > > > > RSTIN# to recover system from a fault condition. > > > > > > > > Currently, only single-edge mode conversion and threshold events support. > > > > > > > > Signed-off-by: Eason Yang <j2anfernee@xxxxxxxxx> > > > > > > ... > > > > > > > + > > > > +static int nct720x_probe(struct i2c_client *client) > > > > +{ > > > > + const struct i2c_device_id *id = i2c_client_get_device_id(client); > > > > + struct nct720x_chip_info *chip; > > > > + struct iio_dev *indio_dev; > > > > + int ret; > > > > + u32 tmp; > > > > + > > > > + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); > > > > + if (!indio_dev) > > > > + return -ENOMEM; > > > > + chip = iio_priv(indio_dev); > > > > + > > > > + if (client->dev.of_node) > > > > + chip->type = (enum nct720x_chips)device_get_match_data(&client->dev); > > > > + else > > > > + chip->type = i2c_match_id(nct720x_id, client)->driver_data; > > > > > > I believe there is a I2C wrapper for above. > > > > > > > Got it. > > Don't pass an enum value as data. Pass a pointer to a structure that describes the particular > variant. The 0 value which tends to end up in enums is an error for device_get_match_data. > I would pass a pointer to the data structure not id to describe the particular variant. I would rewrite the code as below, static const struct nct720x_adc_model_data nct7201_model_data = { .model_name = "nct7201", .channels = nct7201_channels, .num_channels = ARRAY_SIZE(nct7201_channels), .vin_max = 8, }; static const struct nct720x_adc_model_data nct7202_model_data = { .model_name = "nct7202", .channels = nct7202_channels, .num_channels = ARRAY_SIZE(nct7202_channels), .vin_max = 12, }; static const struct i2c_device_id nct720x_id[] = { { "nct7201", (kernel_ulong_t)&nct7201_model_data }, { "nct7202", (kernel_ulong_t)&nct7202_model_data }, { } }; MODULE_DEVICE_TABLE(i2c, nct720x_id); static const struct of_device_id nct720x_of_match[] = { { .compatible = "nuvoton,nct7201", .data = &nct7201_model_data, }, { .compatible = "nuvoton,nct7202", .data = &nct7202_model_data, }, { } }; MODULE_DEVICE_TABLE(of, nct720x_of_match); > > > > > > + > > > > + chip->vin_max = (chip->type == nct7201) ? NCT7201_VIN_MAX : NCT7202_VIN_MAX; > > > > + > > > > + ret = of_property_read_u32(client->dev.of_node, "read-vin-data-size", &tmp); > > > > + if (ret < 0) { > > > > + pr_err("read-vin-data-size property not found\n"); > > > > > > Please use dev_xxx in your driver code. > > > > Got it. > > > > > > > > > > > Best regards, > > > Krzysztof > > > >