From patchwork Mon Mar 25 12:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13601979 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 473D43DABFD; Mon, 25 Mar 2024 12:09:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711368598; cv=none; b=i/jWKfA8mJYpcSkRI91BhmEj3BkeqSmZdJSxyu3+vF8EVcfPzCv/MVnV0IdKwCtmz0d3qDy2zaK8iScCfU98tcDXhrv+f8z0dObSTxQoY1Q+qTkMuyMLAMLXfsoZ3g65NXKONQ+3BlNJuciRdTc0p0WcytVjU/9Lg7/rCh3pb3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711368598; c=relaxed/simple; bh=W/cO6pxnCka0JOSlclAmBwBis0mca+rD5Q5XRSgDsDQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HctzbQpigkiBSkQ6QGMlFXuRTtPDHE9JQKizojl7fnjpHuxIhqBBgpZstHnE7/IOvtxHFfEWEHKm/YW5Zr3fkvv5k9GYnvNv/yp6yVU34AXnfqb5D7vj7oX95C4wNaxsRmBy/+GbojHsira2JD5wD19cXcLVmCnnBUADs6vtIO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CIUeoTB7; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CIUeoTB7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711368597; x=1742904597; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=W/cO6pxnCka0JOSlclAmBwBis0mca+rD5Q5XRSgDsDQ=; b=CIUeoTB7n7KovOBcUy0ll+D1UZ5E25v9aaPGlLyrWNIJsizOPD0gFkdd c7dRoQ3red49CpxH6dYx6BpjsMqy/OU+o98GO1ZsP0dESYk6nd5qhzs9g NlnXgycMnr/QBdFvawsaYA9guX42/WchBkoUmfws/xRfHPZrLwZiEtS/O nvU4gcYVUWh2EoHw2a2VJmF744KdDae4BByGPz9k6kkXKhQ8y4pSWdZ/v LzwyYhk+LqVVBBksewVCvHBTTkaD7nOTiHhonHb3EcqL1fEJeUYniMezS dnn4rMHkE3TK20tYhDfiVvRH5f1h4F/A76/Y7EE6X4U+kobzHzk2FJdle g==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="17757423" X-IronPort-AV: E=Sophos;i="6.07,153,1708416000"; d="scan'208";a="17757423" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 05:09:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070311" X-IronPort-AV: E=Sophos;i="6.07,153,1708416000"; d="scan'208";a="937070311" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 05:09:53 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 05F5713F; Mon, 25 Mar 2024 14:09:52 +0200 (EET) From: Andy Shevchenko To: Guenter Roeck , Patrick Rudolph , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jean Delvare , Andy Shevchenko Subject: [PATCH v1 1/3] hwmon: (pmbus/mp2975) Replace home made version of __assign_bit() Date: Mon, 25 Mar 2024 14:07:42 +0200 Message-ID: <20240325120952.3019767-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com> References: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The newly introduced SWAP() macro is quite generic by naming, but moreover it's a repetition of the existing __assign_bit(). With this applied, add a missing bits.h (via now required bitops.h). Signed-off-by: Andy Shevchenko --- drivers/hwmon/pmbus/mp2975.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c index 953c02a2aeb5..af118087c4ee 100644 --- a/drivers/hwmon/pmbus/mp2975.c +++ b/drivers/hwmon/pmbus/mp2975.c @@ -5,6 +5,7 @@ * Copyright (C) 2020 Nvidia Technologies Ltd. */ +#include #include #include #include @@ -396,7 +397,7 @@ static int mp2973_write_word_data(struct i2c_client *client, int page, int reg, u16 word) { u8 target, mask; - int ret; + long ret; if (reg != PMBUS_SMBALERT_MASK) return -ENODATA; @@ -415,7 +416,6 @@ static int mp2973_write_word_data(struct i2c_client *client, int page, * Set/Clear 'bit' in 'ret' based on condition followed by define for each bit in SMBALERT_MASK. * Also bit 2 & 15 are reserved. */ -#define SWAP(val, mask, cond, bit) (((mask) & (cond)) ? ((val) & ~BIT(bit)) : ((val) | BIT(bit))) #define MP2973_TEMP_OT 0 #define MP2973_VIN_UVLO 1 @@ -434,36 +434,35 @@ static int mp2973_write_word_data(struct i2c_client *client, int page, switch (target) { case PMBUS_STATUS_CML: - ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_DATA, MP2973_INVALID_DATA); - ret = SWAP(ret, mask, PB_CML_FAULT_INVALID_COMMAND, MP2973_INVALID_COMMAND); - ret = SWAP(ret, mask, PB_CML_FAULT_OTHER_COMM, MP2973_OTHER_COMM); - ret = SWAP(ret, mask, PB_CML_FAULT_PACKET_ERROR, MP2973_PACKET_ERROR); + __assign_bit(MP2973_INVALID_DATA, &ret, !(mask & PB_CML_FAULT_INVALID_DATA)); + __assign_bit(MP2973_INVALID_COMMAND, &ret, !(mask & PB_CML_FAULT_INVALID_COMMAND)); + __assign_bit(MP2973_OTHER_COMM, &ret, !(mask & PB_CML_FAULT_OTHER_COMM)); + __assign_bit(MP2973_PACKET_ERROR, &ret, !(mask & PB_CML_FAULT_PACKET_ERROR)); break; case PMBUS_STATUS_VOUT: - ret = SWAP(ret, mask, PB_VOLTAGE_UV_FAULT, MP2973_VOLTAGE_UV); - ret = SWAP(ret, mask, PB_VOLTAGE_OV_FAULT, MP2973_VOLTAGE_OV); + __assign_bit(MP2973_VOLTAGE_UV, &ret, !(mask & PB_VOLTAGE_UV_FAULT)); + __assign_bit(MP2973_VOLTAGE_OV, &ret, !(mask & PB_VOLTAGE_OV_FAULT)); break; case PMBUS_STATUS_IOUT: - ret = SWAP(ret, mask, PB_IOUT_OC_FAULT, MP2973_IOUT_OC); - ret = SWAP(ret, mask, PB_IOUT_OC_LV_FAULT, MP2973_IOUT_OC_LV); + __assign_bit(MP2973_IOUT_OC, &ret, !(mask & PB_IOUT_OC_FAULT)); + __assign_bit(MP2973_IOUT_OC_LV, &ret, !(mask & PB_IOUT_OC_LV_FAULT)); break; case PMBUS_STATUS_TEMPERATURE: - ret = SWAP(ret, mask, PB_TEMP_OT_FAULT, MP2973_TEMP_OT); + __assign_bit(MP2973_TEMP_OT, &ret, !(mask & PB_TEMP_OT_FAULT)); break; /* * Map remaining bits to MFR specific to let the PMBUS core mask * those bits by default. */ case PMBUS_STATUS_MFR_SPECIFIC: - ret = SWAP(ret, mask, BIT(1), MP2973_VIN_UVLO); - ret = SWAP(ret, mask, BIT(3), MP2973_VIN_OVP); - ret = SWAP(ret, mask, BIT(4), MP2973_MTP_FAULT); - ret = SWAP(ret, mask, BIT(6), MP2973_MTP_BLK_TRIG); + __assign_bit(MP2973_VIN_UVLO, &ret, !(mask & BIT(1))); + __assign_bit(MP2973_VIN_OVP, &ret, !(mask & BIT(3))); + __assign_bit(MP2973_MTP_FAULT, &ret, !(mask & BIT(4))); + __assign_bit(MP2973_MTP_BLK_TRIG, &ret, !(mask & BIT(6))); break; default: return 0; } -#undef SWAP return pmbus_write_word_data(client, 0, PMBUS_SMBALERT_MASK, ret); } From patchwork Mon Mar 25 12:07:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13601982 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF1C0CA6B; Mon, 25 Mar 2024 12:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711368600; cv=none; b=RbICcXQcqFLeV0+q1193c0of6A8+XYkpc3Bd3fHOFncLH8nPSxJVro+fzwGOU8BoC2OjgTNo5+chgshI9htEcGKy8F09BkUCfAKzJqfWU0MIo+CBwmTejPjAbIzIv57wYMVe/ovAwWhgcT4GOpRG5ksYZ8BdSicLbmn0AyxtD6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711368600; c=relaxed/simple; bh=0NKiHG7ZlFjs7TiosmHvTOqi/ShFoTyI/Q4Yj+MHyWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fXBbV5dQSD+aFZeWXULUOlvDu7fjjegFobGLsQs1Ihue3a5O3Jr85+vTYYhpaK/AfxR239Yck1CYTueqfJJW5r6S8uto+B0D6HNAk+zy6ffuEh54wwW0hoLY6T82IoVQtkUb0pwW6MQtyC88yisOp72MJOhpTtQ2oJq8wzpwgx8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HBiJJ9ZB; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HBiJJ9ZB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711368599; x=1742904599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0NKiHG7ZlFjs7TiosmHvTOqi/ShFoTyI/Q4Yj+MHyWo=; b=HBiJJ9ZBTEspO2TqR1h168O6pncSI57B6deJW7eI1ArDGifAE67itkSC Qgt9ThiLLpuAT52KP0E+ObZ9sYkIRhw7780XctUCrDIBnG7J0rlo/oPQw gmxHgFu76m/zB2xxhaZLXRLylBizMwLhaHy8SKURdJaZv82EsyaCXR5bl CSt/gs9QqFdX6yeVKifah3E0NI7zvLXi+sxhj9bFYbYxFQVLSunRlC9QU rVfRjnkEncxNhFXNUKG7E75Lzahs5K/8RiaSouxP7kTpVA7qBuxwCPVX4 LtMPwrfEl2JP/8C4DJ6EWUKX3jf884SUFde4LxzThHoIdE6o4JNjsofzO g==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="17757431" X-IronPort-AV: E=Sophos;i="6.07,153,1708416000"; d="scan'208";a="17757431" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 05:09:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070313" X-IronPort-AV: E=Sophos;i="6.07,153,1708416000"; d="scan'208";a="937070313" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 05:09:54 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0F97B2CA; Mon, 25 Mar 2024 14:09:53 +0200 (EET) From: Andy Shevchenko To: Guenter Roeck , Patrick Rudolph , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jean Delvare , Andy Shevchenko Subject: [PATCH v1 2/3] hwmon: (pmbus/mp2975) Constify local pointers to pmbus_driver_info Date: Mon, 25 Mar 2024 14:07:43 +0200 Message-ID: <20240325120952.3019767-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com> References: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Constify the local variables pointing to "struct pmbus_driver_info" and other encoding params to annotate the function is not modifying pointed data. Signed-off-by: Andy Shevchenko --- drivers/hwmon/pmbus/mp2975.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c index af118087c4ee..bc7558dc87ee 100644 --- a/drivers/hwmon/pmbus/mp2975.c +++ b/drivers/hwmon/pmbus/mp2975.c @@ -942,7 +942,7 @@ mp2975_vout_per_rail_config_get(struct i2c_client *client, return 0; } -static struct pmbus_driver_info mp2975_info = { +static const struct pmbus_driver_info mp2975_info = { .pages = 1, .format[PSC_VOLTAGE_IN] = linear, .format[PSC_VOLTAGE_OUT] = direct, @@ -967,7 +967,7 @@ static struct pmbus_driver_info mp2975_info = { #endif }; -static struct pmbus_driver_info mp2973_info = { +static const struct pmbus_driver_info mp2973_info = { .pages = 1, .format[PSC_VOLTAGE_IN] = linear, .format[PSC_VOLTAGE_OUT] = direct, From patchwork Mon Mar 25 12:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13601981 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C84C1843; Mon, 25 Mar 2024 12:10:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711368602; cv=none; b=IgWaf652s05fmfvlmtTw7AkqzBRUhonBAalA5rIfsRNX5aHacTG+W27Zq2QQ+iMzdL2V6C861dQ2Hc4zsbTQqSBgpfRJmBGuG5teVGfV/F4bk2V9YlbI5I7qpaeu8vhCAGV3d32bk3qjy9eLVMvkUIPXIjYaFBz58v8sL6YlSko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711368602; c=relaxed/simple; bh=OmCFaQ0QL0ZY3hfBw/hp9a6NNGjTQFwFe46YUfQbR4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KRMhzZEjuU9t/lNwiEhz0mFVg2f64pU4Ne9iJEDr2ap7t6fQNvFVn8ZkQ0Bie5x/yIXfEvj2w4VSkswVUv+m6xlTunHW7THa8gsBn68RH3dXtghCIWg3umUqeIxVM2FNhMLDA2Pi5YVNjmL0YxDg2d8N852AxipWlSxx8mC9F6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EBh/sJsF; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EBh/sJsF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711368600; x=1742904600; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OmCFaQ0QL0ZY3hfBw/hp9a6NNGjTQFwFe46YUfQbR4g=; b=EBh/sJsFqXSE9SkJUrMVTvvDaSt7ZD9dVTeFjFZWszzgQjpbjj1E4cmQ iIiCLNoqu3S0e1vqvUyHJyoMLft/m6yPvOz/axnBLFWc0KiDemKFcnpRA V924Fc4xqQxwgzLu4S3SjuzqBhFtVAbljpHp6PZYY8qvRt+7Ybbu0jyC5 ouwVayKEPgkPE+Bo+mA3yOmlEsYqjFg8QzA+rz5d1+3Bh01V/QyZxq110 vL9OokUbq7ALb4cLNEiJrMQK3zVTjzG5uDynnYCWAaPorZMVRRdlgcBLv +hQjejNVh7oAA1kJZe+gtsjPL+BcNyAHJqhKI70XQmkkB6h2/jQcYyZVf g==; X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="17757437" X-IronPort-AV: E=Sophos;i="6.07,153,1708416000"; d="scan'208";a="17757437" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2024 05:09:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11023"; a="937070314" X-IronPort-AV: E=Sophos;i="6.07,153,1708416000"; d="scan'208";a="937070314" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 25 Mar 2024 05:09:54 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 22530233; Mon, 25 Mar 2024 14:09:53 +0200 (EET) From: Andy Shevchenko To: Guenter Roeck , Patrick Rudolph , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jean Delvare , Andy Shevchenko Subject: [PATCH v1 3/3] hwmon: (pmbus/mp2975) Use i2c_get_match_data() Date: Mon, 25 Mar 2024 14:07:44 +0200 Message-ID: <20240325120952.3019767-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com> References: <20240325120952.3019767-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use preferred i2c_get_match_data() instead of of_device_get_match_data() to get the driver match data. With this, adjust the includes to explicitly include the correct headers. Signed-off-by: Andy Shevchenko --- drivers/hwmon/pmbus/mp2975.c | 54 +++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/drivers/hwmon/pmbus/mp2975.c b/drivers/hwmon/pmbus/mp2975.c index bc7558dc87ee..79b4ea325cb2 100644 --- a/drivers/hwmon/pmbus/mp2975.c +++ b/drivers/hwmon/pmbus/mp2975.c @@ -10,8 +10,9 @@ #include #include #include +#include #include -#include + #include "pmbus.h" /* Vendor specific registers. */ @@ -98,6 +99,11 @@ static const int mp2975_max_phases[][MP2975_PAGE_NUM] = { [mp2971] = { MP2971_MAX_PHASE_RAIL1, MP2971_MAX_PHASE_RAIL2 }, }; +struct mp2975_driver_info { + const struct pmbus_driver_info *info; + enum chips chip_id; +}; + struct mp2975_data { struct pmbus_driver_info info; enum chips chip_id; @@ -111,15 +117,6 @@ struct mp2975_data { int curr_sense_gain[MP2975_PAGE_NUM]; }; -static const struct i2c_device_id mp2975_id[] = { - {"mp2971", mp2971}, - {"mp2973", mp2973}, - {"mp2975", mp2975}, - {} -}; - -MODULE_DEVICE_TABLE(i2c, mp2975_id); - static const struct regulator_desc __maybe_unused mp2975_reg_desc[] = { PMBUS_REGULATOR("vout", 0), PMBUS_REGULATOR("vout", 1), @@ -989,29 +986,34 @@ static const struct pmbus_driver_info mp2973_info = { #endif }; +static const struct mp2975_driver_info mp2975_ddinfo[] = { + [mp2975] = { .info = &mp2975_info, .chip_id = mp2975 }, + [mp2973] = { .info = &mp2973_info, .chip_id = mp2973 }, + [mp2971] = { .info = &mp2973_info, .chip_id = mp2971 }, +}; + static int mp2975_probe(struct i2c_client *client) { + const struct mp2975_driver_info *ddinfo; struct pmbus_driver_info *info; struct mp2975_data *data; int ret; + ddinfo = i2c_get_match_data(client); + if (!ddinfo) + return -ENODEV; + data = devm_kzalloc(&client->dev, sizeof(struct mp2975_data), GFP_KERNEL); if (!data) return -ENOMEM; - if (client->dev.of_node) - data->chip_id = (enum chips)(unsigned long)of_device_get_match_data(&client->dev); - else - data->chip_id = i2c_match_id(mp2975_id, client)->driver_data; + data->chip_id = ddinfo->chip_id; memcpy(data->max_phases, mp2975_max_phases[data->chip_id], sizeof(data->max_phases)); - if (data->chip_id == mp2975) - memcpy(&data->info, &mp2975_info, sizeof(*info)); - else - memcpy(&data->info, &mp2973_info, sizeof(*info)); + memcpy(&data->info, ddinfo->info, sizeof(data->info)); info = &data->info; @@ -1070,17 +1072,25 @@ static int mp2975_probe(struct i2c_client *client) } static const struct of_device_id __maybe_unused mp2975_of_match[] = { - {.compatible = "mps,mp2971", .data = (void *)mp2971}, - {.compatible = "mps,mp2973", .data = (void *)mp2973}, - {.compatible = "mps,mp2975", .data = (void *)mp2975}, + {.compatible = "mps,mp2971", .data = &mp2975_ddinfo[mp2971]}, + {.compatible = "mps,mp2973", .data = &mp2975_ddinfo[mp2973]}, + {.compatible = "mps,mp2975", .data = &mp2975_ddinfo[mp2975]}, {} }; MODULE_DEVICE_TABLE(of, mp2975_of_match); +static const struct i2c_device_id mp2975_id[] = { + {"mp2971", (kernel_ulong_t)&mp2975_ddinfo[mp2971]}, + {"mp2973", (kernel_ulong_t)&mp2975_ddinfo[mp2973]}, + {"mp2975", (kernel_ulong_t)&mp2975_ddinfo[mp2975]}, + {} +}; +MODULE_DEVICE_TABLE(i2c, mp2975_id); + static struct i2c_driver mp2975_driver = { .driver = { .name = "mp2975", - .of_match_table = of_match_ptr(mp2975_of_match), + .of_match_table = mp2975_of_match, }, .probe = mp2975_probe, .id_table = mp2975_id,