Skip to content

Commit 4ac2d37

Browse files
committed
spi_busnum_to_master関数の削除に伴い、代替のデバイスツリーと関数の組み合わせに変更
[WIP]ビルド未実施
1 parent 4c54283 commit 4ac2d37

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

src/drivers/dts/rtmouse.dts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/dts-v1/;
2+
/plugin/;
3+
4+
/ {
5+
compatible = "brcm,bcm2711";
6+
7+
fragment@0 {
8+
target = <&spi0>;
9+
__overlay__ {
10+
status = "okay";
11+
mcp3208: mcp3208@0 {
12+
compatible = "microchip,mcp3208";
13+
reg = <0>;
14+
spi-max-frequency = <62500>;
15+
// vref-supply = <&vref_reg>; // reference defined Vref
16+
spi-cpha;
17+
spi-cpol;
18+
#io-channel-cells = <1>;
19+
};
20+
};
21+
};
22+
};

src/drivers/rtmouse.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ static unsigned int mcp3204_get_value(int channel);
299299
static void rtcnt_i2c_remove(struct i2c_client *client);
300300
#endif
301301

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+
302306
/* --- Variable Type definitions --- */
303307
/* SPI */
304308
struct mcp3204_drvdata {
@@ -1804,7 +1808,11 @@ static unsigned int mcp3204_get_value(int channel)
18041808
unsigned int r = 0;
18051809
unsigned char c = channel & 0x03;
18061810

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
18081816
snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev),
18091817
mcp3204_info.chip_select);
18101818

@@ -1852,6 +1860,34 @@ static void spi_remove_device(struct spi_master *master, unsigned int cs)
18521860
}
18531861
}
18541862

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+
18551891
/*
18561892
* mcp3204_init - initialize MCP3204
18571893
* called by 'dev_init_module'
@@ -1866,7 +1902,11 @@ static int mcp3204_init(void)
18661902
mcp3204_info.bus_num = spi_bus_num;
18671903
mcp3204_info.chip_select = spi_chip_select;
18681904

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
18701910

18711911
if (!master) {
18721912
printk(KERN_ERR "%s: spi_busnum_to_master returned NULL\n",
@@ -1895,7 +1935,11 @@ static void mcp3204_exit(void)
18951935
{
18961936
struct spi_master *master;
18971937

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
18991943

19001944
if (master) {
19011945
spi_remove_device(master, mcp3204_info.chip_select);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy