Commit a57743bf authored by André Draszik's avatar André Draszik Committed by Alexandre Belloni
Browse files

rtc: s5m: prepare for external regmap



The Samsung S2MPG10 PMIC is not connected via I2C as this driver
assumes, hence this driver's current approach of creating an I2C-based
regmap doesn't work for it, and this driver should use the regmap
provided by the parent (core) driver instead for that PMIC.

To prepare this driver for s2mpg support, restructure the code to only
create a regmap if one isn't provided by the parent.

No functional changes, since the parent doesn't provide a regmap for
any of the PMICs currently supported by this driver. Having this change
separate will simply make the addition of S2MPG10 support more
self-contained, without additional restructuring.

Reviewed-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: default avatarAndré Draszik <andre.draszik@linaro.org>
Link: https://lore.kernel.org/r/20250409-s2mpg10-v4-26-d66d5f39b6bf@linaro.org


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 002cc0ee
Loading
Loading
Loading
Loading
+45 −36
Original line number Diff line number Diff line
@@ -640,14 +640,17 @@ static int s5m_rtc_probe(struct platform_device *pdev)
	enum sec_device_type device_type =
		platform_get_device_id(pdev)->driver_data;
	struct s5m_rtc_info *info;
	struct i2c_client *i2c;
	const struct regmap_config *regmap_cfg;
	int ret, alarm_irq;

	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
	if (!info)
		return -ENOMEM;

	info->regmap = dev_get_regmap(pdev->dev.parent, "rtc");
	if (!info->regmap) {
		const struct regmap_config *regmap_cfg;
		struct i2c_client *i2c;

		switch (device_type) {
		case S2MPS15X:
			regmap_cfg = &s2mps14_rtc_regmap_config;
@@ -671,20 +674,26 @@ static int s5m_rtc_probe(struct platform_device *pdev)
			break;
		default:
			return dev_err_probe(&pdev->dev, -ENODEV,
				     "Device type %d is not supported by RTC driver\n",
					     "Unsupported device type %d\n",
					     device_type);
		}

	i2c = devm_i2c_new_dummy_device(&pdev->dev, s5m87xx->i2c->adapter,
		i2c = devm_i2c_new_dummy_device(&pdev->dev,
						s5m87xx->i2c->adapter,
						RTC_I2C_ADDR);
		if (IS_ERR(i2c))
			return dev_err_probe(&pdev->dev, PTR_ERR(i2c),
				     "Failed to allocate I2C for RTC\n");
					     "Failed to allocate I2C\n");

		info->regmap = devm_regmap_init_i2c(i2c, regmap_cfg);
		if (IS_ERR(info->regmap))
			return dev_err_probe(&pdev->dev, PTR_ERR(info->regmap),
				     "Failed to allocate RTC register map\n");
					     "Failed to allocate regmap\n");
	} else {
		return dev_err_probe(&pdev->dev, -ENODEV,
				     "Unsupported device type %d\n",
				     device_type);
	}

	info->dev = &pdev->dev;
	info->s5m87xx = s5m87xx;