9
0
Fork 0
Commit Graph

21 Commits

Author SHA1 Message Date
Trent Piepho 24fcf5fcee rtc: ds1307: Add support for configuring external clock pin
The DS1307 has a square wave output pin, which can be used to output a
clock signal from the DS1307.  Additionally, the DS1308 supports
configuring this pin as an input from an external clock source to
which it should sync itself.

Add support with OF device tree properties to configure these
settings.  Supported features are using the clock pin as an output, an
input, the rate of the pin, and if it should be enabled on battery
backup power.

The driver does not check that the selected features are supported by
the clock chip being used.  It is the designer's responsibility to
create a valid device tree node; the bootloader does not attempt to be
a device tree validator.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-05-30 07:12:19 +02:00
Trent Piepho a2f8644d71 rtc: ds1307: Add ds1308 to driver's ID list
As far as the driver is concerned, it's the same as a 1338.  It's too
bad the i2c drivers can't make use of OF compatible properties with a
list of compatible devices.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-05-23 08:29:46 +02:00
Andrey Smirnov 750f53c399 ds1307: Configure ds1341 for lowest power mode
Empirical observations show that configuring INTCN=1, ECLK=0, EGFIL=0,
DOSF=1 on DS1341 put the chip in the mode where it draws the least
amount fo current.

Add code to configure DS1341 in such a way in case Barebox is the last
code that runs on the processor before being shut down.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-05 08:42:54 +02:00
Andrey Smirnov 6587b56678 ds1307: Fix a bug in probe()
Add missing "~" to bit clearing operation.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-05 08:42:24 +02:00
Andrey Smirnov 8aeda692f6 rtc: abracon: Check obtained time for validity
Check obtianed time for validity before returning it to the caller
the same way other RTC drivers do.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-04-05 08:40:51 +02:00
Sascha Hauer 3bd69ad077 driver: replace dev_request_mem_region with dev_request_mem_resource
dev_request_mem_region doesn't work properly one some SoCs on which
PTR_ERR() values clash with valid return values from dev_request_mem_region.
Replace them with dev_request_mem_resource where possible.

This patch has been generated with the following semantic patch:

// <smpl>
@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
-if (IS_ERR(io)) {
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores)) {
...
-	return PTR_ERR(io);
-}
+	return PTR_ERR(iores);
+}
+io = IOMEM(iores->start);
...+>
}

@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
-if (IS_ERR(io)) {
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores))
-	return PTR_ERR(io);
-}
+	return PTR_ERR(iores);
+io = IOMEM(iores->start);
...+>
}

@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
-if (IS_ERR(io)) {
-	ret = PTR_ERR(io);
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores)) {
+	ret = PTR_ERR(iores);
...
}
+io = IOMEM(iores->start);
...+>
}

@@
expression d;
expression n;
expression io;
identifier func;
@@
func(...) {
+struct resource *iores;
<+...
-io = dev_request_mem_region(d, n);
+iores = dev_request_mem_resource(d, n);
+if (IS_ERR(iores))
+	return PTR_ERR(iores);
+io = IOMEM(iores->start);
...+>
}

@@
identifier func;
@@
func(...) {
<+...
struct resource *iores;
-struct resource *iores;
...+>
}
// </smpl>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-03-07 08:57:56 +01:00
Sascha Hauer 8ee5479a28 driver: Fix return check of dev_request_mem_region
dev_request_mem_region returns an ERR_PTR, fix places which check for a
NULL pointer instead. This patch has been generated with this semantic
patch, written by me and improved by Andrey Smirnov:

// <smpl>
@@
expression e;
expression e1;
@@
e = dev_request_mem_region(...);
...
-if (!e)
-	return e1;
+if (IS_ERR(e))
+	return PTR_ERR(e);

@ rule1 @
expression e;
@@
e = dev_request_mem_region(...);

@@
expression rule1.e;
identifier ret, label;
constant errno;
@@
if (!e) {
	...
(
-	ret = -errno;
+	ret = PTR_ERR(e);
	...
	goto label;
|
-	return -errno;
+	return PTR_ERR(e);
)
}

@depends on rule1@
expression rule1.e;
@@
-	if (e == NULL)
+	if (IS_ERR(e))
{
...
}
// </smpl>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
2016-02-23 08:14:16 +01:00
Andrey Smirnov 645320b94a rtc-lib: Check tm_wday for validity in rtc_valid_tm()
RTC drivers rely on rtc_valid_tm() in order to make sure that no bogus
values from uninitialized HW registers get passed to the uppper layers.

A somewhat contrived way to reproduce this problem with DS1307 RTC
would be to do the following:

> i2c_write -b <bus> -a <addr> -r 3 0x00
> hwclock

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-07 08:46:10 +01:00
Andrey Smirnov 304cdde167 rtc: ds1307: Fix a memory leak
Several failure paths would result in control being transfered to
'exit' label, so instead of just returning error codes in those cases
we also need to free the memory allocated for 'ds1307'

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-07 08:46:09 +01:00
Andrey Smirnov 540140849c rtc: ds1307: Add code to support ds1337/1341
Port DS1337 specific bits from corresponding Linux driver and add
small changes needed for DS1341.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-07 08:46:09 +01:00
Sascha Hauer 06a524a168 rtc: Add Abracon driver
This patch adds support for the Abracon ab-rtcmc-32.768khz-eoz9-s3
RTC. The driver can probably support other Abracon RTCs aswell, but this
hasn't been verified.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-07 08:46:09 +01:00
Sascha Hauer e259115243 rtc: Fill in weekdays before setting time
Some rtcs store the weekday. Make sure it's filled in correctly before
passinf the time to the driver. This is easily done by converting it to
seconds-since-epoch and back to struct rtc_time.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-07 08:46:09 +01:00
Sascha Hauer db80eaf6d2 rtc: Check time for validity before passing it to the rtc driver
So that rtc drivers do not get invalid times.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2016-01-07 08:46:09 +01:00
Antony Pavlov 377d261708 of: use 'const void *' for struct of_device_id.data
Since 2011 barebox' of_device_id struct uses unsigned long type for data field:

    struct of_device_id {
            char *compatible;
            unsigned long data;
    };

Almost always struct of_device_id.data field are used as pointer
and need 'unsigned long' casting.

E.g. see 'git grep -A 4 of_device_id drivers/' output:

    drivers/ata/sata-imx.c:static __maybe_unused struct of_device_id imx_sata_dt_ids[] = {
    drivers/ata/sata-imx.c- {
    drivers/ata/sata-imx.c-         .compatible = "fsl,imx6q-ahci",
    drivers/ata/sata-imx.c-         .data = (unsigned long)&data_imx6,
    drivers/ata/sata-imx.c- }, {

Here is of_device_id struct in linux kernel v4.0:

    struct of_device_id {
            char name[32];
            char type[32];
            char compatible[128];
            const void *data;
    };

Changing of_device_id.data type to 'const void *data' will increase
barebox' linux kernel compatibility and decrease number of 'unsigned
long' casts.

Part of the patch was done using the 'coccinelle' tool with the
following semantic patch:

    @rule1@
    identifier dev;
    identifier type;
    identifier func;
    @@
    func(...) {
    <...
    - dev_get_drvdata(dev, (unsigned long *)&type)
    + dev_get_drvdata(dev, (const void **)&type)
    ...>
    }
    @rule2@
    identifier dev;
    identifier type;
    identifier func;
    identifier data;
    @@
    func(...) {
    <...
    - dev_get_drvdata(dev, (unsigned long *)&type->data)
    + dev_get_drvdata(dev, (const void **)&type->data)
    ...>
    }

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2015-04-30 08:12:57 +02:00
Lucas Stach cdb0d02b87 rtc: select GREGORIAN_CALENDER
Fixes:
drivers/rtc/rtc-lib.c:109: undefined reference to `mktime'

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-11-27 17:12:39 +01:00
Antony Pavlov 365d26e462 rtc: add jz4740 driver
Add support for the RTC unit on Ingenic JZ4740, JZ475x and JZ477x SoCs.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-08-02 06:45:43 +02:00
Antony Pavlov 287e085fa9 rtc-lib: import rtc_time_to_tm() from linux-3.15
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-08-02 06:45:43 +02:00
Antony Pavlov 686df208b3 rtc: import ds1307 driver from linux-3.15
Current ds1307 rtc driver supports only ds1307 and ds1338 chips;
it has no nvram support at the moment.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-08-02 06:45:43 +02:00
Antony Pavlov ed98f1522d Add a simple rtc framework
This patch adds a simple rtc framework
for reading and setting board's RTC time.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
2014-07-31 07:30:51 +02:00
Sascha Hauer 762019f198 remove unused drivers 2007-09-21 12:43:14 +02:00
Sascha Hauer e47684d5f5 svn_rev_505 2007-07-05 18:01:59 +02:00