16
16
#include <linux/of.h>
17
17
#include <linux/of_device.h>
18
18
#include <linux/spi/spi.h>
19
+ #include <linux/i2c.h>
19
20
20
21
/* RX-6110 Register definitions */
21
22
#define RX6110_REG_SEC 0x10
@@ -310,6 +311,27 @@ static const struct rtc_class_ops rx6110_rtc_ops = {
310
311
.set_time = rx6110_set_time ,
311
312
};
312
313
314
+ static int rx6110_probe (struct rx6110_data * rx6110 , struct device * dev )
315
+ {
316
+ int err ;
317
+
318
+ rx6110 -> rtc = devm_rtc_device_register (dev ,
319
+ RX6110_DRIVER_NAME ,
320
+ & rx6110_rtc_ops , THIS_MODULE );
321
+
322
+ if (IS_ERR (rx6110 -> rtc ))
323
+ return PTR_ERR (rx6110 -> rtc );
324
+
325
+ err = rx6110_init (rx6110 );
326
+ if (err )
327
+ return err ;
328
+
329
+ rx6110 -> rtc -> max_user_freq = 1 ;
330
+
331
+ return 0 ;
332
+ }
333
+
334
+ #ifdef CONFIG_SPI_MASTER
313
335
static struct regmap_config regmap_spi_config = {
314
336
.reg_bits = 8 ,
315
337
.val_bits = 8 ,
@@ -318,13 +340,12 @@ static struct regmap_config regmap_spi_config = {
318
340
};
319
341
320
342
/**
321
- * rx6110_probe - initialize rtc driver
343
+ * rx6110_spi_probe - initialize rtc driver
322
344
* @spi: pointer to spi device
323
345
*/
324
- static int rx6110_probe (struct spi_device * spi )
346
+ static int rx6110_spi_probe (struct spi_device * spi )
325
347
{
326
348
struct rx6110_data * rx6110 ;
327
- int err ;
328
349
329
350
if ((spi -> bits_per_word && spi -> bits_per_word != 8 ) ||
330
351
(spi -> max_speed_hz > 2000000 ) ||
@@ -346,44 +367,142 @@ static int rx6110_probe(struct spi_device *spi)
346
367
347
368
spi_set_drvdata (spi , rx6110 );
348
369
349
- rx6110 -> rtc = devm_rtc_device_register (& spi -> dev ,
350
- RX6110_DRIVER_NAME ,
351
- & rx6110_rtc_ops , THIS_MODULE );
352
-
353
- if (IS_ERR (rx6110 -> rtc ))
354
- return PTR_ERR (rx6110 -> rtc );
355
-
356
- err = rx6110_init (rx6110 );
357
- if (err )
358
- return err ;
359
-
360
- rx6110 -> rtc -> max_user_freq = 1 ;
361
-
362
- return 0 ;
370
+ return rx6110_probe (rx6110 , & spi -> dev );
363
371
}
364
372
365
- static const struct spi_device_id rx6110_id [] = {
373
+ static const struct spi_device_id rx6110_spi_id [] = {
366
374
{ "rx6110" , 0 },
367
375
{ }
368
376
};
369
- MODULE_DEVICE_TABLE (spi , rx6110_id );
377
+ MODULE_DEVICE_TABLE (spi , rx6110_spi_id );
370
378
371
379
static const struct of_device_id rx6110_spi_of_match [] = {
372
380
{ .compatible = "epson,rx6110" },
373
381
{ },
374
382
};
375
383
MODULE_DEVICE_TABLE (of , rx6110_spi_of_match );
376
384
377
- static struct spi_driver rx6110_driver = {
385
+ static struct spi_driver rx6110_spi_driver = {
378
386
.driver = {
379
387
.name = RX6110_DRIVER_NAME ,
380
388
.of_match_table = of_match_ptr (rx6110_spi_of_match ),
381
389
},
382
- .probe = rx6110_probe ,
383
- .id_table = rx6110_id ,
390
+ .probe = rx6110_spi_probe ,
391
+ .id_table = rx6110_spi_id ,
392
+ };
393
+
394
+ static int rx6110_spi_register (void )
395
+ {
396
+ return spi_register_driver (& rx6110_spi_driver );
397
+ }
398
+
399
+ static void rx6110_spi_unregister (void )
400
+ {
401
+ spi_unregister_driver (& rx6110_spi_driver );
402
+ }
403
+ #else
404
+ static int rx6110_spi_register (void )
405
+ {
406
+ return 0 ;
407
+ }
408
+
409
+ static void rx6110_spi_unregister (void )
410
+ {
411
+ }
412
+ #endif /* CONFIG_SPI_MASTER */
413
+
414
+ #ifdef CONFIG_I2C
415
+ static struct regmap_config regmap_i2c_config = {
416
+ .reg_bits = 8 ,
417
+ .val_bits = 8 ,
418
+ .max_register = RX6110_REG_IRQ ,
419
+ .read_flag_mask = 0x80 ,
384
420
};
385
421
386
- module_spi_driver (rx6110_driver );
422
+ static int rx6110_i2c_probe (struct i2c_client * client ,
423
+ const struct i2c_device_id * id )
424
+ {
425
+ struct i2c_adapter * adapter = to_i2c_adapter (client -> dev .parent );
426
+ struct rx6110_data * rx6110 ;
427
+
428
+ if (!i2c_check_functionality (adapter , I2C_FUNC_SMBUS_BYTE_DATA
429
+ | I2C_FUNC_SMBUS_I2C_BLOCK )) {
430
+ dev_err (& adapter -> dev ,
431
+ "doesn't support required functionality\n" );
432
+ return - EIO ;
433
+ }
434
+
435
+ rx6110 = devm_kzalloc (& client -> dev , sizeof (* rx6110 ), GFP_KERNEL );
436
+ if (!rx6110 )
437
+ return - ENOMEM ;
438
+
439
+ rx6110 -> regmap = devm_regmap_init_i2c (client , & regmap_i2c_config );
440
+ if (IS_ERR (rx6110 -> regmap )) {
441
+ dev_err (& client -> dev , "regmap init failed for rtc rx6110\n" );
442
+ return PTR_ERR (rx6110 -> regmap );
443
+ }
444
+
445
+ i2c_set_clientdata (client , rx6110 );
446
+
447
+ return rx6110_probe (rx6110 , & client -> dev );
448
+ }
449
+
450
+ static const struct i2c_device_id rx6110_i2c_id [] = {
451
+ { "rx6110" , 0 },
452
+ { }
453
+ };
454
+ MODULE_DEVICE_TABLE (i2c , rx6110_i2c_id );
455
+
456
+ static struct i2c_driver rx6110_i2c_driver = {
457
+ .driver = {
458
+ .name = RX6110_DRIVER_NAME ,
459
+ },
460
+ .probe = rx6110_i2c_probe ,
461
+ .id_table = rx6110_i2c_id ,
462
+ };
463
+
464
+ static int rx6110_i2c_register (void )
465
+ {
466
+ return i2c_add_driver (& rx6110_i2c_driver );
467
+ }
468
+
469
+ static void rx6110_i2c_unregister (void )
470
+ {
471
+ i2c_del_driver (& rx6110_i2c_driver );
472
+ }
473
+ #else
474
+ static int rx6110_i2c_register (void )
475
+ {
476
+ return 0 ;
477
+ }
478
+
479
+ static void rx6110_i2c_unregister (void )
480
+ {
481
+ }
482
+ #endif /* CONFIG_I2C */
483
+
484
+ static int __init rx6110_module_init (void )
485
+ {
486
+ int ret ;
487
+
488
+ ret = rx6110_spi_register ();
489
+ if (ret )
490
+ return ret ;
491
+
492
+ ret = rx6110_i2c_register ();
493
+ if (ret )
494
+ rx6110_spi_unregister ();
495
+
496
+ return ret ;
497
+ }
498
+ module_init (rx6110_module_init );
499
+
500
+ static void __exit rx6110_module_exit (void )
501
+ {
502
+ rx6110_spi_unregister ();
503
+ rx6110_i2c_unregister ();
504
+ }
505
+ module_exit (rx6110_module_exit );
387
506
388
507
MODULE_AUTHOR (
"Val Krutov <[email protected] >" );
389
508
MODULE_DESCRIPTION ("RX-6110 SA RTC driver" );
0 commit comments