Skip to content

Commit 2c55f67

Browse files
andy-shevbroonie
authored andcommitted
spi: sc18is602: Switch to generic firmware properties and drop of_match_ptr()
This enables using the driver with other firmware types such as ACPI via PRP0001. Also part of a general attempt to move drivers over to generic properties to avoid opportunities for cut and paste. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 096c34d commit 2c55f67

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

drivers/spi/spi-sc18is602.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
#include <linux/kernel.h>
99
#include <linux/err.h>
10+
#include <linux/mod_devicetable.h>
1011
#include <linux/module.h>
1112
#include <linux/spi/spi.h>
1213
#include <linux/i2c.h>
1314
#include <linux/delay.h>
1415
#include <linux/pm_runtime.h>
15-
#include <linux/of.h>
1616
#include <linux/platform_data/sc18is602.h>
17+
#include <linux/property.h>
18+
1719
#include <linux/gpio/consumer.h>
1820

1921
enum chips { sc18is602, sc18is602b, sc18is603 };
@@ -236,9 +238,7 @@ static int sc18is602_setup(struct spi_device *spi)
236238

237239
static int sc18is602_probe(struct i2c_client *client)
238240
{
239-
const struct i2c_device_id *id = i2c_client_get_device_id(client);
240241
struct device *dev = &client->dev;
241-
struct device_node *np = dev->of_node;
242242
struct sc18is602_platform_data *pdata = dev_get_platdata(dev);
243243
struct sc18is602 *hw;
244244
struct spi_controller *host;
@@ -251,8 +251,9 @@ static int sc18is602_probe(struct i2c_client *client)
251251
if (!host)
252252
return -ENOMEM;
253253

254+
device_set_node(&host->dev, dev_fwnode(dev));
255+
254256
hw = spi_controller_get_devdata(host);
255-
i2c_set_clientdata(client, hw);
256257

257258
/* assert reset and then release */
258259
hw->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
@@ -265,11 +266,7 @@ static int sc18is602_probe(struct i2c_client *client)
265266
hw->dev = dev;
266267
hw->ctrl = 0xff;
267268

268-
if (client->dev.of_node)
269-
hw->id = (uintptr_t)of_device_get_match_data(&client->dev);
270-
else
271-
hw->id = id->driver_data;
272-
269+
hw->id = (uintptr_t)i2c_get_match_data(client);
273270
switch (hw->id) {
274271
case sc18is602:
275272
case sc18is602b:
@@ -278,28 +275,21 @@ static int sc18is602_probe(struct i2c_client *client)
278275
break;
279276
case sc18is603:
280277
host->num_chipselect = 2;
281-
if (pdata) {
278+
if (pdata)
282279
hw->freq = pdata->clock_frequency;
283-
} else {
284-
const __be32 *val;
285-
int len;
286-
287-
val = of_get_property(np, "clock-frequency", &len);
288-
if (val && len >= sizeof(__be32))
289-
hw->freq = be32_to_cpup(val);
290-
}
280+
else
281+
device_property_read_u32(dev, "clock-frequency", &hw->freq);
291282
if (!hw->freq)
292283
hw->freq = SC18IS602_CLOCK;
293284
break;
294285
}
295-
host->bus_num = np ? -1 : client->adapter->nr;
286+
host->bus_num = dev_fwnode(dev) ? -1 : client->adapter->nr;
296287
host->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST;
297288
host->bits_per_word_mask = SPI_BPW_MASK(8);
298289
host->setup = sc18is602_setup;
299290
host->transfer_one_message = sc18is602_transfer_one;
300291
host->max_transfer_size = sc18is602_max_transfer_size;
301292
host->max_message_size = sc18is602_max_transfer_size;
302-
host->dev.of_node = np;
303293
host->min_speed_hz = hw->freq / 128;
304294
host->max_speed_hz = hw->freq / 4;
305295

@@ -314,7 +304,7 @@ static const struct i2c_device_id sc18is602_id[] = {
314304
};
315305
MODULE_DEVICE_TABLE(i2c, sc18is602_id);
316306

317-
static const struct of_device_id sc18is602_of_match[] __maybe_unused = {
307+
static const struct of_device_id sc18is602_of_match[] = {
318308
{
319309
.compatible = "nxp,sc18is602",
320310
.data = (void *)sc18is602
@@ -334,7 +324,7 @@ MODULE_DEVICE_TABLE(of, sc18is602_of_match);
334324
static struct i2c_driver sc18is602_driver = {
335325
.driver = {
336326
.name = "sc18is602",
337-
.of_match_table = of_match_ptr(sc18is602_of_match),
327+
.of_match_table = sc18is602_of_match,
338328
},
339329
.probe = sc18is602_probe,
340330
.id_table = sc18is602_id,

0 commit comments

Comments
 (0)