Commit Graph

166 Commits

Author SHA1 Message Date
Clark Wang 33beadb3b1 i3c: master: svc: fix cpu schedule in spin lock
pm_runtime_resume_and_get() may call sleep(). It cannot be used in
svc_i3c_master_start_xfer_locked(), because it is in a spin lock.

Move the pm runtime operations to svc_i3c_master_enqueue_xfer().

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Fixes: 05be23ef78 ("i3c: master: svc: add runtime pm support")
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230517033030.3068085-2-xiaoning.wang@nxp.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-06-05 00:50:51 +02:00
Clark Wang 1c5ee2a77b i3c: master: svc: fix i3c suspend/resume issue
When system suspends, if i3c module is powered down, register
value will lose.
Need to save the key registers before system suspend.
So save these registers value in runtime pm suspend, and restore them
if these register's value is different with the saved values
when runtime pm resume.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230517033030.3068085-1-xiaoning.wang@nxp.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-06-05 00:50:51 +02:00
Tom Rix 6b496a94c5 i3c: ast2600: set variable ast2600_i3c_ops storage-class-specifier to static
smatch reports
drivers/i3c/master/ast2600-i3c-master.c:121:34: warning: symbol
  'ast2600_i3c_ops' was not declared. Should it be static?

This variable is only used in its defining file, so it should be static.

Signed-off-by: Tom Rix <trix@redhat.com>
Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/20230429134601.2688558-1-trix@redhat.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-30 23:50:26 +02:00
Jeremy Kerr 8c6c78ee3b i3c: ast2600: fix register setting for 545 ohm pullups
The 2k register setting is zero, OR-ing it in doesn't parallel the 2k
and 750 ohm pullups. We need a separate value for the 545 ohm setting.

Reported-by: Lukwinski Zbigniew <zbigniew.lukwinski@linux.intel.com>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/20230428001849.1775559-1-jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:52:23 +02:00
Jeremy Kerr f2539c2079 i3c: ast2600: enable IBI support
The ast2600 i3c hardware is capable of IBIs, but we need a workaround
for a hardware issue with the I3C state machine handling IBI payloads
of specific lengths when PEC is not enabled. To avoid this, we need to
unconditionally enable PECs, at the consquence of losing a byte of data
when the device does not send a PEC.

Enable IBIs on the ast2600 platform, including an implementation of the
PEC workaround, which prints a warning when triggered.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/ba923b96d6d129024c975e8a0472c5b2fcb3af32.1680161823.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:49:50 +02:00
Jeremy Kerr f3a3553a51 i3c: dw: Add a platform facility for IBI PEC workarounds
On the AST2600 i3c controller, we'll need to apply a workaround for a
hardware issue with IBI payloads.

Introduce a platform hook to allow dw i3c platform implementations to
modify the DAT entry in IBI enable/disable to allow this workaround in a
future change.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/d5d76a8d2336d2a71886537f42e71d51db184df6.1680161823.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:20:07 +02:00
Jeremy Kerr e389b1d72a i3c: dw: Add support for in-band interrupts
This change adds support for receiving and dequeueing i3c IBIs.

By setting struct dw_i3c_master->ibi_capable before probe, a platform
implementation can select the IBI-enabled version of the i3c_master_ops,
enabling the global IBI infrastrcture for that controller.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/79daeefd7ccb7c935d0c159149df21a6c9a73ffa.1680161823.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:20:07 +02:00
Jeremy Kerr e2d43101f6 i3c: dw: Turn DAT array entry into a struct
In an upcoming change, we will want to store additional data about the
devices we have in the data address table.

Change the type of the DAT entries into a struct, which currently just
has the address data.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/9dc0d9e2857e851a0cf04819df48e5d31921f83e.1680161823.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:20:07 +02:00
Jeremy Kerr 79f42b31c2 i3c: dw: Create a generic fifo read function
In a future change we'll want to read from the IBI FIFO too, so turn
dw_i3c_read_rx_fifo() into a generic read with the FIFO register as a
parameter.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/827204789583dd86addffb47ecaeab9d67cf95d5.1680161823.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:20:07 +02:00
Jeremy Kerr 7dc2e0a875 i3c: Allow OF-alias-based persistent bus numbering
Parse the /aliases node to assign any fixed bus numbers, as is done with
the i2c subsystem. Numbering for non-aliased busses will start after the
highest fixed bus number.

This allows an alias node such as:

    aliases {
        i3c0 = &bus_a,
	i3c4 = &bus_b,
    };

to set the numbering for a set of i3c controllers:

    /* fixed-numbered bus, assigned "i3c-0" */
    bus_a: i3c-master {
    };

    /* another fixed-numbered bus, assigned "i3c-4" */
    bus_b: i3c-master {
    };

    /* dynamic-numbered bus, likely assigned "i3c-5" */
    bus_c: i3c-master {
    };

If no i3c device aliases are present, the numbering will stay as-is,
starting from 0.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/20230405094149.1513209-1-jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:19:01 +02:00
Jeremy Kerr 5844564143 i3c: ast2600: Add AST2600 platform-specific driver
Now that we have platform-specific infrastructure for the dw i3c driver,
add platform support for the ASPEED AST2600 SoC.

The AST2600 has a small set of "i3c global" registers, providing
platform-level i3c configuration outside of the i3c core.

For the ast2600, we need a couple of extra setup operations:

 - on probe: find the i3c global register set and parse the SDA pullup
   resistor values

 - on init: set the pullups accordingly, and set the i3c instance IDs

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/20230331091501.3800299-4-jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:19:01 +02:00
Jeremy Kerr d782188cbb i3c: dw: Add infrastructure for platform-specific implementations
The dw i3c core can be integrated into various SoC devices. Platforms
that use this core may need a little configuration that is specific to
that platform.

Add some infrastructure to allow platform-specific behaviour: common
probe/remove functions, a set of platform hook operations, and a pointer
for platform-specific data in struct dw_i3c_master. Move the common api
into a new (i3c local) header file.

Platforms will provide their own struct platform_driver, which allocates
struct dw_i3c_master, does any platform-specific probe behaviour, and
calls into the common probe.

A future change will add new platform support that uses this
infrastructure.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/20230331091501.3800299-2-jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-28 08:18:53 +02:00
Jeremy Kerr 66b32e3d2c i3c: dw: use bus mode rather than device reg for conditional tCAS setting
In the clock setup path, we set the hardware DEV_CTRL_I2C_SLAVE_PRESENT
bit on a shared mode bus, then read-back this bit for the conditional
tCAS set.

Instead, just use the bus->mode setting for the conditional test.

While we're at it, add a little comment about why the conditional is
there.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/92a933566f7846708a00ad7f5a16ee8e6ed32d0e.1680156630.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-27 23:49:43 +02:00
Matt Johnston 67df5ce9dd i3c: dw: Return the length from a read priv_xfer
We currently assume that the rx_len of a read command will be as
submitted, but we may have a shorter read than expected.

This change populates the output i3c xfer length from the actually-read
length.

Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/f4fff7ab18dee1f662dc7a5a4111fcd921e6792b.1680156630.git.jk@codeconstruct.com.au
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-04-27 23:49:43 +02:00
Uwe Kleine-König 2810f1de81 i3c: svc: Convert to platform remove callback returning void
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230318233311.265186-6-u.kleine-koenig@pengutronix.de
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-21 19:25:25 +01:00
Uwe Kleine-König f959ec6175 i3c: mipi-i3c-hci: Convert to platform remove callback returning void
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230318233311.265186-5-u.kleine-koenig@pengutronix.de
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-21 19:25:25 +01:00
Uwe Kleine-König 3f8ad58359 i3c: cdns: Convert to platform remove callback returning void
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230318233311.265186-4-u.kleine-koenig@pengutronix.de
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-21 19:25:25 +01:00
Uwe Kleine-König 04b5f1be26 i3c: dw: Convert to platform remove callback returning void
The .remove() callback for a platform driver returns an int which makes
many driver authors wrongly assume it's possible to do error handling by
returning an error code. However the value returned is (mostly) ignored
and this typically results in resource leaks. To improve here there is a
quest to make the remove callback return void. In the first step of this
quest all drivers are converted to .remove_new() which already returns
void.

Trivially convert this driver from always returning zero in the remove
callback to the void returning variant.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20230318233311.265186-3-u.kleine-koenig@pengutronix.de
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-21 19:25:25 +01:00
Uwe Kleine-König 0f74f8b667 i3c: Make i3c_master_unregister() return void
The function returned zero unconditionally. Switch the return type to void
and simplify the callers accordingly.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20230318233311.265186-2-u.kleine-koenig@pengutronix.de
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-21 19:25:25 +01:00
Krzysztof Kozlowski 1dae3f1df7 i3c: dw: drop of_match_ptr for ID table
The driver can match only via the DT table so the table should be always
used and the of_match_ptr does not have any sense (this also allows ACPI
matching via PRP0001, even though it might not be relevant here).  This
also fixes !CONFIG_OF error:

  drivers/i3c/master/dw-i3c-master.c:1201:34: error: ‘dw_i3c_master_of_match’ defined but not used [-Werror=unused-const-variable=]

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20230312132535.352246-1-krzysztof.kozlowski@linaro.org
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-03-13 14:41:24 +01:00
Linus Torvalds 1899946aaf I3C for 6.3
Subsystem:
  - transfer pid from boardinfo to device info
 
 Drivers:
  - dw-i3c-master: stop hardcoding initial speed
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEBqsFVZXh8s/0O5JiY6TcMGxwOjIFAmP+hxgACgkQY6TcMGxw
 OjIY2g//ZhSzs3UELnmQFTX+GWKwnUldSrBtj4RhR6R0QDnVhPl5jsoA3KJSlliS
 EzbOxRKi4gIrEmsz0xzpunKuahuf0cAWziElkW7sTEo6TW4O/fwAgkoN88AdoJhB
 YUaj9UUDrZnagDuIQF9iM1goADwreAJQOvFaKG/qNzdn9ycZH3L2cny3yJAbxlDy
 lglIODPqhOf4fNSMUahsV6ZGFB1vnBcwgOTC9mvswEQ9D0vAFpNPel/NXdT7lUeJ
 kgIEK6G3GYrBe6WT4YB6muz7j5xPrF/04IndnajO6sXfEY/8GBefsgYQlYgeKp6t
 8QOSGYVUnAKWzXPEWfnqGBAvmWNiOyGt+66yVinZgvg72sQTYFA0FplAfeVaxp+4
 RyLVGarqHD+a6Ea5QcOrPcvDKy+n24KTq7MrjeaEiFX1PA1LHx9ObLQ5P12BCGbF
 L3NOa95j1vevKX9boggt4iwKaAEbgB02QbDWjD/P9yXPZNcpv5/VqVaJ4akIjITh
 Njw8zmKyWOCvnJY+jobsFx4BpQZyA7I7J2wCynLUrP43QphyqQlrCJRfMJ0NSSD4
 6F9r6WbZhy/U5l0Ya2WvOmZCgY3DPOpvE3pXpyhXM+96dB5vulXlaPqf5fP4lxca
 A0+vYAk+fkyoOE+/K9IoKGqNSN1OFU2sXojG/YQvGE4OAW+7grA=
 =CEs9
 -----END PGP SIGNATURE-----

Merge tag 'i3c/for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull i3c updates from Alexandre Belloni:
 "Subsystem:
   - transfer pid from boardinfo to device info

  Drivers:
   - dw-i3c-master: stop hardcoding initial speed"

* tag 'i3c/for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: master: dw: stop hardcoding initial speed
  i3c: transfer pid from boardinfo to device info
2023-02-28 16:05:01 -08:00
Jack Chen 510d2358c4 i3c: master: dw: stop hardcoding initial speed
Bus-speed could be default(12.5MHz) or defined by users in dts.
Dw-i3c-master should not hard-code the initial speed to be
I3C_BUS_TYP_I3C_SCL_RATE (12.5MHz)
And because of Synopsys's I3C controller limit (hcnt/lcnt register
length) and core-clk provided, there is a limit to bus speed, too.
For example, when core-clk is 250 MHz, the bus speed cannot be
lowered below 1MHz.

Tested: tested with an i3c sensor and captured with a logic analyzer.

Signed-off-by: Jack Chen <zenghuchen@google.com>
Link: https://lore.kernel.org/r/20230216151057.293764-1-zenghuchen@google.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-02-28 23:54:49 +01:00
Jack Chen f195c470f2 i3c: transfer pid from boardinfo to device info
I3C device PID could be defined in device tree and stored in
i3c_dev_boardinfo. It should be passed to i3c_device_info when
allocating a i3c_dev_desc.
Rational behind this change is: when users decide to use SETDASA to
assign a dynamic address with exactly the original static address, in
step of i3c_master_reattach_i3c_dev, this address is checked to be
taken. Then device information retrieving step is skipped. As a result,
though the i3c device is registered correctly, its device driver could
not be probed.

Tested: Tested with a I3C device. If assigned-address is set to be the
device's static address, without this change, its device driver could
not probed. And with this change, its driver is probed successfully.

Signed-off-by: Jack Chen <zenghuchen@google.com>
Link: https://lore.kernel.org/r/20230105212952.56321-1-zenghuchen@google.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2023-02-25 23:03:51 +01:00
Greg Kroah-Hartman 162736b0d7 driver core: make struct device_type.uevent() take a const *
The uevent() callback in struct device_type should not be modifying the
device that is passed into it, so mark it as a const * and propagate the
function signature changes out into all relevant subsystems that use
this callback.

Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Andreas Noever <andreas.noever@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Bard Liao <yung-chuan.liao@linux.intel.com>
Cc: Chaitanya Kulkarni <kch@nvidia.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Frank Rowand <frowand.list@gmail.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Jilin Yuan <yuanjilin@cdjrlc.com>
Cc: Jiri Slaby <jirislaby@kernel.org>
Cc: Len Brown <lenb@kernel.org>
Cc: Mark Gross <markgross@kernel.org>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Maximilian Luz <luzmaximilian@gmail.com>
Cc: Michael Jamet <michael.jamet@intel.com>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Sanyog Kale <sanyog.r.kale@intel.com>
Cc: Sean Young <sean@mess.org>
Cc: Stefan Richter <stefanr@s5r6.in-berlin.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Won Chung <wonchung@google.com>
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> # for Thunderbolt
Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Acked-by: Wolfram Sang <wsa@kernel.org>
Acked-by: Vinod Koul <vkoul@kernel.org>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230111113018.459199-6-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-01-27 13:45:36 +01:00
Greg Kroah-Hartman fa838c8ce5 i3c: move dev_to_i3cdev() to use container_of_const()
The driver core is changing to pass some pointers as const, so move
dev_to_i3cdev() to use container_of_const() to handle this change.
dev_to_i3cdev() now properly keeps the const-ness of the pointer passed
into it, while as before it could be lost.

Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20230111113018.459199-3-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-01-27 13:45:32 +01:00
Jack Chen 672825cd28 i3c: export SETDASA method
Because not all I3C drivers have the hot-join feature ready, and
especially not all I3C devices support hot-join feature, exporting
SETDASA method could be useful. With this function, the I3C controller
could perform a DAA to I3C devices when users decide to turn these I3C
devices off and on again during run-time.

Tested: This change has been tested with turnning off an I3C device and
turning on it again during run-time. The device driver calls SETDASA
method to perform DAA to the device. And communication between I3C
controller and device is set up again correctly.

Signed-off-by: Jack Chen <zenghuchen@google.com>
Link: https://lore.kernel.org/r/20221207205059.3848851-1-zenghuchen@google.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-12-11 21:25:58 +01:00
Billy Tsai 90f4a09a15 i3c: master: Remove the wrong place of reattach.
The reattach should be used when an I3C device has its address changed.
But the modified place in this patch doesn't have the address changed of
the newdev. This wrong reattach will reserve the same address slot twice
and return unexpected -EBUSY when the bus find the duplicate device with
diffent dynamic address.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
Link: https://lore.kernel.org/r/20220926105145.8145-2-billy_tsai@aspeedtech.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-10-12 23:45:29 +02:00
Billy Tsai d4fa7d772a i3c: master: Free the old_dyn_addr when reattach.
This patch is used to free the old_dyn_addr when the caller want to
reattach the device to the different dynamic address. If the
old_dyn_addr is 0 the function will treat it as no old_dyn_addr is
reserved on the bus. Without the patch, when the driver reattach the i3c
device after setnewda the old_dyn_addr will be permanently occupied.

Signed-off-by: Billy Tsai <billy_tsai@aspeedtech.com>
Link: https://lore.kernel.org/r/20220926105145.8145-1-billy_tsai@aspeedtech.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
2022-10-12 23:45:29 +02:00
Guo Zhengkui 227fab1ee7 i3c: master: svc: fix returnvar.cocci warning
Fix the following coccicheck warning:

drivers/i3c/master/svc-i3c-master.c:1600:5-8:
Unneeded variable: "ret". Return "0" on line 1605.

Signed-off-by: Guo Zhengkui <guozhengkui@vivo.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220504164901.9622-1-guozhengkui@vivo.com
2022-05-17 22:34:42 +02:00
Minghao Chi c157a606e7 i3c/master: simplify the return expression of i3c_hci_remove()
Simplify the return expression.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220505021954.54524-1-chi.minghao@zte.com.cn
2022-05-17 22:33:43 +02:00
Jamie Iles 6cbf8b38df i3c: fix uninitialized variable use in i2c setup
Commit 31b9887c72 ("i3c: remove i2c board info from i2c_dev_desc")
removed the boardinfo from i2c_dev_desc to decouple device enumeration from
setup but did not correctly lookup the i2c_dev_desc to store the new
device, instead dereferencing an uninitialized variable.

Lookup the device that has already been registered by address to store
the i2c client device.

Fixes: 31b9887c72 ("i3c: remove i2c board info from i2c_dev_desc")
Reported-by: kernel test robot <lkp@intel.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Jamie Iles <quic_jiles@quicinc.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220308134226.1042367-1-quic_jiles@quicinc.com
2022-03-08 22:33:52 +01:00
Jamie Iles 72a4501b5d i3c: support dynamically added i2c devices
I2C devices can be added to the system dynamically through several
sources other than static board info including device tree overlays and
sysfs i2c new_device.

Add an I2C bus notifier to attach the clients at runtime if they were
not defined in the board info.  For DT devices find the LVR in the reg
property, for user-space new_device additions we synthesize a
conservative setting of no spike filters and fast mode only.

Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Jamie Iles <quic_jiles@quicinc.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220117174816.1963463-3-quic_jiles@quicinc.com
2022-03-04 11:39:03 +01:00
Jamie Iles 31b9887c72 i3c: remove i2c board info from i2c_dev_desc
I2C board info is only required during adapter setup so there is no
requirement to keeping a pointer to it once running.  To support dynamic
device addition we can't rely on board info - user-space creation
through sysfs won't have a boardinfo.

Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Jamie Iles <quic_jiles@quicinc.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220117174816.1963463-2-quic_jiles@quicinc.com
2022-03-04 11:39:03 +01:00
Tom Rix 13462ba181 i3c: master: dw: check return of dw_i3c_master_get_free_pos()
Clang static analysis reports this problem
dw-i3c-master.c:799:9: warning: The result of the left shift is
  undefined because the left operand is negative
                      COMMAND_PORT_DEV_INDEX(pos) |
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~

pos can be negative because dw_i3c_master_get_free_pos() can return an
error.  So check for an error.

Fixes: 1dd728f5d4 ("i3c: master: Add driver for Synopsys DesignWare IP")
Signed-off-by: Tom Rix <trix@redhat.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220108150948.3988790-1-trix@redhat.com
2022-01-13 02:05:50 +01:00
Lukas Bulwahn 7a2bccd1a2 i3c: master: mipi-i3c-hci: correct the config reference for endianness
The referred config BIG_ENDIAN does not exist. The config for the
endianness of the CPU architecture is called CPU_BIG_ENDIAN.

Correct the config name to the existing config for the endianness.

Signed-off-by: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20220103094504.3602-1-lukas.bulwahn@gmail.com
2022-01-05 09:54:54 +01:00
Clark Wang 7ff730ca45 i3c: master: svc: enable the interrupt in the enable ibi function
If enable interrupt in the svc_i3c_master_bus_init() but do not call
enable ibi in the device driver, it will cause a kernel dump in the
svc_i3c_master_handle_ibi() when a slave start occurs on the i3c bus,
because the data->ibi_pool is not initialized.
So only enable the interrupt in svc_i3c_master_enable_ibi() function.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-9-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang c5d4587bb9 i3c: master: svc: add the missing module device table
The missing MODULE_DEVICE_TABLE() will cause the svc-i3c-master cannot
be auto probed when it is built in moudle.
So add it.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-8-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang 05be23ef78 i3c: master: svc: add runtime pm support
Add runtime pm support to dynamically manage the clock.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-7-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang 173fcb2721 i3c: master: svc: set ODSTOP to let I2C device see the STOP signal
If using I2C/I3C mixed mode, need to set ODSTOP. Otherwise, the I2C
devices cannot see the stop signal. It may cause message sending errors.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-6-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang d5e512574d i3c: master: svc: add support for slave to stop returning data
When i3c controller reads data from slave device, slave device can stop
returning data with an ACK after any byte.
Add this support for svc i3c controller. Otherwise, it will timeout
when the slave device ends the read operation early.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-5-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang 9fd6b5ce85 i3c: master: svc: separate err, fifo and disable interrupt of reset function
Sometimes only need to reset err and fifo regs, so split the origin
reset function to three functions.
Put them at the top of the file, to let more functions can call them.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-4-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang a84a9222b2 i3c: master: svc: fix atomic issue
do_daa_locked() function is in a spin lock environment, use
readl_poll_timeout_atomic() to replace the origin
readl_poll_timeout().

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-3-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Clark Wang 57d8d3fc06 i3c: master: svc: move module reset behind clk enable
Reset I3C module will R/W its regs, so enable its clocks first.

Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Jun Li <jun.li@nxp.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20211227074529.1660398-2-xiaoning.wang@nxp.com
2022-01-05 09:53:44 +01:00
Christophe JAILLET 3f43926f27 i3c/master/mipi-i3c-hci: Fix a potentially infinite loop in 'hci_dat_v1_get_index()'
The code in 'hci_dat_v1_get_index()' really looks like a hand coded version
of 'for_each_set_bit()', except that a +1 is missing when searching for the
next set bit.

This really looks odd and it seems that it will loop until 'dat_w0_read()'
returns the expected result.

So use 'for_each_set_bit()' instead. It is less verbose and should be more
correct.

Fixes: 9ad9a52cce ("i3c/master: introduce the mipi-i3c-hci driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/0cdf3cb10293ead1acd271fdb8a70369c298c082.1637186628.git.christophe.jaillet@wanadoo.fr
2021-12-10 15:55:41 +01:00
Jamie Iles f18f98110f i3c: fix incorrect address slot lookup on 64-bit
The address slot bitmap is an array of unsigned long's which are the
same size as an int on 32-bit platforms but not 64-bit.  Loading the
bitmap into an int could result in the incorrect status being returned
for a slot and slots being reported as the wrong status.

Fixes: 3a379bbcea ("i3c: Add core I3C infrastructure")
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Jamie Iles <quic_jiles@quicinc.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210922165600.179394-1-quic_jiles@quicinc.com
2021-12-10 15:54:46 +01:00
Len Baker 313ece2260 i3c/master/mipi-i3c-hci: Prefer kcalloc over open coded arithmetic
As noted in the "Deprecated Interfaces, Language Features, Attributes,
and Conventions" documentation [1], size calculations (especially
multiplication) should not be performed in memory allocator (or similar)
function arguments due to the risk of them overflowing. This could lead
to values wrapping around and a smaller allocation being made than the
caller was expecting. Using those allocations could lead to linear
overflows of heap memory and other misbehaviors.

So, use the purpose specific kcalloc() function instead of the argument
size * count in the kzalloc() function.

[1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Len Baker <len.baker@gmx.com>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210912155135.7541-1-len.baker@gmx.com
2021-12-10 15:54:46 +01:00
Len Baker f96b2e77f6 i3c/master/mipi-i3c-hci: Prefer struct_size over open coded arithmetic
As noted in the "Deprecated Interfaces, Language Features, Attributes,
and Conventions" documentation [1], size calculations (especially
multiplication) should not be performed in memory allocator (or similar)
function arguments due to the risk of them overflowing. This could lead
to values wrapping around and a smaller allocation being made than the
caller was expecting. Using those allocations could lead to linear
overflows of heap memory and other misbehaviors.

So, use the struct_size() helper to do the arithmetic instead of the
argument "size + count * size" in the kzalloc() function.

[1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments

Signed-off-by: Len Baker <len.baker@gmx.com>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210905144054.5124-1-len.baker@gmx.com
2021-12-10 15:54:45 +01:00
Uwe Kleine-König fc7a6209d5 bus: Make remove callback return void
The driver core ignores the return value of this callback because there
is only little it can do when a device disappears.

This is the final bit of a long lasting cleanup quest where several
buses were converted to also return void from their remove callback.
Additionally some resource leaks were fixed that were caused by drivers
returning an error code in the expectation that the driver won't go
away.

With struct bus_type::remove returning void it's prevented that newly
implemented buses return an ignored error code and so don't anticipate
wrong expectations for driver authors.

Reviewed-by: Tom Rix <trix@redhat.com> (For fpga)
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Cornelia Huck <cohuck@redhat.com> (For drivers/s390 and drivers/vfio)
Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> (For ARM, Amba and related parts)
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Chen-Yu Tsai <wens@csie.org> (for sunxi-rsb)
Acked-by: Pali Rohár <pali@kernel.org>
Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> (for media)
Acked-by: Hans de Goede <hdegoede@redhat.com> (For drivers/platform)
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-By: Vinod Koul <vkoul@kernel.org>
Acked-by: Juergen Gross <jgross@suse.com> (For xen)
Acked-by: Lee Jones <lee.jones@linaro.org> (For mfd)
Acked-by: Johannes Thumshirn <jth@kernel.org> (For mcb)
Acked-by: Johan Hovold <johan@kernel.org>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> (For slimbus)
Acked-by: Kirti Wankhede <kwankhede@nvidia.com> (For vfio)
Acked-by: Maximilian Luz <luzmaximilian@gmail.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> (For ulpi and typec)
Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> (For ipack)
Acked-by: Geoff Levand <geoff@infradead.org> (For ps3)
Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com> (For thunderbolt)
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> (For intel_th)
Acked-by: Dominik Brodowski <linux@dominikbrodowski.net> (For pcmcia)
Acked-by: Rafael J. Wysocki <rafael@kernel.org> (For ACPI)
Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> (rpmsg and apr)
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> (For intel-ish-hid)
Acked-by: Dan Williams <dan.j.williams@intel.com> (For CXL, DAX, and NVDIMM)
Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com> (For isa)
Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (For firewire)
Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> (For hid)
Acked-by: Thorsten Scherer <t.scherer@eckelmann.de> (For siox)
Acked-by: Sven Van Asbroeck <TheSven73@gmail.com> (For anybuss)
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> (For MMC)
Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C
Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: Finn Thain <fthain@linux-m68k.org>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Link: https://lore.kernel.org/r/20210713193522.1770306-6-u.kleine-koenig@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-21 11:53:42 +02:00
Linus Torvalds 88bbd8a031 I3C for 5.14
Drivers:
  - svc: two small fixes
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEBqsFVZXh8s/0O5JiY6TcMGxwOjIFAmDo0P0ACgkQY6TcMGxw
 OjLWxA//R11pYCjXStl1hJnLJkvFahxTL4SQ/QPS6fW9K9BXnmt8cV7w65YFFuzf
 SbXVud00ybP2NDpcfNkmir/leLt0Q5mwJrkcG9MXm6XnprQB4VQehpV+lZe7SgRX
 cHvFpKFoG4p/4+CwWb7NDGm7r3GDzcdsx/pEaMmqnd2cK79ZAtZYcsf1VxythQCg
 CnSHFz7bNPzkAAsqVIaDNU0Beh4V4YsDlh9yxfvVT4fNNtG4HgOxD3uzXj09iDco
 KdZQ/Fj0WNpFzm2rO3GkFVabyscp5x/lPSeKjdPfoGuNdK7vqUUpRtF9sSLMIB7f
 nas8d+ybyqUNogPTPrUSJ8oTRiWDeAcL+QUY2T1V6QvkvpibkfQVPONUo7LX4+U8
 xNC8wQvWxKzakf4sCKClvir6PhWV5aq3WFnJtNIlYMXOEIQom85tHfUoTVRGP/nE
 sQGCaoS4/VyUWOF1y3LcSAxyMlulmIhDZj5OlQpAvpU+YguC2vMfU4h1aofDq/YB
 h2rUs6dWujf93gEhhuFCJSW8Dfi6fWEA3VoHYkgdMnBHBAQYjG8I5tWHRezXX48b
 Cp9tmPbVprqk6gW0EyoO7+c9x0n8MnKYNxpVQM9KQvqtkFCE7mt3QWuLR13gbfoO
 oVzGLYsOTCQOLlpm0LdvtXeIzW4woRtardddnvODJ69PtOGHPQ8=
 =iMi5
 -----END PGP SIGNATURE-----

Merge tag 'i3c/for-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull i3c updates from Alexandre Belloni:

 - two small fixes to the svc driver

* tag 'i3c/for-5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: master: svc: fix doc warning in svc-i3c-master.c
  i3c: master: svc: drop free_irq of devm_request_irq allocated irq
2021-07-10 11:53:06 -07:00
Gustavo A. R. Silva ba3fea5472 i3c: master: cdns: Fix fall-through warning for Clang
In preparation to enable -Wimplicit-fallthrough for Clang, fix a warning
by explicitly adding a break statement instead of letting the code fall
through to the next case.

Link: https://github.com/KSPP/linux/issues/115
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2021-06-29 08:37:04 -05:00
Yang Yingliang 3e5feb11a8 i3c: master: svc: fix doc warning in svc-i3c-master.c
Fix the following make W=1 warning:

  drivers/i3c/master/svc-i3c-master.c:207: warning: expecting prototype for struct svc_i3c_i3c_dev_data. Prototype was for struct svc_i3c_i2c_dev_data instead

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210602085544.4101980-1-yangyingliang@huawei.com
2021-06-09 02:02:45 +02:00
Yang Yingliang 59a61e69c4 i3c: master: svc: drop free_irq of devm_request_irq allocated irq
irq allocated with devm_request_irq() will be freed in devm_irq_release(),
using free_irq() in ->remove() will causes a dangling pointer, and a
subsequent double free. So remove the free_irq() in svc_i3c_master_remove().

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210602084935.3977636-1-yangyingliang@huawei.com
2021-06-09 02:02:22 +02:00
Jae Hyun Yoo 0d95f41ebd Revert "i3c master: fix missing destroy_workqueue() on error in i3c_master_register"
Adding the destroy_workqueue call in i3c_master_register introduced below
kernel warning because it makes duplicate destroy_workqueue calls when
i3c_master_register fails after allocating the workqueue. The workqueue will
be destroyed by i3c_masterdev_release which is called by put_device at the
end of the i3c_master_register function eventually in failure cases so the
workqueue doesn't need to be destroyed in i3c_master_register.

[    6.972952] WARNING: CPU: 1 PID: 1 at lib/list_debug.c:48 __list_del_entry_valid+0x9c/0xf4
[    6.982205] list_del corruption, 8fe03c08->prev is LIST_POISON2 (00000122)
[    6.989910] CPU: 1 PID: 1 Comm: swapper/0 Tainted: G        W         5.10.23-c12838a-dirty-31dc772 #1
[    7.000295] Hardware name: Generic DT based system
[    7.005638] Backtrace:
[    7.008369] [<809133f0>] (dump_backtrace) from [<80913644>] (show_stack+0x20/0x24)
[    7.016819]  r7:00000030 r6:60000013 r5:00000000 r4:813b5d40
[    7.023137] [<80913624>] (show_stack) from [<8091e1a0>] (dump_stack+0x9c/0xb0)
[    7.031201] [<8091e104>] (dump_stack) from [<8011fa30>] (__warn+0xf8/0x154)
[    7.038972]  r7:00000030 r6:00000009 r5:804fa1c8 r4:80b6eca4
[    7.045289] [<8011f938>] (__warn) from [<80913d14>] (warn_slowpath_fmt+0x8c/0xc0)
[    7.053641]  r7:00000030 r6:80b6eca4 r5:80b6ed74 r4:818cc000
[    7.059960] [<80913c8c>] (warn_slowpath_fmt) from [<804fa1c8>] (__list_del_entry_valid+0x9c/0xf4)
[    7.069866]  r9:96becf8c r8:818cc000 r7:8fe03c10 r6:8fe03c00 r5:8fe03ba0 r4:ff7ead4c
[    7.078513] [<804fa12c>] (__list_del_entry_valid) from [<8013f0b4>] (destroy_workqueue+0x1c4/0x23c)
[    7.088615] [<8013eef0>] (destroy_workqueue) from [<806aa124>] (i3c_masterdev_release+0x40/0xb0)
[    7.098421]  r7:00000000 r6:81a43b80 r5:8fe65360 r4:8fe65048
[    7.104740] [<806aa0e4>] (i3c_masterdev_release) from [<805f3f04>] (device_release+0x40/0xb0)
[    7.114254]  r5:00000000 r4:8fe65048
[    7.118245] [<805f3ec4>] (device_release) from [<808fe754>] (kobject_put+0xc8/0x204)
[    7.126885]  r5:813978dc r4:8fe65048
[    7.130877] [<808fe68c>] (kobject_put) from [<805f5fbc>] (put_device+0x20/0x24)
[    7.139037]  r7:8fe65358 r6:8fe65368 r5:8fe65358 r4:8fe65048
[    7.145355] [<805f5f9c>] (put_device) from [<806abac4>] (i3c_master_register+0x338/0xb00)
[    7.154487] [<806ab78c>] (i3c_master_register) from [<806ae084>] (dw_i3c_probe+0x224/0x24c)
[    7.163811]  r10:00000000 r9:8fe7a100 r8:00000032 r7:819fa810 r6:819fa800 r5:8fe65040
[    7.172547]  r4:00000000
[    7.175376] [<806ade60>] (dw_i3c_probe) from [<805fdc14>] (platform_drv_probe+0x44/0x80)
[    7.184409]  r9:813a25c0 r8:00000000 r7:815ec114 r6:00000000 r5:813a25c0 r4:819fa810
[    7.193053] [<805fdbd0>] (platform_drv_probe) from [<805fb83c>] (really_probe+0x108/0x50c)
[    7.202275]  r5:815ec004 r4:819fa810
[    7.206265] [<805fb734>] (really_probe) from [<805fc180>] (driver_probe_device+0xb4/0x190)
[    7.215492]  r10:813dc000 r9:80c4385c r8:000000d9 r7:813a25c0 r6:819fa810 r5:00000000
[    7.224228]  r4:813a25c0
[    7.227055] [<805fc0cc>] (driver_probe_device) from [<805fc5cc>] (device_driver_attach+0xb8/0xc0)
[    7.236959]  r9:80c4385c r8:000000d9 r7:813a25c0 r6:819fa854 r4:819fa810
[    7.244439] [<805fc514>] (device_driver_attach) from [<805fc65c>] (__driver_attach+0x88/0x16c)
[    7.254051]  r7:00000000 r6:819fa810 r5:00000000 r4:813a25c0
[    7.260369] [<805fc5d4>] (__driver_attach) from [<805f954c>] (bus_for_each_dev+0x88/0xc8)
[    7.269489]  r7:00000000 r6:818cc000 r5:805fc5d4 r4:813a25c0
[    7.275806] [<805f94c4>] (bus_for_each_dev) from [<805fc76c>] (driver_attach+0x2c/0x30)
[    7.284739]  r7:81397c98 r6:00000000 r5:8fe7db80 r4:813a25c0
[    7.291057] [<805fc740>] (driver_attach) from [<805f9eec>] (bus_add_driver+0x120/0x200)
[    7.299984] [<805f9dcc>] (bus_add_driver) from [<805fce44>] (driver_register+0x98/0x128)
[    7.309005]  r7:80c4383c r6:00000000 r5:00000000 r4:813a25c0
[    7.315323] [<805fcdac>] (driver_register) from [<805fedb4>] (__platform_driver_register+0x50/0x58)
[    7.325410]  r5:818cc000 r4:81397c98
[    7.329404] [<805fed64>] (__platform_driver_register) from [<80c23398>] (dw_i3c_driver_init+0x24/0x28)
[    7.339790]  r5:818cc000 r4:80c23374
[    7.343784] [<80c23374>] (dw_i3c_driver_init) from [<80c01300>] (do_one_initcall+0xac/0x1d0)
[    7.353206] [<80c01254>] (do_one_initcall) from [<80c01630>] (kernel_init_freeable+0x1a8/0x204)
[    7.362916]  r8:000000d9 r7:80c4383c r6:00000007 r5:819ca2c0 r4:80c67680
[    7.370398] [<80c01488>] (kernel_init_freeable) from [<8091eb18>] (kernel_init+0x18/0x12c)
[    7.379616]  r10:00000000 r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:8091eb00
[    7.388343]  r4:00000000
[    7.391170] [<8091eb00>] (kernel_init) from [<80100148>] (ret_from_fork+0x14/0x2c)
[    7.399607] Exception stack(0x818cdfb0 to 0x818cdff8)
[    7.405243] dfa0:                                     00000000 00000000 00000000 00000000
[    7.414371] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[    7.423499] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000
[    7.430879]  r5:8091eb00 r4:00000000

This reverts commit 59165d16c6.

Fixes: 59165d16c6 ("i3c master: fix missing destroy_workqueue() on error in i3c_master_register")
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210408172803.24599-1-jae.hyun.yoo@linux.intel.com
2021-04-24 22:21:01 +02:00
Colin Ian King 436cb709f8 i3c: master: svc: remove redundant assignment to cmd->read_len
The assignment of xfer_len to cmd->read_len appears to be redundant
as the next statement re-assigns the value 0 to it.  Clean up the
code by removing the redundant first assignment.

Addresses-Coverity: ("Unused value")
Fixes: dd3c52846d ("i3c: master: svc: Add Silvaco I3C master driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210224151349.202332-1-colin.king@canonical.com
2021-03-09 21:13:31 +01:00
Linus Torvalds 36c1b20d15 I3C for 5.12
Subsystem:
  - Handle drivers without probe or remove callback
  - Remove callback now returns void
  - DT documentation is now in yaml
 
 New driver:
  - Silvaco I3C master
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEycoQi/giopmpPgB12wIijOdRNOUFAmAy+ycACgkQ2wIijOdR
 NOUDRg/+KPaE8MQMXh/YrnN4VXX+QZe8Yt5WynVThG8GGwDC0PrPtMcepwkd9GGA
 3EsBtuNVE7uvcUX59rmi2VrMlc6e3fRZ6g2Ub2vH5NXDZIeEXjbmq+vk6PlXNgKf
 k7LvVaQLkBCqsBoV1kraR7lPyi7rf2ZFFOYJuObj8yxADhmkpbRFQCbkWkeYGpMn
 2DN3cN2+jybmNBCh5SDDneJn/Bdr0/mBp0bLffOT+uAQ4bu6HbDOrlyZ9gY8rx8y
 TqbOT1JDhTCW0EC6IPw4SSkKXcew20XRmYSax4bx233cTCCjzsXG7vNHtv0KBide
 JlGvKEnE+WDfvPaSoxUjxtmwWfEki/qBzAZ3Mrs8/G9NRWRvE9qDU/x71hduog0g
 pqcRb0plreR7j3XusFaFu83HJtTfwHKVzWb12ExuNfzS4T/uZKs8vM0MFcedIRur
 wJg7+Qv+NGzGegELOaRkquc56x4IjXx+vYj3tbvnOrFdKgAuRU4YBn220QfYwI6d
 zx+6msuzIT/XroH6aq92Ds50hVLMQpNosuJPNsZto57hBShJgA6cmGMj79L9GldM
 CbdOu8ZBgHi4kpCWb9nunNqY0cctlQ0lEV6/1SYhCqRGLS7etS0IaUiWXNDge22N
 kzmeg5+RaA0AlAbzJHi+JOR6OnxxAhvZyys5nfQ4/X08R8JY9iY=
 =282r
 -----END PGP SIGNATURE-----

Merge tag 'i3c/for-5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull i3c update from Alexandre Belloni:
 "Subsystem:
   - Handle drivers without probe or remove callback
   - Remove callback now returns void
   - DT documentation is now in yaml

  New driver:
   - Silvaco I3C master"

* tag 'i3c/for-5.12' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: master: dw: Drop redundant disec call
  MAINTAINERS: Add Silvaco I3C master
  i3c: master: svc: Add Silvaco I3C master driver
  dt-bindings: i3c: Describe Silvaco master binding
  dt-bindings: Add vendor prefix for Silvaco
  dt-bindings: i3c: mipi-hci: Include the bus binding
  dt-bindings: i3c: Convert the bus description to yaml
  i3c: Make remove callback return void
  i3c: Handle drivers without probe or remove callback
  i3c/master/mipi-i3c-hci: Specify HAS_IOMEM dependency
2021-02-22 09:52:55 -08:00
Miquel Raynal 5c34b8e7e8 i3c: master: dw: Drop redundant disec call
Disabling all event calls is already handled by the core right before
starting the DAA process. Do not do it again when the DAA process
completes, it is redundant.

Fixes: 1dd728f5d4 ("i3c: master: Add driver for Synopsys DesignWare IP")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20201228105501.6104-1-miquel.raynal@bootlin.com
2021-02-06 00:44:15 +01:00
Miquel Raynal dd3c52846d i3c: master: svc: Add Silvaco I3C master driver
Add support for Silvaco I3C dual-role IP. The master role is supported
in SDR mode only. I2C transfers have not been tested but are shared
because they are very close to the I3C transfers in terms of register
configuration.

The IBI processing follows this logic:
- When a slave advertizes an interrupt (SDA pulled low) an interrupt
  gets generated by the master. This time is unbounded and may be
  deferred.
- The IRQ handler itself does not process anything: it only queues a
  work that will be run in non-atomic context. This is needed because
  short wait periods must be experienced.
- The IBI job is divided in two parts: the first one is "critical" in
  the sense that it may not support getting interrupted. If this
  happens, after this first section the driver checks the master error
  register and depending on its content either flushes everything and
  errors out, or ends the processing (this second section may be
  interrupted).
- If the critical section got interrupted, the slave will
  automatically respin it's IBI request when it will be allowed to.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210121101808.14654-6-miquel.raynal@bootlin.com
2021-02-06 00:43:29 +01:00
Uwe Kleine-König dd9267034c i3c: Make remove callback return void
The driver core ignores the return value of struct bus_type::remove()
because there is only little that can be done. To simplify the quest to
make this function return void, let struct i3c_driver::remove() return
void, too. This makes it obvious that returning an error code is
a bad idea and future driver authors cannot get that wrong.

Up to now there are no drivers with a remove callback, so there is no
need to adapt drivers.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210128091048.17006-2-u.kleine-koenig@pengutronix.de
2021-02-02 00:16:57 +01:00
Uwe Kleine-König 7456fea589 i3c: Handle drivers without probe or remove callback
A registered driver without a probe callback doesn't make sense, so
refuse to register such a driver. (Otherwise i3c_device_probe() yields a
NULL pointer exception.)

A driver without remove is possible, e.g. when all resources are freed
using devm callbacks. So guard the call to driver->remove by a check
for being non-NULL.

Note that the only in-tree i3c driver
(drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i3c.c) doesn't have a remove
callback.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210128091048.17006-1-u.kleine-koenig@pengutronix.de
2021-02-02 00:16:57 +01:00
David Gow 9d909f1b1e i3c/master/mipi-i3c-hci: Specify HAS_IOMEM dependency
The MIPI i3c HCI driver makes use of IOMEM functions like
devm_platform_ioremap_resource(), which are only available if
CONFIG_HAS_IOMEM is defined.

This causes the driver to be enabled under make ARCH=um allyesconfig,
even though it won't build.

By adding a dependency on HAS_IOMEM, the driver will not be enabled on
architectures which don't support it.

Fixes: 9ad9a52cce ("i3c/master: introduce the mipi-i3c-hci driver")
Signed-off-by: David Gow <davidgow@google.com>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210127040636.1535722-1-davidgow@google.com
2021-02-01 23:39:17 +01:00
Nathan Chancellor 291b5c9870 i3c/master/mipi-i3c-hci: Fix position of __maybe_unused in i3c_hci_of_match
Clang warns:

 ../drivers/i3c/master/mipi-i3c-hci/core.c:780:21: warning: attribute
 declaration must precede definition [-Wignored-attributes]
 static const struct __maybe_unused of_device_id i3c_hci_of_match[] = {
                     ^
 ../include/linux/compiler_attributes.h:267:56: note: expanded from macro
 '__maybe_unused'
 #define __maybe_unused                  __attribute__((__unused__))
                                                        ^
 ../include/linux/mod_devicetable.h:262:8: note: previous definition is
 here
 struct of_device_id {
        ^
1 warning generated.

'struct of_device_id' should not be split, as it is a type. Move the
__maybe_unused attribute after the static and const qualifiers so that
there are no warnings about this variable, period.

Fixes: 95393f3e07 ("i3c/master/mipi-i3c-hci: quiet maybe-unused variable warning")
Link: https://github.com/ClangBuiltLinux/linux/issues/1221
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20201222025931.3043480-1-natechancellor@gmail.com
2020-12-31 18:41:37 +01:00
Nicolas Pitre 95393f3e07 i3c/master/mipi-i3c-hci: quiet maybe-unused variable warning
If CONFIG_OF is disabled then the matching table is notreferenced.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2020-12-17 10:31:30 +01:00
Colin Ian King 8e3457372c i3c/master: Fix uninitialized variable next_addr
The variable next_addr is not initialized and is being used in a call
to i3c_master_get_free_addr as a starting point to find the next address.
Fix this by initializing next_addr to 0 to avoid an uninitialized garbage
starting address from being used.

Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: 9ad9a52cce ("i3c/master: introduce the mipi-i3c-hci driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20201124123504.396249-1-colin.king@canonical.com
2020-11-25 11:02:43 +01:00
Nicolas Pitre 9ad9a52cce i3c/master: introduce the mipi-i3c-hci driver
This adds basic support for hardware implementing the MIPI I3C HCI
specification. This driver is currently limited by the capabilities
of the I3C subsystem, meaning things like scheduled commands,
auto-commands and NCM mode are not yet supported.

This supports version 1.0 of the MIPI I3C HCI spec, as well as the
imminent release of version 1.1. Support for draft version 2.0 of the
spec is also largely included with the caveat that future adjustments
to this code are likely as the spec is still a work in progress.

This is also lightly tested as actual hardware is still very scarce,
even for HCI v1.0. Hence the EXPERIMENTAL tag. Further contributions
to this driver are expected once vendor implementations and new I3C
devices become available.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20201111220510.3622216-3-nico@fluxnic.net
2020-11-23 10:22:18 +01:00
Qinglang Miao 59165d16c6 i3c master: fix missing destroy_workqueue() on error in i3c_master_register
Add the missing destroy_workqueue() before return from
i3c_master_register in the error handling case.

Signed-off-by: Qinglang Miao <miaoqinglang@huawei.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20201028091543.136167-1-miaoqinglang@huawei.com
2020-11-23 10:22:16 +01:00
Linus Torvalds 2a934b38c0 * Fix DAA for the pre-reserved address case
* Fix an error path in the cadence driver
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEKmCqpbOU668PNA69Ze02AX4ItwAFAl+Ko/gACgkQZe02AX4I
 twAcKg//d6FTKiiphDXB7o3cNIcfV+1bbOxxl0JTqIW1kaRXvCVA7L0KQDDttefW
 VyjJTDLU+A3xauuC9kEOJCbX+oO3CEKtBQ5IjAaVgHirtz8E0gqJ2YV6X9zkfF86
 A94Z2e4vK79OpvfFmn+odYx8iFbXWR3q5ip9vMXRzXxGYJU0UwjLNSulvA3wSVAI
 uZzWeuLPxZalPQpp544fx+8AB2vuFOKu80yrPZnIBPCtH4luLlIVOXR18VMEXwaC
 ZAT4QlMNzAbqEOWe4ZFrddoyqj7b/enAjUflGkBpb+ZcsKGHzEQKe7s5Fg5PiJfF
 aWmWDsUh6/8et8sx//RCS442s/ZMIDxEvwgbUe/U19z94yW80rTWC0mbJnpO8KsU
 9doNmkZpjygwCnxc2fj6Sa+PlZt69SqDArWj3KOk/5UMqTh7fRDbB8DuvsTEBCiX
 VKOHbk44Fqdaov6g4JAg/u073ZyvI6jjlbDPuPBUVi++hqCxXk7TZ1U16xgwOsyg
 qiASKtQwztLvvuyHYyQNhpV9yHvSxzzUJHbL/3V3FQkGtVRTPP5+5ctCbndY1C46
 im+o0nlS2OpkYyw8A0AQuI6rnypuerbcafPw1ruvSTaWv60OebneyD9mLJm5pO4D
 zs6XtAoyO99+IEKDz+mvVckTxaj8cyrO5pQhjbyQoIr5ZvE2OPM=
 =yC+2
 -----END PGP SIGNATURE-----

Merge tag 'i3c/for-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull i3c updates from Boris Brezillon:

 - Fix DAA for the pre-reserved address case

 - Fix an error path in the cadence driver

* tag 'i3c/for-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: master: Fix error return in cdns_i3c_master_probe()
  i3c: master: fix for SETDASA and DAA process
  i3c: master add i3c_master_attach_boardinfo to preserve boardinfo
2020-10-17 11:01:01 -07:00
Jing Xiangfeng abea14bfde i3c: master: Fix error return in cdns_i3c_master_probe()
Fix to return negative error code -ENOMEM from the error handling
case instead of 0.

Fixes: 603f2bee2c ("i3c: master: Add driver for Cadence IP")
Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20200911033350.23904-1-jingxiangfeng@huawei.com
2020-10-07 15:14:07 +02:00
Parshuram Thombare cc3a392d69 i3c: master: fix for SETDASA and DAA process
This patch fix following issue.
Controller slots blocked for devices with static_addr
but no init_dyn_addr may limit the number of I3C devices
on the bus which gets dynamic address in DAA. So
instead of attaching all the devices with static_addr,
now we only attach the devices which successfully
complete SETDASA. For remaining devices with init_dyn_addr,
i3c_master_add_i3c_dev_locked() will try to set requested
dynamic address after DAA.

Signed-off-by: Parshuram Thombare <pthombar@cadence.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/1598337109-14770-1-git-send-email-pthombar@cadence.com
2020-09-14 09:05:58 +02:00
Gustavo A. R. Silva df561f6688 treewide: Use fallthrough pseudo-keyword
Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-08-23 17:36:59 -05:00
Parshuram Thombare 9da36a7ec4 i3c: master add i3c_master_attach_boardinfo to preserve boardinfo
Boardinfo was lost if I3C object for devices with boardinfo
available are not created or not added to the I3C device list
because of some failure e.g. SETDASA failed, retrieve info failed etc
This patch adds i3c_master_attach_boardinfo which scan boardinfo list
in the master object and 'attach' it to the I3C device object.

Fixes: 3a379bbcea ("i3c: Add core I3C infrastructure")
Signed-off-by: Parshuram Thombare <pthombar@cadence.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/1590053542-389-1-git-send-email-pthombar@cadence.com
2020-08-19 09:29:56 +02:00
Nicolas Pitre b4203ce055 i3c master: GETMRL's 3rd byte is optional even with BCR_IBI_PAYLOAD
According to the I3C spec v1.1 document, GETMRL's payload is 2 bytes,
with an optional 3rd byte if the IBI private payload is larger than
1 byte. The whole GETMRL may also be optional so max_ibi_len already
defaults to 1 if BCR_IBI_PAYLOAD prior to the i3c_master_getmrl_locked()
call.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/nycvar.YSQ.7.76.2004151623060.2671@knanqh.ubzr
2020-04-16 14:27:46 +02:00
Wolfram Sang c4b9de11d0 i3c: convert to use i2c_new_client_device()
Move away from the deprecated API.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20200326211002.13241-2-wsa+renesas@sang-engineering.com
2020-03-29 10:35:50 +02:00
Gustavo A. R. Silva cd851485ef i3c: master: Replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 7649773293 ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20200227131307.GA24935@embeddedor
2020-02-28 09:36:01 +01:00
Boris Brezillon 65ec1d0ddf i3c: Simplify i3c_device_match_id()
Simply match against ->match_flags instead of trying to be smart and
fix drivers inconsistent ID tables.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Link: https://lore.kernel.org/linux-i3c/8c5d6523e1c161783db834a3447954f7fd6267e6.1582796652.git.vitor.soares@synopsys.com
2020-02-28 09:36:01 +01:00
Boris Brezillon 7ec0ddb007 i3c: Add a modalias sysfs attribute
Create a modalias sysfs attribute for i3c devices.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Link: https://lore.kernel.org/linux-i3c/a90f64f830128cd12762153de7828b775574c156.1582796652.git.vitor.soares@synopsys.com
2020-02-28 09:35:52 +01:00
Boris Brezillon 12e21a23cc i3c: Fix MODALIAS uevents
file2alias uses %X formatters. Fix typos in the MODALIAS uevent to print
the part and ext IDs in uppercase.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Link: https://lore.kernel.org/linux-i3c/9ac5f1f8413fbb0481de76b5e43f2f4e1b2dc49f.1582796652.git.vitor.soares@synopsys.com
2020-02-27 16:51:18 +01:00
Wolfram Sang de8964995c i3c: master: no need to iterate master device twice
We already have the master device in a variable, reuse it.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Vitor Soares <vitor.soares@synopsys.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://lore.kernel.org/linux-i3c/20200214145853.24762-1-wsa+renesas@sang-engineering.com
2020-02-17 23:13:43 +01:00
Vitor Soares 3952cf8ff2 i3c: master: dw: reattach device on first available location of address table
For today the reattach function only update the device address on the
controller.

Update the location to the first available too, will optimize the
enumeration process avoiding additional checks to keep the available
positions on address table consecutive.

Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2020-01-13 10:00:05 +01:00
Yangtao Li 3c67166dc5 i3c: master: cdns: convert to devm_platform_ioremap_resource
Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2020-01-13 09:48:46 +01:00
Yangtao Li fae04237e8 i3c: master: dw: convert to devm_platform_ioremap_resource
Use devm_platform_ioremap_resource() to simplify code.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Acked-by: Vitor Soares <vitor.soares@synopsys.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2020-01-13 09:46:12 +01:00
Benjamin Gaignard 026d8450d4 i3c: master: make i3c_bus_set_mode static
i3c_bus_set_mode function is only used in master.c.
Make it static to avoid warning when compiling with W=1.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@st.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-12-09 16:07:39 +01:00
Przemyslaw Gaj dbd6654329 i3c: master: cdns: add data hold delay support
This patch adds support for THD_DEL (Data Hold Delay) to Cadence
I3C master constoller driver.

As per MIPI I3C Specification 1.0, Table 75 (page 142) defines
non-zero minimal tHD_PP timing on master output (Fig 65). This
setting allows to meet this timing on master's soc outputs,
regardless of PCB balancing.

Signed-off-by: Przemyslaw Gaj <pgaj@cadence.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-12-09 16:07:21 +01:00
Geert Uytterhoeven 708bc6ec65 i3c: Spelling s/dicovered/discovered/
Fix misspellings of "discovered".

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-10-31 11:24:52 +01:00
Vitor Soares f12b524ea3 i3c: master: use i3c_dev_get_master()
Since we have i3c_dev_get_master() available, use it.

Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-10-01 12:57:30 +02:00
Axel Lin 6030f42d20 i3c: master: Use dev_to_i3cmaster()
Since we have dev_to_i3cmaster() available, use it.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-08-27 09:43:59 +02:00
Wenwen Wang 7afe9a4e56 i3c: master: fix a memory leak bug
In i3c_master_getmwl_locked(), the buffer used for the dest payload data is
allocated using kzalloc() in i3c_ccc_cmd_dest_init(). Later on, the length
of the dest payload data is checked against 'sizeof(*mwl)'. If they are not
equal, -EIO is returned to indicate the error. However, the allocated
buffer is not deallocated on this path, leading to a memory leak.

To fix the above issue, free the buffer before returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-08-12 10:11:29 +02:00
Przemyslaw Gaj b1ac3a4b9a i3c: add addr and lvr to i2c_dev_desc structure
I need to store address and lvr value for I2C devices without static definition
in DT. This allows secondary master to transmit DEFSLVS command properly.

Main changes between v4 and v5:
- Change in defslvs to use addr and lvr from i2c_dev_desc structure
- Change in CDNS and DW drivers to use addr and lvr from i2c_dev_desc structure

Signed-off-by: Przemyslaw Gaj <pgaj@cadence.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-08-11 10:48:28 +02:00
Andy Shevchenko fd3f8f3118 i3c: master: cdns: Use for_each_set_bit()
This simplifies and standardizes slot manipulation code
by using for_each_set_bit() library function.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-08-11 10:45:52 +02:00
Nishka Dasgupta 91227632fc i3c: master: Add of_node_put() before return
Each iteration of for_each_available_childe_of_node puts the previous
node, but in the case of a return from the middle of the loop, there
is no put, thus causing a memory leak. Add an of_node_put before the
return.
Issue found with Coccinelle.

Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-08-11 10:45:51 +02:00
Vitor Soares 934d24a5e1 i3c: move i3c_device_match_id to device.c and export it
Some I3C device drivers need to know which entry matches the
i3c_device object passed to the probe function

Let's move i3c_device_match_id() to device.c and export it so it can be
used by drivers.

Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-07-27 11:22:19 +02:00
Linus Torvalds 96407298ff * Drop support for 10-bit I2C addresses
* Add support for limited bus mode
 * Fix the Cadence DT binding doc
 * Use struct_size() to allocate a DEFSLVS packet
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEKmCqpbOU668PNA69Ze02AX4ItwAFAl0gTH0ACgkQZe02AX4I
 twCTwRAAhuaDKLP5fI16392s0G+66V82u9Kdn1pF8bD6r8wcyRjkBsp2p73VPu4D
 ASIKH+XDDegy8H9+N7kZ7w4dYPqei/Rb4VhsUuaaC608iDvN8DCYG2ciMOr5eggv
 ejFt56MeMiON9BYUbk9KQJvNfaiN4d4dtFGuRETpYEGR9NG9V8Y3oQhWOG+EcWO3
 RBKYNi6QDo1y5NEhrsr8m7fdz0S1F8A7DgPirwkARYAAl9LBmdUllt8+h+WHUt7I
 1GJwA4ZCgXJYSGXw6Vf2p8RYakzAz6G7fTqx9maMRCwMqYKvucb0Opxe7jRnhS3s
 JPBVqwMdk3Dn4EWpWENgbGHIdJVwqOGxueKf1vtP64+WaUxG7AioS1QFcgPgSqPg
 7yRbGreO0nCPmW1v2X+2DEYE4iTyB5Sf2xcRrNYyLjAyO2elVjNuzx+IMA2d3nK3
 BS0kMaKjanSP1INCUsIiE/ISRQxQypTrYcoD4jpo/wV43MnOLDn93M9KrlhY5dOn
 M4rQg3FXiLeBhj+1NQPs6ac7LKkUgIIVl8+z2C8z+4DoY1LT+DsxI31YGqRly/H3
 quRtBIpCXVDxd69V9bPWpINZhXeP9ccgHDBTwfQJQk8bNfdJk4dh5ydntnO9rqmp
 nXhBPKgww0BlHecihrIf+RpxH4q6XmvFdpCDNTH1pgdtLCwblcQ=
 =Uj8o
 -----END PGP SIGNATURE-----

Merge tag 'i3c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull ic3 updates from Boris Brezillon:

 - Drop support for 10-bit I2C addresses

 - Add support for limited bus mode

 - Fix the Cadence DT binding doc

 - Use struct_size() to allocate a DEFSLVS packet

* tag 'i3c/for-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: master: Use struct_size() helper
  dt-bindings: i3c: cdns: Use correct cells for I2C device
  i3c: dw: add limited bus mode support
  i3c: add mixed limited bus mode
  i3c: fix i2c and i3c scl rate by bus mode
  dt-bindings: i3c: Document dropped support for I2C 10 bit devices
  i3c: Drop support for I2C 10 bit addresing
2019-07-09 09:04:31 -07:00
Gustavo A. R. Silva ede2001569 i3c: master: Use struct_size() helper
Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes, in particular in the
context in which this code is being used.

So, replace the following form:

sizeof(*defslvs) + ((ndevs - 1) * sizeof(struct i3c_ccc_dev_desc))

with:

struct_size(defslvs, slaves, ndevs - 1)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-07-04 12:05:14 +02:00
Vitor Soares f467907c1c i3c: dw: add limited bus mode support
This patch add limited bus mode support for DesignWare i3c master

Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-06-20 09:23:22 +02:00
Vitor Soares cbf4f7325a i3c: add mixed limited bus mode
The i3c bus spec defines a bus configuration where i2c devices don't
have a 50ns filter but support SCL running at SDR max rate (12.5MHz).

This patch introduces the limited bus mode so that users can use
a higher speed in presence of i2c devices index 1.

Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-06-20 09:23:22 +02:00
Vitor Soares ecc8fb54bd i3c: fix i2c and i3c scl rate by bus mode
Currently the I3C framework limits SCL frequency to FM speed when
dealing with a mixed slow bus, even if all I2C devices are FM+ capable.

The core was also not accounting for I3C speed limitations when
operating in mixed slow mode and was erroneously using FM+ speed as the
max I2C speed when operating in mixed fast mode.

Fixes: 3a379bbcea ("i3c: Add core I3C infrastructure")
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: <stable@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-06-20 09:23:22 +02:00
Przemyslaw Gaj 88c5032244 i3c: Drop support for I2C 10 bit addresing
This patch drops support for I2C devices with 10 bit addressing. When I2C
device with 10 bit address is defined in DT, I3C master registration fails.

Address space for I2C devices has been reduced and ->i2c_funcs() hook has been
removed.

Because this patch series dropped support for 10 bit I2C devices, support is
also dropped in Cadence I3C master driver and Synopsys DesignWare I3C master
driver.

Signed-off-by: Przemyslaw Gaj <pgaj@cadence.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-05-28 09:39:53 +02:00
Thomas Gleixner ec8f24b7fa treewide: Add SPDX license identifier - Makefile/Kconfig
Add SPDX license identifiers to all Make/Kconfig files which:

 - Have no license information of any form

These files fall under the project license, GPL v2 only. The resulting SPDX
license identifier is:

  GPL-2.0-only

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-21 10:50:46 +02:00
Linus Torvalds 80104bb06b * Fix a shift wrap bug in the core
* Remove dead code in the DW driver
 -----BEGIN PGP SIGNATURE-----
 
 iQIcBAABAgAGBQJcz9pLAAoJEGXtNgF+CLcAi3AP/3pjOrrJ0G+G3hry40Zr12NO
 JvbUmRPr0YUmcg479iIxgwuJ4Pj5GNGmczGGvfc6ZIKJdDCZEeu8aLIh/KLDzXPX
 nQ0SlcXBYCIk8gOwtZs/zxB+Oi8DVoiT4iz0Q3vvcqCho1K09IfFCDC1S8CZPUho
 72+KapR1nYBhm5gPKpunFn/II7l9UNAzeF1uWLjREm6pCG2/2UNHgzPYGVdp2Pf/
 i2lm6PXTMJyca6pqSDbMRWyDNeMva5SURoTkavvvBTwnTQTJaPukMi/jgWElHJ3C
 ajMJdDtbLBXKWv7La+G2LtlwbbFCDa5wf/V5G7LH4RnszLNWud2BdUhbLEUJWBSr
 /+VpAyYSUuz3vAGAHVaC+Fe7NtYXIxODKEGlSTqwl1Ns31P8fAwX6n+RuHdFNxpl
 wwIVaJZHeU62e5Z7nujQ9buJMDea2msqi5EqmtWubjN59C3rLRWZhwiL7YG3bjLc
 NbcaL5+Fz1IByKiOq7BGrI2w2uV8fK2/hE2mgw4yuNXvo7G0oKloHnSjB9zOxacJ
 HNCSDx6TnoWWfWCzGfXBKzc1ycTXyYY5vmk45qVA78H4a9LY0KG8WGDfsTPXmp44
 +PGQ+GKvvuPMzyYC+ENx1LN5OLkiZqU5c69++pFqkEXHiyPin+Ig4qm4XKbWy5FZ
 mwd5URtCnn2s0vD5DrDH
 =/U9S
 -----END PGP SIGNATURE-----

Merge tag 'i3c/for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux

Pull i3c update from Boris Brezillon:

 - Fix a shift wrap bug in the core

 - Remove dead code in the DW driver

* tag 'i3c/for-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux:
  i3c: Fix a shift wrap bug in i3c_bus_set_addr_slot_status()
  i3c: master: dw: remove dead code from dw_i3c_master_*_xfers()
2019-05-07 08:50:40 -07:00
Dan Carpenter 476c7e1d34 i3c: Fix a shift wrap bug in i3c_bus_set_addr_slot_status()
The problem here is that addr can be I3C_BROADCAST_ADDR (126).  That
means we're shifting by (126 * 2) % 64 which is 60.  The
I3C_ADDR_SLOT_STATUS_MASK is an enum which is an unsigned int in GCC
so shifts greater than 31 are undefined.

Fixes: 3a379bbcea ("i3c: Add core I3C infrastructure")
Cc: <stable@vger.kernel.org>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-05-06 08:15:02 +02:00
Vitor Soares 907621e94d i3c: dw: Fix dw_i3c_master_disable controller by using correct mask
The controller was being disabled incorrectly. The correct way is to clear
the DEV_CTRL_ENABLE bit.

Fix this by clearing this bit.

Cc: Boris Brezillon <bbrezillon@kernel.org>
Cc: <stable@vger.kernel.org>
Fixes: 1dd728f5d4 ("i3c: master: Add driver for Synopsys DesignWare IP")
Signed-off-by: Vitor Soares <vitor.soares@synopsys.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
2019-04-10 12:46:20 +02:00