From patchwork Sun Aug 7 23:06:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Hauser X-Patchwork-Id: 596050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26D9DC25B0F for ; Sun, 7 Aug 2022 23:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234529AbiHGXHr (ORCPT ); Sun, 7 Aug 2022 19:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234579AbiHGXHo (ORCPT ); Sun, 7 Aug 2022 19:07:44 -0400 Received: from sonic309-25.consmr.mail.ir2.yahoo.com (sonic309-25.consmr.mail.ir2.yahoo.com [77.238.179.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F5985599 for ; Sun, 7 Aug 2022 16:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rocketmail.com; s=s2048; t=1659913662; bh=s8hMp8JriMdWMFhNLLvIXtmbLU7UlvwcBiIrbiApJJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=ry03yBWDSNbfLcAUaQIVkfs5q4GU3fjG+Y6yUHTL7d4cCJmeqi8FmujvHaje68VfKz3gtkbXbJclz1a74Qy3coIZEVo3RInqjJuHusaaDvVsUsGolcC2QQy0efIfJabLAZnTnQeIBq91H0P1mey2omP4N6TAfmFVItqlUYa6kv25YJNGoOhLJcwp3veZ810xuvUS/+u5YZWMStRIIXYKSjEn1t2xYjyMvfWPUnmf8T4w0mdE/uub+b4BSHtmvOzdRaB68BLELk89J80Tym22lOD88iOOjU0dd0Lr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Kwmohx1tm7a1OzE5llz3zt7w_mP5tbnh8Gl_BrXRkOT3RPdAfc6dlJVHD2SdE1G3VbfuY0NtuUB _IHjdjrWYyd9rkDmC2Cw.7LQO.USn63kck5ZnvSosiDJEVkgi_yFcv.jGPSZBHoKK7t05yTRJAaf DTKFrD.6vI90KX_1Dx3MksH4MlK65B1OUWxwX_4fJACjW5CcGve8wpuSwJRt77_0FEXYJVlMc7GS qtL3vMNGwL2suvhQYud9HLNLBVf0cXlWaymcApmH1OncZVDYMAd.I5QjvnnU.ERPKIWAm.tZESxs YuG8joLzmCaPrdtPpcZ9Bdzqty1Bpo0rFV8XIHcIJ.eXaKi3BEpqUdaUoLoEW9sTjO6ZpuVVLlKN RfDADw84oZMoSAEGWfqfRBjUdfGWadpB5K1LJSBDztJ6cp3rh_NataXEenC1NLxLzLMKxHd_oYd1 KP.j2.VPo6jXE8zsNuJ9mtPQIMiCwn5Ffv5Zl.5eezGc37XMdfkWUevdhHEQJ2s582QthpH3j3eL W4nycXhALFLxUgoGMo0WvlmZlfZ7BS5iRSeUA8qEjQnzWEkx2EY97MqBQjzrnZraIThthuFlJMw4 fvDrx6x3pOk2K2g.kK5bNPnkgM14t4QIajn23qGAYX5Mve7_.Rj30uO8Fu69pP9lQI7zEkXkyAvt 1L2UOnDK8NZByqEZT8w40bgDb0mNbphMvNkoORfIuPKZF8QA..lZj6TXpOl9eHRtW2MyHQsIJPO2 ISFvWFgFLDHN.q5oq X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ir2.yahoo.com with HTTP; Sun, 7 Aug 2022 23:07:42 +0000 Received: by hermes--canary-production-ir2-f74ffc99c-2vqg6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID dc92a55cf24372a35650a28a19dee6ae; Sun, 07 Aug 2022 23:07:41 +0000 (UTC) From: Jakob Hauser To: Jonathan Cameron Cc: Lars-Peter Clausen , Linus Walleij , Andy Shevchenko , Hans de Goede , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Jakob Hauser Subject: [PATCH v5 13/14] iio: magnetometer: yas530: Add function pointers to "chip_info" Date: Mon, 8 Aug 2022 01:06:52 +0200 Message-Id: <20ad0e793df229e71575c4e7d0bc4f6a5fb49f29.1659909060.git.jahau@rocketmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add funtion pointers to the "chip_info" structure to ease the handling of different YAS variants. In the function yas5xx_probe(), the function call for "measure_offsets" was added as a conditional "if (yas5xx->chip_info->measure_offsets)". This is a preparatory step for YAS537, as this variant doesn't need an offset measurement. Signed-off-by: Jakob Hauser --- drivers/iio/magnetometer/yamaha-yas530.c | 65 +++++++++++++++--------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c index 780c7f4d1eff..62d5f23d8e08 100644 --- a/drivers/iio/magnetometer/yamaha-yas530.c +++ b/drivers/iio/magnetometer/yamaha-yas530.c @@ -168,6 +168,11 @@ struct yas5xx; * @scaling_val2: scaling value for IIO_CHAN_INFO_SCALE * @t_ref: number of counts at reference temperature * @min_temp_x10: starting point of temperature counting in 1/10:s degrees Celsius + * @get_measure: function pointer to get a measurement + * @get_calibration_data: function pointer to get calibration data + * @dump_calibration: function pointer to dump calibration for debugging + * @measure_offsets: function pointer to measure the offsets + * @power_on: function pointer to power-on procedure */ struct yas5xx_chip_info { unsigned int devid; @@ -178,13 +183,18 @@ struct yas5xx_chip_info { u32 scaling_val2; u16 t_ref; s16 min_temp_x10; + int (*get_measure)(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo); + int (*get_calibration_data)(struct yas5xx *yas5xx); + void (*dump_calibration)(struct yas5xx *yas5xx); + int (*measure_offsets)(struct yas5xx *yas5xx); + int (*power_on)(struct yas5xx *yas5xx); }; /** * struct yas5xx - state container for the YAS5xx driver * @dev: parent device pointer * @chip: enumeration of the device variant - * @chip_info: device-specific data + * @chip_info: device-specific data and function pointers * @version: device version * @calibration: calibration settings from the OTP storage * @hard_offsets: offsets for each axis measured with initcoil actuated @@ -488,7 +498,7 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_RAW: pm_runtime_get_sync(yas5xx->dev); - ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); + ret = yas5xx->chip_info->get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) @@ -528,7 +538,7 @@ static void yas5xx_fill_buffer(struct iio_dev *indio_dev) int ret; pm_runtime_get_sync(yas5xx->dev); - ret = yas530_get_measure(yas5xx, &t, &x, &y, &z); + ret = yas5xx->chip_info->get_measure(yas5xx, &t, &x, &y, &z); pm_runtime_mark_last_busy(yas5xx->dev); pm_runtime_put_autosuspend(yas5xx->dev); if (ret) { @@ -941,6 +951,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000000, /* picotesla to Gauss */ .t_ref = t_ref_counts[yas530], .min_temp_x10 = min_temp_celsius_x10[yas530], + .get_measure = yas530_get_measure, + .get_calibration_data = yas530_get_calibration_data, + .dump_calibration = yas530_dump_calibration, + .measure_offsets = yas530_measure_offsets, + .power_on = yas530_power_on, }, [yas532] = { .devid = YAS532_DEVICE_ID, @@ -951,6 +966,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000, /* nanotesla to Gauss */ .t_ref = t_ref_counts[yas532], .min_temp_x10 = min_temp_celsius_x10[yas532], + .get_measure = yas530_get_measure, + .get_calibration_data = yas532_get_calibration_data, + .dump_calibration = yas530_dump_calibration, + .measure_offsets = yas530_measure_offsets, + .power_on = yas530_power_on, }, [yas533] = { .devid = YAS532_DEVICE_ID, @@ -961,6 +981,11 @@ static const struct yas5xx_chip_info yas5xx_chip_info_tbl[] = { .scaling_val2 = 100000, /* nanotesla to Gauss */ .t_ref = t_ref_counts[yas533], .min_temp_x10 = min_temp_celsius_x10[yas533], + .get_measure = yas530_get_measure, + .get_calibration_data = yas532_get_calibration_data, + .dump_calibration = yas530_dump_calibration, + .measure_offsets = yas530_measure_offsets, + .power_on = yas530_power_on, }, }; @@ -1031,35 +1056,25 @@ static int yas5xx_probe(struct i2c_client *i2c, goto assert_reset; } - switch (yas5xx->chip_info->devid) { - case YAS530_DEVICE_ID: - ret = yas530_get_calibration_data(yas5xx); - if (ret) - goto assert_reset; - break; - case YAS532_DEVICE_ID: - ret = yas532_get_calibration_data(yas5xx); - if (ret) - goto assert_reset; - break; - default: - ret = -ENODEV; - dev_err(dev, "unhandled device ID %02x\n", - yas5xx->chip_info->devid); + ret = yas5xx->chip_info->get_calibration_data(yas5xx); + if (ret) goto assert_reset; - } dev_info(dev, "detected %s %s\n", yas5xx->chip_info->product_name, yas5xx->chip_info->version_name[yas5xx->version]); - yas530_dump_calibration(yas5xx); - ret = yas530_power_on(yas5xx); - if (ret) - goto assert_reset; - ret = yas530_measure_offsets(yas5xx); + yas5xx->chip_info->dump_calibration(yas5xx); + + ret = yas5xx->chip_info->power_on(yas5xx); if (ret) goto assert_reset; + if (yas5xx->chip_info->measure_offsets) { + ret = yas5xx->chip_info->measure_offsets(yas5xx); + if (ret) + goto assert_reset; + } + indio_dev->info = &yas5xx_info; indio_dev->available_scan_masks = yas5xx_scan_masks; indio_dev->modes = INDIO_DIRECT_MODE; @@ -1155,7 +1170,7 @@ static int __maybe_unused yas5xx_runtime_resume(struct device *dev) usleep_range(31000, 40000); gpiod_set_value_cansleep(yas5xx->reset, 0); - ret = yas530_power_on(yas5xx); + ret = yas5xx->chip_info->power_on(yas5xx); if (ret) { dev_err(dev, "cannot power on\n"); goto out_reset;