Part Number: AM3358
Hello,
As I inspected, There are three ways to instantiate a device:
1- Using Device Tree, provided that the "of_match_table" be defined in the driver
2- Using ACPI (deprecated and old way), provided that the "acpi_match_table" be defined in the driver
3- Using ID Table, provided that the "id_table" be defined in the driver
As of kernel 4.9, the RTC DS-1307 driver working on I2C bus does not support Device Tree mechanism, i.e. there is no of_match_table defined in its driver (Link), But in kernel 5.4, all three ways including Device Tree are supported (Link)
In case of kernel 4.9 that RTC DS1307 driver does not support Device Tree, I can use it by using the following commands to instantiate a device an bind it to i2c-x:
1- ~$ cd /sys/class/i2c-adapter/i2c-x .... where i2c-x is the i2c controller
2- /sys/class/i2c-adapter/i2c-x$ sudo sh -c "echo ds1307 0x68 > new_device .... where ds1307 defined in driver's ID Table and 0x68 is the i2c client address
This was an workaround for i2c clients when a client driver does not support device tree by not providing of_match_table
My questions are:
Q1- Is there any additional ways of instantiating a device except the three ones I said?
Q2- What is the workaround for SPI devices? something like the one I said for I2c device, to make them work on the platform
My workaround for SPI is to add a new kernel module and instantiate the device in it:
static struct mcp251x_platform_data mcp251x_info =
{
.oscillator_frequency = 8000000,
};
static struct spi_board_info my_spi_board_info[] =
{
{
.modalias = "mcp2515", //This is the same name as in mcp2515 id_table, something like compatible in device tree approach
.platform_data = &mcp251x_info,
// .irq = IRQ_EINT13,
.max_speed_hz = 10*1000*1000,
.chip_select = 0,
.bus_num = 0,
.mode = SPI_MODE_0
},
};
static int __init devices_init(void)
{
struct spi_master *master;
struct spi_device *spi_dev;
/* Get access to SPI master by knowing its bus number */
master = spi_busnum_to_master(0);
if(!master)
{
pr_err("SPI Master Not Found!!!\n");
return -1;
}
/* Make a new spi device in kernel which leads to calling driver's probe, in this case mcp2515 probe's function */
spi_dev = spi_new_device(master, &my_spi_board_info[0]);
if(!spi_dev)
{
pr_err("SPI add device failed!!!\n");
return -1;
}
return 0;
}
Is there any better way of instantiating a SPI device when Device tree is not supported in the SPI Client Driver? (Of course in the above example mcp2515 support both id table and device tree ways of instantiating ... that was just an example which uses a non device tree approach)
Thanks in advance