[Freedreno] cleanup unused or almost unused IOMMU APIs and the FSL PAMU driver

2021-03-01 Thread Christoph Hellwig
Hi all,

there are a bunch of IOMMU APIs that are entirely unused, or only used as
a private communication channel between the FSL PAMU driver and it's only
consumer, the qbman portal driver.

So this series drops a huge chunk of entirely unused FSL PAMU
functionality, then drops all kinds of unused IOMMU APIs, and then
replaces what is left of the iommu_attrs with properly typed, smaller
and easier to use specific APIs.

Diffstat:
 arch/powerpc/include/asm/fsl_pamu_stash.h   |   12 
 drivers/gpu/drm/msm/adreno/adreno_gpu.c |2 
 drivers/iommu/amd/iommu.c   |   23 
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c |   85 ---
 drivers/iommu/arm/arm-smmu/arm-smmu.c   |  122 +---
 drivers/iommu/dma-iommu.c   |8 
 drivers/iommu/fsl_pamu.c|  264 --
 drivers/iommu/fsl_pamu.h|   10 
 drivers/iommu/fsl_pamu_domain.c |  694 ++--
 drivers/iommu/fsl_pamu_domain.h |   46 -
 drivers/iommu/intel/iommu.c |   55 --
 drivers/iommu/iommu.c   |   75 ---
 drivers/soc/fsl/qbman/qman_portal.c |   56 --
 drivers/vfio/vfio_iommu_type1.c |   31 -
 drivers/vhost/vdpa.c|   10 
 include/linux/iommu.h   |   81 ---
 16 files changed, 214 insertions(+), 1360 deletions(-)
___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 01/17] iommu: remove the unused domain_window_disable method

2021-03-01 Thread Christoph Hellwig
domain_window_disable is wired up by fsl_pamu, but never actually called.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 48 -
 include/linux/iommu.h   |  2 --
 2 files changed, 50 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index b2110767caf49c..53380cf1fa452f 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -473,53 +473,6 @@ static int update_domain_mapping(struct fsl_dma_domain 
*dma_domain, u32 wnd_nr)
return ret;
 }
 
-static int disable_domain_win(struct fsl_dma_domain *dma_domain, u32 wnd_nr)
-{
-   struct device_domain_info *info;
-   int ret = 0;
-
-   list_for_each_entry(info, &dma_domain->devices, link) {
-   if (dma_domain->win_cnt == 1 && dma_domain->enabled) {
-   ret = pamu_disable_liodn(info->liodn);
-   if (!ret)
-   dma_domain->enabled = 0;
-   } else {
-   ret = pamu_disable_spaace(info->liodn, wnd_nr);
-   }
-   }
-
-   return ret;
-}
-
-static void fsl_pamu_window_disable(struct iommu_domain *domain, u32 wnd_nr)
-{
-   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-   unsigned long flags;
-   int ret;
-
-   spin_lock_irqsave(&dma_domain->domain_lock, flags);
-   if (!dma_domain->win_arr) {
-   pr_debug("Number of windows not configured\n");
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-   return;
-   }
-
-   if (wnd_nr >= dma_domain->win_cnt) {
-   pr_debug("Invalid window index\n");
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-   return;
-   }
-
-   if (dma_domain->win_arr[wnd_nr].valid) {
-   ret = disable_domain_win(dma_domain, wnd_nr);
-   if (!ret) {
-   dma_domain->win_arr[wnd_nr].valid = 0;
-   dma_domain->mapped--;
-   }
-   }
-
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-}
 
 static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr,
  phys_addr_t paddr, u64 size, int prot)
@@ -1032,7 +985,6 @@ static const struct iommu_ops fsl_pamu_ops = {
.attach_dev = fsl_pamu_attach_device,
.detach_dev = fsl_pamu_detach_device,
.domain_window_enable = fsl_pamu_window_enable,
-   .domain_window_disable = fsl_pamu_window_disable,
.iova_to_phys   = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
.domain_get_attr = fsl_pamu_get_domain_attr,
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 5e7fe519430af4..47c8b318d8f523 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -209,7 +209,6 @@ struct iommu_iotlb_gather {
  * @put_resv_regions: Free list of reserved regions for a device
  * @apply_resv_region: Temporary helper call-back for iova reserved ranges
  * @domain_window_enable: Configure and enable a particular window for a domain
- * @domain_window_disable: Disable a particular window for a domain
  * @of_xlate: add OF master IDs to iommu grouping
  * @is_attach_deferred: Check if domain attach should be deferred from iommu
  *  driver init to device driver init (default no)
@@ -270,7 +269,6 @@ struct iommu_ops {
/* Window handling functions */
int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
phys_addr_t paddr, u64 size, int prot);
-   void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
 
int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
bool (*is_attach_deferred)(struct iommu_domain *domain, struct device 
*dev);
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 02/17] iommu/fsl_pamu: remove fsl_pamu_get_domain_attr

2021-03-01 Thread Christoph Hellwig
None of the values returned by this function are ever queried.  Also
remove the DOMAIN_ATTR_FSL_PAMUV1 enum value that is not otherwise used.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 30 --
 include/linux/iommu.h   |  4 
 2 files changed, 34 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 53380cf1fa452f..e587ec43f7e750 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -832,35 +832,6 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain 
*domain,
return ret;
 }
 
-static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
-   enum iommu_attr attr_type, void *data)
-{
-   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-   int ret = 0;
-
-   switch (attr_type) {
-   case DOMAIN_ATTR_FSL_PAMU_STASH:
-   memcpy(data, &dma_domain->dma_stash,
-  sizeof(struct pamu_stash_attribute));
-   break;
-   case DOMAIN_ATTR_FSL_PAMU_ENABLE:
-   *(int *)data = dma_domain->enabled;
-   break;
-   case DOMAIN_ATTR_FSL_PAMUV1:
-   *(int *)data = DOMAIN_ATTR_FSL_PAMUV1;
-   break;
-   case DOMAIN_ATTR_WINDOWS:
-   *(u32 *)data = dma_domain->win_cnt;
-   break;
-   default:
-   pr_debug("Unsupported attribute type\n");
-   ret = -EINVAL;
-   break;
-   }
-
-   return ret;
-}
-
 static struct iommu_group *get_device_iommu_group(struct device *dev)
 {
struct iommu_group *group;
@@ -987,7 +958,6 @@ static const struct iommu_ops fsl_pamu_ops = {
.domain_window_enable = fsl_pamu_window_enable,
.iova_to_phys   = fsl_pamu_iova_to_phys,
.domain_set_attr = fsl_pamu_set_domain_attr,
-   .domain_get_attr = fsl_pamu_get_domain_attr,
.probe_device   = fsl_pamu_probe_device,
.release_device = fsl_pamu_release_device,
.device_group   = fsl_pamu_device_group,
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 47c8b318d8f523..52874ae164dd60 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -104,9 +104,6 @@ enum iommu_cap {
  *  -the actual size of the mapped region of a window must be power
  *   of 2 starting with 4KB and physical address must be naturally
  *   aligned.
- * DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints.
- * The caller can invoke iommu_domain_get_attr to check if the underlying
- * iommu implementation supports these constraints.
  */
 
 enum iommu_attr {
@@ -115,7 +112,6 @@ enum iommu_attr {
DOMAIN_ATTR_WINDOWS,
DOMAIN_ATTR_FSL_PAMU_STASH,
DOMAIN_ATTR_FSL_PAMU_ENABLE,
-   DOMAIN_ATTR_FSL_PAMUV1,
DOMAIN_ATTR_NESTING,/* two stages of translation */
DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE,
DOMAIN_ATTR_IO_PGTABLE_CFG,
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 03/17] iommu/fsl_pamu: remove support for setting DOMAIN_ATTR_GEOMETRY

2021-03-01 Thread Christoph Hellwig
The default geometry is the same as the one set by qman_port given
that FSL_PAMU depends on having 64-bit physical and thus DMA addresses.

Remove the support to update the geometry and remove the now pointless
geom_size field.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 55 +++--
 drivers/iommu/fsl_pamu_domain.h |  6 
 drivers/soc/fsl/qbman/qman_portal.c | 12 ---
 3 files changed, 5 insertions(+), 68 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index e587ec43f7e750..7bd08ddad07779 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -62,7 +62,7 @@ static phys_addr_t get_phys_addr(struct fsl_dma_domain 
*dma_domain, dma_addr_t i
 
geom = &dma_domain->iommu_domain.geometry;
 
-   if (!win_cnt || !dma_domain->geom_size) {
+   if (!win_cnt) {
pr_debug("Number of windows/geometry not configured for the 
domain\n");
return 0;
}
@@ -72,7 +72,7 @@ static phys_addr_t get_phys_addr(struct fsl_dma_domain 
*dma_domain, dma_addr_t i
dma_addr_t subwin_iova;
u32 wnd;
 
-   subwin_size = dma_domain->geom_size >> ilog2(win_cnt);
+   subwin_size = (geom->aperture_end + 1) >> ilog2(win_cnt);
subwin_iova = iova & ~(subwin_size - 1);
wnd = (subwin_iova - geom->aperture_start) >> 
ilog2(subwin_size);
win_ptr = &dma_domain->win_arr[wnd];
@@ -234,7 +234,7 @@ static int pamu_set_liodn(int liodn, struct device *dev,
get_ome_index(&omi_index, dev);
 
window_addr = geom_attr->aperture_start;
-   window_size = dma_domain->geom_size;
+   window_size = geom_attr->aperture_end + 1;
 
spin_lock_irqsave(&iommu_lock, flags);
ret = pamu_disable_liodn(liodn);
@@ -303,7 +303,6 @@ static struct fsl_dma_domain *iommu_alloc_dma_domain(void)
domain->stash_id = ~(u32)0;
domain->snoop_id = ~(u32)0;
domain->win_cnt = pamu_get_max_subwin_cnt();
-   domain->geom_size = 0;
 
INIT_LIST_HEAD(&domain->devices);
 
@@ -502,7 +501,8 @@ static int fsl_pamu_window_enable(struct iommu_domain 
*domain, u32 wnd_nr,
return -EINVAL;
}
 
-   win_size = dma_domain->geom_size >> ilog2(dma_domain->win_cnt);
+   win_size = (domain->geometry.aperture_end + 1) >>
+   ilog2(dma_domain->win_cnt);
if (size > win_size) {
pr_debug("Invalid window size\n");
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
@@ -665,41 +665,6 @@ static void fsl_pamu_detach_device(struct iommu_domain 
*domain,
pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
 }
 
-static  int configure_domain_geometry(struct iommu_domain *domain, void *data)
-{
-   struct iommu_domain_geometry *geom_attr = data;
-   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-   dma_addr_t geom_size;
-   unsigned long flags;
-
-   geom_size = geom_attr->aperture_end - geom_attr->aperture_start + 1;
-   /*
-* Sanity check the geometry size. Also, we do not support
-* DMA outside of the geometry.
-*/
-   if (check_size(geom_size, geom_attr->aperture_start) ||
-   !geom_attr->force_aperture) {
-   pr_debug("Invalid PAMU geometry attributes\n");
-   return -EINVAL;
-   }
-
-   spin_lock_irqsave(&dma_domain->domain_lock, flags);
-   if (dma_domain->enabled) {
-   pr_debug("Can't set geometry attributes as domain is active\n");
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-   return  -EBUSY;
-   }
-
-   /* Copy the domain geometry information */
-   memcpy(&domain->geometry, geom_attr,
-  sizeof(struct iommu_domain_geometry));
-   dma_domain->geom_size = geom_size;
-
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-
-   return 0;
-}
-
 /* Set the domain stash attribute */
 static int configure_domain_stash(struct fsl_dma_domain *dma_domain, void 
*data)
 {
@@ -769,13 +734,6 @@ static int fsl_pamu_set_windows(struct iommu_domain 
*domain, u32 w_count)
return  -EBUSY;
}
 
-   /* Ensure that the geometry has been set for the domain */
-   if (!dma_domain->geom_size) {
-   pr_debug("Please configure geometry before setting the number 
of windows\n");
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-   return -EINVAL;
-   }
-
/*
 * Ensure we have valid window count i.e. it should be less than
 * maximum permissible limit and should be a power of two.
@@ -811,9 +769,6 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain 
*domain,
int ret = 0;
 
switch (attr_type) {
-   case DOMAIN_ATTR_GEOME

[Freedreno] [PATCH 04/17] iommu/fsl_pamu: merge iommu_alloc_dma_domain into fsl_pamu_domain_alloc

2021-03-01 Thread Christoph Hellwig
Keep the functionality to allocate the domain together.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 34 ++---
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 7bd08ddad07779..a4da5597755d3d 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -292,25 +292,6 @@ static int check_size(u64 size, dma_addr_t iova)
return 0;
 }
 
-static struct fsl_dma_domain *iommu_alloc_dma_domain(void)
-{
-   struct fsl_dma_domain *domain;
-
-   domain = kmem_cache_zalloc(fsl_pamu_domain_cache, GFP_KERNEL);
-   if (!domain)
-   return NULL;
-
-   domain->stash_id = ~(u32)0;
-   domain->snoop_id = ~(u32)0;
-   domain->win_cnt = pamu_get_max_subwin_cnt();
-
-   INIT_LIST_HEAD(&domain->devices);
-
-   spin_lock_init(&domain->domain_lock);
-
-   return domain;
-}
-
 static void remove_device_ref(struct device_domain_info *info, u32 win_cnt)
 {
unsigned long flags;
@@ -412,12 +393,17 @@ static struct iommu_domain 
*fsl_pamu_domain_alloc(unsigned type)
if (type != IOMMU_DOMAIN_UNMANAGED)
return NULL;
 
-   dma_domain = iommu_alloc_dma_domain();
-   if (!dma_domain) {
-   pr_debug("dma_domain allocation failed\n");
+   dma_domain = kmem_cache_zalloc(fsl_pamu_domain_cache, GFP_KERNEL);
+   if (!dma_domain)
return NULL;
-   }
-   /* defaul geometry 64 GB i.e. maximum system address */
+
+   dma_domain->stash_id = ~(u32)0;
+   dma_domain->snoop_id = ~(u32)0;
+   dma_domain->win_cnt = pamu_get_max_subwin_cnt();
+   INIT_LIST_HEAD(&dma_domain->devices);
+   spin_lock_init(&dma_domain->domain_lock);
+
+   /* default geometry 64 GB i.e. maximum system address */
dma_domain->iommu_domain. geometry.aperture_start = 0;
dma_domain->iommu_domain.geometry.aperture_end = (1ULL << 36) - 1;
dma_domain->iommu_domain.geometry.force_aperture = true;
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 05/17] iommu/fsl_pamu: remove support for multiple windows

2021-03-01 Thread Christoph Hellwig
The only domains allocated forces use of a single window.  Remove all
the code related to multiple window support, as well as the need for
qman_portal to force a single window.

Remove the now unused DOMAIN_ATTR_WINDOWS iommu_attr.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu.c| 264 +-
 drivers/iommu/fsl_pamu.h|  10 +-
 drivers/iommu/fsl_pamu_domain.c | 275 +---
 drivers/iommu/fsl_pamu_domain.h |  12 +-
 drivers/soc/fsl/qbman/qman_portal.c |   7 -
 include/linux/iommu.h   |   1 -
 6 files changed, 59 insertions(+), 510 deletions(-)

diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c
index b9a974d9783113..3e1647cd5ad47a 100644
--- a/drivers/iommu/fsl_pamu.c
+++ b/drivers/iommu/fsl_pamu.c
@@ -63,19 +63,6 @@ static const struct of_device_id l3_device_ids[] = {
 /* maximum subwindows permitted per liodn */
 static u32 max_subwindow_count;
 
-/* Pool for fspi allocation */
-static struct gen_pool *spaace_pool;
-
-/**
- * pamu_get_max_subwin_cnt() - Return the maximum supported
- * subwindow count per liodn.
- *
- */
-u32 pamu_get_max_subwin_cnt(void)
-{
-   return max_subwindow_count;
-}
-
 /**
  * pamu_get_ppaace() - Return the primary PACCE
  * @liodn: liodn PAACT index for desired PAACE
@@ -155,13 +142,6 @@ static unsigned int map_addrspace_size_to_wse(phys_addr_t 
addrspace_size)
return fls64(addrspace_size) - 2;
 }
 
-/* Derive the PAACE window count encoding for the subwindow count */
-static unsigned int map_subwindow_cnt_to_wce(u32 subwindow_cnt)
-{
-   /* window count is 2^(WCE+1) bytes */
-   return __ffs(subwindow_cnt) - 1;
-}
-
 /*
  * Set the PAACE type as primary and set the coherency required domain
  * attribute
@@ -174,89 +154,11 @@ static void pamu_init_ppaace(struct paace *ppaace)
   PAACE_M_COHERENCE_REQ);
 }
 
-/*
- * Set the PAACE type as secondary and set the coherency required domain
- * attribute.
- */
-static void pamu_init_spaace(struct paace *spaace)
-{
-   set_bf(spaace->addr_bitfields, PAACE_AF_PT, PAACE_PT_SECONDARY);
-   set_bf(spaace->domain_attr.to_host.coherency_required, PAACE_DA_HOST_CR,
-  PAACE_M_COHERENCE_REQ);
-}
-
-/*
- * Return the spaace (corresponding to the secondary window index)
- * for a particular ppaace.
- */
-static struct paace *pamu_get_spaace(struct paace *paace, u32 wnum)
-{
-   u32 subwin_cnt;
-   struct paace *spaace = NULL;
-
-   subwin_cnt = 1UL << (get_bf(paace->impl_attr, PAACE_IA_WCE) + 1);
-
-   if (wnum < subwin_cnt)
-   spaace = &spaact[paace->fspi + wnum];
-   else
-   pr_debug("secondary paace out of bounds\n");
-
-   return spaace;
-}
-
-/**
- * pamu_get_fspi_and_allocate() - Allocates fspi index and reserves subwindows
- *required for primary PAACE in the secondary
- *PAACE table.
- * @subwin_cnt: Number of subwindows to be reserved.
- *
- * A PPAACE entry may have a number of associated subwindows. A subwindow
- * corresponds to a SPAACE entry in the SPAACT table. Each PAACE entry stores
- * the index (fspi) of the first SPAACE entry in the SPAACT table. This
- * function returns the index of the first SPAACE entry. The remaining
- * SPAACE entries are reserved contiguously from that index.
- *
- * Returns a valid fspi index in the range of 0 - SPAACE_NUMBER_ENTRIES on 
success.
- * If no SPAACE entry is available or the allocator can not reserve the 
required
- * number of contiguous entries function returns ULONG_MAX indicating a 
failure.
- *
- */
-static unsigned long pamu_get_fspi_and_allocate(u32 subwin_cnt)
-{
-   unsigned long spaace_addr;
-
-   spaace_addr = gen_pool_alloc(spaace_pool, subwin_cnt * sizeof(struct 
paace));
-   if (!spaace_addr)
-   return ULONG_MAX;
-
-   return (spaace_addr - (unsigned long)spaact) / (sizeof(struct paace));
-}
-
-/* Release the subwindows reserved for a particular LIODN */
-void pamu_free_subwins(int liodn)
-{
-   struct paace *ppaace;
-   u32 subwin_cnt, size;
-
-   ppaace = pamu_get_ppaace(liodn);
-   if (!ppaace) {
-   pr_debug("Invalid liodn entry\n");
-   return;
-   }
-
-   if (get_bf(ppaace->addr_bitfields, PPAACE_AF_MW)) {
-   subwin_cnt = 1UL << (get_bf(ppaace->impl_attr, PAACE_IA_WCE) + 
1);
-   size = (subwin_cnt - 1) * sizeof(struct paace);
-   gen_pool_free(spaace_pool, (unsigned 
long)&spaact[ppaace->fspi], size);
-   set_bf(ppaace->addr_bitfields, PPAACE_AF_MW, 0);
-   }
-}
-
 /*
  * Function used for updating stash destination for the coressponding
  * LIODN.
  */
-int  pamu_update_paace_stash(int liodn, u32 subwin, u32 value)
+int pamu_update_paace_stash(int liodn, u32 value)
 {
struct paace *paace;
 
@@ -265,11 +167,6 @@ int  pamu_update_paace_stash(int liodn, u32 s

[Freedreno] [PATCH 06/17] iommu/fsl_pamu: remove ->domain_window_enable

2021-03-01 Thread Christoph Hellwig
The only thing that fsl_pamu_window_enable does for the current caller
is to fill in the prot value in the only dma_window structure, and to
propagate a few values from the iommu_domain_geometry struture into the
dma_window.  Remove the dma_window entirely, hardcode the prot value and
otherwise use the iommu_domain_geometry structure instead.

Remove the now unused ->domain_window_enable iommu method.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 182 +++-
 drivers/iommu/fsl_pamu_domain.h |  17 ---
 drivers/iommu/iommu.c   |  11 --
 drivers/soc/fsl/qbman/qman_portal.c |   7 --
 include/linux/iommu.h   |  17 ---
 5 files changed, 14 insertions(+), 220 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index e6bdd38fc18409..fd2bc88b690465 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -54,34 +54,18 @@ static int __init iommu_init_mempool(void)
return 0;
 }
 
-static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t 
iova)
-{
-   struct dma_window *win_ptr = &dma_domain->win_arr[0];
-   struct iommu_domain_geometry *geom;
-
-   geom = &dma_domain->iommu_domain.geometry;
-
-   if (win_ptr->valid)
-   return win_ptr->paddr + (iova & (win_ptr->size - 1));
-
-   return 0;
-}
-
 /* Map the DMA window corresponding to the LIODN */
 static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain)
 {
int ret;
-   struct dma_window *wnd = &dma_domain->win_arr[0];
-   phys_addr_t wnd_addr = dma_domain->iommu_domain.geometry.aperture_start;
+   struct iommu_domain_geometry *geom = &dma_domain->iommu_domain.geometry;
unsigned long flags;
 
spin_lock_irqsave(&iommu_lock, flags);
-   ret = pamu_config_ppaace(liodn, wnd_addr,
-wnd->size,
-~(u32)0,
-wnd->paddr >> PAMU_PAGE_SHIFT,
-dma_domain->snoop_id, dma_domain->stash_id,
-wnd->prot);
+   ret = pamu_config_ppaace(liodn, geom->aperture_start,
+geom->aperture_end - 1, ~(u32)0,
+0, dma_domain->snoop_id, dma_domain->stash_id,
+PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE);
spin_unlock_irqrestore(&iommu_lock, flags);
if (ret)
pr_debug("PAACE configuration failed for liodn %d\n", liodn);
@@ -89,33 +73,6 @@ static int map_liodn(int liodn, struct fsl_dma_domain 
*dma_domain)
return ret;
 }
 
-/* Update window/subwindow mapping for the LIODN */
-static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 
wnd_nr)
-{
-   int ret;
-   struct dma_window *wnd = &dma_domain->win_arr[wnd_nr];
-   phys_addr_t wnd_addr;
-   unsigned long flags;
-
-   spin_lock_irqsave(&iommu_lock, flags);
-
-   wnd_addr = dma_domain->iommu_domain.geometry.aperture_start;
-
-   ret = pamu_config_ppaace(liodn, wnd_addr,
-wnd->size,
-~(u32)0,
-wnd->paddr >> PAMU_PAGE_SHIFT,
-dma_domain->snoop_id, dma_domain->stash_id,
-wnd->prot);
-   if (ret)
-   pr_debug("Window reconfiguration failed for liodn %d\n",
-liodn);
-
-   spin_unlock_irqrestore(&iommu_lock, flags);
-
-   return ret;
-}
-
 static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain,
  u32 val)
 {
@@ -172,26 +129,6 @@ static int pamu_set_liodn(int liodn, struct device *dev,
return ret;
 }
 
-static int check_size(u64 size, dma_addr_t iova)
-{
-   /*
-* Size must be a power of two and at least be equal
-* to PAMU page size.
-*/
-   if ((size & (size - 1)) || size < PAMU_PAGE_SIZE) {
-   pr_debug("Size too small or not a power of two\n");
-   return -EINVAL;
-   }
-
-   /* iova must be page size aligned */
-   if (iova & (size - 1)) {
-   pr_debug("Address is not aligned with window size\n");
-   return -EINVAL;
-   }
-
-   return 0;
-}
-
 static void remove_device_ref(struct device_domain_info *info)
 {
unsigned long flags;
@@ -257,13 +194,10 @@ static void attach_device(struct fsl_dma_domain 
*dma_domain, int liodn, struct d
 static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
 dma_addr_t iova)
 {
-   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-
if (iova < domain->geometry.aperture_start ||
iova > domain->geometry.aperture_end)
return 0;
-
-   return get_phys_addr(dma_do

[Freedreno] [PATCH 07/17] iommu/fsl_pamu: replace DOMAIN_ATTR_FSL_PAMU_STASH with a direct call

2021-03-01 Thread Christoph Hellwig
Add a fsl_pamu_configure_l1_stash API that qman_portal can call directly
instead of indirecting through the iommu attr API.

Signed-off-by: Christoph Hellwig 
---
 arch/powerpc/include/asm/fsl_pamu_stash.h | 12 +++-
 drivers/iommu/fsl_pamu_domain.c   | 16 +++-
 drivers/iommu/fsl_pamu_domain.h   |  2 --
 drivers/soc/fsl/qbman/qman_portal.c   | 18 +++---
 include/linux/iommu.h |  1 -
 5 files changed, 9 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/include/asm/fsl_pamu_stash.h 
b/arch/powerpc/include/asm/fsl_pamu_stash.h
index 30a31ad2123d86..c0fbadb70b5dad 100644
--- a/arch/powerpc/include/asm/fsl_pamu_stash.h
+++ b/arch/powerpc/include/asm/fsl_pamu_stash.h
@@ -7,6 +7,8 @@
 #ifndef __FSL_PAMU_STASH_H
 #define __FSL_PAMU_STASH_H
 
+struct iommu_domain;
+
 /* cache stash targets */
 enum pamu_stash_target {
PAMU_ATTR_CACHE_L1 = 1,
@@ -14,14 +16,6 @@ enum pamu_stash_target {
PAMU_ATTR_CACHE_L3,
 };
 
-/*
- * This attribute allows configuring stashig specific parameters
- * in the PAMU hardware.
- */
-
-struct pamu_stash_attribute {
-   u32 cpu;/* cpu number */
-   u32 cache;  /* cache to stash to: L1,L2,L3 */
-};
+int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu);
 
 #endif  /* __FSL_PAMU_STASH_H */
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index fd2bc88b690465..40eff4b7bc5d42 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -372,27 +372,20 @@ static void fsl_pamu_detach_device(struct iommu_domain 
*domain,
 }
 
 /* Set the domain stash attribute */
-static int configure_domain_stash(struct fsl_dma_domain *dma_domain, void 
*data)
+int fsl_pamu_configure_l1_stash(struct iommu_domain *domain, u32 cpu)
 {
-   struct pamu_stash_attribute *stash_attr = data;
+   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
unsigned long flags;
int ret;
 
spin_lock_irqsave(&dma_domain->domain_lock, flags);
-
-   memcpy(&dma_domain->dma_stash, stash_attr,
-  sizeof(struct pamu_stash_attribute));
-
-   dma_domain->stash_id = get_stash_id(stash_attr->cache,
-   stash_attr->cpu);
+   dma_domain->stash_id = get_stash_id(PAMU_ATTR_CACHE_L1, cpu);
if (dma_domain->stash_id == ~(u32)0) {
pr_debug("Invalid stash attributes\n");
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
return -EINVAL;
}
-
ret = update_domain_stash(dma_domain, dma_domain->stash_id);
-
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
 
return ret;
@@ -426,9 +419,6 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain 
*domain,
int ret = 0;
 
switch (attr_type) {
-   case DOMAIN_ATTR_FSL_PAMU_STASH:
-   ret = configure_domain_stash(dma_domain, data);
-   break;
case DOMAIN_ATTR_FSL_PAMU_ENABLE:
ret = configure_domain_dma_state(dma_domain, *(int *)data);
break;
diff --git a/drivers/iommu/fsl_pamu_domain.h b/drivers/iommu/fsl_pamu_domain.h
index 13ee06e0ef0136..cd488004acd1b3 100644
--- a/drivers/iommu/fsl_pamu_domain.h
+++ b/drivers/iommu/fsl_pamu_domain.h
@@ -22,9 +22,7 @@ struct fsl_dma_domain {
 *
 */
int enabled;
-   /* stash_id obtained from the stash attribute details */
u32 stash_id;
-   struct pamu_stash_attribute dma_stash;
u32 snoop_id;
struct iommu_domain iommu_domain;
spinlock_t  domain_lock;
diff --git a/drivers/soc/fsl/qbman/qman_portal.c 
b/drivers/soc/fsl/qbman/qman_portal.c
index 9ee1663f422cbf..798b3a1ffd0b9c 100644
--- a/drivers/soc/fsl/qbman/qman_portal.c
+++ b/drivers/soc/fsl/qbman/qman_portal.c
@@ -47,7 +47,6 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, int 
cpu)
 #ifdef CONFIG_FSL_PAMU
struct device *dev = pcfg->dev;
int window_count = 1;
-   struct pamu_stash_attribute stash_attr;
int ret;
 
pcfg->iommu_domain = iommu_domain_alloc(&platform_bus_type);
@@ -55,13 +54,9 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, 
int cpu)
dev_err(dev, "%s(): iommu_domain_alloc() failed", __func__);
goto no_iommu;
}
-   stash_attr.cpu = cpu;
-   stash_attr.cache = PAMU_ATTR_CACHE_L1;
-   ret = iommu_domain_set_attr(pcfg->iommu_domain,
-   DOMAIN_ATTR_FSL_PAMU_STASH,
-   &stash_attr);
+   ret = fsl_pamu_configure_l1_stash(pcfg->iommu_domain, cpu);
if (ret < 0) {
-   dev_err(dev, "%s(): iommu_domain_set_attr() = %d",
+   dev_err(dev, "%s(): fsl_pamu_configure_l1

[Freedreno] [PATCH 08/17] iommu/fsl_pamu: merge pamu_set_liodn and map_liodn

2021-03-01 Thread Christoph Hellwig
Merge the two fuctions that configure the ppaace into a single coherent
function.  I somehow doubt we need the two pamu_config_ppaace calls,
but keep the existing behavior just to be on the safe side.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 65 +
 1 file changed, 17 insertions(+), 48 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 40eff4b7bc5d42..4a4944332674f7 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -54,25 +54,6 @@ static int __init iommu_init_mempool(void)
return 0;
 }
 
-/* Map the DMA window corresponding to the LIODN */
-static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain)
-{
-   int ret;
-   struct iommu_domain_geometry *geom = &dma_domain->iommu_domain.geometry;
-   unsigned long flags;
-
-   spin_lock_irqsave(&iommu_lock, flags);
-   ret = pamu_config_ppaace(liodn, geom->aperture_start,
-geom->aperture_end - 1, ~(u32)0,
-0, dma_domain->snoop_id, dma_domain->stash_id,
-PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE);
-   spin_unlock_irqrestore(&iommu_lock, flags);
-   if (ret)
-   pr_debug("PAACE configuration failed for liodn %d\n", liodn);
-
-   return ret;
-}
-
 static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain,
  u32 val)
 {
@@ -94,11 +75,11 @@ static int update_liodn_stash(int liodn, struct 
fsl_dma_domain *dma_domain,
 }
 
 /* Set the geometry parameters for a LIODN */
-static int pamu_set_liodn(int liodn, struct device *dev,
- struct fsl_dma_domain *dma_domain,
- struct iommu_domain_geometry *geom_attr)
+static int pamu_set_liodn(struct fsl_dma_domain *dma_domain, struct device 
*dev,
+ int liodn)
 {
-   phys_addr_t window_addr, window_size;
+   struct iommu_domain *domain = &dma_domain->iommu_domain;
+   struct iommu_domain_geometry *geom = &domain->geometry;
u32 omi_index = ~(u32)0;
unsigned long flags;
int ret;
@@ -110,22 +91,25 @@ static int pamu_set_liodn(int liodn, struct device *dev,
 */
get_ome_index(&omi_index, dev);
 
-   window_addr = geom_attr->aperture_start;
-   window_size = geom_attr->aperture_end + 1;
-
spin_lock_irqsave(&iommu_lock, flags);
ret = pamu_disable_liodn(liodn);
-   if (!ret)
-   ret = pamu_config_ppaace(liodn, window_addr, window_size, 
omi_index,
-0, dma_domain->snoop_id,
-dma_domain->stash_id, 0);
+   if (ret)
+   goto out_unlock;
+   ret = pamu_config_ppaace(liodn, geom->aperture_start,
+geom->aperture_end - 1, omi_index, 0,
+dma_domain->snoop_id, dma_domain->stash_id, 0);
+   if (ret)
+   goto out_unlock;
+   ret = pamu_config_ppaace(liodn, geom->aperture_start,
+geom->aperture_end - 1, ~(u32)0,
+0, dma_domain->snoop_id, dma_domain->stash_id,
+PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE);
+out_unlock:
spin_unlock_irqrestore(&iommu_lock, flags);
if (ret) {
pr_debug("PAACE configuration failed for liodn %d\n",
 liodn);
-   return ret;
}
-
return ret;
 }
 
@@ -265,7 +249,6 @@ static int handle_attach_device(struct fsl_dma_domain 
*dma_domain,
int num)
 {
unsigned long flags;
-   struct iommu_domain *domain = &dma_domain->iommu_domain;
int ret = 0;
int i;
 
@@ -280,21 +263,7 @@ static int handle_attach_device(struct fsl_dma_domain 
*dma_domain,
}
 
attach_device(dma_domain, liodn[i], dev);
-   /*
-* Check if geometry has already been configured
-* for the domain. If yes, set the geometry for
-* the LIODN.
-*/
-   ret = pamu_set_liodn(liodn[i], dev, dma_domain,
-&domain->geometry);
-   if (ret)
-   break;
-
-   /*
-* Create window/subwindow mapping for
-* the LIODN.
-*/
-   ret = map_liodn(liodn[i], dma_domain);
+   ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
if (ret)
break;
}
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 09/17] iommu/fsl_pamu: merge handle_attach_device into fsl_pamu_attach_device

2021-03-01 Thread Christoph Hellwig
No good reason to split this functionality over two functions.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 59 +++--
 1 file changed, 20 insertions(+), 39 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 4a4944332674f7..962cdc1a4a1924 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -240,45 +240,13 @@ static int update_domain_stash(struct fsl_dma_domain 
*dma_domain, u32 val)
return ret;
 }
 
-/*
- * Attach the LIODN to the DMA domain and configure the geometry
- * and window mappings.
- */
-static int handle_attach_device(struct fsl_dma_domain *dma_domain,
-   struct device *dev, const u32 *liodn,
-   int num)
-{
-   unsigned long flags;
-   int ret = 0;
-   int i;
-
-   spin_lock_irqsave(&dma_domain->domain_lock, flags);
-   for (i = 0; i < num; i++) {
-   /* Ensure that LIODN value is valid */
-   if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
-   pr_debug("Invalid liodn %d, attach device failed for 
%pOF\n",
-liodn[i], dev->of_node);
-   ret = -EINVAL;
-   break;
-   }
-
-   attach_device(dma_domain, liodn[i], dev);
-   ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
-   if (ret)
-   break;
-   }
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-
-   return ret;
-}
-
 static int fsl_pamu_attach_device(struct iommu_domain *domain,
  struct device *dev)
 {
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
+   unsigned long flags;
+   int len, ret = 0, i;
const u32 *liodn;
-   u32 liodn_cnt;
-   int len, ret = 0;
struct pci_dev *pdev = NULL;
struct pci_controller *pci_ctl;
 
@@ -298,14 +266,27 @@ static int fsl_pamu_attach_device(struct iommu_domain 
*domain,
}
 
liodn = of_get_property(dev->of_node, "fsl,liodn", &len);
-   if (liodn) {
-   liodn_cnt = len / sizeof(u32);
-   ret = handle_attach_device(dma_domain, dev, liodn, liodn_cnt);
-   } else {
+   if (!liodn) {
pr_debug("missing fsl,liodn property at %pOF\n", dev->of_node);
-   ret = -EINVAL;
+   return -EINVAL;
}
 
+   spin_lock_irqsave(&dma_domain->domain_lock, flags);
+   for (i = 0; i < len / sizeof(u32); i++) {
+   /* Ensure that LIODN value is valid */
+   if (liodn[i] >= PAACE_NUMBER_ENTRIES) {
+   pr_debug("Invalid liodn %d, attach device failed for 
%pOF\n",
+liodn[i], dev->of_node);
+   ret = -EINVAL;
+   break;
+   }
+
+   attach_device(dma_domain, liodn[i], dev);
+   ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
+   if (ret)
+   break;
+   }
+   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
return ret;
 }
 
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 10/17] iommu/fsl_pamu: enable the liodn when attaching a device

2021-03-01 Thread Christoph Hellwig
Instead of a separate call to enable all devices from the list, just
enablde the liodn one the device is attached to the iommu domain.

This also remove the DOMAIN_ATTR_FSL_PAMU_ENABLE iommu_attr.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 47 ++---
 drivers/iommu/fsl_pamu_domain.h | 10 --
 drivers/soc/fsl/qbman/qman_portal.c | 11 ---
 include/linux/iommu.h   |  1 -
 4 files changed, 3 insertions(+), 66 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 962cdc1a4a1924..21c6d9e79eddf9 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -195,9 +195,6 @@ static void fsl_pamu_domain_free(struct iommu_domain 
*domain)
 
/* remove all the devices from the device list */
detach_device(NULL, dma_domain);
-
-   dma_domain->enabled = 0;
-
kmem_cache_free(fsl_pamu_domain_cache, dma_domain);
 }
 
@@ -285,6 +282,9 @@ static int fsl_pamu_attach_device(struct iommu_domain 
*domain,
ret = pamu_set_liodn(dma_domain, dev, liodn[i]);
if (ret)
break;
+   ret = pamu_enable_liodn(liodn[i]);
+   if (ret)
+   break;
}
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
return ret;
@@ -341,46 +341,6 @@ int fsl_pamu_configure_l1_stash(struct iommu_domain 
*domain, u32 cpu)
return ret;
 }
 
-/* Configure domain dma state i.e. enable/disable DMA */
-static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool 
enable)
-{
-   struct device_domain_info *info;
-   unsigned long flags;
-   int ret;
-
-   spin_lock_irqsave(&dma_domain->domain_lock, flags);
-   dma_domain->enabled = enable;
-   list_for_each_entry(info, &dma_domain->devices, link) {
-   ret = (enable) ? pamu_enable_liodn(info->liodn) :
-   pamu_disable_liodn(info->liodn);
-   if (ret)
-   pr_debug("Unable to set dma state for liodn %d",
-info->liodn);
-   }
-   spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
-
-   return 0;
-}
-
-static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
-   enum iommu_attr attr_type, void *data)
-{
-   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-   int ret = 0;
-
-   switch (attr_type) {
-   case DOMAIN_ATTR_FSL_PAMU_ENABLE:
-   ret = configure_domain_dma_state(dma_domain, *(int *)data);
-   break;
-   default:
-   pr_debug("Unsupported attribute type\n");
-   ret = -EINVAL;
-   break;
-   }
-
-   return ret;
-}
-
 static struct iommu_group *get_device_iommu_group(struct device *dev)
 {
struct iommu_group *group;
@@ -505,7 +465,6 @@ static const struct iommu_ops fsl_pamu_ops = {
.attach_dev = fsl_pamu_attach_device,
.detach_dev = fsl_pamu_detach_device,
.iova_to_phys   = fsl_pamu_iova_to_phys,
-   .domain_set_attr = fsl_pamu_set_domain_attr,
.probe_device   = fsl_pamu_probe_device,
.release_device = fsl_pamu_release_device,
.device_group   = fsl_pamu_device_group,
diff --git a/drivers/iommu/fsl_pamu_domain.h b/drivers/iommu/fsl_pamu_domain.h
index cd488004acd1b3..5f4ed253f61b31 100644
--- a/drivers/iommu/fsl_pamu_domain.h
+++ b/drivers/iommu/fsl_pamu_domain.h
@@ -12,16 +12,6 @@
 struct fsl_dma_domain {
/* list of devices associated with the domain */
struct list_headdevices;
-   /* dma_domain states:
-* enabled - DMA has been enabled for the given
-* domain. This translates to setting of the
-* valid bit for the primary PAACE in the PAMU
-* PAACT table. Domain geometry should be set and
-* it must have a valid mapping before DMA can be
-* enabled for it.
-*
-*/
-   int enabled;
u32 stash_id;
u32 snoop_id;
struct iommu_domain iommu_domain;
diff --git a/drivers/soc/fsl/qbman/qman_portal.c 
b/drivers/soc/fsl/qbman/qman_portal.c
index 798b3a1ffd0b9c..bf38eb0042ed52 100644
--- a/drivers/soc/fsl/qbman/qman_portal.c
+++ b/drivers/soc/fsl/qbman/qman_portal.c
@@ -46,7 +46,6 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, int 
cpu)
 {
 #ifdef CONFIG_FSL_PAMU
struct device *dev = pcfg->dev;
-   int window_count = 1;
int ret;
 
pcfg->iommu_domain = iommu_domain_alloc(&platform_bus_type);
@@ -66,14 +65,6 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, 
int cpu)
ret);
goto out_domain_free;
}
-   ret = iommu_domain_set_attr(pcfg->iommu_domain

[Freedreno] [PATCH 11/17] iommu/fsl_pamu: remove the snoop_id field

2021-03-01 Thread Christoph Hellwig
The snoop_id is always set to ~(u32)0.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/fsl_pamu_domain.c | 5 ++---
 drivers/iommu/fsl_pamu_domain.h | 1 -
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 21c6d9e79eddf9..701fc3f187a100 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -97,12 +97,12 @@ static int pamu_set_liodn(struct fsl_dma_domain 
*dma_domain, struct device *dev,
goto out_unlock;
ret = pamu_config_ppaace(liodn, geom->aperture_start,
 geom->aperture_end - 1, omi_index, 0,
-dma_domain->snoop_id, dma_domain->stash_id, 0);
+~(u32)0, dma_domain->stash_id, 0);
if (ret)
goto out_unlock;
ret = pamu_config_ppaace(liodn, geom->aperture_start,
 geom->aperture_end - 1, ~(u32)0,
-0, dma_domain->snoop_id, dma_domain->stash_id,
+0, ~(u32)0, dma_domain->stash_id,
 PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE);
 out_unlock:
spin_unlock_irqrestore(&iommu_lock, flags);
@@ -210,7 +210,6 @@ static struct iommu_domain *fsl_pamu_domain_alloc(unsigned 
type)
return NULL;
 
dma_domain->stash_id = ~(u32)0;
-   dma_domain->snoop_id = ~(u32)0;
INIT_LIST_HEAD(&dma_domain->devices);
spin_lock_init(&dma_domain->domain_lock);
 
diff --git a/drivers/iommu/fsl_pamu_domain.h b/drivers/iommu/fsl_pamu_domain.h
index 5f4ed253f61b31..95ac1b3cab3b69 100644
--- a/drivers/iommu/fsl_pamu_domain.h
+++ b/drivers/iommu/fsl_pamu_domain.h
@@ -13,7 +13,6 @@ struct fsl_dma_domain {
/* list of devices associated with the domain */
struct list_headdevices;
u32 stash_id;
-   u32 snoop_id;
struct iommu_domain iommu_domain;
spinlock_t  domain_lock;
 };
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 13/17] iommu: remove DOMAIN_ATTR_GEOMETRY

2021-03-01 Thread Christoph Hellwig
The geometry information can be trivially queried from the iommu_domain
struture.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/iommu.c   | 20 +++-
 drivers/soc/fsl/qbman/qman_portal.c |  1 +
 drivers/vfio/vfio_iommu_type1.c | 26 --
 drivers/vhost/vdpa.c| 10 +++---
 include/linux/iommu.h   |  1 -
 5 files changed, 19 insertions(+), 39 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 9a4cda390993e6..23daaea7883b75 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2667,23 +2667,9 @@ core_initcall(iommu_init);
 int iommu_domain_get_attr(struct iommu_domain *domain,
  enum iommu_attr attr, void *data)
 {
-   struct iommu_domain_geometry *geometry;
-   int ret = 0;
-
-   switch (attr) {
-   case DOMAIN_ATTR_GEOMETRY:
-   geometry  = data;
-   *geometry = domain->geometry;
-
-   break;
-   default:
-   if (!domain->ops->domain_get_attr)
-   return -EINVAL;
-
-   ret = domain->ops->domain_get_attr(domain, attr, data);
-   }
-
-   return ret;
+   if (!domain->ops->domain_get_attr)
+   return -EINVAL;
+   return domain->ops->domain_get_attr(domain, attr, data);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_get_attr);
 
diff --git a/drivers/soc/fsl/qbman/qman_portal.c 
b/drivers/soc/fsl/qbman/qman_portal.c
index bf38eb0042ed52..4a4466cc26c232 100644
--- a/drivers/soc/fsl/qbman/qman_portal.c
+++ b/drivers/soc/fsl/qbman/qman_portal.c
@@ -53,6 +53,7 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, int 
cpu)
dev_err(dev, "%s(): iommu_domain_alloc() failed", __func__);
goto no_iommu;
}
+
ret = fsl_pamu_configure_l1_stash(pcfg->iommu_domain, cpu);
if (ret < 0) {
dev_err(dev, "%s(): fsl_pamu_configure_l1_stash() = %d",
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 4bb162c1d649b3..c8e57f22f421c5 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -2252,7 +2252,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
int ret;
bool resv_msi, msi_remap;
phys_addr_t resv_msi_base = 0;
-   struct iommu_domain_geometry geo;
+   struct iommu_domain_geometry *geo;
LIST_HEAD(iova_copy);
LIST_HEAD(group_resv_regions);
 
@@ -2333,10 +2333,9 @@ static int vfio_iommu_type1_attach_group(void 
*iommu_data,
goto out_domain;
 
/* Get aperture info */
-   iommu_domain_get_attr(domain->domain, DOMAIN_ATTR_GEOMETRY, &geo);
-
-   if (vfio_iommu_aper_conflict(iommu, geo.aperture_start,
-geo.aperture_end)) {
+   geo = &domain->domain->geometry;
+   if (vfio_iommu_aper_conflict(iommu, geo->aperture_start,
+geo->aperture_end)) {
ret = -EINVAL;
goto out_detach;
}
@@ -2359,8 +2358,8 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
if (ret)
goto out_detach;
 
-   ret = vfio_iommu_aper_resize(&iova_copy, geo.aperture_start,
-geo.aperture_end);
+   ret = vfio_iommu_aper_resize(&iova_copy, geo->aperture_start,
+geo->aperture_end);
if (ret)
goto out_detach;
 
@@ -2493,7 +2492,6 @@ static void vfio_iommu_aper_expand(struct vfio_iommu 
*iommu,
   struct list_head *iova_copy)
 {
struct vfio_domain *domain;
-   struct iommu_domain_geometry geo;
struct vfio_iova *node;
dma_addr_t start = 0;
dma_addr_t end = (dma_addr_t)~0;
@@ -2502,12 +2500,12 @@ static void vfio_iommu_aper_expand(struct vfio_iommu 
*iommu,
return;
 
list_for_each_entry(domain, &iommu->domain_list, next) {
-   iommu_domain_get_attr(domain->domain, DOMAIN_ATTR_GEOMETRY,
- &geo);
-   if (geo.aperture_start > start)
-   start = geo.aperture_start;
-   if (geo.aperture_end < end)
-   end = geo.aperture_end;
+   struct iommu_domain_geometry *geo = &domain->domain->geometry;
+
+   if (geo->aperture_start > start)
+   start = geo->aperture_start;
+   if (geo->aperture_end < end)
+   end = geo->aperture_end;
}
 
/* Modify aperture limits. The new aper is either same or bigger */
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index ef688c8c0e0e6f..25824fab433d0a 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -826,18 +826,14 @@ static void vhost_vdpa_free_domain(struct vhost_vdpa *v)
 static void vhost_vdpa_set_i

[Freedreno] [PATCH 12/17] iommu: remove DOMAIN_ATTR_PAGING

2021-03-01 Thread Christoph Hellwig
DOMAIN_ATTR_PAGING is never used.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/iommu.c | 5 -
 include/linux/iommu.h | 1 -
 2 files changed, 6 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b212bf0261820b..9a4cda390993e6 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2668,7 +2668,6 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
  enum iommu_attr attr, void *data)
 {
struct iommu_domain_geometry *geometry;
-   bool *paging;
int ret = 0;
 
switch (attr) {
@@ -2676,10 +2675,6 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
geometry  = data;
*geometry = domain->geometry;
 
-   break;
-   case DOMAIN_ATTR_PAGING:
-   paging  = data;
-   *paging = (domain->pgsize_bitmap != 0UL);
break;
default:
if (!domain->ops->domain_get_attr)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 840864844027dc..180ff4bd7fa7ef 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -108,7 +108,6 @@ enum iommu_cap {
 
 enum iommu_attr {
DOMAIN_ATTR_GEOMETRY,
-   DOMAIN_ATTR_PAGING,
DOMAIN_ATTR_NESTING,/* two stages of translation */
DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE,
DOMAIN_ATTR_IO_PGTABLE_CFG,
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 14/17] iommu: remove DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE

2021-03-01 Thread Christoph Hellwig
Use explicit methods for setting and querying the information instead.

Also remove the now unused iommu_domain_get_attr functionality.

Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/amd/iommu.c   | 23 ++---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 47 ++---
 drivers/iommu/arm/arm-smmu/arm-smmu.c   | 56 +
 drivers/iommu/dma-iommu.c   |  8 ++-
 drivers/iommu/intel/iommu.c | 27 ++
 drivers/iommu/iommu.c   | 19 +++
 include/linux/iommu.h   | 17 ++-
 7 files changed, 51 insertions(+), 146 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a69a8b573e40d0..37a8e51db17656 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1771,24 +1771,11 @@ static struct iommu_group 
*amd_iommu_device_group(struct device *dev)
return acpihid_device_group(dev);
 }
 
-static int amd_iommu_domain_get_attr(struct iommu_domain *domain,
-   enum iommu_attr attr, void *data)
+static bool amd_iommu_dma_use_flush_queue(struct iommu_domain *domain)
 {
-   switch (domain->type) {
-   case IOMMU_DOMAIN_UNMANAGED:
-   return -ENODEV;
-   case IOMMU_DOMAIN_DMA:
-   switch (attr) {
-   case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE:
-   *(int *)data = !amd_iommu_unmap_flush;
-   return 0;
-   default:
-   return -ENODEV;
-   }
-   break;
-   default:
-   return -EINVAL;
-   }
+   if (domain->type != IOMMU_DOMAIN_DMA)
+   return false;
+   return !amd_iommu_unmap_flush;
 }
 
 /*
@@ -2257,7 +2244,7 @@ const struct iommu_ops amd_iommu_ops = {
.release_device = amd_iommu_release_device,
.probe_finalize = amd_iommu_probe_finalize,
.device_group = amd_iommu_device_group,
-   .domain_get_attr = amd_iommu_domain_get_attr,
+   .dma_use_flush_queue = amd_iommu_dma_use_flush_queue,
.get_resv_regions = amd_iommu_get_resv_regions,
.put_resv_regions = generic_iommu_put_resv_regions,
.is_attach_deferred = amd_iommu_is_attach_deferred,
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c 
b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 8594b4a8304375..bf96172e8c1f71 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2449,33 +2449,21 @@ static struct iommu_group *arm_smmu_device_group(struct 
device *dev)
return group;
 }
 
-static int arm_smmu_domain_get_attr(struct iommu_domain *domain,
-   enum iommu_attr attr, void *data)
+static bool arm_smmu_dma_use_flush_queue(struct iommu_domain *domain)
 {
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
 
-   switch (domain->type) {
-   case IOMMU_DOMAIN_UNMANAGED:
-   switch (attr) {
-   case DOMAIN_ATTR_NESTING:
-   *(int *)data = (smmu_domain->stage == 
ARM_SMMU_DOMAIN_NESTED);
-   return 0;
-   default:
-   return -ENODEV;
-   }
-   break;
-   case IOMMU_DOMAIN_DMA:
-   switch (attr) {
-   case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE:
-   *(int *)data = smmu_domain->non_strict;
-   return 0;
-   default:
-   return -ENODEV;
-   }
-   break;
-   default:
-   return -EINVAL;
-   }
+   if (domain->type != IOMMU_DOMAIN_DMA)
+   return false;
+   return smmu_domain->non_strict;
+}
+
+
+static void arm_smmu_dma_enable_flush_queue(struct iommu_domain *domain)
+{
+   if (domain->type != IOMMU_DOMAIN_DMA)
+   return;
+   to_smmu_domain(domain)->non_strict = true;
 }
 
 static int arm_smmu_domain_set_attr(struct iommu_domain *domain,
@@ -2505,13 +2493,7 @@ static int arm_smmu_domain_set_attr(struct iommu_domain 
*domain,
}
break;
case IOMMU_DOMAIN_DMA:
-   switch(attr) {
-   case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE:
-   smmu_domain->non_strict = *(int *)data;
-   break;
-   default:
-   ret = -ENODEV;
-   }
+   ret = -ENODEV;
break;
default:
ret = -EINVAL;
@@ -2619,7 +2601,8 @@ static struct iommu_ops arm_smmu_ops = {
.probe_device   = arm_smmu_probe_device,
.release_device = arm_smmu_release_device,
.device_group   = arm_smmu_device_group,
-   .domain_get_attr= arm_smmu_domain_get_attr,
+   .dma_use_flush_queue

[Freedreno] [PATCH 15/17] iommu: remove DOMAIN_ATTR_NESTING

2021-03-01 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 40 ++---
 drivers/iommu/arm/arm-smmu/arm-smmu.c   | 30 ++--
 drivers/iommu/intel/iommu.c | 28 +--
 drivers/iommu/iommu.c   |  8 +
 drivers/vfio/vfio_iommu_type1.c |  5 +--
 include/linux/iommu.h   |  4 ++-
 6 files changed, 50 insertions(+), 65 deletions(-)

diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c 
b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index bf96172e8c1f71..8e6fee3ea454d3 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -2466,41 +2466,21 @@ static void arm_smmu_dma_enable_flush_queue(struct 
iommu_domain *domain)
to_smmu_domain(domain)->non_strict = true;
 }
 
-static int arm_smmu_domain_set_attr(struct iommu_domain *domain,
-   enum iommu_attr attr, void *data)
+static int arm_smmu_domain_enable_nesting(struct iommu_domain *domain)
 {
-   int ret = 0;
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
+   int ret = -EPERM;
 
-   mutex_lock(&smmu_domain->init_mutex);
+   if (domain->type != IOMMU_DOMAIN_UNMANAGED)
+   return -EINVAL;
 
-   switch (domain->type) {
-   case IOMMU_DOMAIN_UNMANAGED:
-   switch (attr) {
-   case DOMAIN_ATTR_NESTING:
-   if (smmu_domain->smmu) {
-   ret = -EPERM;
-   goto out_unlock;
-   }
-
-   if (*(int *)data)
-   smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED;
-   else
-   smmu_domain->stage = ARM_SMMU_DOMAIN_S1;
-   break;
-   default:
-   ret = -ENODEV;
-   }
-   break;
-   case IOMMU_DOMAIN_DMA:
-   ret = -ENODEV;
-   break;
-   default:
-   ret = -EINVAL;
+   mutex_lock(&smmu_domain->init_mutex);
+   if (!smmu_domain->smmu) {
+   smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED;
+   ret = 0;
}
-
-out_unlock:
mutex_unlock(&smmu_domain->init_mutex);
+
return ret;
 }
 
@@ -2603,7 +2583,7 @@ static struct iommu_ops arm_smmu_ops = {
.device_group   = arm_smmu_device_group,
.dma_use_flush_queue= arm_smmu_dma_use_flush_queue,
.dma_enable_flush_queue = arm_smmu_dma_enable_flush_queue,
-   .domain_set_attr= arm_smmu_domain_set_attr,
+   .domain_enable_nesting  = arm_smmu_domain_enable_nesting,
.of_xlate   = arm_smmu_of_xlate,
.get_resv_regions   = arm_smmu_get_resv_regions,
.put_resv_regions   = generic_iommu_put_resv_regions,
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c 
b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index e7893e96f5177a..2e17d990d04481 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -1497,6 +1497,24 @@ static void arm_smmu_dma_enable_flush_queue(struct 
iommu_domain *domain)
to_smmu_domain(domain)->pgtbl_cfg.quirks |= IO_PGTABLE_QUIRK_NON_STRICT;
 }
 
+static int arm_smmu_domain_enable_nesting(struct iommu_domain *domain)
+{
+   struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
+   int ret = -EPERM;
+   
+   if (domain->type != IOMMU_DOMAIN_UNMANAGED)
+   return -EINVAL;
+
+   mutex_lock(&smmu_domain->init_mutex);
+   if (!smmu_domain->smmu) {
+   smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED;
+   ret = 0;
+   }
+   mutex_unlock(&smmu_domain->init_mutex);
+
+   return ret;
+}
+
 static int arm_smmu_domain_set_attr(struct iommu_domain *domain,
enum iommu_attr attr, void *data)
 {
@@ -1508,17 +1526,6 @@ static int arm_smmu_domain_set_attr(struct iommu_domain 
*domain,
switch(domain->type) {
case IOMMU_DOMAIN_UNMANAGED:
switch (attr) {
-   case DOMAIN_ATTR_NESTING:
-   if (smmu_domain->smmu) {
-   ret = -EPERM;
-   goto out_unlock;
-   }
-
-   if (*(int *)data)
-   smmu_domain->stage = ARM_SMMU_DOMAIN_NESTED;
-   else
-   smmu_domain->stage = ARM_SMMU_DOMAIN_S1;
-   break;
case DOMAIN_ATTR_IO_PGTABLE_CFG: {
struct io_pgtable_domain_attr *pgtbl_cfg = data;
 
@@ -1603,6 +1610,7 @@ static struct iommu_ops arm_smmu_ops = {
.dma_use_flush_queue= arm_smmu_dma_use_flush_queue,
.dma_enable_flush_queue = arm_smmu_dma_enable_flush_queue,
.

[Freedreno] [PATCH 16/17] iommu: remove DOMAIN_ATTR_IO_PGTABLE_CFG

2021-03-01 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
---
 drivers/gpu/drm/msm/adreno/adreno_gpu.c |  2 +-
 drivers/iommu/arm/arm-smmu/arm-smmu.c   | 40 +++--
 drivers/iommu/iommu.c   |  9 ++
 include/linux/iommu.h   |  9 +-
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c 
b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
index 0f184c3dd9d9ec..78d98ab2ee3a68 100644
--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c
@@ -191,7 +191,7 @@ void adreno_set_llc_attributes(struct iommu_domain *iommu)
struct io_pgtable_domain_attr pgtbl_cfg;
 
pgtbl_cfg.quirks = IO_PGTABLE_QUIRK_ARM_OUTER_WBWA;
-   iommu_domain_set_attr(iommu, DOMAIN_ATTR_IO_PGTABLE_CFG, &pgtbl_cfg);
+   iommu_domain_set_pgtable_attr(iommu, &pgtbl_cfg);
 }
 
 struct msm_gem_address_space *
diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c 
b/drivers/iommu/arm/arm-smmu/arm-smmu.c
index 2e17d990d04481..2858999c86dfd1 100644
--- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
+++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
@@ -1515,40 +1515,22 @@ static int arm_smmu_domain_enable_nesting(struct 
iommu_domain *domain)
return ret;
 }
 
-static int arm_smmu_domain_set_attr(struct iommu_domain *domain,
-   enum iommu_attr attr, void *data)
+static int arm_smmu_domain_set_pgtable_attr(struct iommu_domain *domain,
+   struct io_pgtable_domain_attr *pgtbl_cfg)
 {
-   int ret = 0;
struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
+   int ret = -EPERM;
 
-   mutex_lock(&smmu_domain->init_mutex);
-
-   switch(domain->type) {
-   case IOMMU_DOMAIN_UNMANAGED:
-   switch (attr) {
-   case DOMAIN_ATTR_IO_PGTABLE_CFG: {
-   struct io_pgtable_domain_attr *pgtbl_cfg = data;
-
-   if (smmu_domain->smmu) {
-   ret = -EPERM;
-   goto out_unlock;
-   }
+   if (domain->type != IOMMU_DOMAIN_UNMANAGED)
+   return -EINVAL;
 
-   smmu_domain->pgtbl_cfg = *pgtbl_cfg;
-   break;
-   }
-   default:
-   ret = -ENODEV;
-   }
-   break;
-   case IOMMU_DOMAIN_DMA:
-   ret = -ENODEV;
-   break;
-   default:
-   ret = -EINVAL;
+   mutex_lock(&smmu_domain->init_mutex);
+   if (!smmu_domain->smmu) {
+   smmu_domain->pgtbl_cfg = *pgtbl_cfg;
+   ret = 0;
}
-out_unlock:
mutex_unlock(&smmu_domain->init_mutex);
+
return ret;
 }
 
@@ -1609,7 +1591,7 @@ static struct iommu_ops arm_smmu_ops = {
.device_group   = arm_smmu_device_group,
.dma_use_flush_queue= arm_smmu_dma_use_flush_queue,
.dma_enable_flush_queue = arm_smmu_dma_enable_flush_queue,
-   .domain_set_attr= arm_smmu_domain_set_attr,
+   .domain_set_pgtable_attr = arm_smmu_domain_set_pgtable_attr,
.domain_enable_nesting  = arm_smmu_domain_enable_nesting,
.of_xlate   = arm_smmu_of_xlate,
.get_resv_regions   = arm_smmu_get_resv_regions,
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 2e9e058501a953..8490aefd4b41f8 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2693,6 +2693,15 @@ int iommu_domain_enable_nesting(struct iommu_domain 
*domain)
 }
 EXPORT_SYMBOL_GPL(iommu_domain_enable_nesting);
 
+int iommu_domain_set_pgtable_attr(struct iommu_domain *domain,
+   struct io_pgtable_domain_attr *pgtbl_cfg)
+{
+   if (!domain->ops->domain_set_pgtable_attr)
+   return -EINVAL;
+   return domain->ops->domain_set_pgtable_attr(domain, pgtbl_cfg);
+}
+EXPORT_SYMBOL_GPL(iommu_domain_set_pgtable_attr);
+
 void iommu_get_resv_regions(struct device *dev, struct list_head *list)
 {
const struct iommu_ops *ops = dev->bus->iommu_ops;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index aed88aa3bd3edf..39d3ed4d2700ac 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -40,6 +40,7 @@ struct iommu_domain;
 struct notifier_block;
 struct iommu_sva;
 struct iommu_fault_event;
+struct io_pgtable_domain_attr;
 
 /* iommu fault flags */
 #define IOMMU_FAULT_READ   0x0
@@ -107,7 +108,6 @@ enum iommu_cap {
  */
 
 enum iommu_attr {
-   DOMAIN_ATTR_IO_PGTABLE_CFG,
DOMAIN_ATTR_MAX,
 };
 
@@ -196,6 +196,7 @@ struct iommu_iotlb_gather {
  * @dma_enable_flush_queue: Try to enable the DMA flush queue
  * @domain_set_attr: Change domain attributes
  * @domain_enable_nesting: Enable nesting
+ * @domain_set_pgtable_attr: Set io page table attributes
  * @get_resv_regions: Request list of reserved regions for a device
  * @put_resv_regions: Free list of reserved regions for a device

[Freedreno] [PATCH 17/17] iommu: remove iommu_domain_set_attr

2021-03-01 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
---
 drivers/iommu/iommu.c | 17 -
 include/linux/iommu.h | 27 ---
 2 files changed, 44 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8490aefd4b41f8..b04e6cefe8520d 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2668,23 +2668,6 @@ bool iommu_dma_use_flush_queue(struct iommu_domain 
*domain)
 }
 EXPORT_SYMBOL_GPL(iommu_dma_use_flush_queue);
 
-int iommu_domain_set_attr(struct iommu_domain *domain,
- enum iommu_attr attr, void *data)
-{
-   int ret = 0;
-
-   switch (attr) {
-   default:
-   if (domain->ops->domain_set_attr == NULL)
-   return -EINVAL;
-
-   ret = domain->ops->domain_set_attr(domain, attr, data);
-   }
-
-   return ret;
-}
-EXPORT_SYMBOL_GPL(iommu_domain_set_attr);
-
 int iommu_domain_enable_nesting(struct iommu_domain *domain)
 {
if (!domain->ops->domain_enable_nesting)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 39d3ed4d2700ac..62535f563aa491 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -97,20 +97,6 @@ enum iommu_cap {
IOMMU_CAP_NOEXEC,   /* IOMMU_NOEXEC flag */
 };
 
-/*
- * Following constraints are specifc to FSL_PAMUV1:
- *  -aperture must be power of 2, and naturally aligned
- *  -number of windows must be power of 2, and address space size
- *   of each window is determined by aperture size / # of windows
- *  -the actual size of the mapped region of a window must be power
- *   of 2 starting with 4KB and physical address must be naturally
- *   aligned.
- */
-
-enum iommu_attr {
-   DOMAIN_ATTR_MAX,
-};
-
 /* These are the possible reserved region types */
 enum iommu_resv_type {
/* Memory regions which must be mapped 1:1 at all times */
@@ -194,7 +180,6 @@ struct iommu_iotlb_gather {
  * @device_group: find iommu group for a particular device
  * @dma_use_flush_queue: Returns %true if a DMA flush queue is used
  * @dma_enable_flush_queue: Try to enable the DMA flush queue
- * @domain_set_attr: Change domain attributes
  * @domain_enable_nesting: Enable nesting
  * @domain_set_pgtable_attr: Set io page table attributes
  * @get_resv_regions: Request list of reserved regions for a device
@@ -247,8 +232,6 @@ struct iommu_ops {
struct iommu_group *(*device_group)(struct device *dev);
bool (*dma_use_flush_queue)(struct iommu_domain *domain);
void (*dma_enable_flush_queue)(struct iommu_domain *domain);
-   int (*domain_set_attr)(struct iommu_domain *domain,
-  enum iommu_attr attr, void *data);
int (*domain_enable_nesting)(struct iommu_domain *domain);
int (*domain_set_pgtable_attr)(struct iommu_domain *domain,
struct io_pgtable_domain_attr *pgtbl_cfg);
@@ -498,11 +481,7 @@ extern struct iommu_domain 
*iommu_group_default_domain(struct iommu_group *);
 bool iommu_dma_use_flush_queue(struct iommu_domain *domain);
 int iommu_domain_set_pgtable_attr(struct iommu_domain *domain,
struct io_pgtable_domain_attr *pgtbl_cfg);
-extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr,
-void *data);
 int iommu_domain_enable_nesting(struct iommu_domain *domain);
-int iommu_domain_set_pgtable_attr(struct iommu_domain *domain,
-   struct io_pgtable_domain_attr *pgtbl_cfg);
 
 extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev,
  unsigned long iova, int flags);
@@ -869,12 +848,6 @@ static inline int iommu_group_id(struct iommu_group *group)
return -ENODEV;
 }
 
-static inline int iommu_domain_set_attr(struct iommu_domain *domain,
-   enum iommu_attr attr, void *data)
-{
-   return -EINVAL;
-}
-
 static inline int  iommu_device_register(struct iommu_device *iommu)
 {
return -ENODEV;
-- 
2.29.2

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


Re: [Freedreno] [PATCH] drm/dsi: Add _NO_ to MIPI_DSI_* flags disabling features

2021-03-01 Thread Linus Walleij
On Thu, Feb 11, 2021 at 4:34 AM Nicolas Boichat  wrote:

> Many of the DSI flags have names opposite to their actual effects,
> e.g. MIPI_DSI_MODE_EOT_PACKET means that EoT packets will actually
> be disabled. Fix this by including _NO_ in the flag names, e.g.
> MIPI_DSI_MODE_NO_EOT_PACKET.

Unless someone like me interpreted it literally...

Like in these:

>  drivers/gpu/drm/mcde/mcde_dsi.c  | 2 +-
>  drivers/gpu/drm/panel/panel-novatek-nt35510.c| 2 +-
>  drivers/gpu/drm/panel/panel-samsung-s6d16d0.c| 2 +-
>  drivers/gpu/drm/panel/panel-sony-acx424akp.c | 2 +-

> diff --git a/drivers/gpu/drm/mcde/mcde_dsi.c b/drivers/gpu/drm/mcde/mcde_dsi.c
> index 2314c8122992..f4cdc3cfd7d0 100644
> --- a/drivers/gpu/drm/mcde/mcde_dsi.c
> +++ b/drivers/gpu/drm/mcde/mcde_dsi.c
> @@ -760,7 +760,7 @@ static void mcde_dsi_start(struct mcde_dsi *d)
> DSI_MCTL_MAIN_DATA_CTL_BTA_EN |
> DSI_MCTL_MAIN_DATA_CTL_READ_EN |
> DSI_MCTL_MAIN_DATA_CTL_REG_TE_EN;
> -   if (d->mdsi->mode_flags & MIPI_DSI_MODE_EOT_PACKET)
> +   if (d->mdsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET)
> val |= DSI_MCTL_MAIN_DATA_CTL_HOST_EOT_GEN;

If you read the code you can see that this is interpreted as inserting
an EOT packet, so here you need to change the logic such:

if (!d->mdsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET)
val |= DSI_MCTL_MAIN_DATA_CTL_HOST_EOT_GEN;

This will make sure the host generates the EOT packet in HS mode
*unless* the flag is set.

(I checked the data sheet.)

> diff --git a/drivers/gpu/drm/panel/panel-novatek-nt35510.c 
> b/drivers/gpu/drm/panel/panel-novatek-nt35510.c
> index b9a0e56f33e2..9d9334656803 100644
> --- a/drivers/gpu/drm/panel/panel-novatek-nt35510.c
> +++ b/drivers/gpu/drm/panel/panel-novatek-nt35510.c
> @@ -899,7 +899,7 @@ static int nt35510_probe(struct mipi_dsi_device *dsi)
> dsi->hs_rate = 34944;
> dsi->lp_rate = 960;
> dsi->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS |
> -   MIPI_DSI_MODE_EOT_PACKET;
> +   MIPI_DSI_MODE_NO_EOT_PACKET;

Here you should just delete the MIPI_DSI_MODE_EOT_PACKET
flag because this was used with the MCDE driver which interpret the
flag literally.

> diff --git a/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c 
> b/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
> index 4aac0d1573dd..b04b9975e9b2 100644
> --- a/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
> +++ b/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
> @@ -186,7 +186,7 @@ static int s6d16d0_probe(struct mipi_dsi_device *dsi)
>  */
> dsi->mode_flags =
> MIPI_DSI_CLOCK_NON_CONTINUOUS |
> -   MIPI_DSI_MODE_EOT_PACKET;
> +   MIPI_DSI_MODE_NO_EOT_PACKET;

Same, just delete the flag.

> --- a/drivers/gpu/drm/panel/panel-samsung-s6e63m0-dsi.c
> +++ b/drivers/gpu/drm/panel/panel-samsung-s6e63m0-dsi.c
> @@ -97,7 +97,7 @@ static int s6e63m0_dsi_probe(struct mipi_dsi_device *dsi)
> dsi->hs_rate = 34944;
> dsi->lp_rate = 960;
> dsi->mode_flags = MIPI_DSI_MODE_VIDEO |
> -   MIPI_DSI_MODE_EOT_PACKET |
> +   MIPI_DSI_MODE_NO_EOT_PACKET |
> MIPI_DSI_MODE_VIDEO_BURST;

Same, just delete the flag.

> diff --git a/drivers/gpu/drm/panel/panel-sony-acx424akp.c 
> b/drivers/gpu/drm/panel/panel-sony-acx424akp.c
> index 065efae213f5..6b706cbf2f9c 100644
> --- a/drivers/gpu/drm/panel/panel-sony-acx424akp.c
> +++ b/drivers/gpu/drm/panel/panel-sony-acx424akp.c
> @@ -450,7 +450,7 @@ static int acx424akp_probe(struct mipi_dsi_device *dsi)
> else
> dsi->mode_flags =
> MIPI_DSI_CLOCK_NON_CONTINUOUS |
> -   MIPI_DSI_MODE_EOT_PACKET;
> +   MIPI_DSI_MODE_NO_EOT_PACKET;

Same, just delete the flag.

These are all just semantic bugs due to the ambiguity of the flags, it is
possible to provide a Fixes: flag for each file using this flag the wrong way
but I dunno if it's worth it.

Yours,
Linus Walleij
___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] 2021 X.Org Board of Directions Nomination period ends next Sunday

2021-03-01 Thread Harry Wentland
Unfortunately my previous email seems to not have been received by many 
people. I will send this email separately to each mailing list to 
hopefully get better coverage.


The nomination period is currently ongoing. So far we have received 3 
nominations and will need at least 4 to fill the vacant spots on the 
board. We hope you will consider putting your nomination forward.


To nominate yourself or someone else please send the nomination, along 
with a personal statement to elections at x dot org.


** Election Schedule **

Nomination period Start: Mon 22nd February
Nomination period End: Sun 7th March
Deadline of X.Org membership application or renewal: Thu 11th March
Publication of Candidates & start of Candidate QA: Mon 15th March
Election Planned Start: Mon 22nd March anywhere on earth
Election Planned End: Sun 4th April anywhere on earth

** Election Committee **

* Eric Anholt
* Mark Filion
* Keith Packard
* Harry Wentland

Cheers,
Harry Wentland,
on behalf of the X.Org elections committee
___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH 5.11 513/775] drm/msm/dp: Add a missing semi-colon

2021-03-01 Thread Greg Kroah-Hartman
From: Stephen Boyd 

[ Upstream commit 182b4a2d251305201b6f9cae29067f7112f05835 ]

A missing semicolon here causes my external display to stop working.
Indeed, missing the semicolon on the return statement leads to
dp_panel_update_tu_timings() not existing because the compiler thinks
it's part of the return statement of a void function, so it must not be
important.

  $ ./scripts/bloat-o-meter before.o after.o
  add/remove: 1/1 grow/shrink: 0/1 up/down: 7400/-7540 (-140)
  Function old new   delta
  dp_panel_update_tu_timings -7400   +7400
  _dp_ctrl_calc_tu.constprop 18024   17900-124
  dp_panel_update_tu_timings.constprop7416   -   -7416
  Total: Before=54440, After=54300, chg -0.26%

Add a semicolon so this function works like it used to.

Cc: Sean Paul 
Cc: Kuogee Hsieh 
Cc: linux-arm-...@vger.kernel.org
Cc: dri-de...@lists.freedesktop.org
Cc: freedreno@lists.freedesktop.org
Cc: Lee Jones 
Fixes: cc9014bf63a4 ("drm/msm/dp/dp_ctrl: Move 'tu' from the stack to the heap")
Signed-off-by: Stephen Boyd 
Signed-off-by: Rob Clark 
Signed-off-by: Sasha Levin 
---
 drivers/gpu/drm/msm/dp/dp_ctrl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
index e3462f5d96d75..6cbe10af0a7af 100644
--- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
+++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
@@ -631,7 +631,7 @@ static void _dp_ctrl_calc_tu(struct dp_tu_calc_input *in,
 
tu = kzalloc(sizeof(*tu), GFP_KERNEL);
if (!tu)
-   return
+   return;
 
dp_panel_update_tu_timings(in, tu);
 
-- 
2.27.0



___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [PATCH] gpu/drm/msm: fix shutdown hook in case GPU components failed to bind

2021-03-01 Thread Dmitry Baryshkov
if GPU components have failed to bind, shutdown callback would fail with
the following backtrace. Add safeguard check to stop that oops from
happening and allow the board to reboot.

[   66.617046] Unable to handle kernel NULL pointer dereference at virtual 
address 
[   66.626066] Mem abort info:
[   66.628939]   ESR = 0x9606
[   66.632088]   EC = 0x25: DABT (current EL), IL = 32 bits
[   66.637542]   SET = 0, FnV = 0
[   66.640688]   EA = 0, S1PTW = 0
[   66.643924] Data abort info:
[   66.646889]   ISV = 0, ISS = 0x0006
[   66.650832]   CM = 0, WnR = 0
[   66.653890] user pgtable: 4k pages, 48-bit VAs, pgdp=000107f81000
[   66.660505] [] pgd=000100bb2003, p4d=000100bb2003, 
pud=000100897003, pmd=
[   66.671398] Internal error: Oops: 9606 [#1] PREEMPT SMP
[   66.677115] Modules linked in:
[   66.680261] CPU: 6 PID: 352 Comm: reboot Not tainted 
5.11.0-rc2-00309-g79e3faa756b2 #38
[   66.688473] Hardware name: Qualcomm Technologies, Inc. Robotics RB5 (DT)
[   66.695347] pstate: 6045 (nZCv daif +PAN -UAO -TCO BTYPE=--)
[   66.701507] pc : msm_atomic_commit_tail+0x78/0x4e0
[   66.706437] lr : commit_tail+0xa4/0x184
[   66.710381] sp : 8000108f3af0
[   66.713791] x29: 8000108f3af0 x28: 418c44337000
[   66.719242] x27:  x26: 418c40a24490
[   66.724693] x25: d3a842a4f1a0 x24: 0008
[   66.730146] x23: d3a84313f030 x22: 418c444ce000
[   66.735598] x21: 418c408a4980 x20: 
[   66.741049] x19:  x18: 800010710fbc
[   66.746500] x17: 000c x16: 0001
[   66.751954] x15: 00010008 x14: 0068
[   66.757405] x13: 0001 x12: 
[   66.762855] x11: 0001 x10: 09b0
[   66.768306] x9 : d3a843192000 x8 : 418c44337000
[   66.773757] x7 :  x6 : a401b34e
[   66.779210] x5 : 00ff x4 : 
[   66.784660] x3 :  x2 : 418c444ce000
[   66.790111] x1 : d3a841dce530 x0 : 418c444cf000
[   66.795563] Call trace:
[   66.798075]  msm_atomic_commit_tail+0x78/0x4e0
[   66.802633]  commit_tail+0xa4/0x184
[   66.806217]  drm_atomic_helper_commit+0x160/0x390
[   66.811051]  drm_atomic_commit+0x4c/0x60
[   66.815082]  drm_atomic_helper_disable_all+0x1f4/0x210
[   66.820355]  drm_atomic_helper_shutdown+0x80/0x130
[   66.825276]  msm_pdev_shutdown+0x14/0x20
[   66.829303]  platform_shutdown+0x28/0x40
[   66.80]  device_shutdown+0x158/0x330
[   66.837357]  kernel_restart+0x40/0xa0
[   66.841122]  __do_sys_reboot+0x228/0x250
[   66.845148]  __arm64_sys_reboot+0x28/0x34
[   66.849264]  el0_svc_common.constprop.0+0x74/0x190
[   66.854187]  do_el0_svc+0x24/0x90
[   66.857595]  el0_svc+0x14/0x20
[   66.860739]  el0_sync_handler+0x1a4/0x1b0
[   66.864858]  el0_sync+0x174/0x180
[   66.868269] Code: 1ac020a0 2a000273 eb02007f 5401 (f9400285)
[   66.874525] ---[ end trace 20dedb2a3229fec8 ]---

Fixes: 9d5cbf5fe46e ("drm/msm: add shutdown support for display 
platform_driver")
Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/msm_atomic.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c
index 6a326761dc4a..2fd0cf6421ad 100644
--- a/drivers/gpu/drm/msm/msm_atomic.c
+++ b/drivers/gpu/drm/msm/msm_atomic.c
@@ -207,7 +207,12 @@ void msm_atomic_commit_tail(struct drm_atomic_state *state)
struct msm_kms *kms = priv->kms;
struct drm_crtc *async_crtc = NULL;
unsigned crtc_mask = get_crtc_mask(state);
-   bool async = kms->funcs->vsync_time &&
+   bool async;
+
+   if (!kms)
+   return;
+
+   async = kms->funcs->vsync_time &&
can_do_async(state, &async_crtc);
 
trace_msm_atomic_commit_tail_start(async, crtc_mask);
-- 
2.30.1

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 00/24] drm/msm/dsi: refactor MSM DSI PHY/PLL drivers

2021-03-01 Thread Dmitry Baryshkov
This is an RFC attempt to restructure MSM DSI PHY drivers. What started
as an attempt to grok the overcomplicated PHY drivers, has lead up to
the idea of merging PHY and PLL code, reducing abstractions, code
duplication, dropping dead code, etc.

The patches were mainly tested on RB5 (sm8250, 7nm) and lightly tested on RB3
(sdm845, 10nm), DB410c (apq8016, 28nm-lp).

The following changes since commit fe07bfda2fb9cdef8a4d4008a409bb02f35f1bd8:

  Linux 5.12-rc1 (2021-02-28 16:05:19 -0800)

are available in the Git repository at:

  ssh://g...@git.linaro.org/people/dmitry.baryshkov/kernel.git dsi-phy-rfc

for you to fetch changes up to 819a9071587f1acba14a6780f422d78fdb55d671:

  arm64: dts: qcom: sdm845: assign DSI clock source parents (2021-03-02 
02:23:14 +0300)


Dmitry Baryshkov (24):
  drm/msm/dsi: fuse dsi_pll_* code into dsi_phy_* code
  drm/msm/dsi: drop multiple pll enable_seq support
  drm/msm/dsi: move all PLL callbacks into PHY config struct
  drm/msm/dsi: move min/max PLL rate to phy config
  drm/msm/dsi: remove msm_dsi_pll_set_usecase
  drm/msm/dsi: stop setting clock parents manually
  arm64: dts: qcom: sm8250: assign DSI clock source parents
  drm/msm/dsi: push provided clocks handling into a generic code
  clk: mux: provide devm_clk_hw_register_mux()
  clk: divider: add devm_clk_hw_register_divider
  drm/msm/dsi: use devm_clk_*register to registe DSI PHY clocks
  drm/msm/dsi: use devm_of_clk_add_hw_provider
  drm/msm/dsi: replace PHY's init callback with configurable data
  drm/msm/dsi: make save/restore_state phy-level functions
  drm/msm/dsi: limit vco_delay to 28nm PHY
  drm/msi/dsi: inline msm_dsi_pll_helper_clk_prepare/unprepare
  drm/msm/dsi: make save_state/restore_state callbacks accept msm_dsi_phy
  drm/msm/dsi: drop msm_dsi_pll abstracton
  drm/msm/dsi: drop PLL accessor functions
  drm/msm/dsi: move ioremaps to dsi_phy_driver_probe
  drm/msm/dsi: remove duplicate fields from dsi_pll_Nnm instances
  drm/msm/dsi: remove temp data from global pll structure
  drm/msm/dsi: drop global msm_dsi_phy_type enumaration
  arm64: dts: qcom: sdm845: assign DSI clock source parents

 arch/arm64/boot/dts/qcom/sdm845.dtsi|6 +
 arch/arm64/boot/dts/qcom/sm8250.dtsi|6 +
 drivers/clk/clk-mux.c   |   35 +
 drivers/gpu/drm/msm/Kconfig |8 -
 drivers/gpu/drm/msm/Makefile|9 -
 drivers/gpu/drm/msm/dsi/dsi.h   |   56 +-
 drivers/gpu/drm/msm/dsi/dsi_host.c  |   51 --
 drivers/gpu/drm/msm/dsi/dsi_manager.c   |   18 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c   |  129 +--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h   |   31 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c  |  741 ++-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c  |  925 ++-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_20nm.c  |3 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c  |  662 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c |  476 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c   |  769 +++-
 drivers/gpu/drm/msm/dsi/pll/dsi_pll.c   |  184 
 drivers/gpu/drm/msm/dsi/pll/dsi_pll.h   |  130 ---
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_10nm.c  |  881 --
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c  | 1096 ---
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c  |  643 -
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c |  526 ---
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_7nm.c   |  912 ---
 include/linux/clk-provider.h|   30 +
 24 files changed, 3678 insertions(+), 4649 deletions(-)
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll.c
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll.h
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll_10nm.c
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c
 delete mode 100644 drivers/gpu/drm/msm/dsi/pll/dsi_pll_7nm.c

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 02/24] drm/msm/dsi: drop multiple pll enable_seq support

2021-03-01 Thread Dmitry Baryshkov
The only PLL using multiple enable sequences is the 28nm PLL, which just
does the single step in the loop. Push that support back into the PLL
code.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c|  3 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 23 +--
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   |  3 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c | 65 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h |  4 +-
 5 files changed, 42 insertions(+), 56 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
index 4cf289ff8d7e..bd73aa612e76 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
@@ -1087,8 +1087,7 @@ struct msm_dsi_pll *msm_dsi_pll_14nm_init(struct 
platform_device *pdev, int id)
 
pll_14nm->vco_delay = 1;
 
-   pll->en_seq_cnt = 1;
-   pll->enable_seqs[0] = dsi_pll_14nm_enable_seq;
+   pll->enable_seq = dsi_pll_14nm_enable_seq;
 
ret = pll_14nm_register(pll_14nm);
if (ret) {
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
index b2eac57700ce..e92070633b5f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
@@ -311,7 +311,7 @@ static const struct clk_ops clk_ops_dsi_pll_28nm_vco = {
 /*
  * PLL Callbacks
  */
-static int dsi_pll_28nm_enable_seq_hpm(struct msm_dsi_pll *pll)
+static int _dsi_pll_28nm_enable_seq_hpm(struct msm_dsi_pll *pll)
 {
struct dsi_pll_28nm *pll_28nm = to_pll_28nm(pll);
struct device *dev = &pll_28nm->pdev->dev;
@@ -386,6 +386,19 @@ static int dsi_pll_28nm_enable_seq_hpm(struct msm_dsi_pll 
*pll)
return locked ? 0 : -EINVAL;
 }
 
+static int dsi_pll_28nm_enable_seq_hpm(struct msm_dsi_pll *pll)
+{
+   int i, ret;
+
+   for (i = 0; i < 3; i++) {
+   ret = _dsi_pll_28nm_enable_seq_hpm(pll);
+   if (!ret)
+   return 0;
+   }
+
+   return ret;
+}
+
 static int dsi_pll_28nm_enable_seq_lp(struct msm_dsi_pll *pll)
 {
struct dsi_pll_28nm *pll_28nm = to_pll_28nm(pll);
@@ -619,15 +632,11 @@ struct msm_dsi_pll *msm_dsi_pll_28nm_init(struct 
platform_device *pdev,
if (type == MSM_DSI_PHY_28NM_HPM) {
pll_28nm->vco_delay = 1;
 
-   pll->en_seq_cnt = 3;
-   pll->enable_seqs[0] = dsi_pll_28nm_enable_seq_hpm;
-   pll->enable_seqs[1] = dsi_pll_28nm_enable_seq_hpm;
-   pll->enable_seqs[2] = dsi_pll_28nm_enable_seq_hpm;
+   pll->enable_seq = dsi_pll_28nm_enable_seq_hpm;
} else if (type == MSM_DSI_PHY_28NM_LP) {
pll_28nm->vco_delay = 1000;
 
-   pll->en_seq_cnt = 1;
-   pll->enable_seqs[0] = dsi_pll_28nm_enable_seq_lp;
+   pll->enable_seq = dsi_pll_28nm_enable_seq_lp;
} else {
DRM_DEV_ERROR(&pdev->dev, "phy type (%d) is not 28nm\n", type);
return ERR_PTR(-EINVAL);
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c
index 50ed935a5d3e..1b9a5abc9275 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c
@@ -515,8 +515,7 @@ struct msm_dsi_pll *msm_dsi_pll_28nm_8960_init(struct 
platform_device *pdev,
pll->save_state = dsi_pll_28nm_save_state;
pll->restore_state = dsi_pll_28nm_restore_state;
 
-   pll->en_seq_cnt = 1;
-   pll->enable_seqs[0] = dsi_pll_28nm_enable_seq;
+   pll->enable_seq = dsi_pll_28nm_enable_seq;
 
ret = pll_28nm_register(pll_28nm);
if (ret) {
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_pll.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_pll.c
index a45fe95aff49..b409ae2874b4 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_pll.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_pll.c
@@ -5,46 +5,6 @@
 
 #include "dsi_pll.h"
 
-static int dsi_pll_enable(struct msm_dsi_pll *pll)
-{
-   int i, ret = 0;
-
-   /*
-* Certain PLLs do not allow VCO rate update when it is on.
-* Keep track of their status to turn on/off after set rate success.
-*/
-   if (unlikely(pll->pll_on))
-   return 0;
-
-   /* Try all enable sequences until one succeeds */
-   for (i = 0; i < pll->en_seq_cnt; i++) {
-   ret = pll->enable_seqs[i](pll);
-   DBG("DSI PLL %s after sequence #%d",
-   ret ? "unlocked" : "locked", i + 1);
-   if (!ret)
-   break;
-   }
-
-   if (ret) {
-   DRM_ERROR("DSI PLL failed to lock\n");
-   return ret;
-   }
-
-   pll->pll_on = true;
-
-   return 0;
-}
-
-static void dsi_pll_disable(struct msm_dsi_pll *pll)
-{
-   if (unlikely(!pll->pll_on))
-   return;
-
-   pll->disab

[Freedreno] [RFC 03/24] drm/msm/dsi: move all PLL callbacks into PHY config struct

2021-03-01 Thread Dmitry Baryshkov
Move all PLL-related callbacks into struct msm_dsi_phy_cfg. This limits
the amount of data in the struct msm_dsi_pll.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/dsi.h |  6 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c | 14 +--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h | 15 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 38 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 47 ++---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 99 +++
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 33 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 48 ++---
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c | 67 +++--
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h | 65 +---
 10 files changed, 226 insertions(+), 206 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index 78ef5d4ed922..21cf883fb6f1 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -107,8 +107,6 @@ struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi 
*msm_dsi);
 /* dsi pll */
 struct msm_dsi_pll;
 #ifdef CONFIG_DRM_MSM_DSI_PLL
-struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device *pdev,
-   enum msm_dsi_phy_type type, int dsi_id);
 void msm_dsi_pll_destroy(struct msm_dsi_pll *pll);
 int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
@@ -117,10 +115,6 @@ int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
 int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
enum msm_dsi_phy_usecase uc);
 #else
-static inline struct msm_dsi_pll *msm_dsi_pll_init(struct platform_device 
*pdev,
-enum msm_dsi_phy_type type, int id) {
-   return ERR_PTR(-ENODEV);
-}
 static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll)
 {
 }
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index e8c1a727179c..33abeff16a6f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -715,12 +715,14 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
if (ret)
goto fail;
 
-   phy->pll = msm_dsi_pll_init(pdev, phy->cfg->type, phy->id);
-   if (IS_ERR_OR_NULL(phy->pll)) {
-   DRM_DEV_INFO(dev,
-   "%s: pll init failed: %ld, need separate pll clk 
driver\n",
-   __func__, PTR_ERR(phy->pll));
-   phy->pll = NULL;
+   if (phy->cfg->ops.pll_init) {
+   ret = phy->cfg->ops.pll_init(phy);
+   if (ret) {
+   DRM_DEV_INFO(dev,
+   "%s: pll init failed: %d, need separate pll clk 
driver\n",
+   __func__, ret);
+   goto fail;
+   }
}
 
dsi_phy_disable_resource(phy);
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index d2bd74b6f357..45ab2f23ac5b 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -18,15 +18,30 @@
 
 struct msm_dsi_phy_ops {
int (*init) (struct msm_dsi_phy *phy);
+   int (*pll_init)(struct msm_dsi_phy *phy);
int (*enable)(struct msm_dsi_phy *phy, int src_pll_id,
struct msm_dsi_phy_clk_request *clk_req);
void (*disable)(struct msm_dsi_phy *phy);
 };
 
+struct msm_dsi_pll_ops {
+   int (*enable_seq)(struct msm_dsi_pll *pll);
+   void (*disable_seq)(struct msm_dsi_pll *pll);
+   int (*get_provider)(struct msm_dsi_pll *pll,
+   struct clk **byte_clk_provider,
+   struct clk **pixel_clk_provider);
+   void (*destroy)(struct msm_dsi_pll *pll);
+   void (*save_state)(struct msm_dsi_pll *pll);
+   int (*restore_state)(struct msm_dsi_pll *pll);
+   int (*set_usecase)(struct msm_dsi_pll *pll,
+  enum msm_dsi_phy_usecase uc);
+};
+
 struct msm_dsi_phy_cfg {
enum msm_dsi_phy_type type;
struct dsi_reg_config reg_cfg;
struct msm_dsi_phy_ops ops;
+   const struct msm_dsi_pll_ops pll_ops;
 
/*
 * Each cell {phy_id, pll_id} of the truth table indicates
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 535d7e2393ae..49eb1440a269 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -828,15 +828,17 @@ static int pll_10nm_register(struct dsi_pll_10nm 
*pll_10nm)
return ret;
 }
 
-struct msm_dsi_pll *msm_dsi_pll_10nm_init(struct platform_device *pdev, int id)
+static int dsi_pll_10nm_init(struct msm_dsi_phy *phy)
 {
+   struct platform_device *pdev = phy->pdev;
+   int id = phy->id;
struct dsi_pll_10nm *pll_10nm;
str

[Freedreno] [RFC 04/24] drm/msm/dsi: move min/max PLL rate to phy config

2021-03-01 Thread Dmitry Baryshkov
Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h   |  3 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c  |  6 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c  |  6 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c  | 10 ++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c |  4 ++--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c   | 12 
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c   |  8 
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h   |  3 ---
 8 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 45ab2f23ac5b..ce2969c63927 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -43,6 +43,9 @@ struct msm_dsi_phy_cfg {
struct msm_dsi_phy_ops ops;
const struct msm_dsi_pll_ops pll_ops;
 
+   unsigned long   min_pll_rate;
+   unsigned long   max_pll_rate;
+
/*
 * Each cell {phy_id, pll_id} of the truth table indicates
 * if the source PLL selection bit should be set for each PHY.
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 49eb1440a269..799d7f44cf6d 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -861,8 +861,6 @@ static int dsi_pll_10nm_init(struct msm_dsi_phy *phy)
spin_lock_init(&pll_10nm->postdiv_lock);
 
pll = &pll_10nm->base;
-   pll->min_rate = 10UL;
-   pll->max_rate = 35UL;
pll->cfg = phy->cfg;
 
pll_10nm->vco_delay = 1;
@@ -1126,6 +1124,8 @@ const struct msm_dsi_phy_cfg dsi_phy_10nm_cfgs = {
.restore_state = dsi_pll_10nm_restore_state,
.set_usecase = dsi_pll_10nm_set_usecase,
},
+   .min_pll_rate = 10UL,
+   .max_pll_rate = 35UL,
.io_start = { 0xae94400, 0xae96400 },
.num_dsi_phy = 2,
 };
@@ -1152,6 +1152,8 @@ const struct msm_dsi_phy_cfg dsi_phy_10nm_8998_cfgs = {
.restore_state = dsi_pll_10nm_restore_state,
.set_usecase = dsi_pll_10nm_set_usecase,
},
+   .min_pll_rate = 10UL,
+   .max_pll_rate = 35UL,
.io_start = { 0xc994400, 0xc996400 },
.num_dsi_phy = 2,
.quirks = V3_0_0_10NM_OLD_TIMINGS_QUIRK,
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
index 82e5d225d83e..cd66b01ad17d 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
@@ -1078,8 +1078,6 @@ static int dsi_pll_14nm_init(struct msm_dsi_phy *phy)
spin_lock_init(&pll_14nm->postdiv_lock);
 
pll = &pll_14nm->base;
-   pll->min_rate = VCO_MIN_RATE;
-   pll->max_rate = VCO_MAX_RATE;
pll->cfg = phy->cfg;
 
pll_14nm->vco_delay = 1;
@@ -1253,6 +1251,8 @@ const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs = {
.disable_seq = dsi_pll_14nm_disable_seq,
.enable_seq = dsi_pll_14nm_enable_seq,
},
+   .min_pll_rate = VCO_MIN_RATE,
+   .max_pll_rate = VCO_MAX_RATE,
.io_start = { 0x994400, 0x996400 },
.num_dsi_phy = 2,
 };
@@ -1281,6 +1281,8 @@ const struct msm_dsi_phy_cfg dsi_phy_14nm_660_cfgs = {
.disable_seq = dsi_pll_14nm_disable_seq,
.enable_seq = dsi_pll_14nm_enable_seq,
},
+   .min_pll_rate = VCO_MIN_RATE,
+   .max_pll_rate = VCO_MAX_RATE,
.io_start = { 0xc994400, 0xc996000 },
.num_dsi_phy = 2,
 };
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
index 7330672d95c0..4ddb68f5a82a 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
@@ -622,8 +622,6 @@ static int dsi_pll_28nm_hpm_init(struct msm_dsi_phy *phy)
}
 
pll = &pll_28nm->base;
-   pll->min_rate = VCO_MIN_RATE;
-   pll->max_rate = VCO_MAX_RATE;
pll_28nm->vco_delay = 1;
 
pll->cfg = phy->cfg;
@@ -664,8 +662,6 @@ static int dsi_pll_28nm_lp_init(struct msm_dsi_phy *phy)
}
 
pll = &pll_28nm->base;
-   pll->min_rate = VCO_MIN_RATE;
-   pll->max_rate = VCO_MAX_RATE;
pll_28nm->vco_delay = 1000;
 
pll->cfg = phy->cfg;
@@ -849,6 +845,8 @@ const struct msm_dsi_phy_cfg dsi_phy_28nm_hpm_cfgs = {
.disable_seq = dsi_pll_28nm_disable_seq,
.enable_seq = dsi_pll_28nm_enable_seq_hpm,
},
+   .min_pll_rate = VCO_MIN_RATE,
+   .max_pll_rate = VCO_MAX_RATE,
.io_start = { 0xfd922b00, 0xfd923100 },
.num_dsi_phy = 2,
 };
@@ -876,6 +874,8 @@ const struct msm_dsi_phy_cfg dsi_phy_28nm_hpm_famb_cfgs = {
.disable_seq = dsi_pll_28nm_disable_seq,
.enable_seq = dsi_pll_28nm_enable_seq_hp

[Freedreno] [RFC 05/24] drm/msm/dsi: remove msm_dsi_pll_set_usecase

2021-03-01 Thread Dmitry Baryshkov
msm_dsi_pll_set_usecase() function is not used outside of individual DSI
PHY drivers, so drop it in favour of calling the the respective
set_usecase functions directly.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/dsi.h  | 7 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h  | 2 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c | 4 +---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c | 4 +---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c  | 4 +---
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c  | 9 -
 6 files changed, 3 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index 21cf883fb6f1..a130330b97b6 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -112,8 +112,6 @@ int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
 void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
 int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
-int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
-   enum msm_dsi_phy_usecase uc);
 #else
 static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll)
 {
@@ -130,11 +128,6 @@ static inline int msm_dsi_pll_restore_state(struct 
msm_dsi_pll *pll)
 {
return 0;
 }
-static inline int msm_dsi_pll_set_usecase(struct msm_dsi_pll *pll,
- enum msm_dsi_phy_usecase uc)
-{
-   return -ENODEV;
-}
 #endif
 
 /* dsi host */
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index ce2969c63927..b8dd8072d24c 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -33,8 +33,6 @@ struct msm_dsi_pll_ops {
void (*destroy)(struct msm_dsi_pll *pll);
void (*save_state)(struct msm_dsi_pll *pll);
int (*restore_state)(struct msm_dsi_pll *pll);
-   int (*set_usecase)(struct msm_dsi_pll *pll,
-  enum msm_dsi_phy_usecase uc);
 };
 
 struct msm_dsi_phy_cfg {
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 799d7f44cf6d..339f7a56e555 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -1046,7 +1046,7 @@ static int dsi_10nm_phy_enable(struct msm_dsi_phy *phy, 
int src_pll_id,
/* Select full-rate mode */
dsi_phy_write(base + REG_DSI_10nm_PHY_CMN_CTRL_2, 0x40);
 
-   ret = msm_dsi_pll_set_usecase(phy->pll, phy->usecase);
+   ret = dsi_pll_10nm_set_usecase(phy->pll, phy->usecase);
if (ret) {
DRM_DEV_ERROR(&phy->pdev->dev, "%s: set pll usecase failed, 
%d\n",
__func__, ret);
@@ -1122,7 +1122,6 @@ const struct msm_dsi_phy_cfg dsi_phy_10nm_cfgs = {
.destroy = dsi_pll_10nm_destroy,
.save_state = dsi_pll_10nm_save_state,
.restore_state = dsi_pll_10nm_restore_state,
-   .set_usecase = dsi_pll_10nm_set_usecase,
},
.min_pll_rate = 10UL,
.max_pll_rate = 35UL,
@@ -1150,7 +1149,6 @@ const struct msm_dsi_phy_cfg dsi_phy_10nm_8998_cfgs = {
.destroy = dsi_pll_10nm_destroy,
.save_state = dsi_pll_10nm_save_state,
.restore_state = dsi_pll_10nm_restore_state,
-   .set_usecase = dsi_pll_10nm_set_usecase,
},
.min_pll_rate = 10UL,
.max_pll_rate = 35UL,
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
index cd66b01ad17d..a141c37d86ab 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
@@ -1190,7 +1190,7 @@ static int dsi_14nm_phy_enable(struct msm_dsi_phy *phy, 
int src_pll_id,
REG_DSI_14nm_PHY_CMN_GLBL_TEST_CTRL,
DSI_14nm_PHY_CMN_GLBL_TEST_CTRL_BITCLK_HS_SEL);
 
-   ret = msm_dsi_pll_set_usecase(phy->pll, phy->usecase);
+   ret = dsi_pll_14nm_set_usecase(phy->pll, phy->usecase);
if (ret) {
DRM_DEV_ERROR(&phy->pdev->dev, "%s: set pll usecase failed, 
%d\n",
__func__, ret);
@@ -1247,7 +1247,6 @@ const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs = {
.destroy = dsi_pll_14nm_destroy,
.save_state = dsi_pll_14nm_save_state,
.restore_state = dsi_pll_14nm_restore_state,
-   .set_usecase = dsi_pll_14nm_set_usecase,
.disable_seq = dsi_pll_14nm_disable_seq,
.enable_seq = dsi_pll_14nm_enable_seq,
},
@@ -1277,7 +1276,6 @@ const struct msm_dsi_phy_cfg dsi_phy_14nm_660_cfgs = {
.destroy = dsi_pll_14nm_destroy,
.save_state = dsi_pll_14nm_save_state,
.restore_state = dsi_pll_14nm_restore_state,
-

[Freedreno] [RFC 06/24] drm/msm/dsi: stop setting clock parents manually

2021-03-01 Thread Dmitry Baryshkov
There is no reason to set clock parents manually, use device tree to
assign DSI/display clock parents to DSI PHY clocks. Dropping this manual
setup allows us to drop repeating code and to move registration of hw
clock providers to generic place.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/dsi.h |  9 
 drivers/gpu/drm/msm/dsi/dsi_host.c| 51 ---
 drivers/gpu/drm/msm/dsi/dsi_manager.c | 12 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |  3 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 19 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 17 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 18 ---
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 16 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 19 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c | 11 
 10 files changed, 175 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index a130330b97b6..da59f8bc8d2c 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -108,19 +108,12 @@ struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi 
*msm_dsi);
 struct msm_dsi_pll;
 #ifdef CONFIG_DRM_MSM_DSI_PLL
 void msm_dsi_pll_destroy(struct msm_dsi_pll *pll);
-int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
-   struct clk **byte_clk_provider, struct clk **pixel_clk_provider);
 void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
 int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
 #else
 static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll)
 {
 }
-static inline int msm_dsi_pll_get_clk_provider(struct msm_dsi_pll *pll,
-   struct clk **byte_clk_provider, struct clk **pixel_clk_provider)
-{
-   return -ENODEV;
-}
 static inline void msm_dsi_pll_save_state(struct msm_dsi_pll *pll)
 {
 }
@@ -155,8 +148,6 @@ unsigned long msm_dsi_host_get_mode_flags(struct 
mipi_dsi_host *host);
 struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host);
 int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer);
 void msm_dsi_host_unregister(struct mipi_dsi_host *host);
-int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
-   struct msm_dsi_pll *src_pll);
 void msm_dsi_host_reset_phy(struct mipi_dsi_host *host);
 void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
struct msm_dsi_phy_clk_request *clk_req,
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c 
b/drivers/gpu/drm/msm/dsi/dsi_host.c
index ab281cba0f08..bf3468ccc965 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -2225,57 +2225,6 @@ void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host 
*host, u32 dma_base,
wmb();
 }
 
-int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
-   struct msm_dsi_pll *src_pll)
-{
-   struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
-   struct clk *byte_clk_provider, *pixel_clk_provider;
-   int ret;
-
-   ret = msm_dsi_pll_get_clk_provider(src_pll,
-   &byte_clk_provider, &pixel_clk_provider);
-   if (ret) {
-   pr_info("%s: can't get provider from pll, don't set parent\n",
-   __func__);
-   return 0;
-   }
-
-   ret = clk_set_parent(msm_host->byte_clk_src, byte_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to byte_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-
-   ret = clk_set_parent(msm_host->pixel_clk_src, pixel_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to pixel_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-
-   if (msm_host->dsi_clk_src) {
-   ret = clk_set_parent(msm_host->dsi_clk_src, pixel_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to dsi_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-   }
-
-   if (msm_host->esc_clk_src) {
-   ret = clk_set_parent(msm_host->esc_clk_src, byte_clk_provider);
-   if (ret) {
-   pr_err("%s: can't set parent to esc_clk_src. ret=%d\n",
-   __func__, ret);
-   goto exit;
-   }
-   }
-
-exit:
-   return ret;
-}
-
 void msm_dsi_host_reset_phy(struct mipi_dsi_host *host)
 {
struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c 
b/drivers/gpu/drm/msm/dsi/dsi_manager.c
index 1d28dfba2c9b..6b65d86d116a 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_manager.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c
@@ -70,7 +70,6 @@ static int dsi_mgr_setup_components(int id)
struct msm_dsi *other_dsi = dsi_mgr_get_other_dsi(id);
struct m

[Freedreno] [RFC 09/24] clk: mux: provide devm_clk_hw_register_mux()

2021-03-01 Thread Dmitry Baryshkov
Add devm_clk_hw_register_mux() - devres-managed version of
clk_hw_register_mux().

Signed-off-by: Dmitry Baryshkov 
---
 drivers/clk/clk-mux.c| 35 +++
 include/linux/clk-provider.h | 13 +
 2 files changed, 48 insertions(+)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index e54e79714818..20582aae7a35 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -8,6 +8,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -206,6 +207,40 @@ struct clk_hw *__clk_hw_register_mux(struct device *dev, 
struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(__clk_hw_register_mux);
 
+static void devm_clk_hw_release_mux(struct device *dev, void *res)
+{
+   clk_hw_unregister_mux(*(struct clk_hw **)res);
+}
+
+struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct 
device_node *np,
+   const char *name, u8 num_parents,
+   const char * const *parent_names,
+   const struct clk_hw **parent_hws,
+   const struct clk_parent_data *parent_data,
+   unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
+   u8 clk_mux_flags, u32 *table, spinlock_t *lock)
+{
+   struct clk_hw **ptr, *hw;
+
+   ptr = devres_alloc(devm_clk_hw_release_mux, sizeof(*ptr), GFP_KERNEL);
+   if (!ptr)
+   return ERR_PTR(-ENOMEM);
+
+   hw = __clk_hw_register_mux(dev, np, name, num_parents, parent_names, 
parent_hws,
+  parent_data, flags, reg, shift, mask,
+  clk_mux_flags, table, lock);
+
+   if (!IS_ERR(hw)) {
+   *ptr = hw;
+   devres_add(dev, ptr);
+   } else {
+   devres_free(ptr);
+   }
+
+   return hw;
+}
+EXPORT_SYMBOL_GPL(__devm_clk_hw_register_mux);
+
 struct clk *clk_register_mux_table(struct device *dev, const char *name,
const char * const *parent_names, u8 num_parents,
unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 58f6fe866ae9..3eb15e0262f5 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -868,6 +868,13 @@ struct clk_hw *__clk_hw_register_mux(struct device *dev, 
struct device_node *np,
const struct clk_parent_data *parent_data,
unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
u8 clk_mux_flags, u32 *table, spinlock_t *lock);
+struct clk_hw *__devm_clk_hw_register_mux(struct device *dev, struct 
device_node *np,
+   const char *name, u8 num_parents,
+   const char * const *parent_names,
+   const struct clk_hw **parent_hws,
+   const struct clk_parent_data *parent_data,
+   unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
+   u8 clk_mux_flags, u32 *table, spinlock_t *lock);
 struct clk *clk_register_mux_table(struct device *dev, const char *name,
const char * const *parent_names, u8 num_parents,
unsigned long flags, void __iomem *reg, u8 shift, u32 mask,
@@ -902,6 +909,12 @@ struct clk *clk_register_mux_table(struct device *dev, 
const char *name,
__clk_hw_register_mux((dev), NULL, (name), (num_parents), NULL, NULL, \
  (parent_data), (flags), (reg), (shift), \
  BIT((width)) - 1, (clk_mux_flags), NULL, (lock))
+#define devm_clk_hw_register_mux(dev, name, parent_names, num_parents, flags, 
reg, \
+   shift, width, clk_mux_flags, lock)\
+   __devm_clk_hw_register_mux((dev), NULL, (name), (num_parents),\
+ (parent_names), NULL, NULL, (flags), (reg), \
+ (shift), BIT((width)) - 1, (clk_mux_flags), \
+ NULL, (lock))
 
 int clk_mux_val_to_index(struct clk_hw *hw, u32 *table, unsigned int flags,
 unsigned int val);
-- 
2.30.0

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 10/24] clk: divider: add devm_clk_hw_register_divider

2021-03-01 Thread Dmitry Baryshkov
Add devm_clk_hw_register_divider() - devres version of
clk_hw_register_divider().

Signed-off-by: Dmitry Baryshkov 
---
 include/linux/clk-provider.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 3eb15e0262f5..162a2e5546a3 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -785,6 +785,23 @@ struct clk *clk_register_divider_table(struct device *dev, 
const char *name,
  (parent_data), (flags), (reg), (shift), \
  (width), (clk_divider_flags), (table),  \
  (lock))
+/**
+ * devm_clk_hw_register_divider - register a divider clock with the clock 
framework
+ * @dev: device registering this clock
+ * @name: name of this clock
+ * @parent_name: name of clock's parent
+ * @flags: framework-specific flags
+ * @reg: register address to adjust divider
+ * @shift: number of bits to shift the bitfield
+ * @width: width of the bitfield
+ * @clk_divider_flags: divider-specific flags for this clock
+ * @lock: shared register lock for this clock
+ */
+#define devm_clk_hw_register_divider(dev, name, parent_name, flags, reg, 
shift,\
+   width, clk_divider_flags, lock)   \
+   __devm_clk_hw_register_divider((dev), NULL, (name), (parent_name), 
NULL,   \
+ NULL, (flags), (reg), (shift), (width), \
+ (clk_divider_flags), NULL, (lock))
 /**
  * devm_clk_hw_register_divider_table - register a table based divider clock
  * with the clock framework (devres variant)
-- 
2.30.0

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 08/24] drm/msm/dsi: push provided clocks handling into a generic code

2021-03-01 Thread Dmitry Baryshkov
All MSM DSI PHYs provide two clocks: byte and pixel ones.
Register/unregister provided clocks from the generic place, removing
boilerplate code from all MSM DSI PHY drivers.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c | 23 ++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |  6 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 36 ++-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 36 ++-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 44 ---
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 41 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 36 ++-
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c |  5 +--
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h |  3 +-
 9 files changed, 59 insertions(+), 171 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 33abeff16a6f..2742b18168b7 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  */
 
+#include 
 #include 
 
 #include "dsi_phy.h"
@@ -670,6 +671,14 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
if (!match)
return -ENODEV;
 
+   phy->provided_clocks = devm_kzalloc(dev, sizeof(*phy->provided_clocks) +
+  NUM_PROVIDED_CLKS * sizeof(struct clk_hw *),
+  GFP_KERNEL);
+   if (!phy->provided_clocks)
+   return -ENOMEM;
+
+   phy->provided_clocks->num = NUM_PROVIDED_CLKS;
+
phy->cfg = match->data;
phy->pdev = pdev;
 
@@ -725,6 +734,13 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
}
}
 
+   ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
+phy->provided_clocks);
+   if (ret) {
+   DRM_DEV_ERROR(dev, "%s: failed to register clk provider: %d\n", 
__func__, ret);
+   goto fail;
+   }
+
dsi_phy_disable_resource(phy);
 
platform_set_drvdata(pdev, phy);
@@ -732,6 +748,12 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
return 0;
 
 fail:
+   if (phy->pll) {
+   of_clk_del_provider(dev->of_node);
+   msm_dsi_pll_destroy(phy->pll);
+   phy->pll = NULL;
+   }
+
return ret;
 }
 
@@ -740,6 +762,7 @@ static int dsi_phy_driver_remove(struct platform_device 
*pdev)
struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
 
if (phy && phy->pll) {
+   of_clk_del_provider(pdev->dev.of_node);
msm_dsi_pll_destroy(phy->pll);
phy->pll = NULL;
}
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index ea1bd375b9ff..cb461c39c204 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -87,6 +87,10 @@ struct msm_dsi_dphy_timing {
u8 hs_halfbyte_en_ckln;
 };
 
+#define DSI_BYTE_PLL_CLK   0
+#define DSI_PIXEL_PLL_CLK  1
+#define NUM_PROVIDED_CLKS  2
+
 struct msm_dsi_phy {
struct platform_device *pdev;
void __iomem *base;
@@ -104,6 +108,8 @@ struct msm_dsi_phy {
bool regulator_ldo_mode;
 
struct msm_dsi_pll *pll;
+
+   struct clk_hw_onecell_data *provided_clocks;
 };
 
 /*
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index fee080677c36..6dc1c104d2f6 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -36,10 +36,6 @@
  *  dsi0_pll_post_out_div_clk
  */
 
-#define DSI_BYTE_PLL_CLK   0
-#define DSI_PIXEL_PLL_CLK  1
-#define NUM_PROVIDED_CLKS  2
-
 #define VCO_REF_CLK_RATE   1920
 
 struct dsi_pll_regs {
@@ -113,9 +109,6 @@ struct dsi_pll_10nm {
struct clk_hw *pclk_mux_hw;
struct clk_hw *out_dsiclk_hw;
 
-   /* clock-provider: */
-   struct clk_hw_onecell_data *hw_data;
-
struct pll_10nm_cached_state cached_state;
 
enum msm_dsi_phy_usecase uc;
@@ -621,10 +614,8 @@ static int dsi_pll_10nm_set_usecase(struct msm_dsi_pll 
*pll,
 static void dsi_pll_10nm_destroy(struct msm_dsi_pll *pll)
 {
struct dsi_pll_10nm *pll_10nm = to_pll_10nm(pll);
-   struct device *dev = &pll_10nm->pdev->dev;
 
DBG("DSI PLL%d", pll_10nm->id);
-   of_clk_del_provider(dev->of_node);
 
clk_hw_unregister_divider(pll_10nm->out_dsiclk_hw);
clk_hw_unregister_mux(pll_10nm->pclk_mux_hw);
@@ -642,7 +633,7 @@ static void dsi_pll_10nm_destroy(struct msm_dsi_pll *pll)
  * state to follow the master PLL's divider/mux state. Therefore, we don't
  * require special clock 

[Freedreno] [RFC 07/24] arm64: dts: qcom: sm8250: assign DSI clock source parents

2021-03-01 Thread Dmitry Baryshkov
Assign DSI clock source parents to DSI PHY clocks.

Signed-off-by: Dmitry Baryshkov 
---
 arch/arm64/boot/dts/qcom/sm8250.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi 
b/arch/arm64/boot/dts/qcom/sm8250.dtsi
index 947e1accae3a..b6ed94497e8a 100644
--- a/arch/arm64/boot/dts/qcom/sm8250.dtsi
+++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi
@@ -2445,6 +2445,9 @@ dsi0: dsi@ae94000 {
  "iface",
  "bus";
 
+   assigned-clocks = <&dispcc 
DISP_CC_MDSS_BYTE0_CLK_SRC>, <&dispcc DISP_CC_MDSS_PCLK0_CLK_SRC>;
+   assigned-clock-parents = <&dsi0_phy 0>, 
<&dsi0_phy 1>;
+
operating-points-v2 = <&dsi_opp_table>;
power-domains = <&rpmhpd SM8250_MMCX>;
 
@@ -2512,6 +2515,9 @@ dsi1: dsi@ae96000 {
  "iface",
  "bus";
 
+   assigned-clocks = <&dispcc 
DISP_CC_MDSS_BYTE1_CLK_SRC>, <&dispcc DISP_CC_MDSS_PCLK1_CLK_SRC>;
+   assigned-clock-parents = <&dsi1_phy 0>, 
<&dsi1_phy 1>;
+
operating-points-v2 = <&dsi_opp_table>;
power-domains = <&rpmhpd SM8250_MMCX>;
 
-- 
2.30.0

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 12/24] drm/msm/dsi: use devm_of_clk_add_hw_provider

2021-03-01 Thread Dmitry Baryshkov
Use devm_of_clk_add_hw_provider() to register provided clocks. This
allows dropping the remove function alltogether.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c | 22 +-
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 8c0bc5ccba8f..0c26451db310 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -734,7 +734,7 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
}
}
 
-   ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
+   ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
 phy->provided_clocks);
if (ret) {
DRM_DEV_ERROR(dev, "%s: failed to register clk provider: %d\n", 
__func__, ret);
@@ -748,31 +748,11 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
return 0;
 
 fail:
-   if (phy->pll) {
-   of_clk_del_provider(dev->of_node);
-   phy->pll = NULL;
-   }
-
return ret;
 }
 
-static int dsi_phy_driver_remove(struct platform_device *pdev)
-{
-   struct msm_dsi_phy *phy = platform_get_drvdata(pdev);
-
-   if (phy && phy->pll) {
-   of_clk_del_provider(pdev->dev.of_node);
-   phy->pll = NULL;
-   }
-
-   platform_set_drvdata(pdev, NULL);
-
-   return 0;
-}
-
 static struct platform_driver dsi_phy_platform_driver = {
.probe  = dsi_phy_driver_probe,
-   .remove = dsi_phy_driver_remove,
.driver = {
.name   = "msm_dsi_phy",
.of_match_table = dsi_phy_dt_match,
-- 
2.30.0

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 11/24] drm/msm/dsi: use devm_clk_*register to registe DSI PHY clocks

2021-03-01 Thread Dmitry Baryshkov
Use devres-enabled version of clock registration functions. This lets us
remove dsi_pll destroy callbacks completely.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/dsi.h |  4 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c |  2 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |  1 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 84 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 35 +---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 50 +--
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 39 +++--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 84 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c | 17 
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h |  4 -
 10 files changed, 71 insertions(+), 249 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index da59f8bc8d2c..c4a3ef4a3c09 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -107,13 +107,9 @@ struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi 
*msm_dsi);
 /* dsi pll */
 struct msm_dsi_pll;
 #ifdef CONFIG_DRM_MSM_DSI_PLL
-void msm_dsi_pll_destroy(struct msm_dsi_pll *pll);
 void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
 int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
 #else
-static inline void msm_dsi_pll_destroy(struct msm_dsi_pll *pll)
-{
-}
 static inline void msm_dsi_pll_save_state(struct msm_dsi_pll *pll)
 {
 }
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 2742b18168b7..8c0bc5ccba8f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -750,7 +750,6 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
 fail:
if (phy->pll) {
of_clk_del_provider(dev->of_node);
-   msm_dsi_pll_destroy(phy->pll);
phy->pll = NULL;
}
 
@@ -763,7 +762,6 @@ static int dsi_phy_driver_remove(struct platform_device 
*pdev)
 
if (phy && phy->pll) {
of_clk_del_provider(pdev->dev.of_node);
-   msm_dsi_pll_destroy(phy->pll);
phy->pll = NULL;
}
 
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index cb461c39c204..049feaaa479f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -27,7 +27,6 @@ struct msm_dsi_phy_ops {
 struct msm_dsi_pll_ops {
int (*enable_seq)(struct msm_dsi_pll *pll);
void (*disable_seq)(struct msm_dsi_pll *pll);
-   void (*destroy)(struct msm_dsi_pll *pll);
void (*save_state)(struct msm_dsi_pll *pll);
int (*restore_state)(struct msm_dsi_pll *pll);
 };
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 6dc1c104d2f6..6ddf852782a4 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -100,15 +100,6 @@ struct dsi_pll_10nm {
struct dsi_pll_config pll_configuration;
struct dsi_pll_regs reg_setup;
 
-   /* private clocks: */
-   struct clk_hw *out_div_clk_hw;
-   struct clk_hw *bit_clk_hw;
-   struct clk_hw *byte_clk_hw;
-   struct clk_hw *by_2_bit_clk_hw;
-   struct clk_hw *post_out_div_clk_hw;
-   struct clk_hw *pclk_mux_hw;
-   struct clk_hw *out_dsiclk_hw;
-
struct pll_10nm_cached_state cached_state;
 
enum msm_dsi_phy_usecase uc;
@@ -611,22 +602,6 @@ static int dsi_pll_10nm_set_usecase(struct msm_dsi_pll 
*pll,
return 0;
 }
 
-static void dsi_pll_10nm_destroy(struct msm_dsi_pll *pll)
-{
-   struct dsi_pll_10nm *pll_10nm = to_pll_10nm(pll);
-
-   DBG("DSI PLL%d", pll_10nm->id);
-
-   clk_hw_unregister_divider(pll_10nm->out_dsiclk_hw);
-   clk_hw_unregister_mux(pll_10nm->pclk_mux_hw);
-   clk_hw_unregister_fixed_factor(pll_10nm->post_out_div_clk_hw);
-   clk_hw_unregister_fixed_factor(pll_10nm->by_2_bit_clk_hw);
-   clk_hw_unregister_fixed_factor(pll_10nm->byte_clk_hw);
-   clk_hw_unregister_divider(pll_10nm->bit_clk_hw);
-   clk_hw_unregister_divider(pll_10nm->out_div_clk_hw);
-   clk_hw_unregister(&pll_10nm->base.clk_hw);
-}
-
 /*
  * The post dividers and mux clocks are created using the standard divider and
  * mux API. Unlike the 14nm PHY, the slave PLL doesn't need its dividers/mux
@@ -653,30 +628,28 @@ static int pll_10nm_register(struct dsi_pll_10nm 
*pll_10nm, struct clk_hw_onecel
snprintf(vco_name, 32, "dsi%dvco_clk", pll_10nm->id);
pll_10nm->base.clk_hw.init = &vco_init;
 
-   ret = clk_hw_register(dev, &pll_10nm->base.clk_hw);
+   ret = devm_clk_hw_register(dev, &pll_10nm->base.clk_hw);
if (ret)
return ret;
 
snprintf(clk_name, 32, "dsi%d_pll_out_div_clk", pll_10nm->id);
snprintf(parent, 32, "dsi%dvco_clk", pll_10nm->id);
 
-   hw = clk_hw_re

[Freedreno] [RFC 13/24] drm/msm/dsi: replace PHY's init callback with configurable data

2021-03-01 Thread Dmitry Baryshkov
DSI PHY init callback would either map dsi_phy_regulator or dsi_phy_lane
depending on the PHY type. Replace those callbacks with configuration
options governing mapping those regions.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c | 42 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |  4 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 19 +
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 19 +
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_20nm.c|  2 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c|  6 +--
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   |  2 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 19 +
 8 files changed, 31 insertions(+), 82 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 0c26451db310..4535cc5d22a5 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -638,24 +638,6 @@ static int dsi_phy_get_id(struct msm_dsi_phy *phy)
return -EINVAL;
 }
 
-int msm_dsi_phy_init_common(struct msm_dsi_phy *phy)
-{
-   struct platform_device *pdev = phy->pdev;
-   int ret = 0;
-
-   phy->reg_base = msm_ioremap(pdev, "dsi_phy_regulator",
-   "DSI_PHY_REG");
-   if (IS_ERR(phy->reg_base)) {
-   DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy regulator 
base\n",
-   __func__);
-   ret = -ENOMEM;
-   goto fail;
-   }
-
-fail:
-   return ret;
-}
-
 static int dsi_phy_driver_probe(struct platform_device *pdev)
 {
struct msm_dsi_phy *phy;
@@ -700,6 +682,24 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
goto fail;
}
 
+   if (phy->cfg->has_phy_lane) {
+   phy->lane_base = msm_ioremap(pdev, "dsi_phy_lane", 
"DSI_PHY_LANE");
+   if (IS_ERR(phy->lane_base)) {
+   DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy lane 
base\n", __func__);
+   ret = -ENOMEM;
+   goto fail;
+   }
+   }
+
+   if (phy->cfg->has_phy_regulator) {
+   phy->reg_base = msm_ioremap(pdev, "dsi_phy_regulator", 
"DSI_PHY_REG");
+   if (IS_ERR(phy->reg_base)) {
+   DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy 
regulator base\n", __func__);
+   ret = -ENOMEM;
+   goto fail;
+   }
+   }
+
ret = dsi_phy_regulator_init(phy);
if (ret)
goto fail;
@@ -711,12 +711,6 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
goto fail;
}
 
-   if (phy->cfg->ops.init) {
-   ret = phy->cfg->ops.init(phy);
-   if (ret)
-   goto fail;
-   }
-
/* PLL init will call into clk_register which requires
 * register access, so we need to enable power and ahb clock.
 */
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 049feaaa479f..06e560548c8e 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -17,7 +17,6 @@
 #define V3_0_0_10NM_OLD_TIMINGS_QUIRK  BIT(0)
 
 struct msm_dsi_phy_ops {
-   int (*init) (struct msm_dsi_phy *phy);
int (*pll_init)(struct msm_dsi_phy *phy);
int (*enable)(struct msm_dsi_phy *phy, int src_pll_id,
struct msm_dsi_phy_clk_request *clk_req);
@@ -49,6 +48,8 @@ struct msm_dsi_phy_cfg {
const resource_size_t io_start[DSI_MAX];
const int num_dsi_phy;
const int quirks;
+   bool has_phy_regulator;
+   bool has_phy_lane;
 };
 
 extern const struct msm_dsi_phy_cfg dsi_phy_28nm_hpm_cfgs;
@@ -124,7 +125,6 @@ int msm_dsi_dphy_timing_calc_v4(struct msm_dsi_dphy_timing 
*timing,
struct msm_dsi_phy_clk_request *clk_req);
 void msm_dsi_phy_set_src_pll(struct msm_dsi_phy *phy, int pll_id, u32 reg,
u32 bit_mask);
-int msm_dsi_phy_init_common(struct msm_dsi_phy *phy);
 
 #endif /* __DSI_PHY_H__ */
 
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 6ddf852782a4..9910cee8c9a5 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -992,24 +992,10 @@ static void dsi_10nm_phy_disable(struct msm_dsi_phy *phy)
DBG("DSI%d PHY disabled", phy->id);
 }
 
-static int dsi_10nm_phy_init(struct msm_dsi_phy *phy)
-{
-   struct platform_device *pdev = phy->pdev;
-
-   phy->lane_base = msm_ioremap(pdev, "dsi_phy_lane",
-"DSI_PHY_LANE");
-   if (IS_ERR(phy->lane_base)) {
-   DRM_DEV_ERROR(&pdev->dev, "%s: failed to map phy lane base\n",
-   __func__);
-   

[Freedreno] [RFC 15/24] drm/msm/dsi: limit vco_delay to 28nm PHY

2021-03-01 Thread Dmitry Baryshkov
Only 28nm PHY requires sleeping during the VCO rate setting procedure.
Rewrite sleeping for 28nm and drop vco_delay from the rest of PHYs.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c |  3 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c |  4 
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c | 10 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c  |  3 ---
 4 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 81ca0cf2a3ad..7533db8955a5 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -96,7 +96,6 @@ struct dsi_pll_10nm {
/* protects REG_DSI_10nm_PHY_CMN_CLK_CFG0 register */
spinlock_t postdiv_lock;
 
-   int vco_delay;
struct dsi_pll_config pll_configuration;
struct dsi_pll_regs reg_setup;
 
@@ -768,8 +767,6 @@ static int dsi_pll_10nm_init(struct msm_dsi_phy *phy)
pll = &pll_10nm->base;
pll->cfg = phy->cfg;
 
-   pll_10nm->vco_delay = 1;
-
ret = pll_10nm_register(pll_10nm, phy->provided_clocks);
if (ret) {
DRM_DEV_ERROR(&pdev->dev, "failed to register PLL: %d\n", ret);
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
index c531ddf26521..023727623847 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
@@ -122,8 +122,6 @@ struct dsi_pll_14nm {
void __iomem *phy_cmn_mmio;
void __iomem *mmio;
 
-   int vco_delay;
-
struct dsi_pll_input in;
struct dsi_pll_output out;
 
@@ -1012,8 +1010,6 @@ static int dsi_pll_14nm_init(struct msm_dsi_phy *phy)
pll = &pll_14nm->base;
pll->cfg = phy->cfg;
 
-   pll_14nm->vco_delay = 1;
-
ret = pll_14nm_register(pll_14nm, phy->provided_clocks);
if (ret) {
DRM_DEV_ERROR(&pdev->dev, "failed to register PLL: %d\n", ret);
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
index fa96bfc21fdb..e77b21f0d3bf 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c
@@ -69,8 +69,6 @@ struct dsi_pll_28nm {
struct platform_device *pdev;
void __iomem *mmio;
 
-   int vco_delay;
-
struct pll_28nm_cached_state cached_state;
 };
 
@@ -209,8 +207,10 @@ static int dsi_pll_28nm_clk_set_rate(struct clk_hw *hw, 
unsigned long rate,
pll_write(base + REG_DSI_28nm_PHY_PLL_SDM_CFG4, 0x00);
 
/* Add hardware recommended delay for correct PLL configuration */
-   if (pll_28nm->vco_delay)
-   udelay(pll_28nm->vco_delay);
+   if (pll->cfg->type == MSM_DSI_PHY_28NM_HPM)
+   udelay(1);
+   else /* LP */
+   udelay(1000);
 
pll_write(base + REG_DSI_28nm_PHY_PLL_REFCLK_CFG, refclk_cfg);
pll_write(base + REG_DSI_28nm_PHY_PLL_PWRGEN_CFG, 0x00);
@@ -576,7 +576,6 @@ static int dsi_pll_28nm_hpm_init(struct msm_dsi_phy *phy)
}
 
pll = &pll_28nm->base;
-   pll_28nm->vco_delay = 1;
 
pll->cfg = phy->cfg;
 
@@ -616,7 +615,6 @@ static int dsi_pll_28nm_lp_init(struct msm_dsi_phy *phy)
}
 
pll = &pll_28nm->base;
-   pll_28nm->vco_delay = 1000;
 
pll->cfg = phy->cfg;
 
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c
index c6f0aca66fa9..d3fea4a2b498 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c
@@ -96,7 +96,6 @@ struct dsi_pll_7nm {
/* protects REG_DSI_7nm_PHY_CMN_CLK_CFG0 register */
spinlock_t postdiv_lock;
 
-   int vco_delay;
struct dsi_pll_config pll_configuration;
struct dsi_pll_regs reg_setup;
 
@@ -793,8 +792,6 @@ static int dsi_pll_7nm_init(struct msm_dsi_phy *phy)
pll = &pll_7nm->base;
pll->cfg = phy->cfg;
 
-   pll_7nm->vco_delay = 1;
-
ret = pll_7nm_register(pll_7nm, phy->provided_clocks);
if (ret) {
DRM_DEV_ERROR(&pdev->dev, "failed to register PLL: %d\n", ret);
-- 
2.30.0

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 17/24] drm/msm/dsi: make save_state/restore_state callbacks accept msm_dsi_phy

2021-03-01 Thread Dmitry Baryshkov
Make save_state/restore callbacks accept struct msm_dsi_phy rather than
struct msm_dsi_pll. This moves them to struct msm_dsi_phy_ops, allowing
us to drop struct msm_dsi_pll_ops.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c | 12 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h | 11 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 22 ++---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 24 ++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 32 ---
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 18 +--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 22 ++---
 7 files changed, 59 insertions(+), 82 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index e9424a4c636e..2ef9abaf052d 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -847,9 +847,9 @@ void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
 
 void msm_dsi_phy_save_state(struct msm_dsi_phy *phy)
 {
-   if (phy->cfg->pll_ops.save_state) {
-   phy->cfg->pll_ops.save_state(phy->pll);
-   phy->pll->state_saved = true;
+   if (phy->cfg->ops.save_state) {
+   phy->cfg->ops.save_state(phy);
+   phy->state_saved = true;
}
 }
 
@@ -857,12 +857,12 @@ int msm_dsi_phy_restore_state(struct msm_dsi_phy *phy)
 {
int ret;
 
-   if (phy->cfg->pll_ops.restore_state && phy->pll->state_saved) {
-   ret = phy->cfg->pll_ops.restore_state(phy->pll);
+   if (phy->cfg->ops.restore_state && phy->state_saved) {
+   ret = phy->cfg->ops.restore_state(phy);
if (ret)
return ret;
 
-   phy->pll->state_saved = false;
+   phy->state_saved = false;
}
 
return 0;
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 0fff9e3afb53..179027b2c4e3 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -20,7 +20,6 @@
 struct msm_dsi_pll {
struct clk_hw   clk_hw;
boolpll_on;
-   boolstate_saved;
 
const struct msm_dsi_phy_cfg *cfg;
 };
@@ -32,18 +31,14 @@ struct msm_dsi_phy_ops {
int (*enable)(struct msm_dsi_phy *phy, int src_pll_id,
struct msm_dsi_phy_clk_request *clk_req);
void (*disable)(struct msm_dsi_phy *phy);
-};
-
-struct msm_dsi_pll_ops {
-   void (*save_state)(struct msm_dsi_pll *pll);
-   int (*restore_state)(struct msm_dsi_pll *pll);
+   void (*save_state)(struct msm_dsi_phy *phy);
+   int (*restore_state)(struct msm_dsi_phy *phy);
 };
 
 struct msm_dsi_phy_cfg {
enum msm_dsi_phy_type type;
struct dsi_reg_config reg_cfg;
struct msm_dsi_phy_ops ops;
-   const struct msm_dsi_pll_ops pll_ops;
 
unsigned long   min_pll_rate;
unsigned long   max_pll_rate;
@@ -119,6 +114,8 @@ struct msm_dsi_phy {
struct msm_dsi_pll *pll;
 
struct clk_hw_onecell_data *provided_clocks;
+
+   bool state_saved;
 };
 
 /*
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 7533db8955a5..1a470c7356ea 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -515,9 +515,9 @@ static const struct clk_ops clk_ops_dsi_pll_10nm_vco = {
  * PLL Callbacks
  */
 
-static void dsi_pll_10nm_save_state(struct msm_dsi_pll *pll)
+static void dsi_10nm_save_state(struct msm_dsi_phy *phy)
 {
-   struct dsi_pll_10nm *pll_10nm = to_pll_10nm(pll);
+   struct dsi_pll_10nm *pll_10nm = to_pll_10nm(phy->pll);
struct pll_10nm_cached_state *cached = &pll_10nm->cached_state;
void __iomem *phy_base = pll_10nm->phy_cmn_mmio;
u32 cmn_clk_cfg0, cmn_clk_cfg1;
@@ -538,9 +538,9 @@ static void dsi_pll_10nm_save_state(struct msm_dsi_pll *pll)
cached->pix_clk_div, cached->pll_mux);
 }
 
-static int dsi_pll_10nm_restore_state(struct msm_dsi_pll *pll)
+static int dsi_10nm_restore_state(struct msm_dsi_phy *phy)
 {
-   struct dsi_pll_10nm *pll_10nm = to_pll_10nm(pll);
+   struct dsi_pll_10nm *pll_10nm = to_pll_10nm(phy->pll);
struct pll_10nm_cached_state *cached = &pll_10nm->cached_state;
void __iomem *phy_base = pll_10nm->phy_cmn_mmio;
u32 val;
@@ -559,7 +559,7 @@ static int dsi_pll_10nm_restore_state(struct msm_dsi_pll 
*pll)
val |= cached->pll_mux;
pll_write(phy_base + REG_DSI_10nm_PHY_CMN_CLK_CFG1, val);
 
-   ret = dsi_pll_10nm_vco_set_rate(&pll->clk_hw, 
pll_10nm->vco_current_rate, pll_10nm->vco_ref_clk_rate);
+   ret = dsi_pll_10nm_vco_set_rate(&phy->pll->clk_hw, 
pll_10nm->vco_current_rate, pll_10nm->vco_ref_clk_rate);
if (ret) {
DRM_DEV_ERROR(&pll_10nm->pdev->dev,
 

[Freedreno] [RFC 16/24] drm/msi/dsi: inline msm_dsi_pll_helper_clk_prepare/unprepare

2021-03-01 Thread Dmitry Baryshkov
10nm and 7nm already do not use these helpers, as they handle setting
slave DSI clocks after enabling VCO. Modify the rest of PHY drivers to
remove unnecessary indirection and drop enable_seq/disable_seq PLL
callbacks.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |   2 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c|  87 +++--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c|  88 -
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 120 ++
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c |  35 -
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h |   2 -
 6 files changed, 170 insertions(+), 164 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 75fc24f9f013..0fff9e3afb53 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -35,8 +35,6 @@ struct msm_dsi_phy_ops {
 };
 
 struct msm_dsi_pll_ops {
-   int (*enable_seq)(struct msm_dsi_pll *pll);
-   void (*disable_seq)(struct msm_dsi_pll *pll);
void (*save_state)(struct msm_dsi_pll *pll);
int (*restore_state)(struct msm_dsi_pll *pll);
 };
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
index 023727623847..23f198164c0e 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
@@ -652,12 +652,58 @@ static unsigned long dsi_pll_14nm_vco_recalc_rate(struct 
clk_hw *hw,
return (unsigned long)vco_rate;
 }
 
+static int dsi_pll_14nm_vco_prepare(struct clk_hw *hw)
+{
+   struct msm_dsi_pll *pll = hw_clk_to_pll(hw);
+   struct dsi_pll_14nm *pll_14nm = to_pll_14nm(pll);
+   void __iomem *base = pll_14nm->mmio;
+   void __iomem *cmn_base = pll_14nm->phy_cmn_mmio;
+   bool locked;
+
+   DBG("");
+
+   if (unlikely(pll->pll_on))
+   return 0;
+
+   pll_write(base + REG_DSI_14nm_PHY_PLL_VREF_CFG1, 0x10);
+   pll_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 1);
+
+   locked = pll_14nm_poll_for_ready(pll_14nm, POLL_MAX_READS,
+POLL_TIMEOUT_US);
+
+   if (unlikely(!locked)) {
+   DRM_DEV_ERROR(&pll_14nm->pdev->dev, "DSI PLL lock failed\n");
+   return -EINVAL;
+   }
+
+   DBG("DSI PLL lock success");
+   pll->pll_on = true;
+
+   return 0;
+}
+
+static void dsi_pll_14nm_vco_unprepare(struct clk_hw *hw)
+{
+   struct msm_dsi_pll *pll = hw_clk_to_pll(hw);
+   struct dsi_pll_14nm *pll_14nm = to_pll_14nm(pll);
+   void __iomem *cmn_base = pll_14nm->phy_cmn_mmio;
+
+   DBG("");
+
+   if (unlikely(!pll->pll_on))
+   return;
+
+   pll_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 0);
+
+   pll->pll_on = false;
+}
+
 static const struct clk_ops clk_ops_dsi_pll_14nm_vco = {
.round_rate = msm_dsi_pll_helper_clk_round_rate,
.set_rate = dsi_pll_14nm_vco_set_rate,
.recalc_rate = dsi_pll_14nm_vco_recalc_rate,
-   .prepare = msm_dsi_pll_helper_clk_prepare,
-   .unprepare = msm_dsi_pll_helper_clk_unprepare,
+   .prepare = dsi_pll_14nm_vco_prepare,
+   .unprepare = dsi_pll_14nm_vco_unprepare,
 };
 
 /*
@@ -749,39 +795,6 @@ static const struct clk_ops clk_ops_dsi_pll_14nm_postdiv = 
{
  * PLL Callbacks
  */
 
-static int dsi_pll_14nm_enable_seq(struct msm_dsi_pll *pll)
-{
-   struct dsi_pll_14nm *pll_14nm = to_pll_14nm(pll);
-   void __iomem *base = pll_14nm->mmio;
-   void __iomem *cmn_base = pll_14nm->phy_cmn_mmio;
-   bool locked;
-
-   DBG("");
-
-   pll_write(base + REG_DSI_14nm_PHY_PLL_VREF_CFG1, 0x10);
-   pll_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 1);
-
-   locked = pll_14nm_poll_for_ready(pll_14nm, POLL_MAX_READS,
-POLL_TIMEOUT_US);
-
-   if (unlikely(!locked))
-   DRM_DEV_ERROR(&pll_14nm->pdev->dev, "DSI PLL lock failed\n");
-   else
-   DBG("DSI PLL lock success");
-
-   return locked ? 0 : -EINVAL;
-}
-
-static void dsi_pll_14nm_disable_seq(struct msm_dsi_pll *pll)
-{
-   struct dsi_pll_14nm *pll_14nm = to_pll_14nm(pll);
-   void __iomem *cmn_base = pll_14nm->phy_cmn_mmio;
-
-   DBG("");
-
-   pll_write(cmn_base + REG_DSI_14nm_PHY_CMN_PLL_CNTRL, 0);
-}
-
 static void dsi_pll_14nm_save_state(struct msm_dsi_pll *pll)
 {
struct dsi_pll_14nm *pll_14nm = to_pll_14nm(pll);
@@ -1158,8 +1171,6 @@ const struct msm_dsi_phy_cfg dsi_phy_14nm_cfgs = {
.pll_ops = {
.save_state = dsi_pll_14nm_save_state,
.restore_state = dsi_pll_14nm_restore_state,
-   .disable_seq = dsi_pll_14nm_disable_seq,
-   .enable_seq = dsi_pll_14nm_enable_seq,
},
.min_pll_rate = VCO_MIN_RATE,
.max_pll_rate = VCO_MAX_RATE,
@@ -1185,8 +1196,6 @@ const struct msm_dsi_phy_cfg dsi

[Freedreno] [RFC 18/24] drm/msm/dsi: drop msm_dsi_pll abstracton

2021-03-01 Thread Dmitry Baryshkov
Drop the struct msm_dsi_pll abstraction, by including vco's clk_hw
directly into struct msm_dsi_phy.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/Kconfig   |  8 --
 drivers/gpu/drm/msm/Makefile  |  2 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h | 36 +---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 66 +++---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 71 ---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 89 ++-
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 65 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 74 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c | 23 -
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h | 44 -
 10 files changed, 220 insertions(+), 258 deletions(-)
 delete mode 100644 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c
 delete mode 100644 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h

diff --git a/drivers/gpu/drm/msm/Kconfig b/drivers/gpu/drm/msm/Kconfig
index dabb4a1ccdcf..1f0b3f0e7149 100644
--- a/drivers/gpu/drm/msm/Kconfig
+++ b/drivers/gpu/drm/msm/Kconfig
@@ -76,14 +76,6 @@ config DRM_MSM_DSI
  Choose this option if you have a need for MIPI DSI connector
  support.
 
-config DRM_MSM_DSI_PLL
-   bool "Enable DSI PLL driver in MSM DRM"
-   depends on DRM_MSM_DSI && COMMON_CLK
-   default y
-   help
- Choose this option to enable DSI PLL driver which provides DSI
- source clocks under common clock framework.
-
 config DRM_MSM_DSI_28NM_PHY
bool "Enable DSI 28nm PHY driver in MSM DRM"
depends on DRM_MSM_DSI
diff --git a/drivers/gpu/drm/msm/Makefile b/drivers/gpu/drm/msm/Makefile
index 1be6996b80b7..610d630326bb 100644
--- a/drivers/gpu/drm/msm/Makefile
+++ b/drivers/gpu/drm/msm/Makefile
@@ -136,6 +136,4 @@ msm-$(CONFIG_DRM_MSM_DSI_14NM_PHY) += dsi/phy/dsi_phy_14nm.o
 msm-$(CONFIG_DRM_MSM_DSI_10NM_PHY) += dsi/phy/dsi_phy_10nm.o
 msm-$(CONFIG_DRM_MSM_DSI_7NM_PHY) += dsi/phy/dsi_phy_7nm.o
 
-msm-$(CONFIG_DRM_MSM_DSI_PLL) += dsi/phy/dsi_pll.o
-
 obj-$(CONFIG_DRM_MSM)  += msm.o
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 179027b2c4e3..b8e865979650 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -7,6 +7,7 @@
 #define __DSI_PHY_H__
 
 #include 
+#include 
 #include 
 
 #include "dsi.h"
@@ -17,15 +18,6 @@
 /* v3.0.0 10nm implementation that requires the old timings settings */
 #define V3_0_0_10NM_OLD_TIMINGS_QUIRK  BIT(0)
 
-struct msm_dsi_pll {
-   struct clk_hw   clk_hw;
-   boolpll_on;
-
-   const struct msm_dsi_phy_cfg *cfg;
-};
-
-#define hw_clk_to_pll(x) container_of(x, struct msm_dsi_pll, clk_hw)
-
 struct msm_dsi_phy_ops {
int (*pll_init)(struct msm_dsi_phy *phy);
int (*enable)(struct msm_dsi_phy *phy, int src_pll_id,
@@ -111,7 +103,8 @@ struct msm_dsi_phy {
enum msm_dsi_phy_usecase usecase;
bool regulator_ldo_mode;
 
-   struct msm_dsi_pll *pll;
+   struct clk_hw *vco_hw;
+   bool pll_on;
 
struct clk_hw_onecell_data *provided_clocks;
 
@@ -131,6 +124,27 @@ int msm_dsi_dphy_timing_calc_v4(struct msm_dsi_dphy_timing 
*timing,
struct msm_dsi_phy_clk_request *clk_req);
 void msm_dsi_phy_set_src_pll(struct msm_dsi_phy *phy, int pll_id, u32 reg,
u32 bit_mask);
+/* PLL accessors */
+static inline void pll_write(void __iomem *reg, u32 data)
+{
+   msm_writel(data, reg);
+}
+
+static inline u32 pll_read(const void __iomem *reg)
+{
+   return msm_readl(reg);
+}
+
+static inline void pll_write_udelay(void __iomem *reg, u32 data, u32 delay_us)
+{
+   pll_write(reg, data);
+   udelay(delay_us);
+}
+
+static inline void pll_write_ndelay(void __iomem *reg, u32 data, u32 delay_ns)
+{
+   pll_write((reg), data);
+   ndelay(delay_ns);
+}
 
 #endif /* __DSI_PHY_H__ */
-
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 1a470c7356ea..7bcef1cfd515 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -7,7 +7,6 @@
 #include 
 #include 
 
-#include "dsi_pll.h"
 #include "dsi_phy.h"
 #include "dsi.xml.h"
 
@@ -82,11 +81,13 @@ struct pll_10nm_cached_state {
 };
 
 struct dsi_pll_10nm {
-   struct msm_dsi_pll base;
+   struct clk_hw clk_hw;
 
int id;
struct platform_device *pdev;
 
+   struct msm_dsi_phy *phy;
+
void __iomem *phy_cmn_mmio;
void __iomem *mmio;
 
@@ -101,11 +102,10 @@ struct dsi_pll_10nm {
 
struct pll_10nm_cached_state cached_state;
 
-   enum msm_dsi_phy_usecase uc;
struct dsi_pll_10nm *slave;
 };
 
-#define to_pll_10nm(x) container_of(x, struct dsi_pll_10nm, base)
+#define to_pll_10nm(x) container_of(x, struct dsi_pll_10nm, clk_hw)
 
 /*
  * Global list of private DSI 

[Freedreno] [RFC 14/24] drm/msm/dsi: make save/restore_state phy-level functions

2021-03-01 Thread Dmitry Baryshkov
Morph msm_dsi_pll_save/restore_state() into msm_dsi_phy_save/restore_state(),
thus removing last bits of knowledge about msm_dsi_pll from dsi_manager.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/dsi.h  | 18 ++-
 drivers/gpu/drm/msm/dsi/dsi_manager.c  |  6 ++--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c  | 35 +++---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h  | 11 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c |  2 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c  |  2 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.c  | 26 
 drivers/gpu/drm/msm/dsi/phy/dsi_pll.h  | 11 ---
 8 files changed, 42 insertions(+), 69 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index c4a3ef4a3c09..351bfbeb53bd 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -104,21 +104,6 @@ static inline bool msm_dsi_device_connected(struct msm_dsi 
*msm_dsi)
 
 struct drm_encoder *msm_dsi_get_encoder(struct msm_dsi *msm_dsi);
 
-/* dsi pll */
-struct msm_dsi_pll;
-#ifdef CONFIG_DRM_MSM_DSI_PLL
-void msm_dsi_pll_save_state(struct msm_dsi_pll *pll);
-int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll);
-#else
-static inline void msm_dsi_pll_save_state(struct msm_dsi_pll *pll)
-{
-}
-static inline int msm_dsi_pll_restore_state(struct msm_dsi_pll *pll)
-{
-   return 0;
-}
-#endif
-
 /* dsi host */
 struct msm_dsi_host;
 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
@@ -192,9 +177,10 @@ int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int 
src_pll_id,
 void msm_dsi_phy_disable(struct msm_dsi_phy *phy);
 void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy *phy,
struct msm_dsi_phy_shared_timings *shared_timing);
-struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy);
 void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
 enum msm_dsi_phy_usecase uc);
+void msm_dsi_phy_save_state(struct msm_dsi_phy *phy);
+int msm_dsi_phy_restore_state(struct msm_dsi_phy *phy);
 
 #endif /* __DSI_CONNECTOR_H__ */
 
diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c 
b/drivers/gpu/drm/msm/dsi/dsi_manager.c
index 6b65d86d116a..2976b09a881d 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_manager.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c
@@ -493,7 +493,6 @@ static void dsi_mgr_bridge_post_disable(struct drm_bridge 
*bridge)
struct msm_dsi *msm_dsi1 = dsi_mgr_get_dsi(DSI_1);
struct mipi_dsi_host *host = msm_dsi->host;
struct drm_panel *panel = msm_dsi->panel;
-   struct msm_dsi_pll *src_pll;
bool is_dual_dsi = IS_DUAL_DSI();
int ret;
 
@@ -527,9 +526,8 @@ static void dsi_mgr_bridge_post_disable(struct drm_bridge 
*bridge)
id, ret);
}
 
-   /* Save PLL status if it is a clock source */
-   src_pll = msm_dsi_phy_get_pll(msm_dsi->phy);
-   msm_dsi_pll_save_state(src_pll);
+   /* Save PHY status if it is a clock source */
+   msm_dsi_phy_save_state(msm_dsi->phy);
 
ret = msm_dsi_host_power_off(host);
if (ret)
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 4535cc5d22a5..e9424a4c636e 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -799,9 +799,9 @@ int msm_dsi_phy_enable(struct msm_dsi_phy *phy, int 
src_pll_id,
 * source.
 */
if (phy->usecase != MSM_DSI_PHY_SLAVE) {
-   ret = msm_dsi_pll_restore_state(phy->pll);
+   ret = msm_dsi_phy_restore_state(phy);
if (ret) {
-   DRM_DEV_ERROR(dev, "%s: failed to restore pll state, 
%d\n",
+   DRM_DEV_ERROR(dev, "%s: failed to restore phy state, 
%d\n",
__func__, ret);
goto pll_restor_fail;
}
@@ -838,17 +838,32 @@ void msm_dsi_phy_get_shared_timings(struct msm_dsi_phy 
*phy,
   sizeof(*shared_timings));
 }
 
-struct msm_dsi_pll *msm_dsi_phy_get_pll(struct msm_dsi_phy *phy)
-{
-   if (!phy)
-   return NULL;
-
-   return phy->pll;
-}
-
 void msm_dsi_phy_set_usecase(struct msm_dsi_phy *phy,
 enum msm_dsi_phy_usecase uc)
 {
if (phy)
phy->usecase = uc;
 }
+
+void msm_dsi_phy_save_state(struct msm_dsi_phy *phy)
+{
+   if (phy->cfg->pll_ops.save_state) {
+   phy->cfg->pll_ops.save_state(phy->pll);
+   phy->pll->state_saved = true;
+   }
+}
+
+int msm_dsi_phy_restore_state(struct msm_dsi_phy *phy)
+{
+   int ret;
+
+   if (phy->cfg->pll_ops.restore_state && phy->pll->state_saved) {
+   ret = phy->cfg->pll_ops.restore_state(phy->pll);
+   if (ret)
+   return ret;
+
+   phy->pll->state_saved = false;
+   }
+
+

[Freedreno] [RFC 19/24] drm/msm/dsi: drop PLL accessor functions

2021-03-01 Thread Dmitry Baryshkov
Replace PLL accessor functions (pll_read/pll_write*) with the DSI PHY
accessors, reducing duplication.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |  24 +--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 124 
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 126 
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 118 +++
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   |  54 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 140 +-
 6 files changed, 283 insertions(+), 303 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index b8e865979650..43c4b43cb41f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -14,6 +14,8 @@
 
 #define dsi_phy_read(offset) msm_readl((offset))
 #define dsi_phy_write(offset, data) msm_writel((data), (offset))
+#define dsi_phy_write_udelay(offset, data, delay_us) { msm_writel((data), 
(offset)); udelay(delay_us); }
+#define dsi_phy_write_ndelay(offset, data, delay_ns) { msm_writel((data), 
(offset)); ndelay(delay_ns); }
 
 /* v3.0.0 10nm implementation that requires the old timings settings */
 #define V3_0_0_10NM_OLD_TIMINGS_QUIRK  BIT(0)
@@ -124,27 +126,5 @@ int msm_dsi_dphy_timing_calc_v4(struct msm_dsi_dphy_timing 
*timing,
struct msm_dsi_phy_clk_request *clk_req);
 void msm_dsi_phy_set_src_pll(struct msm_dsi_phy *phy, int pll_id, u32 reg,
u32 bit_mask);
-/* PLL accessors */
-static inline void pll_write(void __iomem *reg, u32 data)
-{
-   msm_writel(data, reg);
-}
-
-static inline u32 pll_read(const void __iomem *reg)
-{
-   return msm_readl(reg);
-}
-
-static inline void pll_write_udelay(void __iomem *reg, u32 data, u32 delay_us)
-{
-   pll_write(reg, data);
-   udelay(delay_us);
-}
-
-static inline void pll_write_ndelay(void __iomem *reg, u32 data, u32 delay_ns)
-{
-   pll_write((reg), data);
-   ndelay(delay_ns);
-}
 
 #endif /* __DSI_PHY_H__ */
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 7bcef1cfd515..6eb18a159bf5 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -231,19 +231,19 @@ static void dsi_pll_ssc_commit(struct dsi_pll_10nm *pll)
if (pll->pll_configuration.enable_ssc) {
pr_debug("SSC is enabled\n");
 
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_LOW_1,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_LOW_1,
  regs->ssc_stepsize_low);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_HIGH_1,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_STEPSIZE_HIGH_1,
  regs->ssc_stepsize_high);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_LOW_1,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_LOW_1,
  regs->ssc_div_per_low);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_HIGH_1,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_PER_HIGH_1,
  regs->ssc_div_per_high);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_LOW_1,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_LOW_1,
  regs->ssc_adjper_low);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_HIGH_1,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_DIV_ADJPER_HIGH_1,
  regs->ssc_adjper_high);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_SSC_CONTROL,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_SSC_CONTROL,
  SSC_EN | regs->ssc_control);
}
 }
@@ -252,26 +252,26 @@ static void dsi_pll_config_hzindep_reg(struct 
dsi_pll_10nm *pll)
 {
void __iomem *base = pll->mmio;
 
-   pll_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_ONE, 0x80);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_TWO, 0x03);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_THREE, 0x00);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_DSM_DIVIDER, 0x00);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_FEEDBACK_DIVIDER, 0x4e);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_CALIBRATION_SETTINGS, 0x40);
-   pll_write(base + REG_DSI_10nm_PHY_PLL_BAND_SEL_CAL_SETTINGS_THREE,
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_ONE, 0x80);
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_TWO, 0x03);
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_THREE, 0x00);
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_DSM_DIVIDER, 0x00);
+   dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_FEEDBACK_DIVIDER, 0x4e);
+   dsi_phy_write(ba

[Freedreno] [RFC 20/24] drm/msm/dsi: move ioremaps to dsi_phy_driver_probe

2021-03-01 Thread Dmitry Baryshkov
All PHY drivers would map dsi_pll area. Some PHY drivers would also
map dsi_phy area again (a leftover from old PHY/PLL separation). Move
all ioremaps to the common dsi_phy driver code and drop individual
ioremapped areas from PHY drivers.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c |  7 ++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h |  1 +
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 75 +++---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 49 
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 40 +++---
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 27 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 79 ---
 7 files changed, 108 insertions(+), 170 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
index 2ef9abaf052d..5b1cba4ba672 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.c
@@ -682,6 +682,13 @@ static int dsi_phy_driver_probe(struct platform_device 
*pdev)
goto fail;
}
 
+   phy->pll_base = msm_ioremap(pdev, "dsi_pll", "DSI_PLL");
+   if (IS_ERR(phy->pll_base)) {
+   DRM_DEV_ERROR(&pdev->dev, "%s: failed to map pll base\n", 
__func__);
+   ret = -ENOMEM;
+   goto fail;
+   }
+
if (phy->cfg->has_phy_lane) {
phy->lane_base = msm_ioremap(pdev, "dsi_phy_lane", 
"DSI_PHY_LANE");
if (IS_ERR(phy->lane_base)) {
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 43c4b43cb41f..0aa2729ed4b5 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -92,6 +92,7 @@ struct msm_dsi_dphy_timing {
 struct msm_dsi_phy {
struct platform_device *pdev;
void __iomem *base;
+   void __iomem *pll_base;
void __iomem *reg_base;
void __iomem *lane_base;
int id;
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 6eb18a159bf5..65e6ca2038c8 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -88,9 +88,6 @@ struct dsi_pll_10nm {
 
struct msm_dsi_phy *phy;
 
-   void __iomem *phy_cmn_mmio;
-   void __iomem *mmio;
-
u64 vco_ref_clk_rate;
u64 vco_current_rate;
 
@@ -225,7 +222,7 @@ static void dsi_pll_calc_ssc(struct dsi_pll_10nm *pll)
 
 static void dsi_pll_ssc_commit(struct dsi_pll_10nm *pll)
 {
-   void __iomem *base = pll->mmio;
+   void __iomem *base = pll->phy->pll_base;
struct dsi_pll_regs *regs = &pll->reg_setup;
 
if (pll->pll_configuration.enable_ssc) {
@@ -250,7 +247,7 @@ static void dsi_pll_ssc_commit(struct dsi_pll_10nm *pll)
 
 static void dsi_pll_config_hzindep_reg(struct dsi_pll_10nm *pll)
 {
-   void __iomem *base = pll->mmio;
+   void __iomem *base = pll->phy->pll_base;
 
dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_ONE, 0x80);
dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_ANALOG_CONTROLS_TWO, 0x03);
@@ -276,7 +273,7 @@ static void dsi_pll_config_hzindep_reg(struct dsi_pll_10nm 
*pll)
 
 static void dsi_pll_commit(struct dsi_pll_10nm *pll)
 {
-   void __iomem *base = pll->mmio;
+   void __iomem *base = pll->phy->pll_base;
struct dsi_pll_regs *reg = &pll->reg_setup;
 
dsi_phy_write(base + REG_DSI_10nm_PHY_PLL_CORE_INPUT_OVERRIDE, 0x12);
@@ -333,7 +330,7 @@ static int dsi_pll_10nm_lock_status(struct dsi_pll_10nm 
*pll)
u32 const delay_us = 100;
u32 const timeout_us = 5000;
 
-   rc = readl_poll_timeout_atomic(pll->mmio +
+   rc = readl_poll_timeout_atomic(pll->phy->pll_base +
   REG_DSI_10nm_PHY_PLL_COMMON_STATUS_ONE,
   status,
   ((status & BIT(0)) > 0),
@@ -348,21 +345,21 @@ static int dsi_pll_10nm_lock_status(struct dsi_pll_10nm 
*pll)
 
 static void dsi_pll_disable_pll_bias(struct dsi_pll_10nm *pll)
 {
-   u32 data = dsi_phy_read(pll->phy_cmn_mmio + 
REG_DSI_10nm_PHY_CMN_CTRL_0);
+   u32 data = dsi_phy_read(pll->phy->base + REG_DSI_10nm_PHY_CMN_CTRL_0);
 
-   dsi_phy_write(pll->mmio + REG_DSI_10nm_PHY_PLL_SYSTEM_MUXES, 0);
-   dsi_phy_write(pll->phy_cmn_mmio + REG_DSI_10nm_PHY_CMN_CTRL_0,
+   dsi_phy_write(pll->phy->pll_base + REG_DSI_10nm_PHY_PLL_SYSTEM_MUXES, 
0);
+   dsi_phy_write(pll->phy->base + REG_DSI_10nm_PHY_CMN_CTRL_0,
  data & ~BIT(5));
ndelay(250);
 }
 
 static void dsi_pll_enable_pll_bias(struct dsi_pll_10nm *pll)
 {
-   u32 data = dsi_phy_read(pll->phy_cmn_mmio + 
REG_DSI_10nm_PHY_CMN_CTRL_0);
+   u32 data = dsi_phy_read(pll->phy->base + REG_DSI_10nm_PHY_CMN_CTRL_0);
 
-   dsi_phy_write(pll->phy_cmn_mmio + REG_DSI_10nm_PHY_CMN_CTRL_0,
+   dsi_phy_wri

[Freedreno] [RFC 21/24] drm/msm/dsi: remove duplicate fields from dsi_pll_Nnm instances

2021-03-01 Thread Dmitry Baryshkov
Drop duplicate fields pdev and id from dsi_pll_Nnm instances. Reuse
those fields from the provided msm_dsi_phy.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c| 72 +--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c| 54 +++---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c| 51 ++---
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c   | 26 +++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c | 68 --
 5 files changed, 119 insertions(+), 152 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 65e6ca2038c8..e5ea16e4459f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -83,9 +83,6 @@ struct pll_10nm_cached_state {
 struct dsi_pll_10nm {
struct clk_hw clk_hw;
 
-   int id;
-   struct platform_device *pdev;
-
struct msm_dsi_phy *phy;
 
u64 vco_ref_clk_rate;
@@ -298,7 +295,7 @@ static int dsi_pll_10nm_vco_set_rate(struct clk_hw *hw, 
unsigned long rate,
 {
struct dsi_pll_10nm *pll_10nm = to_pll_10nm(hw);
 
-   DBG("DSI PLL%d rate=%lu, parent's=%lu", pll_10nm->id, rate,
+   DBG("DSI PLL%d rate=%lu, parent's=%lu", pll_10nm->phy->id, rate,
parent_rate);
 
pll_10nm->vco_current_rate = rate;
@@ -324,7 +321,7 @@ static int dsi_pll_10nm_vco_set_rate(struct clk_hw *hw, 
unsigned long rate,
 
 static int dsi_pll_10nm_lock_status(struct dsi_pll_10nm *pll)
 {
-   struct device *dev = &pll->pdev->dev;
+   struct device *dev = &pll->phy->pdev->dev;
int rc;
u32 status = 0;
u32 const delay_us = 100;
@@ -338,7 +335,7 @@ static int dsi_pll_10nm_lock_status(struct dsi_pll_10nm 
*pll)
   timeout_us);
if (rc)
DRM_DEV_ERROR(dev, "DSI PLL(%d) lock failed, status=0x%08x\n",
- pll->id, status);
+ pll->phy->id, status);
 
return rc;
 }
@@ -384,7 +381,7 @@ static void dsi_pll_enable_global_clk(struct dsi_pll_10nm 
*pll)
 static int dsi_pll_10nm_vco_prepare(struct clk_hw *hw)
 {
struct dsi_pll_10nm *pll_10nm = to_pll_10nm(hw);
-   struct device *dev = &pll_10nm->pdev->dev;
+   struct device *dev = &pll_10nm->phy->pdev->dev;
int rc;
 
dsi_pll_enable_pll_bias(pll_10nm);
@@ -410,7 +407,7 @@ static int dsi_pll_10nm_vco_prepare(struct clk_hw *hw)
/* Check for PLL lock */
rc = dsi_pll_10nm_lock_status(pll_10nm);
if (rc) {
-   DRM_DEV_ERROR(dev, "PLL(%d) lock failed\n", pll_10nm->id);
+   DRM_DEV_ERROR(dev, "PLL(%d) lock failed\n", pll_10nm->phy->id);
goto error;
}
 
@@ -491,7 +488,7 @@ static unsigned long dsi_pll_10nm_vco_recalc_rate(struct 
clk_hw *hw,
vco_rate = pll_freq;
 
DBG("DSI PLL%d returning vco rate = %lu, dec = %x, frac = %x",
-   pll_10nm->id, (unsigned long)vco_rate, dec, frac);
+   pll_10nm->phy->id, (unsigned long)vco_rate, dec, frac);
 
return (unsigned long)vco_rate;
 }
@@ -540,7 +537,7 @@ static void dsi_10nm_save_state(struct msm_dsi_phy *phy)
cached->pll_mux = cmn_clk_cfg1 & 0x3;
 
DBG("DSI PLL%d outdiv %x bit_clk_div %x pix_clk_div %x pll_mux %x",
-   pll_10nm->id, cached->pll_out_div, cached->bit_clk_div,
+   pll_10nm->phy->id, cached->pll_out_div, cached->bit_clk_div,
cached->pix_clk_div, cached->pll_mux);
 }
 
@@ -567,12 +564,12 @@ static int dsi_10nm_restore_state(struct msm_dsi_phy *phy)
 
ret = dsi_pll_10nm_vco_set_rate(phy->vco_hw, 
pll_10nm->vco_current_rate, pll_10nm->vco_ref_clk_rate);
if (ret) {
-   DRM_DEV_ERROR(&pll_10nm->pdev->dev,
+   DRM_DEV_ERROR(&pll_10nm->phy->pdev->dev,
"restore vco rate failed. ret=%d\n", ret);
return ret;
}
 
-   DBG("DSI PLL%d", pll_10nm->id);
+   DBG("DSI PLL%d", pll_10nm->phy->id);
 
return 0;
 }
@@ -583,13 +580,13 @@ static int dsi_10nm_set_usecase(struct msm_dsi_phy *phy)
void __iomem *base = pll_10nm->phy->base;
u32 data = 0x0; /* internal PLL */
 
-   DBG("DSI PLL%d", pll_10nm->id);
+   DBG("DSI PLL%d", pll_10nm->phy->id);
 
switch (phy->usecase) {
case MSM_DSI_PHY_STANDALONE:
break;
case MSM_DSI_PHY_MASTER:
-   pll_10nm->slave = pll_10nm_list[(pll_10nm->id + 1) % DSI_MAX];
+   pll_10nm->slave = pll_10nm_list[(pll_10nm->phy->id + 1) % 
DSI_MAX];
break;
case MSM_DSI_PHY_SLAVE:
data = 0x1; /* external PLL */
@@ -621,21 +618,21 @@ static int pll_10nm_register(struct dsi_pll_10nm 
*pll_10nm, struct clk_hw_onecel
.flags = CLK_IGNORE_UNUSED,
.ops = &clk_ops_dsi_pll_10nm_vco,
};
-   struct device *dev =

[Freedreno] [RFC 22/24] drm/msm/dsi: remove temp data from global pll structure

2021-03-01 Thread Dmitry Baryshkov
The 7nm, 10nm and 14nm drivers would store interim data used during
VCO/PLL rate setting in the global dsi_pll_Nnm structure. Move this data
structures to the onstack storage. While we are at it, drop
unused/static 'config' data, unused config fields, etc.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c | 167 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c | 342 +++--
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c  | 161 --
 3 files changed, 221 insertions(+), 449 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index e5ea16e4459f..5456ba67245c 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -36,40 +36,22 @@
  */
 
 #define VCO_REF_CLK_RATE   1920
-
-struct dsi_pll_regs {
-   u32 pll_prop_gain_rate;
-   u32 pll_lockdet_rate;
-   u32 decimal_div_start;
-   u32 frac_div_start_low;
-   u32 frac_div_start_mid;
-   u32 frac_div_start_high;
-   u32 pll_clock_inverters;
-   u32 ssc_stepsize_low;
-   u32 ssc_stepsize_high;
-   u32 ssc_div_per_low;
-   u32 ssc_div_per_high;
-   u32 ssc_adjper_low;
-   u32 ssc_adjper_high;
-   u32 ssc_control;
-};
+#define FRAC_BITS 18
 
 struct dsi_pll_config {
-   u32 ref_freq;
-   bool div_override;
-   u32 output_div;
-   bool ignore_frac;
-   bool disable_prescaler;
bool enable_ssc;
bool ssc_center;
-   u32 dec_bits;
-   u32 frac_bits;
-   u32 lock_timer;
u32 ssc_freq;
u32 ssc_offset;
u32 ssc_adj_per;
-   u32 thresh_cycles;
-   u32 refclk_cycles;
+
+   /* out */
+   u32 pll_prop_gain_rate;
+   u32 decimal_div_start;
+   u32 frac_div_start;
+   u32 pll_clock_inverters;
+   u32 ssc_stepsize;
+   u32 ssc_div_per;
 };
 
 struct pll_10nm_cached_state {
@@ -85,15 +67,11 @@ struct dsi_pll_10nm {
 
struct msm_dsi_phy *phy;
 
-   u64 vco_ref_clk_rate;
u64 vco_current_rate;
 
/* protects REG_DSI_10nm_PHY_CMN_CLK_CFG0 register */
spinlock_t postdiv_lock;
 
-   struct dsi_pll_config pll_configuration;
-   struct dsi_pll_regs reg_setup;
-
struct pll_10nm_cached_state cached_state;
 
struct dsi_pll_10nm *slave;
@@ -107,34 +85,19 @@ struct dsi_pll_10nm {
  */
 static struct dsi_pll_10nm *pll_10nm_list[DSI_MAX];
 
-static void dsi_pll_setup_config(struct dsi_pll_10nm *pll)
+static void dsi_pll_setup_config(struct dsi_pll_config *config)
 {
-   struct dsi_pll_config *config = &pll->pll_configuration;
-
-   config->ref_freq = pll->vco_ref_clk_rate;
-   config->output_div = 1;
-   config->dec_bits = 8;
-   config->frac_bits = 18;
-   config->lock_timer = 64;
config->ssc_freq = 31500;
config->ssc_offset = 5000;
config->ssc_adj_per = 2;
-   config->thresh_cycles = 32;
-   config->refclk_cycles = 256;
-
-   config->div_override = false;
-   config->ignore_frac = false;
-   config->disable_prescaler = false;
 
config->enable_ssc = false;
-   config->ssc_center = 0;
+   config->ssc_center = false;
 }
 
-static void dsi_pll_calc_dec_frac(struct dsi_pll_10nm *pll)
+static void dsi_pll_calc_dec_frac(struct dsi_pll_10nm *pll, struct 
dsi_pll_config *config)
 {
-   struct dsi_pll_config *config = &pll->pll_configuration;
-   struct dsi_pll_regs *regs = &pll->reg_setup;
-   u64 fref = pll->vco_ref_clk_rate;
+   u64 fref = VCO_REF_CLK_RATE;
u64 pll_freq;
u64 divider;
u64 dec, dec_multiple;
@@ -143,40 +106,32 @@ static void dsi_pll_calc_dec_frac(struct dsi_pll_10nm 
*pll)
 
pll_freq = pll->vco_current_rate;
 
-   if (config->disable_prescaler)
-   divider = fref;
-   else
-   divider = fref * 2;
+   divider = fref * 2;
 
-   multiplier = 1 << config->frac_bits;
+   multiplier = 1 << FRAC_BITS;
dec_multiple = div_u64(pll_freq * multiplier, divider);
dec = div_u64_rem(dec_multiple, multiplier, &frac);
 
if (pll_freq <= 19UL)
-   regs->pll_prop_gain_rate = 8;
+   config->pll_prop_gain_rate = 8;
else if (pll_freq <= 30UL)
-   regs->pll_prop_gain_rate = 10;
+   config->pll_prop_gain_rate = 10;
else
-   regs->pll_prop_gain_rate = 12;
+   config->pll_prop_gain_rate = 12;
if (pll_freq < 11UL)
-   regs->pll_clock_inverters = 8;
+   config->pll_clock_inverters = 8;
else
-   regs->pll_clock_inverters = 0;
+   config->pll_clock_inverters = 0;
 
-   regs->pll_lockdet_rate = config->lock_timer;
-   regs->decimal_div_start = dec;
-   regs->frac_div_start_low = (frac & 0xff);
-   regs->frac_div_start_mid = (frac & 0xff00

[Freedreno] [RFC 24/24] arm64: dts: qcom: sdm845: assign DSI clock source parents

2021-03-01 Thread Dmitry Baryshkov
Assign DSI clock source parents to DSI PHY clocks.

Signed-off-by: Dmitry Baryshkov 
---
 arch/arm64/boot/dts/qcom/sdm845.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sdm845.dtsi 
b/arch/arm64/boot/dts/qcom/sdm845.dtsi
index 454f794af547..2166549382c1 100644
--- a/arch/arm64/boot/dts/qcom/sdm845.dtsi
+++ b/arch/arm64/boot/dts/qcom/sdm845.dtsi
@@ -4113,6 +4113,9 @@ dsi0: dsi@ae94000 {
  "core",
  "iface",
  "bus";
+   assigned-clocks = <&dispcc 
DISP_CC_MDSS_BYTE0_CLK_SRC>, <&dispcc DISP_CC_MDSS_PCLK0_CLK_SRC>;
+   assigned-clock-parents = <&dsi0_phy 0>, 
<&dsi0_phy 1>;
+
operating-points-v2 = <&dsi_opp_table>;
power-domains = <&rpmhpd SDM845_CX>;
 
@@ -4179,6 +4182,9 @@ dsi1: dsi@ae96000 {
  "core",
  "iface",
  "bus";
+   assigned-clocks = <&dispcc 
DISP_CC_MDSS_BYTE1_CLK_SRC>, <&dispcc DISP_CC_MDSS_PCLK1_CLK_SRC>;
+   assigned-clock-parents = <&dsi1_phy 0>, 
<&dsi1_phy 1>;
+
operating-points-v2 = <&dsi_opp_table>;
power-domains = <&rpmhpd SDM845_CX>;
 
-- 
2.30.0

___
Freedreno mailing list
Freedreno@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/freedreno


[Freedreno] [RFC 23/24] drm/msm/dsi: drop global msm_dsi_phy_type enumaration

2021-03-01 Thread Dmitry Baryshkov
With the current upstream driver the msm_dsi_phy_type enum does not make
much sense: all DSI PHYs are probed using the dt bindings, the phy type
is not passed between drivers. Use quirks in phy individual PHY drivers
to differentiate minor harware differences and drop the enum.

Signed-off-by: Dmitry Baryshkov 
---
 drivers/gpu/drm/msm/dsi/dsi.h  | 12 
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h  |  4 
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c | 11 ++-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c |  2 --
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_20nm.c |  1 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_28nm.c | 15 ---
 .../gpu/drm/msm/dsi/phy/dsi_phy_28nm_8960.c|  1 -
 drivers/gpu/drm/msm/dsi/phy/dsi_phy_7nm.c  | 18 ++
 8 files changed, 24 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index 351bfbeb53bd..5c32ee2b3605 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -23,18 +23,6 @@
 struct msm_dsi_phy_shared_timings;
 struct msm_dsi_phy_clk_request;
 
-enum msm_dsi_phy_type {
-   MSM_DSI_PHY_28NM_HPM,
-   MSM_DSI_PHY_28NM_LP,
-   MSM_DSI_PHY_20NM,
-   MSM_DSI_PHY_28NM_8960,
-   MSM_DSI_PHY_14NM,
-   MSM_DSI_PHY_10NM,
-   MSM_DSI_PHY_7NM,
-   MSM_DSI_PHY_7NM_V4_1,
-   MSM_DSI_PHY_MAX
-};
-
 enum msm_dsi_phy_usecase {
MSM_DSI_PHY_STANDALONE,
MSM_DSI_PHY_MASTER,
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
index 0aa2729ed4b5..8e828c5ca8f4 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy.h
@@ -17,9 +17,6 @@
 #define dsi_phy_write_udelay(offset, data, delay_us) { msm_writel((data), 
(offset)); udelay(delay_us); }
 #define dsi_phy_write_ndelay(offset, data, delay_ns) { msm_writel((data), 
(offset)); ndelay(delay_ns); }
 
-/* v3.0.0 10nm implementation that requires the old timings settings */
-#define V3_0_0_10NM_OLD_TIMINGS_QUIRK  BIT(0)
-
 struct msm_dsi_phy_ops {
int (*pll_init)(struct msm_dsi_phy *phy);
int (*enable)(struct msm_dsi_phy *phy, int src_pll_id,
@@ -30,7 +27,6 @@ struct msm_dsi_phy_ops {
 };
 
 struct msm_dsi_phy_cfg {
-   enum msm_dsi_phy_type type;
struct dsi_reg_config reg_cfg;
struct msm_dsi_phy_ops ops;
 
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
index 5456ba67245c..6bb6507d6a2f 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_10nm.c
@@ -38,6 +38,9 @@
 #define VCO_REF_CLK_RATE   1920
 #define FRAC_BITS 18
 
+/* v3.0.0 10nm implementation that requires the old timings settings */
+#define DSI_PHY_10NM_QUIRK_OLD_TIMINGS BIT(0)
+
 struct dsi_pll_config {
bool enable_ssc;
bool ssc_center;
@@ -741,7 +744,7 @@ static void dsi_phy_hw_v3_0_lane_settings(struct 
msm_dsi_phy *phy)
u8 tx_dctrl[] = { 0x00, 0x00, 0x00, 0x04, 0x01 };
void __iomem *lane_base = phy->lane_base;
 
-   if (phy->cfg->quirks & V3_0_0_10NM_OLD_TIMINGS_QUIRK)
+   if (phy->cfg->quirks & DSI_PHY_10NM_QUIRK_OLD_TIMINGS)
tx_dctrl[3] = 0x02;
 
/* Strength ctrl settings */
@@ -776,7 +779,7 @@ static void dsi_phy_hw_v3_0_lane_settings(struct 
msm_dsi_phy *phy)
  tx_dctrl[i]);
}
 
-   if (!(phy->cfg->quirks & V3_0_0_10NM_OLD_TIMINGS_QUIRK)) {
+   if (!(phy->cfg->quirks & DSI_PHY_10NM_QUIRK_OLD_TIMINGS)) {
/* Toggle BIT 0 to release freeze I/0 */
dsi_phy_write(lane_base + REG_DSI_10nm_PHY_LN_TX_DCTRL(3), 
0x05);
dsi_phy_write(lane_base + REG_DSI_10nm_PHY_LN_TX_DCTRL(3), 
0x04);
@@ -916,7 +919,6 @@ static void dsi_10nm_phy_disable(struct msm_dsi_phy *phy)
 }
 
 const struct msm_dsi_phy_cfg dsi_phy_10nm_cfgs = {
-   .type = MSM_DSI_PHY_10NM,
.src_pll_truthtable = { {false, false}, {true, false} },
.has_phy_lane = true,
.reg_cfg = {
@@ -939,7 +941,6 @@ const struct msm_dsi_phy_cfg dsi_phy_10nm_cfgs = {
 };
 
 const struct msm_dsi_phy_cfg dsi_phy_10nm_8998_cfgs = {
-   .type = MSM_DSI_PHY_10NM,
.src_pll_truthtable = { {false, false}, {true, false} },
.has_phy_lane = true,
.reg_cfg = {
@@ -959,5 +960,5 @@ const struct msm_dsi_phy_cfg dsi_phy_10nm_8998_cfgs = {
.max_pll_rate = 35UL,
.io_start = { 0xc994400, 0xc996400 },
.num_dsi_phy = 2,
-   .quirks = V3_0_0_10NM_OLD_TIMINGS_QUIRK,
+   .quirks = DSI_PHY_10NM_QUIRK_OLD_TIMINGS,
 };
diff --git a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c 
b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
index 88800d68b1bb..b4257434e4ee 100644
--- a/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
+++ b/drivers/gpu/drm/msm/dsi/phy/dsi_phy_14nm.c
@@ -1022,7 +1022,6 @@ static void dsi_14nm_phy_disable(struct