From: Andy Shevchenko <andy@kernel.org>
To: Francesco Dolcini <francesco@dolcini.it>
Cc: "Emanuele Ghidoli" <ghidoliemanuele@gmail.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Emanuele Ghidoli" <emanuele.ghidoli@toradex.com>,
"Francesco Dolcini" <francesco.dolcini@toradex.com>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-i2c@vger.kernel.org, "Arnd Bergmann" <arnd@arndb.de>,
soc@kernel.org, "Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: Re: [RFC PATCH v1 2/2] platform: toradex: add preliminary support for Embedded Controller
Date: Thu, 13 Mar 2025 16:53:35 +0200 [thread overview]
Message-ID: <Z9LxbzJ3zf0RT-JS@smile.fi.intel.com> (raw)
In-Reply-To: <20250313144331.70591-3-francesco@dolcini.it>
On Thu, Mar 13, 2025 at 03:43:31PM +0100, Francesco Dolcini wrote:
> Add new platform driver for the Embedded Controller currently used
> in Toradex SMARC iMX8MP and SMARC iMX95.
> It currently provides power-off and restart (reset) handlers.
...
+ array_size.h
+ device.h
+ err.h
> +#include <linux/i2c.h>
+ mod_devicetable,h
> +#include <linux/module.h>
> +#include <linux/reboot.h>
> +#include <linux/regmap.h>
+ types.h
...
> +#define EC_CHIP_ID_REG 0x00
> +#define EC_VERSION_REG_MAJOR 0x01
> +#define EC_VERSION_REG_MINOR 0x02
> +#define EC_CMD_REG 0xD0
> +#define EC_REG_MAX 0xD0
> +
> +#define EC_CHIP_ID_SMARC_IMX95 0x11
> +#define EC_CHIP_ID_SMARC_IMX8MP 0x12
> +
> +#define EC_POWEROFF_CMD 0x01
> +#define EC_RESET_CMD 0x02
Can you interleave the register offsets with the values in them, so we can
easily see the relationship?
...
> +struct tdx_ec {
> + struct i2c_client *client;
Why do you need this? What for?..
> + struct regmap *regmap;
...note, the device pointer you may retrieve from the regmap.
> +};
...
> +static int tdx_ec_register_power_off_restart(struct device *dev, struct tdx_ec *ec)
> +{
> + int err;
> +
> + err = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART,
> + SYS_OFF_PRIO_FIRMWARE,
> + tdx_ec_restart, ec);
> + if (err)
> + return err;
> + err = devm_register_sys_off_handler(dev, SYS_OFF_MODE_POWER_OFF,
> + SYS_OFF_PRIO_FIRMWARE,
> + tdx_ec_power_off, ec);
> + return err;
return devm_...
> +}
...
> +static int tdx_ec_probe(struct i2c_client *client)
> +{
> + struct device *dev = &client->dev;
> + u8 reg_val[EC_ID_VERSION_LEN];
> + struct tdx_ec *ec;
> + int err;
> +
> + ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL);
> + if (!ec)
> + return -ENOMEM;
> +
> + ec->client = client;
> + i2c_set_clientdata(client, ec);
What for?
> + ec->regmap = devm_regmap_init_i2c(client, ®map_config);
> + if (IS_ERR(ec->regmap))
> + return PTR_ERR(ec->regmap);
> +
> + err = regmap_bulk_read(ec->regmap, EC_CHIP_ID_REG, ®_val, EC_ID_VERSION_LEN);
> + if (err)
> + return dev_err_probe(dev, err,
> + "Cannot read id and version registers\n");
> +
> + dev_info(dev, "Toradex Embedded Controller id %x - Firmware %d.%d\n",
Specifiers are semirandom. Why signed? Why x and not %u?
> + reg_val[0], reg_val[1], reg_val[2]);
> + err = tdx_ec_register_power_off_restart(dev, ec);
> + if (err)
> + return dev_err_probe(dev, err,
> + "Cannot register system restart handler\n");
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2025-03-13 14:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 14:43 [RFC PATCH v1 0/2] platform: toradex: Add toradex embedded controller Francesco Dolcini
2025-03-13 14:43 ` [RFC PATCH v1 1/2] dt-bindings: firmware: add toradex,embedded-controller Francesco Dolcini
2025-03-13 14:43 ` [RFC PATCH v1 2/2] platform: toradex: add preliminary support for Embedded Controller Francesco Dolcini
2025-03-13 14:53 ` Andy Shevchenko [this message]
2025-03-17 8:39 ` Francesco Dolcini
2025-03-17 9:31 ` Andy Shevchenko
2025-03-13 14:54 ` [RFC PATCH v1 0/2] platform: toradex: Add toradex embedded controller Andy Shevchenko
2025-03-17 9:31 ` Francesco Dolcini
2025-03-17 9:45 ` Andy Shevchenko
2025-03-13 15:08 ` Hans de Goede
2025-03-17 10:08 ` Francesco Dolcini
2025-03-17 10:14 ` Andy Shevchenko
2025-03-17 10:18 ` Andy Shevchenko
2025-03-17 10:39 ` Hans de Goede
2025-03-17 12:06 ` Andy Shevchenko
2025-03-17 12:08 ` Hans de Goede
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=Z9LxbzJ3zf0RT-JS@smile.fi.intel.com \
--to=andy@kernel.org \
--cc=arnd@arndb.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=emanuele.ghidoli@toradex.com \
--cc=francesco.dolcini@toradex.com \
--cc=francesco@dolcini.it \
--cc=ghidoliemanuele@gmail.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=krzk+dt@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=soc@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox