All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: "Jean-François Lessard" <jefflessard3@gmail.com>
Cc: Andy Shevchenko <andy@kernel.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v5 6/7] auxdisplay: TM16xx: Add support for I2C-based controllers
Date: Mon, 24 Nov 2025 09:31:30 +0200	[thread overview]
Message-ID: <aSQJ0sadpeyiuWRh@smile.fi.intel.com> (raw)
In-Reply-To: <20250926141913.25919-7-jefflessard3@gmail.com>

On Fri, Sep 26, 2025 at 10:19:07AM -0400, Jean-François Lessard wrote:
> Add support for TM16xx-compatible auxiliary display controllers connected
> via the I2C bus.
> 
> The implementation includes:
> - I2C driver registration and initialization
> - Probe/remove logic for I2C devices
> - Controller-specific handling and communication sequences
> - Integration with the TM16xx core driver for common functionality
> 
> This allows platforms using TM16xx or compatible controllers over I2C to be
> managed by the TM16xx driver infrastructure.

...

> +	help
> +	  This driver supports the following TM16XX compatible
> +	  I2C (2-wire) 7-segment led display chips:

LED

> +	  - Titanmec: TM1650
> +	  - Fuda Hisi: FD650, FD655, FD6551
> +	  - i-Core: AiP650
> +	  - Winrise: HBS658
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called tm16xx_i2c and you will also get tm16xx for the
> +	  core module.

...

Please, check the include blocks to follow IWYU principle.

+ array_size.h

> +#include <linux/bitfield.h>
> +#include <linux/device.h>

dev_printk.h
device/devres.h

?

+ err

> +#include <linux/i2c.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/module.h>

+ types.h

...

> +static int tm16xx_i2c_probe(struct i2c_client *client)
> +{
> +	const struct tm16xx_controller *controller;
> +	struct tm16xx_display *display;
> +	int ret;
> +
> +	controller = i2c_get_match_data(client);
> +	if (!controller)
> +		return -EINVAL;
> +
> +	display = devm_kzalloc(&client->dev, sizeof(*display), GFP_KERNEL);
> +	if (!display)
> +		return -ENOMEM;
> +
> +	display->dev = &client->dev;
> +	display->controller = controller;
> +
> +	i2c_set_clientdata(client, display);

> +	ret = tm16xx_probe(display);
> +	if (ret)
> +		return ret;
> +
> +	return 0;

	return tm16xx_probe(...);

> +}

...

> +static void tm16xx_i2c_remove(struct i2c_client *client)
> +{
> +	struct tm16xx_display *display = i2c_get_clientdata(client);
> +
> +	tm16xx_remove(display);
> +}

Just provide dem_tm16xx_probe() and drop this.

...

> +static int tm16xx_i2c_read(struct tm16xx_display *display, u8 cmd, u8 *data, size_t len)
> +{
> +	struct i2c_client *i2c = to_i2c_client(display->dev);
> +
> +	/* expected sequence: S Command [A] [Data] [A] P */
> +	struct i2c_msg msgs[1] = {{

Why an array out of a sudden? Previous function coped with just a single structure.

> +		.addr = cmd >> 1,
> +		.flags = I2C_M_RD | I2C_M_NO_RD_ACK,
> +		.len = len,
> +		.buf = data,
> +	}};
> +	int ret;
> +
> +	ret = i2c_transfer(i2c->adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +
> +	return (ret == ARRAY_SIZE(msgs)) ? 0 : -EIO;
> +}

...

> +static int tm1650_init(struct tm16xx_display *display)
> +{
> +	const enum led_brightness brightness = display->main_led.brightness;
> +	u8 cmds[2];
> +
> +	cmds[0] = TM1650_CMD_CTRL;
> +	cmds[1] = TM16XX_CTRL_BRIGHTNESS(brightness, brightness, TM1650) |
> +		  TM1650_CTRL_SEG8_MODE;
> +
> +	return tm16xx_i2c_write(display, cmds, ARRAY_SIZE(cmds));

For cases of char / u8 the sizeof() is fine.

> +}
> +
> +static int tm1650_data(struct tm16xx_display *display, u8 index,
> +		       unsigned int grid)
> +{
> +	u8 cmds[2];
> +
> +	cmds[0] = TM1650_CMD_ADDR + index * 2;
> +	cmds[1] = grid; /* SEG 1 to 8 */
> +
> +	return tm16xx_i2c_write(display, cmds, ARRAY_SIZE(cmds));

Ditto.

> +}

...

> +static void hbs658_swap_nibbles(u8 *data, size_t len)
> +{
> +	for (size_t i = 0; i < len; i++)
> +		data[i] = (data[i] << 4) | (data[i] >> 4);
> +}

At least these ones
drivers/iio/adc/mcp320x.c:158:          *val = (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
drivers/mtd/tests/nandbiterrs.c:83:     c = (c & 0x0F) << 4 | (c & 0xF0) >> 4;
drivers/usb/atm/ueagle-atm.c:2072:      sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;

use the same code (and I believe more, but that needs a bit more sophisticated `grep`).

Perhaps make it a part of include/linux/swab.h

as

static inline void swab_nibbles(u8 *buf, unsigned int words)
{
	...
}

in a separate patch?

...

> +static int hbs658_init(struct tm16xx_display *display)
> +{
> +	const enum led_brightness brightness = display->main_led.brightness;
> +	u8 cmd;
> +	int ret;
> +
> +	/* Set data command */
> +	cmd = TM16XX_CMD_WRITE | TM16XX_DATA_ADDR_AUTO;
> +	hbs658_swap_nibbles(&cmd, 1);
> +	ret = tm16xx_i2c_write(display, &cmd, 1);
> +	if (ret)
> +		return ret;
> +
> +	/* Set control command with brightness */
> +	cmd = TM16XX_CMD_CTRL |
> +	      TM16XX_CTRL_BRIGHTNESS(brightness, brightness - 1, TM16XX);
> +	hbs658_swap_nibbles(&cmd, 1);

> +	ret = tm16xx_i2c_write(display, &cmd, 1);
> +	if (ret)
> +		return ret;
> +
> +	return 0;

	return tm16xx_i2c_write(display, &cmd, 1);

> +}

...

> +	if (keycode != 0xFF) {

Hmm... Maybe


	if (keycode == 0xFF)
		return 0;

?

Also you use 0xFF magic several times. If it's the same semantically, define it
with name and use everywhere, if it's different we need either comments or a
few definitions for each semantically different case.

> +		col = FIELD_GET(HBS658_KEY_COL_MASK, keycode);
> +		tm16xx_set_key(display, 0, col, true);
> +	}
> +
> +	return 0;

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-11-24  7:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-26 14:19 [PATCH v5 0/7] auxdisplay: Add TM16xx 7-segment LED matrix display controllers driver Jean-François Lessard
2025-09-26 14:19 ` [PATCH v5 1/7] dt-bindings: vendor-prefixes: Add fdhisi, titanmec, princeton, winrise, wxicore Jean-François Lessard
2025-09-26 14:19 ` [PATCH v5 2/7] dt-bindings: leds: add default-brightness property to common.yaml Jean-François Lessard
2025-10-02  2:26   ` Rob Herring (Arm)
2025-10-09 15:06   ` (subset) " Lee Jones
2025-09-26 14:19 ` [PATCH v5 3/7] dt-bindings: auxdisplay: add Titan Micro Electronics TM16xx Jean-François Lessard
2025-10-02  2:44   ` Rob Herring
2025-10-02  2:58     ` Jean-François Lessard
2025-10-31 17:59       ` Jean-François Lessard
2025-09-26 14:19 ` [PATCH v5 4/7] auxdisplay: Add TM16xx 7-segment LED matrix display controllers driver Jean-François Lessard
2025-10-31  9:41   ` Andy Shevchenko
2025-10-31 17:17     ` Jean-François Lessard
2025-11-01 17:06       ` Andy Shevchenko
2025-11-02 17:04         ` Jean-François Lessard
2025-09-26 14:19 ` [PATCH v5 5/7] auxdisplay: TM16xx: Add keypad support for scanning matrix keys Jean-François Lessard
2025-09-26 14:19 ` [PATCH v5 6/7] auxdisplay: TM16xx: Add support for I2C-based controllers Jean-François Lessard
2025-11-24  7:31   ` Andy Shevchenko [this message]
2025-09-26 14:19 ` [PATCH v5 7/7] auxdisplay: TM16xx: Add support for SPI-based controllers Jean-François Lessard

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=aSQJ0sadpeyiuWRh@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=jefflessard3@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=robh@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.