Commit 299b6101 authored by Thomas Bogendoerfer's avatar Thomas Bogendoerfer Committed by Alexandre Belloni

rtc: ds1685: add indirect access method and remove plat_read/plat_write

SGI Octane (IP30) doesn't have RTC register directly mapped into CPU
address space, but accesses RTC registers with an address and data
register.  This is now supported by additional access functions, which
are selected by a new field in platform data. Removed plat_read/plat_write
since there is no user and their usage could introduce lifetime issue,
when functions are placed in different modules.
Signed-off-by: default avatarThomas Bogendoerfer <tbogendoerfer@suse.de>
Acked-by: default avatarJoshua Kinard <kumba@gentoo.org>
Reviewed-by: default avatarJoshua Kinard <kumba@gentoo.org>
Link: https://lore.kernel.org/r/20191014214621.25257-1-tbogendoerfer@suse.deSigned-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent af818031
...@@ -115,7 +115,7 @@ ip32_rtc_platform_data[] = { ...@@ -115,7 +115,7 @@ ip32_rtc_platform_data[] = {
.bcd_mode = true, .bcd_mode = true,
.no_irq = false, .no_irq = false,
.uie_unsupported = false, .uie_unsupported = false,
.alloc_io_resources = true, .access_type = ds1685_reg_direct,
.plat_prepare_poweroff = ip32_prepare_poweroff, .plat_prepare_poweroff = ip32_prepare_poweroff,
}, },
}; };
......
...@@ -31,7 +31,10 @@ ...@@ -31,7 +31,10 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* Standard read/write functions if platform does not provide overrides */ /*
* Standard read/write
* all registers are mapped in CPU address space
*/
/** /**
* ds1685_read - read a value from an rtc register. * ds1685_read - read a value from an rtc register.
...@@ -59,6 +62,35 @@ ds1685_write(struct ds1685_priv *rtc, int reg, u8 value) ...@@ -59,6 +62,35 @@ ds1685_write(struct ds1685_priv *rtc, int reg, u8 value)
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*
* Indirect read/write functions
* access happens via address and data register mapped in CPU address space
*/
/**
* ds1685_indirect_read - read a value from an rtc register.
* @rtc: pointer to the ds1685 rtc structure.
* @reg: the register address to read.
*/
static u8
ds1685_indirect_read(struct ds1685_priv *rtc, int reg)
{
writeb(reg, rtc->regs);
return readb(rtc->data);
}
/**
* ds1685_indirect_write - write a value to an rtc register.
* @rtc: pointer to the ds1685 rtc structure.
* @reg: the register address to write.
* @value: value to write to the register.
*/
static void
ds1685_indirect_write(struct ds1685_priv *rtc, int reg, u8 value)
{
writeb(reg, rtc->regs);
writeb(value, rtc->data);
}
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* Inlined functions */ /* Inlined functions */
...@@ -1062,42 +1094,36 @@ ds1685_rtc_probe(struct platform_device *pdev) ...@@ -1062,42 +1094,36 @@ ds1685_rtc_probe(struct platform_device *pdev)
if (!rtc) if (!rtc)
return -ENOMEM; return -ENOMEM;
/* /* Setup resources and access functions */
* Allocate/setup any IORESOURCE_MEM resources, if required. Not all switch (pdata->access_type) {
* platforms put the RTC in an easy-access place. Like the SGI Octane, case ds1685_reg_direct:
* which attaches the RTC to a "ByteBus", hooked to a SuperIO chip rtc->regs = devm_platform_ioremap_resource(pdev, 0);
* that sits behind the IOC3 PCI metadevice. if (IS_ERR(rtc->regs))
*/ return PTR_ERR(rtc->regs);
if (pdata->alloc_io_resources) { rtc->read = ds1685_read;
rtc->write = ds1685_write;
break;
case ds1685_reg_indirect:
rtc->regs = devm_platform_ioremap_resource(pdev, 0); rtc->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(rtc->regs)) if (IS_ERR(rtc->regs))
return PTR_ERR(rtc->regs); return PTR_ERR(rtc->regs);
rtc->data = devm_platform_ioremap_resource(pdev, 1);
if (IS_ERR(rtc->data))
return PTR_ERR(rtc->data);
rtc->read = ds1685_indirect_read;
rtc->write = ds1685_indirect_write;
break;
} }
if (!rtc->read || !rtc->write)
return -ENXIO;
/* Get the register step size. */ /* Get the register step size. */
if (pdata->regstep > 0) if (pdata->regstep > 0)
rtc->regstep = pdata->regstep; rtc->regstep = pdata->regstep;
else else
rtc->regstep = 1; rtc->regstep = 1;
/* Platform read function, else default if mmio setup */
if (pdata->plat_read)
rtc->read = pdata->plat_read;
else
if (pdata->alloc_io_resources)
rtc->read = ds1685_read;
else
return -ENXIO;
/* Platform write function, else default if mmio setup */
if (pdata->plat_write)
rtc->write = pdata->plat_write;
else
if (pdata->alloc_io_resources)
rtc->write = ds1685_write;
else
return -ENXIO;
/* Platform pre-shutdown function, if defined. */ /* Platform pre-shutdown function, if defined. */
if (pdata->plat_prepare_poweroff) if (pdata->plat_prepare_poweroff)
rtc->prepare_poweroff = pdata->plat_prepare_poweroff; rtc->prepare_poweroff = pdata->plat_prepare_poweroff;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
struct ds1685_priv { struct ds1685_priv {
struct rtc_device *dev; struct rtc_device *dev;
void __iomem *regs; void __iomem *regs;
void __iomem *data;
u32 regstep; u32 regstep;
int irq_num; int irq_num;
bool bcd_mode; bool bcd_mode;
...@@ -70,12 +71,13 @@ struct ds1685_rtc_platform_data { ...@@ -70,12 +71,13 @@ struct ds1685_rtc_platform_data {
const bool bcd_mode; const bool bcd_mode;
const bool no_irq; const bool no_irq;
const bool uie_unsupported; const bool uie_unsupported;
const bool alloc_io_resources;
u8 (*plat_read)(struct ds1685_priv *, int);
void (*plat_write)(struct ds1685_priv *, int, u8);
void (*plat_prepare_poweroff)(void); void (*plat_prepare_poweroff)(void);
void (*plat_wake_alarm)(void); void (*plat_wake_alarm)(void);
void (*plat_post_ram_clear)(void); void (*plat_post_ram_clear)(void);
enum {
ds1685_reg_direct,
ds1685_reg_indirect
} access_type;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment