Linux RTC
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Atharva Tiwari <atharvatiwarilinuxdev@gmail.com>
Cc: "Ihor Odainyi" <pv4k@odayny.com>,
	"Antoine Sidem" <sidemantoine@gmail.com>,
	"Aditya Garg" <aditya.garg@linux.dev>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Len Brown" <lenb@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	"Sven Peter" <sven@kernel.org>, "Janne Grunau" <j@jannau.net>,
	"Neal Gompa" <neal@gompa.dev>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>, "Lee Jones" <lee@kernel.org>,
	"Pavel Machek" <pavel@kernel.org>,
	"Griffin Kroah-Hartman" <griffin@kroah.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Wim Van Sebroeck" <wim@linux-watchdog.org>,
	"Jarkko Sakkinen" <jarkko@kernel.org>,
	"Mimi Zohar" <zohar@linux.ibm.com>,
	"Roberto Sassu" <roberto.sassu@huawei.com>,
	"Dmitry Kasatkin" <dmitry.kasatkin@gmail.com>,
	"Eric Snowberg" <eric.snowberg@oracle.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-acpi@vger.kernel.org, linux-gpio@vger.kernel.org,
	asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-hwmon@vger.kernel.org, linux-iio@vger.kernel.org,
	linux-leds@vger.kernel.org, mfd@lists.linux.dev,
	platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org,
	linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
	linux-security-module@vger.kernel.org
Subject: Re: [PATCH 02/14] platform/x86: add backend for macsmc in intel macs
Date: Fri, 4 Dec 2026 16:19:17 +0200	[thread overview]
Message-ID: <axLL5X8wA-DULZgY@ashevche-desk.local> (raw)
In-Reply-To: <20261204131619.5059-3-atharvatiwarilinuxdev@gmail.com>

On Fri, Dec 04, 2026 at 08:12:42AM -0500, Atharva Tiwari wrote:
> Add a backend that talks to the SMC on Intel Macs over ACPI.
> It supports the old I/O port interface, and also MMIO and
> interrupt-driven completion, which applesmc doesn't have.
> If an interrupt is missed it falls back to polling.
> 
> This is the base that lets the macsmc drivers replace
> applesmc.

...

> +#include <linux/acpi.h>
> +#include <linux/bits.h>

> +#include <linux/byteorder/generic.h>

Wrong, the asm/byteorder.h has to be used.

> +#include <linux/cleanup.h>
> +#include <linux/compiler.h>
> +#include <linux/completion.h>
> +#include <linux/device.h>
> +#include <linux/devm-helpers.h>
> +#include <linux/interrupt.h>
> +#include <linux/io.h>

> +#include <linux/ioport.h>

> +#include <linux/iopoll.h>

With this, io.h is not required.

> +#include <linux/kfifo.h>
> +#include <linux/mfd/macsmc.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/platform_device.h>
> +#include <linux/pm.h>
> +#include <linux/reboot.h>
> +#include <linux/spinlock.h>
> +#include <linux/time.h>
> +#include <linux/types.h>
> +#include <linux/unaligned.h>
> +#include <linux/workqueue.h>

...

> +#define SMC_TIMEOUT_MS			1000

Why not (1 * MSEC_PER_SEC) here ?

...

> +struct apple_smc_acpi {
> +	struct device *dev;
> +
> +	u8 __iomem *iomem_base;
> +	u32 iomem_base_addr, iomem_base_size;
> +	bool is_mmio;
> +
> +	u16 port_base;
> +	bool has_port;
> +
> +	int irq;

> +	bool has_interrupt;

Why? Isn't non-positive value means no interrupt?

> +	bool interrupt_enabled;

Why? Isn't IRQ core provides something for this?

> +	struct completion cmd_done;
> +
> +	struct blocking_notifier_head event_handlers;
> +	struct work_struct shutdown_work;
> +	struct work_struct notifier_work;
> +
> +	DECLARE_KFIFO(event_fifo, u8, 64);
> +	/* Protects event_fifo, shared between the IRQ handler and notifier_work */
> +	spinlock_t event_lock;
> +};
> +
> +

Why double blank line?

> +static int apple_smc_acpi_port_wait(struct apple_smc_acpi *smc, u8 val, u8 mask)
> +{
> +	u8 status;
> +	int ret;
> +
> +	if (smc->interrupt_enabled) {
> +		reinit_completion(&smc->cmd_done);
> +		if (wait_for_completion_timeout(&smc->cmd_done,
> +					msecs_to_jiffies(SMC_TIMEOUT_MS)) > 0)
> +			return 0;
> +
> +		smc->interrupt_enabled = 0;
> +		dev_dbg(smc->dev, "mmio/wait: interrupt missed, reverting to polling\n");
> +	}
> +
> +	ret = read_poll_timeout(inb, status, (status & mask) == val,
> +				USEC_PER_MSEC, SMC_TIMEOUT_MS * USEC_PER_MSEC,
> +				false, smc->port_base + SMC_IO_CMD_PORT);
> +	if (ret)
> +		dev_dbg(smc->dev, "port/wait: timeout value:%u, mask:%u\n", val, mask);
> +
> +	return ret;
> +}

...

> +static int apple_smc_acpi_port_write_key(struct apple_smc_acpi *smc, smc_key key)
> +{
> +	int i;
> +
> +	for (i = 3; i >= 0; i--) {
> +		if (apple_smc_acpi_port_write_byte(smc, (key >> (i * 8)) & 0xff))
> +			return -EIO;
> +	}

Missing blank line.

> +	return 0;

This should use proper __be32 type instead.

> +}
> +
> +static int apple_smc_acpi_port_valid(struct apple_smc_acpi *smc)
> +{
> +	int ret;

> +	ret = apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
> +	if (!ret)

Huh?! This is way non-standard. Don't do that.
This is a semantic mistake.

> +		return ret;
> +
> +	ret = apple_smc_acpi_port_write_cmd(smc, SMC_MSG_READ_KEY);
> +	if (ret)
> +		return ret;
> +
> +	return apple_smc_acpi_port_wait(smc, 0, SMC_IO_STATUS_BUSY);
> +}

...

> +static const struct acpi_device_id apple_smc_acpi_ids[] = {
> +	{"APP0001", 0},
> +	{}
> +};

Where have you been last half a year?

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2026-12-04 14:19 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:12 [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc Atharva Tiwari
2026-12-04 13:12 ` [PATCH 01/14] treewide: Add backend for macsmc Atharva Tiwari
2026-12-04 13:56   ` sashiko-bot
2026-12-04 14:07   ` Andy Shevchenko
2026-12-04 16:45   ` Sven Peter
2026-12-04 13:12 ` [PATCH 02/14] platform/x86: add backend for macsmc in intel macs Atharva Tiwari
2026-12-04 13:58   ` sashiko-bot
2026-12-04 14:19   ` Andy Shevchenko [this message]
2026-12-04 14:52     ` Aditya Garg
2026-12-04 17:23       ` Andy Shevchenko
2026-12-04 18:34         ` Aditya Garg
2026-12-04 19:57     ` Atharva Tiwari
2026-12-04 20:23       ` Andy Shevchenko
2026-12-04 13:12 ` [PATCH 03/14] watchdog: add driver for apple smc Atharva Tiwari
2026-12-04 13:48   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 04/14] iio/light: add new driver for macsmc Atharva Tiwari
2026-12-04 13:47   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 05/14] iio/accel: add driver for apple SMS Atharva Tiwari
2026-12-04 14:11   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 06/14] leds: add support for macsmc kbl Atharva Tiwari
2026-12-04 14:07   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 07/14] rtc: add support for x86 macs in macsmc-rtc Atharva Tiwari
2026-12-04 14:12   ` Andy Shevchenko
2026-12-04 14:48     ` Aditya Garg
2026-12-04 17:06       ` Andy Shevchenko
2026-12-04 17:10         ` Aditya Garg
2026-12-04 17:18           ` Andy Shevchenko
2026-12-04 17:26       ` Sven Peter
2026-12-04 14:16   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 08/14] treewide: Add a flag to detect the Apple T2 chip Atharva Tiwari
2026-12-04 14:11   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 09/14] treewide: disable other rtc's in t2 macs Atharva Tiwari
2026-12-04 14:27   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 10/14] power/supply: add support for x86 macs in macsmc-power Atharva Tiwari
2026-12-04 14:39   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 11/14] acpi: disable battery and adapter for x86 apple machines Atharva Tiwari
2026-12-04 14:08   ` Andy Shevchenko
2026-12-04 14:56     ` Aditya Garg
2026-12-04 17:14       ` Andy Shevchenko
2026-12-04 18:51         ` Aditya Garg
2026-12-04 20:02           ` Andy Shevchenko
2026-12-04 20:13             ` Andy Shevchenko
2026-12-04 14:25   ` sashiko-bot
2026-12-04 13:12 ` [PATCH 12/14] hwmon/macsmc: add more types Atharva Tiwari
2026-12-04 14:37   ` sashiko-bot
2026-12-04 18:44     ` Guenter Roeck
2026-12-04 13:12 ` [PATCH 13/14] hwmon: add support for x86 macs in macsmc-hwmon Atharva Tiwari
2026-12-04 14:48   ` sashiko-bot
2026-12-04 18:45     ` Guenter Roeck
2026-12-04 20:13       ` Jarkko Sakkinen
2026-12-04 13:12 ` [PATCH 14/14] mfd/macsmc: add ioctl to access smc keys Atharva Tiwari
2026-12-04 14:48   ` sashiko-bot
2026-12-04 14:20 ` [PATCH 00/14] Add macsmc support for Intel Macs, replacing applesmc 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=axLL5X8wA-DULZgY@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=aditya.garg@linux.dev \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy@kernel.org \
    --cc=asahi@lists.linux.dev \
    --cc=atharvatiwarilinuxdev@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=brgl@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=dlechner@baylibre.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=griffin@kroah.com \
    --cc=hansg@kernel.org \
    --cc=hpa@zytor.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=j@jannau.net \
    --cc=jarkko@kernel.org \
    --cc=jic23@kernel.org \
    --cc=jmorris@namei.org \
    --cc=keyrings@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mfd@lists.linux.dev \
    --cc=mingo@redhat.com \
    --cc=neal@gompa.dev \
    --cc=nuno.sa@analog.com \
    --cc=paul@paul-moore.com \
    --cc=pavel@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=pv4k@odayny.com \
    --cc=rafael@kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=serge@hallyn.com \
    --cc=sidemantoine@gmail.com \
    --cc=sre@kernel.org \
    --cc=sven@kernel.org \
    --cc=tglx@kernel.org \
    --cc=wim@linux-watchdog.org \
    --cc=x86@kernel.org \
    --cc=zohar@linux.ibm.com \
    /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