[PATCH V2] ACPI: Support D3 COLD device in old BIOS for ZPODD

2015-12-09 Thread Ken Xue
D3cold is only regarded as valid if the "_PR3" object is
present for the given device after the commit 20dacb71ad28
("ACPI/PM: Rework device power management to follow ACPI 6").

But some old BIOS only defined "_PS3" for the D3COLD device,
such as ZPODD device. And old kernel also believes the device with
"_PS3" is a D3COLD device.

So, add some logics for supporting D3 COLD device with old BIOS
which is compatible with earlier ACPI spec and kernel behavior.

Reference:
http://marc.info/?l=linux-acpi=144946938709759=2

Signed-off-by: Ken Xue 
Reported-and-tested-by: Gang Long 
---
 include/acpi/acpi_bus.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index ad0a5ff..9894b75 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -631,7 +631,9 @@ static inline bool acpi_device_can_wakeup(struct 
acpi_device *adev)
 
 static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
 {
-   return adev->power.states[ACPI_STATE_D3_COLD].flags.valid;
+   return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
+   ((acpi_gbl_FADT.header.revision < 6) &&
+   adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
 }
 
 #else  /* CONFIG_ACPI */
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2] ACPI: Support D3 COLD device in old BIOS for ZPODD

2015-12-09 Thread Ken Xue
D3cold is only regarded as valid if the "_PR3" object is
present for the given device after the commit 20dacb71ad28
("ACPI/PM: Rework device power management to follow ACPI 6").

But some old BIOS only defined "_PS3" for the D3COLD device,
such as ZPODD device. And old kernel also believes the device with
"_PS3" is a D3COLD device.

So, add some logics for supporting D3 COLD device with old BIOS
which is compatible with earlier ACPI spec and kernel behavior.

Reference:
http://marc.info/?l=linux-acpi=144946938709759=2

Signed-off-by: Ken Xue <ken@amd.com>
Reported-and-tested-by: Gang Long <gang.l...@amd.com>
---
 include/acpi/acpi_bus.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index ad0a5ff..9894b75 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -631,7 +631,9 @@ static inline bool acpi_device_can_wakeup(struct 
acpi_device *adev)
 
 static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
 {
-   return adev->power.states[ACPI_STATE_D3_COLD].flags.valid;
+   return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
+   ((acpi_gbl_FADT.header.revision < 6) &&
+   adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
 }
 
 #else  /* CONFIG_ACPI */
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] ACPI: Support D3 COLD device for old BIOS

2015-12-08 Thread Ken Xue
On Tue, 2015-12-08 at 14:14 +0100, Rafael J. Wysocki wrote:
> On Tuesday, December 08, 2015 09:37:56 AM Ken Xue wrote:
> > On Mon, 2015-12-07 at 23:48 +0100, Rafael J. Wysocki wrote:
> > > On Monday, December 07, 2015 12:44:33 PM Ken Xue wrote:
> > > > D3cold is only regarded as valid if the "_PR3" object is present
> > > > for the given device after the commit <20dacb71ad28>
> > > > (ACPI/PM: Reworkdevice power management to follow ACPI 6).
> > > > 
> > > > But some old BIOS only defined "_PS3" for the D3COLD device.
> > > > And old kernel also believes the device has "_PS3" is a
> > > > D3COLD device.
> > > > 
> > > > So, add some logics for supporting D3 COLD device for old BIOS
> > > > which is compatible with earlier ACPI spec.
> > > > 
> > > > Signed-off-by: Ken Xue 
> > > > Reported-and-tested-by: Gang Long 
> > > 
> > > Well, what really is the problem?
> > 
> > My problem is that
> > "acpi_device_can_poweroff" is called by "zpodd_init" in libata-zpodd.c. 
> > And ZPODD feature only can be enabled when D3_COLD is valid.
> 
> This means that acpi_device_can_poweroff() needs to be updated.  What about
> like this:
> 
> static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
> {
>   return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
((acpi_gbl_FADT.header.revision < 6) &&
>adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
> }

It also could work by refining "acpi_device_can_poweroff".
But ZPODD exactly requests D3 Cold support, So, checking ACPI version
should be necessary when D3 hot is explicit_set.
If you do not have other concern, I will submit new Patch later.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] ACPI: Support D3 COLD device for old BIOS

2015-12-08 Thread Ken Xue
On Tue, 2015-12-08 at 14:14 +0100, Rafael J. Wysocki wrote:
> On Tuesday, December 08, 2015 09:37:56 AM Ken Xue wrote:
> > On Mon, 2015-12-07 at 23:48 +0100, Rafael J. Wysocki wrote:
> > > On Monday, December 07, 2015 12:44:33 PM Ken Xue wrote:
> > > > D3cold is only regarded as valid if the "_PR3" object is present
> > > > for the given device after the commit <20dacb71ad28>
> > > > (ACPI/PM: Reworkdevice power management to follow ACPI 6).
> > > > 
> > > > But some old BIOS only defined "_PS3" for the D3COLD device.
> > > > And old kernel also believes the device has "_PS3" is a
> > > > D3COLD device.
> > > > 
> > > > So, add some logics for supporting D3 COLD device for old BIOS
> > > > which is compatible with earlier ACPI spec.
> > > > 
> > > > Signed-off-by: Ken Xue <ken@amd.com>
> > > > Reported-and-tested-by: Gang Long <gang.l...@amd.com>
> > > 
> > > Well, what really is the problem?
> > 
> > My problem is that
> > "acpi_device_can_poweroff" is called by "zpodd_init" in libata-zpodd.c. 
> > And ZPODD feature only can be enabled when D3_COLD is valid.
> 
> This means that acpi_device_can_poweroff() needs to be updated.  What about
> like this:
> 
> static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
> {
>   return adev->power.states[ACPI_STATE_D3_COLD].flags.valid ||
((acpi_gbl_FADT.header.revision < 6) &&
>adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
> }

It also could work by refining "acpi_device_can_poweroff".
But ZPODD exactly requests D3 Cold support, So, checking ACPI version
should be necessary when D3 hot is explicit_set.
If you do not have other concern, I will submit new Patch later.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] ACPI: Support D3 COLD device for old BIOS

2015-12-07 Thread Ken Xue
On Mon, 2015-12-07 at 23:48 +0100, Rafael J. Wysocki wrote:
> On Monday, December 07, 2015 12:44:33 PM Ken Xue wrote:
> > D3cold is only regarded as valid if the "_PR3" object is present
> > for the given device after the commit <20dacb71ad28>
> > (ACPI/PM: Reworkdevice power management to follow ACPI 6).
> > 
> > But some old BIOS only defined "_PS3" for the D3COLD device.
> > And old kernel also believes the device has "_PS3" is a
> > D3COLD device.
> > 
> > So, add some logics for supporting D3 COLD device for old BIOS
> > which is compatible with earlier ACPI spec.
> > 
> > Signed-off-by: Ken Xue 
> > Reported-and-tested-by: Gang Long 
> 
> Well, what really is the problem?

My problem is that
"acpi_device_can_poweroff" is called by "zpodd_init" in libata-zpodd.c. 
And ZPODD feature only can be enabled when D3_COLD is valid.

> 
> acpi_device_set_power() has a special case specifically for D3cold and
> falls back to D3hot if D3cold has been requested but is not "valid".
> 
> > ---
> >  drivers/acpi/scan.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> > index 01136b8..85c16bb 100644
> > --- a/drivers/acpi/scan.c
> > +++ b/drivers/acpi/scan.c
> > @@ -979,7 +979,9 @@ static void acpi_bus_get_power_flags(struct acpi_device 
> > *device)
> > acpi_bus_init_power_state(device, i);
> >  
> > INIT_LIST_HEAD(>power.states[ACPI_STATE_D3_COLD].resources);
> > -   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources))
> > +   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources) ||
> > +   ((acpi_gbl_FADT.header.revision < 6) &&
> > +   device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set))
> > device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
> >  
> > /* Set defaults for D0 and D3hot states (always valid) */
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/1] ACPI: Support D3 COLD device for old BIOS

2015-12-07 Thread Ken Xue
On Mon, 2015-12-07 at 23:48 +0100, Rafael J. Wysocki wrote:
> On Monday, December 07, 2015 12:44:33 PM Ken Xue wrote:
> > D3cold is only regarded as valid if the "_PR3" object is present
> > for the given device after the commit <20dacb71ad28>
> > (ACPI/PM: Reworkdevice power management to follow ACPI 6).
> > 
> > But some old BIOS only defined "_PS3" for the D3COLD device.
> > And old kernel also believes the device has "_PS3" is a
> > D3COLD device.
> > 
> > So, add some logics for supporting D3 COLD device for old BIOS
> > which is compatible with earlier ACPI spec.
> > 
> > Signed-off-by: Ken Xue <ken@amd.com>
> > Reported-and-tested-by: Gang Long <gang.l...@amd.com>
> 
> Well, what really is the problem?

My problem is that
"acpi_device_can_poweroff" is called by "zpodd_init" in libata-zpodd.c. 
And ZPODD feature only can be enabled when D3_COLD is valid.

> 
> acpi_device_set_power() has a special case specifically for D3cold and
> falls back to D3hot if D3cold has been requested but is not "valid".
> 
> > ---
> >  drivers/acpi/scan.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> > index 01136b8..85c16bb 100644
> > --- a/drivers/acpi/scan.c
> > +++ b/drivers/acpi/scan.c
> > @@ -979,7 +979,9 @@ static void acpi_bus_get_power_flags(struct acpi_device 
> > *device)
> > acpi_bus_init_power_state(device, i);
> >  
> > INIT_LIST_HEAD(>power.states[ACPI_STATE_D3_COLD].resources);
> > -   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources))
> > +   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources) ||
> > +   ((acpi_gbl_FADT.header.revision < 6) &&
> > +   device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set))
> > device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
> >  
> > /* Set defaults for D0 and D3hot states (always valid) */
> > 
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] ACPI: Support D3 COLD device for old BIOS

2015-12-06 Thread Ken Xue
D3cold is only regarded as valid if the "_PR3" object is present
for the given device after the commit <20dacb71ad28>
(ACPI/PM: Reworkdevice power management to follow ACPI 6).

But some old BIOS only defined "_PS3" for the D3COLD device.
And old kernel also believes the device has "_PS3" is a
D3COLD device.

So, add some logics for supporting D3 COLD device for old BIOS
which is compatible with earlier ACPI spec.

Signed-off-by: Ken Xue 
Reported-and-tested-by: Gang Long 

---
 drivers/acpi/scan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 01136b8..85c16bb 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -979,7 +979,9 @@ static void acpi_bus_get_power_flags(struct acpi_device 
*device)
acpi_bus_init_power_state(device, i);
 
INIT_LIST_HEAD(>power.states[ACPI_STATE_D3_COLD].resources);
-   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources))
+   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources) ||
+   ((acpi_gbl_FADT.header.revision < 6) &&
+   device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set))
device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
 
/* Set defaults for D0 and D3hot states (always valid) */
-- 
1.9.1





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] ACPI: Support D3 COLD device for old BIOS

2015-12-06 Thread Ken Xue
D3cold is only regarded as valid if the "_PR3" object is present
for the given device after the commit <20dacb71ad28>
(ACPI/PM: Reworkdevice power management to follow ACPI 6).

But some old BIOS only defined "_PS3" for the D3COLD device.
And old kernel also believes the device has "_PS3" is a
D3COLD device.

So, add some logics for supporting D3 COLD device for old BIOS
which is compatible with earlier ACPI spec.

Signed-off-by: Ken Xue <ken@amd.com>
Reported-and-tested-by: Gang Long <gang.l...@amd.com>

---
 drivers/acpi/scan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 01136b8..85c16bb 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -979,7 +979,9 @@ static void acpi_bus_get_power_flags(struct acpi_device 
*device)
acpi_bus_init_power_state(device, i);
 
INIT_LIST_HEAD(>power.states[ACPI_STATE_D3_COLD].resources);
-   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources))
+   if (!list_empty(>power.states[ACPI_STATE_D3_HOT].resources) ||
+   ((acpi_gbl_FADT.header.revision < 6) &&
+   device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set))
device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
 
/* Set defaults for D0 and D3hot states (always valid) */
-- 
1.9.1





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] SCSI: Fix NULL pointer dereference in runtime PM

2015-11-30 Thread Ken Xue
The routines in scsi_pm.c assume that if a runtime-PM callback is
invoked for a SCSI device, it can only mean that the device's driver
has asked the block layer to handle the runtime power management (by
calling blk_pm_runtime_init(), which among other things sets q->dev).

However, this assumption turns out to be wrong for things like the ses
driver.  Normally ses devices are not allowed to do runtime PM, but
userspace can override this setting.  If this happens, the kernel gets
a NULL pointer dereference when blk_post_runtime_resume() tries to use
the uninitialized q->dev pointer.

This patch fixes the problem by checking q->dev in block layer before
handle runtime PM. Since ses doesn't define any PM callbacks and call
blk_pm_runtime_init(), the crash won't occur.

This fixes Bugzilla #101371.
https://bugzilla.kernel.org/show_bug.cgi?id=101371

More discussion can be found from below link.
http://marc.info/?l=linux-scsi=144163730531875=2

Signed-off-by: Ken Xue 
Acked-by: Alan Stern 
Cc: Xiangliang Yu 
Cc: James E.J. Bottomley 
Cc: Jens Axboe 
Cc: Michael Terry 
Cc: sta...@vger.kernel.org

---
 block/blk-core.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/block/blk-core.c b/block/blk-core.c
index 60912e9..a07ab18 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3280,6 +3280,9 @@ int blk_pre_runtime_suspend(struct request_queue *q)
 {
int ret = 0;
 
+   if (!q->dev)
+   return ret;
+
spin_lock_irq(q->queue_lock);
if (q->nr_pending) {
ret = -EBUSY;
@@ -3307,6 +3310,9 @@ EXPORT_SYMBOL(blk_pre_runtime_suspend);
  */
 void blk_post_runtime_suspend(struct request_queue *q, int err)
 {
+   if (!q->dev)
+   return;
+
spin_lock_irq(q->queue_lock);
if (!err) {
q->rpm_status = RPM_SUSPENDED;
@@ -3331,6 +3337,9 @@ EXPORT_SYMBOL(blk_post_runtime_suspend);
  */
 void blk_pre_runtime_resume(struct request_queue *q)
 {
+   if (!q->dev)
+   return;
+
spin_lock_irq(q->queue_lock);
q->rpm_status = RPM_RESUMING;
spin_unlock_irq(q->queue_lock);
@@ -3353,6 +3362,9 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
  */
 void blk_post_runtime_resume(struct request_queue *q, int err)
 {
+   if (!q->dev)
+   return;
+
spin_lock_irq(q->queue_lock);
if (!err) {
q->rpm_status = RPM_ACTIVE;
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2]Revert "SCSI: Fix NULL pointer dereference in runtime PM"

2015-11-30 Thread Ken Xue
This reverts commit 49718f0fb8c9 ("SCSI: Fix NULL pointer dereference in
runtime PM")

The old commit may lead to a issue that blk_{pre|post}_runtime_suspend and
blk_{pre|post}_runtime_resume may not be called in pairs.

Take sr device as example, when sr device goes to runtime suspend, 
blk_{pre|post}_runtime_suspend will be called since sr device defined
pm->runtime_suspend. But blk_{pre|post}_runtime_resume will not be called
since sr device doesn't have pm->runtime_resume. so, sr device can not
resume correctly anymore.

More discussion can be found from below link.
http://marc.info/?l=linux-scsi=144163730531875=2

Signed-off-by: Ken Xue 
Acked-by: Alan Stern 
Cc: Xiangliang Yu 
Cc: James E.J. Bottomley 
Cc: Jens Axboe 
Cc: Michael Terry 
Cc: sta...@vger.kernel.org

---
 drivers/scsi/scsi_pm.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index e4b7998..459abe1 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -219,13 +219,13 @@ static int sdev_runtime_suspend(struct device *dev)
struct scsi_device *sdev = to_scsi_device(dev);
int err = 0;
 
-   if (pm && pm->runtime_suspend) {
-   err = blk_pre_runtime_suspend(sdev->request_queue);
-   if (err)
-   return err;
+   err = blk_pre_runtime_suspend(sdev->request_queue);
+   if (err)
+   return err;
+   if (pm && pm->runtime_suspend)
err = pm->runtime_suspend(dev);
-   blk_post_runtime_suspend(sdev->request_queue, err);
-   }
+   blk_post_runtime_suspend(sdev->request_queue, err);
+
return err;
 }
 
@@ -248,11 +248,11 @@ static int sdev_runtime_resume(struct device *dev)
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int err = 0;
 
-   if (pm && pm->runtime_resume) {
-   blk_pre_runtime_resume(sdev->request_queue);
+   blk_pre_runtime_resume(sdev->request_queue);
+   if (pm && pm->runtime_resume)
err = pm->runtime_resume(dev);
-   blk_post_runtime_resume(sdev->request_queue, err);
-   }
+   blk_post_runtime_resume(sdev->request_queue, err);
+
return err;
 }
 
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] SCSI: Fix NULL pointer dereference in runtime PM

2015-11-30 Thread Ken Xue
The routines in scsi_pm.c assume that if a runtime-PM callback is
invoked for a SCSI device, it can only mean that the device's driver
has asked the block layer to handle the runtime power management (by
calling blk_pm_runtime_init(), which among other things sets q->dev).

However, this assumption turns out to be wrong for things like the ses
driver.  Normally ses devices are not allowed to do runtime PM, but
userspace can override this setting.  If this happens, the kernel gets
a NULL pointer dereference when blk_post_runtime_resume() tries to use
the uninitialized q->dev pointer.

This patch fixes the problem by checking q->dev in block layer before
handle runtime PM. Since ses doesn't define any PM callbacks and call
blk_pm_runtime_init(), the crash won't occur.

This fixes Bugzilla #101371.
https://bugzilla.kernel.org/show_bug.cgi?id=101371

More discussion can be found from below link.
http://marc.info/?l=linux-scsi=144163730531875=2

Signed-off-by: Ken Xue <ken@amd.com>
Acked-by: Alan Stern <st...@rowland.harvard.edu>
Cc: Xiangliang Yu <xiangliang...@amd.com>
Cc: James E.J. Bottomley <jbottom...@odin.com>
Cc: Jens Axboe <ax...@kernel.dk>
Cc: Michael Terry <michael.te...@canonical.com>
Cc: sta...@vger.kernel.org

---
 block/blk-core.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/block/blk-core.c b/block/blk-core.c
index 60912e9..a07ab18 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3280,6 +3280,9 @@ int blk_pre_runtime_suspend(struct request_queue *q)
 {
int ret = 0;
 
+   if (!q->dev)
+   return ret;
+
spin_lock_irq(q->queue_lock);
if (q->nr_pending) {
ret = -EBUSY;
@@ -3307,6 +3310,9 @@ EXPORT_SYMBOL(blk_pre_runtime_suspend);
  */
 void blk_post_runtime_suspend(struct request_queue *q, int err)
 {
+   if (!q->dev)
+   return;
+
spin_lock_irq(q->queue_lock);
if (!err) {
q->rpm_status = RPM_SUSPENDED;
@@ -3331,6 +3337,9 @@ EXPORT_SYMBOL(blk_post_runtime_suspend);
  */
 void blk_pre_runtime_resume(struct request_queue *q)
 {
+   if (!q->dev)
+   return;
+
spin_lock_irq(q->queue_lock);
q->rpm_status = RPM_RESUMING;
spin_unlock_irq(q->queue_lock);
@@ -3353,6 +3362,9 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
  */
 void blk_post_runtime_resume(struct request_queue *q, int err)
 {
+   if (!q->dev)
+   return;
+
spin_lock_irq(q->queue_lock);
if (!err) {
q->rpm_status = RPM_ACTIVE;
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2]Revert "SCSI: Fix NULL pointer dereference in runtime PM"

2015-11-30 Thread Ken Xue
This reverts commit 49718f0fb8c9 ("SCSI: Fix NULL pointer dereference in
runtime PM")

The old commit may lead to a issue that blk_{pre|post}_runtime_suspend and
blk_{pre|post}_runtime_resume may not be called in pairs.

Take sr device as example, when sr device goes to runtime suspend, 
blk_{pre|post}_runtime_suspend will be called since sr device defined
pm->runtime_suspend. But blk_{pre|post}_runtime_resume will not be called
since sr device doesn't have pm->runtime_resume. so, sr device can not
resume correctly anymore.

More discussion can be found from below link.
http://marc.info/?l=linux-scsi=144163730531875=2

Signed-off-by: Ken Xue <ken@amd.com>
Acked-by: Alan Stern <st...@rowland.harvard.edu>
Cc: Xiangliang Yu <xiangliang...@amd.com>
Cc: James E.J. Bottomley <jbottom...@odin.com>
Cc: Jens Axboe <ax...@kernel.dk>
Cc: Michael Terry <michael.te...@canonical.com>
Cc: sta...@vger.kernel.org

---
 drivers/scsi/scsi_pm.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index e4b7998..459abe1 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -219,13 +219,13 @@ static int sdev_runtime_suspend(struct device *dev)
struct scsi_device *sdev = to_scsi_device(dev);
int err = 0;
 
-   if (pm && pm->runtime_suspend) {
-   err = blk_pre_runtime_suspend(sdev->request_queue);
-   if (err)
-   return err;
+   err = blk_pre_runtime_suspend(sdev->request_queue);
+   if (err)
+   return err;
+   if (pm && pm->runtime_suspend)
err = pm->runtime_suspend(dev);
-   blk_post_runtime_suspend(sdev->request_queue, err);
-   }
+   blk_post_runtime_suspend(sdev->request_queue, err);
+
return err;
 }
 
@@ -248,11 +248,11 @@ static int sdev_runtime_resume(struct device *dev)
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
int err = 0;
 
-   if (pm && pm->runtime_resume) {
-   blk_pre_runtime_resume(sdev->request_queue);
+   blk_pre_runtime_resume(sdev->request_queue);
+   if (pm && pm->runtime_resume)
err = pm->runtime_resume(dev);
-   blk_post_runtime_resume(sdev->request_queue, err);
-   }
+   blk_post_runtime_resume(sdev->request_queue, err);
+
return err;
 }
 
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-22 Thread Ken Xue
On Wed, 2015-10-21 at 13:46 +0300, Mika Westerberg wrote:
> You are saying that the original commit a445900c906092 ("i2c:
> designware: Add support for AMD I2C controller") actually never worked
> because it failed to register the clock with clkdev? In that case it is
> not even a regression ;-) Oh my...

You are right :-). The new patch for reverting a445900c906092 is
submitted.
Please help to review. Thanks.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] i2c: designware: reverts "i2c: designware: Add support for AMD I2C controller"

2015-10-22 Thread Ken Xue
The patch reverts commit a445900c9060 (i2c: designware: Add support for
AMD I2C controller)

Since kernel starts to support APD(drivers/acpi/acpi_apd.c), there is
no need to get freq from id->driver_data for AMD0010. clkdev is supposed
to be already registered in APD.

So, revert old design and make AMD0010 looks like other ones.

Signed-off-by: Ken Xue 
Signed-off-by: Xiangliang Yu 
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 27 +--
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 472b882..4bf5fc1 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -97,7 +97,6 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, 
char method[],
 static int dw_i2c_acpi_configure(struct platform_device *pdev)
 {
struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
-   const struct acpi_device_id *id;
 
dev->adapter.nr = -1;
dev->tx_fifo_depth = 32;
@@ -111,29 +110,9 @@ static int dw_i2c_acpi_configure(struct platform_device 
*pdev)
dw_i2c_acpi_params(pdev, "FMCN", >fs_hcnt, >fs_lcnt,
   >sda_hold_time);
 
-   /*
-* Provide a way for Designware I2C host controllers that are not
-* based on Intel LPSS to specify their input clock frequency via
-* id->driver_data.
-*/
-   id = acpi_match_device(pdev->dev.driver->acpi_match_table, >dev);
-   if (id && id->driver_data)
-   clk_register_fixed_rate(>dev, dev_name(>dev), NULL,
-   CLK_IS_ROOT, id->driver_data);
-
return 0;
 }
 
-static void dw_i2c_acpi_unconfigure(struct platform_device *pdev)
-{
-   struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
-   const struct acpi_device_id *id;
-
-   id = acpi_match_device(pdev->dev.driver->acpi_match_table, >dev);
-   if (id && id->driver_data)
-   clk_unregister(dev->clk);
-}
-
 static const struct acpi_device_id dw_i2c_acpi_match[] = {
{ "INT33C2", 0 },
{ "INT33C3", 0 },
@@ -141,7 +120,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = {
{ "INT3433", 0 },
{ "80860F41", 0 },
{ "808622C1", 0 },
-   { "AMD0010", 133 * 1000 * 1000 },
+   { "AMD0010", 0 },
{ }
 };
 MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match);
@@ -150,7 +129,6 @@ static inline int dw_i2c_acpi_configure(struct 
platform_device *pdev)
 {
return -ENODEV;
 }
-static inline void dw_i2c_acpi_unconfigure(struct platform_device *pdev) { }
 #endif
 
 static int dw_i2c_probe(struct platform_device *pdev)
@@ -306,9 +284,6 @@ static int dw_i2c_remove(struct platform_device *pdev)
pm_runtime_put_sync(>dev);
pm_runtime_disable(>dev);
 
-   if (has_acpi_companion(>dev))
-   dw_i2c_acpi_unconfigure(pdev);
-
return 0;
 }
 
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-22 Thread Ken Xue
On Wed, 2015-10-21 at 13:46 +0300, Mika Westerberg wrote:
> You are saying that the original commit a445900c906092 ("i2c:
> designware: Add support for AMD I2C controller") actually never worked
> because it failed to register the clock with clkdev? In that case it is
> not even a regression ;-) Oh my...

You are right :-). The new patch for reverting a445900c906092 is
submitted.
Please help to review. Thanks.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] i2c: designware: reverts "i2c: designware: Add support for AMD I2C controller"

2015-10-22 Thread Ken Xue
The patch reverts commit a445900c9060 (i2c: designware: Add support for
AMD I2C controller)

Since kernel starts to support APD(drivers/acpi/acpi_apd.c), there is
no need to get freq from id->driver_data for AMD0010. clkdev is supposed
to be already registered in APD.

So, revert old design and make AMD0010 looks like other ones.

Signed-off-by: Ken Xue <ken@amd.com>
Signed-off-by: Xiangliang Yu <xiangliang...@amd.com>
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 27 +--
 1 file changed, 1 insertion(+), 26 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 472b882..4bf5fc1 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -97,7 +97,6 @@ static void dw_i2c_acpi_params(struct platform_device *pdev, 
char method[],
 static int dw_i2c_acpi_configure(struct platform_device *pdev)
 {
struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
-   const struct acpi_device_id *id;
 
dev->adapter.nr = -1;
dev->tx_fifo_depth = 32;
@@ -111,29 +110,9 @@ static int dw_i2c_acpi_configure(struct platform_device 
*pdev)
dw_i2c_acpi_params(pdev, "FMCN", >fs_hcnt, >fs_lcnt,
   >sda_hold_time);
 
-   /*
-* Provide a way for Designware I2C host controllers that are not
-* based on Intel LPSS to specify their input clock frequency via
-* id->driver_data.
-*/
-   id = acpi_match_device(pdev->dev.driver->acpi_match_table, >dev);
-   if (id && id->driver_data)
-   clk_register_fixed_rate(>dev, dev_name(>dev), NULL,
-   CLK_IS_ROOT, id->driver_data);
-
return 0;
 }
 
-static void dw_i2c_acpi_unconfigure(struct platform_device *pdev)
-{
-   struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
-   const struct acpi_device_id *id;
-
-   id = acpi_match_device(pdev->dev.driver->acpi_match_table, >dev);
-   if (id && id->driver_data)
-   clk_unregister(dev->clk);
-}
-
 static const struct acpi_device_id dw_i2c_acpi_match[] = {
{ "INT33C2", 0 },
{ "INT33C3", 0 },
@@ -141,7 +120,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = {
{ "INT3433", 0 },
{ "80860F41", 0 },
{ "808622C1", 0 },
-   { "AMD0010", 133 * 1000 * 1000 },
+   { "AMD0010", 0 },
{ }
 };
 MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match);
@@ -150,7 +129,6 @@ static inline int dw_i2c_acpi_configure(struct 
platform_device *pdev)
 {
return -ENODEV;
 }
-static inline void dw_i2c_acpi_unconfigure(struct platform_device *pdev) { }
 #endif
 
 static int dw_i2c_probe(struct platform_device *pdev)
@@ -306,9 +284,6 @@ static int dw_i2c_remove(struct platform_device *pdev)
pm_runtime_put_sync(>dev);
pm_runtime_disable(>dev);
 
-   if (has_acpi_companion(>dev))
-   dw_i2c_acpi_unconfigure(pdev);
-
return 0;
 }
 
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-21 Thread Ken Xue
On Wed, 2015-10-21 at 10:28 +0300, Mika Westerberg wrote:
> On Wed, Oct 21, 2015 at 09:11:33AM +0800, Ken Xue wrote:
> > On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> > > On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > > > DW I2C driver tries to register a clk from id->driver_data as an
> > > > alternative way besides intel lpss. But code doesn't register the
> > > > clk to clkdev. So, devm_clk_get will fail during probe.
> > > > 
> > > > The patch can fix this issue.
> > > 
> > > Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, can you
> > > create the clock there just like we do for Intel stuff?
> > Sure. APD already creates the clock for AMD0010 as you expected. And the
> > next patch([PATCH 2/2] i2c: designware: remove freq definition for
> > "AMD0010" in acpi_device_id) is dropping the old way for getting freq.
> 
> So this patch is not necessary, right?
Even though there is no use case that getting freq from id->driver_data,
But if we want to keep this design, then we should use current patch for
fixing the potential issue. So, the patch is nice to have.

Otherwise, we have to revert whole old design(a445900c).

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-21 Thread Ken Xue
On Wed, 2015-10-21 at 12:49 +0300, Mika Westerberg wrote:
> On Wed, Oct 21, 2015 at 05:37:53PM +0800, Ken Xue wrote:
> > On Wed, 2015-10-21 at 12:25 +0300, Mika Westerberg wrote:
> > > On Wed, Oct 21, 2015 at 04:42:23PM +0800, Ken Xue wrote:
> > > > On Wed, 2015-10-21 at 10:28 +0300, Mika Westerberg wrote:
> > > > > On Wed, Oct 21, 2015 at 09:11:33AM +0800, Ken Xue wrote:
> > > > > > On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> > > > > > > On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > > > > > > > DW I2C driver tries to register a clk from id->driver_data as an
> > > > > > > > alternative way besides intel lpss. But code doesn't register 
> > > > > > > > the
> > > > > > > > clk to clkdev. So, devm_clk_get will fail during probe.
> > > > > > > > 
> > > > > > > > The patch can fix this issue.
> > > > > > > 
> > > > > > > Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, 
> > > > > > > can you
> > > > > > > create the clock there just like we do for Intel stuff?
> > > > > > Sure. APD already creates the clock for AMD0010 as you expected. 
> > > > > > And the
> > > > > > next patch([PATCH 2/2] i2c: designware: remove freq definition for
> > > > > > "AMD0010" in acpi_device_id) is dropping the old way for getting 
> > > > > > freq.
> > > > > 
> > > > > So this patch is not necessary, right?
> > > > Even though there is no use case that getting freq from id->driver_data,
> > > > But if we want to keep this design, then we should use current patch for
> > > > fixing the potential issue. So, the patch is nice to have.
> > > 
> > > What potential issue?
> > devm_clk_get will fail during probe for AMD0010 without current patch.
> 
> How can it fail if you provide the very clock from drivers/acpi/acpi_apd.c?
After apd was accept in kernel V4.1, there is no issue. But between 3.18
and V4.1, there will be a problem.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-21 Thread Ken Xue
On Wed, 2015-10-21 at 12:25 +0300, Mika Westerberg wrote:
> On Wed, Oct 21, 2015 at 04:42:23PM +0800, Ken Xue wrote:
> > On Wed, 2015-10-21 at 10:28 +0300, Mika Westerberg wrote:
> > > On Wed, Oct 21, 2015 at 09:11:33AM +0800, Ken Xue wrote:
> > > > On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> > > > > On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > > > > > DW I2C driver tries to register a clk from id->driver_data as an
> > > > > > alternative way besides intel lpss. But code doesn't register the
> > > > > > clk to clkdev. So, devm_clk_get will fail during probe.
> > > > > > 
> > > > > > The patch can fix this issue.
> > > > > 
> > > > > Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, can you
> > > > > create the clock there just like we do for Intel stuff?
> > > > Sure. APD already creates the clock for AMD0010 as you expected. And the
> > > > next patch([PATCH 2/2] i2c: designware: remove freq definition for
> > > > "AMD0010" in acpi_device_id) is dropping the old way for getting freq.
> > > 
> > > So this patch is not necessary, right?
> > Even though there is no use case that getting freq from id->driver_data,
> > But if we want to keep this design, then we should use current patch for
> > fixing the potential issue. So, the patch is nice to have.
> 
> What potential issue?
devm_clk_get will fail during probe for AMD0010 without current patch.

> 
> If you pass clock from drivers/acpi/acpi_apd.c and drop the hard coded
> freq for AMD0010 in the I2C designware driver, the driver still works
> just fine.
> 
> > Otherwise, we have to revert whole old design(a445900c).
> 
> Yes please :-)
Glad to do.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-21 Thread Ken Xue
On Wed, 2015-10-21 at 12:25 +0300, Mika Westerberg wrote:
> On Wed, Oct 21, 2015 at 04:42:23PM +0800, Ken Xue wrote:
> > On Wed, 2015-10-21 at 10:28 +0300, Mika Westerberg wrote:
> > > On Wed, Oct 21, 2015 at 09:11:33AM +0800, Ken Xue wrote:
> > > > On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> > > > > On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > > > > > DW I2C driver tries to register a clk from id->driver_data as an
> > > > > > alternative way besides intel lpss. But code doesn't register the
> > > > > > clk to clkdev. So, devm_clk_get will fail during probe.
> > > > > > 
> > > > > > The patch can fix this issue.
> > > > > 
> > > > > Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, can you
> > > > > create the clock there just like we do for Intel stuff?
> > > > Sure. APD already creates the clock for AMD0010 as you expected. And the
> > > > next patch([PATCH 2/2] i2c: designware: remove freq definition for
> > > > "AMD0010" in acpi_device_id) is dropping the old way for getting freq.
> > > 
> > > So this patch is not necessary, right?
> > Even though there is no use case that getting freq from id->driver_data,
> > But if we want to keep this design, then we should use current patch for
> > fixing the potential issue. So, the patch is nice to have.
> 
> What potential issue?
devm_clk_get will fail during probe for AMD0010 without current patch.

> 
> If you pass clock from drivers/acpi/acpi_apd.c and drop the hard coded
> freq for AMD0010 in the I2C designware driver, the driver still works
> just fine.
> 
> > Otherwise, we have to revert whole old design(a445900c).
> 
> Yes please :-)
Glad to do.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-21 Thread Ken Xue
On Wed, 2015-10-21 at 12:49 +0300, Mika Westerberg wrote:
> On Wed, Oct 21, 2015 at 05:37:53PM +0800, Ken Xue wrote:
> > On Wed, 2015-10-21 at 12:25 +0300, Mika Westerberg wrote:
> > > On Wed, Oct 21, 2015 at 04:42:23PM +0800, Ken Xue wrote:
> > > > On Wed, 2015-10-21 at 10:28 +0300, Mika Westerberg wrote:
> > > > > On Wed, Oct 21, 2015 at 09:11:33AM +0800, Ken Xue wrote:
> > > > > > On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> > > > > > > On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > > > > > > > DW I2C driver tries to register a clk from id->driver_data as an
> > > > > > > > alternative way besides intel lpss. But code doesn't register 
> > > > > > > > the
> > > > > > > > clk to clkdev. So, devm_clk_get will fail during probe.
> > > > > > > > 
> > > > > > > > The patch can fix this issue.
> > > > > > > 
> > > > > > > Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, 
> > > > > > > can you
> > > > > > > create the clock there just like we do for Intel stuff?
> > > > > > Sure. APD already creates the clock for AMD0010 as you expected. 
> > > > > > And the
> > > > > > next patch([PATCH 2/2] i2c: designware: remove freq definition for
> > > > > > "AMD0010" in acpi_device_id) is dropping the old way for getting 
> > > > > > freq.
> > > > > 
> > > > > So this patch is not necessary, right?
> > > > Even though there is no use case that getting freq from id->driver_data,
> > > > But if we want to keep this design, then we should use current patch for
> > > > fixing the potential issue. So, the patch is nice to have.
> > > 
> > > What potential issue?
> > devm_clk_get will fail during probe for AMD0010 without current patch.
> 
> How can it fail if you provide the very clock from drivers/acpi/acpi_apd.c?
After apd was accept in kernel V4.1, there is no issue. But between 3.18
and V4.1, there will be a problem.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-21 Thread Ken Xue
On Wed, 2015-10-21 at 10:28 +0300, Mika Westerberg wrote:
> On Wed, Oct 21, 2015 at 09:11:33AM +0800, Ken Xue wrote:
> > On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> > > On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > > > DW I2C driver tries to register a clk from id->driver_data as an
> > > > alternative way besides intel lpss. But code doesn't register the
> > > > clk to clkdev. So, devm_clk_get will fail during probe.
> > > > 
> > > > The patch can fix this issue.
> > > 
> > > Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, can you
> > > create the clock there just like we do for Intel stuff?
> > Sure. APD already creates the clock for AMD0010 as you expected. And the
> > next patch([PATCH 2/2] i2c: designware: remove freq definition for
> > "AMD0010" in acpi_device_id) is dropping the old way for getting freq.
> 
> So this patch is not necessary, right?
Even though there is no use case that getting freq from id->driver_data,
But if we want to keep this design, then we should use current patch for
fixing the potential issue. So, the patch is nice to have.

Otherwise, we have to revert whole old design(a445900c).

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-20 Thread Ken Xue
On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > DW I2C driver tries to register a clk from id->driver_data as an
> > alternative way besides intel lpss. But code doesn't register the
> > clk to clkdev. So, devm_clk_get will fail during probe.
> > 
> > The patch can fix this issue.
> 
> Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, can you
> create the clock there just like we do for Intel stuff?
Sure. APD already creates the clock for AMD0010 as you expected. And the
next patch([PATCH 2/2] i2c: designware: remove freq definition for
"AMD0010" in acpi_device_id) is dropping the old way for getting freq.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] i2c: designware: remove freq definition for "AMD0010" in acpi_device_id

2015-10-20 Thread Ken Xue
Now, AMD ACPI devices can be reworked by APD which is similar to intel
lpss. And the clkdev for "AMD0010" can be registered in APD. So, try
to remove freq definition from id->driver_data for "AMD0010".

Make "AMD0010" look like other ones.

Signed-off-by: Ken Xue 
Signed-off-by: Xiangliang Yu 
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 9ee1fc6..c8acbff 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -125,7 +125,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = {
{ "INT3433", 0 },
{ "80860F41", 0 },
{ "808622C1", 0 },
-   { "AMD0010", 133 * 1000 * 1000 },
+   { "AMD0010", 0 },
{ }
 };
 MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match);
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-20 Thread Ken Xue
DW I2C driver tries to register a clk from id->driver_data as an
alternative way besides intel lpss. But code doesn't register the
clk to clkdev. So, devm_clk_get will fail during probe.

The patch can fix this issue.

Signed-off-by: Ken Xue 
Signed-off-by: Xiangliang Yu 
Cc: sta...@vger.kernel.org
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 3dd2de3..9ee1fc6 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -78,6 +79,7 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
 {
struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
const struct acpi_device_id *id;
+   struct clk *clk;
 
dev->adapter.nr = -1;
dev->tx_fifo_depth = 32;
@@ -97,9 +99,11 @@ static int dw_i2c_acpi_configure(struct platform_device 
*pdev)
 * id->driver_data.
 */
id = acpi_match_device(pdev->dev.driver->acpi_match_table, >dev);
-   if (id && id->driver_data)
-   clk_register_fixed_rate(>dev, dev_name(>dev), NULL,
-   CLK_IS_ROOT, id->driver_data);
+   if (id && id->driver_data) {
+   clk = clk_register_fixed_rate(>dev, dev_name(>dev),
+   NULL, CLK_IS_ROOT, id->driver_data);
+   clk_register_clkdev(clk, NULL, dev_name(>dev));
+   }
 
return 0;
 }
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-20 Thread Ken Xue
DW I2C driver tries to register a clk from id->driver_data as an
alternative way besides intel lpss. But code doesn't register the
clk to clkdev. So, devm_clk_get will fail during probe.

The patch can fix this issue.

Signed-off-by: Ken Xue <ken@amd.com>
Signed-off-by: Xiangliang Yu <xiangliang...@amd.com>
Cc: sta...@vger.kernel.org
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 3dd2de3..9ee1fc6 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -78,6 +79,7 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
 {
struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
const struct acpi_device_id *id;
+   struct clk *clk;
 
dev->adapter.nr = -1;
dev->tx_fifo_depth = 32;
@@ -97,9 +99,11 @@ static int dw_i2c_acpi_configure(struct platform_device 
*pdev)
 * id->driver_data.
 */
id = acpi_match_device(pdev->dev.driver->acpi_match_table, >dev);
-   if (id && id->driver_data)
-   clk_register_fixed_rate(>dev, dev_name(>dev), NULL,
-   CLK_IS_ROOT, id->driver_data);
+   if (id && id->driver_data) {
+   clk = clk_register_fixed_rate(>dev, dev_name(>dev),
+   NULL, CLK_IS_ROOT, id->driver_data);
+   clk_register_clkdev(clk, NULL, dev_name(>dev));
+   }
 
return 0;
 }
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] i2c: designware: remove freq definition for "AMD0010" in acpi_device_id

2015-10-20 Thread Ken Xue
Now, AMD ACPI devices can be reworked by APD which is similar to intel
lpss. And the clkdev for "AMD0010" can be registered in APD. So, try
to remove freq definition from id->driver_data for "AMD0010".

Make "AMD0010" look like other ones.

Signed-off-by: Ken Xue <ken@amd.com>
Signed-off-by: Xiangliang Yu <xiangliang...@amd.com>
---
 drivers/i2c/busses/i2c-designware-platdrv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 9ee1fc6..c8acbff 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -125,7 +125,7 @@ static const struct acpi_device_id dw_i2c_acpi_match[] = {
{ "INT3433", 0 },
{ "80860F41", 0 },
{ "808622C1", 0 },
-   { "AMD0010", 133 * 1000 * 1000 },
+   { "AMD0010", 0 },
{ }
 };
 MODULE_DEVICE_TABLE(acpi, dw_i2c_acpi_match);
-- 
1.9.1



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] i2c: designware: register clkdev during acpi device configuration

2015-10-20 Thread Ken Xue
On Tue, 2015-10-20 at 14:17 +0300, Mika Westerberg wrote:
> On Tue, Oct 20, 2015 at 02:38:01PM +0800, Ken Xue wrote:
> > DW I2C driver tries to register a clk from id->driver_data as an
> > alternative way besides intel lpss. But code doesn't register the
> > clk to clkdev. So, devm_clk_get will fail during probe.
> > 
> > The patch can fix this issue.
> 
> Since you now have drivers/acpi/acpi_apd.c for AMD ACPI stuff, can you
> create the clock there just like we do for Intel stuff?
Sure. APD already creates the clock for AMD0010 as you expected. And the
next patch([PATCH 2/2] i2c: designware: remove freq definition for
"AMD0010" in acpi_device_id) is dropping the old way for getting freq.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V4] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-05 Thread Ken Xue
>From 1a6a3a5c0815cb1f52ec0a2b9601edfa9bfebe81 Mon Sep 17 00:00:00 2001
From: Ken Xue 
Date: Fri, 6 Feb 2015 08:27:51 +0800
Subject: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

This new feature is to interpret AMD specific ACPI device to
platform device such as I2C, UART, GPIO found on AMD CZ and
later chipsets. It based on example intel LPSS. Now, it can
support AMD I2C, UART and GPIO.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig|  11 
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 150 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..3e15cee 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART, GPIO found on AMD Carrizo and later chipsets.
+ I2C and UART depend on COMMON_CLK to set clock. GPIO driver is
+ implemented under PINCTRL subsystem.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..3984ea9
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,150 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_apd");
+struct apd_private_data;
+
+/**
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * Device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   const struct apd_device_desc *dev_desc;
+};
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   pdata->clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+/**
+* Create platform device during acpi scan attach handle.
+* Return value > 0 on success of crea

[PATCH V4] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-05 Thread Ken Xue
From 1a6a3a5c0815cb1f52ec0a2b9601edfa9bfebe81 Mon Sep 17 00:00:00 2001
From: Ken Xue ken@amd.com
Date: Fri, 6 Feb 2015 08:27:51 +0800
Subject: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

This new feature is to interpret AMD specific ACPI device to
platform device such as I2C, UART, GPIO found on AMD CZ and
later chipsets. It based on example intel LPSS. Now, it can
support AMD I2C, UART and GPIO.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig|  11 
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 150 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..3e15cee 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART, GPIO found on AMD Carrizo and later chipsets.
+ I2C and UART depend on COMMON_CLK to set clock. GPIO driver is
+ implemented under PINCTRL subsystem.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..3984ea9
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,150 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk-provider.h
+#include linux/platform_device.h
+#include linux/pm_domain.h
+#include linux/clkdev.h
+#include linux/acpi.h
+#include linux/err.h
+#include linux/clk.h
+#include linux/pm.h
+
+#include internal.h
+
+ACPI_MODULE_NAME(acpi_apd);
+struct apd_private_data;
+
+/**
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * Device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   const struct apd_device_desc *dev_desc;
+};
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   pdata-clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE

[PATCH V4] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-04 Thread Ken Xue
>From d22789f089ee644413a144633f368f45cb0ac9d8 Mon Sep 17 00:00:00 2001
From: Ken Xue 
Date: Thu, 5 Feb 2015 11:04:44 +0800
Subject: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

This new feature is to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later chipsets. It
based on example intel LPSS. Now, it can support AMD I2C & UART.
---
 arch/x86/Kconfig|  11 
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 150 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..3e15cee 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART, GPIO found on AMD Carrizo and later chipsets.
+ I2C and UART depend on COMMON_CLK to set clock. GPIO driver is
+ implemented under PINCTRL subsystem.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..3984ea9
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,150 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_apd");
+struct apd_private_data;
+
+/**
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * Device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   const struct apd_device_desc *dev_desc;
+};
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   pdata->clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+/**
+* Create platform device during acpi scan attach handle.
+* Return value > 0 on success of creating device.
+*/
+static int acpi_apd_create_

[PATCH V4] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-04 Thread Ken Xue
From d22789f089ee644413a144633f368f45cb0ac9d8 Mon Sep 17 00:00:00 2001
From: Ken Xue ken@amd.com
Date: Thu, 5 Feb 2015 11:04:44 +0800
Subject: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

This new feature is to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later chipsets. It
based on example intel LPSS. Now, it can support AMD I2C  UART.
---
 arch/x86/Kconfig|  11 
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 150 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 165 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..3e15cee 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART, GPIO found on AMD Carrizo and later chipsets.
+ I2C and UART depend on COMMON_CLK to set clock. GPIO driver is
+ implemented under PINCTRL subsystem.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..3984ea9
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,150 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk-provider.h
+#include linux/platform_device.h
+#include linux/pm_domain.h
+#include linux/clkdev.h
+#include linux/acpi.h
+#include linux/err.h
+#include linux/clk.h
+#include linux/pm.h
+
+#include internal.h
+
+ACPI_MODULE_NAME(acpi_apd);
+struct apd_private_data;
+
+/**
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like %ACPI_APD_SYSFS, %ACPI_APD_PM
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * Device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   const struct apd_device_desc *dev_desc;
+};
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   pdata-clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+/**
+* Create platform device during acpi scan attach handle

Re: [PATCH V3] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-03 Thread Ken Xue
On Tue, 2015-02-03 at 23:07 +0100, Rafael J. Wysocki wrote:
> On Tuesday, February 03, 2015 12:06:06 PM Andy Shevchenko wrote:
> > On Tue, Feb 3, 2015 at 3:54 AM, Ken Xue  wrote:
> > > This new feature is to interpret AMD specific ACPI device to
> > > platform device such as I2C, UART found on AMD CZ and later chipsets. It
> > > based on example intel LPSS. Now, it can support AMD I2C & UART.
> > >
> > 
> > Few minor things below.
> > Be free to fix in depend on what Mika and Rafael confirm.
> > 
> > Anyway,
> > Reviewed-by: Andy Shevchenko 
> 
> Thanks Andy!
> 
> Ken, please address the Andy's comments given below, they all make sense to 
> me.
> 
Thanks for all your comments.

> > > Signed-off-by: Ken Xue 
> > > ---
> > >  arch/x86/Kconfig|  11 +++
> > >  drivers/acpi/Makefile   |   2 +-
> > >  drivers/acpi/acpi_apd.c | 201 
> > > 
> > >  drivers/acpi/internal.h |   2 +
> > >  drivers/acpi/scan.c |   1 +
> > >  5 files changed, 216 insertions(+), 1 deletion(-)
> > >  create mode 100644 drivers/acpi/acpi_apd.c
> > >
> > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> > > index 0dc9d01..ddf8d42 100644
> > > --- a/arch/x86/Kconfig
> > > +++ b/arch/x86/Kconfig
> > > @@ -496,6 +496,17 @@ config X86_INTEL_LPSS
> > >   things like clock tree (common clock framework) and pincontrol
> > >   which are needed by the LPSS peripheral drivers.
> > >
> > > +config X86_AMD_PLATFORM_DEVICE
> > > +   bool "AMD ACPI2Platform devices support"
> > > +   depends on ACPI
> > > +   select COMMON_CLK
> > > +   select PINCTRL
> > > +   ---help---
> > > + Select to interpret AMD specific ACPI device to platform device
> > > + such as I2C, UART found on AMD Carrizo and later chipsets. 
> > > Selecting
> > > + this option enables things like clock tree (common clock 
> > > framework)
> > > + and pinctrl.
> > 
> > Sounds 'like' is redundant here. It explicitly enables common clock
> > and pin control frameworks.
> > 
I just copy the last sentence from description of X86_INTEL_LPSS. but it
is OK, i will remove it from next release.

> > > +
> > >  config IOSF_MBI
> > > tristate "Intel SoC IOSF Sideband support for SoC platforms"
> > > depends on PCI
> > > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> > > index f74317c..0071141 100644
> > > --- a/drivers/acpi/Makefile
> > > +++ b/drivers/acpi/Makefile
> > > @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += 
> > > processor_pdc.o
> > >  acpi-y += ec.o
> > >  acpi-$(CONFIG_ACPI_DOCK)   += dock.o
> > >  acpi-y += pci_root.o pci_link.o pci_irq.o
> > > -acpi-y += acpi_lpss.o
> > > +acpi-y         += acpi_lpss.o acpi_apd.o
> > >  acpi-y += acpi_platform.o
> > >  acpi-y += acpi_pnp.o
> > >  acpi-y += int340x_thermal.o
> > > diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
> > > new file mode 100644
> > > index 000..b27bc1c
> > > --- /dev/null
> > > +++ b/drivers/acpi/acpi_apd.c
> > > @@ -0,0 +1,201 @@
> > > +/*
> > > + * AMD ACPI support for ACPI2platform device.
> > > + *
> > > + * Copyright (c) 2014,2015 AMD Corporation.
> > > + * Authors: Ken Xue 
> > > + * Wu, Jeff 
> > > + *
> > > + * This program is free software; you can redistribute it and/or modify
> > > + * it under the terms of the GNU General Public License version 2 as
> > > + * published by the Free Software Foundation.
> > > + */
> > > +
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +#include 
> > > +
> > > +#include "internal.h"
> > > +
> > > +ACPI_MODULE_NAME("acpi_apd");
> > > +struct apd_private_data;
> > > +
> > > +/**
> > 
> > /*, or use description on per flag basis.
> > 
OK.

> > > + * device flags of acpi_apd_dev_desc.
> > > + * ACPI_APD_SYSFS : 

Re: [PATCH V2] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-03 Thread Ken Xue
On Tue, 2015-02-03 at 11:53 +0200, mika.westerb...@linux.intel.com
wrote:
> On Tue, Feb 03, 2015 at 09:04:55AM +0800, Ken Xue wrote:
> > as you said, platform_drv_probe calls dev_pm_domain_attach(). but
> > platform_drv_probe just is a default probe routine. Not all platform
> > device drivers use this probe routine. so, codes here may be still
> > necessary.
> 
> Are you saying that for platform devices there is some other path to get
> a driver probed, other than platform_drv_probe()? Can you point me to
> it?
>From the codes, i can see there is a possibility that drv->driver.probe
may not be set in __platform_driver_register. But i really can not point
out a use case that platform device driver without probe.
so, it is safe to remove "dev_pm_domain_attach" in
"acpi_apd_platform_notify". right?

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH V3] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-03 Thread Ken Xue
On Tue, 2015-02-03 at 23:07 +0100, Rafael J. Wysocki wrote:
 On Tuesday, February 03, 2015 12:06:06 PM Andy Shevchenko wrote:
  On Tue, Feb 3, 2015 at 3:54 AM, Ken Xue ken@amd.com wrote:
   This new feature is to interpret AMD specific ACPI device to
   platform device such as I2C, UART found on AMD CZ and later chipsets. It
   based on example intel LPSS. Now, it can support AMD I2C  UART.
  
  
  Few minor things below.
  Be free to fix in depend on what Mika and Rafael confirm.
  
  Anyway,
  Reviewed-by: Andy Shevchenko andy.shevche...@gmail.com
 
 Thanks Andy!
 
 Ken, please address the Andy's comments given below, they all make sense to 
 me.
 
Thanks for all your comments.

   Signed-off-by: Ken Xue ken@amd.com
   ---
arch/x86/Kconfig|  11 +++
drivers/acpi/Makefile   |   2 +-
drivers/acpi/acpi_apd.c | 201 
   
drivers/acpi/internal.h |   2 +
drivers/acpi/scan.c |   1 +
5 files changed, 216 insertions(+), 1 deletion(-)
create mode 100644 drivers/acpi/acpi_apd.c
  
   diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
   index 0dc9d01..ddf8d42 100644
   --- a/arch/x86/Kconfig
   +++ b/arch/x86/Kconfig
   @@ -496,6 +496,17 @@ config X86_INTEL_LPSS
 things like clock tree (common clock framework) and pincontrol
 which are needed by the LPSS peripheral drivers.
  
   +config X86_AMD_PLATFORM_DEVICE
   +   bool AMD ACPI2Platform devices support
   +   depends on ACPI
   +   select COMMON_CLK
   +   select PINCTRL
   +   ---help---
   + Select to interpret AMD specific ACPI device to platform device
   + such as I2C, UART found on AMD Carrizo and later chipsets. 
   Selecting
   + this option enables things like clock tree (common clock 
   framework)
   + and pinctrl.
  
  Sounds 'like' is redundant here. It explicitly enables common clock
  and pin control frameworks.
  
I just copy the last sentence from description of X86_INTEL_LPSS. but it
is OK, i will remove it from next release.

   +
config IOSF_MBI
   tristate Intel SoC IOSF Sideband support for SoC platforms
   depends on PCI
   diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
   index f74317c..0071141 100644
   --- a/drivers/acpi/Makefile
   +++ b/drivers/acpi/Makefile
   @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += 
   processor_pdc.o
acpi-y += ec.o
acpi-$(CONFIG_ACPI_DOCK)   += dock.o
acpi-y += pci_root.o pci_link.o pci_irq.o
   -acpi-y += acpi_lpss.o
   +acpi-y += acpi_lpss.o acpi_apd.o
acpi-y += acpi_platform.o
acpi-y += acpi_pnp.o
acpi-y += int340x_thermal.o
   diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
   new file mode 100644
   index 000..b27bc1c
   --- /dev/null
   +++ b/drivers/acpi/acpi_apd.c
   @@ -0,0 +1,201 @@
   +/*
   + * AMD ACPI support for ACPI2platform device.
   + *
   + * Copyright (c) 2014,2015 AMD Corporation.
   + * Authors: Ken Xue ken@amd.com
   + * Wu, Jeff jeff...@amd.com
   + *
   + * This program is free software; you can redistribute it and/or modify
   + * it under the terms of the GNU General Public License version 2 as
   + * published by the Free Software Foundation.
   + */
   +
   +#include linux/clk-provider.h
   +#include linux/platform_device.h
   +#include linux/pm_domain.h
   +#include linux/clkdev.h
   +#include linux/acpi.h
   +#include linux/err.h
   +#include linux/clk.h
   +#include linux/pm.h
   +
   +#include internal.h
   +
   +ACPI_MODULE_NAME(acpi_apd);
   +struct apd_private_data;
   +
   +/**
  
  /*, or use description on per flag basis.
  
OK.

   + * device flags of acpi_apd_dev_desc.
   + * ACPI_APD_SYSFS : add device attributes in sysfs
   + * ACPI_APD_PM : attach power domain to device
   + * ACPI_APD_PM_ON : power on device when attach power domain
   + */
   +#define ACPI_APD_SYSFS BIT(0)
   +#define ACPI_APD_PMBIT(1)
   +#define ACPI_APD_PM_ON BIT(2)
   +
   +/**
   + * struct apd_device_desc - a descriptor for apd device
   + * @flags: device flags like ACPI_APD_SYSFS ACPI_APD_PM ACPI_APD_PM_ON
  
  %ACPI_APD_SYSFS, %ACPI_APD_PM, %ACPI_APD_APM_ON.
  
  Could it be combination? State this explicitly.
  
OK.

   + * @fixed_clk_rate: fixed rate input clock source for acpi device;
   + * 0 means no fixed rate input clock source
   + * @setup: a hook routine to set device resource during create platform 
   device
   + *
   + * device description defined as acpi_device_id.driver_data
  
  d - D
  
OK.

   + */
   +struct apd_device_desc {
   +   unsigned int flags;
   +   unsigned int fixed_clk_rate;
   +   int (*setup)(struct apd_private_data *pdata);
   +};
   +
   +struct apd_private_data {
   +   struct clk

Re: [PATCH V2] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-03 Thread Ken Xue
On Tue, 2015-02-03 at 11:53 +0200, mika.westerb...@linux.intel.com
wrote:
 On Tue, Feb 03, 2015 at 09:04:55AM +0800, Ken Xue wrote:
  as you said, platform_drv_probe calls dev_pm_domain_attach(). but
  platform_drv_probe just is a default probe routine. Not all platform
  device drivers use this probe routine. so, codes here may be still
  necessary.
 
 Are you saying that for platform devices there is some other path to get
 a driver probed, other than platform_drv_probe()? Can you point me to
 it?
From the codes, i can see there is a possibility that drv-driver.probe
may not be set in __platform_driver_register. But i really can not point
out a use case that platform device driver without probe.
so, it is safe to remove dev_pm_domain_attach in
acpi_apd_platform_notify. right?

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V3] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-02 Thread Ken Xue
This new feature is to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later chipsets. It
based on example intel LPSS. Now, it can support AMD I2C & UART.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 201 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..ddf8d42 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..b27bc1c
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,201 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_apd");
+struct apd_private_data;
+
+/**
+ * device flags of acpi_apd_dev_desc.
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ * ACPI_APD_PM_ON : power on device when attach power domain
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+#define ACPI_APD_PM_ON BIT(2)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like ACPI_APD_SYSFS ACPI_APD_PM ACPI_APD_PM_ON
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   const struct apd_device_desc *dev_desc;
+};
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   pdata->clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static int acpi_apd_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   const struct apd_device_desc *dev_desc;
+   struct apd_

Re: [PATCH V2] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-02 Thread Ken Xue
On Mon, 2015-02-02 at 15:03 +0200, mika.westerb...@linux.intel.com
wrote:
> On Mon, Feb 02, 2015 at 05:50:52PM +0800, Ken Xue wrote:
> > >From b9654ecbfaebde00aee746a024eec9fe8de24b97 Mon Sep 17 00:00:00 2001
> > From: Ken Xue 
> > Date: Mon, 2 Feb 2015 17:32:24 +0800
> > Subject: [PATCH] This new feature is to interpret AMD specific ACPI device 
> > to
> >  platform device such as I2C, UART found on AMD CZ and later chipsets. It
> >  based on example INTEL LPSS. Now, it can support AMD I2C & UART.
> 
> Looks good to me. There are few smallish issues still, see below.
> 
...

> > +   switch (action) {
> > +   case BUS_NOTIFY_ADD_DEVICE:
> > +   if (pdata->dev_desc->flags & ACPI_APD_PM) {
> > +   if (pdata->dev_desc->flags & ACPI_APD_PM_ON)
> > +   ret = dev_pm_domain_attach(>dev, true);
> > +   else
> > +   ret = dev_pm_domain_attach(>dev, false);
> 
> How about:
> 
>   power_on = !!(pdata->dev_desc->flags & ACPI_APD_PM_ON)
>   ret = dev_pm_domain_attach(>dev, power_on);
> 
> ?
good 

> 
> Furthermore I think this is not needed at all. If you check
> platform_drv_probe() it calls dev_pm_domain_attach() already.
> 
as you said, platform_drv_probe calls dev_pm_domain_attach(). but
platform_drv_probe just is a default probe routine. Not all platform
device drivers use this probe routine. so, codes here may be still
necessary.



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-02 Thread Ken Xue
>From b9654ecbfaebde00aee746a024eec9fe8de24b97 Mon Sep 17 00:00:00 2001
From: Ken Xue 
Date: Mon, 2 Feb 2015 17:32:24 +0800
Subject: [PATCH] This new feature is to interpret AMD specific ACPI device to
 platform device such as I2C, UART found on AMD CZ and later chipsets. It
 based on example INTEL LPSS. Now, it can support AMD I2C & UART.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 208 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..ddf8d42 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..b875ef6
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,208 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+
+ACPI_MODULE_NAME("acpi_apd");
+struct apd_private_data;
+
+/**
+ * device flags of acpi_apd_dev_desc.
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ * ACPI_APD_PM_ON : power on device when attach power domain
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+#define ACPI_APD_PM_ON BIT(2)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like ACPI_APD_SYSFS ACPI_APD_PM ACPI_APD_PM_ON
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   struct apd_device_desc *dev_desc;
+};
+
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   struct apd_device_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   pdata->clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static int acpi_apd_create_device(struct acpi_device *adev,
+   

Re: [PATCH V2] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-02 Thread Ken Xue
On Mon, 2015-02-02 at 15:03 +0200, mika.westerb...@linux.intel.com
wrote:
 On Mon, Feb 02, 2015 at 05:50:52PM +0800, Ken Xue wrote:
  From b9654ecbfaebde00aee746a024eec9fe8de24b97 Mon Sep 17 00:00:00 2001
  From: Ken Xue ken@amd.com
  Date: Mon, 2 Feb 2015 17:32:24 +0800
  Subject: [PATCH] This new feature is to interpret AMD specific ACPI device 
  to
   platform device such as I2C, UART found on AMD CZ and later chipsets. It
   based on example INTEL LPSS. Now, it can support AMD I2C  UART.
 
 Looks good to me. There are few smallish issues still, see below.
 
...

  +   switch (action) {
  +   case BUS_NOTIFY_ADD_DEVICE:
  +   if (pdata-dev_desc-flags  ACPI_APD_PM) {
  +   if (pdata-dev_desc-flags  ACPI_APD_PM_ON)
  +   ret = dev_pm_domain_attach(pdev-dev, true);
  +   else
  +   ret = dev_pm_domain_attach(pdev-dev, false);
 
 How about:
 
   power_on = !!(pdata-dev_desc-flags  ACPI_APD_PM_ON)
   ret = dev_pm_domain_attach(pdev-dev, power_on);
 
 ?
good 

 
 Furthermore I think this is not needed at all. If you check
 platform_drv_probe() it calls dev_pm_domain_attach() already.
 
as you said, platform_drv_probe calls dev_pm_domain_attach(). but
platform_drv_probe just is a default probe routine. Not all platform
device drivers use this probe routine. so, codes here may be still
necessary.



--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH V2] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-02 Thread Ken Xue
From b9654ecbfaebde00aee746a024eec9fe8de24b97 Mon Sep 17 00:00:00 2001
From: Ken Xue ken@amd.com
Date: Mon, 2 Feb 2015 17:32:24 +0800
Subject: [PATCH] This new feature is to interpret AMD specific ACPI device to
 platform device such as I2C, UART found on AMD CZ and later chipsets. It
 based on example INTEL LPSS. Now, it can support AMD I2C  UART.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 208 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..ddf8d42 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..b875ef6
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,208 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include linux/clk-provider.h
+#include linux/platform_device.h
+#include linux/pm_domain.h
+#include linux/clkdev.h
+#include linux/acpi.h
+#include linux/err.h
+#include linux/clk.h
+#include linux/pm.h
+
+#include internal.h
+
+
+ACPI_MODULE_NAME(acpi_apd);
+struct apd_private_data;
+
+/**
+ * device flags of acpi_apd_dev_desc.
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ * ACPI_APD_PM_ON : power on device when attach power domain
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+#define ACPI_APD_PM_ON BIT(2)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like ACPI_APD_SYSFS ACPI_APD_PM ACPI_APD_PM_ON
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   struct apd_device_desc *dev_desc;
+};
+
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   struct apd_device_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   pdata-clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif

[PATCH V3] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2015-02-02 Thread Ken Xue
This new feature is to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later chipsets. It
based on example intel LPSS. Now, it can support AMD I2C  UART.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 201 
 drivers/acpi/internal.h |   2 +
 drivers/acpi/scan.c |   1 +
 5 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 0dc9d01..ddf8d42 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -496,6 +496,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..0071141 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..b27bc1c
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,201 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014,2015 AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk-provider.h
+#include linux/platform_device.h
+#include linux/pm_domain.h
+#include linux/clkdev.h
+#include linux/acpi.h
+#include linux/err.h
+#include linux/clk.h
+#include linux/pm.h
+
+#include internal.h
+
+ACPI_MODULE_NAME(acpi_apd);
+struct apd_private_data;
+
+/**
+ * device flags of acpi_apd_dev_desc.
+ * ACPI_APD_SYSFS : add device attributes in sysfs
+ * ACPI_APD_PM : attach power domain to device
+ * ACPI_APD_PM_ON : power on device when attach power domain
+ */
+#define ACPI_APD_SYSFS BIT(0)
+#define ACPI_APD_PMBIT(1)
+#define ACPI_APD_PM_ON BIT(2)
+
+/**
+ * struct apd_device_desc - a descriptor for apd device
+ * @flags: device flags like ACPI_APD_SYSFS ACPI_APD_PM ACPI_APD_PM_ON
+ * @fixed_clk_rate: fixed rate input clock source for acpi device;
+ * 0 means no fixed rate input clock source
+ * @setup: a hook routine to set device resource during create platform device
+ *
+ * device description defined as acpi_device_id.driver_data
+ */
+struct apd_device_desc {
+   unsigned int flags;
+   unsigned int fixed_clk_rate;
+   int (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   struct clk *clk;
+   struct acpi_device *adev;
+   const struct apd_device_desc *dev_desc;
+};
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   pdata-clk = clk;
+   }
+
+   return 0;
+}
+
+static struct apd_device_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct apd_device_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static int acpi_apd_create_device(struct acpi_device *adev,
+  const struct

[PATCH 3/3 V2] acpi:lpss:Refine LPSS codes to fit ACPI SOC.

2014-12-18 Thread Ken Xue
ACPI SOC provides common codes to 1)create platform device from ACPI
2)and handle platform bus notification. These common codes can be
used by LPSS with this patch.

Signed-off-by: Ken Xue 
---
 drivers/acpi/acpi_lpss.c | 604 ---
 1 file changed, 251 insertions(+), 353 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 4f3febf..993a772 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -10,7 +10,6 @@
  * published by the Free Software Foundation.
  */
 
-#include 
 #include 
 #include 
 #include 
@@ -21,10 +20,14 @@
 #include 
 #include 
 
+#include "acpi_soc.h"
 #include "internal.h"
 
 ACPI_MODULE_NAME("acpi_lpss");
 
+static struct acpi_soc a_soc;
+static struct device *proxy_device;
+
 #ifdef CONFIG_X86_INTEL_LPSS
 
 #define LPSS_ADDR(desc) ((unsigned long))
@@ -56,178 +59,77 @@ ACPI_MODULE_NAME("acpi_lpss");
 
 /* LPSS Flags */
 #define LPSS_CLK   BIT(0)
-#define LPSS_CLK_GATE  BIT(1)
-#define LPSS_CLK_DIVIDER   BIT(2)
+#define LPSS_CLK_GATE  BIT(1)
+#define LPSS_CLK_DIVIDER   BIT(2)
 #define LPSS_LTR   BIT(3)
-#define LPSS_SAVE_CTX  BIT(4)
-#define LPSS_DEV_PROXY BIT(5)
-#define LPSS_PROXY_REQ BIT(6)
-
-struct lpss_private_data;
-
-struct lpss_device_desc {
-   unsigned int flags;
-   unsigned int prv_offset;
-   size_t prv_size_override;
-   void (*setup)(struct lpss_private_data *pdata);
-};
-
-static struct device *proxy_device;
-
-static struct lpss_device_desc lpss_dma_desc = {
-   .flags = LPSS_CLK | LPSS_PROXY_REQ,
-};
-
-struct lpss_private_data {
-   void __iomem *mmio_base;
-   resource_size_t mmio_size;
-   unsigned int fixed_clk_rate;
-   struct clk *clk;
-   const struct lpss_device_desc *dev_desc;
-   u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
-};
+#define LPSS_SAVE_CTX  BIT(4)
+#define LPSS_DEV_PROXY BIT(5)
+#define LPSS_PROXY_REQ BIT(6)
 
 /* UART Component Parameter Register */
 #define LPSS_UART_CPR  0xF4
 #define LPSS_UART_CPR_AFCE BIT(4)
 
-static void lpss_uart_setup(struct lpss_private_data *pdata)
+static u32 __lpss_reg_read(struct acpi_soc_dev_private_data *pdata,
+   unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
-   val = readl(pdata->mmio_base + offset);
-   writel(val | LPSS_TX_INT_MASK, pdata->mmio_base + offset);
-
-   val = readl(pdata->mmio_base + LPSS_UART_CPR);
-   if (!(val & LPSS_UART_CPR_AFCE)) {
-   offset = pdata->dev_desc->prv_offset + LPSS_GENERAL;
-   val = readl(pdata->mmio_base + offset);
-   val |= LPSS_GENERAL_UART_RTS_OVRD;
-   writel(val, pdata->mmio_base + offset);
-   }
+   return readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
 }
 
-static void byt_i2c_setup(struct lpss_private_data *pdata)
+static void __lpss_reg_write(u32 val, struct acpi_soc_dev_private_data *pdata,
+unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata->dev_desc->prv_offset + LPSS_RESETS;
-   val = readl(pdata->mmio_base + offset);
-   val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
-   writel(val, pdata->mmio_base + offset);
-
-   if (readl(pdata->mmio_base + pdata->dev_desc->prv_offset))
-   pdata->fixed_clk_rate = 13300;
+   writel(val, pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
 }
 
-static struct lpss_device_desc lpt_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_i2c_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc lpt_sdio_dev_desc = {
-   .flags = LPSS_LTR,
-   .prv_offset = 0x1000,
-   .prv_size_override = 0x1018,
-};
-
-static struct lpss_device_desc byt_pwm_dev_desc = {
-   .flags = LPSS_SAVE_CTX,
-};
-
-static struct lpss_device_desc byt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX |
-LPSS_DEV_PROXY,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc byt_spi_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX |
-LPSS_DEV_PROXY,
-   .prv_offset = 0x400,
-};
-
-stat

[PATCH 2/3 V3] acpi:apd:add AMD ACPI2Platform device support

2014-12-18 Thread Ken Xue
This is a new feature to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later
chipsets. It based on ACPI SOC.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig| 11 
 drivers/acpi/Makefile   |  2 +-
 drivers/acpi/acpi_apd.c | 71 +
 drivers/acpi/internal.h |  2 ++
 drivers/acpi/scan.c |  1 +
 5 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index bea3a015..d189864 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -499,6 +499,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 66c7457..1eef7f0 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_soc.o acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..78ba028
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,71 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+
+#include "acpi_soc.h"
+#include "internal.h"
+
+static struct acpi_soc a_soc;
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   }
+
+   return 0;
+}
+
+static struct acpi_soc_dev_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct acpi_soc_dev_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { "AMD0010", APD_ADDR(cz_i2c_desc) },
+   { "AMD0020", APD_ADDR(cz_uart_desc) },
+   { }
+};
+
+void __init acpi_apd_init(void)
+{
+   a_soc.ids = acpi_apd_device_ids;
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+   register_acpi_soc(_soc, false);
+#else
+   register_acpi_soc(_soc, true);
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 163e82f..c24ae9d 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -68,6 +68,8 @@ static inline void acpi_debugfs_init(void) { return; }
 #endif
 void acpi_lpss_init(void);
 
+void acpi_apd_init(void);
+
 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
 bool acpi_queue_hotplug_work(struct work_struct *work);
 void acpi_device_hotplug(struct acpi_device *adev, u32 src);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 1b1cf55..ced689d 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2541,6 +2541,7 @@ int __init acpi_scan_init(void)
acpi_pci_link_init();
acpi_processor_init();
acpi_lpss_init();
+   acpi_apd_init();
acpi_cmos_rtc_init();
acpi_container_init();
a

[PATCH 1/3 V3] acpi:soc: merge common codes for creating platform device

2014-12-18 Thread Ken Xue

This patch is supposed to deliver some common codes for AMD APD and
intel LPSS. It can help to convert some specific acpi devices to be
platform devices.

Signed-off-by: Ken Xue 
---
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_soc.c | 228 
 drivers/acpi/acpi_soc.h | 104 ++
 3 files changed, 333 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_soc.c
 create mode 100644 drivers/acpi/acpi_soc.h

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..66c7457 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
new file mode 100644
index 000..2abbac9
--- /dev/null
+++ b/drivers/acpi/acpi_soc.c
@@ -0,0 +1,228 @@
+/*
+ * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
+ *
+ * Copyright (C) 2013, 2014, Intel Corporation
+ * Copyright (C) 2014, AMD Corporation
+ * Authors: Ken Xue 
+ * Mika Westerberg 
+ * Rafael J. Wysocki 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "acpi_soc.h"
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_soc");
+
+/* A list for all ACPI SOC device */
+static LIST_HEAD(a_soc_list);
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, );
+}
+
+static int acpi_soc_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct acpi_soc_dev_private_data *pdata;
+   struct acpi_soc_dev_desc *dev_desc;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct acpi_soc_dev_desc *)id->driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(adev);
+   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
+   }
+   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(_list);
+   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
+   if (ret < 0)
+   goto err_out;
+
+   list_for_each_entry(rentry, _list, node)
+   if (resource_type(>res) == IORESOURCE_MEM) {
+   if (dev_desc->mem_size_override)
+   pdata->mmio_size = dev_desc->mem_size_override;
+   else
+   pdata->mmio_size = resource_size(>res);
+   pdata->mmio_base = ioremap(rentry->res.start,
+  pdata->mmio_size);
+   break;
+   }
+
+   acpi_dev_free_resource_list(_list);
+
+   pdata->adev = adev;
+   pdata->dev_desc = dev_desc;
+
+   if (dev_desc->setup) {
+   ret = dev_desc->setup(pdata);
+   if (ret)
+   goto err_out;
+   }
+
+   /*
+* This works around a known issue in ACPI tables where ACPI SOC devices
+* have _PS0 and _PS3 without _PSC (and no power resources), so
+* acpi_bus_init_power() will assume that the BIOS has put them into D0.
+*/
+   ret = acpi_device_fix_up_power(adev);
+   if (ret) {
+   /* Skip the device, but continue the namespace scan. */
+   ret = 0;
+   goto err_out;
+   }
+
+   adev->driver_data = pdata;
+   pdev = acpi_create_platform_device(adev);
+   if (!IS_ERR_OR_NULL(pdev)) {
+   pdata->pdev = pdev;
+   if (dev_desc->post_setup) {
+   ret = dev_desc->post_setup(pdata);
+   if (ret)
+   goto err_out;
+   }
+   return 1;
+   }
+
+   ret = PTR_ERR(pdev);
+   adev->driver_data = NULL;
+
+ err_out:
+   kfree(pdata);
+   return ret;
+}
+
+static int acpi_soc_platform_notify(struct notifier_block *nb,
+unsigned long action, void *data)
+{
+   struct platform_device *pdev = to_pl

[PATCH 1/3 V3] acpi:soc: merge common codes for creating platform device

2014-12-18 Thread Ken Xue

This patch is supposed to deliver some common codes for AMD APD and
intel LPSS. It can help to convert some specific acpi devices to be
platform devices.

Signed-off-by: Ken Xue ken@amd.com
---
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_soc.c | 228 
 drivers/acpi/acpi_soc.h | 104 ++
 3 files changed, 333 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_soc.c
 create mode 100644 drivers/acpi/acpi_soc.h

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index f74317c..66c7457 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
new file mode 100644
index 000..2abbac9
--- /dev/null
+++ b/drivers/acpi/acpi_soc.c
@@ -0,0 +1,228 @@
+/*
+ * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
+ *
+ * Copyright (C) 2013, 2014, Intel Corporation
+ * Copyright (C) 2014, AMD Corporation
+ * Authors: Ken Xue ken@amd.com
+ * Mika Westerberg mika.westerb...@linux.intel.com
+ * Rafael J. Wysocki rafael.j.wyso...@intel.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/err.h
+#include linux/list.h
+#include linux/pm_domain.h
+#include linux/platform_device.h
+
+#include acpi_soc.h
+#include internal.h
+
+ACPI_MODULE_NAME(acpi_soc);
+
+/* A list for all ACPI SOC device */
+static LIST_HEAD(a_soc_list);
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, r);
+}
+
+static int acpi_soc_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct acpi_soc_dev_private_data *pdata;
+   struct acpi_soc_dev_desc *dev_desc;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct acpi_soc_dev_desc *)id-driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(adev);
+   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
+   }
+   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(resource_list);
+   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
+   if (ret  0)
+   goto err_out;
+
+   list_for_each_entry(rentry, resource_list, node)
+   if (resource_type(rentry-res) == IORESOURCE_MEM) {
+   if (dev_desc-mem_size_override)
+   pdata-mmio_size = dev_desc-mem_size_override;
+   else
+   pdata-mmio_size = resource_size(rentry-res);
+   pdata-mmio_base = ioremap(rentry-res.start,
+  pdata-mmio_size);
+   break;
+   }
+
+   acpi_dev_free_resource_list(resource_list);
+
+   pdata-adev = adev;
+   pdata-dev_desc = dev_desc;
+
+   if (dev_desc-setup) {
+   ret = dev_desc-setup(pdata);
+   if (ret)
+   goto err_out;
+   }
+
+   /*
+* This works around a known issue in ACPI tables where ACPI SOC devices
+* have _PS0 and _PS3 without _PSC (and no power resources), so
+* acpi_bus_init_power() will assume that the BIOS has put them into D0.
+*/
+   ret = acpi_device_fix_up_power(adev);
+   if (ret) {
+   /* Skip the device, but continue the namespace scan. */
+   ret = 0;
+   goto err_out;
+   }
+
+   adev-driver_data = pdata;
+   pdev = acpi_create_platform_device(adev);
+   if (!IS_ERR_OR_NULL(pdev)) {
+   pdata-pdev = pdev;
+   if (dev_desc-post_setup) {
+   ret = dev_desc-post_setup(pdata);
+   if (ret)
+   goto err_out;
+   }
+   return 1;
+   }
+
+   ret = PTR_ERR(pdev);
+   adev-driver_data = NULL;
+
+ err_out:
+   kfree(pdata);
+   return ret;
+}
+
+static int acpi_soc_platform_notify(struct notifier_block *nb,
+unsigned long

[PATCH 2/3 V3] acpi:apd:add AMD ACPI2Platform device support

2014-12-18 Thread Ken Xue
This is a new feature to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later
chipsets. It based on ACPI SOC.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig| 11 
 drivers/acpi/Makefile   |  2 +-
 drivers/acpi/acpi_apd.c | 71 +
 drivers/acpi/internal.h |  2 ++
 drivers/acpi/scan.c |  1 +
 5 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index bea3a015..d189864 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -499,6 +499,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 66c7457..1eef7f0 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_soc.o acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..78ba028
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,71 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include linux/clkdev.h
+#include linux/clk-provider.h
+#include linux/err.h
+
+#include acpi_soc.h
+#include internal.h
+
+static struct acpi_soc a_soc;
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   }
+
+   return 0;
+}
+
+static struct acpi_soc_dev_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct acpi_soc_dev_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { AMD0010, APD_ADDR(cz_i2c_desc) },
+   { AMD0020, APD_ADDR(cz_uart_desc) },
+   { }
+};
+
+void __init acpi_apd_init(void)
+{
+   a_soc.ids = acpi_apd_device_ids;
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+   register_acpi_soc(a_soc, false);
+#else
+   register_acpi_soc(a_soc, true);
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 163e82f..c24ae9d 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -68,6 +68,8 @@ static inline void acpi_debugfs_init(void) { return; }
 #endif
 void acpi_lpss_init(void);
 
+void acpi_apd_init(void);
+
 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
 bool acpi_queue_hotplug_work(struct work_struct *work);
 void acpi_device_hotplug(struct acpi_device *adev, u32 src);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 1b1cf55..ced689d 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2541,6 +2541,7 @@ int __init acpi_scan_init(void)
acpi_pci_link_init();
acpi_processor_init();
acpi_lpss_init();
+   acpi_apd_init();
acpi_cmos_rtc_init();
acpi_container_init

[PATCH 3/3 V2] acpi:lpss:Refine LPSS codes to fit ACPI SOC.

2014-12-18 Thread Ken Xue
ACPI SOC provides common codes to 1)create platform device from ACPI
2)and handle platform bus notification. These common codes can be
used by LPSS with this patch.

Signed-off-by: Ken Xue ken@amd.com
---
 drivers/acpi/acpi_lpss.c | 604 ---
 1 file changed, 251 insertions(+), 353 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 4f3febf..993a772 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -10,7 +10,6 @@
  * published by the Free Software Foundation.
  */
 
-#include linux/acpi.h
 #include linux/clk.h
 #include linux/clkdev.h
 #include linux/clk-provider.h
@@ -21,10 +20,14 @@
 #include linux/pm_runtime.h
 #include linux/delay.h
 
+#include acpi_soc.h
 #include internal.h
 
 ACPI_MODULE_NAME(acpi_lpss);
 
+static struct acpi_soc a_soc;
+static struct device *proxy_device;
+
 #ifdef CONFIG_X86_INTEL_LPSS
 
 #define LPSS_ADDR(desc) ((unsigned long)desc)
@@ -56,178 +59,77 @@ ACPI_MODULE_NAME(acpi_lpss);
 
 /* LPSS Flags */
 #define LPSS_CLK   BIT(0)
-#define LPSS_CLK_GATE  BIT(1)
-#define LPSS_CLK_DIVIDER   BIT(2)
+#define LPSS_CLK_GATE  BIT(1)
+#define LPSS_CLK_DIVIDER   BIT(2)
 #define LPSS_LTR   BIT(3)
-#define LPSS_SAVE_CTX  BIT(4)
-#define LPSS_DEV_PROXY BIT(5)
-#define LPSS_PROXY_REQ BIT(6)
-
-struct lpss_private_data;
-
-struct lpss_device_desc {
-   unsigned int flags;
-   unsigned int prv_offset;
-   size_t prv_size_override;
-   void (*setup)(struct lpss_private_data *pdata);
-};
-
-static struct device *proxy_device;
-
-static struct lpss_device_desc lpss_dma_desc = {
-   .flags = LPSS_CLK | LPSS_PROXY_REQ,
-};
-
-struct lpss_private_data {
-   void __iomem *mmio_base;
-   resource_size_t mmio_size;
-   unsigned int fixed_clk_rate;
-   struct clk *clk;
-   const struct lpss_device_desc *dev_desc;
-   u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
-};
+#define LPSS_SAVE_CTX  BIT(4)
+#define LPSS_DEV_PROXY BIT(5)
+#define LPSS_PROXY_REQ BIT(6)
 
 /* UART Component Parameter Register */
 #define LPSS_UART_CPR  0xF4
 #define LPSS_UART_CPR_AFCE BIT(4)
 
-static void lpss_uart_setup(struct lpss_private_data *pdata)
+static u32 __lpss_reg_read(struct acpi_soc_dev_private_data *pdata,
+   unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata-dev_desc-prv_offset + LPSS_TX_INT;
-   val = readl(pdata-mmio_base + offset);
-   writel(val | LPSS_TX_INT_MASK, pdata-mmio_base + offset);
-
-   val = readl(pdata-mmio_base + LPSS_UART_CPR);
-   if (!(val  LPSS_UART_CPR_AFCE)) {
-   offset = pdata-dev_desc-prv_offset + LPSS_GENERAL;
-   val = readl(pdata-mmio_base + offset);
-   val |= LPSS_GENERAL_UART_RTS_OVRD;
-   writel(val, pdata-mmio_base + offset);
-   }
+   return readl(pdata-mmio_base + pdata-dev_desc-prv_offset + reg);
 }
 
-static void byt_i2c_setup(struct lpss_private_data *pdata)
+static void __lpss_reg_write(u32 val, struct acpi_soc_dev_private_data *pdata,
+unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata-dev_desc-prv_offset + LPSS_RESETS;
-   val = readl(pdata-mmio_base + offset);
-   val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
-   writel(val, pdata-mmio_base + offset);
-
-   if (readl(pdata-mmio_base + pdata-dev_desc-prv_offset))
-   pdata-fixed_clk_rate = 13300;
+   writel(val, pdata-mmio_base + pdata-dev_desc-prv_offset + reg);
 }
 
-static struct lpss_device_desc lpt_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_i2c_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc lpt_sdio_dev_desc = {
-   .flags = LPSS_LTR,
-   .prv_offset = 0x1000,
-   .prv_size_override = 0x1018,
-};
-
-static struct lpss_device_desc byt_pwm_dev_desc = {
-   .flags = LPSS_SAVE_CTX,
-};
-
-static struct lpss_device_desc byt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX |
-LPSS_DEV_PROXY,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc byt_spi_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX |
-LPSS_DEV_PROXY,
-   .prv_offset = 0x400,
-};
-
-static struct lpss_device_desc byt_sdio_dev_desc

Re: [PATCH 3/3] acpi:lpss:Refine lpss codes to fit acpi soc.

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:27 +0200, Andy Shevchenko wrote:
> On Thu, Dec 11, 2014 at 5:05 AM, Ken Xue  wrote:
> 
> Make a commit message not empty.
> 
[ken]got it.

> > Signed-off-by: Ken Xue 
> > ---
> >  drivers/acpi/acpi_lpss.c | 566 
> > ++-
> >  1 file changed, 221 insertions(+), 345 deletions(-)
> >
> > -static int acpi_lpss_platform_notify(struct notifier_block *nb,
> > -unsigned long action, void *data)
> 
> Could it be just a part of this file? It seems for me that AMD doesn't
> have anything specific which requires to have a dedicated power
> domain. Am I wrong?
> 
[Ken] AMD does not have any specific PM domain now. But i believe it is
a good and necessary feature for low power management. and AMD will have
similar HW design. so, can you share a reason to keep it as a part of
this file?


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/3] acpi:lpss:Refine lpss codes to fit acpi soc.

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:16 +0200, Mika Westerberg wrote:
> On Thu, Dec 11, 2014 at 11:05:51AM +0800, Ken Xue wrote:
> 
> This is missing changelog.
> 
> > Signed-off-by: Ken Xue 
> 
> ...
> 
[Ken]got it.

> > +static int lpss_common_setup(struct acpi_soc_dev_private_data *pdata)
> >  {
> > -   struct lpss_device_desc *dev_desc;
> > -   struct lpss_private_data *pdata;
> > -   struct resource_list_entry *rentry;
> > -   struct list_head resource_list;
> > -   struct platform_device *pdev;
> > -   int ret;
> > -
> > -   dev_desc = (struct lpss_device_desc *)id->driver_data;
> > -   if (!dev_desc) {
> > -   pdev = acpi_create_platform_device(adev);
> > -   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
> > -   }
> > -   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
> > -   if (!pdata)
> > -   return -ENOMEM;
> > -
> > -   INIT_LIST_HEAD(_list);
> > -   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
> > -   if (ret < 0)
> > -   goto err_out;
> > -
> > -   list_for_each_entry(rentry, _list, node)
> > -   if (resource_type(>res) == IORESOURCE_MEM) {
> > -   if (dev_desc->prv_size_override)
> > -   pdata->mmio_size = dev_desc->prv_size_override;
> > -   else
> > -   pdata->mmio_size = resource_size(>res);
> > -   pdata->mmio_base = ioremap(rentry->res.start,
> > -  pdata->mmio_size);
> > -   break;
> > -   }
> > -
> > -   acpi_dev_free_resource_list(_list);
> > +   int ret = 0;
> > +   struct acpi_soc_dev_desc *dev_desc;
> 
> 
> Please order these so that the longest line is on top. E.g
> 
[ken]got it.

>   struct acpi_soc_dev_desc *dev_desc;
>   int ret = 0;
> 
> Ditto for other similar places.
> 
> >  
> > -   pdata->dev_desc = dev_desc;
> > +   dev_desc = pdata->dev_desc;
> >  
> > -   if (dev_desc->setup)
> > -   dev_desc->setup(pdata);
> > +   if (dev_desc->flags & LPSS_CLK)
> > +   ret = register_device_clock(pdata->adev, pdata);
> >  
> > -   if (dev_desc->flags & LPSS_CLK) {
> > -   ret = register_device_clock(adev, pdata);
> > -   if (ret) {
> > -   /* Skip the device, but continue the namespace scan. */
> > -   ret = 0;
> > -   goto err_out;
> > -   }
> > -   }
> > +   return ret;
> > +}
> 
> ...
> 
> >  void __init acpi_lpss_init(void)
> >  {
> > if (!lpt_clk_init()) {
> > -   bus_register_notifier(_bus_type, _lpss_nb);
> > -   acpi_scan_add_handler(_handler);
> > +   a_soc.ids = acpi_lpss_device_ids;
> > +   a_soc.attr_group = _attr_group;
> > +   a_soc.pm_domain = _lpss_pm_domain;
> 
> If AMD stuff is not needing PM domain or LTR, I suggest that you leave
> both to be part of LPSS and not move them to acpi_soc.
> 
[Ken]there is no strong reason i can see to remove it. AMD may be also
has similar good feature in the future. and intel also can modify acpi
soc as you need, if it really can not meet your design. 

> > +   register_acpi_soc(_soc, true);
>    This needs to be false
> 
> > }
> >  }


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/3 V2] acpi:soc: merge common codes for creating platform device

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:01 +0200, Mika Westerberg wrote:
> On Thu, Dec 11, 2014 at 11:04:49AM +0800, Ken Xue wrote:
> > This patch is supposed to deliver some common codes for AMD APD and
> > INTEL LPSS. It can help to convert some specific acpi devices to be
> 
> INTEL -> Intel, acpi -> ACPI
> 
[ken]ok.

> > platform devices.
> >
> > Signed-off-by: Ken Xue 
> > ---
> >  drivers/acpi/Makefile   |   2 +-
> >  drivers/acpi/acpi_soc.c | 224 
> > 
> >  drivers/acpi/acpi_soc.h |  98 +
> >  3 files changed, 323 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/acpi/acpi_soc.c
> >  create mode 100644 drivers/acpi/acpi_soc.h
> > 
> > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> > index c3b2fcb..ae3397d 100644
> > --- a/drivers/acpi/Makefile
> > +++ b/drivers/acpi/Makefile
> > @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
> >  acpi-y += ec.o
> >  acpi-$(CONFIG_ACPI_DOCK)   += dock.o
> >  acpi-y += pci_root.o pci_link.o pci_irq.o
> > -acpi-y += acpi_lpss.o
> > +acpi-y += acpi_soc.o acpi_lpss.o
> >  acpi-y += acpi_platform.o
> >  acpi-y += acpi_pnp.o
> >  acpi-y += int340x_thermal.o
> > diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
> > new file mode 100644
> > index 000..46901d5
> > --- /dev/null
> > +++ b/drivers/acpi/acpi_soc.c
> > @@ -0,0 +1,224 @@
> > +/*
> > + * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
> > + *
> > + * Copyright (C) 2015, Intel Corporation & AMD Corporation
> > + * Authors: Ken Xue 
> > + * Mika Westerberg 
> > + * Rafael J. Wysocki 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "acpi_soc.h"
> > +#include "internal.h"
> > +
> > +ACPI_MODULE_NAME("acpi_soc");
> > +
> > +/* A list for all acpi soc device */
> > +static LIST_HEAD(a_soc_list);
> > +
> > +static int is_memory(struct acpi_resource *res, void *not_used)
> > +{
> > +   struct resource r;
> > +
> > +   return !acpi_dev_resource_memory(res, );
> > +}
> > +
> > +static int acpi_soc_create_device(struct acpi_device *adev,
> > +  const struct acpi_device_id *id)
> > +{
> > +   struct acpi_soc_dev_desc *dev_desc;
> > +   struct acpi_soc_dev_private_data *pdata;
> > +   struct resource_list_entry *rentry;
> > +   struct list_head resource_list;
> > +   struct platform_device *pdev;
> > +   int ret;
> > +
> > +   dev_desc = (struct acpi_soc_dev_desc *)id->driver_data;
> > +   if (!dev_desc) {
> > +   pdev = acpi_create_platform_device(adev);
> > +   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
> > +   }
> > +   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
> > +   if (!pdata)
> > +   return -ENOMEM;
> > +
> > +   INIT_LIST_HEAD(_list);
> > +   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
> > +   if (ret < 0)
> > +   goto err_out;
> > +
> > +   list_for_each_entry(rentry, _list, node)
> > +   if (resource_type(>res) == IORESOURCE_MEM) {
> > +   if (dev_desc->mem_size_override)
> > +   pdata->mmio_size = dev_desc->mem_size_override;
> > +   else
> > +   pdata->mmio_size = resource_size(>res);
> > +   pdata->mmio_base = ioremap(rentry->res.start,
> > +  pdata->mmio_size);
> > +   break;
> > +   }
> > +
> > +   acpi_dev_free_resource_list(_list);
> > +
> > +   pdata->adev = adev;
> > +   pdata->dev_desc = dev_desc;
> > +
> > +   if (dev_desc->setup) {
> > +   ret = dev_desc->setup(pdata);
> > +   if (ret)
> > +   goto err_out;
> > +   }
> > +
> > +   /*
> > +* This works around

Re: [PATCH 1/3 V2] acpi:soc: merge common codes for creating platform device

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:19 +0200, Andy Shevchenko wrote:
> On Thu, Dec 11, 2014 at 5:04 AM, Ken Xue  wrote:
> > This patch is supposed to deliver some common codes for AMD APD and
> > INTEL LPSS. It can help to convert some specific acpi devices to be
> > platform devices.
> 
> My few comments below.
> 
> First of all, please, add me to the Cc list of this patch set in the future.
> 
[ken]got it.

> >
> > Signed-off-by: Ken Xue 
> > ---
> >  drivers/acpi/Makefile   |   2 +-
> >  drivers/acpi/acpi_soc.c | 224 
> > 
> >  drivers/acpi/acpi_soc.h |  98 +
> >  3 files changed, 323 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/acpi/acpi_soc.c
> >  create mode 100644 drivers/acpi/acpi_soc.h
> >
> > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> > index c3b2fcb..ae3397d 100644
> > --- a/drivers/acpi/Makefile
> > +++ b/drivers/acpi/Makefile
> > @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
> >  acpi-y += ec.o
> >  acpi-$(CONFIG_ACPI_DOCK)   += dock.o
> >  acpi-y += pci_root.o pci_link.o pci_irq.o
> > -acpi-y += acpi_lpss.o
> > +acpi-y += acpi_soc.o acpi_lpss.o
> >  acpi-y += acpi_platform.o
> >  acpi-y += acpi_pnp.o
> >  acpi-y += int340x_thermal.o
> > diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
> > new file mode 100644
> > index 000..46901d5
> > --- /dev/null
> > +++ b/drivers/acpi/acpi_soc.c
> > @@ -0,0 +1,224 @@
> > +/*
> > + * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
> > + *
> > + * Copyright (C) 2015, Intel Corporation & AMD Corporation
> 
> 2015? Wait couple of weeks :-)
> Moreover, Intel code is copyrighted starting from 2013. I think it
> would be better to keep two lines, one is original from Intel and one
> from AMD.
> 
[ken]ok.

> > + * Authors: Ken Xue 
> > + * Mika Westerberg 
> > + * Rafael J. Wysocki 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "acpi_soc.h"
> > +#include "internal.h"
> > +
> > +ACPI_MODULE_NAME("acpi_soc");
> > +
> > +/* A list for all acpi soc device */
> > +static LIST_HEAD(a_soc_list);
> > +
> > +static int is_memory(struct acpi_resource *res, void *not_used)
> > +{
> > +   struct resource r;
> > +
> > +   return !acpi_dev_resource_memory(res, );
> > +}
> > +
> > +static int acpi_soc_create_device(struct acpi_device *adev,
> > +  const struct acpi_device_id *id)
> > +{
> > +   struct acpi_soc_dev_desc *dev_desc;
> > +   struct acpi_soc_dev_private_data *pdata;
> > +   struct resource_list_entry *rentry;
> > +   struct list_head resource_list;
> > +   struct platform_device *pdev;
> > +   int ret;
> > +
> > +   dev_desc = (struct acpi_soc_dev_desc *)id->driver_data;
> > +   if (!dev_desc) {
> > +   pdev = acpi_create_platform_device(adev);
> > +   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
> > +   }
> > +   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
> > +   if (!pdata)
> > +   return -ENOMEM;
> > +
> > +   INIT_LIST_HEAD(_list);
> > +   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
> > +   if (ret < 0)
> > +   goto err_out;
> > +
> > +   list_for_each_entry(rentry, _list, node)
> > +   if (resource_type(>res) == IORESOURCE_MEM) {
> > +   if (dev_desc->mem_size_override)
> > +   pdata->mmio_size = 
> > dev_desc->mem_size_override;
> > +   else
> > +   pdata->mmio_size = 
> > resource_size(>res);
> > +   pdata->mmio_base = ioremap(rentry->res.start,
> > +  pdata->mmio_size);
> > +   break;
> > +  

Re: [PATCH 1/3 V2] acpi:soc: merge common codes for creating platform device

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:19 +0200, Andy Shevchenko wrote:
 On Thu, Dec 11, 2014 at 5:04 AM, Ken Xue ken@amd.com wrote:
  This patch is supposed to deliver some common codes for AMD APD and
  INTEL LPSS. It can help to convert some specific acpi devices to be
  platform devices.
 
 My few comments below.
 
 First of all, please, add me to the Cc list of this patch set in the future.
 
[ken]got it.

 
  Signed-off-by: Ken Xue ken@amd.com
  ---
   drivers/acpi/Makefile   |   2 +-
   drivers/acpi/acpi_soc.c | 224 
  
   drivers/acpi/acpi_soc.h |  98 +
   3 files changed, 323 insertions(+), 1 deletion(-)
   create mode 100644 drivers/acpi/acpi_soc.c
   create mode 100644 drivers/acpi/acpi_soc.h
 
  diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
  index c3b2fcb..ae3397d 100644
  --- a/drivers/acpi/Makefile
  +++ b/drivers/acpi/Makefile
  @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
   acpi-y += ec.o
   acpi-$(CONFIG_ACPI_DOCK)   += dock.o
   acpi-y += pci_root.o pci_link.o pci_irq.o
  -acpi-y += acpi_lpss.o
  +acpi-y += acpi_soc.o acpi_lpss.o
   acpi-y += acpi_platform.o
   acpi-y += acpi_pnp.o
   acpi-y += int340x_thermal.o
  diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
  new file mode 100644
  index 000..46901d5
  --- /dev/null
  +++ b/drivers/acpi/acpi_soc.c
  @@ -0,0 +1,224 @@
  +/*
  + * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
  + *
  + * Copyright (C) 2015, Intel Corporation  AMD Corporation
 
 2015? Wait couple of weeks :-)
 Moreover, Intel code is copyrighted starting from 2013. I think it
 would be better to keep two lines, one is original from Intel and one
 from AMD.
 
[ken]ok.

  + * Authors: Ken Xue ken@amd.com
  + * Mika Westerberg mika.westerb...@linux.intel.com
  + * Rafael J. Wysocki rafael.j.wyso...@intel.com
  + *
  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License version 2 as
  + * published by the Free Software Foundation.
  + */
  +
  +#include linux/err.h
  +#include linux/list.h
  +#include linux/pm_domain.h
  +#include linux/platform_device.h
  +
  +#include acpi_soc.h
  +#include internal.h
  +
  +ACPI_MODULE_NAME(acpi_soc);
  +
  +/* A list for all acpi soc device */
  +static LIST_HEAD(a_soc_list);
  +
  +static int is_memory(struct acpi_resource *res, void *not_used)
  +{
  +   struct resource r;
  +
  +   return !acpi_dev_resource_memory(res, r);
  +}
  +
  +static int acpi_soc_create_device(struct acpi_device *adev,
  +  const struct acpi_device_id *id)
  +{
  +   struct acpi_soc_dev_desc *dev_desc;
  +   struct acpi_soc_dev_private_data *pdata;
  +   struct resource_list_entry *rentry;
  +   struct list_head resource_list;
  +   struct platform_device *pdev;
  +   int ret;
  +
  +   dev_desc = (struct acpi_soc_dev_desc *)id-driver_data;
  +   if (!dev_desc) {
  +   pdev = acpi_create_platform_device(adev);
  +   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
  +   }
  +   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  +   if (!pdata)
  +   return -ENOMEM;
  +
  +   INIT_LIST_HEAD(resource_list);
  +   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
  +   if (ret  0)
  +   goto err_out;
  +
  +   list_for_each_entry(rentry, resource_list, node)
  +   if (resource_type(rentry-res) == IORESOURCE_MEM) {
  +   if (dev_desc-mem_size_override)
  +   pdata-mmio_size = 
  dev_desc-mem_size_override;
  +   else
  +   pdata-mmio_size = 
  resource_size(rentry-res);
  +   pdata-mmio_base = ioremap(rentry-res.start,
  +  pdata-mmio_size);
  +   break;
  +   }
  +
  +   acpi_dev_free_resource_list(resource_list);
  +
  +   pdata-adev = adev;
  +   pdata-dev_desc = dev_desc;
  +
  +   if (dev_desc-setup) {
  +   ret = dev_desc-setup(pdata);
  +   if (ret)
  +   goto err_out;
  +   }
  +
  +   /*
  +* This works around a known issue in ACPI tables where acpi soc 
  devices
  +* have _PS0 and _PS3 without _PSC (and no power resources), so
  +* acpi_bus_init_power() will assume that the BIOS has put them 
  into D0.
  +*/
  +   ret = acpi_device_fix_up_power(adev);
  +   if (ret) {
  +   /* Skip the device, but continue the namespace scan. */
  +   ret = 0

Re: [PATCH 1/3 V2] acpi:soc: merge common codes for creating platform device

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:01 +0200, Mika Westerberg wrote:
 On Thu, Dec 11, 2014 at 11:04:49AM +0800, Ken Xue wrote:
  This patch is supposed to deliver some common codes for AMD APD and
  INTEL LPSS. It can help to convert some specific acpi devices to be
 
 INTEL - Intel, acpi - ACPI
 
[ken]ok.

  platform devices.
 
  Signed-off-by: Ken Xue ken@amd.com
  ---
   drivers/acpi/Makefile   |   2 +-
   drivers/acpi/acpi_soc.c | 224 
  
   drivers/acpi/acpi_soc.h |  98 +
   3 files changed, 323 insertions(+), 1 deletion(-)
   create mode 100644 drivers/acpi/acpi_soc.c
   create mode 100644 drivers/acpi/acpi_soc.h
  
  diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
  index c3b2fcb..ae3397d 100644
  --- a/drivers/acpi/Makefile
  +++ b/drivers/acpi/Makefile
  @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
   acpi-y += ec.o
   acpi-$(CONFIG_ACPI_DOCK)   += dock.o
   acpi-y += pci_root.o pci_link.o pci_irq.o
  -acpi-y += acpi_lpss.o
  +acpi-y += acpi_soc.o acpi_lpss.o
   acpi-y += acpi_platform.o
   acpi-y += acpi_pnp.o
   acpi-y += int340x_thermal.o
  diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
  new file mode 100644
  index 000..46901d5
  --- /dev/null
  +++ b/drivers/acpi/acpi_soc.c
  @@ -0,0 +1,224 @@
  +/*
  + * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
  + *
  + * Copyright (C) 2015, Intel Corporation  AMD Corporation
  + * Authors: Ken Xue ken@amd.com
  + * Mika Westerberg mika.westerb...@linux.intel.com
  + * Rafael J. Wysocki rafael.j.wyso...@intel.com
  + *
  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License version 2 as
  + * published by the Free Software Foundation.
  + */
  +
  +#include linux/err.h
  +#include linux/list.h
  +#include linux/pm_domain.h
  +#include linux/platform_device.h
  +
  +#include acpi_soc.h
  +#include internal.h
  +
  +ACPI_MODULE_NAME(acpi_soc);
  +
  +/* A list for all acpi soc device */
  +static LIST_HEAD(a_soc_list);
  +
  +static int is_memory(struct acpi_resource *res, void *not_used)
  +{
  +   struct resource r;
  +
  +   return !acpi_dev_resource_memory(res, r);
  +}
  +
  +static int acpi_soc_create_device(struct acpi_device *adev,
  +  const struct acpi_device_id *id)
  +{
  +   struct acpi_soc_dev_desc *dev_desc;
  +   struct acpi_soc_dev_private_data *pdata;
  +   struct resource_list_entry *rentry;
  +   struct list_head resource_list;
  +   struct platform_device *pdev;
  +   int ret;
  +
  +   dev_desc = (struct acpi_soc_dev_desc *)id-driver_data;
  +   if (!dev_desc) {
  +   pdev = acpi_create_platform_device(adev);
  +   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
  +   }
  +   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  +   if (!pdata)
  +   return -ENOMEM;
  +
  +   INIT_LIST_HEAD(resource_list);
  +   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
  +   if (ret  0)
  +   goto err_out;
  +
  +   list_for_each_entry(rentry, resource_list, node)
  +   if (resource_type(rentry-res) == IORESOURCE_MEM) {
  +   if (dev_desc-mem_size_override)
  +   pdata-mmio_size = dev_desc-mem_size_override;
  +   else
  +   pdata-mmio_size = resource_size(rentry-res);
  +   pdata-mmio_base = ioremap(rentry-res.start,
  +  pdata-mmio_size);
  +   break;
  +   }
  +
  +   acpi_dev_free_resource_list(resource_list);
  +
  +   pdata-adev = adev;
  +   pdata-dev_desc = dev_desc;
  +
  +   if (dev_desc-setup) {
  +   ret = dev_desc-setup(pdata);
  +   if (ret)
  +   goto err_out;
  +   }
  +
  +   /*
  +* This works around a known issue in ACPI tables where acpi soc devices
 
 acpi soc - ACPI SoC
 
 Please use these consistently.
 
[ken]got it.

  +* have _PS0 and _PS3 without _PSC (and no power resources), so
  +* acpi_bus_init_power() will assume that the BIOS has put them into D0.
  +*/
  +   ret = acpi_device_fix_up_power(adev);
  +   if (ret) {
  +   /* Skip the device, but continue the namespace scan. */
  +   ret = 0;
  +   goto err_out;
  +   }
  +
  +   adev-driver_data = pdata;
  +   pdev = acpi_create_platform_device(adev);
  +   if (!IS_ERR_OR_NULL(pdev))
  +   return 1;
  +
  +   ret = PTR_ERR(pdev);
  +   adev-driver_data = NULL;
  +
  + err_out:
  +   kfree(pdata);
  +   return ret;
  +}
  +
  +static int acpi_soc_platform_notify(struct notifier_block *nb

Re: [PATCH 3/3] acpi:lpss:Refine lpss codes to fit acpi soc.

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:16 +0200, Mika Westerberg wrote:
 On Thu, Dec 11, 2014 at 11:05:51AM +0800, Ken Xue wrote:
 
 This is missing changelog.
 
  Signed-off-by: Ken Xue ken@amd.com
 
 ...
 
[Ken]got it.

  +static int lpss_common_setup(struct acpi_soc_dev_private_data *pdata)
   {
  -   struct lpss_device_desc *dev_desc;
  -   struct lpss_private_data *pdata;
  -   struct resource_list_entry *rentry;
  -   struct list_head resource_list;
  -   struct platform_device *pdev;
  -   int ret;
  -
  -   dev_desc = (struct lpss_device_desc *)id-driver_data;
  -   if (!dev_desc) {
  -   pdev = acpi_create_platform_device(adev);
  -   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
  -   }
  -   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  -   if (!pdata)
  -   return -ENOMEM;
  -
  -   INIT_LIST_HEAD(resource_list);
  -   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
  -   if (ret  0)
  -   goto err_out;
  -
  -   list_for_each_entry(rentry, resource_list, node)
  -   if (resource_type(rentry-res) == IORESOURCE_MEM) {
  -   if (dev_desc-prv_size_override)
  -   pdata-mmio_size = dev_desc-prv_size_override;
  -   else
  -   pdata-mmio_size = resource_size(rentry-res);
  -   pdata-mmio_base = ioremap(rentry-res.start,
  -  pdata-mmio_size);
  -   break;
  -   }
  -
  -   acpi_dev_free_resource_list(resource_list);
  +   int ret = 0;
  +   struct acpi_soc_dev_desc *dev_desc;
 
 
 Please order these so that the longest line is on top. E.g
 
[ken]got it.

   struct acpi_soc_dev_desc *dev_desc;
   int ret = 0;
 
 Ditto for other similar places.
 
   
  -   pdata-dev_desc = dev_desc;
  +   dev_desc = pdata-dev_desc;
   
  -   if (dev_desc-setup)
  -   dev_desc-setup(pdata);
  +   if (dev_desc-flags  LPSS_CLK)
  +   ret = register_device_clock(pdata-adev, pdata);
   
  -   if (dev_desc-flags  LPSS_CLK) {
  -   ret = register_device_clock(adev, pdata);
  -   if (ret) {
  -   /* Skip the device, but continue the namespace scan. */
  -   ret = 0;
  -   goto err_out;
  -   }
  -   }
  +   return ret;
  +}
 
 ...
 
   void __init acpi_lpss_init(void)
   {
  if (!lpt_clk_init()) {
  -   bus_register_notifier(platform_bus_type, acpi_lpss_nb);
  -   acpi_scan_add_handler(lpss_handler);
  +   a_soc.ids = acpi_lpss_device_ids;
  +   a_soc.attr_group = lpss_attr_group;
  +   a_soc.pm_domain = acpi_lpss_pm_domain;
 
 If AMD stuff is not needing PM domain or LTR, I suggest that you leave
 both to be part of LPSS and not move them to acpi_soc.
 
[Ken]there is no strong reason i can see to remove it. AMD may be also
has similar good feature in the future. and intel also can modify acpi
soc as you need, if it really can not meet your design. 

  +   register_acpi_soc(a_soc, true);
    This needs to be false
 
  }
   }


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 3/3] acpi:lpss:Refine lpss codes to fit acpi soc.

2014-12-17 Thread Ken Xue
On Tue, 2014-12-16 at 12:27 +0200, Andy Shevchenko wrote:
 On Thu, Dec 11, 2014 at 5:05 AM, Ken Xue ken@amd.com wrote:
 
 Make a commit message not empty.
 
[ken]got it.

  Signed-off-by: Ken Xue ken@amd.com
  ---
   drivers/acpi/acpi_lpss.c | 566 
  ++-
   1 file changed, 221 insertions(+), 345 deletions(-)
 
  -static int acpi_lpss_platform_notify(struct notifier_block *nb,
  -unsigned long action, void *data)
 
 Could it be just a part of this file? It seems for me that AMD doesn't
 have anything specific which requires to have a dedicated power
 domain. Am I wrong?
 
[Ken] AMD does not have any specific PM domain now. But i believe it is
a good and necessary feature for low power management. and AMD will have
similar HW design. so, can you share a reason to keep it as a part of
this file?


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/3 V2] acpi:apd:add AMD ACPI2Platform device support

2014-12-10 Thread Ken Xue
This is a new feature to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later
chipsets. It based on acpi soc.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig| 11 
 drivers/acpi/Makefile   |  2 +-
 drivers/acpi/acpi_apd.c | 71 +
 drivers/acpi/internal.h |  2 ++
 drivers/acpi/scan.c |  1 +
 5 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..030f508 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index ae3397d..b07003a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_soc.o acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..b46e2af
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,71 @@
+/*
+ * AMD ACPI support for  ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+
+#include "acpi_soc.h"
+#include "internal.h"
+
+static struct acpi_soc a_soc;
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   }
+
+   return 0;
+}
+
+static struct acpi_soc_dev_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct acpi_soc_dev_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { "AMD0010", APD_ADDR(cz_i2c_desc) },
+   { "AMD0020", APD_ADDR(cz_uart_desc) },
+   { }
+};
+
+void __init acpi_apd_init(void)
+{
+   a_soc.ids = acpi_apd_device_ids;
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+   register_acpi_soc(_soc, false);
+#else
+   register_acpi_soc(_soc, true);
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 447f6d6..bade825 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -68,6 +68,8 @@ static inline void acpi_debugfs_init(void) { return; }
 #endif
 void acpi_lpss_init(void);
 
+void acpi_apd_init(void);
+
 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
 bool acpi_queue_hotplug_work(struct work_struct *work);
 void acpi_device_hotplug(struct acpi_device *adev, u32 src);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 0476e90..24fef2b 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2349,6 +2349,7 @@ int __init acpi_scan_init(void)
acpi_pci_link_init();
acpi_processor_init();
acpi_lpss_init();
+   acpi_apd_init();
acpi_cmos_rtc_init();
acpi_container_init();
   

[PATCH 1/3 V2] acpi:soc: merge common codes for creating platform device

2014-12-10 Thread Ken Xue
This patch is supposed to deliver some common codes for AMD APD and
INTEL LPSS. It can help to convert some specific acpi devices to be
platform devices.

Signed-off-by: Ken Xue 
---
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_soc.c | 224 
 drivers/acpi/acpi_soc.h |  98 +
 3 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_soc.c
 create mode 100644 drivers/acpi/acpi_soc.h

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..ae3397d 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
new file mode 100644
index 000..46901d5
--- /dev/null
+++ b/drivers/acpi/acpi_soc.c
@@ -0,0 +1,224 @@
+/*
+ * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
+ *
+ * Copyright (C) 2015, Intel Corporation & AMD Corporation
+ * Authors: Ken Xue 
+ * Mika Westerberg 
+ * Rafael J. Wysocki 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "acpi_soc.h"
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_soc");
+
+/* A list for all acpi soc device */
+static LIST_HEAD(a_soc_list);
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, );
+}
+
+static int acpi_soc_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct acpi_soc_dev_desc *dev_desc;
+   struct acpi_soc_dev_private_data *pdata;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct acpi_soc_dev_desc *)id->driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(adev);
+   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
+   }
+   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(_list);
+   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
+   if (ret < 0)
+   goto err_out;
+
+   list_for_each_entry(rentry, _list, node)
+   if (resource_type(>res) == IORESOURCE_MEM) {
+   if (dev_desc->mem_size_override)
+   pdata->mmio_size = dev_desc->mem_size_override;
+   else
+   pdata->mmio_size = resource_size(>res);
+   pdata->mmio_base = ioremap(rentry->res.start,
+  pdata->mmio_size);
+   break;
+   }
+
+   acpi_dev_free_resource_list(_list);
+
+   pdata->adev = adev;
+   pdata->dev_desc = dev_desc;
+
+   if (dev_desc->setup) {
+   ret = dev_desc->setup(pdata);
+   if (ret)
+   goto err_out;
+   }
+
+   /*
+* This works around a known issue in ACPI tables where acpi soc devices
+* have _PS0 and _PS3 without _PSC (and no power resources), so
+* acpi_bus_init_power() will assume that the BIOS has put them into D0.
+*/
+   ret = acpi_device_fix_up_power(adev);
+   if (ret) {
+   /* Skip the device, but continue the namespace scan. */
+   ret = 0;
+   goto err_out;
+   }
+
+   adev->driver_data = pdata;
+   pdev = acpi_create_platform_device(adev);
+   if (!IS_ERR_OR_NULL(pdev))
+   return 1;
+
+   ret = PTR_ERR(pdev);
+   adev->driver_data = NULL;
+
+ err_out:
+   kfree(pdata);
+   return ret;
+}
+
+static int acpi_soc_platform_notify(struct notifier_block *nb,
+unsigned long action, void *data)
+{
+   struct platform_device *pdev = to_platform_device(data);
+   struct acpi_soc_dev_private_data *pdata;
+   struct acpi_device *adev;
+   struct acpi_soc *a_soc_entry;
+   const struct acpi_device_id *id = NULL;
+
+   list_for_each_entry(a_soc_entry, _soc_list, list) {
+   id = acpi_match_

[PATCH 3/3] acpi:lpss:Refine lpss codes to fit acpi soc.

2014-12-10 Thread Ken Xue
Signed-off-by: Ken Xue 
---
 drivers/acpi/acpi_lpss.c | 566 ++-
 1 file changed, 221 insertions(+), 345 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 93d1606..554c932 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -10,7 +10,6 @@
  * published by the Free Software Foundation.
  */
 
-#include 
 #include 
 #include 
 #include 
@@ -21,10 +20,13 @@
 #include 
 #include 
 
+#include "acpi_soc.h"
 #include "internal.h"
 
 ACPI_MODULE_NAME("acpi_lpss");
 
+static struct acpi_soc a_soc;
+
 #ifdef CONFIG_X86_INTEL_LPSS
 
 #define LPSS_ADDR(desc) ((unsigned long))
@@ -58,170 +60,71 @@ ACPI_MODULE_NAME("acpi_lpss");
 #define LPSS_CLK   BIT(0)
 #define LPSS_CLK_GATE  BIT(1)
 #define LPSS_CLK_DIVIDER   BIT(2)
-#define LPSS_LTR   BIT(3)
-#define LPSS_SAVE_CTX  BIT(4)
-
-struct lpss_private_data;
-
-struct lpss_device_desc {
-   unsigned int flags;
-   unsigned int prv_offset;
-   size_t prv_size_override;
-   void (*setup)(struct lpss_private_data *pdata);
-};
-
-static struct lpss_device_desc lpss_dma_desc = {
-   .flags = LPSS_CLK,
-};
-
-struct lpss_private_data {
-   void __iomem *mmio_base;
-   resource_size_t mmio_size;
-   unsigned int fixed_clk_rate;
-   struct clk *clk;
-   const struct lpss_device_desc *dev_desc;
-   u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
-};
 
 /* UART Component Parameter Register */
 #define LPSS_UART_CPR  0xF4
 #define LPSS_UART_CPR_AFCE BIT(4)
 
-static void lpss_uart_setup(struct lpss_private_data *pdata)
+static u32 __lpss_reg_read(struct acpi_soc_dev_private_data *pdata,
+   unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata->dev_desc->prv_offset + LPSS_TX_INT;
-   val = readl(pdata->mmio_base + offset);
-   writel(val | LPSS_TX_INT_MASK, pdata->mmio_base + offset);
-
-   val = readl(pdata->mmio_base + LPSS_UART_CPR);
-   if (!(val & LPSS_UART_CPR_AFCE)) {
-   offset = pdata->dev_desc->prv_offset + LPSS_GENERAL;
-   val = readl(pdata->mmio_base + offset);
-   val |= LPSS_GENERAL_UART_RTS_OVRD;
-   writel(val, pdata->mmio_base + offset);
-   }
+   return readl(pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
 }
 
-static void byt_i2c_setup(struct lpss_private_data *pdata)
+static void __lpss_reg_write(u32 val, struct acpi_soc_dev_private_data *pdata,
+unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata->dev_desc->prv_offset + LPSS_RESETS;
-   val = readl(pdata->mmio_base + offset);
-   val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
-   writel(val, pdata->mmio_base + offset);
-
-   if (readl(pdata->mmio_base + pdata->dev_desc->prv_offset))
-   pdata->fixed_clk_rate = 13300;
+   writel(val, pdata->mmio_base + pdata->dev_desc->prv_offset + reg);
 }
 
-static struct lpss_device_desc lpt_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_i2c_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc lpt_sdio_dev_desc = {
-   .flags = LPSS_LTR,
-   .prv_offset = 0x1000,
-   .prv_size_override = 0x1018,
-};
-
-static struct lpss_device_desc byt_pwm_dev_desc = {
-   .flags = LPSS_SAVE_CTX,
-};
-
-static struct lpss_device_desc byt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc byt_spi_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
-   .prv_offset = 0x400,
-};
-
-static struct lpss_device_desc byt_sdio_dev_desc = {
-   .flags = LPSS_CLK,
-};
-
-static struct lpss_device_desc byt_i2c_dev_desc = {
-   .flags = LPSS_CLK | LPSS_SAVE_CTX,
-   .prv_offset = 0x800,
-   .setup = byt_i2c_setup,
-};
-
-#else
-
-#define LPSS_ADDR(desc) (0UL)
-
-#endif /* CONFIG_X86_INTEL_LPSS */
-
-static const struct acpi_device_id acpi_lpss_device_ids[] = {
-   /* Generic LPSS devices */
-   { "INTL9C60", LPSS_ADDR(lpss_dma_desc) },
-
-   /* Lynxpoint LPSS devices */
-   { "INT33C0", LPSS_ADDR(lpt_dev_desc) },
-   { "INT33C1", LPSS_ADDR(lpt_dev_desc) },
-   {

[PATCH 3/3] acpi:lpss:Refine lpss codes to fit acpi soc.

2014-12-10 Thread Ken Xue
Signed-off-by: Ken Xue ken@amd.com
---
 drivers/acpi/acpi_lpss.c | 566 ++-
 1 file changed, 221 insertions(+), 345 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 93d1606..554c932 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -10,7 +10,6 @@
  * published by the Free Software Foundation.
  */
 
-#include linux/acpi.h
 #include linux/clk.h
 #include linux/clkdev.h
 #include linux/clk-provider.h
@@ -21,10 +20,13 @@
 #include linux/pm_runtime.h
 #include linux/delay.h
 
+#include acpi_soc.h
 #include internal.h
 
 ACPI_MODULE_NAME(acpi_lpss);
 
+static struct acpi_soc a_soc;
+
 #ifdef CONFIG_X86_INTEL_LPSS
 
 #define LPSS_ADDR(desc) ((unsigned long)desc)
@@ -58,170 +60,71 @@ ACPI_MODULE_NAME(acpi_lpss);
 #define LPSS_CLK   BIT(0)
 #define LPSS_CLK_GATE  BIT(1)
 #define LPSS_CLK_DIVIDER   BIT(2)
-#define LPSS_LTR   BIT(3)
-#define LPSS_SAVE_CTX  BIT(4)
-
-struct lpss_private_data;
-
-struct lpss_device_desc {
-   unsigned int flags;
-   unsigned int prv_offset;
-   size_t prv_size_override;
-   void (*setup)(struct lpss_private_data *pdata);
-};
-
-static struct lpss_device_desc lpss_dma_desc = {
-   .flags = LPSS_CLK,
-};
-
-struct lpss_private_data {
-   void __iomem *mmio_base;
-   resource_size_t mmio_size;
-   unsigned int fixed_clk_rate;
-   struct clk *clk;
-   const struct lpss_device_desc *dev_desc;
-   u32 prv_reg_ctx[LPSS_PRV_REG_COUNT];
-};
 
 /* UART Component Parameter Register */
 #define LPSS_UART_CPR  0xF4
 #define LPSS_UART_CPR_AFCE BIT(4)
 
-static void lpss_uart_setup(struct lpss_private_data *pdata)
+static u32 __lpss_reg_read(struct acpi_soc_dev_private_data *pdata,
+   unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata-dev_desc-prv_offset + LPSS_TX_INT;
-   val = readl(pdata-mmio_base + offset);
-   writel(val | LPSS_TX_INT_MASK, pdata-mmio_base + offset);
-
-   val = readl(pdata-mmio_base + LPSS_UART_CPR);
-   if (!(val  LPSS_UART_CPR_AFCE)) {
-   offset = pdata-dev_desc-prv_offset + LPSS_GENERAL;
-   val = readl(pdata-mmio_base + offset);
-   val |= LPSS_GENERAL_UART_RTS_OVRD;
-   writel(val, pdata-mmio_base + offset);
-   }
+   return readl(pdata-mmio_base + pdata-dev_desc-prv_offset + reg);
 }
 
-static void byt_i2c_setup(struct lpss_private_data *pdata)
+static void __lpss_reg_write(u32 val, struct acpi_soc_dev_private_data *pdata,
+unsigned int reg)
 {
-   unsigned int offset;
-   u32 val;
-
-   offset = pdata-dev_desc-prv_offset + LPSS_RESETS;
-   val = readl(pdata-mmio_base + offset);
-   val |= LPSS_RESETS_RESET_APB | LPSS_RESETS_RESET_FUNC;
-   writel(val, pdata-mmio_base + offset);
-
-   if (readl(pdata-mmio_base + pdata-dev_desc-prv_offset))
-   pdata-fixed_clk_rate = 13300;
+   writel(val, pdata-mmio_base + pdata-dev_desc-prv_offset + reg);
 }
 
-static struct lpss_device_desc lpt_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_i2c_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_LTR,
-   .prv_offset = 0x800,
-};
-
-static struct lpss_device_desc lpt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_LTR,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc lpt_sdio_dev_desc = {
-   .flags = LPSS_LTR,
-   .prv_offset = 0x1000,
-   .prv_size_override = 0x1018,
-};
-
-static struct lpss_device_desc byt_pwm_dev_desc = {
-   .flags = LPSS_SAVE_CTX,
-};
-
-static struct lpss_device_desc byt_uart_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
-   .prv_offset = 0x800,
-   .setup = lpss_uart_setup,
-};
-
-static struct lpss_device_desc byt_spi_dev_desc = {
-   .flags = LPSS_CLK | LPSS_CLK_GATE | LPSS_CLK_DIVIDER | LPSS_SAVE_CTX,
-   .prv_offset = 0x400,
-};
-
-static struct lpss_device_desc byt_sdio_dev_desc = {
-   .flags = LPSS_CLK,
-};
-
-static struct lpss_device_desc byt_i2c_dev_desc = {
-   .flags = LPSS_CLK | LPSS_SAVE_CTX,
-   .prv_offset = 0x800,
-   .setup = byt_i2c_setup,
-};
-
-#else
-
-#define LPSS_ADDR(desc) (0UL)
-
-#endif /* CONFIG_X86_INTEL_LPSS */
-
-static const struct acpi_device_id acpi_lpss_device_ids[] = {
-   /* Generic LPSS devices */
-   { INTL9C60, LPSS_ADDR(lpss_dma_desc) },
-
-   /* Lynxpoint LPSS devices */
-   { INT33C0, LPSS_ADDR(lpt_dev_desc) },
-   { INT33C1, LPSS_ADDR(lpt_dev_desc) },
-   { INT33C2, LPSS_ADDR(lpt_i2c_dev_desc) },
-   { INT33C3, LPSS_ADDR

[PATCH 1/3 V2] acpi:soc: merge common codes for creating platform device

2014-12-10 Thread Ken Xue
This patch is supposed to deliver some common codes for AMD APD and
INTEL LPSS. It can help to convert some specific acpi devices to be
platform devices.

Signed-off-by: Ken Xue ken@amd.com
---
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_soc.c | 224 
 drivers/acpi/acpi_soc.h |  98 +
 3 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_soc.c
 create mode 100644 drivers/acpi/acpi_soc.h

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..ae3397d 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
new file mode 100644
index 000..46901d5
--- /dev/null
+++ b/drivers/acpi/acpi_soc.c
@@ -0,0 +1,224 @@
+/*
+ * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
+ *
+ * Copyright (C) 2015, Intel Corporation  AMD Corporation
+ * Authors: Ken Xue ken@amd.com
+ * Mika Westerberg mika.westerb...@linux.intel.com
+ * Rafael J. Wysocki rafael.j.wyso...@intel.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/err.h
+#include linux/list.h
+#include linux/pm_domain.h
+#include linux/platform_device.h
+
+#include acpi_soc.h
+#include internal.h
+
+ACPI_MODULE_NAME(acpi_soc);
+
+/* A list for all acpi soc device */
+static LIST_HEAD(a_soc_list);
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, r);
+}
+
+static int acpi_soc_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct acpi_soc_dev_desc *dev_desc;
+   struct acpi_soc_dev_private_data *pdata;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct acpi_soc_dev_desc *)id-driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(adev);
+   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
+   }
+   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(resource_list);
+   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
+   if (ret  0)
+   goto err_out;
+
+   list_for_each_entry(rentry, resource_list, node)
+   if (resource_type(rentry-res) == IORESOURCE_MEM) {
+   if (dev_desc-mem_size_override)
+   pdata-mmio_size = dev_desc-mem_size_override;
+   else
+   pdata-mmio_size = resource_size(rentry-res);
+   pdata-mmio_base = ioremap(rentry-res.start,
+  pdata-mmio_size);
+   break;
+   }
+
+   acpi_dev_free_resource_list(resource_list);
+
+   pdata-adev = adev;
+   pdata-dev_desc = dev_desc;
+
+   if (dev_desc-setup) {
+   ret = dev_desc-setup(pdata);
+   if (ret)
+   goto err_out;
+   }
+
+   /*
+* This works around a known issue in ACPI tables where acpi soc devices
+* have _PS0 and _PS3 without _PSC (and no power resources), so
+* acpi_bus_init_power() will assume that the BIOS has put them into D0.
+*/
+   ret = acpi_device_fix_up_power(adev);
+   if (ret) {
+   /* Skip the device, but continue the namespace scan. */
+   ret = 0;
+   goto err_out;
+   }
+
+   adev-driver_data = pdata;
+   pdev = acpi_create_platform_device(adev);
+   if (!IS_ERR_OR_NULL(pdev))
+   return 1;
+
+   ret = PTR_ERR(pdev);
+   adev-driver_data = NULL;
+
+ err_out:
+   kfree(pdata);
+   return ret;
+}
+
+static int acpi_soc_platform_notify(struct notifier_block *nb,
+unsigned long action, void *data)
+{
+   struct platform_device *pdev = to_platform_device(data);
+   struct acpi_soc_dev_private_data *pdata;
+   struct acpi_device *adev;
+   struct acpi_soc *a_soc_entry;
+   const struct acpi_device_id *id = NULL

[PATCH 2/3 V2] acpi:apd:add AMD ACPI2Platform device support

2014-12-10 Thread Ken Xue
This is a new feature to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later
chipsets. It based on acpi soc.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig| 11 
 drivers/acpi/Makefile   |  2 +-
 drivers/acpi/acpi_apd.c | 71 +
 drivers/acpi/internal.h |  2 ++
 drivers/acpi/scan.c |  1 +
 5 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..030f508 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD Carrizo and later chipsets. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index ae3397d..b07003a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_soc.o acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..b46e2af
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,71 @@
+/*
+ * AMD ACPI support for  ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include linux/clkdev.h
+#include linux/clk-provider.h
+#include linux/err.h
+
+#include acpi_soc.h
+#include internal.h
+
+static struct acpi_soc a_soc;
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   }
+
+   return 0;
+}
+
+static struct acpi_soc_dev_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct acpi_soc_dev_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { AMD0010, APD_ADDR(cz_i2c_desc) },
+   { AMD0020, APD_ADDR(cz_uart_desc) },
+   { }
+};
+
+void __init acpi_apd_init(void)
+{
+   a_soc.ids = acpi_apd_device_ids;
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+   register_acpi_soc(a_soc, false);
+#else
+   register_acpi_soc(a_soc, true);
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 447f6d6..bade825 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -68,6 +68,8 @@ static inline void acpi_debugfs_init(void) { return; }
 #endif
 void acpi_lpss_init(void);
 
+void acpi_apd_init(void);
+
 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
 bool acpi_queue_hotplug_work(struct work_struct *work);
 void acpi_device_hotplug(struct acpi_device *adev, u32 src);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 0476e90..24fef2b 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2349,6 +2349,7 @@ int __init acpi_scan_init(void)
acpi_pci_link_init();
acpi_processor_init();
acpi_lpss_init();
+   acpi_apd_init();
acpi_cmos_rtc_init();
acpi_container_init

Re: [PATCH 2/2] acpi:apd:add AMD ACPI2Platform device support

2014-12-04 Thread Ken Xue
On Thu, 2014-12-04 at 13:58 +0200, Mika Westerberg wrote:
> On Wed, Dec 03, 2014 at 08:34:32PM +0800, Ken Xue wrote:
> > This is a new feature to interpret AMD specific ACPI device to
> > platform device such as I2C, UART found on AMD CZ and later
> > chipsets. It based on INTEL LPSS and acpi soc.
> > 
> > Signed-off-by: Ken Xue 
> > ---
> >  arch/x86/Kconfig| 11 +++
> >  drivers/acpi/Makefile   |  2 +-
> >  drivers/acpi/acpi_apd.c | 82 
> > +
> >  drivers/acpi/internal.h |  6 
> >  drivers/acpi/scan.c |  1 +
> >  5 files changed, 101 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/acpi/acpi_apd.c
> 
> Trying to compile this with !X86_AMD_PLATFORM_DEVICE gives me
> 
> drivers/acpi/acpi_apd.c:74:13: error: redefinition of ‘acpi_apd_init’
>  void __init acpi_apd_init(void)
>  ^
> In file included from drivers/acpi/acpi_apd.c:22:0:
> drivers/acpi/internal.h:74:20: note: previous definition of ‘acpi_apd_init’ 
> was here
>  static inline void acpi_apd_init(void) {}
> ^
> scripts/Makefile.build:257: recipe for target 'drivers/acpi/acpi_apd.o' failed
> make[2]: *** [drivers/acpi/acpi_apd.o] Error 1
> make[2]: *** Waiting for unfinished jobs
> 
> 
[Ken] sorry for it. it is my mistake.

> > 
> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> > index ded8a67..6402c79f 100644
> > --- a/arch/x86/Kconfig
> > +++ b/arch/x86/Kconfig
> > @@ -495,6 +495,17 @@ config X86_INTEL_LPSS
> >   things like clock tree (common clock framework) and pincontrol
> >   which are needed by the LPSS peripheral drivers.
> >  
> > +config X86_AMD_PLATFORM_DEVICE
> > +   bool "AMD ACPI2Platform devices support"
> > +   depends on ACPI
> > +   select COMMON_CLK
> > +   select PINCTRL
> > +   ---help---
> > + Select to interpret AMD specific ACPI device to platform device
> > + such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
> > + this option enables things like clock tree (common clock framework)
> > + and pinctrl.
> > +
> >  config IOSF_MBI
> > tristate "Intel SoC IOSF Sideband support for SoC platforms"
> > depends on PCI
> > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> > index ae3397d..b07003a 100644
> > --- a/drivers/acpi/Makefile
> > +++ b/drivers/acpi/Makefile
> > @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
> >  acpi-y += ec.o
> >  acpi-$(CONFIG_ACPI_DOCK)   += dock.o
> >  acpi-y += pci_root.o pci_link.o pci_irq.o
> > -acpi-y += acpi_soc.o acpi_lpss.o
> > +acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
> >  acpi-y += acpi_platform.o
> >  acpi-y += acpi_pnp.o
> >  acpi-y         += int340x_thermal.o
> > diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
> > new file mode 100644
> > index 000..9afc144
> > --- /dev/null
> > +++ b/drivers/acpi/acpi_apd.c
> > @@ -0,0 +1,82 @@
> > +/*
> > + * AMD ACPI support for  ACPI2platform device.
> > + *
> > + * Copyright (c) 2014, AMD Corporation.
> > + * Authors: Ken Xue 
> > + * Wu, Jeff 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Are you sure you need all those headers?
> 
[ken] refine it with next release.

> > +#include "internal.h"
> > +#include "acpi_soc.h"
> > +
> > +struct acpi_soc asoc;
> > +
> > +#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
> > +#define APD_ADDR(desc) ((unsigned long))
> > +
> > +static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
> > +{
> > +   struct acpi_soc_dev_desc *dev_desc = pdata->dev_desc;
> > +   struct clk *clk = ERR_PTR(-ENODEV);
> > +
> > +   if (dev_desc->clk)
> > +   return 0;
> > +
> > +   if (dev_desc->fixed_clk_rate) {
> > +   clk = clk_register_fixed_rate(>adev->dev,
> > +   dev_name(>adev->

Re: [PATCH 1/2] acpi:soc: merge common codes for creating platform device

2014-12-04 Thread Ken Xue
On Thu, 2014-12-04 at 15:04 +0200, Mika Westerberg wrote:
> On Wed, Dec 03, 2014 at 08:33:37PM +0800, Ken Xue wrote:
> > This patch is supposed to deliver some common codes for AMD APD and
> > INTEL LPSS. It can help to convert some specific acpi devices to be
> > platform devices.
> > 
> > Signed-off-by: Ken Xue 
> > ---
> >  drivers/acpi/Makefile   |   2 +-
> >  drivers/acpi/acpi_soc.c | 211 
> > 
> >  drivers/acpi/acpi_soc.h |  90 +
> >  3 files changed, 302 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/acpi/acpi_soc.c
> >  create mode 100644 drivers/acpi/acpi_soc.h
> > 
> > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
> > index c3b2fcb..ae3397d 100644
> > --- a/drivers/acpi/Makefile
> > +++ b/drivers/acpi/Makefile
> > @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
> >  acpi-y += ec.o
> >  acpi-$(CONFIG_ACPI_DOCK)   += dock.o
> >  acpi-y += pci_root.o pci_link.o pci_irq.o
> > -acpi-y += acpi_lpss.o
> > +acpi-y += acpi_soc.o acpi_lpss.o
> 
> I think you need to convert acpi_lpss.c to use this new acpi_soc.c.
> 
[ken] I would like to merge lpss. But you know that I am lack of INTEL
platforms to verify codes before submit. And i am a little worried about
i may not cover so much rich features of lpss well. so, can we merge
lpss after current patch? or what's your plan?

> >  acpi-y += acpi_platform.o
> >  acpi-y += acpi_pnp.o
> >  acpi-y += int340x_thermal.o
> > diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
> > new file mode 100644
> > index 000..25089a0
> > --- /dev/null
> > +++ b/drivers/acpi/acpi_soc.c
> > @@ -0,0 +1,211 @@
> > +/*
> > + * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
> > + *
> > + * Copyright (C) 2015, Intel Corporation & AMD Corporation
> > + * Authors: Ken Xue 
> > + * Mika Westerberg 
> > + * Rafael J. Wysocki 
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include "internal.h"
> > +#include "acpi_soc.h"
> > +
> > +ACPI_MODULE_NAME("acpi_soc");
> > +
> > +/* A list for all acpi soc device */
> > +static LIST_HEAD(a_soc_list);
> > +
> > +static int is_memory(struct acpi_resource *res, void *not_used)
> > +{
> > +   struct resource r;
> > +
> > +   return !acpi_dev_resource_memory(res, );
> > +}
> > +
> > +static int acpi_soc_create_device(struct acpi_device *adev,
> > +  const struct acpi_device_id *id)
> > +{
> > +   struct acpi_soc_dev_desc *dev_desc;
> > +   struct acpi_soc_dev_private_data *pdata;
> > +   struct resource_list_entry *rentry;
> > +   struct list_head resource_list;
> > +   struct platform_device *pdev;
> > +   int ret;
> > +
> > +   dev_desc = (struct acpi_soc_dev_desc *)id->driver_data;
> > +   if (!dev_desc) {
> > +   pdev = acpi_create_platform_device(adev);
> > +   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
> > +   }
> > +   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
> > +   if (!pdata)
> > +   return -ENOMEM;
> > +
> > +   INIT_LIST_HEAD(_list);
> > +   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
> > +   if (ret < 0)
> > +   goto err_out;
> > +
> > +   list_for_each_entry(rentry, _list, node)
> > +   if (resource_type(>res) == IORESOURCE_MEM) {
> > +   if (dev_desc->mem_size_override)
> > +   pdata->mmio_size = dev_desc->mem_size_override;
> > +   else
> > +   pdata->mmio_size = resource_size(>res);
> > +   pdata->mmio_base = ioremap(rentry->res.start,
> > +  pdata->mmio_size);
> > +   break;
> > +   }
> > +
> > +   acpi_dev_free_resource_li

Re: [PATCH 1/2] acpi:soc: merge common codes for creating platform device

2014-12-04 Thread Ken Xue
On Thu, 2014-12-04 at 15:04 +0200, Mika Westerberg wrote:
 On Wed, Dec 03, 2014 at 08:33:37PM +0800, Ken Xue wrote:
  This patch is supposed to deliver some common codes for AMD APD and
  INTEL LPSS. It can help to convert some specific acpi devices to be
  platform devices.
  
  Signed-off-by: Ken Xue ken@amd.com
  ---
   drivers/acpi/Makefile   |   2 +-
   drivers/acpi/acpi_soc.c | 211 
  
   drivers/acpi/acpi_soc.h |  90 +
   3 files changed, 302 insertions(+), 1 deletion(-)
   create mode 100644 drivers/acpi/acpi_soc.c
   create mode 100644 drivers/acpi/acpi_soc.h
  
  diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
  index c3b2fcb..ae3397d 100644
  --- a/drivers/acpi/Makefile
  +++ b/drivers/acpi/Makefile
  @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
   acpi-y += ec.o
   acpi-$(CONFIG_ACPI_DOCK)   += dock.o
   acpi-y += pci_root.o pci_link.o pci_irq.o
  -acpi-y += acpi_lpss.o
  +acpi-y += acpi_soc.o acpi_lpss.o
 
 I think you need to convert acpi_lpss.c to use this new acpi_soc.c.
 
[ken] I would like to merge lpss. But you know that I am lack of INTEL
platforms to verify codes before submit. And i am a little worried about
i may not cover so much rich features of lpss well. so, can we merge
lpss after current patch? or what's your plan?

   acpi-y += acpi_platform.o
   acpi-y += acpi_pnp.o
   acpi-y += int340x_thermal.o
  diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
  new file mode 100644
  index 000..25089a0
  --- /dev/null
  +++ b/drivers/acpi/acpi_soc.c
  @@ -0,0 +1,211 @@
  +/*
  + * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
  + *
  + * Copyright (C) 2015, Intel Corporation  AMD Corporation
  + * Authors: Ken Xue ken@amd.com
  + * Mika Westerberg mika.westerb...@linux.intel.com
  + * Rafael J. Wysocki rafael.j.wyso...@intel.com
  + *
  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License version 2 as
  + * published by the Free Software Foundation.
  + */
  +
  +#include linux/acpi.h
  +#include linux/err.h
  +#include linux/io.h
  +#include linux/platform_device.h
  +#include linux/pm_runtime.h
  +#include linux/delay.h
  +#include linux/pm_domain.h
  +
  +#include internal.h
  +#include acpi_soc.h
  +
  +ACPI_MODULE_NAME(acpi_soc);
  +
  +/* A list for all acpi soc device */
  +static LIST_HEAD(a_soc_list);
  +
  +static int is_memory(struct acpi_resource *res, void *not_used)
  +{
  +   struct resource r;
  +
  +   return !acpi_dev_resource_memory(res, r);
  +}
  +
  +static int acpi_soc_create_device(struct acpi_device *adev,
  +  const struct acpi_device_id *id)
  +{
  +   struct acpi_soc_dev_desc *dev_desc;
  +   struct acpi_soc_dev_private_data *pdata;
  +   struct resource_list_entry *rentry;
  +   struct list_head resource_list;
  +   struct platform_device *pdev;
  +   int ret;
  +
  +   dev_desc = (struct acpi_soc_dev_desc *)id-driver_data;
  +   if (!dev_desc) {
  +   pdev = acpi_create_platform_device(adev);
  +   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
  +   }
  +   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  +   if (!pdata)
  +   return -ENOMEM;
  +
  +   INIT_LIST_HEAD(resource_list);
  +   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
  +   if (ret  0)
  +   goto err_out;
  +
  +   list_for_each_entry(rentry, resource_list, node)
  +   if (resource_type(rentry-res) == IORESOURCE_MEM) {
  +   if (dev_desc-mem_size_override)
  +   pdata-mmio_size = dev_desc-mem_size_override;
  +   else
  +   pdata-mmio_size = resource_size(rentry-res);
  +   pdata-mmio_base = ioremap(rentry-res.start,
  +  pdata-mmio_size);
  +   break;
  +   }
  +
  +   acpi_dev_free_resource_list(resource_list);
  +
  +   pdata-adev = adev;
  +   pdata-dev_desc = dev_desc;
  +
  +   if (dev_desc-setup)
  +   dev_desc-setup(pdata);
  +
  +   /*
  +* This works around a known issue in ACPI tables where acpi soc devices
  +* have _PS0 and _PS3 without _PSC (and no power resources), so
  +* acpi_bus_init_power() will assume that the BIOS has put them into D0.
  +*/
  +   ret = acpi_device_fix_up_power(adev);
  +   if (ret) {
  +   /* Skip the device, but continue the namespace scan. */
  +   ret = 0;
  +   goto err_out;
  +   }
  +
  +   adev-driver_data = pdata;
  +   pdev = acpi_create_platform_device(adev);
  +   if (!IS_ERR_OR_NULL(pdev))
  +   return 1

Re: [PATCH 2/2] acpi:apd:add AMD ACPI2Platform device support

2014-12-04 Thread Ken Xue
On Thu, 2014-12-04 at 13:58 +0200, Mika Westerberg wrote:
 On Wed, Dec 03, 2014 at 08:34:32PM +0800, Ken Xue wrote:
  This is a new feature to interpret AMD specific ACPI device to
  platform device such as I2C, UART found on AMD CZ and later
  chipsets. It based on INTEL LPSS and acpi soc.
  
  Signed-off-by: Ken Xue ken@amd.com
  ---
   arch/x86/Kconfig| 11 +++
   drivers/acpi/Makefile   |  2 +-
   drivers/acpi/acpi_apd.c | 82 
  +
   drivers/acpi/internal.h |  6 
   drivers/acpi/scan.c |  1 +
   5 files changed, 101 insertions(+), 1 deletion(-)
   create mode 100644 drivers/acpi/acpi_apd.c
 
 Trying to compile this with !X86_AMD_PLATFORM_DEVICE gives me
 
 drivers/acpi/acpi_apd.c:74:13: error: redefinition of ‘acpi_apd_init’
  void __init acpi_apd_init(void)
  ^
 In file included from drivers/acpi/acpi_apd.c:22:0:
 drivers/acpi/internal.h:74:20: note: previous definition of ‘acpi_apd_init’ 
 was here
  static inline void acpi_apd_init(void) {}
 ^
 scripts/Makefile.build:257: recipe for target 'drivers/acpi/acpi_apd.o' failed
 make[2]: *** [drivers/acpi/acpi_apd.o] Error 1
 make[2]: *** Waiting for unfinished jobs
 
 
[Ken] sorry for it. it is my mistake.

  
  diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
  index ded8a67..6402c79f 100644
  --- a/arch/x86/Kconfig
  +++ b/arch/x86/Kconfig
  @@ -495,6 +495,17 @@ config X86_INTEL_LPSS
things like clock tree (common clock framework) and pincontrol
which are needed by the LPSS peripheral drivers.
   
  +config X86_AMD_PLATFORM_DEVICE
  +   bool AMD ACPI2Platform devices support
  +   depends on ACPI
  +   select COMMON_CLK
  +   select PINCTRL
  +   ---help---
  + Select to interpret AMD specific ACPI device to platform device
  + such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
  + this option enables things like clock tree (common clock framework)
  + and pinctrl.
  +
   config IOSF_MBI
  tristate Intel SoC IOSF Sideband support for SoC platforms
  depends on PCI
  diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
  index ae3397d..b07003a 100644
  --- a/drivers/acpi/Makefile
  +++ b/drivers/acpi/Makefile
  @@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
   acpi-y += ec.o
   acpi-$(CONFIG_ACPI_DOCK)   += dock.o
   acpi-y += pci_root.o pci_link.o pci_irq.o
  -acpi-y += acpi_soc.o acpi_lpss.o
  +acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
   acpi-y += acpi_platform.o
   acpi-y += acpi_pnp.o
   acpi-y += int340x_thermal.o
  diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
  new file mode 100644
  index 000..9afc144
  --- /dev/null
  +++ b/drivers/acpi/acpi_apd.c
  @@ -0,0 +1,82 @@
  +/*
  + * AMD ACPI support for  ACPI2platform device.
  + *
  + * Copyright (c) 2014, AMD Corporation.
  + * Authors: Ken Xue ken@amd.com
  + * Wu, Jeff jeff...@amd.com
  + *
  + * This program is free software; you can redistribute it and/or modify
  + * it under the terms of the GNU General Public License version 2 as
  + * published by the Free Software Foundation.
  + */
  +
  +#include linux/acpi.h
  +#include linux/clk.h
  +#include linux/clkdev.h
  +#include linux/clk-provider.h
  +#include linux/err.h
  +#include linux/io.h
  +#include linux/platform_device.h
  +#include linux/pm_runtime.h
 
 Are you sure you need all those headers?
 
[ken] refine it with next release.

  +#include internal.h
  +#include acpi_soc.h
  +
  +struct acpi_soc asoc;
  +
  +#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
  +#define APD_ADDR(desc) ((unsigned long)desc)
  +
  +static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
  +{
  +   struct acpi_soc_dev_desc *dev_desc = pdata-dev_desc;
  +   struct clk *clk = ERR_PTR(-ENODEV);
  +
  +   if (dev_desc-clk)
  +   return 0;
  +
  +   if (dev_desc-fixed_clk_rate) {
  +   clk = clk_register_fixed_rate(pdata-adev-dev,
  +   dev_name(pdata-adev-dev),
  +   NULL, CLK_IS_ROOT,
  +   dev_desc-fixed_clk_rate);
  +   dev_desc-clk = clk;
  +   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
  +   }
  +
  +   return 0;
  +}
  +
  +static struct acpi_soc_dev_desc cz_i2c_desc = {
  +   .setup = acpi_apd_setup,
  +   .fixed_clk_rate = 13300,
  +};
  +
  +static struct acpi_soc_dev_desc cz_uart_desc = {
  +   .setup = acpi_apd_setup,
  +   .fixed_clk_rate = 4800,
  +};
  +
  +#else
  +
  +#define APD_ADDR(desc) (0UL)
  +
  +#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
  +
  +static struct acpi_device_id acpi_apd_device_ids[] = {
  +   /* Generic apd devices */
  +   { AMD0010, APD_ADDR

[PATCH 2/2] acpi:apd:add AMD ACPI2Platform device support

2014-12-03 Thread Ken Xue
This is a new feature to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later
chipsets. It based on INTEL LPSS and acpi soc.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig| 11 +++
 drivers/acpi/Makefile   |  2 +-
 drivers/acpi/acpi_apd.c | 82 +
 drivers/acpi/internal.h |  6 
 drivers/acpi/scan.c |  1 +
 5 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..6402c79f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index ae3397d..b07003a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_soc.o acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..9afc144
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,82 @@
+/*
+ * AMD ACPI support for  ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+#include "acpi_soc.h"
+
+struct acpi_soc asoc;
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long))
+
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->clk)
+   return 0;
+
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev,
+   dev_name(>adev->dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc->fixed_clk_rate);
+   dev_desc->clk = clk;
+   clk_register_clkdev(clk, NULL, dev_name(>adev->dev));
+   }
+
+   return 0;
+}
+
+static struct acpi_soc_dev_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct acpi_soc_dev_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { "AMD0010", APD_ADDR(cz_i2c_desc) },
+   { "AMD0020", APD_ADDR(cz_uart_desc) },
+   { }
+};
+
+
+void __init acpi_apd_init(void)
+{
+   asoc.ids = acpi_apd_device_ids;
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+   register_acpi_soc(, false);
+#else
+   register_acpi_soc(, true);
+#endif /*CONFIG_X86_AMD_PLATFORM_DEVICE*/
+}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 447f6d6..c8a0e8e 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -68,6 +68,12 @@ static inline void acpi_debugfs_init(void) { return; }
 #endif
 void acpi_lpss_init(void);
 
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+void acpi_apd_init(void);
+#else
+static inline void acpi_apd_init(void) {}
+#endif
+
 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
 bool acpi_queue_hotplug_work(struct work_struct *work);
 void acpi_device_hotplug(struct acpi_device *adev, u32 src);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 0476e90..24fef2b 100644
--- a/drivers/acpi/scan.c
+++ b/drivers

[PATCH 1/2] acpi:soc: merge common codes for creating platform device

2014-12-03 Thread Ken Xue
This patch is supposed to deliver some common codes for AMD APD and
INTEL LPSS. It can help to convert some specific acpi devices to be
platform devices.

Signed-off-by: Ken Xue 
---
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_soc.c | 211 
 drivers/acpi/acpi_soc.h |  90 +
 3 files changed, 302 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_soc.c
 create mode 100644 drivers/acpi/acpi_soc.h

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..ae3397d 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
new file mode 100644
index 000..25089a0
--- /dev/null
+++ b/drivers/acpi/acpi_soc.c
@@ -0,0 +1,211 @@
+/*
+ * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
+ *
+ * Copyright (C) 2015, Intel Corporation & AMD Corporation
+ * Authors: Ken Xue 
+ * Mika Westerberg 
+ * Rafael J. Wysocki 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+#include "acpi_soc.h"
+
+ACPI_MODULE_NAME("acpi_soc");
+
+/* A list for all acpi soc device */
+static LIST_HEAD(a_soc_list);
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, );
+}
+
+static int acpi_soc_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct acpi_soc_dev_desc *dev_desc;
+   struct acpi_soc_dev_private_data *pdata;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct acpi_soc_dev_desc *)id->driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(adev);
+   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
+   }
+   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(_list);
+   ret = acpi_dev_get_resources(adev, _list, is_memory, NULL);
+   if (ret < 0)
+   goto err_out;
+
+   list_for_each_entry(rentry, _list, node)
+   if (resource_type(>res) == IORESOURCE_MEM) {
+   if (dev_desc->mem_size_override)
+   pdata->mmio_size = dev_desc->mem_size_override;
+   else
+   pdata->mmio_size = resource_size(>res);
+   pdata->mmio_base = ioremap(rentry->res.start,
+  pdata->mmio_size);
+   break;
+   }
+
+   acpi_dev_free_resource_list(_list);
+
+   pdata->adev = adev;
+   pdata->dev_desc = dev_desc;
+
+   if (dev_desc->setup)
+   dev_desc->setup(pdata);
+
+   /*
+* This works around a known issue in ACPI tables where acpi soc devices
+* have _PS0 and _PS3 without _PSC (and no power resources), so
+* acpi_bus_init_power() will assume that the BIOS has put them into D0.
+*/
+   ret = acpi_device_fix_up_power(adev);
+   if (ret) {
+   /* Skip the device, but continue the namespace scan. */
+   ret = 0;
+   goto err_out;
+   }
+
+   adev->driver_data = pdata;
+   pdev = acpi_create_platform_device(adev);
+   if (!IS_ERR_OR_NULL(pdev))
+   return 1;
+
+   ret = PTR_ERR(pdev);
+   adev->driver_data = NULL;
+
+ err_out:
+   kfree(pdata);
+   return ret;
+}
+
+static int acpi_soc_platform_notify(struct notifier_block *nb,
+unsigned long action, void *data)
+{
+   struct platform_device *pdev = to_platform_device(data);
+   struct acpi_soc_dev_private_data *pdata;
+   struct acpi_device *adev;
+   struct acpi_soc *a_soc_entry;
+   const struct acpi_device_id *id = NULL;
+
+   list_for_each_entry(a_soc_entry, _soc_list, list) {
+   id = acpi_match_device(a_soc_entry->ids, >dev);
+   

[PATCH 1/2] acpi:soc: merge common codes for creating platform device

2014-12-03 Thread Ken Xue
This patch is supposed to deliver some common codes for AMD APD and
INTEL LPSS. It can help to convert some specific acpi devices to be
platform devices.

Signed-off-by: Ken Xue ken@amd.com
---
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_soc.c | 211 
 drivers/acpi/acpi_soc.h |  90 +
 3 files changed, 302 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_soc.c
 create mode 100644 drivers/acpi/acpi_soc.h

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..ae3397d 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_soc.c b/drivers/acpi/acpi_soc.c
new file mode 100644
index 000..25089a0
--- /dev/null
+++ b/drivers/acpi/acpi_soc.c
@@ -0,0 +1,211 @@
+/*
+ * ACPI SOC support for Intel Lynxpoint LPSS and AMD APD.
+ *
+ * Copyright (C) 2015, Intel Corporation  AMD Corporation
+ * Authors: Ken Xue ken@amd.com
+ * Mika Westerberg mika.westerb...@linux.intel.com
+ * Rafael J. Wysocki rafael.j.wyso...@intel.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/acpi.h
+#include linux/err.h
+#include linux/io.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+#include linux/delay.h
+#include linux/pm_domain.h
+
+#include internal.h
+#include acpi_soc.h
+
+ACPI_MODULE_NAME(acpi_soc);
+
+/* A list for all acpi soc device */
+static LIST_HEAD(a_soc_list);
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, r);
+}
+
+static int acpi_soc_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct acpi_soc_dev_desc *dev_desc;
+   struct acpi_soc_dev_private_data *pdata;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct acpi_soc_dev_desc *)id-driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(adev);
+   return IS_ERR_OR_NULL(pdev) ? PTR_ERR(pdev) : 1;
+   }
+   pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(resource_list);
+   ret = acpi_dev_get_resources(adev, resource_list, is_memory, NULL);
+   if (ret  0)
+   goto err_out;
+
+   list_for_each_entry(rentry, resource_list, node)
+   if (resource_type(rentry-res) == IORESOURCE_MEM) {
+   if (dev_desc-mem_size_override)
+   pdata-mmio_size = dev_desc-mem_size_override;
+   else
+   pdata-mmio_size = resource_size(rentry-res);
+   pdata-mmio_base = ioremap(rentry-res.start,
+  pdata-mmio_size);
+   break;
+   }
+
+   acpi_dev_free_resource_list(resource_list);
+
+   pdata-adev = adev;
+   pdata-dev_desc = dev_desc;
+
+   if (dev_desc-setup)
+   dev_desc-setup(pdata);
+
+   /*
+* This works around a known issue in ACPI tables where acpi soc devices
+* have _PS0 and _PS3 without _PSC (and no power resources), so
+* acpi_bus_init_power() will assume that the BIOS has put them into D0.
+*/
+   ret = acpi_device_fix_up_power(adev);
+   if (ret) {
+   /* Skip the device, but continue the namespace scan. */
+   ret = 0;
+   goto err_out;
+   }
+
+   adev-driver_data = pdata;
+   pdev = acpi_create_platform_device(adev);
+   if (!IS_ERR_OR_NULL(pdev))
+   return 1;
+
+   ret = PTR_ERR(pdev);
+   adev-driver_data = NULL;
+
+ err_out:
+   kfree(pdata);
+   return ret;
+}
+
+static int acpi_soc_platform_notify(struct notifier_block *nb,
+unsigned long action, void *data)
+{
+   struct platform_device *pdev = to_platform_device(data);
+   struct acpi_soc_dev_private_data *pdata;
+   struct acpi_device *adev;
+   struct acpi_soc *a_soc_entry;
+   const struct acpi_device_id *id = NULL

[PATCH 2/2] acpi:apd:add AMD ACPI2Platform device support

2014-12-03 Thread Ken Xue
This is a new feature to interpret AMD specific ACPI device to
platform device such as I2C, UART found on AMD CZ and later
chipsets. It based on INTEL LPSS and acpi soc.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig| 11 +++
 drivers/acpi/Makefile   |  2 +-
 drivers/acpi/acpi_apd.c | 82 +
 drivers/acpi/internal.h |  6 
 drivers/acpi/scan.c |  1 +
 5 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..6402c79f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index ae3397d..b07003a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_soc.o acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..9afc144
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,82 @@
+/*
+ * AMD ACPI support for  ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/acpi.h
+#include linux/clk.h
+#include linux/clkdev.h
+#include linux/clk-provider.h
+#include linux/err.h
+#include linux/io.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+
+#include internal.h
+#include acpi_soc.h
+
+struct acpi_soc asoc;
+
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+#define APD_ADDR(desc) ((unsigned long)desc)
+
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-clk)
+   return 0;
+
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev,
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT,
+   dev_desc-fixed_clk_rate);
+   dev_desc-clk = clk;
+   clk_register_clkdev(clk, NULL, dev_name(pdata-adev-dev));
+   }
+
+   return 0;
+}
+
+static struct acpi_soc_dev_desc cz_i2c_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 13300,
+};
+
+static struct acpi_soc_dev_desc cz_uart_desc = {
+   .setup = acpi_apd_setup,
+   .fixed_clk_rate = 4800,
+};
+
+#else
+
+#define APD_ADDR(desc) (0UL)
+
+#endif /* CONFIG_X86_AMD_PLATFORM_DEVICE */
+
+static struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { AMD0010, APD_ADDR(cz_i2c_desc) },
+   { AMD0020, APD_ADDR(cz_uart_desc) },
+   { }
+};
+
+
+void __init acpi_apd_init(void)
+{
+   asoc.ids = acpi_apd_device_ids;
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+   register_acpi_soc(asoc, false);
+#else
+   register_acpi_soc(asoc, true);
+#endif /*CONFIG_X86_AMD_PLATFORM_DEVICE*/
+}
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 447f6d6..c8a0e8e 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -68,6 +68,12 @@ static inline void acpi_debugfs_init(void) { return; }
 #endif
 void acpi_lpss_init(void);
 
+#ifdef CONFIG_X86_AMD_PLATFORM_DEVICE
+void acpi_apd_init(void);
+#else
+static inline void acpi_apd_init(void) {}
+#endif
+
 acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
 bool acpi_queue_hotplug_work(struct work_struct *work);
 void acpi_device_hotplug(struct acpi_device *adev, u32 src);
diff --git a/drivers/acpi/scan.c b/drivers/acpi

Re: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2014-11-27 Thread Ken Xue
On Thu, 2014-11-27 at 13:46 +0200, Mika Westerberg wrote:
> On Wed, Nov 26, 2014 at 06:31:38PM +0800, Ken Xue wrote:
> > On Monday, 2014-11-24 at 02:47 +0100, Rafael J. Wysocki wrote:
> > > On Monday, November 24, 2014 01:02:30 AM Xue, Ken wrote:
> > > > 
> > > > On Tuesday, November 18, 2014 01:58:11 PM Ken Xue wrote:
> > > > > This new feature is to interpret AMD specific ACPI device to platform 
> > > > > device such as I2C, UART found on AMD CZ and later chipsets. It is 
> > > > > based on example INTEL LPSS. Now, it can support AMD I2C & UART.
> > > > > 
> > > > > Signed-off-by: Ken Xue 
> > > > > Signed-off-by: Jeff Wu 
> > > > 
> > > > Generally speaking, this seems to duplicate much code from acpi_lpss 
> > > > which should be re-used instead.  What about moving the code that will 
> > > > be common between acpi_lpss and the new driver into a new file (say 
> > > > acpi_soc.c)?
> > > > 
> > > > Also, you need to avoid automatic creation of platform devices when 
> > > > !X86_AMD_PLATFORM_DEVICE in analogy with what acpi_lpss does, or bad 
> > > > things will happen.
> > > > 
> > > > [ken] sounds fair enough.  Let me take action to merge drivers to 
> > > > acpi_soc.c ? or you have other plan?
> > > 
> > > I'd prefer the common code to reside in one file (or one .c file and one 
> > > header
> > > file), and the driver-specific code to stay in separate per-driver files.
> > > 
> > [Ken] I wrote a proto type for acpi_soc.c. please help to confirm if it
> > can match your ideal. if yes, i will submit a new patch after do more
> > test and refine codes. I think it will impact lpss driver greatly, even
> > i have taken it into account. below codes is for acpi_soc.c.
> 
> In general looks good. I have few comments though.
[Ken] thanks for your comments.

> > 
> > >From fc323fb7b3b4cbb79bda05ce3b1d6d8dfe5e883b Mon Sep 17 00:00:00 2001
> > From: Ken Xue 
> > Date: Wed, 26 Nov 2014 17:15:30 +0800
> > Subject: [PATCH] This is proto type for acpi_soc.
> > 
> > Signed-off-by: Ken Xue 
> > ---
> >  arch/x86/Kconfig|  11 +++
> >  drivers/acpi/Makefile   |   2 +-
> >  drivers/acpi/acpi_apd.c | 123 
> >  drivers/acpi/acpi_soc.c | 213
> > 
> 
> This is line-wrapped, please make sure when you submit the actual patch
> that it is formatted properly. Also you need proper changelog etc.
[Ken] sure. 

> > +#include "internal.h"
> > +#include "acpi_soc.h"
> > +
> > +struct acpi_soc asoc;
> 
> static?
> 
> Also Is "asoc" good name? That might get confused with Alsa SoC (ASoC).
[Ken] I will use "static", and change name to be a_soc.


> > +
> > +static struct acpi_soc_dev_desc cz_i2c_desc = {
> > +   .setup = acpi_apd_setup;
> > +   .fixed_clk_rate = 13300,
> 
> Oh, good so now we can get rid the hack we did for
> i2c-designware-platdrv.c with this commit:
> 
> a445900c906092f i2c: designware: Add support for AMD I2C controller
> 
> Since now you have means to pass clock to the driver.
> 
> Are you going to handle that driver as well?
[Ken]sure, thanks. this was one of reasons to create AMD APD.

> > +};
> > +
> > +static struct acpi_soc_dev_desc cz_uart_desc = {
> > +   .setup = acpi_apd_setup;
> > +   .fixed_clk_rate = 4800,
> > +};
> > +
> > +#else
> > +
> > +#define APD_ADDR(desc) (0UL)
> > +
> > +#endif /* CONFIG_X86_INTEL_LPSS */
> > +
> > +static struct acpi_device_id acpi_apd_device_ids[] = {
> 
> const?
[ken]No. "acpi_soc_dev_desc" may be modified later.

> > +   /* Generic apd devices */
> > +   { "AMD0010", APD_ADDR(cz_i2c_desc) },
> > +   { "AMD0020", APD_ADDR(cz_uart_desc) },
> > +   { }
> > +};
> > +
> > +#ifdef X86_AMD_PLATFORM_DEVICE
> > +
> > +static ssize_t apd_device_desc_show(struct device *dev,
> > +   struct device_attribute *attr, char *buf)
> > +{
> > +   int ret;
> > +   struct acpi_device *adev;
> > +   struct acpi_soc_dev_private_data *pdata;
> > +   struct acpi_soc_dev_desc *dev_desc;
> > +
> > +   ret = acpi_bus_get_device(ACPI_HANDLE(dev), );
> > +   if (WARN_ON(ret))
> > +   return ret;
> > +
> > +   pdata = acpi_driver_data(adev);
> > +   if (WARN_ON(!pdat

Re: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2014-11-27 Thread Ken Xue
On Thu, 2014-11-27 at 13:46 +0200, Mika Westerberg wrote:
 On Wed, Nov 26, 2014 at 06:31:38PM +0800, Ken Xue wrote:
  On Monday, 2014-11-24 at 02:47 +0100, Rafael J. Wysocki wrote:
   On Monday, November 24, 2014 01:02:30 AM Xue, Ken wrote:

On Tuesday, November 18, 2014 01:58:11 PM Ken Xue wrote:
 This new feature is to interpret AMD specific ACPI device to platform 
 device such as I2C, UART found on AMD CZ and later chipsets. It is 
 based on example INTEL LPSS. Now, it can support AMD I2C  UART.
 
 Signed-off-by: Ken Xue ken@amd.com
 Signed-off-by: Jeff Wu jeff...@amd.com

Generally speaking, this seems to duplicate much code from acpi_lpss 
which should be re-used instead.  What about moving the code that will 
be common between acpi_lpss and the new driver into a new file (say 
acpi_soc.c)?

Also, you need to avoid automatic creation of platform devices when 
!X86_AMD_PLATFORM_DEVICE in analogy with what acpi_lpss does, or bad 
things will happen.

[ken] sounds fair enough.  Let me take action to merge drivers to 
acpi_soc.c ? or you have other plan?
   
   I'd prefer the common code to reside in one file (or one .c file and one 
   header
   file), and the driver-specific code to stay in separate per-driver files.
   
  [Ken] I wrote a proto type for acpi_soc.c. please help to confirm if it
  can match your ideal. if yes, i will submit a new patch after do more
  test and refine codes. I think it will impact lpss driver greatly, even
  i have taken it into account. below codes is for acpi_soc.c.
 
 In general looks good. I have few comments though.
[Ken] thanks for your comments.

  
  From fc323fb7b3b4cbb79bda05ce3b1d6d8dfe5e883b Mon Sep 17 00:00:00 2001
  From: Ken Xue ken@amd.com
  Date: Wed, 26 Nov 2014 17:15:30 +0800
  Subject: [PATCH] This is proto type for acpi_soc.
  
  Signed-off-by: Ken Xue ken@amd.com
  ---
   arch/x86/Kconfig|  11 +++
   drivers/acpi/Makefile   |   2 +-
   drivers/acpi/acpi_apd.c | 123 
   drivers/acpi/acpi_soc.c | 213
  
 
 This is line-wrapped, please make sure when you submit the actual patch
 that it is formatted properly. Also you need proper changelog etc.
[Ken] sure. 

  +#include internal.h
  +#include acpi_soc.h
  +
  +struct acpi_soc asoc;
 
 static?
 
 Also Is asoc good name? That might get confused with Alsa SoC (ASoC).
[Ken] I will use static, and change name to be a_soc.


  +
  +static struct acpi_soc_dev_desc cz_i2c_desc = {
  +   .setup = acpi_apd_setup;
  +   .fixed_clk_rate = 13300,
 
 Oh, good so now we can get rid the hack we did for
 i2c-designware-platdrv.c with this commit:
 
 a445900c906092f i2c: designware: Add support for AMD I2C controller
 
 Since now you have means to pass clock to the driver.
 
 Are you going to handle that driver as well?
[Ken]sure, thanks. this was one of reasons to create AMD APD.

  +};
  +
  +static struct acpi_soc_dev_desc cz_uart_desc = {
  +   .setup = acpi_apd_setup;
  +   .fixed_clk_rate = 4800,
  +};
  +
  +#else
  +
  +#define APD_ADDR(desc) (0UL)
  +
  +#endif /* CONFIG_X86_INTEL_LPSS */
  +
  +static struct acpi_device_id acpi_apd_device_ids[] = {
 
 const?
[ken]No. acpi_soc_dev_desc may be modified later.

  +   /* Generic apd devices */
  +   { AMD0010, APD_ADDR(cz_i2c_desc) },
  +   { AMD0020, APD_ADDR(cz_uart_desc) },
  +   { }
  +};
  +
  +#ifdef X86_AMD_PLATFORM_DEVICE
  +
  +static ssize_t apd_device_desc_show(struct device *dev,
  +   struct device_attribute *attr, char *buf)
  +{
  +   int ret;
  +   struct acpi_device *adev;
  +   struct acpi_soc_dev_private_data *pdata;
  +   struct acpi_soc_dev_desc *dev_desc;
  +
  +   ret = acpi_bus_get_device(ACPI_HANDLE(dev), adev);
  +   if (WARN_ON(ret))
  +   return ret;
  +
  +   pdata = acpi_driver_data(adev);
  +   if (WARN_ON(!pdata || !pdata-dev_desc))
  +   return -ENODEV;
  +   
  +   dev_desc = pdata-dev_desc;
  +   if (dev_desc-fixed_clk_rate)
  +   return sprintf(buf, Required fix rate clk %s: %ld\n,
  +   dev_desc-clk-name,
  +   dev_desc-fixed_clk_rate);
  +   else
  +   return sprintf(buf, No need clk\n);
  +}
  +
  +static DEVICE_ATTR(device_desc, S_IRUSR, apd_device_desc_show, NULL);
  +
  +static struct attribute *apd_attrs[] = {
  +   dev_attr_device_desc.attr,
  +   NULL,
  +};
  +
  +static struct attribute_group apd_attr_group = {
  +   .attrs = apd_attrs,
  +   .name = apd,
  +};
 
 This requires updating sysfs ABI but then again, do you really need the
 above? And does it belong to sysfs in the first place?
[Ken] just want to output some debug information with sysfs. I think i
can add sysfs interface after APD has rich features in the future.

  
  +#include internal.h
  +#include acpi_soc.h
  +
  +
 
 Delete the extra blank line
[ken] got it.

 
  +   pdata-dev_desc

Re: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2014-11-26 Thread Ken Xue
On 一, 2014-11-24 at 02:47 +0100, Rafael J. Wysocki wrote:
> On Monday, November 24, 2014 01:02:30 AM Xue, Ken wrote:
> > 
> > On Tuesday, November 18, 2014 01:58:11 PM Ken Xue wrote:
> > > This new feature is to interpret AMD specific ACPI device to platform 
> > > device such as I2C, UART found on AMD CZ and later chipsets. It is 
> > > based on example INTEL LPSS. Now, it can support AMD I2C & UART.
> > > 
> > > Signed-off-by: Ken Xue 
> > > Signed-off-by: Jeff Wu 
> > 
> > Generally speaking, this seems to duplicate much code from acpi_lpss which 
> > should be re-used instead.  What about moving the code that will be common 
> > between acpi_lpss and the new driver into a new file (say acpi_soc.c)?
> > 
> > Also, you need to avoid automatic creation of platform devices when 
> > !X86_AMD_PLATFORM_DEVICE in analogy with what acpi_lpss does, or bad things 
> > will happen.
> > 
> > [ken] sounds fair enough.  Let me take action to merge drivers to 
> > acpi_soc.c ? or you have other plan?
> 
> I'd prefer the common code to reside in one file (or one .c file and one 
> header
> file), and the driver-specific code to stay in separate per-driver files.
> 
[Ken] I wrote a proto type for acpi_soc.c. please help to confirm if it
can match your ideal. if yes, i will submit a new patch after do more
test and refine codes. I think it will impact lpss driver greatly, even
i have taken it into account. below codes is for acpi_soc.c.


>From fc323fb7b3b4cbb79bda05ce3b1d6d8dfe5e883b Mon Sep 17 00:00:00 2001
From: Ken Xue 
Date: Wed, 26 Nov 2014 17:15:30 +0800
Subject: [PATCH] This is proto type for acpi_soc.

Signed-off-by: Ken Xue 
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 123 
 drivers/acpi/acpi_soc.c | 213

 drivers/acpi/acpi_soc.h |  91 +
 drivers/acpi/internal.h |   6 ++
 drivers/acpi/scan.c |   1 +
 7 files changed, 446 insertions(+), 1 deletion(-)
 create mode 100755 drivers/acpi/acpi_apd.c
 create mode 100755 drivers/acpi/acpi_soc.c
 create mode 100755 drivers/acpi/acpi_soc.h

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..6402c79f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..b07003a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) +=
processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100755
index 000..c7e916b
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,123 @@
+/*
+ * AMD ACPI support for  ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue 
+ * Wu, Jeff 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+#include "acpi_soc.h"
+
+struct acpi_soc asoc;
+
+#ifdef X86_AMD_PLATFORM_DEVICE
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc->clk)
+   return 0;
+   
+   if (dev_desc->fixed_clk_rate) {
+   clk = clk_register_fixed_rate(>adev->dev, 
+   dev_name(>adev->dev),
+   

Re: [PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2014-11-26 Thread Ken Xue
On 一, 2014-11-24 at 02:47 +0100, Rafael J. Wysocki wrote:
 On Monday, November 24, 2014 01:02:30 AM Xue, Ken wrote:
  
  On Tuesday, November 18, 2014 01:58:11 PM Ken Xue wrote:
   This new feature is to interpret AMD specific ACPI device to platform 
   device such as I2C, UART found on AMD CZ and later chipsets. It is 
   based on example INTEL LPSS. Now, it can support AMD I2C  UART.
   
   Signed-off-by: Ken Xue ken@amd.com
   Signed-off-by: Jeff Wu jeff...@amd.com
  
  Generally speaking, this seems to duplicate much code from acpi_lpss which 
  should be re-used instead.  What about moving the code that will be common 
  between acpi_lpss and the new driver into a new file (say acpi_soc.c)?
  
  Also, you need to avoid automatic creation of platform devices when 
  !X86_AMD_PLATFORM_DEVICE in analogy with what acpi_lpss does, or bad things 
  will happen.
  
  [ken] sounds fair enough.  Let me take action to merge drivers to 
  acpi_soc.c ? or you have other plan?
 
 I'd prefer the common code to reside in one file (or one .c file and one 
 header
 file), and the driver-specific code to stay in separate per-driver files.
 
[Ken] I wrote a proto type for acpi_soc.c. please help to confirm if it
can match your ideal. if yes, i will submit a new patch after do more
test and refine codes. I think it will impact lpss driver greatly, even
i have taken it into account. below codes is for acpi_soc.c.


From fc323fb7b3b4cbb79bda05ce3b1d6d8dfe5e883b Mon Sep 17 00:00:00 2001
From: Ken Xue ken@amd.com
Date: Wed, 26 Nov 2014 17:15:30 +0800
Subject: [PATCH] This is proto type for acpi_soc.

Signed-off-by: Ken Xue ken@amd.com
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   2 +-
 drivers/acpi/acpi_apd.c | 123 
 drivers/acpi/acpi_soc.c | 213

 drivers/acpi/acpi_soc.h |  91 +
 drivers/acpi/internal.h |   6 ++
 drivers/acpi/scan.c |   1 +
 7 files changed, 446 insertions(+), 1 deletion(-)
 create mode 100755 drivers/acpi/acpi_apd.c
 create mode 100755 drivers/acpi/acpi_soc.c
 create mode 100755 drivers/acpi/acpi_soc.h

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..6402c79f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..b07003a 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,7 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) +=
processor_pdc.o
 acpi-y += ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
-acpi-y += acpi_lpss.o
+acpi-y += acpi_soc.o acpi_lpss.o acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100755
index 000..c7e916b
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,123 @@
+/*
+ * AMD ACPI support for  ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Wu, Jeff jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/acpi.h
+#include linux/clk.h
+#include linux/clkdev.h
+#include linux/clk-provider.h
+#include linux/err.h
+#include linux/io.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+
+#include internal.h
+#include acpi_soc.h
+
+struct acpi_soc asoc;
+
+#ifdef X86_AMD_PLATFORM_DEVICE
+static int acpi_apd_setup(struct acpi_soc_dev_private_data *pdata)
+{
+   struct acpi_soc_dev_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   if (dev_desc-clk)
+   return 0;
+   
+   if (dev_desc-fixed_clk_rate) {
+   clk = clk_register_fixed_rate(pdata-adev-dev, 
+   dev_name(pdata-adev-dev),
+   NULL, CLK_IS_ROOT, dev_desc-rate

[PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2014-11-17 Thread Ken Xue
This new feature is to interpret AMD specific ACPI device to platform device
such as I2C, UART found on AMD CZ and later chipsets. It is based on example
INTEL LPSS. Now, it can support AMD I2C & UART.

Signed-off-by: Ken Xue 
Signed-off-by: Jeff Wu 
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   1 +
 drivers/acpi/acpi_apd.c | 245 
 drivers/acpi/internal.h |   6 ++
 drivers/acpi/scan.c |   1 +
 5 files changed, 264 insertions(+)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..6402c79f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool "AMD ACPI2Platform devices support"
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate "Intel SoC IOSF Sideband support for SoC platforms"
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..91fc1c2 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -41,6 +41,7 @@ acpi-y+= ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
 acpi-y += acpi_lpss.o
+acpi-$(CONFIG_X86_AMD_PLATFORM_DEVICE) += acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..994b7db
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,245 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue 
+ * Jeff Wu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+ACPI_MODULE_NAME("acpi_apd");
+struct apd_private_data;
+
+struct apd_device_desc {
+   bool clk_required;
+   bool fixed_root_clock;
+   const char *clk_name;
+   unsigned long   rate;
+   size_t prv_size_override;
+   void (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   void __iomem *mmio_base;
+   resource_size_t mmio_size;
+   struct clk *clk;
+   const struct apd_device_desc *dev_desc;
+};
+
+static struct apd_device_desc amd_i2c_desc = {
+   .clk_required = true,
+   .fixed_root_clock = true,
+   .clk_name = "i2c_clk",
+   .rate = 13300, /*(133 * 1000 * 1000)*/
+};
+
+static struct apd_device_desc amd_uart_desc = {
+   .clk_required = true,
+   .fixed_root_clock = true,
+   .clk_name = "uart_clk",
+   .rate = 4800,
+};
+
+static const struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { "AMD0010", (unsigned long)_i2c_desc },
+   { "AMD0020", (unsigned long)_uart_desc },
+   { }
+};
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, );
+}
+
+static int register_device_clock(struct acpi_device *adev,
+struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata->dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   clk = pdata->clk;
+   if (!clk && dev_desc->fixed_root_clock) {
+   clk = clk_register_fixed_rate(>dev, dev_name(>dev),
+ NULL, CLK_IS_ROOT, dev_desc->rate);
+   pdata->clk = clk;
+   clk_register_clkdev(clk, NULL, dev_name(>dev));
+   }
+
+   return 0;
+}
+
+static int acpi_apd_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct apd_device_desc *dev_desc;
+   struct apd_private_data *pdata;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct apd_device_desc *)id->driver_data;
+   if (!dev_desc) {
+   pdev = acpi_create_platform_device(ad

[PATCH] acpi:apd:add AMD ACPI2Platform device support for x86 system.

2014-11-17 Thread Ken Xue
This new feature is to interpret AMD specific ACPI device to platform device
such as I2C, UART found on AMD CZ and later chipsets. It is based on example
INTEL LPSS. Now, it can support AMD I2C  UART.

Signed-off-by: Ken Xue ken@amd.com
Signed-off-by: Jeff Wu jeff...@amd.com
---
 arch/x86/Kconfig|  11 +++
 drivers/acpi/Makefile   |   1 +
 drivers/acpi/acpi_apd.c | 245 
 drivers/acpi/internal.h |   6 ++
 drivers/acpi/scan.c |   1 +
 5 files changed, 264 insertions(+)
 create mode 100644 drivers/acpi/acpi_apd.c

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a67..6402c79f 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -495,6 +495,17 @@ config X86_INTEL_LPSS
  things like clock tree (common clock framework) and pincontrol
  which are needed by the LPSS peripheral drivers.
 
+config X86_AMD_PLATFORM_DEVICE
+   bool AMD ACPI2Platform devices support
+   depends on ACPI
+   select COMMON_CLK
+   select PINCTRL
+   ---help---
+ Select to interpret AMD specific ACPI device to platform device
+ such as I2C, UART found on AMD CARRIZO and later chipset. Selecting
+ this option enables things like clock tree (common clock framework)
+ and pinctrl.
+
 config IOSF_MBI
tristate Intel SoC IOSF Sideband support for SoC platforms
depends on PCI
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index c3b2fcb..91fc1c2 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -41,6 +41,7 @@ acpi-y+= ec.o
 acpi-$(CONFIG_ACPI_DOCK)   += dock.o
 acpi-y += pci_root.o pci_link.o pci_irq.o
 acpi-y += acpi_lpss.o
+acpi-$(CONFIG_X86_AMD_PLATFORM_DEVICE) += acpi_apd.o
 acpi-y += acpi_platform.o
 acpi-y += acpi_pnp.o
 acpi-y += int340x_thermal.o
diff --git a/drivers/acpi/acpi_apd.c b/drivers/acpi/acpi_apd.c
new file mode 100644
index 000..994b7db
--- /dev/null
+++ b/drivers/acpi/acpi_apd.c
@@ -0,0 +1,245 @@
+/*
+ * AMD ACPI support for ACPI2platform device.
+ *
+ * Copyright (c) 2014, AMD Corporation.
+ * Authors: Ken Xue ken@amd.com
+ * Jeff Wu jeff...@amd.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/acpi.h
+#include linux/clk.h
+#include linux/clkdev.h
+#include linux/clk-provider.h
+#include linux/err.h
+#include linux/io.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+
+#include internal.h
+
+ACPI_MODULE_NAME(acpi_apd);
+struct apd_private_data;
+
+struct apd_device_desc {
+   bool clk_required;
+   bool fixed_root_clock;
+   const char *clk_name;
+   unsigned long   rate;
+   size_t prv_size_override;
+   void (*setup)(struct apd_private_data *pdata);
+};
+
+struct apd_private_data {
+   void __iomem *mmio_base;
+   resource_size_t mmio_size;
+   struct clk *clk;
+   const struct apd_device_desc *dev_desc;
+};
+
+static struct apd_device_desc amd_i2c_desc = {
+   .clk_required = true,
+   .fixed_root_clock = true,
+   .clk_name = i2c_clk,
+   .rate = 13300, /*(133 * 1000 * 1000)*/
+};
+
+static struct apd_device_desc amd_uart_desc = {
+   .clk_required = true,
+   .fixed_root_clock = true,
+   .clk_name = uart_clk,
+   .rate = 4800,
+};
+
+static const struct acpi_device_id acpi_apd_device_ids[] = {
+   /* Generic apd devices */
+   { AMD0010, (unsigned long)amd_i2c_desc },
+   { AMD0020, (unsigned long)amd_uart_desc },
+   { }
+};
+
+static int is_memory(struct acpi_resource *res, void *not_used)
+{
+   struct resource r;
+
+   return !acpi_dev_resource_memory(res, r);
+}
+
+static int register_device_clock(struct acpi_device *adev,
+struct apd_private_data *pdata)
+{
+   const struct apd_device_desc *dev_desc = pdata-dev_desc;
+   struct clk *clk = ERR_PTR(-ENODEV);
+
+   clk = pdata-clk;
+   if (!clk  dev_desc-fixed_root_clock) {
+   clk = clk_register_fixed_rate(adev-dev, dev_name(adev-dev),
+ NULL, CLK_IS_ROOT, dev_desc-rate);
+   pdata-clk = clk;
+   clk_register_clkdev(clk, NULL, dev_name(adev-dev));
+   }
+
+   return 0;
+}
+
+static int acpi_apd_create_device(struct acpi_device *adev,
+  const struct acpi_device_id *id)
+{
+   struct apd_device_desc *dev_desc;
+   struct apd_private_data *pdata;
+   struct resource_list_entry *rentry;
+   struct list_head resource_list;
+   struct platform_device *pdev;
+   int ret;
+
+   dev_desc = (struct apd_device_desc *)id-driver_data;
+   if (!dev_desc