@@ -78,21 +78,15 @@ static struct class *class_dev[ID_DEV_SIZE] = {
78
78
[ID_DEV_MOTORRAWR ] = NULL , [ID_DEV_MOTORRAWL ] = NULL ,
79
79
[ID_DEV_MOTOREN ] = NULL , [ID_DEV_MOTOR ] = NULL };
80
80
81
- volatile void __iomem * pwm_base ;
82
81
static volatile void __iomem * clk_base ;
83
- volatile uint32_t * gpio_base ;
84
82
static volatile int cdev_index = 0 ;
83
+
84
+ // used in rtmouse_dev_fops.c
85
+ volatile void __iomem * pwm_base ;
86
+ volatile uint32_t * gpio_base ;
85
87
struct mutex lock ;
86
88
87
89
/* --- Function Declarations --- */
88
- #if LINUX_VERSION_CODE < KERNEL_VERSION (5 , 18 , 0 )
89
- static int mcp3204_remove (struct spi_device * spi );
90
- #else
91
- static void mcp3204_remove (struct spi_device * spi );
92
- #endif
93
-
94
- static int mcp3204_probe (struct spi_device * spi );
95
-
96
90
#if LINUX_VERSION_CODE < KERNEL_VERSION (6 , 2 , 0 )
97
91
static int rtcnt_i2c_probe (struct i2c_client * client ,
98
92
const struct i2c_device_id * id );
@@ -107,37 +101,11 @@ static void rtcnt_i2c_remove(struct i2c_client *client);
107
101
#endif
108
102
109
103
/* --- Static variables --- */
110
- /* SPI device ID */
111
- static struct spi_device_id mcp3204_id [] = {
112
- {"mcp3204" , 0 },
113
- {},
114
- };
115
-
116
- /* SPI Info */
117
- struct spi_board_info mcp3204_info = {
118
- .modalias = "mcp3204" ,
119
- .max_speed_hz = 100000 ,
120
- .bus_num = 0 ,
121
- .chip_select = 0 ,
122
- .mode = SPI_MODE_3 ,
123
- };
124
-
104
+ // used in rtmouse_dev_fops.c
125
105
#if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
126
106
struct device * mcp320x_dev ;
127
107
#endif
128
108
129
- /* SPI Dirver Info */
130
- static struct spi_driver mcp3204_driver = {
131
- .driver =
132
- {
133
- .name = DEVNAME_SENSOR ,
134
- .owner = THIS_MODULE ,
135
- },
136
- .id_table = mcp3204_id ,
137
- .probe = mcp3204_probe ,
138
- .remove = mcp3204_remove ,
139
- };
140
-
141
109
static struct i2c_client * i2c_client_r = NULL ;
142
110
static struct i2c_client * i2c_client_l = NULL ;
143
111
@@ -161,7 +129,6 @@ static struct i2c_driver i2c_counter_driver = {
161
129
};
162
130
163
131
/* -- Device Addition -- */
164
- MODULE_DEVICE_TABLE (spi , mcp3204_id );
165
132
MODULE_DEVICE_TABLE (i2c , i2c_counter_id );
166
133
167
134
/*
@@ -365,172 +332,6 @@ static int register_dev(int id_dev)
365
332
return 0 ;
366
333
}
367
334
368
- /* mcp3204_remove - remove function lined with spi_dirver */
369
- #if LINUX_VERSION_CODE < KERNEL_VERSION (5 , 18 , 0 )
370
- static int mcp3204_remove (struct spi_device * spi )
371
- {
372
- struct mcp3204_drvdata * data ;
373
- /* get drvdata */
374
- data = (struct mcp3204_drvdata * )spi_get_drvdata (spi );
375
- /* free kernel memory */
376
- kfree (data );
377
- printk (KERN_INFO "%s: mcp3204 removed\n" , DRIVER_NAME );
378
- return 0 ;
379
- }
380
- #else
381
- static void mcp3204_remove (struct spi_device * spi )
382
- {
383
- struct mcp3204_drvdata * data ;
384
- /* get drvdata */
385
- data = (struct mcp3204_drvdata * )spi_get_drvdata (spi );
386
- /* free kernel memory */
387
- kfree (data );
388
- printk (KERN_INFO "%s: mcp3204 removed\n" , DRIVER_NAME );
389
- }
390
- #endif
391
-
392
- /* mcp3204_probe - probe function lined with spi_dirver */
393
- static int mcp3204_probe (struct spi_device * spi )
394
- {
395
- struct mcp3204_drvdata * data ;
396
-
397
- spi -> max_speed_hz = mcp3204_info .max_speed_hz ;
398
- spi -> mode = mcp3204_info .mode ;
399
- spi -> bits_per_word = 8 ;
400
-
401
- if (spi_setup (spi )) {
402
- printk (KERN_ERR "%s:spi_setup failed!\n" , __func__ );
403
- return - ENODEV ;
404
- }
405
-
406
- /* alloc kernel memory */
407
- data = kzalloc (sizeof (struct mcp3204_drvdata ), GFP_KERNEL );
408
- if (data == NULL ) {
409
- printk (KERN_ERR "%s:kzalloc() failed!\n" , __func__ );
410
- return - ENODEV ;
411
- }
412
-
413
- data -> spi = spi ;
414
-
415
- mutex_init (& data -> lock );
416
-
417
- // memset(data->tx, 0, MCP320X_PACKET_SIZE);
418
- // memset(data->rx, 0, MCP320X_PACKET_SIZE);
419
-
420
- data -> xfer .tx_buf = data -> tx ;
421
- data -> xfer .rx_buf = data -> rx ;
422
- data -> xfer .bits_per_word = 8 ;
423
- data -> xfer .len = MCP320X_PACKET_SIZE ;
424
- data -> xfer .cs_change = 0 ;
425
- data -> xfer .speed_hz = 100000 ;
426
-
427
- spi_message_init_with_transfers (& data -> msg , & data -> xfer , 1 );
428
-
429
- /* set drvdata */
430
- spi_set_drvdata (spi , data );
431
-
432
- printk (KERN_INFO "%s: mcp3204 probed" , DRIVER_NAME );
433
-
434
- return 0 ;
435
- }
436
-
437
- /*
438
- * spi_remove_device - remove SPI device
439
- * called by mcp3204_init and mcp3204_exit
440
- */
441
- static void spi_remove_device (struct spi_master * master , unsigned int cs )
442
- {
443
- struct device * dev ;
444
- char str [128 ];
445
-
446
- snprintf (str , sizeof (str ), "%s.%u" , dev_name (& master -> dev ), cs );
447
-
448
- dev = bus_find_device_by_name (& spi_bus_type , NULL , str );
449
- // ここを参考にspi_deviceを取得するプログラムを作成する
450
- if (dev ) {
451
- device_del (dev );
452
- }
453
- }
454
-
455
- #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
456
- /* spiをサーチする関数 */
457
- static int __callback_find_mcp3204 (struct device * dev , void * data )
458
- {
459
- printk (KERN_INFO " device_name: %s\n" , dev -> driver -> name );
460
- if (mcp320x_dev == NULL && strcmp (dev -> driver -> name , "mcp320x" ) == 0 ) {
461
- mcp320x_dev = dev ;
462
- mcp3204_probe (to_spi_device (dev ));
463
- }
464
- return 0 ;
465
- }
466
- #endif
467
-
468
- /*
469
- * mcp3204_init - initialize MCP3204
470
- * called by 'dev_init_module'
471
- */
472
- static int mcp3204_init (void )
473
- {
474
-
475
- #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
476
- bus_for_each_dev (& spi_bus_type , NULL , NULL , __callback_find_mcp3204 );
477
- #else
478
- struct spi_master * master ;
479
- struct spi_device * spi_device ;
480
-
481
- spi_register_driver (& mcp3204_driver );
482
-
483
- mcp3204_info .bus_num = SPI_BUS_NUM ;
484
- mcp3204_info .chip_select = SPI_CHIP_SELECT ;
485
-
486
- master = spi_busnum_to_master (mcp3204_info .bus_num );
487
-
488
- if (!master ) {
489
- printk (KERN_ERR "%s: spi_busnum_to_master returned NULL\n" ,
490
- __func__ );
491
- spi_unregister_driver (& mcp3204_driver );
492
- return - ENODEV ;
493
- }
494
-
495
- spi_remove_device (master , mcp3204_info .chip_select );
496
-
497
- spi_device = spi_new_device (master , & mcp3204_info );
498
- if (!spi_device ) {
499
- printk (KERN_ERR "%s: spi_new_device returned NULL\n" , __func__ );
500
- spi_unregister_driver (& mcp3204_driver );
501
- return - ENODEV ;
502
- }
503
- #endif
504
-
505
- return 0 ;
506
- }
507
-
508
- /*
509
- * mcp3204_exit - cleanup MCP3204
510
- * called by dev_cleanup_module()
511
- */
512
- static void mcp3204_exit (void )
513
- {
514
-
515
- #if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 16 , 0 )
516
- printk (KERN_INFO " mcp3204_exit\n" );
517
- if (mcp320x_dev ) {
518
- mcp3204_remove (to_spi_device (mcp320x_dev ));
519
- }
520
- #else
521
- struct spi_master * master ;
522
- master = spi_busnum_to_master (mcp3204_info .bus_num );
523
-
524
- if (master ) {
525
- spi_remove_device (master , mcp3204_info .chip_select );
526
- } else {
527
- printk (KERN_ERR "mcp3204 remove error\n" );
528
- }
529
-
530
- spi_unregister_driver (& mcp3204_driver );
531
- #endif
532
- }
533
-
534
335
static int rtcntr_i2c_create_cdev (struct rtcnt_device_info * dev_info )
535
336
{
536
337
int minor ;
0 commit comments