[RFC 2/5] add rtc support

Sascha Hauer s.hauer at pengutronix.de
Thu Jul 10 14:40:30 PDT 2014


On Thu, Jul 10, 2014 at 12:33:16PM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> ---
>  drivers/Kconfig       |  1 +
>  drivers/Makefile      |  1 +
>  drivers/rtc/Kconfig   | 16 +++++++++++++
>  drivers/rtc/Makefile  |  6 +++++
>  drivers/rtc/class.c   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/rtc/rtc-lib.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/rtc.h   | 46 ++++++++++++++++++++++++++++++++++++
>  include/rtc.h         |  2 ++
>  8 files changed, 198 insertions(+)
> 
> diff --git a/drivers/Kconfig b/drivers/Kconfig
> index 12a9d8c..d38032c 100644
> --- a/drivers/Kconfig
> +++ b/drivers/Kconfig
> @@ -28,5 +28,6 @@ source "drivers/bus/Kconfig"
>  source "drivers/regulator/Kconfig"
>  source "drivers/reset/Kconfig"
>  source "drivers/pci/Kconfig"
> +source "drivers/rtc/Kconfig"
>  
>  endmenu
> diff --git a/drivers/Makefile b/drivers/Makefile
> index 1990e86..4591f9a 100644
> --- a/drivers/Makefile
> +++ b/drivers/Makefile
> @@ -27,3 +27,4 @@ obj-y += bus/
>  obj-$(CONFIG_REGULATOR) += regulator/
>  obj-$(CONFIG_RESET_CONTROLLER) += reset/
>  obj-$(CONFIG_PCI) += pci/
> +obj-y += rtc/
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> new file mode 100644
> index 0000000..f148266
> --- /dev/null
> +++ b/drivers/rtc/Kconfig
> @@ -0,0 +1,16 @@
> +#
> +# RTC class/drivers configuration
> +#
> +
> +config RTC_LIB
> +	bool
> +
> +menuconfig RTC_CLASS
> +        bool "Real Time Clock"
> +        default n
> +        depends on !S390 && !UML
> +        select RTC_LIB
> +        help
> +          Generic RTC class support. If you say yes here, you will
> +          be allowed to plug one or more RTCs to your system. You will
> +          probably want to enable one or more of the interfaces below.
> diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
> new file mode 100644
> index 0000000..7d1b5bc
> --- /dev/null
> +++ b/drivers/rtc/Makefile
> @@ -0,0 +1,6 @@
> +#
> +# Makefile for RTC class/drivers.
> +#
> +
> +obj-$(CONFIG_RTC_LIB)           += rtc-lib.o
> +obj-$(CONFIG_RTC_CLASS)         += class.o
> diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
> new file mode 100644
> index 0000000..b808f3d
> --- /dev/null
> +++ b/drivers/rtc/class.c
> @@ -0,0 +1,62 @@
> +#include <linux/err.h>
> +#include <rtc.h>
> +#include <linux/rtc.h>
> +
> +LIST_HEAD(rtc_list);
> +EXPORT_SYMBOL(rtc_list);
> +
> +struct rtc_device *rtc_lookup(const char *name)
> +{
> +	struct rtc_device *r;
> +
> +	if (!name)
> +		return ERR_PTR(-ENODEV);
> +
> +	list_for_each_entry(r, &rtc_list, list) {
> +		if (!strcmp(dev_name(&r->class_dev), name))
> +			return r;
> +	}
> +
> +	return ERR_PTR(-ENODEV);
> +}
> +EXPORT_SYMBOL(rtc_lookup);
> +
> +int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
> +{
> +	return rtc->ops->read_time(rtc, tm);
> +}
> +EXPORT_SYMBOL(rtc_read_time);
> +
> +int rtc_register(struct rtc_device *rtcdev)
> +{
> +	struct device_d *dev = &rtcdev->class_dev;
> +
> +	dev->id = DEVICE_ID_DYNAMIC;
> +	strcpy(dev->name, "rtc");
> +	if (rtcdev->dev)
> +		dev->parent = rtcdev->dev;
> +	platform_device_register(dev);

Please check the return value.

> +
> +	list_add_tail(&rtcdev->list, &rtc_list);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(rtc_register);
> +
> +#if 0
> +int rtc_unregister(struct rtc_device *cdev)
> +{
> +	struct device_d *dev = &cdev->class_dev;
> +	int status;
> +
> +	list_del(&cdev->list);
> +	if (list_empty(&rtc_list))
> +		initialized = CONSOLE_UNINITIALIZED;
> +
> +	status = unregister_device(dev);
> +	if (!status)
> +		memset(cdev, 0, sizeof(*cdev));
> +	return status;
> +}
> +EXPORT_SYMBOL(rtc_unregister);
> +#endif

CONSOLE_UNINITIALIZED? This probably wouldn't compile if it wasn't
ifdeffed. I think we can just remove this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list