On Thu, Mar 14, 2024 at 02:32:31PM +0000, Jonathan Cameron wrote: > On Wed, 13 Mar 2024 21:28:47 +0200 > Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote: > > > On Wed, Mar 13, 2024 at 08:22:45PM +0100, Vasileios Amoiridis wrote: > > > On Wed, Mar 13, 2024 at 09:01:55PM +0200, Andy Shevchenko wrote: > > > > On Wed, Mar 13, 2024 at 06:40:03PM +0100, Vasileios Amoiridis wrote: > > > > ... > > > > > > > case IIO_TEMP: > > > > > - ret = data->chip_info->read_temp(data, val, val2); > > > > > + ret = data->chip_info->read_temp(data); > > > > > + *val = data->chip_info->temp_coeffs[0] * ret; > > > > > + *val2 = data->chip_info->temp_coeffs[1]; > > > > > > > > > + if (!strcmp(indio_dev->name, "bmp580")) > > > > > + ret = IIO_VAL_FRACTIONAL_LOG2; > > > > > + else > > > > > + ret = IIO_VAL_FRACTIONAL; > > > > > > > > I'm wondering if we may replace these strcmp():s by using enum and respective > > > > values in chip_info. > > > > > > The whole problem starts from the fact that all these BMPxxx_CHIP_ID defines are > > > not unique for the respective BMPxxx device. You mean to add a new variable > > > that could store some enum values that would be the actual chip_info IDs? Like: > > > > > > enum chip_info_ids = { > > > BMP085, > > > BMP180, > > > ... > > > BMP580, > > > }; > > > > > > and later for every chip_info struct to use it like this: > > > > > > const struct bmp280_chip_info bmpxxx_chip_info = { > > > ... > > > .chip_info_id = BIT(BMPxxx), > > > > No BIT(), but yes. > > > Better to use something more meaningful such as just storing the > type you need to return alongside the values it refers to. > temp_coeffs_type = IIO_VAL_FRACTIONAL_LOG2 / IIO_VAL_FRACTIONAL as appropriate. > That way the data and what it is are found in one simple place. > > Basic rule of thumb is that if there is a string comparison to identify > what to do in a driver (other than deep in the fw handling code) then > that is a bad design. Likewise any matching on an enum value that correlates > with that chip ID. I want to see all the difference between chips in one place, > not scattered through the code. > > Jonathan > Yes, sounds totally right. I was just hesitating to add new variables in the chip_info structure (as you probably noticed in the next commits as well). Best regards, Vasilis > > > > ... > > > } > > > > > > And in the read_raw() function to just use the test_bit() function in the same > > > way that is done with the test_bit() and avail_scan_mask to test for the > > > enabled channels? > > > > If BIT() is more suitable, than also yes. > > >