@@ -299,6 +299,10 @@ static unsigned int mcp3204_get_value(int channel);
299
299
static void rtcnt_i2c_remove (struct i2c_client * client );
300
300
#endif
301
301
302
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
303
+ static struct spi_master * spi_get_master (const char * spi_name );
304
+ #endif
305
+
302
306
/* --- Variable Type definitions --- */
303
307
/* SPI */
304
308
struct mcp3204_drvdata {
@@ -1804,7 +1808,11 @@ static unsigned int mcp3204_get_value(int channel)
1804
1808
unsigned int r = 0 ;
1805
1809
unsigned char c = channel & 0x03 ;
1806
1810
1807
- master = spi_busnum_to_master (mcp3204_info .bus_num );
1811
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
1812
+ master = spi_get_master ("spi0" );
1813
+ #else
1814
+ master = spi_busnum_to_master (mcp3204_info .bus_num );
1815
+ #endif
1808
1816
snprintf (str , sizeof (str ), "%s.%u" , dev_name (& master -> dev ),
1809
1817
mcp3204_info .chip_select );
1810
1818
@@ -1852,6 +1860,34 @@ static void spi_remove_device(struct spi_master *master, unsigned int cs)
1852
1860
}
1853
1861
}
1854
1862
1863
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
1864
+ /*
1865
+ * spi_get_master - get master info
1866
+ * get from Device-Tree
1867
+ */
1868
+ static struct spi_master * spi_get_master (const char * spi_name )
1869
+ {
1870
+ struct device_node * np ;
1871
+ struct device_node * spi_node ;
1872
+
1873
+ // get SPI node from device tree
1874
+ np = of_find_node_by_name (NULL , spi_name );
1875
+ if (!np ) {
1876
+ printk (KERN_ERR "%s: of_find_node_by_name returned NULL\n" );
1877
+ return - ENODEV ;
1878
+ }
1879
+
1880
+ strcut device * dev ;
1881
+
1882
+ dev = bus_find_device (& spi_bus_type , NULL , np , (void * )of_node_to_dev );
1883
+ if (!dev )
1884
+ printf ("Couldn't find Device\n" );
1885
+ return NULL ;
1886
+
1887
+ return container_of (dev , struct spi_master , dev );
1888
+ }
1889
+ #endif
1890
+
1855
1891
/*
1856
1892
* mcp3204_init - initialize MCP3204
1857
1893
* called by 'dev_init_module'
@@ -1866,7 +1902,11 @@ static int mcp3204_init(void)
1866
1902
mcp3204_info .bus_num = spi_bus_num ;
1867
1903
mcp3204_info .chip_select = spi_chip_select ;
1868
1904
1869
- master = spi_busnum_to_master (mcp3204_info .bus_num );
1905
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
1906
+ master = spi_get_master ("spi0" );
1907
+ #else
1908
+ master = spi_busnum_to_master (mcp3204_info .bus_num );
1909
+ #endif
1870
1910
1871
1911
if (!master ) {
1872
1912
printk (KERN_ERR "%s: spi_busnum_to_master returned NULL\n" ,
@@ -1895,7 +1935,11 @@ static void mcp3204_exit(void)
1895
1935
{
1896
1936
struct spi_master * master ;
1897
1937
1898
- master = spi_busnum_to_master (mcp3204_info .bus_num );
1938
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
1939
+ master = spi_get_master ("spi0" );
1940
+ #else
1941
+ master = spi_busnum_to_master (mcp3204_info .bus_num );
1942
+ #endif
1899
1943
1900
1944
if (master ) {
1901
1945
spi_remove_device (master , mcp3204_info .chip_select );
0 commit comments