mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-07-05 21:35:46 +02:00
rtc: cmos: use generic nvmem
Instead of adding a binary sysfs attribute from the driver, use the core to register an nvmem device. This allows to use the in-kernel interface to access the nvram. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
This commit is contained in:
parent
53d29e0a3a
commit
8b5b7958fd
|
@ -541,11 +541,10 @@ static const struct rtc_class_ops cmos_rtc_ops = {
|
||||||
|
|
||||||
#define NVRAM_OFFSET (RTC_REG_D + 1)
|
#define NVRAM_OFFSET (RTC_REG_D + 1)
|
||||||
|
|
||||||
static ssize_t
|
static int cmos_nvram_read(void *priv, unsigned int off, void *val,
|
||||||
cmos_nvram_read(struct file *filp, struct kobject *kobj,
|
size_t count)
|
||||||
struct bin_attribute *attr,
|
|
||||||
char *buf, loff_t off, size_t count)
|
|
||||||
{
|
{
|
||||||
|
unsigned char *buf = val;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
off += NVRAM_OFFSET;
|
off += NVRAM_OFFSET;
|
||||||
|
@ -563,16 +562,13 @@ cmos_nvram_read(struct file *filp, struct kobject *kobj,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t
|
static int cmos_nvram_write(void *priv, unsigned int off, void *val,
|
||||||
cmos_nvram_write(struct file *filp, struct kobject *kobj,
|
size_t count)
|
||||||
struct bin_attribute *attr,
|
|
||||||
char *buf, loff_t off, size_t count)
|
|
||||||
{
|
{
|
||||||
struct cmos_rtc *cmos;
|
struct cmos_rtc *cmos = priv;
|
||||||
|
unsigned char *buf = val;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
cmos = dev_get_drvdata(container_of(kobj, struct device, kobj));
|
|
||||||
|
|
||||||
/* NOTE: on at least PCs and Ataris, the boot firmware uses a
|
/* NOTE: on at least PCs and Ataris, the boot firmware uses a
|
||||||
* checksum on part of the NVRAM data. That's currently ignored
|
* checksum on part of the NVRAM data. That's currently ignored
|
||||||
* here. If userspace is smart enough to know what fields of
|
* here. If userspace is smart enough to know what fields of
|
||||||
|
@ -598,17 +594,6 @@ cmos_nvram_write(struct file *filp, struct kobject *kobj,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bin_attribute nvram = {
|
|
||||||
.attr = {
|
|
||||||
.name = "nvram",
|
|
||||||
.mode = S_IRUGO | S_IWUSR,
|
|
||||||
},
|
|
||||||
|
|
||||||
.read = cmos_nvram_read,
|
|
||||||
.write = cmos_nvram_write,
|
|
||||||
/* size gets set up later */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------*/
|
/*----------------------------------------------------------------*/
|
||||||
|
|
||||||
static struct cmos_rtc cmos_rtc;
|
static struct cmos_rtc cmos_rtc;
|
||||||
|
@ -675,6 +660,14 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
|
||||||
unsigned char rtc_control;
|
unsigned char rtc_control;
|
||||||
unsigned address_space;
|
unsigned address_space;
|
||||||
u32 flags = 0;
|
u32 flags = 0;
|
||||||
|
struct nvmem_config nvmem_cfg = {
|
||||||
|
.name = "cmos_nvram",
|
||||||
|
.word_size = 1,
|
||||||
|
.stride = 1,
|
||||||
|
.reg_read = cmos_nvram_read,
|
||||||
|
.reg_write = cmos_nvram_write,
|
||||||
|
.priv = &cmos_rtc,
|
||||||
|
};
|
||||||
|
|
||||||
/* there can be only one ... */
|
/* there can be only one ... */
|
||||||
if (cmos_rtc.dev)
|
if (cmos_rtc.dev)
|
||||||
|
@ -813,32 +806,28 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* export at least the first block of NVRAM */
|
|
||||||
nvram.size = address_space - NVRAM_OFFSET;
|
|
||||||
retval = sysfs_create_bin_file(&dev->kobj, &nvram);
|
|
||||||
if (retval < 0) {
|
|
||||||
dev_dbg(dev, "can't create nvram file? %d\n", retval);
|
|
||||||
goto cleanup2;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmos_rtc.rtc->ops = &cmos_rtc_ops;
|
cmos_rtc.rtc->ops = &cmos_rtc_ops;
|
||||||
|
cmos_rtc.rtc->nvram_old_abi = true;
|
||||||
retval = rtc_register_device(cmos_rtc.rtc);
|
retval = rtc_register_device(cmos_rtc.rtc);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto cleanup3;
|
goto cleanup2;
|
||||||
|
|
||||||
dev_info(dev, "%s%s, %zd bytes nvram%s\n",
|
/* export at least the first block of NVRAM */
|
||||||
|
nvmem_cfg.size = address_space - NVRAM_OFFSET;
|
||||||
|
if (rtc_nvmem_register(cmos_rtc.rtc, &nvmem_cfg))
|
||||||
|
dev_err(dev, "nvmem registration failed\n");
|
||||||
|
|
||||||
|
dev_info(dev, "%s%s, %d bytes nvram%s\n",
|
||||||
!is_valid_irq(rtc_irq) ? "no alarms" :
|
!is_valid_irq(rtc_irq) ? "no alarms" :
|
||||||
cmos_rtc.mon_alrm ? "alarms up to one year" :
|
cmos_rtc.mon_alrm ? "alarms up to one year" :
|
||||||
cmos_rtc.day_alrm ? "alarms up to one month" :
|
cmos_rtc.day_alrm ? "alarms up to one month" :
|
||||||
"alarms up to one day",
|
"alarms up to one day",
|
||||||
cmos_rtc.century ? ", y3k" : "",
|
cmos_rtc.century ? ", y3k" : "",
|
||||||
nvram.size,
|
nvmem_cfg.size,
|
||||||
is_hpet_enabled() ? ", hpet irqs" : "");
|
is_hpet_enabled() ? ", hpet irqs" : "");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup3:
|
|
||||||
sysfs_remove_bin_file(&dev->kobj, &nvram);
|
|
||||||
cleanup2:
|
cleanup2:
|
||||||
if (is_valid_irq(rtc_irq))
|
if (is_valid_irq(rtc_irq))
|
||||||
free_irq(rtc_irq, cmos_rtc.rtc);
|
free_irq(rtc_irq, cmos_rtc.rtc);
|
||||||
|
@ -867,8 +856,6 @@ static void cmos_do_remove(struct device *dev)
|
||||||
|
|
||||||
cmos_do_shutdown(cmos->irq);
|
cmos_do_shutdown(cmos->irq);
|
||||||
|
|
||||||
sysfs_remove_bin_file(&dev->kobj, &nvram);
|
|
||||||
|
|
||||||
if (is_valid_irq(cmos->irq)) {
|
if (is_valid_irq(cmos->irq)) {
|
||||||
free_irq(cmos->irq, cmos->rtc);
|
free_irq(cmos->irq, cmos->rtc);
|
||||||
hpet_unregister_irq_handler(cmos_interrupt);
|
hpet_unregister_irq_handler(cmos_interrupt);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user