From 9a3044f3b796b21026cbe593290297116190e463 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Tue, 16 Jul 2024 18:14:05 +0900 Subject: [PATCH 01/22] =?UTF-8?q?kernel=206.4.0=E4=BB=A5=E9=99=8D=E3=81=AE?= =?UTF-8?q?class=5Fcreate=E9=96=A2=E6=95=B0=E3=81=AE=E5=BC=95=E6=95=B0?= =?UTF-8?q?=E5=A4=89=E5=8C=96=E3=81=AB=E5=AF=BE=E5=BF=9C=20[WIP]=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=89=E3=81=A7=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=8C?= =?UTF-8?q?=E5=87=BA=E3=82=8B=E7=8A=B6=E6=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 61 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 15f4791..b680865 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -1319,7 +1319,12 @@ static int led_register_dev(void) _major_led = MAJOR(dev); /* デバイスクラスを作成する */ - class_led = class_create(THIS_MODULE, DEVNAME_LED); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_led = class_create(THIS_MODULE, DEVNAME_LED); + # else + class_led = class_create(DEVNAME_LED); + #endif + if (IS_ERR(class_led)) { return PTR_ERR(class_led); } @@ -1368,7 +1373,11 @@ static int buzzer_register_dev(void) _major_buzzer = MAJOR(dev); /* デバイスクラスを作成する */ - class_buzzer = class_create(THIS_MODULE, DEVNAME_BUZZER); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_buzzer = class_create(THIS_MODULE, DEVNAME_BUZZER); + else + class_buzzer = class_create(DEVNAME_BUZZER); + #endif if (IS_ERR(class_buzzer)) { return PTR_ERR(class_buzzer); } @@ -1414,7 +1423,11 @@ static int motorrawr_register_dev(void) _major_motorrawr = MAJOR(dev); /* デバイスクラスを作成する */ - class_motorrawr = class_create(THIS_MODULE, DEVNAME_MOTORRAWR); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motorrawr = class_create(THIS_MODULE, DEVNAME_MOTORRAWR); + #else + class_motorrawr = class_create(DEVNAME_MOTORRAWR); + #endif if (IS_ERR(class_motorrawr)) { return PTR_ERR(class_motorrawr); } @@ -1462,7 +1475,11 @@ static int motorrawl_register_dev(void) _major_motorrawl = MAJOR(dev); /* デバイスクラスを作成する */ - class_motorrawl = class_create(THIS_MODULE, DEVNAME_MOTORRAWL); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motorrawl = class_create(THIS_MODULE, DEVNAME_MOTORRAWL); + #else + class_motorrawl = class_create(DEVNAME_MOTORRAWL); + #endif if (IS_ERR(class_motorrawl)) { return PTR_ERR(class_motorrawl); } @@ -1509,7 +1526,11 @@ static int switch_register_dev(void) _major_switch = MAJOR(dev); /* デバイスクラスを作成する */ - class_switch = class_create(THIS_MODULE, DEVNAME_SWITCH); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_switch = class_create(THIS_MODULE, DEVNAME_SWITCH); + #else + class_switch = class_create(DEVNAME_SWITCH); + #endif if (IS_ERR(class_switch)) { return PTR_ERR(class_switch); } @@ -1558,7 +1579,11 @@ static int sensor_register_dev(void) _major_sensor = MAJOR(dev); /* デバイスクラスを作成する */ - class_sensor = class_create(THIS_MODULE, DEVNAME_SENSOR); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_sensor = class_create(THIS_MODULE, DEVNAME_SENSOR); + #else + class_sensor = class_create(DEVNAME_SENSOR); + #endif if (IS_ERR(class_sensor)) { return PTR_ERR(class_sensor); } @@ -1604,7 +1629,11 @@ static int motoren_register_dev(void) _major_motoren = MAJOR(dev); /* デバイスクラスを作成する */ - class_motoren = class_create(THIS_MODULE, DEVNAME_MOTOREN); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motoren = class_create(THIS_MODULE, DEVNAME_MOTOREN); + #else + class_motoren = class_create(DEVNAME_MOTOREN); + #endif if (IS_ERR(class_motoren)) { return PTR_ERR(class_motoren); } @@ -1649,7 +1678,11 @@ static int motor_register_dev(void) _major_motor = MAJOR(dev); /* デバイスクラスを作成する */ - class_motor = class_create(THIS_MODULE, DEVNAME_MOTOR); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motor = class_create(THIS_MODULE, DEVNAME_MOTOR); + #else + class_motor = class_create(DEVNAME_MOTOR); + #endif if (IS_ERR(class_motor)) { return PTR_ERR(class_motor); } @@ -1879,7 +1912,11 @@ static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) } /* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */ - dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTR); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTR); + #else + dev_info->device_class = class_create(DEVNAME_CNTR); + #endif if (IS_ERR(dev_info->device_class)) { printk(KERN_ERR "class_create\n"); cdev_del(&dev_info->cdev); @@ -1929,7 +1966,11 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) } /* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */ - dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTL); + #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTL); + #else + dev_info->device_class = class_create(DEVNAME_CNTL); + #endif if (IS_ERR(dev_info->device_class)) { printk(KERN_ERR "class_create\n"); cdev_del(&dev_info->cdev); From c9479c3ba68110c0956b0a710abe46e8ee856550 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Thu, 18 Jul 2024 10:42:13 +0900 Subject: [PATCH 02/22] =?UTF-8?q?"spi=5Fdriver"=E3=81=AE=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=90=E5=A4=89=E6=95=B0"remove"=E3=81=AE=E5=9E=8B=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=81=A6"=20mcp32?= =?UTF-8?q?04=5Fremove"=E3=81=AE=E5=9E=8B=E3=82=82=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index b680865..a0825df 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -277,7 +277,11 @@ static struct mutex lock; /* --- Function Declarations --- */ static void set_motor_r_freq(int freq); static void set_motor_l_freq(int freq); -static int mcp3204_remove(struct spi_device *spi); +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) + static int mcp3204_remove(struct spi_device *spi); +#else + static void mcp3204_remove(struct spi_device *spi); +#endif static int mcp3204_probe(struct spi_device *spi); static unsigned int mcp3204_get_value(int channel); static int rtcnt_i2c_probe(struct i2c_client *client, @@ -1706,16 +1710,28 @@ static int motor_register_dev(void) } /* mcp3204_remove - remove function lined with spi_dirver */ -static int mcp3204_remove(struct spi_device *spi) -{ - struct mcp3204_drvdata *data; - /* get drvdata */ - data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); - /* free kernel memory */ - kfree(data); - printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); - return 0; -} +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) + static int mcp3204_remove(struct spi_device *spi) + { + struct mcp3204_drvdata *data; + /* get drvdata */ + data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); + /* free kernel memory */ + kfree(data); + printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); + return 0; + } +#else + static void mcp3204_remove(struct spi_device *spi) + { + struct mcp3204_drvdata *data; + /* get drvdata */ + data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); + /* free kernel memory */ + kfree(data); + printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); + } +#endif /* mcp3204_probe - probe function lined with spi_dirver */ static int mcp3204_probe(struct spi_device *spi) From 5f6ed955cea7a7af2114a523c545e02390e065ef Mon Sep 17 00:00:00 2001 From: kurasawa Date: Thu, 18 Jul 2024 11:04:29 +0900 Subject: [PATCH 03/22] =?UTF-8?q?"i2c=5Fdriver"=E3=81=AE=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=90=E5=A4=89=E6=95=B0"remove"=E3=81=AE=E5=9E=8B=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=81=A6"=20rtcnt?= =?UTF-8?q?=5Fi2c=5Fremove"=E3=81=AE=E5=9E=8B=E3=82=82=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index a0825df..9f369e3 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -286,7 +286,12 @@ static int mcp3204_probe(struct spi_device *spi); static unsigned int mcp3204_get_value(int channel); static int rtcnt_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id); -static int rtcnt_i2c_remove(struct i2c_client *client); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0) + static int rtcnt_i2c_remove(struct i2c_client *client); +#else + static void rtcnt_i2c_remove(struct i2c_client *client); +#endif /* --- Variable Type definitions --- */ /* SPI */ @@ -2135,17 +2140,30 @@ static void rtcnt_i2c_delete_cdev(struct rtcnt_device_info *dev_info) * i2c_counter_remove - I2C pulse counter * called when I2C pulse counter removed */ -static int rtcnt_i2c_remove(struct i2c_client *client) -{ - struct rtcnt_device_info *dev_info; - // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, - // client->addr); - dev_info = i2c_get_clientdata(client); - rtcnt_i2c_delete_cdev(dev_info); - printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, - client->addr); - return 0; -} +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0) + static int rtcnt_i2c_remove(struct i2c_client *client) + { + struct rtcnt_device_info *dev_info; + // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, + // client->addr); + dev_info = i2c_get_clientdata(client); + rtcnt_i2c_delete_cdev(dev_info); + printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, + client->addr); + return 0; + } +#else + static void rtcnt_i2c_remove(struct i2c_client *client) + { + struct rtcnt_device_info *dev_info; + // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, + // client->addr); + dev_info = i2c_get_clientdata(client); + rtcnt_i2c_delete_cdev(dev_info); + printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, + client->addr); + } +#endif /* * dev_init_module - register driver module From fa2b3e157ba71a77e72c6d8a554fc46e3239bad3 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Thu, 18 Jul 2024 11:51:33 +0900 Subject: [PATCH 04/22] =?UTF-8?q?"i2c=5Fdriver"=E3=81=AE=E3=83=A1=E3=83=B3?= =?UTF-8?q?=E3=83=90=E5=A4=89=E6=95=B0"probe"=E3=81=AE=E5=BC=95=E6=95=B0?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=81=A6?= =?UTF-8?q?"rtcnt=5Fi2c=5Fprobe"=E3=81=AE=E5=BC=95=E6=95=B0=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=97=E3=80=81id=E3=82=92=E6=96=B0?= =?UTF-8?q?=E8=A6=8F=E8=BF=BD=E5=8A=A0=E3=81=95=E3=82=8C=E3=81=9F=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=81=8B=E3=82=89=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 131 +++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 41 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 9f369e3..8b6f266 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -277,6 +277,7 @@ static struct mutex lock; /* --- Function Declarations --- */ static void set_motor_r_freq(int freq); static void set_motor_l_freq(int freq); + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) static int mcp3204_remove(struct spi_device *spi); #else @@ -284,8 +285,13 @@ static void set_motor_l_freq(int freq); #endif static int mcp3204_probe(struct spi_device *spi); static unsigned int mcp3204_get_value(int channel); -static int rtcnt_i2c_probe(struct i2c_client *client, + +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) + static int rtcnt_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id); +#else + static int rtcnt_i2c_probe(struct i2c_client *client); +#endif #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0) static int rtcnt_i2c_remove(struct i2c_client *client); @@ -2009,46 +2015,89 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) return 0; } -static int rtcnt_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) -{ - struct rtcnt_device_info *dev_info; - int msb = 0, lsb = 0; - // printk(KERN_DEBUG "%s: probing i2c device", __func__); - - /* check i2c device */ - // printk(KERN_DEBUG "%s: checking i2c device", __func__); - msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); - lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); - if ((msb < 0) || (lsb < 0)) { - printk(KERN_INFO - "%s: rtcounter not found, or wrong i2c device probed", - DRIVER_NAME); - // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, - // client->addr, msb, lsb); - return -ENODEV; - } - printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " - "id.driver_data=%d, addr=0x%x\n", - DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); - - dev_info = (struct rtcnt_device_info *)devm_kzalloc( - &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); - dev_info->client = client; - i2c_set_clientdata(client, dev_info); - mutex_init(&dev_info->lock); - - /* create character device */ - if ((int)(id->driver_data) == 0) { - if (rtcntl_i2c_create_cdev(dev_info)) - return -ENOMEM; - } else if ((int)(id->driver_data) == 1) { - if (rtcntr_i2c_create_cdev(dev_info)) - return -ENOMEM; - } - - return 0; -} +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) + static int rtcnt_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) + { + struct rtcnt_device_info *dev_info; + int msb = 0, lsb = 0; + // printk(KERN_DEBUG "%s: probing i2c device", __func__); + + /* check i2c device */ + // printk(KERN_DEBUG "%s: checking i2c device", __func__); + msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); + lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); + if ((msb < 0) || (lsb < 0)) { + printk(KERN_INFO + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); + // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, + // client->addr, msb, lsb); + return -ENODEV; + } + printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " + "id.driver_data=%d, addr=0x%x\n", + DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); + + dev_info = (struct rtcnt_device_info *)devm_kzalloc( + &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); + dev_info->client = client; + i2c_set_clientdata(client, dev_info); + mutex_init(&dev_info->lock); + + /* create character device */ + if ((int)(id->driver_data) == 0) { + if (rtcntl_i2c_create_cdev(dev_info)) + return -ENOMEM; + } else if ((int)(id->driver_data) == 1) { + if (rtcntr_i2c_create_cdev(dev_info)) + return -ENOMEM; + } + + return 0; + } +#else + static int rtcnt_i2c_probe(struct i2c_client *client) + { + const struct i2c_device_id *id = i2c_client_get_device_id(client); + struct rtcnt_device_info *dev_info; + int msb = 0, lsb = 0; + // printk(KERN_DEBUG "%s: probing i2c device", __func__); + + /* check i2c device */ + // printk(KERN_DEBUG "%s: checking i2c device", __func__); + msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); + lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); + if ((msb < 0) || (lsb < 0)) { + printk(KERN_INFO + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); + // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, + // client->addr, msb, lsb); + return -ENODEV; + } + printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " + "id.driver_data=%d, addr=0x%x\n", + DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); + + dev_info = (struct rtcnt_device_info *)devm_kzalloc( + &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); + dev_info->client = client; + i2c_set_clientdata(client, dev_info); + mutex_init(&dev_info->lock); + + /* create character device */ + if ((int)(id->driver_data) == 0) { + if (rtcntl_i2c_create_cdev(dev_info)) + return -ENOMEM; + } else if ((int)(id->driver_data) == 1) { + if (rtcntr_i2c_create_cdev(dev_info)) + return -ENOMEM; + } + + return 0; + } +#endif /* * i2c_counter_init - initialize I2C counter From 4c542835b5d5eebd9acc560d24fb1ea15c1a8c6d Mon Sep 17 00:00:00 2001 From: kurasawa Date: Fri, 19 Jul 2024 14:50:36 +0900 Subject: [PATCH 05/22] =?UTF-8?q?1=E3=81=A4=E5=89=8D=E3=81=AE=E3=82=B3?= =?UTF-8?q?=E3=83=9F=E3=83=83=E3=83=88=E3=81=A7=E3=81=AE"rtcnt=5Fi2c=5Fpro?= =?UTF-8?q?be"=E3=81=AE=E5=A4=89=E6=9B=B4=E3=82=AB=E3=83=BC=E3=83=8D?= =?UTF-8?q?=E3=83=AB=E3=81=8C6.2.0=E3=81=A0=E3=81=A3=E3=81=9F=E3=81=9F?= =?UTF-8?q?=E3=82=81=E5=88=86=E5=B2=90=E6=9D=A1=E4=BB=B6=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 8b6f266..dcff72d 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -286,7 +286,7 @@ static void set_motor_l_freq(int freq); static int mcp3204_probe(struct spi_device *spi); static unsigned int mcp3204_get_value(int channel); -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) static int rtcnt_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id); #else @@ -2015,7 +2015,7 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) return 0; } -#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 3, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) static int rtcnt_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { From 7c00077b06ac06f549d52887ae66fe61acd7f1d9 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Fri, 23 Aug 2024 18:05:44 +0900 Subject: [PATCH 06/22] =?UTF-8?q?mcp3204=E3=81=AB=E3=81=A4=E3=81=84?= =?UTF-8?q?=E3=81=A6=E3=80=81=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E3=83=84?= =?UTF-8?q?=E3=83=AA=E3=83=BC=E3=82=92=E3=82=AA=E3=83=BC=E3=83=90=E3=83=BC?= =?UTF-8?q?=E3=83=AC=E3=82=A4=E3=81=A7=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=99?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=A7=E5=AF=BE=E5=87=A6=20[=E8=A3=9C?= =?UTF-8?q?=E8=B6=B3]=E3=82=B5=E3=83=B3=E3=83=97=E3=83=AB=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=83=A9=E3=83=A0step2=E4=BB=A5=E5=A4=96?= =?UTF-8?q?=E3=81=AF=E5=8B=95=E4=BD=9C=E3=81=97=E3=81=9F=E7=8A=B6=E6=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 109 ++++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 36 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index dcff72d..453ff31 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -51,7 +51,7 @@ // Raspberry Pi 2 B : 2 // Raspberry Pi 3 B/A+/B+ : 2 // Raspberry Pi 4 B : 4 -#define RASPBERRYPI 2 +#define RASPBERRYPI 4 MODULE_AUTHOR("RT Corporation"); MODULE_LICENSE("GPL"); @@ -326,6 +326,9 @@ static struct spi_board_info mcp3204_info = { .mode = SPI_MODE_3, }; +static struct device *mcp320x_dev; + + /* SPI Dirver Info */ static struct spi_driver mcp3204_driver = { .driver = @@ -1799,19 +1802,28 @@ static unsigned int mcp3204_get_value(int channel) struct mcp3204_drvdata *data; struct spi_device *spi; char str[128]; - struct spi_master *master; unsigned int r = 0; unsigned char c = channel & 0x03; - master = spi_busnum_to_master(mcp3204_info.bus_num); - snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), - mcp3204_info.chip_select); + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) - dev = bus_find_device_by_name(&spi_bus_type, NULL, str); - spi = to_spi_device(dev); - data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); + struct spi_master *master; + master = spi_busnum_to_master(mcp3204_info.bus_num); + snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), + mcp3204_info.chip_select); + + dev = bus_find_device_by_name(&spi_bus_type, NULL, str); + + #else + + if (mcp320x_dev == NULL) return 0; + dev = mcp320x_dev; + + #endif + spi = to_spi_device(dev); + data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); mutex_lock(&data->lock); data->tx[0] = 1 << 2; // start bit data->tx[0] |= 1 << 1; // Single @@ -1820,7 +1832,7 @@ static unsigned int mcp3204_get_value(int channel) if (spi_sync(data->spi, &data->msg)) { printk(KERN_INFO "%s: spi_sync_transfer returned non zero\n", - __func__); + __func__); } mutex_unlock(&data->lock); @@ -1852,37 +1864,54 @@ static void spi_remove_device(struct spi_master *master, unsigned int cs) } } +/* spiをサーチする関数 */ +static int __callback_find_mcp3204(struct device *dev, void *data) +{ + printk(KERN_INFO " device_name: %s\n", dev->driver->name); + if(mcp320x_dev == NULL && strcmp(dev->driver->name, "mcp320x") == 0){ + mcp320x_dev = dev; + mcp3204_probe(to_spi_device(dev)); + } + return 0; +} + + /* * mcp3204_init - initialize MCP3204 * called by 'dev_init_module' */ static int mcp3204_init(void) { - struct spi_master *master; - struct spi_device *spi_device; - spi_register_driver(&mcp3204_driver); + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) + struct spi_master *master; + struct spi_device *spi_device; - mcp3204_info.bus_num = spi_bus_num; - mcp3204_info.chip_select = spi_chip_select; + spi_register_driver(&mcp3204_driver); // ここifdefで囲っていいかも - master = spi_busnum_to_master(mcp3204_info.bus_num); + mcp3204_info.bus_num = spi_bus_num; + mcp3204_info.chip_select = spi_chip_select; - if (!master) { - printk(KERN_ERR "%s: spi_busnum_to_master returned NULL\n", - __func__); - spi_unregister_driver(&mcp3204_driver); - return -ENODEV; - } + master = spi_busnum_to_master(mcp3204_info.bus_num); - spi_remove_device(master, mcp3204_info.chip_select); + if (!master) { + printk(KERN_ERR "%s: spi_busnum_to_master returned NULL\n", + __func__); + spi_unregister_driver(&mcp3204_driver); + return -ENODEV; + } - spi_device = spi_new_device(master, &mcp3204_info); - if (!spi_device) { - printk(KERN_ERR "%s: spi_new_device returned NULL\n", __func__); - spi_unregister_driver(&mcp3204_driver); - return -ENODEV; - } + spi_remove_device(master, mcp3204_info.chip_select); + + spi_device = spi_new_device(master, &mcp3204_info); + if (!spi_device) { + printk(KERN_ERR "%s: spi_new_device returned NULL\n", __func__); + spi_unregister_driver(&mcp3204_driver); + return -ENODEV; + } + #else + bus_for_each_dev(&spi_bus_type, NULL, NULL, __callback_find_mcp3204); + #endif return 0; } @@ -1893,17 +1922,25 @@ static int mcp3204_init(void) */ static void mcp3204_exit(void) { - struct spi_master *master; - master = spi_busnum_to_master(mcp3204_info.bus_num); + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) + struct spi_master *master; - if (master) { - spi_remove_device(master, mcp3204_info.chip_select); - } else { - printk(KERN_ERR "mcp3204 remove error\n"); - } + master = spi_busnum_to_master(mcp3204_info.bus_num); - spi_unregister_driver(&mcp3204_driver); + if (master) { + spi_remove_device(master, mcp3204_info.chip_select); + } else { + printk(KERN_ERR "mcp3204 remove error\n"); + } + + spi_unregister_driver(&mcp3204_driver); + #else + printk(KERN_INFO " mcp3204_exit\n"); + if (mcp320x_dev) { + mcp3204_remove(to_spi_device(mcp320x_dev)); + } + #endif } static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) From 460d96587d145160cb4152fda031954dfd1c739f Mon Sep 17 00:00:00 2001 From: kurasawa Date: Mon, 26 Aug 2024 14:40:03 +0900 Subject: [PATCH 07/22] =?UTF-8?q?buzzer=E5=86=85=E9=83=A8=E3=81=AE?= =?UTF-8?q?=E3=83=9E=E3=82=AF=E3=83=AD=E3=81=A7#else=E3=81=AB#=E3=81=8C?= =?UTF-8?q?=E4=BB=98=E3=81=84=E3=81=A6=E3=81=8A=E3=82=89=E3=81=9A=E3=81=AB?= =?UTF-8?q?=E3=83=96=E3=82=B6=E3=83=BC=E3=81=AE=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=81=8C=E4=BD=9C=E6=88=90=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E5=A4=A9=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 453ff31..d06fe44 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -1339,7 +1339,7 @@ static int led_register_dev(void) /* デバイスクラスを作成する */ #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) class_led = class_create(THIS_MODULE, DEVNAME_LED); - # else + #else class_led = class_create(DEVNAME_LED); #endif @@ -1393,7 +1393,7 @@ static int buzzer_register_dev(void) /* デバイスクラスを作成する */ #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) class_buzzer = class_create(THIS_MODULE, DEVNAME_BUZZER); - else + #else class_buzzer = class_create(DEVNAME_BUZZER); #endif if (IS_ERR(class_buzzer)) { From 9dc585bba06a24da2291a52f8c0f17cb78b61bd6 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Mon, 26 Aug 2024 15:26:15 +0900 Subject: [PATCH 08/22] =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E4=BD=9C=E6=88=90=E3=81=8C?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B=E3=81=8B?= =?UTF-8?q?=E3=82=92device=5Fcreate=E3=81=AE=E5=BC=95=E6=95=B0=E3=81=8B?= =?UTF-8?q?=E3=82=89=E5=88=A4=E5=AE=9A=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 111 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 7 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index d06fe44..f213e36 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -1360,8 +1360,18 @@ static int led_register_dev(void) _minor_led + i); } else { /* デバイスノードの作成 */ - device_create(class_led, NULL, devno, NULL, + struct device *dev_ret; + dev_ret = device_create(class_led, NULL, devno, NULL, DEVNAME_LED "%u", _minor_led + i); + + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_led + i); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; } @@ -1410,8 +1420,18 @@ static int buzzer_register_dev(void) printk(KERN_ERR "cdev_add failed minor = %d\n", _minor_buzzer); } else { /* デバイスノードの作成 */ - device_create(class_buzzer, NULL, devno, NULL, + struct device *dev_ret; + dev_ret = device_create(class_buzzer, NULL, devno, NULL, DEVNAME_BUZZER "%u", _minor_buzzer); + + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_buzzer); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; @@ -1461,8 +1481,17 @@ static int motorrawr_register_dev(void) _minor_motorrawr); } else { /* デバイスノードの作成 */ + struct device *dev_ret; device_create(class_motorrawr, NULL, devno, NULL, DEVNAME_MOTORRAWR "%u", _minor_motorrawr); + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_motorrawr); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; @@ -1512,8 +1541,18 @@ static int motorrawl_register_dev(void) _minor_motorrawl); } else { /* デバイスノードの作成 */ + struct device *dev_ret; device_create(class_motorrawl, NULL, devno, NULL, DEVNAME_MOTORRAWL "%u", _minor_motorrawl); + + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_motorrawl); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; @@ -1566,8 +1605,17 @@ static int switch_register_dev(void) _minor_switch + i); } else { /* デバイスノードの作成 */ + struct device *dev_ret; device_create(class_switch, NULL, devno, NULL, DEVNAME_SWITCH "%u", _minor_switch + i); + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_switch + i); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; } @@ -1616,8 +1664,17 @@ static int sensor_register_dev(void) printk(KERN_ERR "cdev_add failed minor = %d\n", _minor_sensor); } else { /* デバイスノードの作成 */ - device_create(class_sensor, NULL, devno, NULL, + struct device *dev_ret; + dev_ret = device_create(class_sensor, NULL, devno, NULL, DEVNAME_SENSOR "%u", _minor_sensor); + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_sensor); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; @@ -1665,8 +1722,17 @@ static int motoren_register_dev(void) printk(KERN_ERR "cdev_add failed minor = %d\n", _minor_motoren); } else { /* デバイスノードの作成 */ - device_create(class_motoren, NULL, devno, NULL, + struct device *dev_ret; + dev_ret = device_create(class_motoren, NULL, devno, NULL, DEVNAME_MOTOREN "%u", _minor_motoren); + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_motoren); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; @@ -1714,8 +1780,17 @@ static int motor_register_dev(void) printk(KERN_ERR "cdev_add failed minor = %d\n", _minor_motor); } else { /* デバイスノードの作成 */ - device_create(class_motor, NULL, devno, NULL, + struct device *dev_ret; + dev_ret = device_create(class_motor, NULL, devno, NULL, DEVNAME_MOTOR "%u", _minor_motor); + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", _minor_motor); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } cdev_index++; @@ -1989,9 +2064,20 @@ static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) } for (minor = DEV_MINOR; minor < DEV_MINOR + NUM_DEV_CNT; minor++) { - device_create(dev_info->device_class, NULL, + + struct device *dev_ret; + dev_ret = device_create(dev_info->device_class, NULL, MKDEV(dev_info->device_major, minor), NULL, "rtcounter_r%d", minor); + + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", minor); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } return 0; @@ -2044,9 +2130,20 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) /* /sys/class/mydevice/mydevice* を作る */ for (minor = DEV_MINOR; minor < DEV_MINOR + NUM_DEV_CNT; minor++) { - device_create(dev_info->device_class, NULL, + + struct device *dev_ret; + dev_ret = device_create(dev_info->device_class, NULL, MKDEV(dev_info->device_major, minor), NULL, "rtcounter_l%d", minor); + + /* デバイスファイル作成の可否を判定 */ + if (IS_ERR(dev_ret)) { + /* デバイスファイルの作成に失敗した */ + printk(KERN_ERR "device_create failed minor = %d\n", minor); + /* リソースリークを避けるために登録された状態cdevを削除する */ + cdev_del(&(cdev_array[cdev_index])); + return PTR_ERR(dev_ret); + } } return 0; From 2e320a26dce2de85e76877cb4993fb9419587228 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Mon, 26 Aug 2024 18:07:17 +0900 Subject: [PATCH 09/22] =?UTF-8?q?spi=E3=82=92=E3=82=B5=E3=83=BC=E3=83=81?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=B3=E3=83=BC=E3=83=AB=E3=83=90=E3=83=83?= =?UTF-8?q?=E3=82=AF=E9=96=A2=E6=95=B0=E3=81=8C=E9=81=8E=E5=8E=BB=E3=81=AE?= =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=8D=E3=83=AB=E3=81=A7=E3=82=82=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=81=95=E3=82=8C=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86?= =?UTF-8?q?=E7=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3=E3=80=82=E5=88=86=E5=B2=90?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E3=81=AE=E5=A4=A7=E3=81=AA=E3=82=8A=E5=B0=8F?= =?UTF-8?q?=E3=81=AA=E3=82=8A=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=A6?= =?UTF-8?q?=E6=89=B1=E3=81=84=E3=82=84=E3=81=99=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 55 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index f213e36..e2bb26e 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -326,6 +326,7 @@ static struct spi_board_info mcp3204_info = { .mode = SPI_MODE_3, }; + static struct device *mcp320x_dev; @@ -1881,20 +1882,18 @@ static unsigned int mcp3204_get_value(int channel) unsigned int r = 0; unsigned char c = channel & 0x03; - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) + #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) + if (mcp320x_dev == NULL) return 0; + dev = mcp320x_dev; + + #else struct spi_master *master; master = spi_busnum_to_master(mcp3204_info.bus_num); snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), mcp3204_info.chip_select); dev = bus_find_device_by_name(&spi_bus_type, NULL, str); - - #else - - if (mcp320x_dev == NULL) return 0; - dev = mcp320x_dev; - #endif spi = to_spi_device(dev); @@ -1939,17 +1938,18 @@ static void spi_remove_device(struct spi_master *master, unsigned int cs) } } -/* spiをサーチする関数 */ -static int __callback_find_mcp3204(struct device *dev, void *data) -{ - printk(KERN_INFO " device_name: %s\n", dev->driver->name); - if(mcp320x_dev == NULL && strcmp(dev->driver->name, "mcp320x") == 0){ - mcp320x_dev = dev; - mcp3204_probe(to_spi_device(dev)); - } - return 0; -} - +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) + /* spiをサーチする関数 */ + static int __callback_find_mcp3204(struct device *dev, void *data) + { + printk(KERN_INFO " device_name: %s\n", dev->driver->name); + if(mcp320x_dev == NULL && strcmp(dev->driver->name, "mcp320x") == 0){ + mcp320x_dev = dev; + mcp3204_probe(to_spi_device(dev)); + } + return 0; + } +#endif /* * mcp3204_init - initialize MCP3204 @@ -1958,7 +1958,9 @@ static int __callback_find_mcp3204(struct device *dev, void *data) static int mcp3204_init(void) { - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) + #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) + bus_for_each_dev(&spi_bus_type, NULL, NULL, __callback_find_mcp3204); + #else struct spi_master *master; struct spi_device *spi_device; @@ -1984,8 +1986,6 @@ static int mcp3204_init(void) spi_unregister_driver(&mcp3204_driver); return -ENODEV; } - #else - bus_for_each_dev(&spi_bus_type, NULL, NULL, __callback_find_mcp3204); #endif return 0; @@ -1998,9 +1998,13 @@ static int mcp3204_init(void) static void mcp3204_exit(void) { - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) + #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) + printk(KERN_INFO " mcp3204_exit\n"); + if (mcp320x_dev) { + mcp3204_remove(to_spi_device(mcp320x_dev)); + } + #else struct spi_master *master; - master = spi_busnum_to_master(mcp3204_info.bus_num); if (master) { @@ -2010,11 +2014,6 @@ static void mcp3204_exit(void) } spi_unregister_driver(&mcp3204_driver); - #else - printk(KERN_INFO " mcp3204_exit\n"); - if (mcp320x_dev) { - mcp3204_remove(to_spi_device(mcp320x_dev)); - } #endif } From c393000f2f63f24f8c43e02a78ed84920469ce7f Mon Sep 17 00:00:00 2001 From: kurasawa Date: Mon, 26 Aug 2024 18:31:56 +0900 Subject: [PATCH 10/22] =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E3=83=84=E3=83=AA=E3=83=BC=E3=81=8B=E3=82=89=E5=8F=97=E3=81=91?= =?UTF-8?q?=E5=8F=96=E3=82=8Bmcp320x=5Fdev=E3=81=AE=E6=A7=8B=E9=80=A0?= =?UTF-8?q?=E4=BD=93=E3=81=AE=E5=AE=9A=E7=BE=A9=E3=82=92=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E3=81=A7=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=20[=E8=A3=9C=E8=B6=B3]=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E3=81=AA=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index e2bb26e..a057d3e 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -326,9 +326,9 @@ static struct spi_board_info mcp3204_info = { .mode = SPI_MODE_3, }; - +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) static struct device *mcp320x_dev; - +#endif /* SPI Dirver Info */ static struct spi_driver mcp3204_driver = { @@ -1964,7 +1964,7 @@ static int mcp3204_init(void) struct spi_master *master; struct spi_device *spi_device; - spi_register_driver(&mcp3204_driver); // ここifdefで囲っていいかも + spi_register_driver(&mcp3204_driver); mcp3204_info.bus_num = spi_bus_num; mcp3204_info.chip_select = spi_chip_select; From 3d1860ec58ff52dce88f093ee40afae6e0c86d9c Mon Sep 17 00:00:00 2001 From: kurasawa Date: Tue, 27 Aug 2024 13:57:26 +0900 Subject: [PATCH 11/22] =?UTF-8?q?dtoverlay=E3=82=92/boot/firmware/config.t?= =?UTF-8?q?xt=E3=81=AE=E6=9C=AB=E5=B0=BE=E3=81=AB=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/add_dtoverlay.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 utils/add_dtoverlay.sh diff --git a/utils/add_dtoverlay.sh b/utils/add_dtoverlay.sh new file mode 100755 index 0000000..59dcddc --- /dev/null +++ b/utils/add_dtoverlay.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -eu + +# dtoverlay-setting +DTOVERLAY='dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000' + +# config-file PATH +CONFIG_FILE='/boot/firmware/config.txt' + +# add dtoverlay-setting for "/boot/firmware/config.txt" +if ! grep -qxF "$DTOVERLAY" "$CONFIG_FILE"; then + echo "$DTOVERLAY" | sudo tee -a "$CONFIG_FILE" +fi From 3c5cb33f7f9b8ff1ed2ac96e044d5fe5bb3ade9c Mon Sep 17 00:00:00 2001 From: kurasawa Date: Wed, 28 Aug 2024 15:58:50 +0900 Subject: [PATCH 12/22] =?UTF-8?q?Raspberry=20Pi=20=E3=81=AE=E3=83=90?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E6=8C=87=E5=AE=9A=E3=81=8C?= =?UTF-8?q?2=E3=81=8B=E3=82=894=E3=81=AB=E5=A4=89=E3=82=8F=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=97=E3=81=BE=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F?= =?UTF-8?q?=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index a057d3e..6563a98 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -51,7 +51,7 @@ // Raspberry Pi 2 B : 2 // Raspberry Pi 3 B/A+/B+ : 2 // Raspberry Pi 4 B : 4 -#define RASPBERRYPI 4 +#define RASPBERRYPI 2 MODULE_AUTHOR("RT Corporation"); MODULE_LICENSE("GPL"); From 988a4b378817275f74853675caa1b0da8e2a869c Mon Sep 17 00:00:00 2001 From: kurasawa Date: Wed, 28 Aug 2024 16:12:45 +0900 Subject: [PATCH 13/22] =?UTF-8?q?"/boot/firmware/config.txt"=E3=81=B8?= =?UTF-8?q?=E6=9B=B8=E3=81=8D=E8=BE=BC=E3=82=80=E3=82=B9=E3=82=AF=E3=83=AA?= =?UTF-8?q?=E3=83=97=E3=83=88=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/add_dtoverlay.sh | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100755 utils/add_dtoverlay.sh diff --git a/utils/add_dtoverlay.sh b/utils/add_dtoverlay.sh deleted file mode 100755 index 59dcddc..0000000 --- a/utils/add_dtoverlay.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -eu - -# dtoverlay-setting -DTOVERLAY='dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000' - -# config-file PATH -CONFIG_FILE='/boot/firmware/config.txt' - -# add dtoverlay-setting for "/boot/firmware/config.txt" -if ! grep -qxF "$DTOVERLAY" "$CONFIG_FILE"; then - echo "$DTOVERLAY" | sudo tee -a "$CONFIG_FILE" -fi From 436f93dfe2baea180c1c89b9749ffbcd3f38e255 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Wed, 28 Aug 2024 18:33:20 +0900 Subject: [PATCH 14/22] =?UTF-8?q?=E3=83=9E=E3=82=AF=E3=83=AD=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=E9=83=A8=E5=88=86=E3=81=AE=E3=82=A4=E3=83=B3=E3=83=87?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 421 +++++++++++++++++++++--------------------- 1 file changed, 213 insertions(+), 208 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 6563a98..5af56f8 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -279,24 +279,25 @@ static void set_motor_r_freq(int freq); static void set_motor_l_freq(int freq); #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) - static int mcp3204_remove(struct spi_device *spi); +static int mcp3204_remove(struct spi_device *spi); #else - static void mcp3204_remove(struct spi_device *spi); +static void mcp3204_remove(struct spi_device *spi); #endif + static int mcp3204_probe(struct spi_device *spi); static unsigned int mcp3204_get_value(int channel); #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) - static int rtcnt_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id); +static int rtcnt_i2c_probe( + struct i2c_client *client,const struct i2c_device_id *id); #else - static int rtcnt_i2c_probe(struct i2c_client *client); +static int rtcnt_i2c_probe(struct i2c_client *client); #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0) - static int rtcnt_i2c_remove(struct i2c_client *client); +static int rtcnt_i2c_remove(struct i2c_client *client); #else - static void rtcnt_i2c_remove(struct i2c_client *client); +static void rtcnt_i2c_remove(struct i2c_client *client); #endif /* --- Variable Type definitions --- */ @@ -1338,11 +1339,11 @@ static int led_register_dev(void) _major_led = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_led = class_create(THIS_MODULE, DEVNAME_LED); - #else - class_led = class_create(DEVNAME_LED); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_led = class_create(THIS_MODULE, DEVNAME_LED); +#else + class_led = class_create(DEVNAME_LED); +#endif if (IS_ERR(class_led)) { return PTR_ERR(class_led); @@ -1402,11 +1403,12 @@ static int buzzer_register_dev(void) _major_buzzer = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_buzzer = class_create(THIS_MODULE, DEVNAME_BUZZER); - #else - class_buzzer = class_create(DEVNAME_BUZZER); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_buzzer = class_create(THIS_MODULE, DEVNAME_BUZZER); +#else + class_buzzer = class_create(DEVNAME_BUZZER); +#endif + if (IS_ERR(class_buzzer)) { return PTR_ERR(class_buzzer); } @@ -1462,11 +1464,12 @@ static int motorrawr_register_dev(void) _major_motorrawr = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_motorrawr = class_create(THIS_MODULE, DEVNAME_MOTORRAWR); - #else - class_motorrawr = class_create(DEVNAME_MOTORRAWR); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motorrawr = class_create(THIS_MODULE, DEVNAME_MOTORRAWR); +#else + class_motorrawr = class_create(DEVNAME_MOTORRAWR); +#endif + if (IS_ERR(class_motorrawr)) { return PTR_ERR(class_motorrawr); } @@ -1523,11 +1526,12 @@ static int motorrawl_register_dev(void) _major_motorrawl = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_motorrawl = class_create(THIS_MODULE, DEVNAME_MOTORRAWL); - #else - class_motorrawl = class_create(DEVNAME_MOTORRAWL); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motorrawl = class_create(THIS_MODULE, DEVNAME_MOTORRAWL); +#else + class_motorrawl = class_create(DEVNAME_MOTORRAWL); +#endif + if (IS_ERR(class_motorrawl)) { return PTR_ERR(class_motorrawl); } @@ -1584,11 +1588,12 @@ static int switch_register_dev(void) _major_switch = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_switch = class_create(THIS_MODULE, DEVNAME_SWITCH); - #else - class_switch = class_create(DEVNAME_SWITCH); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_switch = class_create(THIS_MODULE, DEVNAME_SWITCH); +#else + class_switch = class_create(DEVNAME_SWITCH); +#endif + if (IS_ERR(class_switch)) { return PTR_ERR(class_switch); } @@ -1646,11 +1651,12 @@ static int sensor_register_dev(void) _major_sensor = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_sensor = class_create(THIS_MODULE, DEVNAME_SENSOR); - #else - class_sensor = class_create(DEVNAME_SENSOR); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_sensor = class_create(THIS_MODULE, DEVNAME_SENSOR); +#else + class_sensor = class_create(DEVNAME_SENSOR); +#endif + if (IS_ERR(class_sensor)) { return PTR_ERR(class_sensor); } @@ -1705,11 +1711,12 @@ static int motoren_register_dev(void) _major_motoren = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_motoren = class_create(THIS_MODULE, DEVNAME_MOTOREN); - #else - class_motoren = class_create(DEVNAME_MOTOREN); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motoren = class_create(THIS_MODULE, DEVNAME_MOTOREN); +#else + class_motoren = class_create(DEVNAME_MOTOREN); +#endif + if (IS_ERR(class_motoren)) { return PTR_ERR(class_motoren); } @@ -1763,11 +1770,12 @@ static int motor_register_dev(void) _major_motor = MAJOR(dev); /* デバイスクラスを作成する */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - class_motor = class_create(THIS_MODULE, DEVNAME_MOTOR); - #else - class_motor = class_create(DEVNAME_MOTOR); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + class_motor = class_create(THIS_MODULE, DEVNAME_MOTOR); +#else + class_motor = class_create(DEVNAME_MOTOR); +#endif + if (IS_ERR(class_motor)) { return PTR_ERR(class_motor); } @@ -1882,19 +1890,18 @@ static unsigned int mcp3204_get_value(int channel) unsigned int r = 0; unsigned char c = channel & 0x03; - #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) - - if (mcp320x_dev == NULL) return 0; - dev = mcp320x_dev; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) - #else - struct spi_master *master; - master = spi_busnum_to_master(mcp3204_info.bus_num); - snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), - mcp3204_info.chip_select); + if (mcp320x_dev == NULL) return 0; + dev = mcp320x_dev; - dev = bus_find_device_by_name(&spi_bus_type, NULL, str); - #endif +#else + struct spi_master *master; + master = spi_busnum_to_master(mcp3204_info.bus_num); + snprintf( + str, sizeof(str), "%s.%u", dev_name(&master->dev),mcp3204_info.chip_select); + dev = bus_find_device_by_name(&spi_bus_type, NULL, str); +#endif spi = to_spi_device(dev); data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); @@ -1958,35 +1965,35 @@ static void spi_remove_device(struct spi_master *master, unsigned int cs) static int mcp3204_init(void) { - #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) - bus_for_each_dev(&spi_bus_type, NULL, NULL, __callback_find_mcp3204); - #else - struct spi_master *master; - struct spi_device *spi_device; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) + bus_for_each_dev(&spi_bus_type, NULL, NULL, __callback_find_mcp3204); +#else + struct spi_master *master; + struct spi_device *spi_device; - spi_register_driver(&mcp3204_driver); + spi_register_driver(&mcp3204_driver); - mcp3204_info.bus_num = spi_bus_num; - mcp3204_info.chip_select = spi_chip_select; + mcp3204_info.bus_num = spi_bus_num; + mcp3204_info.chip_select = spi_chip_select; - master = spi_busnum_to_master(mcp3204_info.bus_num); + master = spi_busnum_to_master(mcp3204_info.bus_num); - if (!master) { - printk(KERN_ERR "%s: spi_busnum_to_master returned NULL\n", - __func__); - spi_unregister_driver(&mcp3204_driver); - return -ENODEV; - } + if (!master) { + printk(KERN_ERR "%s: spi_busnum_to_master returned NULL\n", + __func__); + spi_unregister_driver(&mcp3204_driver); + return -ENODEV; + } - spi_remove_device(master, mcp3204_info.chip_select); + spi_remove_device(master, mcp3204_info.chip_select); - spi_device = spi_new_device(master, &mcp3204_info); - if (!spi_device) { - printk(KERN_ERR "%s: spi_new_device returned NULL\n", __func__); - spi_unregister_driver(&mcp3204_driver); - return -ENODEV; - } - #endif + spi_device = spi_new_device(master, &mcp3204_info); + if (!spi_device) { + printk(KERN_ERR "%s: spi_new_device returned NULL\n", __func__); + spi_unregister_driver(&mcp3204_driver); + return -ENODEV; + } +#endif return 0; } @@ -1998,23 +2005,23 @@ static int mcp3204_init(void) static void mcp3204_exit(void) { - #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) - printk(KERN_INFO " mcp3204_exit\n"); - if (mcp320x_dev) { - mcp3204_remove(to_spi_device(mcp320x_dev)); - } - #else - struct spi_master *master; - master = spi_busnum_to_master(mcp3204_info.bus_num); - - if (master) { - spi_remove_device(master, mcp3204_info.chip_select); - } else { - printk(KERN_ERR "mcp3204 remove error\n"); - } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) + printk(KERN_INFO " mcp3204_exit\n"); + if (mcp320x_dev) { + mcp3204_remove(to_spi_device(mcp320x_dev)); + } +#else + struct spi_master *master; + master = spi_busnum_to_master(mcp3204_info.bus_num); - spi_unregister_driver(&mcp3204_driver); - #endif + if (master) { + spi_remove_device(master, mcp3204_info.chip_select); + } else { + printk(KERN_ERR "mcp3204 remove error\n"); + } + + spi_unregister_driver(&mcp3204_driver); +#endif } static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) @@ -2050,11 +2057,12 @@ static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) } /* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTR); - #else - dev_info->device_class = class_create(DEVNAME_CNTR); - #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTR); +#else + dev_info->device_class = class_create(DEVNAME_CNTR); +#endif + if (IS_ERR(dev_info->device_class)) { printk(KERN_ERR "class_create\n"); cdev_del(&dev_info->cdev); @@ -2114,12 +2122,13 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) return -1; } - /* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */ - #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) - dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTL); - #else - dev_info->device_class = class_create(DEVNAME_CNTL); - #endif +/* このデバイスのクラス登録をする(/sys/class/mydevice/ を作る) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) + dev_info->device_class = class_create(THIS_MODULE, DEVNAME_CNTL); +#else + dev_info->device_class = class_create(DEVNAME_CNTL); +#endif + if (IS_ERR(dev_info->device_class)) { printk(KERN_ERR "class_create\n"); cdev_del(&dev_info->cdev); @@ -2149,87 +2158,83 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) } #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) - static int rtcnt_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) - { - struct rtcnt_device_info *dev_info; - int msb = 0, lsb = 0; - // printk(KERN_DEBUG "%s: probing i2c device", __func__); - - /* check i2c device */ - // printk(KERN_DEBUG "%s: checking i2c device", __func__); - msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); - lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); - if ((msb < 0) || (lsb < 0)) { - printk(KERN_INFO - "%s: rtcounter not found, or wrong i2c device probed", - DRIVER_NAME); - // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, - // client->addr, msb, lsb); - return -ENODEV; - } - printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " - "id.driver_data=%d, addr=0x%x\n", - DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); - - dev_info = (struct rtcnt_device_info *)devm_kzalloc( - &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); - dev_info->client = client; - i2c_set_clientdata(client, dev_info); - mutex_init(&dev_info->lock); - - /* create character device */ - if ((int)(id->driver_data) == 0) { - if (rtcntl_i2c_create_cdev(dev_info)) - return -ENOMEM; - } else if ((int)(id->driver_data) == 1) { - if (rtcntr_i2c_create_cdev(dev_info)) - return -ENOMEM; - } +static int rtcnt_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct rtcnt_device_info *dev_info; + int msb = 0, lsb = 0; + // printk(KERN_DEBUG "%s: probing i2c device", __func__); - return 0; - } + /* check i2c device */ + // printk(KERN_DEBUG "%s: checking i2c device", __func__); + msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); + lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); + if ((msb < 0) || (lsb < 0)) { + printk(KERN_INFO + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); + // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, + // client->addr, msb, lsb); + return -ENODEV; + } + printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " + "id.driver_data=%d, addr=0x%x\n", + DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); + + dev_info = (struct rtcnt_device_info *)devm_kzalloc( + &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); + dev_info->client = client; + i2c_set_clientdata(client, dev_info); + mutex_init(&dev_info->lock); + + /* create character device */ + if ((int)(id->driver_data) == 0) { + if (rtcntl_i2c_create_cdev(dev_info)) return -ENOMEM; + } else if ((int)(id->driver_data) == 1) { + if (rtcntr_i2c_create_cdev(dev_info)) return -ENOMEM; + } + + return 0; +} #else - static int rtcnt_i2c_probe(struct i2c_client *client) - { - const struct i2c_device_id *id = i2c_client_get_device_id(client); - struct rtcnt_device_info *dev_info; - int msb = 0, lsb = 0; - // printk(KERN_DEBUG "%s: probing i2c device", __func__); - - /* check i2c device */ - // printk(KERN_DEBUG "%s: checking i2c device", __func__); - msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); - lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); - if ((msb < 0) || (lsb < 0)) { - printk(KERN_INFO - "%s: rtcounter not found, or wrong i2c device probed", - DRIVER_NAME); - // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, - // client->addr, msb, lsb); - return -ENODEV; - } - printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " - "id.driver_data=%d, addr=0x%x\n", - DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); - - dev_info = (struct rtcnt_device_info *)devm_kzalloc( - &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); - dev_info->client = client; - i2c_set_clientdata(client, dev_info); - mutex_init(&dev_info->lock); - - /* create character device */ - if ((int)(id->driver_data) == 0) { - if (rtcntl_i2c_create_cdev(dev_info)) - return -ENOMEM; - } else if ((int)(id->driver_data) == 1) { - if (rtcntr_i2c_create_cdev(dev_info)) - return -ENOMEM; - } +static int rtcnt_i2c_probe(struct i2c_client *client) +{ + const struct i2c_device_id *id = i2c_client_get_device_id(client); + struct rtcnt_device_info *dev_info; + int msb = 0, lsb = 0; + // printk(KERN_DEBUG "%s: probing i2c device", __func__); - return 0; - } + /* check i2c device */ + // printk(KERN_DEBUG "%s: checking i2c device", __func__); + msb = i2c_smbus_read_byte_data(client, CNT_ADDR_MSB); + lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); + if ((msb < 0) || (lsb < 0)) { + printk(KERN_INFO + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); + // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, + // client->addr, msb, lsb); + return -ENODEV; + } + printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " + "id.driver_data=%d, addr=0x%x\n", + DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); + + dev_info = (struct rtcnt_device_info *)devm_kzalloc( + &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); + dev_info->client = client; + i2c_set_clientdata(client, dev_info); + mutex_init(&dev_info->lock); + + /* create character device */ + if ((int)(id->driver_data) == 0) { + if (rtcntl_i2c_create_cdev(dev_info)) return -ENOMEM; + } else if ((int)(id->driver_data) == 1) { + if (rtcntr_i2c_create_cdev(dev_info)) return -ENOMEM; + } + + return 0; +} #endif /* @@ -2280,7 +2285,7 @@ static int i2c_counter_init(void) i2c_adap_r = i2c_get_adapter(1); i2c_client_r = i2c_new_client_device(i2c_adap_r, &i2c_board_info_r); i2c_put_adapter(i2c_adap_r); -// printk(KERN_DEBUG "%s: added i2c device rtcntr", __func__); + // printk(KERN_DEBUG "%s: added i2c device rtcntr", __func__); #endif return retval; @@ -2323,28 +2328,28 @@ static void rtcnt_i2c_delete_cdev(struct rtcnt_device_info *dev_info) * called when I2C pulse counter removed */ #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0) - static int rtcnt_i2c_remove(struct i2c_client *client) - { - struct rtcnt_device_info *dev_info; - // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, - // client->addr); - dev_info = i2c_get_clientdata(client); - rtcnt_i2c_delete_cdev(dev_info); - printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, - client->addr); - return 0; - } +static int rtcnt_i2c_remove(struct i2c_client *client) +{ + struct rtcnt_device_info *dev_info; + // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, + // client->addr); + dev_info = i2c_get_clientdata(client); + rtcnt_i2c_delete_cdev(dev_info); + printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, + client->addr); + return 0; +} #else - static void rtcnt_i2c_remove(struct i2c_client *client) - { - struct rtcnt_device_info *dev_info; - // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, - // client->addr); - dev_info = i2c_get_clientdata(client); - rtcnt_i2c_delete_cdev(dev_info); - printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, - client->addr); - } +static void rtcnt_i2c_remove(struct i2c_client *client) +{ + struct rtcnt_device_info *dev_info; + // printk(KERN_DEBUG "%s: removing i2c device 0x%x\n", __func__, + // client->addr); + dev_info = i2c_get_clientdata(client); + rtcnt_i2c_delete_cdev(dev_info); + printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, + client->addr); +} #endif /* From cd4967aaf6658fdebb5a2e031111e92055633c12 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Thu, 29 Aug 2024 10:37:07 +0900 Subject: [PATCH 15/22] =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=BF=E3=81=AB?= =?UTF-8?q?=E5=90=88=E3=82=8F=E3=81=9B=E3=81=9F=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E=E3=83=83=E3=83=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 190 ++++++++++++++++++++++++------------------ 1 file changed, 109 insertions(+), 81 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 5af56f8..660a5c2 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -288,8 +288,8 @@ static int mcp3204_probe(struct spi_device *spi); static unsigned int mcp3204_get_value(int channel); #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) -static int rtcnt_i2c_probe( - struct i2c_client *client,const struct i2c_device_id *id); +static int rtcnt_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id); #else static int rtcnt_i2c_probe(struct i2c_client *client); #endif @@ -1363,14 +1363,18 @@ static int led_register_dev(void) } else { /* デバイスノードの作成 */ struct device *dev_ret; - dev_ret = device_create(class_led, NULL, devno, NULL, - DEVNAME_LED "%u", _minor_led + i); + dev_ret = + device_create(class_led, NULL, devno, NULL, + DEVNAME_LED "%u", _minor_led + i); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_led + i); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR + "device_create failed minor = %d\n", + _minor_led + i); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1425,13 +1429,15 @@ static int buzzer_register_dev(void) /* デバイスノードの作成 */ struct device *dev_ret; dev_ret = device_create(class_buzzer, NULL, devno, NULL, - DEVNAME_BUZZER "%u", _minor_buzzer); + DEVNAME_BUZZER "%u", _minor_buzzer); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_buzzer); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + _minor_buzzer); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1491,8 +1497,10 @@ static int motorrawr_register_dev(void) /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_motorrawr); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + _minor_motorrawr); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1553,8 +1561,10 @@ static int motorrawl_register_dev(void) /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_motorrawl); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + _minor_motorrawl); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1617,8 +1627,11 @@ static int switch_register_dev(void) /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_switch + i); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR + "device_create failed minor = %d\n", + _minor_switch + i); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1673,12 +1686,14 @@ static int sensor_register_dev(void) /* デバイスノードの作成 */ struct device *dev_ret; dev_ret = device_create(class_sensor, NULL, devno, NULL, - DEVNAME_SENSOR "%u", _minor_sensor); + DEVNAME_SENSOR "%u", _minor_sensor); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_sensor); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + _minor_sensor); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1732,12 +1747,14 @@ static int motoren_register_dev(void) /* デバイスノードの作成 */ struct device *dev_ret; dev_ret = device_create(class_motoren, NULL, devno, NULL, - DEVNAME_MOTOREN "%u", _minor_motoren); + DEVNAME_MOTOREN "%u", _minor_motoren); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_motoren); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + _minor_motoren); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1791,12 +1808,14 @@ static int motor_register_dev(void) /* デバイスノードの作成 */ struct device *dev_ret; dev_ret = device_create(class_motor, NULL, devno, NULL, - DEVNAME_MOTOR "%u", _minor_motor); + DEVNAME_MOTOR "%u", _minor_motor); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", _minor_motor); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + _minor_motor); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -1809,26 +1828,26 @@ static int motor_register_dev(void) /* mcp3204_remove - remove function lined with spi_dirver */ #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) - static int mcp3204_remove(struct spi_device *spi) - { - struct mcp3204_drvdata *data; - /* get drvdata */ - data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); - /* free kernel memory */ - kfree(data); - printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); - return 0; - } +static int mcp3204_remove(struct spi_device *spi) +{ + struct mcp3204_drvdata *data; + /* get drvdata */ + data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); + /* free kernel memory */ + kfree(data); + printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); + return 0; +} #else - static void mcp3204_remove(struct spi_device *spi) - { - struct mcp3204_drvdata *data; - /* get drvdata */ - data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); - /* free kernel memory */ - kfree(data); - printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); - } +static void mcp3204_remove(struct spi_device *spi) +{ + struct mcp3204_drvdata *data; + /* get drvdata */ + data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); + /* free kernel memory */ + kfree(data); + printk(KERN_INFO "%s: mcp3204 removed\n", DRIVER_NAME); +} #endif /* mcp3204_probe - probe function lined with spi_dirver */ @@ -1892,19 +1911,20 @@ static unsigned int mcp3204_get_value(int channel) #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) - if (mcp320x_dev == NULL) return 0; - dev = mcp320x_dev; + if (mcp320x_dev == NULL) + return 0; + dev = mcp320x_dev; #else struct spi_master *master; master = spi_busnum_to_master(mcp3204_info.bus_num); - snprintf( - str, sizeof(str), "%s.%u", dev_name(&master->dev),mcp3204_info.chip_select); + snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), + mcp3204_info.chip_select); dev = bus_find_device_by_name(&spi_bus_type, NULL, str); #endif spi = to_spi_device(dev); - data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); + data = (struct mcp3204_drvdata *)spi_get_drvdata(spi); mutex_lock(&data->lock); data->tx[0] = 1 << 2; // start bit data->tx[0] |= 1 << 1; // Single @@ -1913,7 +1933,7 @@ static unsigned int mcp3204_get_value(int channel) if (spi_sync(data->spi, &data->msg)) { printk(KERN_INFO "%s: spi_sync_transfer returned non zero\n", - __func__); + __func__); } mutex_unlock(&data->lock); @@ -1939,23 +1959,23 @@ static void spi_remove_device(struct spi_master *master, unsigned int cs) snprintf(str, sizeof(str), "%s.%u", dev_name(&master->dev), cs); dev = bus_find_device_by_name(&spi_bus_type, NULL, str); - //ここを参考にspi_deviceを取得するプログラムを作成する + // ここを参考にspi_deviceを取得するプログラムを作成する if (dev) { device_del(dev); } } #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0) - /* spiをサーチする関数 */ - static int __callback_find_mcp3204(struct device *dev, void *data) - { +/* spiをサーチする関数 */ +static int __callback_find_mcp3204(struct device *dev, void *data) +{ printk(KERN_INFO " device_name: %s\n", dev->driver->name); - if(mcp320x_dev == NULL && strcmp(dev->driver->name, "mcp320x") == 0){ + if (mcp320x_dev == NULL && strcmp(dev->driver->name, "mcp320x") == 0) { mcp320x_dev = dev; mcp3204_probe(to_spi_device(dev)); } return 0; - } +} #endif /* @@ -1980,7 +2000,7 @@ static int mcp3204_init(void) if (!master) { printk(KERN_ERR "%s: spi_busnum_to_master returned NULL\n", - __func__); + __func__); spi_unregister_driver(&mcp3204_driver); return -ENODEV; } @@ -2074,14 +2094,16 @@ static int rtcntr_i2c_create_cdev(struct rtcnt_device_info *dev_info) struct device *dev_ret; dev_ret = device_create(dev_info->device_class, NULL, - MKDEV(dev_info->device_major, minor), NULL, - "rtcounter_r%d", minor); + MKDEV(dev_info->device_major, minor), + NULL, "rtcounter_r%d", minor); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", minor); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + minor); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -2141,14 +2163,16 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) struct device *dev_ret; dev_ret = device_create(dev_info->device_class, NULL, - MKDEV(dev_info->device_major, minor), NULL, - "rtcounter_l%d", minor); + MKDEV(dev_info->device_major, minor), + NULL, "rtcounter_l%d", minor); /* デバイスファイル作成の可否を判定 */ if (IS_ERR(dev_ret)) { /* デバイスファイルの作成に失敗した */ - printk(KERN_ERR "device_create failed minor = %d\n", minor); - /* リソースリークを避けるために登録された状態cdevを削除する */ + printk(KERN_ERR "device_create failed minor = %d\n", + minor); + /* リソースリークを避けるために登録された状態cdevを削除する + */ cdev_del(&(cdev_array[cdev_index])); return PTR_ERR(dev_ret); } @@ -2159,7 +2183,7 @@ static int rtcntl_i2c_create_cdev(struct rtcnt_device_info *dev_info) #if LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0) static int rtcnt_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { struct rtcnt_device_info *dev_info; int msb = 0, lsb = 0; @@ -2171,27 +2195,29 @@ static int rtcnt_i2c_probe(struct i2c_client *client, lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); if ((msb < 0) || (lsb < 0)) { printk(KERN_INFO - "%s: rtcounter not found, or wrong i2c device probed", - DRIVER_NAME); + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, // client->addr, msb, lsb); return -ENODEV; } printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " - "id.driver_data=%d, addr=0x%x\n", - DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); + "id.driver_data=%d, addr=0x%x\n", + DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); dev_info = (struct rtcnt_device_info *)devm_kzalloc( - &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); + &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); dev_info->client = client; i2c_set_clientdata(client, dev_info); mutex_init(&dev_info->lock); /* create character device */ if ((int)(id->driver_data) == 0) { - if (rtcntl_i2c_create_cdev(dev_info)) return -ENOMEM; + if (rtcntl_i2c_create_cdev(dev_info)) + return -ENOMEM; } else if ((int)(id->driver_data) == 1) { - if (rtcntr_i2c_create_cdev(dev_info)) return -ENOMEM; + if (rtcntr_i2c_create_cdev(dev_info)) + return -ENOMEM; } return 0; @@ -2210,27 +2236,29 @@ static int rtcnt_i2c_probe(struct i2c_client *client) lsb = i2c_smbus_read_byte_data(client, CNT_ADDR_LSB); if ((msb < 0) || (lsb < 0)) { printk(KERN_INFO - "%s: rtcounter not found, or wrong i2c device probed", - DRIVER_NAME); + "%s: rtcounter not found, or wrong i2c device probed", + DRIVER_NAME); // printk(KERN_DEBUG "%s: addr 0x%x, msb %d, lsb %d", __func__, // client->addr, msb, lsb); return -ENODEV; } printk(KERN_INFO "%s: new i2c device probed, id.name=%s, " - "id.driver_data=%d, addr=0x%x\n", - DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); + "id.driver_data=%d, addr=0x%x\n", + DRIVER_NAME, id->name, (int)(id->driver_data), client->addr); dev_info = (struct rtcnt_device_info *)devm_kzalloc( - &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); + &client->dev, sizeof(struct rtcnt_device_info), GFP_KERNEL); dev_info->client = client; i2c_set_clientdata(client, dev_info); mutex_init(&dev_info->lock); /* create character device */ if ((int)(id->driver_data) == 0) { - if (rtcntl_i2c_create_cdev(dev_info)) return -ENOMEM; + if (rtcntl_i2c_create_cdev(dev_info)) + return -ENOMEM; } else if ((int)(id->driver_data) == 1) { - if (rtcntr_i2c_create_cdev(dev_info)) return -ENOMEM; + if (rtcntr_i2c_create_cdev(dev_info)) + return -ENOMEM; } return 0; @@ -2336,7 +2364,7 @@ static int rtcnt_i2c_remove(struct i2c_client *client) dev_info = i2c_get_clientdata(client); rtcnt_i2c_delete_cdev(dev_info); printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, - client->addr); + client->addr); return 0; } #else @@ -2348,7 +2376,7 @@ static void rtcnt_i2c_remove(struct i2c_client *client) dev_info = i2c_get_clientdata(client); rtcnt_i2c_delete_cdev(dev_info); printk(KERN_INFO "%s: i2c device 0x%x removed\n", DRIVER_NAME, - client->addr); + client->addr); } #endif From d93887e7bfb722ef15851005bb76bcf92903af36 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Thu, 29 Aug 2024 10:43:07 +0900 Subject: [PATCH 16/22] =?UTF-8?q?=E4=BB=8A=E5=9B=9E=E3=81=AEUbuntu=20Serve?= =?UTF-8?q?r=2024.04=E3=81=AE=E5=AF=BE=E5=BF=9C=E3=81=AB=E5=90=88=E3=82=8F?= =?UTF-8?q?=E3=81=9B=E3=81=A6=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/drivers/rtmouse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/drivers/rtmouse.c b/src/drivers/rtmouse.c index 660a5c2..464d74c 100644 --- a/src/drivers/rtmouse.c +++ b/src/drivers/rtmouse.c @@ -3,7 +3,7 @@ * rtmouse.c * Raspberry Pi Mouse device driver * - * Version: 3.2.0 + * Version: 3.3.0 * * Copyright (C) 2015-2021 RT Corporation * @@ -55,7 +55,7 @@ MODULE_AUTHOR("RT Corporation"); MODULE_LICENSE("GPL"); -MODULE_VERSION("3.2.0"); +MODULE_VERSION("3.3.0"); MODULE_DESCRIPTION("Raspberry Pi Mouse device driver"); /* --- Device Numbers --- */ From 5dad352a38543eccac1feb1cbf766c9e8aeeacdc Mon Sep 17 00:00:00 2001 From: kurasawa Date: Mon, 2 Sep 2024 16:21:44 +0900 Subject: [PATCH 17/22] =?UTF-8?q?Ubuntu=2024.04=E3=82=92=E3=83=9B=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=A8=E3=81=97=E3=81=9FRaspberry=20Pi=E7=94=A8?= =?UTF-8?q?=E3=81=AE=E3=82=AB=E3=83=BC=E3=83=8D=E3=83=AB6.6=E3=82=92CI?= =?UTF-8?q?=E3=81=AEbuild=E5=AF=BE=E8=B1=A1=E3=81=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/driver-cross-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/driver-cross-build.yml b/.github/workflows/driver-cross-build.yml index 835f7e1..0fa210d 100644 --- a/.github/workflows/driver-cross-build.yml +++ b/.github/workflows/driver-cross-build.yml @@ -39,8 +39,8 @@ jobs: - { HOST: 20.04, KERNEL_VER: rpi-5.4.y, OS_BIT: armhf } # Debian 10 (Buster) - { HOST: 20.04, KERNEL_VER: rpi-5.10.y, OS_BIT: armhf } # Debian 11 (Bullseye) - { HOST: 22.04, KERNEL_VER: rpi-5.15.y, OS_BIT: armhf } # Debian 11 (Bullseye) - # - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: armhf } # Debian 12 (Bookworm) 32-bit - # - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: arm64 } # Debian 12 (Bookworm) 64-bit + - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: armhf } # Debian 12 (Bookworm) 32-bit + - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: arm64 } # Debian 12 (Bookworm) 64-bit runs-on: ubuntu-${{ matrix.env.HOST }} From 093abaccac8280d5c004b498cbce2ac311987dca Mon Sep 17 00:00:00 2001 From: kurasawa Date: Tue, 3 Sep 2024 10:58:15 +0900 Subject: [PATCH 18/22] =?UTF-8?q?=E3=82=AB=E3=83=BC=E3=83=8D=E3=83=ABrpi-6?= =?UTF-8?q?.6y=E3=81=AE=E3=83=9B=E3=82=B9=E3=83=88=E5=81=B4=E3=81=AE?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E3=82=9222.04?= =?UTF-8?q?=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/driver-cross-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/driver-cross-build.yml b/.github/workflows/driver-cross-build.yml index 0fa210d..da64dd5 100644 --- a/.github/workflows/driver-cross-build.yml +++ b/.github/workflows/driver-cross-build.yml @@ -39,8 +39,8 @@ jobs: - { HOST: 20.04, KERNEL_VER: rpi-5.4.y, OS_BIT: armhf } # Debian 10 (Buster) - { HOST: 20.04, KERNEL_VER: rpi-5.10.y, OS_BIT: armhf } # Debian 11 (Bullseye) - { HOST: 22.04, KERNEL_VER: rpi-5.15.y, OS_BIT: armhf } # Debian 11 (Bullseye) - - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: armhf } # Debian 12 (Bookworm) 32-bit - - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: arm64 } # Debian 12 (Bookworm) 64-bit + - { HOST: 22.04, KERNEL_VER: rpi-6.6.y, OS_BIT: armhf } # Debian 12 (Bookworm) 32-bit + - { HOST: 22.04, KERNEL_VER: rpi-6.6.y, OS_BIT: arm64 } # Debian 12 (Bookworm) 64-bit runs-on: ubuntu-${{ matrix.env.HOST }} From 5cf2297ecb4865cec89b64a1bceb242ea3bc7345 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Tue, 3 Sep 2024 11:13:26 +0900 Subject: [PATCH 19/22] =?UTF-8?q?modpost=E3=83=95=E3=82=A7=E3=83=BC?= =?UTF-8?q?=E3=82=BA=E3=81=A7=E3=81=AE=E8=AD=A6=E5=91=8A=E3=82=92=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=A8=E3=81=97=E3=81=A6=E6=89=B1=E3=82=8F?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=87=A6=E7=90=86=E3=81=A8=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0?= =?UTF-8?q?=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/driver-cross-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/driver-cross-build.yml b/.github/workflows/driver-cross-build.yml index da64dd5..ad30c77 100644 --- a/.github/workflows/driver-cross-build.yml +++ b/.github/workflows/driver-cross-build.yml @@ -76,7 +76,7 @@ jobs: run: | cd linux if [ "${{ matrix.env.OS_BIT }}" == "armhf" ]; then - make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- M=$GITHUB_WORKSPACE/src/drivers V=1 modules + make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- M=$GITHUB_WORKSPACE/src/drivers V=1 KBUILD_MODPOST_WARN=1 modules else - make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=$GITHUB_WORKSPACE/src/drivers V=1 modules + make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- M=$GITHUB_WORKSPACE/src/drivers V=1 KBUILD_MODPOST_WARN=1 modules fi From e6d91e7e8242cdfe5d8d762e71c6c7873a24aff5 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Tue, 3 Sep 2024 11:17:36 +0900 Subject: [PATCH 20/22] =?UTF-8?q?rpi-6.6.y=E3=81=AFHost=E5=81=B4=E3=81=AE?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E3=82=9224.04?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=20[=E8=A3=9C=E8=B6=B3]22.04=E3=81=A7?= =?UTF-8?q?=E3=81=AFCI=E3=82=92=E9=80=9A=E9=81=8E=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=9F=E7=8A=B6=E6=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/driver-cross-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/driver-cross-build.yml b/.github/workflows/driver-cross-build.yml index ad30c77..4b0f9c6 100644 --- a/.github/workflows/driver-cross-build.yml +++ b/.github/workflows/driver-cross-build.yml @@ -39,8 +39,8 @@ jobs: - { HOST: 20.04, KERNEL_VER: rpi-5.4.y, OS_BIT: armhf } # Debian 10 (Buster) - { HOST: 20.04, KERNEL_VER: rpi-5.10.y, OS_BIT: armhf } # Debian 11 (Bullseye) - { HOST: 22.04, KERNEL_VER: rpi-5.15.y, OS_BIT: armhf } # Debian 11 (Bullseye) - - { HOST: 22.04, KERNEL_VER: rpi-6.6.y, OS_BIT: armhf } # Debian 12 (Bookworm) 32-bit - - { HOST: 22.04, KERNEL_VER: rpi-6.6.y, OS_BIT: arm64 } # Debian 12 (Bookworm) 64-bit + - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: armhf } # Debian 12 (Bookworm) 32-bit + - { HOST: 24.04, KERNEL_VER: rpi-6.6.y, OS_BIT: arm64 } # Debian 12 (Bookworm) 64-bit runs-on: ubuntu-${{ matrix.env.HOST }} From 87d75797cdd1189cbd62dc5d1fcf4e333cecda89 Mon Sep 17 00:00:00 2001 From: kurasawa Date: Tue, 3 Sep 2024 11:59:32 +0900 Subject: [PATCH 21/22] =?UTF-8?q?README=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e392ef3..37f32a3 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,19 @@ Run the installation script ([`./utils/build_install.bash`](https://github.com/r インストール用のシェルスクリプト([`./utils/build_install.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/build_install.bash))を実行します。 -### for Raspbian +### for Raspberry Pi OS + +`/boot/firmware/config.txt`を編集し、ファイル末尾に以下の設定を追加します。 + +```sh +arm_64bit=0 # "64-bit"版では不要です +dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 +dtparam=i2c_baudrate=62500 +``` + +Raspberry Piを再起動します。 + +以下のコマンドでインストールを実行します。 ```sh $ git clone https://github.com/rt-net/RaspberryPiMouse.git @@ -22,6 +34,17 @@ $ ./build_install.bash ### for Ubuntu +`/boot/firmware/config.txt`を編集し、ファイル末尾に以下の設定を追加します。 + +```sh +dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 # "Ubuntu Server 22.04"では不要です +dtparam=i2c_baudrate=62500 +``` + +Raspberry Piを再起動します。 + +以下のコマンドでインストールを実行します。 + ```sh $ git clone https://github.com/rt-net/RaspberryPiMouse.git $ cd RaspberryPiMouse/utils @@ -40,7 +63,7 @@ $ sudo insmod rtmouse.ko ## Notes for the installation (ドライバの導入の際の注意) -### for Raspbian +### for Raspberry Pi OS Enable SPI and I2C functions via `raspi-config` command. @@ -50,17 +73,13 @@ Enable SPI and I2C functions via `raspi-config` command. * SPI機能を「入」にする。 * I2C機能を「入」にする。 -2017年1月現在、以下の設定は不要です。 -rtmouseをインストールして不具合が出た場合のみ以下の設定を追加で行ってください。 - -* Device Tree機能を「切」にする。 ### for Raspberry Pi 4 Edit [`rtmouse.c`](https://github.com/rt-net/RaspberryPiMouse/blob/dd0343449951a99b067e24aef3c03ae5ed9ab936/src/drivers/rtmouse.c#L54) to change the defined value `RASPBERRYPI` from '2' to '4'. -Raspberry Pi 4ではCPUのレジスタがそれまでのRaspberry Piとは異なります([issues#21](https://github.com/rt-net/RaspberryPiMouse/issues/21))。 -Raspberry Pi 4で本ドライバを使用する際には`rtmouse.c`の以下の行(2020年4月13日現在の最新版のv2.1.0では[54行目](https://github.com/rt-net/RaspberryPiMouse/blob/dd0343449951a99b067e24aef3c03ae5ed9ab936/src/drivers/rtmouse.c#L54))を`RASPBERRYPI 4`に書き換えてビルドする必要があります。 +Raspberry Pi 4ではCPUのレジスタがそれまでのRaspberry Piとは異なります([issues#21](https://github.com/rt-net/RaspberryPiMouse/issues/21))。 +Raspberry Pi 4で本ドライバを使用する際には`rtmouse.c`の以下の行(2020年4月13日現在の最新版のv2.1.0では[54行目](https://github.com/rt-net/RaspberryPiMouse/blob/dd0343449951a99b067e24aef3c03ae5ed9ab936/src/drivers/rtmouse.c#L54))を`RASPBERRYPI 4`に書き換えてビルドする必要があります。 ※[`./utils/build_install.bash`](./utils/build_install.bash)を実行すると、Raspberry Piのモデルに合わせて[`rtmouse.c`](./src/drivers/rtmouse.c)が[自動で書き換わります](https://github.com/rt-net/RaspberryPiMouse/blob/a9af4fa2b2a8e34c0f93a6ce5cf88ebd50ff39c2/utils/build_install.raspi4ubuntu.bash#L13-L14)。 ```c @@ -74,7 +93,7 @@ Raspberry Pi 4で本ドライバを使用する際には`rtmouse.c`の以下の ### パルスカウンタについて -パルスカウンタは値の読み取りにI2Cを使用しています。仕様上は400kHzまでbaudrateを上げることができます(※1)。 +パルスカウンタは値の読み取りにI2Cを使用しています。仕様上は400kHzまでbaudrateを上げることができます(※1)。 I2Cのbaudrateを上げると通信に失敗する場合がある([issues#13](https://github.com/rt-net/RaspberryPiMouse/issues/13))ので、基本的にはI2Cのbaudrateはデフォルト値(※2)から変更して62.5kHzに固定してください。 According to @@ -86,7 +105,7 @@ Add a following new line in `/boot/firmware/config.txt` to change the i2c_baudra ``` dtparam=i2c_baudrate=62500 ``` -※1 Raspberry Pi 4 Model B(Ubuntu 18.04とUbuntu 20.04)を搭載して400kHzで通信できることを確認しています。 +※1 Raspberry Pi 4 Model B(Ubuntu Server `18.04` / `20.04` / `22.04` / `24.04`)を搭載して400kHzで通信できることを確認しています。 ※2 現在設定されているI2Cのbaudrateは以下のコマンドを実行することで確認できます。 ``` $ printf "%d\n" 0x$(xxd -ps /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency) From 80b76a7441caaf527a88f9e31233adef1d65f7cd Mon Sep 17 00:00:00 2001 From: kurasawa Date: Fri, 6 Sep 2024 16:31:43 +0900 Subject: [PATCH 22/22] =?UTF-8?q?Raspberry=20Pi=20OS=E3=81=A7dtoverlay?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0=E3=81=8C=E4=B8=8D=E8=A6=81=E3=81=AA?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E3=81=AB=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37f32a3..bb78fd5 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Run the installation script ([`./utils/build_install.bash`](https://github.com/r ```sh arm_64bit=0 # "64-bit"版では不要です -dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 +dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 # カーネル5.16未満の場合は不要です dtparam=i2c_baudrate=62500 ```