Skip to content

Commit afa819c

Browse files
cmhealexandrebelloni
authored andcommitted
rtc: rx6110: add i2c support
The RX6110 also supports I2C, so this patch adds support for it to the driver. This also renames the SPI specific functions and variables to include `_spi_` in their names. Signed-off-by: Claudius Heine <[email protected]> Signed-off-by: Henning Schild <[email protected]> Signed-off-by: Alexandre Belloni <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7e6066c commit afa819c

File tree

2 files changed

+153
-32
lines changed

2 files changed

+153
-32
lines changed

drivers/rtc/Kconfig

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,6 @@ config RTC_DRV_RX4581
817817
This driver can also be built as a module. If so the module
818818
will be called rtc-rx4581.
819819

820-
config RTC_DRV_RX6110
821-
tristate "Epson RX-6110"
822-
select REGMAP_SPI
823-
help
824-
If you say yes here you will get support for the Epson RX-6110.
825-
826-
This driver can also be built as a module. If so the module
827-
will be called rtc-rx6110.
828-
829820
config RTC_DRV_RS5C348
830821
tristate "Ricoh RS5C348A/B"
831822
help
@@ -936,6 +927,17 @@ config RTC_DRV_RV3029_HWMON
936927
Say Y here if you want to expose temperature sensor data on
937928
rtc-rv3029.
938929

930+
config RTC_DRV_RX6110
931+
tristate "Epson RX-6110"
932+
depends on RTC_I2C_AND_SPI
933+
select REGMAP_SPI if SPI_MASTER
934+
select REGMAP_I2C if I2C
935+
help
936+
If you say yes here you will get support for the Epson RX-6110.
937+
938+
This driver can also be built as a module. If so the module
939+
will be called rtc-rx6110.
940+
939941
comment "Platform RTC drivers"
940942

941943
# this 'CMOS' RTC driver is arch dependent because it requires

drivers/rtc/rtc-rx6110.c

Lines changed: 142 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/of.h>
1717
#include <linux/of_device.h>
1818
#include <linux/spi/spi.h>
19+
#include <linux/i2c.h>
1920

2021
/* RX-6110 Register definitions */
2122
#define RX6110_REG_SEC 0x10
@@ -310,6 +311,27 @@ static const struct rtc_class_ops rx6110_rtc_ops = {
310311
.set_time = rx6110_set_time,
311312
};
312313

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
313335
static struct regmap_config regmap_spi_config = {
314336
.reg_bits = 8,
315337
.val_bits = 8,
@@ -318,13 +340,12 @@ static struct regmap_config regmap_spi_config = {
318340
};
319341

320342
/**
321-
* rx6110_probe - initialize rtc driver
343+
* rx6110_spi_probe - initialize rtc driver
322344
* @spi: pointer to spi device
323345
*/
324-
static int rx6110_probe(struct spi_device *spi)
346+
static int rx6110_spi_probe(struct spi_device *spi)
325347
{
326348
struct rx6110_data *rx6110;
327-
int err;
328349

329350
if ((spi->bits_per_word && spi->bits_per_word != 8) ||
330351
(spi->max_speed_hz > 2000000) ||
@@ -346,44 +367,142 @@ static int rx6110_probe(struct spi_device *spi)
346367

347368
spi_set_drvdata(spi, rx6110);
348369

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);
363371
}
364372

365-
static const struct spi_device_id rx6110_id[] = {
373+
static const struct spi_device_id rx6110_spi_id[] = {
366374
{ "rx6110", 0 },
367375
{ }
368376
};
369-
MODULE_DEVICE_TABLE(spi, rx6110_id);
377+
MODULE_DEVICE_TABLE(spi, rx6110_spi_id);
370378

371379
static const struct of_device_id rx6110_spi_of_match[] = {
372380
{ .compatible = "epson,rx6110" },
373381
{ },
374382
};
375383
MODULE_DEVICE_TABLE(of, rx6110_spi_of_match);
376384

377-
static struct spi_driver rx6110_driver = {
385+
static struct spi_driver rx6110_spi_driver = {
378386
.driver = {
379387
.name = RX6110_DRIVER_NAME,
380388
.of_match_table = of_match_ptr(rx6110_spi_of_match),
381389
},
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,
384420
};
385421

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);
387506

388507
MODULE_AUTHOR("Val Krutov <[email protected]>");
389508
MODULE_DESCRIPTION("RX-6110 SA RTC driver");

0 commit comments

Comments
 (0)