Skip to content

Commit 1600285

Browse files
committed
media: vidtv: add date to the current event
The current event is using an undefined date. Instead, it should be the timestamp when the EIT table was generated. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent bfa4aae commit 1600285

1 file changed

Lines changed: 41 additions & 3 deletions

File tree

drivers/media/test-drivers/vidtv/vidtv_psi.c

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111

1212
#define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__
1313

14+
#include <linux/bcd.h>
1415
#include <linux/crc32.h>
1516
#include <linux/kernel.h>
17+
#include <linux/ktime.h>
1618
#include <linux/printk.h>
1719
#include <linux/ratelimit.h>
1820
#include <linux/slab.h>
1921
#include <linux/string.h>
2022
#include <linux/string.h>
23+
#include <linux/time.h>
2124
#include <linux/types.h>
2225

2326
#include "vidtv_common.h"
@@ -1953,16 +1956,51 @@ u32 vidtv_psi_eit_write_into(struct vidtv_psi_eit_write_args args)
19531956
struct vidtv_psi_table_eit_event
19541957
*vidtv_psi_eit_event_init(struct vidtv_psi_table_eit_event *head, u16 event_id)
19551958
{
1956-
const u8 DURATION_ONE_HOUR[] = {1, 0, 0};
1959+
const u8 DURATION[] = {0x23, 0x59, 0x59}; /* BCD encoded */
19571960
struct vidtv_psi_table_eit_event *e;
1961+
struct timespec64 ts;
1962+
struct tm time;
1963+
int mjd, l;
1964+
__be16 mjd_be;
19581965

19591966
e = kzalloc(sizeof(*e), GFP_KERNEL);
19601967
if (!e)
19611968
return NULL;
19621969

19631970
e->event_id = cpu_to_be16(event_id);
1964-
memset(e->start_time, 0xff, sizeof(e->start_time)); //todo: 0xff means 'unspecified'
1965-
memcpy(e->duration, DURATION_ONE_HOUR, sizeof(e->duration)); //todo, default to this for now
1971+
1972+
ts = ktime_to_timespec64(ktime_get_real());
1973+
time64_to_tm(ts.tv_sec, 0, &time);
1974+
1975+
/* Convert date to Modified Julian Date - per EN 300 468 Annex C */
1976+
if (time.tm_mon < 2)
1977+
l = 1;
1978+
else
1979+
l = 0;
1980+
1981+
mjd = 14956 + time.tm_mday;
1982+
mjd += (time.tm_year - l) * 36525 / 100;
1983+
mjd += (time.tm_mon + 2 + l * 12) * 306001 / 10000;
1984+
mjd_be = cpu_to_be16(mjd);
1985+
1986+
/*
1987+
* Store MJD and hour/min/sec to the event.
1988+
*
1989+
* Let's make the event to start on a full hour
1990+
*/
1991+
memcpy(e->start_time, &mjd_be, sizeof(mjd_be));
1992+
e->start_time[2] = bin2bcd(time.tm_hour);
1993+
e->start_time[3] = 0;
1994+
e->start_time[4] = 0;
1995+
1996+
/*
1997+
* TODO: for now, the event will last for a day. Should be
1998+
* enough for testing purposes, but if one runs the driver
1999+
* for more than that, the current event will become invalid.
2000+
* So, we need a better code here in order to change the start
2001+
* time once the event expires.
2002+
*/
2003+
memcpy(e->duration, DURATION, sizeof(e->duration));
19662004

19672005
e->bitfield = cpu_to_be16(RUNNING << 13);
19682006

0 commit comments

Comments
 (0)