Skip to content

Conversation

@agordon
Copy link

@agordon agordon commented Apr 17, 2021

This small driver creates an LCD device (/dev/lcd)
for HD44780 LCD over I2C. These modules typically use the PCF8574 chip
to convert I2C input to HD44780's SPI protocol.

signed-off-by: Assaf Gordon [email protected]

@agordon
Copy link
Author

agordon commented Apr 17, 2021

Dear RPI/Linux devs,

I would like to offer a small new driver+overlay to work with the very common HD44780 LCD module over I2C.
E.g. this module: https://tutorials-raspberrypi.com/control-a-raspberry-pi-hd44780-lcd-display-via-i2c/ .
This patch is against rpi-5.12.y branch (not the current rpi-5.10.y because it doesn't have the refactored hd44780_common.c file).
The driver is a thin layer connecting the hd47800_common driver with the i2c bus using i2c_smbus_write_byte .

As I'm not a kernel developer, I'm certain there will be some needed changes - feedback and suggestions very welcomed.
Thanks!

popcornmix and others added 29 commits April 19, 2021 12:14
Possible fixed upstream by 'net: bcmgenet: keep MAC in reset until PHY is up'

Signed-off-by: popcornmix <[email protected]>
Adds a format that is 3 10bit YUV 4:2:0 samples packed into
a 32bit work (with 2 spare bits).

Supported on Broadcom BCM2711 chips.

Signed-off-by: Dave Stevenson <[email protected]>
Taken from https://patchwork.linuxtv.org/patch/60728/
Changes (mainly documentation) have been requested.

HEVC has a scaling matrix concept. Add support for it.

Signed-off-by: Jernej Skrabec <[email protected]>
From https://patchwork.linuxtv.org/patch/60725/
Changes requested, but mainly docs.

If HEVC frame consists of multiple slices, segment address has to be
known in order to properly decode it.

Add segment address field to slice parameters.

Signed-off-by: Jernej Skrabec <[email protected]>
Adds V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT define.

Signed-off-by: Dave Stevenson <[email protected]>
WPP can allow greater parallelism within the decode, but needs
offset information to be passed in.

Adds num_entry_point_offsets and entry_point_offset_minus1 to
v4l2_ctrl_hevc_slice_params.

This is based on Jernej Skrabec's patches for cedrus which
implement the same feature.

Signed-off-by: Dave Stevenson <[email protected]>
Some of the Broadcom codec blocks use a column based YUV4:2:0 image
format, so add the documentation and defines for both 8 and 10 bit
versions.

Signed-off-by: Dave Stevenson <[email protected]>
…nish

Allow the capture buffer to be detached from a v4l2 request job such
that another job can start before the capture buffer is returned. This
allows h/w codecs that can process multiple requests at the same time
to operate more efficiently.

Signed-off-by: John Cox <[email protected]>
Adds a binding for the HEVC decoder found on the BCM2711 / Raspberry Pi 4.

Signed-off-by: Dave Stevenson <[email protected]>
This driver is for the HEVC/H265 decoder block on the Raspberry
Pi 4, and conforms to the V4L2 stateless decoder API.

Signed-off-by: John Cox <[email protected]>
When the MMC isn't plugged in, the driver will spam the console which is
pretty annoying when using NFS.

Signed-off-by: Maxime Ripard <[email protected]>
The firmare running on the RPi VideoCore can be used to discover and
change the various clocks running in the BCM2711. Since devices will
need to use them through the DT, let's add a pretty simple binding.

Cc: Michael Turquette <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Maxime Ripard <[email protected]>
The HDMI controllers found in the BCM2711 SoC need some adjustments to the
bindings, especially since the registers have been shuffled around in more
register ranges.

Cc: Rob Herring <[email protected]>
Cc: [email protected]
Signed-off-by: Maxime Ripard <[email protected]>
framebuffer_check was computing a minimum pitch value and ensuring
that the provided value was greater than this.
That check is only valid if the format is linear.

Signed-off-by: Dave Stevenson <[email protected]>
Commit f3186dd ("spi: Optionally use GPIO descriptors for CS GPIOs")
amended of_spi_parse_dt() to always set SPI_CS_HIGH for SPI slaves whose
Chip Select is defined by a "cs-gpios" devicetree property.

This change breaks drivers whose probe functions set the mode field of
the spi_device because in doing so they clear the SPI_CS_HIGH flag.

Fix by setting SPI_CS_HIGH in spi_setup (under the same conditions as
in of_spi_parse_dt()).

See also: 83b2a8f ("spi: spidev: Fix CS polarity if GPIO descriptors are used")

Fixes: f3186dd ("spi: Optionally use GPIO descriptors for CS GPIOs")
Signed-off-by: Phil Elwell <[email protected]>

SQUASH: spi: Demote SPI_CS_HIGH warning to KERN_DEBUG

This warning is unavoidable from a client's perspective and
doesn't indicate anything wrong (just surprising).

SQUASH with "spi: use_gpio_descriptor fixup moved to spi_setup"

Signed-off-by: Phil Elwell <[email protected]>
Limit mappings to the permitted range, but don't map more than asked
for otherwise we walk off the end of the allocated VMA.

Signed-off-by: Phil Elwell <[email protected]>
Add driver for the Unicam camera receiver block on
BCM283x processors.

This commit is made up of a series of changes cherry-picked from the
rpi-4.19.y branch.

Signed-off-by: Dave Stevenson <[email protected]>
Signed-off-by: Naushir Patuck <[email protected]>
Add V4L2_META_FMT_SENSOR_DATA format 4CC.

This new format will be used by the BCM2835 Unicam device to return
out camera sensor embedded data.

Signed-off-by: Naushir Patuck <[email protected]>
This patch adds MEDIA_BUS_FMT_SENSOR_DATA used by the bcm2835-unicam
driver to support CSI-2 embedded data streams from camera sensors.

Signed-off-by: Naushir Patuck <[email protected]>
Move device node specific state out of the device state structure and
into a new node structure.  This separation will be needed for future
changes where we will add an embedded data node to the driver to work
alongside the existing image data node.

Currently only use a single image node, so this commit does not add
any functional changes.

Signed-off-by: Naushir Patuck <[email protected]>
This patch adds a new node in the bcm2835-unicam driver to support
CSI-2 embedded data streams.  The subdevice is queried to see if
embedded data is available from the sensor.

Signed-off-by: Naushir Patuck <[email protected]>
If no buffer has been queued by a userland application, we use an
internal dummy buffer for the hardware to spin in. This will allow
the driver to release the existing userland buffer back to the
application for processing.

Signed-off-by: Naushir Patuck <[email protected]>
The unicam driver supports both the SOURCE_CHANGE and CTRL events. Both
events are only generated on the image video node, so the event-related
ioctls are useless on the medatada node. Disable them.

Signed-off-by: Laurent Pinchart <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
Reviewed-by: Naushir Patuck <[email protected]>
The FRAME_SYNC event is useful for userspace image processing algorithms
to program the camera sensor as early as possible after frame start.
Support it.

Signed-off-by: Laurent Pinchart <[email protected]>
Reviewed-by: Kieran Bingham <[email protected]>
Reviewed-by: Jacopo Mondi <[email protected]>
Reviewed-by: Naushir Patuck <[email protected]>
The sensor subdevice may change the Bayer order if a H/V flip is
requested after a s_fmt call.  Unicam g_fmt must call the subdev get_fmt
in case this has happened and return out the correct format 4cc.

Signed-off-by: Naushir Patuck <[email protected]>
Add V4L2_META_FMT_BCM2835_ISP_STATS V4L2 format type.

This new format will be used by the BCM2835 ISP device to return
out ISP statistics for 3A.

Signed-off-by: Naushir Patuck <[email protected]>
We are reserving controls for the new bcm2835-isp driver.

Signed-off-by: Naushir Patuck <[email protected]>
bcmn2835_isp is a platform driver dependent on vchiq,
therefore add the load/unload functions for it to vchiq.

Signed-off-by: Naushir Patuck <[email protected]>
pelwell and others added 11 commits April 19, 2021 12:15
1. Reduce the delay between RELAY1 and RELAY2 to 1000ms.
2. Rename the states to simplify LED control by an external script.
3. Claim all the required GPIOs, enabling pull-ups on the input.

Signed-off-by: Phil Elwell <[email protected]>
Neither CM4 nor Pi 400 have appeared upstream yet, and as a result
they have missed out on improvements to the Pi 4B platform.

Signed-off-by: Phil Elwell <[email protected]>

ARM: dts: Bring bcm2711-rpi-400.dts up-to-date

Pi 400 support has not appeared upstream yet, and as a result it has
missed out on improvements to the other Pi 4 platforms.

Signed-off-by: Phil Elwell <[email protected]>
warning: attribute declaration must precede definition
warning: variable 'retval' is used uninitialized whenever 'if' condition is false
warning: address of array 'desc->wMaxPacketSize' will always evaluate to 'true'

The wMaxPacketSize field is actually a two element array which content should
be accessed via the UGETW macro.
Add unique names to the individual dac coded drivers
Remove some of the codec controls that are not used.

Signed-off-by: Paul Hermann <[email protected]>

# Conflicts:
#	sound/soc/bcm/allo-piano-dac-plus.c
Commit 158e800 upstream

A test was added to the probe function to ensure the device was
actually connected and working before successfully completing a
probe.  If the device was actually there, but the I2C bus was not
ready yet for whatever reason, the probe fails permanently.

Change the probe so that we defer the probe on a regmap read
failure so that we try the probe again when the dependent drivers
are potentially loaded.  This should not affect the case where the
device truly isn't present because the probe will never successfully
complete.

Fixes: 2aa916e ("sc16is7xx: Read the LSR register for basic device presence check")
Cc: [email protected]
Signed-off-by: Annaliese McDermond <[email protected]>
Link: https://lore.kernel.org/r/010101787f9c3fd8-c1815c00-2d6b-4c85-a96a-a13e68597fda-000000@us-west-2.amazonses.com
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Commit 1ca1156 upstream

Clock registration must be performed before the component is
registered.  aic32x4_component_probe attempts to get all the
clocks right off the bat.  If the component is registered before
the clocks there is a race condition where the clocks may not
be registered by the time aic32x4_componet_probe actually runs.

Fixes: d1c859d ("ASoC: codec: tlv3204: Increased maximum supported channels")
Cc: [email protected]
Signed-off-by: Annaliese McDermond <[email protected]>
Link: https://lore.kernel.org/r/0101017889850206-dcac4cce-8cc8-4a21-80e9-4e4bef44b981-000000@us-west-2.amazonses.com
Signed-off-by: Mark Brown <[email protected]>
Commit 29654ed upstream

AIC32X4_REFPOWERUP was added as a register, but the maximum register value
in the regmap and regmap range was not correspondingly increased.  This
caused an error when this register was attempted to be written.

Fixes: ec96690 ("ASoC: tlv320aic32x4: Enable fast charge")
Cc: [email protected]
Signed-off-by: Annaliese McDermond <[email protected]>
Link: https://lore.kernel.org/r/0101017889851cab-ce60cfdb-d88c-43d8-bbd2-7fbf34a0c912-000000@us-west-2.amazonses.com
Signed-off-by: Mark Brown <[email protected]>
This small driver creates an LCD device (/dev/lcd)
for HD44780 LCD over I2C. These modules typically use the PCF8574 chip
to convert I2C input to HD44780's SPI protocol.

signed-off-by: Assaf Gordon <[email protected]>
Copy link
Contributor

@pelwell pelwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver looks plausible, and apart from a few minor niggles with the README etc. the overlay looks good. The real problem is that this driver should be submitted upstream - it is not Pi-specific in any way, and we can't take on maintenance of random bits of code like this.

display_width Width of the display in characters


Name: hd44780-i2c-lcd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section should come before hd44780-lcd.


Name: hd44780-i2c-lcd
Info: Configures an HD44780 compatible LCD display over I2C bus.
These LCD module typically use the PCF8574D chip to convert I2C to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line starts with a hard TAB character - it should be 8 spaces.

@@ -0,0 +1,32 @@
/dts-v1/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overlay needs an entry in the Makefile, otherwise it won't be compiled.

@6by9
Copy link
Contributor

6by9 commented Apr 21, 2021

checkpatch has a fair few complaints too. Best to fix those before considering submitting upstream.

WARNING: 'Signed-off-by:' is the preferred signature form
#10: 
signed-off-by: Assaf Gordon <[email protected]>

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#69: 
new file mode 100644

WARNING: Block comments use * on subsequent lines
#96: FILE: drivers/auxdisplay/hd44780-i2c.c:23:
+/*
+  I2C/hd88470 bits in 4-bit GPIO mode:

WARNING: Block comments use * on subsequent lines
#164: FILE: drivers/auxdisplay/hd44780-i2c.c:91:
+/* Write 4bits of data to the HD44780 through i2c bus.
+   Three i2c 'write' commands are issues, toggling the "EN/ENALBLE" bit.

WARNING: Avoid unnecessary line continuations
#184: FILE: drivers/auxdisplay/hd44780-i2c.c:111:
+		pr_err("write_gpio4_nibble, part 1: " \

WARNING: Avoid unnecessary line continuations
#192: FILE: drivers/auxdisplay/hd44780-i2c.c:119:
+		pr_err("write_gpio4_nibble, part 2: " \

WARNING: Avoid unnecessary line continuations
#200: FILE: drivers/auxdisplay/hd44780-i2c.c:127:
+		pr_err("write_gpio4_nibble, part 3: " \

WARNING: Block comments use * on subsequent lines
#210: FILE: drivers/auxdisplay/hd44780-i2c.c:137:
+/* writes an octet (8bit) to the hd44780 through the I2C bus,
+ by splitting the octet to two nibbles and sending them. */

WARNING: Block comments use a trailing */ on a separate line
#210: FILE: drivers/auxdisplay/hd44780-i2c.c:137:
+ by splitting the octet to two nibbles and sending them. */

CHECK: spaces preferred around that '|' (ctx:VxV)
#219: FILE: drivers/auxdisplay/hd44780-i2c.c:146:
+	ret = hd44780_i2c_write_gpio4_nibble(hdc, (data & 0xF0)|rs|bl);
 	                                                       ^

CHECK: spaces preferred around that '|' (ctx:VxV)
#219: FILE: drivers/auxdisplay/hd44780-i2c.c:146:
+	ret = hd44780_i2c_write_gpio4_nibble(hdc, (data & 0xF0)|rs|bl);
 	                                                          ^

CHECK: spaces preferred around that '<<' (ctx:VxV)
#223: FILE: drivers/auxdisplay/hd44780-i2c.c:150:
+	ret = hd44780_i2c_write_gpio4_nibble(hdc, (data & 0x0F)<<4|rs|bl);
 	                                                       ^

CHECK: spaces preferred around that '|' (ctx:VxV)
#223: FILE: drivers/auxdisplay/hd44780-i2c.c:150:
+	ret = hd44780_i2c_write_gpio4_nibble(hdc, (data & 0x0F)<<4|rs|bl);
 	                                                          ^

CHECK: spaces preferred around that '|' (ctx:VxV)
#223: FILE: drivers/auxdisplay/hd44780-i2c.c:150:
+	ret = hd44780_i2c_write_gpio4_nibble(hdc, (data & 0x0F)<<4|rs|bl);
 	                                                             ^

CHECK: Alignment should match open parenthesis
#236: FILE: drivers/auxdisplay/hd44780-i2c.c:163:
+		pr_err("write_cmd_gpio4: failed to send 0x%02x, ret = %d",
+			cmd, ret);

CHECK: Alignment should match open parenthesis
#241: FILE: drivers/auxdisplay/hd44780-i2c.c:168:
+static void hd44780_i2c_write_cmd_raw_gpio4(struct hd44780_common *hdc,
+						int cmd)

CHECK: Alignment should match open parenthesis
#249: FILE: drivers/auxdisplay/hd44780-i2c.c:176:
+		pr_err("write_cmd_raw_gpio4: failed to send 0x%02x, ret = %d",
+			cmd, ret);

WARNING: Missing a blank line after declarations
#258: FILE: drivers/auxdisplay/hd44780-i2c.c:185:
+	int ret = hd44780_i2c_write_gpio4_byte(hdc, data, DATA, BACKLIGHT_ON);
+	if (ret)

CHECK: Alignment should match open parenthesis
#260: FILE: drivers/auxdisplay/hd44780-i2c.c:187:
+		pr_err("write_data_gpio4: failed to send 0x%02x, ret = %d",
+			data, ret);

CHECK: Alignment should match open parenthesis
#264: FILE: drivers/auxdisplay/hd44780-i2c.c:191:
+static int hd44780_i2c_probe(struct i2c_client *client,
+				const struct i2c_device_id *id)

CHECK: Alignment should match open parenthesis
#307: FILE: drivers/auxdisplay/hd44780-i2c.c:234:
+	pr_debug("hd44780-i2c: width: %d, height: %d",
+		lcd->width, lcd->height);

WARNING: DT compatible string "hit,hd44780_i2c" appears un-documented -- check ./Documentation/devicetree/bindings/
#367: FILE: drivers/auxdisplay/hd44780-i2c.c:294:
+		.compatible = "hit,hd44780_i2c",

total: 0 errors, 11 warnings, 11 checks, 354 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] hd44780-i2c-lcd: new driver and overlay" has style problems, please review.

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.

(Note that that was ./scripts/checkpatch.pl --strict --codespell which most of the upstream reviewers will be using).

But also isn't the HD44780 over I2C is actually just an HD44780 with a PCF8574 I2C GPIO chip strapped to the front? Rereading your overlay readme confirms that.
The same result can therefore be achieved using the existing HD44780 driver and the PCF857x driver (CONFIG_GPIO_PCF857X) configured through device tree. It's more I2C traffic as each bit will be changed individually, but I suspect it would be the preferred solution upstream.

@oniongarlic
Copy link
Contributor

Just noticed this and I've been planing on submitting this overlay someday, but just haven't had the time to dig into how to do that properly. As noted above, a separate driver is not needed as you can just plug into into the existing one.

pcf8574-hd44780.dts.txt

@pelwell
Copy link
Contributor

pelwell commented Apr 21, 2021

Thanks - that looks like a better solution since the PCF8574 driver exists and is more fully featured.

@popcornmix popcornmix force-pushed the rpi-5.12.y branch 2 times, most recently from 496bd6f to 8f357c9 Compare May 13, 2021 16:57
@popcornmix popcornmix force-pushed the rpi-5.12.y branch 2 times, most recently from 7818498 to 94535fc Compare May 25, 2021 10:13
@pelwell
Copy link
Contributor

pelwell commented May 25, 2021

@agordon Are you happy to use the alternative overlay suggested above? Rename it to match your overlay and README entry, then drop your driver and the associated Kconfig and Makefile changes.

@agordon
Copy link
Author

agordon commented May 30, 2021

Hi,

@agordon Are you happy to use the alternative overlay suggested above?

I could not get this overlay to work, but it could be just me.

The hd44780 driver does software big-banging of one-sided SPI protocol using 4 GPIOs, not sure how you overlay this over the pcf8574 driver - but again, I'm far from an expert on this.

I would say, that kernel developers split the old hd44780 driver into two parts - hd44780_common.c (the protocol commands) and hd44780.c (the SPI physical layer) - and they did that exactly so that other physical layers could be added (e.g. hd44780-over-I2C instead SPI, just like me patch above adds).

However, if you are able to make this alternative overlay work - then by all means, I'm happy to use it (perhaps adding some documentation could be useful?).

@popcornmix popcornmix force-pushed the rpi-5.12.y branch 2 times, most recently from 58483d2 to cc33d27 Compare June 14, 2021 11:45
@popcornmix popcornmix force-pushed the rpi-5.12.y branch 2 times, most recently from 06ba288 to ed4c467 Compare July 15, 2021 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.