All of lore.kernel.org
 help / color / mirror / Atom feed
From: Danny Kaehn <kaehndan@gmail.com>
To: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
	jikos@kernel.org, benjamin.tissoires@redhat.com
Cc: bartosz.golaszewski@linaro.org,
	andriy.shevchenko@linux.intel.com, dmitry.torokhov@gmail.com,
	devicetree@vger.kernel.org, linux-input@vger.kernel.org,
	ethan.twardy@plexus.com
Subject: [PATCH v8 3/3] HID: cp2112: Fwnode Support
Date: Mon, 27 Feb 2023 08:07:58 -0600	[thread overview]
Message-ID: <20230227140758.1575-4-kaehndan@gmail.com> (raw)
In-Reply-To: <20230227140758.1575-1-kaehndan@gmail.com>

Bind I2C and GPIO interfaces to subnodes with names
"i2c" and "gpio" if they exist, respectively. This
allows the GPIO and I2C controllers to be described
in firmware as usual. Additionally, support configuring the
I2C bus speed from the clock-frequency device property.

Signed-off-by: Danny Kaehn <kaehndan@gmail.com>
---
 drivers/hid/hid-cp2112.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 27cadadda7c9..491e3c83af12 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -1234,6 +1234,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	u8 buf[3];
 	struct cp2112_smbus_config_report config;
 	struct gpio_irq_chip *girq;
+	struct i2c_timings timings;
 	int ret;
 
 	dev = devm_kzalloc(&hdev->dev, sizeof(*dev), GFP_KERNEL);
@@ -1292,6 +1293,10 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		goto err_power_normal;
 	}
 
+	device_set_node(&dev->adap.dev, device_get_named_child_node(&hdev->dev, "i2c"));
+	i2c_parse_fw_timings(&dev->adap.dev, &timings, true);
+
+	config.clock_speed = cpu_to_be32(timings.bus_freq_hz);
 	config.retry_time = cpu_to_be16(1);
 
 	ret = cp2112_hid_output(hdev, (u8 *)&config, sizeof(config),
@@ -1300,7 +1305,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
 		hid_err(hdev, "error setting SMBus config\n");
 		if (ret >= 0)
 			ret = -EIO;
-		goto err_power_normal;
+		goto err_free_i2c_of;
 	}
 
 	hid_set_drvdata(hdev, (void *)dev);
@@ -1322,7 +1327,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
 
 	if (ret) {
 		hid_err(hdev, "error registering i2c adapter\n");
-		goto err_power_normal;
+		goto err_free_i2c_of;
 	}
 
 	hid_dbg(hdev, "adapter registered\n");
@@ -1336,6 +1341,7 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	dev->gc.ngpio			= 8;
 	dev->gc.can_sleep		= 1;
 	dev->gc.parent			= &hdev->dev;
+	dev->gc.fwnode			= device_get_named_child_node(&hdev->dev, "gpio");
 
 	dev->irq.name = "cp2112-gpio";
 	dev->irq.irq_startup = cp2112_gpio_irq_startup;
@@ -1376,7 +1382,10 @@ static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
 err_gpiochip_remove:
 	gpiochip_remove(&dev->gc);
 err_free_i2c:
+	fwnode_handle_put(dev->gc.fwnode);
 	i2c_del_adapter(&dev->adap);
+err_free_i2c_of:
+	fwnode_handle_put(dev_fwnode(&dev->adap.dev));
 err_power_normal:
 	hid_hw_power(hdev, PM_HINT_NORMAL);
 err_hid_close:
@@ -1391,6 +1400,8 @@ static void cp2112_remove(struct hid_device *hdev)
 	struct cp2112_device *dev = hid_get_drvdata(hdev);
 	int i;
 
+	fwnode_handle_put(dev->gc.fwnode);
+	fwnode_handle_put(dev_fwnode(&dev->adap.dev));
 	sysfs_remove_group(&hdev->dev.kobj, &cp2112_attr_group);
 	i2c_del_adapter(&dev->adap);
 
-- 
2.25.1


  parent reply	other threads:[~2023-02-27 14:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 14:07 [PATCH v8 0/3] Firmware Support for USB-HID Devices and CP2112 Danny Kaehn
2023-02-27 14:07 ` [PATCH v8 1/3] dt-bindings: i2c: Add CP2112 HID USB to SMBus Bridge Danny Kaehn
2023-02-27 14:07 ` [PATCH v8 2/3] HID: usbhid: Share USB device firmware node with child HID device Danny Kaehn
2023-02-27 14:07 ` Danny Kaehn [this message]
2023-02-27 23:07   ` [PATCH v8 3/3] HID: cp2112: Fwnode Support Andy Shevchenko
2023-02-28 19:05     ` Daniel Kaehn
2023-03-01 14:59       ` Andy Shevchenko
2023-03-01 15:04         ` Andy Shevchenko
2023-03-02 17:06         ` Benjamin Tissoires
2023-03-06 10:49           ` Andy Shevchenko
2023-03-06 12:36             ` Benjamin Tissoires
2023-03-06 13:07               ` Andy Shevchenko
2023-03-06 14:48                 ` Benjamin Tissoires
2023-03-06 17:01                   ` Andy Shevchenko
2023-03-06 19:40                     ` Daniel Kaehn
2023-03-06 20:36                       ` Andy Shevchenko
2023-03-07 13:17                         ` Benjamin Tissoires
2023-03-07 13:53                           ` Daniel Kaehn
2023-03-07 14:48                             ` Benjamin Tissoires
2023-03-07 18:18                               ` Andy Shevchenko
2023-03-08 15:26                                 ` Benjamin Tissoires
2023-03-08 15:37                                   ` Daniel Kaehn
2023-03-08 15:55                                     ` Benjamin Tissoires
2023-03-08 16:30                                       ` Andy Shevchenko
2023-03-08 16:36                                         ` Andy Shevchenko
2023-03-08 18:32                                           ` Daniel Kaehn
2023-03-09 11:43                                             ` Andy Shevchenko
2023-03-09 11:56                                               ` Andy Shevchenko
2023-03-09  9:38                                         ` Benjamin Tissoires
2023-03-09 13:50                                           ` Andy Shevchenko
2023-03-08 16:20                                   ` Andy Shevchenko
2023-03-07 18:15                             ` Andy Shevchenko
2023-03-07 18:14                           ` Andy Shevchenko
2023-03-07 19:57                             ` Daniel Kaehn
2023-03-08 12:41                               ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230227140758.1575-4-kaehndan@gmail.com \
    --to=kaehndan@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=ethan.twardy@plexus.com \
    --cc=jikos@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.