Page MenuHomeFreeBSD

gpio: Add support for mcp23008/mcp23017/mcp23s08/mcp23s17 IO expanders
Needs ReviewPublic

Authored by devivanov_proton.me on Aug 29 2025, 8:50 PM.
Tags
None
Referenced Files
F131981149: D52246.id161211.diff
Sun, Oct 12, 4:48 PM
Unknown Object (File)
Thu, Oct 9, 5:23 PM
Unknown Object (File)
Fri, Oct 3, 11:38 AM
Unknown Object (File)
Fri, Oct 3, 8:16 AM
Unknown Object (File)
Wed, Oct 1, 9:01 AM
Unknown Object (File)
Wed, Oct 1, 7:23 AM
Unknown Object (File)
Tue, Sep 30, 8:53 AM
Unknown Object (File)
Thu, Sep 25, 8:33 PM
Subscribers

Details

Summary

Add support for mcp23xxx IO expanders, SPI and IIC variants. Interrupt support left out for now.

Test Plan

Tested via gpioctl(1)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 66720
Build 63603: arc lint + arc unit

Event Timeline

The new files (excluding the makefiles) are missing licenses.

sys/conf/files
1737–1738
sys/dev/gpio/mcp23017.c
16

This is unused.

42

Wouldn't buf[1] be uninitialized if sc->npin isn't 16?

65–66
117–131

We traditionally put these here.

sys/dev/gpio/mcp23s17.c
37

Not very familiar with the SPI stuff. Is this guaranteed to work? It looks odd to me.

71–72
105–106
sys/dev/gpio/mcp23xxx.c
78
103
152

I'm confused by this. What does pin direction have to do with toggling the pin?

291

I know this is done elsewhere, but style(9) prohibits it.

Update code for style(9)
Add licenses
Fix pin toggle using sc->dir instead of sc->gpio

sys/dev/gpio/mcp23017.c
42

It should be fine since the upper bits aren't used if npin is not 16, but not 100% sure.
Could default initialise the buffer.

sys/dev/gpio/mcp23s17.c
37

It might actually be driver dependent, if it sends the data before receiving. Might require a discard buffer just in case.

The inline comments are in wildly incorrect places now, I'm not sure if I can fix that.

sys/dev/gpio/mcp23017.c
42

It should be fine since the upper bits aren't used if npin is not 16, but not 100% sure.

They are used either way.

(uint16_t)buf[1] << 8

Could default initialise the buffer.

I think it would be better to explicitly initialize it to zero. Default initialization is a C23 extension. :)

sys/dev/gpio/mcp23017.c
42

I think it would be better to explicitly initialize it to zero. Default initialization is a C23 extension. :)

Correction: empty initialization is a C23 thing.