Re: [rtc-linux] Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-07-16 Thread Keerthy


On Friday 14 July 2017 02:13 AM, Alexandre Belloni wrote:
> Hi,
> 
> On 05/05/2017 at 00:38:27 +0200, Alexandre Belloni wrote:
>> Hi,
>>
>> On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
>>> On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
 From: Russ Dill 

 Many RTCs provide scratch registers that are maintained so long as the RTC
 has power. Provide a generic method to access these registers.

>>>
>>> A gentle ping on this
>>>
>>
>> Yeah, I apologize for the delay (I know you already sent this 6-8 months
>> ago).
>> I'm not satisfied with the interface (and its name). I gave a lot of
>> thought into it and I'm currently reworking part of the subsystem to
>> create a similar feature. I'm planning to have it in 4.13.
>>
> 
> So, the nvmem stuff is now in 4.13. If you can still wait a bit, I'll
> implement it myself and test on am335x.

Sure.

> 
> 


Re: [rtc-linux] Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-07-16 Thread Keerthy


On Friday 14 July 2017 02:13 AM, Alexandre Belloni wrote:
> Hi,
> 
> On 05/05/2017 at 00:38:27 +0200, Alexandre Belloni wrote:
>> Hi,
>>
>> On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
>>> On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
 From: Russ Dill 

 Many RTCs provide scratch registers that are maintained so long as the RTC
 has power. Provide a generic method to access these registers.

>>>
>>> A gentle ping on this
>>>
>>
>> Yeah, I apologize for the delay (I know you already sent this 6-8 months
>> ago).
>> I'm not satisfied with the interface (and its name). I gave a lot of
>> thought into it and I'm currently reworking part of the subsystem to
>> create a similar feature. I'm planning to have it in 4.13.
>>
> 
> So, the nvmem stuff is now in 4.13. If you can still wait a bit, I'll
> implement it myself and test on am335x.

Sure.

> 
> 


Re: [rtc-linux] Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-07-13 Thread Alexandre Belloni
Hi,

On 05/05/2017 at 00:38:27 +0200, Alexandre Belloni wrote:
> Hi,
> 
> On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
> > On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
> > > From: Russ Dill 
> > > 
> > > Many RTCs provide scratch registers that are maintained so long as the RTC
> > > has power. Provide a generic method to access these registers.
> > > 
> > 
> > A gentle ping on this
> > 
> 
> Yeah, I apologize for the delay (I know you already sent this 6-8 months
> ago).
> I'm not satisfied with the interface (and its name). I gave a lot of
> thought into it and I'm currently reworking part of the subsystem to
> create a similar feature. I'm planning to have it in 4.13.
> 

So, the nvmem stuff is now in 4.13. If you can still wait a bit, I'll
implement it myself and test on am335x.


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


Re: [rtc-linux] Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-07-13 Thread Alexandre Belloni
Hi,

On 05/05/2017 at 00:38:27 +0200, Alexandre Belloni wrote:
> Hi,
> 
> On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
> > On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
> > > From: Russ Dill 
> > > 
> > > Many RTCs provide scratch registers that are maintained so long as the RTC
> > > has power. Provide a generic method to access these registers.
> > > 
> > 
> > A gentle ping on this
> > 
> 
> Yeah, I apologize for the delay (I know you already sent this 6-8 months
> ago).
> I'm not satisfied with the interface (and its name). I gave a lot of
> thought into it and I'm currently reworking part of the subsystem to
> create a similar feature. I'm planning to have it in 4.13.
> 

So, the nvmem stuff is now in 4.13. If you can still wait a bit, I'll
implement it myself and test on am335x.


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-05-04 Thread Keerthy


On Friday 05 May 2017 04:08 AM, Alexandre Belloni wrote:
> Hi,
> 
> On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
>> On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
>>> From: Russ Dill 
>>>
>>> Many RTCs provide scratch registers that are maintained so long as the RTC
>>> has power. Provide a generic method to access these registers.
>>>
>>
>> A gentle ping on this
>>
> 
> Yeah, I apologize for the delay (I know you already sent this 6-8 months
> ago).
> I'm not satisfied with the interface (and its name). I gave a lot of
> thought into it and I'm currently reworking part of the subsystem to
> create a similar feature. I'm planning to have it in 4.13.

Okay then i will wait for that. Thanks for the response.

> 
>>> Signed-off-by: Russ Dill 
>>> Signed-off-by: Keerthy 
>>> ---
>>>  drivers/rtc/interface.c | 50 
>>> +
>>>  drivers/rtc/rtc-omap.c  | 35 ++
>>>  include/linux/rtc.h |  7 +++
>>>  3 files changed, 92 insertions(+)
>>>
>>> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
>>> index fc0fa75..facde06 100644
>>> --- a/drivers/rtc/interface.c
>>> +++ b/drivers/rtc/interface.c
>>> @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long 
>>> offset)
>>> mutex_unlock(>ops_lock);
>>> return ret;
>>>  }
>>> +
>>> +/* rtc_read_scratch - Read from RTC scratch register
>>> + * @ rtc: rtc device to be used
>>> + * @ index: index of scratch register
>>> + * @ value: returned value read
>>> + *
>>> + * Kernel interface read from an RTC scratch register
>>> + */
>>> +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 
>>> *value)
>>> +{
>>> +   int err;
>>> +
>>> +   mutex_lock(>ops_lock);
>>> +   if (!rtc->ops)
>>> +   err = -ENODEV;
>>> +   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
>>> +   err = -EINVAL;
>>> +   else
>>> +   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
>>> +   mutex_unlock(>ops_lock);
>>> +   return err;
>>> +}
>>> +EXPORT_SYMBOL_GPL(rtc_read_scratch);
>>> +
>>> +/* rtc_write_scratch - Write to RTC scratch register
>>> + * @ rtc: rtc device to be used
>>> + * @ index: index of scratch register
>>> + * @ value: value to write
>>> + *
>>> + * Kernel interface write to an RTC scratch register
>>> + */
>>> +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 
>>> value)
>>> +{
>>> +   int err;
>>> +
>>> +   mutex_lock(>ops_lock);
>>> +
>>> +   if (!rtc->ops)
>>> +   err = -ENODEV;
>>> +   else if (index >= rtc->ops->scratch_size ||
>>> +!rtc->ops->write_scratch)
>>> +   err = -EINVAL;
>>> +   else
>>> +   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
>>> +
>>> +   mutex_unlock(>ops_lock);
>>> +
>>> +   return err;
>>> +}
>>> +EXPORT_SYMBOL_GPL(rtc_write_scratch);
>>> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
>>> index 13f7cd1..c90d93e 100644
>>> --- a/drivers/rtc/rtc-omap.c
>>> +++ b/drivers/rtc/rtc-omap.c
>>> @@ -70,6 +70,10 @@
>>>  #define OMAP_RTC_COMP_MSB_REG  0x50
>>>  #define OMAP_RTC_OSC_REG   0x54
>>>  
>>> +#define OMAP_RTC_SCRATCH0_REG  0x60
>>> +#define OMAP_RTC_SCRATCH1_REG  0x64
>>> +#define OMAP_RTC_SCRATCH2_REG  0x68
>>> +
>>>  #define OMAP_RTC_KICK0_REG 0x6c
>>>  #define OMAP_RTC_KICK1_REG 0x70
>>>  
>>> @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, 
>>> struct rtc_wkalrm *alm)
>>>  
>>>  static struct omap_rtc *omap_rtc_power_off_rtc;
>>>  
>>> +static const u32 omap_rtc_scratch_regs[] = {
>>> +   OMAP_RTC_SCRATCH0_REG,
>>> +   OMAP_RTC_SCRATCH1_REG,
>>> +   OMAP_RTC_SCRATCH2_REG,
>>> +};
>>> +
>>> +static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
>>> +u32 *value)
>>> +{
>>> +   *value = readl(omap_rtc_power_off_rtc->base +
>>> +  omap_rtc_scratch_regs[index]);
>>> +
>>> +   return 0;
>>> +}
>>> +
>>> +static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
>>> + u32 value)
>>> +{
>>> +   struct omap_rtc *rtc = dev_get_drvdata(dev);
>>> +
>>> +   rtc->type->unlock(rtc);
>>> +   writel(value, omap_rtc_power_off_rtc->base +
>>> +  omap_rtc_scratch_regs[index]);
>>> +   rtc->type->lock(rtc);
>>> +
>>> +   return 0;
>>> +}
>>> +
>>>  /*
>>>   * omap_rtc_poweroff: RTC-controlled power off
>>>   *
>>> @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
>>> .read_alarm = omap_rtc_read_alarm,
>>> .set_alarm  = omap_rtc_set_alarm,
>>> .alarm_irq_enable = omap_rtc_alarm_irq_enable,
>>> +   .read_scratch   = omap_rtc_read_scratch,
>>> +   .write_scratch  = omap_rtc_write_scratch,
>>> +   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
>>>  };
>>>  
>>>  static const struct omap_rtc_device_type 

Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-05-04 Thread Keerthy


On Friday 05 May 2017 04:08 AM, Alexandre Belloni wrote:
> Hi,
> 
> On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
>> On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
>>> From: Russ Dill 
>>>
>>> Many RTCs provide scratch registers that are maintained so long as the RTC
>>> has power. Provide a generic method to access these registers.
>>>
>>
>> A gentle ping on this
>>
> 
> Yeah, I apologize for the delay (I know you already sent this 6-8 months
> ago).
> I'm not satisfied with the interface (and its name). I gave a lot of
> thought into it and I'm currently reworking part of the subsystem to
> create a similar feature. I'm planning to have it in 4.13.

Okay then i will wait for that. Thanks for the response.

> 
>>> Signed-off-by: Russ Dill 
>>> Signed-off-by: Keerthy 
>>> ---
>>>  drivers/rtc/interface.c | 50 
>>> +
>>>  drivers/rtc/rtc-omap.c  | 35 ++
>>>  include/linux/rtc.h |  7 +++
>>>  3 files changed, 92 insertions(+)
>>>
>>> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
>>> index fc0fa75..facde06 100644
>>> --- a/drivers/rtc/interface.c
>>> +++ b/drivers/rtc/interface.c
>>> @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long 
>>> offset)
>>> mutex_unlock(>ops_lock);
>>> return ret;
>>>  }
>>> +
>>> +/* rtc_read_scratch - Read from RTC scratch register
>>> + * @ rtc: rtc device to be used
>>> + * @ index: index of scratch register
>>> + * @ value: returned value read
>>> + *
>>> + * Kernel interface read from an RTC scratch register
>>> + */
>>> +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 
>>> *value)
>>> +{
>>> +   int err;
>>> +
>>> +   mutex_lock(>ops_lock);
>>> +   if (!rtc->ops)
>>> +   err = -ENODEV;
>>> +   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
>>> +   err = -EINVAL;
>>> +   else
>>> +   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
>>> +   mutex_unlock(>ops_lock);
>>> +   return err;
>>> +}
>>> +EXPORT_SYMBOL_GPL(rtc_read_scratch);
>>> +
>>> +/* rtc_write_scratch - Write to RTC scratch register
>>> + * @ rtc: rtc device to be used
>>> + * @ index: index of scratch register
>>> + * @ value: value to write
>>> + *
>>> + * Kernel interface write to an RTC scratch register
>>> + */
>>> +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 
>>> value)
>>> +{
>>> +   int err;
>>> +
>>> +   mutex_lock(>ops_lock);
>>> +
>>> +   if (!rtc->ops)
>>> +   err = -ENODEV;
>>> +   else if (index >= rtc->ops->scratch_size ||
>>> +!rtc->ops->write_scratch)
>>> +   err = -EINVAL;
>>> +   else
>>> +   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
>>> +
>>> +   mutex_unlock(>ops_lock);
>>> +
>>> +   return err;
>>> +}
>>> +EXPORT_SYMBOL_GPL(rtc_write_scratch);
>>> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
>>> index 13f7cd1..c90d93e 100644
>>> --- a/drivers/rtc/rtc-omap.c
>>> +++ b/drivers/rtc/rtc-omap.c
>>> @@ -70,6 +70,10 @@
>>>  #define OMAP_RTC_COMP_MSB_REG  0x50
>>>  #define OMAP_RTC_OSC_REG   0x54
>>>  
>>> +#define OMAP_RTC_SCRATCH0_REG  0x60
>>> +#define OMAP_RTC_SCRATCH1_REG  0x64
>>> +#define OMAP_RTC_SCRATCH2_REG  0x68
>>> +
>>>  #define OMAP_RTC_KICK0_REG 0x6c
>>>  #define OMAP_RTC_KICK1_REG 0x70
>>>  
>>> @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, 
>>> struct rtc_wkalrm *alm)
>>>  
>>>  static struct omap_rtc *omap_rtc_power_off_rtc;
>>>  
>>> +static const u32 omap_rtc_scratch_regs[] = {
>>> +   OMAP_RTC_SCRATCH0_REG,
>>> +   OMAP_RTC_SCRATCH1_REG,
>>> +   OMAP_RTC_SCRATCH2_REG,
>>> +};
>>> +
>>> +static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
>>> +u32 *value)
>>> +{
>>> +   *value = readl(omap_rtc_power_off_rtc->base +
>>> +  omap_rtc_scratch_regs[index]);
>>> +
>>> +   return 0;
>>> +}
>>> +
>>> +static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
>>> + u32 value)
>>> +{
>>> +   struct omap_rtc *rtc = dev_get_drvdata(dev);
>>> +
>>> +   rtc->type->unlock(rtc);
>>> +   writel(value, omap_rtc_power_off_rtc->base +
>>> +  omap_rtc_scratch_regs[index]);
>>> +   rtc->type->lock(rtc);
>>> +
>>> +   return 0;
>>> +}
>>> +
>>>  /*
>>>   * omap_rtc_poweroff: RTC-controlled power off
>>>   *
>>> @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
>>> .read_alarm = omap_rtc_read_alarm,
>>> .set_alarm  = omap_rtc_set_alarm,
>>> .alarm_irq_enable = omap_rtc_alarm_irq_enable,
>>> +   .read_scratch   = omap_rtc_read_scratch,
>>> +   .write_scratch  = omap_rtc_write_scratch,
>>> +   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
>>>  };
>>>  
>>>  static const struct omap_rtc_device_type omap_rtc_default_type = {
>>> diff --git 

Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-05-04 Thread Alexandre Belloni
Hi,

On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
> On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
> > From: Russ Dill 
> > 
> > Many RTCs provide scratch registers that are maintained so long as the RTC
> > has power. Provide a generic method to access these registers.
> > 
> 
> A gentle ping on this
> 

Yeah, I apologize for the delay (I know you already sent this 6-8 months
ago).
I'm not satisfied with the interface (and its name). I gave a lot of
thought into it and I'm currently reworking part of the subsystem to
create a similar feature. I'm planning to have it in 4.13.

> > Signed-off-by: Russ Dill 
> > Signed-off-by: Keerthy 
> > ---
> >  drivers/rtc/interface.c | 50 
> > +
> >  drivers/rtc/rtc-omap.c  | 35 ++
> >  include/linux/rtc.h |  7 +++
> >  3 files changed, 92 insertions(+)
> > 
> > diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> > index fc0fa75..facde06 100644
> > --- a/drivers/rtc/interface.c
> > +++ b/drivers/rtc/interface.c
> > @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long 
> > offset)
> > mutex_unlock(>ops_lock);
> > return ret;
> >  }
> > +
> > +/* rtc_read_scratch - Read from RTC scratch register
> > + * @ rtc: rtc device to be used
> > + * @ index: index of scratch register
> > + * @ value: returned value read
> > + *
> > + * Kernel interface read from an RTC scratch register
> > + */
> > +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 
> > *value)
> > +{
> > +   int err;
> > +
> > +   mutex_lock(>ops_lock);
> > +   if (!rtc->ops)
> > +   err = -ENODEV;
> > +   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
> > +   err = -EINVAL;
> > +   else
> > +   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
> > +   mutex_unlock(>ops_lock);
> > +   return err;
> > +}
> > +EXPORT_SYMBOL_GPL(rtc_read_scratch);
> > +
> > +/* rtc_write_scratch - Write to RTC scratch register
> > + * @ rtc: rtc device to be used
> > + * @ index: index of scratch register
> > + * @ value: value to write
> > + *
> > + * Kernel interface write to an RTC scratch register
> > + */
> > +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 
> > value)
> > +{
> > +   int err;
> > +
> > +   mutex_lock(>ops_lock);
> > +
> > +   if (!rtc->ops)
> > +   err = -ENODEV;
> > +   else if (index >= rtc->ops->scratch_size ||
> > +!rtc->ops->write_scratch)
> > +   err = -EINVAL;
> > +   else
> > +   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
> > +
> > +   mutex_unlock(>ops_lock);
> > +
> > +   return err;
> > +}
> > +EXPORT_SYMBOL_GPL(rtc_write_scratch);
> > diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> > index 13f7cd1..c90d93e 100644
> > --- a/drivers/rtc/rtc-omap.c
> > +++ b/drivers/rtc/rtc-omap.c
> > @@ -70,6 +70,10 @@
> >  #define OMAP_RTC_COMP_MSB_REG  0x50
> >  #define OMAP_RTC_OSC_REG   0x54
> >  
> > +#define OMAP_RTC_SCRATCH0_REG  0x60
> > +#define OMAP_RTC_SCRATCH1_REG  0x64
> > +#define OMAP_RTC_SCRATCH2_REG  0x68
> > +
> >  #define OMAP_RTC_KICK0_REG 0x6c
> >  #define OMAP_RTC_KICK1_REG 0x70
> >  
> > @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, 
> > struct rtc_wkalrm *alm)
> >  
> >  static struct omap_rtc *omap_rtc_power_off_rtc;
> >  
> > +static const u32 omap_rtc_scratch_regs[] = {
> > +   OMAP_RTC_SCRATCH0_REG,
> > +   OMAP_RTC_SCRATCH1_REG,
> > +   OMAP_RTC_SCRATCH2_REG,
> > +};
> > +
> > +static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
> > +u32 *value)
> > +{
> > +   *value = readl(omap_rtc_power_off_rtc->base +
> > +  omap_rtc_scratch_regs[index]);
> > +
> > +   return 0;
> > +}
> > +
> > +static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
> > + u32 value)
> > +{
> > +   struct omap_rtc *rtc = dev_get_drvdata(dev);
> > +
> > +   rtc->type->unlock(rtc);
> > +   writel(value, omap_rtc_power_off_rtc->base +
> > +  omap_rtc_scratch_regs[index]);
> > +   rtc->type->lock(rtc);
> > +
> > +   return 0;
> > +}
> > +
> >  /*
> >   * omap_rtc_poweroff: RTC-controlled power off
> >   *
> > @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
> > .read_alarm = omap_rtc_read_alarm,
> > .set_alarm  = omap_rtc_set_alarm,
> > .alarm_irq_enable = omap_rtc_alarm_irq_enable,
> > +   .read_scratch   = omap_rtc_read_scratch,
> > +   .write_scratch  = omap_rtc_write_scratch,
> > +   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
> >  };
> >  
> >  static const struct omap_rtc_device_type omap_rtc_default_type = {
> > diff --git a/include/linux/rtc.h b/include/linux/rtc.h
> > index b693ada..da5e003 100644
> > --- 

Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-05-04 Thread Alexandre Belloni
Hi,

On 03/05/2017 at 11:39:34 +0530, Keerthy wrote:
> On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
> > From: Russ Dill 
> > 
> > Many RTCs provide scratch registers that are maintained so long as the RTC
> > has power. Provide a generic method to access these registers.
> > 
> 
> A gentle ping on this
> 

Yeah, I apologize for the delay (I know you already sent this 6-8 months
ago).
I'm not satisfied with the interface (and its name). I gave a lot of
thought into it and I'm currently reworking part of the subsystem to
create a similar feature. I'm planning to have it in 4.13.

> > Signed-off-by: Russ Dill 
> > Signed-off-by: Keerthy 
> > ---
> >  drivers/rtc/interface.c | 50 
> > +
> >  drivers/rtc/rtc-omap.c  | 35 ++
> >  include/linux/rtc.h |  7 +++
> >  3 files changed, 92 insertions(+)
> > 
> > diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> > index fc0fa75..facde06 100644
> > --- a/drivers/rtc/interface.c
> > +++ b/drivers/rtc/interface.c
> > @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long 
> > offset)
> > mutex_unlock(>ops_lock);
> > return ret;
> >  }
> > +
> > +/* rtc_read_scratch - Read from RTC scratch register
> > + * @ rtc: rtc device to be used
> > + * @ index: index of scratch register
> > + * @ value: returned value read
> > + *
> > + * Kernel interface read from an RTC scratch register
> > + */
> > +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 
> > *value)
> > +{
> > +   int err;
> > +
> > +   mutex_lock(>ops_lock);
> > +   if (!rtc->ops)
> > +   err = -ENODEV;
> > +   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
> > +   err = -EINVAL;
> > +   else
> > +   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
> > +   mutex_unlock(>ops_lock);
> > +   return err;
> > +}
> > +EXPORT_SYMBOL_GPL(rtc_read_scratch);
> > +
> > +/* rtc_write_scratch - Write to RTC scratch register
> > + * @ rtc: rtc device to be used
> > + * @ index: index of scratch register
> > + * @ value: value to write
> > + *
> > + * Kernel interface write to an RTC scratch register
> > + */
> > +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 
> > value)
> > +{
> > +   int err;
> > +
> > +   mutex_lock(>ops_lock);
> > +
> > +   if (!rtc->ops)
> > +   err = -ENODEV;
> > +   else if (index >= rtc->ops->scratch_size ||
> > +!rtc->ops->write_scratch)
> > +   err = -EINVAL;
> > +   else
> > +   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
> > +
> > +   mutex_unlock(>ops_lock);
> > +
> > +   return err;
> > +}
> > +EXPORT_SYMBOL_GPL(rtc_write_scratch);
> > diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> > index 13f7cd1..c90d93e 100644
> > --- a/drivers/rtc/rtc-omap.c
> > +++ b/drivers/rtc/rtc-omap.c
> > @@ -70,6 +70,10 @@
> >  #define OMAP_RTC_COMP_MSB_REG  0x50
> >  #define OMAP_RTC_OSC_REG   0x54
> >  
> > +#define OMAP_RTC_SCRATCH0_REG  0x60
> > +#define OMAP_RTC_SCRATCH1_REG  0x64
> > +#define OMAP_RTC_SCRATCH2_REG  0x68
> > +
> >  #define OMAP_RTC_KICK0_REG 0x6c
> >  #define OMAP_RTC_KICK1_REG 0x70
> >  
> > @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, 
> > struct rtc_wkalrm *alm)
> >  
> >  static struct omap_rtc *omap_rtc_power_off_rtc;
> >  
> > +static const u32 omap_rtc_scratch_regs[] = {
> > +   OMAP_RTC_SCRATCH0_REG,
> > +   OMAP_RTC_SCRATCH1_REG,
> > +   OMAP_RTC_SCRATCH2_REG,
> > +};
> > +
> > +static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
> > +u32 *value)
> > +{
> > +   *value = readl(omap_rtc_power_off_rtc->base +
> > +  omap_rtc_scratch_regs[index]);
> > +
> > +   return 0;
> > +}
> > +
> > +static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
> > + u32 value)
> > +{
> > +   struct omap_rtc *rtc = dev_get_drvdata(dev);
> > +
> > +   rtc->type->unlock(rtc);
> > +   writel(value, omap_rtc_power_off_rtc->base +
> > +  omap_rtc_scratch_regs[index]);
> > +   rtc->type->lock(rtc);
> > +
> > +   return 0;
> > +}
> > +
> >  /*
> >   * omap_rtc_poweroff: RTC-controlled power off
> >   *
> > @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
> > .read_alarm = omap_rtc_read_alarm,
> > .set_alarm  = omap_rtc_set_alarm,
> > .alarm_irq_enable = omap_rtc_alarm_irq_enable,
> > +   .read_scratch   = omap_rtc_read_scratch,
> > +   .write_scratch  = omap_rtc_write_scratch,
> > +   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
> >  };
> >  
> >  static const struct omap_rtc_device_type omap_rtc_default_type = {
> > diff --git a/include/linux/rtc.h b/include/linux/rtc.h
> > index b693ada..da5e003 100644
> > --- a/include/linux/rtc.h
> > +++ b/include/linux/rtc.h
> > @@ -91,6 

Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-05-03 Thread Keerthy


On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
> From: Russ Dill 
> 
> Many RTCs provide scratch registers that are maintained so long as the RTC
> has power. Provide a generic method to access these registers.
> 

A gentle ping on this

> Signed-off-by: Russ Dill 
> Signed-off-by: Keerthy 
> ---
>  drivers/rtc/interface.c | 50 
> +
>  drivers/rtc/rtc-omap.c  | 35 ++
>  include/linux/rtc.h |  7 +++
>  3 files changed, 92 insertions(+)
> 
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index fc0fa75..facde06 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
>   mutex_unlock(>ops_lock);
>   return ret;
>  }
> +
> +/* rtc_read_scratch - Read from RTC scratch register
> + * @ rtc: rtc device to be used
> + * @ index: index of scratch register
> + * @ value: returned value read
> + *
> + * Kernel interface read from an RTC scratch register
> + */
> +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value)
> +{
> + int err;
> +
> + mutex_lock(>ops_lock);
> + if (!rtc->ops)
> + err = -ENODEV;
> + else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
> + err = -EINVAL;
> + else
> + err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
> + mutex_unlock(>ops_lock);
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(rtc_read_scratch);
> +
> +/* rtc_write_scratch - Write to RTC scratch register
> + * @ rtc: rtc device to be used
> + * @ index: index of scratch register
> + * @ value: value to write
> + *
> + * Kernel interface write to an RTC scratch register
> + */
> +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value)
> +{
> + int err;
> +
> + mutex_lock(>ops_lock);
> +
> + if (!rtc->ops)
> + err = -ENODEV;
> + else if (index >= rtc->ops->scratch_size ||
> +  !rtc->ops->write_scratch)
> + err = -EINVAL;
> + else
> + err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
> +
> + mutex_unlock(>ops_lock);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(rtc_write_scratch);
> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> index 13f7cd1..c90d93e 100644
> --- a/drivers/rtc/rtc-omap.c
> +++ b/drivers/rtc/rtc-omap.c
> @@ -70,6 +70,10 @@
>  #define OMAP_RTC_COMP_MSB_REG0x50
>  #define OMAP_RTC_OSC_REG 0x54
>  
> +#define OMAP_RTC_SCRATCH0_REG0x60
> +#define OMAP_RTC_SCRATCH1_REG0x64
> +#define OMAP_RTC_SCRATCH2_REG0x68
> +
>  #define OMAP_RTC_KICK0_REG   0x6c
>  #define OMAP_RTC_KICK1_REG   0x70
>  
> @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct 
> rtc_wkalrm *alm)
>  
>  static struct omap_rtc *omap_rtc_power_off_rtc;
>  
> +static const u32 omap_rtc_scratch_regs[] = {
> + OMAP_RTC_SCRATCH0_REG,
> + OMAP_RTC_SCRATCH1_REG,
> + OMAP_RTC_SCRATCH2_REG,
> +};
> +
> +static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
> +  u32 *value)
> +{
> + *value = readl(omap_rtc_power_off_rtc->base +
> +omap_rtc_scratch_regs[index]);
> +
> + return 0;
> +}
> +
> +static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
> +   u32 value)
> +{
> + struct omap_rtc *rtc = dev_get_drvdata(dev);
> +
> + rtc->type->unlock(rtc);
> + writel(value, omap_rtc_power_off_rtc->base +
> +omap_rtc_scratch_regs[index]);
> + rtc->type->lock(rtc);
> +
> + return 0;
> +}
> +
>  /*
>   * omap_rtc_poweroff: RTC-controlled power off
>   *
> @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
>   .read_alarm = omap_rtc_read_alarm,
>   .set_alarm  = omap_rtc_set_alarm,
>   .alarm_irq_enable = omap_rtc_alarm_irq_enable,
> + .read_scratch   = omap_rtc_read_scratch,
> + .write_scratch  = omap_rtc_write_scratch,
> + .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
>  };
>  
>  static const struct omap_rtc_device_type omap_rtc_default_type = {
> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
> index b693ada..da5e003 100644
> --- a/include/linux/rtc.h
> +++ b/include/linux/rtc.h
> @@ -91,6 +91,10 @@ struct rtc_class_ops {
>   int (*alarm_irq_enable)(struct device *, unsigned int enabled);
>   int (*read_offset)(struct device *, long *offset);
>   int (*set_offset)(struct device *, long offset);
> + int (*read_scratch)(struct device *, unsigned int, u32*);
> + int (*write_scratch)(struct device *, unsigned int, u32);
> +
> + unsigned int scratch_size;
>  };
>  
>  #define RTC_DEVICE_NAME_SIZE 20
> @@ -214,6 +218,9 @@ int 

Re: [PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-05-03 Thread Keerthy


On Tuesday 18 April 2017 10:50 AM, Keerthy wrote:
> From: Russ Dill 
> 
> Many RTCs provide scratch registers that are maintained so long as the RTC
> has power. Provide a generic method to access these registers.
> 

A gentle ping on this

> Signed-off-by: Russ Dill 
> Signed-off-by: Keerthy 
> ---
>  drivers/rtc/interface.c | 50 
> +
>  drivers/rtc/rtc-omap.c  | 35 ++
>  include/linux/rtc.h |  7 +++
>  3 files changed, 92 insertions(+)
> 
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index fc0fa75..facde06 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
>   mutex_unlock(>ops_lock);
>   return ret;
>  }
> +
> +/* rtc_read_scratch - Read from RTC scratch register
> + * @ rtc: rtc device to be used
> + * @ index: index of scratch register
> + * @ value: returned value read
> + *
> + * Kernel interface read from an RTC scratch register
> + */
> +int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value)
> +{
> + int err;
> +
> + mutex_lock(>ops_lock);
> + if (!rtc->ops)
> + err = -ENODEV;
> + else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
> + err = -EINVAL;
> + else
> + err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
> + mutex_unlock(>ops_lock);
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(rtc_read_scratch);
> +
> +/* rtc_write_scratch - Write to RTC scratch register
> + * @ rtc: rtc device to be used
> + * @ index: index of scratch register
> + * @ value: value to write
> + *
> + * Kernel interface write to an RTC scratch register
> + */
> +int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value)
> +{
> + int err;
> +
> + mutex_lock(>ops_lock);
> +
> + if (!rtc->ops)
> + err = -ENODEV;
> + else if (index >= rtc->ops->scratch_size ||
> +  !rtc->ops->write_scratch)
> + err = -EINVAL;
> + else
> + err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
> +
> + mutex_unlock(>ops_lock);
> +
> + return err;
> +}
> +EXPORT_SYMBOL_GPL(rtc_write_scratch);
> diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
> index 13f7cd1..c90d93e 100644
> --- a/drivers/rtc/rtc-omap.c
> +++ b/drivers/rtc/rtc-omap.c
> @@ -70,6 +70,10 @@
>  #define OMAP_RTC_COMP_MSB_REG0x50
>  #define OMAP_RTC_OSC_REG 0x54
>  
> +#define OMAP_RTC_SCRATCH0_REG0x60
> +#define OMAP_RTC_SCRATCH1_REG0x64
> +#define OMAP_RTC_SCRATCH2_REG0x68
> +
>  #define OMAP_RTC_KICK0_REG   0x6c
>  #define OMAP_RTC_KICK1_REG   0x70
>  
> @@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct 
> rtc_wkalrm *alm)
>  
>  static struct omap_rtc *omap_rtc_power_off_rtc;
>  
> +static const u32 omap_rtc_scratch_regs[] = {
> + OMAP_RTC_SCRATCH0_REG,
> + OMAP_RTC_SCRATCH1_REG,
> + OMAP_RTC_SCRATCH2_REG,
> +};
> +
> +static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
> +  u32 *value)
> +{
> + *value = readl(omap_rtc_power_off_rtc->base +
> +omap_rtc_scratch_regs[index]);
> +
> + return 0;
> +}
> +
> +static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
> +   u32 value)
> +{
> + struct omap_rtc *rtc = dev_get_drvdata(dev);
> +
> + rtc->type->unlock(rtc);
> + writel(value, omap_rtc_power_off_rtc->base +
> +omap_rtc_scratch_regs[index]);
> + rtc->type->lock(rtc);
> +
> + return 0;
> +}
> +
>  /*
>   * omap_rtc_poweroff: RTC-controlled power off
>   *
> @@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
>   .read_alarm = omap_rtc_read_alarm,
>   .set_alarm  = omap_rtc_set_alarm,
>   .alarm_irq_enable = omap_rtc_alarm_irq_enable,
> + .read_scratch   = omap_rtc_read_scratch,
> + .write_scratch  = omap_rtc_write_scratch,
> + .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
>  };
>  
>  static const struct omap_rtc_device_type omap_rtc_default_type = {
> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
> index b693ada..da5e003 100644
> --- a/include/linux/rtc.h
> +++ b/include/linux/rtc.h
> @@ -91,6 +91,10 @@ struct rtc_class_ops {
>   int (*alarm_irq_enable)(struct device *, unsigned int enabled);
>   int (*read_offset)(struct device *, long *offset);
>   int (*set_offset)(struct device *, long offset);
> + int (*read_scratch)(struct device *, unsigned int, u32*);
> + int (*write_scratch)(struct device *, unsigned int, u32);
> +
> + unsigned int scratch_size;
>  };
>  
>  #define RTC_DEVICE_NAME_SIZE 20
> @@ -214,6 +218,9 @@ int rtc_timer_start(struct rtc_device *rtc, struct 
> rtc_timer 

[PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-04-17 Thread Keerthy
From: Russ Dill 

Many RTCs provide scratch registers that are maintained so long as the RTC
has power. Provide a generic method to access these registers.

Signed-off-by: Russ Dill 
Signed-off-by: Keerthy 
---
 drivers/rtc/interface.c | 50 +
 drivers/rtc/rtc-omap.c  | 35 ++
 include/linux/rtc.h |  7 +++
 3 files changed, 92 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index fc0fa75..facde06 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
mutex_unlock(>ops_lock);
return ret;
 }
+
+/* rtc_read_scratch - Read from RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: returned value read
+ *
+ * Kernel interface read from an RTC scratch register
+ */
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
+   mutex_unlock(>ops_lock);
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_read_scratch);
+
+/* rtc_write_scratch - Write to RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: value to write
+ *
+ * Kernel interface write to an RTC scratch register
+ */
+int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size ||
+!rtc->ops->write_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
+
+   mutex_unlock(>ops_lock);
+
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_write_scratch);
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 13f7cd1..c90d93e 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -70,6 +70,10 @@
 #define OMAP_RTC_COMP_MSB_REG  0x50
 #define OMAP_RTC_OSC_REG   0x54
 
+#define OMAP_RTC_SCRATCH0_REG  0x60
+#define OMAP_RTC_SCRATCH1_REG  0x64
+#define OMAP_RTC_SCRATCH2_REG  0x68
+
 #define OMAP_RTC_KICK0_REG 0x6c
 #define OMAP_RTC_KICK1_REG 0x70
 
@@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct 
rtc_wkalrm *alm)
 
 static struct omap_rtc *omap_rtc_power_off_rtc;
 
+static const u32 omap_rtc_scratch_regs[] = {
+   OMAP_RTC_SCRATCH0_REG,
+   OMAP_RTC_SCRATCH1_REG,
+   OMAP_RTC_SCRATCH2_REG,
+};
+
+static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
+u32 *value)
+{
+   *value = readl(omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+
+   return 0;
+}
+
+static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
+ u32 value)
+{
+   struct omap_rtc *rtc = dev_get_drvdata(dev);
+
+   rtc->type->unlock(rtc);
+   writel(value, omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+   rtc->type->lock(rtc);
+
+   return 0;
+}
+
 /*
  * omap_rtc_poweroff: RTC-controlled power off
  *
@@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
.read_alarm = omap_rtc_read_alarm,
.set_alarm  = omap_rtc_set_alarm,
.alarm_irq_enable = omap_rtc_alarm_irq_enable,
+   .read_scratch   = omap_rtc_read_scratch,
+   .write_scratch  = omap_rtc_write_scratch,
+   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
 };
 
 static const struct omap_rtc_device_type omap_rtc_default_type = {
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index b693ada..da5e003 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -91,6 +91,10 @@ struct rtc_class_ops {
int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset);
+   int (*read_scratch)(struct device *, unsigned int, u32*);
+   int (*write_scratch)(struct device *, unsigned int, u32);
+
+   unsigned int scratch_size;
 };
 
 #define RTC_DEVICE_NAME_SIZE 20
@@ -214,6 +218,9 @@ int rtc_timer_start(struct rtc_device *rtc, struct 
rtc_timer *timer,
 int rtc_set_offset(struct rtc_device *rtc, long offset);
 void rtc_timer_do_work(struct work_struct *work);
 
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value);
+int rtc_write_scratch(struct rtc_device *rtc, 

[PATCH] RTC: Add functionality to read/write rtc scratch registers

2017-04-17 Thread Keerthy
From: Russ Dill 

Many RTCs provide scratch registers that are maintained so long as the RTC
has power. Provide a generic method to access these registers.

Signed-off-by: Russ Dill 
Signed-off-by: Keerthy 
---
 drivers/rtc/interface.c | 50 +
 drivers/rtc/rtc-omap.c  | 35 ++
 include/linux/rtc.h |  7 +++
 3 files changed, 92 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index fc0fa75..facde06 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -1016,3 +1016,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
mutex_unlock(>ops_lock);
return ret;
 }
+
+/* rtc_read_scratch - Read from RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: returned value read
+ *
+ * Kernel interface read from an RTC scratch register
+ */
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
+   mutex_unlock(>ops_lock);
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_read_scratch);
+
+/* rtc_write_scratch - Write to RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: value to write
+ *
+ * Kernel interface write to an RTC scratch register
+ */
+int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size ||
+!rtc->ops->write_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
+
+   mutex_unlock(>ops_lock);
+
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_write_scratch);
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 13f7cd1..c90d93e 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -70,6 +70,10 @@
 #define OMAP_RTC_COMP_MSB_REG  0x50
 #define OMAP_RTC_OSC_REG   0x54
 
+#define OMAP_RTC_SCRATCH0_REG  0x60
+#define OMAP_RTC_SCRATCH1_REG  0x64
+#define OMAP_RTC_SCRATCH2_REG  0x68
+
 #define OMAP_RTC_KICK0_REG 0x6c
 #define OMAP_RTC_KICK1_REG 0x70
 
@@ -414,6 +418,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct 
rtc_wkalrm *alm)
 
 static struct omap_rtc *omap_rtc_power_off_rtc;
 
+static const u32 omap_rtc_scratch_regs[] = {
+   OMAP_RTC_SCRATCH0_REG,
+   OMAP_RTC_SCRATCH1_REG,
+   OMAP_RTC_SCRATCH2_REG,
+};
+
+static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
+u32 *value)
+{
+   *value = readl(omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+
+   return 0;
+}
+
+static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
+ u32 value)
+{
+   struct omap_rtc *rtc = dev_get_drvdata(dev);
+
+   rtc->type->unlock(rtc);
+   writel(value, omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+   rtc->type->lock(rtc);
+
+   return 0;
+}
+
 /*
  * omap_rtc_poweroff: RTC-controlled power off
  *
@@ -484,6 +516,9 @@ static void omap_rtc_power_off(void)
.read_alarm = omap_rtc_read_alarm,
.set_alarm  = omap_rtc_set_alarm,
.alarm_irq_enable = omap_rtc_alarm_irq_enable,
+   .read_scratch   = omap_rtc_read_scratch,
+   .write_scratch  = omap_rtc_write_scratch,
+   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
 };
 
 static const struct omap_rtc_device_type omap_rtc_default_type = {
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index b693ada..da5e003 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -91,6 +91,10 @@ struct rtc_class_ops {
int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset);
+   int (*read_scratch)(struct device *, unsigned int, u32*);
+   int (*write_scratch)(struct device *, unsigned int, u32);
+
+   unsigned int scratch_size;
 };
 
 #define RTC_DEVICE_NAME_SIZE 20
@@ -214,6 +218,9 @@ int rtc_timer_start(struct rtc_device *rtc, struct 
rtc_timer *timer,
 int rtc_set_offset(struct rtc_device *rtc, long offset);
 void rtc_timer_do_work(struct work_struct *work);
 
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value);
+int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value);
+
 static inline bool 

[PATCH] RTC: Add functionality to read/write rtc scratch registers

2016-06-14 Thread Keerthy
From: Russ Dill  

Many RTCs provide scratch registers that are maintained so long as the RTC
has power. Provide a generic method to access these registers.

Signed-off-by: Russ Dill 
Signed-off-by: Keerthy 
---
 drivers/rtc/interface.c | 50 +
 drivers/rtc/rtc-omap.c  | 35 ++
 include/linux/rtc.h |  7 +++
 3 files changed, 92 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 7cafd4d..d5a7ee2 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -1018,3 +1018,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
mutex_unlock(>ops_lock);
return ret;
 }
+
+/* rtc_read_scratch - Read from RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: returned value read
+ *
+ * Kernel interface read from an RTC scratch register
+ */
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
+   mutex_unlock(>ops_lock);
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_read_scratch);
+
+/* rtc_write_scratch - Write to RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: value to write
+ *
+ * Kernel interface write to an RTC scratch register
+ */
+int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size ||
+!rtc->ops->write_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
+
+   mutex_unlock(>ops_lock);
+
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_write_scratch);
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index ec2e9c5..d00ca11 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -66,6 +66,10 @@
 #define OMAP_RTC_COMP_MSB_REG  0x50
 #define OMAP_RTC_OSC_REG   0x54
 
+#define OMAP_RTC_SCRATCH0_REG  0x60
+#define OMAP_RTC_SCRATCH1_REG  0x64
+#define OMAP_RTC_SCRATCH2_REG  0x68
+
 #define OMAP_RTC_KICK0_REG 0x6c
 #define OMAP_RTC_KICK1_REG 0x70
 
@@ -405,6 +409,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct 
rtc_wkalrm *alm)
 
 static struct omap_rtc *omap_rtc_power_off_rtc;
 
+static const u32 omap_rtc_scratch_regs[] = {
+   OMAP_RTC_SCRATCH0_REG,
+   OMAP_RTC_SCRATCH1_REG,
+   OMAP_RTC_SCRATCH2_REG,
+};
+
+static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
+u32 *value)
+{
+   *value = readl(omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+
+   return 0;
+}
+
+static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
+ u32 value)
+{
+   struct omap_rtc *rtc = dev_get_drvdata(dev);
+
+   rtc->type->unlock(rtc);
+   writel(value, omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+   rtc->type->lock(rtc);
+
+   return 0;
+}
+
 /*
  * omap_rtc_poweroff: RTC-controlled power off
  *
@@ -475,6 +507,9 @@ static struct rtc_class_ops omap_rtc_ops = {
.read_alarm = omap_rtc_read_alarm,
.set_alarm  = omap_rtc_set_alarm,
.alarm_irq_enable = omap_rtc_alarm_irq_enable,
+   .read_scratch   = omap_rtc_read_scratch,
+   .write_scratch  = omap_rtc_write_scratch,
+   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
 };
 
 static const struct omap_rtc_device_type omap_rtc_default_type = {
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index b693ada..da5e003 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -91,6 +91,10 @@ struct rtc_class_ops {
int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset);
+   int (*read_scratch)(struct device *, unsigned int, u32*);
+   int (*write_scratch)(struct device *, unsigned int, u32);
+
+   unsigned int scratch_size;
 };
 
 #define RTC_DEVICE_NAME_SIZE 20
@@ -214,6 +218,9 @@ int rtc_read_offset(struct rtc_device *rtc, long *offset);
 int rtc_set_offset(struct rtc_device *rtc, long offset);
 void rtc_timer_do_work(struct work_struct *work);
 
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value);
+int rtc_write_scratch(struct rtc_device *rtc, 

[PATCH] RTC: Add functionality to read/write rtc scratch registers

2016-06-14 Thread Keerthy
From: Russ Dill  

Many RTCs provide scratch registers that are maintained so long as the RTC
has power. Provide a generic method to access these registers.

Signed-off-by: Russ Dill 
Signed-off-by: Keerthy 
---
 drivers/rtc/interface.c | 50 +
 drivers/rtc/rtc-omap.c  | 35 ++
 include/linux/rtc.h |  7 +++
 3 files changed, 92 insertions(+)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 7cafd4d..d5a7ee2 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -1018,3 +1018,53 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
mutex_unlock(>ops_lock);
return ret;
 }
+
+/* rtc_read_scratch - Read from RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: returned value read
+ *
+ * Kernel interface read from an RTC scratch register
+ */
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size || !rtc->ops->read_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->read_scratch(rtc->dev.parent, index, value);
+   mutex_unlock(>ops_lock);
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_read_scratch);
+
+/* rtc_write_scratch - Write to RTC scratch register
+ * @ rtc: rtc device to be used
+ * @ index: index of scratch register
+ * @ value: value to write
+ *
+ * Kernel interface write to an RTC scratch register
+ */
+int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value)
+{
+   int err;
+
+   mutex_lock(>ops_lock);
+
+   if (!rtc->ops)
+   err = -ENODEV;
+   else if (index >= rtc->ops->scratch_size ||
+!rtc->ops->write_scratch)
+   err = -EINVAL;
+   else
+   err = rtc->ops->write_scratch(rtc->dev.parent, index, value);
+
+   mutex_unlock(>ops_lock);
+
+   return err;
+}
+EXPORT_SYMBOL_GPL(rtc_write_scratch);
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index ec2e9c5..d00ca11 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -66,6 +66,10 @@
 #define OMAP_RTC_COMP_MSB_REG  0x50
 #define OMAP_RTC_OSC_REG   0x54
 
+#define OMAP_RTC_SCRATCH0_REG  0x60
+#define OMAP_RTC_SCRATCH1_REG  0x64
+#define OMAP_RTC_SCRATCH2_REG  0x68
+
 #define OMAP_RTC_KICK0_REG 0x6c
 #define OMAP_RTC_KICK1_REG 0x70
 
@@ -405,6 +409,34 @@ static int omap_rtc_set_alarm(struct device *dev, struct 
rtc_wkalrm *alm)
 
 static struct omap_rtc *omap_rtc_power_off_rtc;
 
+static const u32 omap_rtc_scratch_regs[] = {
+   OMAP_RTC_SCRATCH0_REG,
+   OMAP_RTC_SCRATCH1_REG,
+   OMAP_RTC_SCRATCH2_REG,
+};
+
+static int omap_rtc_read_scratch(struct device *dev, unsigned int index,
+u32 *value)
+{
+   *value = readl(omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+
+   return 0;
+}
+
+static int omap_rtc_write_scratch(struct device *dev, unsigned int index,
+ u32 value)
+{
+   struct omap_rtc *rtc = dev_get_drvdata(dev);
+
+   rtc->type->unlock(rtc);
+   writel(value, omap_rtc_power_off_rtc->base +
+  omap_rtc_scratch_regs[index]);
+   rtc->type->lock(rtc);
+
+   return 0;
+}
+
 /*
  * omap_rtc_poweroff: RTC-controlled power off
  *
@@ -475,6 +507,9 @@ static struct rtc_class_ops omap_rtc_ops = {
.read_alarm = omap_rtc_read_alarm,
.set_alarm  = omap_rtc_set_alarm,
.alarm_irq_enable = omap_rtc_alarm_irq_enable,
+   .read_scratch   = omap_rtc_read_scratch,
+   .write_scratch  = omap_rtc_write_scratch,
+   .scratch_size   = ARRAY_SIZE(omap_rtc_scratch_regs),
 };
 
 static const struct omap_rtc_device_type omap_rtc_default_type = {
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index b693ada..da5e003 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -91,6 +91,10 @@ struct rtc_class_ops {
int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset);
+   int (*read_scratch)(struct device *, unsigned int, u32*);
+   int (*write_scratch)(struct device *, unsigned int, u32);
+
+   unsigned int scratch_size;
 };
 
 #define RTC_DEVICE_NAME_SIZE 20
@@ -214,6 +218,9 @@ int rtc_read_offset(struct rtc_device *rtc, long *offset);
 int rtc_set_offset(struct rtc_device *rtc, long offset);
 void rtc_timer_do_work(struct work_struct *work);
 
+int rtc_read_scratch(struct rtc_device *rtc, unsigned int index, u32 *value);
+int rtc_write_scratch(struct rtc_device *rtc, unsigned int index, u32 value);
+
 static inline bool