| @@ -11,6 +11,7 @@ · 10 unmodified lines |
| 11 | * | 11 | * |
| 12 | */ | 12 | */ |
| 13 | | 13 | |
| | 14 | #include <linux/bitfield.h> |
| 14 | #include <linux/clk-provider.h> | 15 | #include <linux/clk-provider.h> |
| 15 | #include <linux/clkdev.h> | 16 | #include <linux/clkdev.h> |
| 16 | #include <linux/clk/at91_pmc.h> | 17 | #include <linux/clk/at91_pmc.h> |
| @@ -31,6 +32,7 @@ struct clk_generated { · 14 unmodified lines |
| 31 | spinlock_t *lock; | 32 | spinlock_t *lock; |
| 32 | u32 id; | 33 | u32 id; |
| 33 | u32 gckdiv; | 34 | u32 gckdiv; |
| | 35 | const struct clk_pcr_layout *layout; |
| 34 | u8 parent_id; | 36 | u8 parent_id; |
| 35 | bool audio_pll_allowed; | 37 | bool audio_pll_allowed; |
| 36 | }; | 38 | }; |
| @@ -47,14 +49,14 @@ static int clk_generated_enable(struct clk_hw *hw) · 10 unmodified lines |
| 47 | __func__, gck->gckdiv, gck->parent_id); | 49 | __func__, gck->gckdiv, gck->parent_id); |
| 48 | | 50 | |
| 49 | spin_lock_irqsave(gck->lock, flags); | 51 | spin_lock_irqsave(gck->lock, flags); |
| 50 | regmap_write(gck->regmap, AT91_PMC_PCR, | 52 | regmap_write(gck->regmap, gck->layout->offset, |
| 51 | (gck->id & AT91_PMC_PCR_PID_MASK)); | 53 | (gck->id & gck->layout->pid_mask)); |
| 52 | regmap_update_bits(gck->regmap, AT91_PMC_PCR, | 54 | regmap_update_bits(gck->regmap, gck->layout->offset, |
| 53 | AT91_PMC_PCR_GCKDIV_MASK | AT91_PMC_PCR_GCKCSS_MASK | | 55 | AT91_PMC_PCR_GCKDIV_MASK | gck->layout->gckcss_mask | |
| 54 | AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN, | 56 | gck->layout->cmd | AT91_PMC_PCR_GCKEN, |
| 55 | AT91_PMC_PCR_GCKCSS(gck->parent_id) | | 57 | field_prep(gck->layout->gckcss_mask, gck->parent_id) | |
| 56 | AT91_PMC_PCR_CMD | | 58 | gck->layout->cmd | |
| 57 | AT91_PMC_PCR_GCKDIV(gck->gckdiv) | | 59 | FIELD_PREP(AT91_PMC_PCR_GCKDIV_MASK, gck->gckdiv) | |
| 58 | AT91_PMC_PCR_GCKEN); | 60 | AT91_PMC_PCR_GCKEN); |
| 59 | spin_unlock_irqrestore(gck->lock, flags); | 61 | spin_unlock_irqrestore(gck->lock, flags); |
| 60 | return 0; | 62 | return 0; |
| @@ -66,11 +68,11 @@ static void clk_generated_disable(struct clk_hw *hw) · 5 unmodified lines |
| 66 | unsigned long flags; | 68 | unsigned long flags; |
| 67 | | 69 | |
| 68 | spin_lock_irqsave(gck->lock, flags); | 70 | spin_lock_irqsave(gck->lock, flags); |
| 69 | regmap_write(gck->regmap, AT91_PMC_PCR, | 71 | regmap_write(gck->regmap, gck->layout->offset, |
| 70 | (gck->id & AT91_PMC_PCR_PID_MASK)); | 72 | (gck->id & gck->layout->pid_mask)); |
| 71 | regmap_update_bits(gck->regmap, AT91_PMC_PCR, | 73 | regmap_update_bits(gck->regmap, gck->layout->offset, |
| 72 | AT91_PMC_PCR_CMD | AT91_PMC_PCR_GCKEN, | 74 | gck->layout->cmd | AT91_PMC_PCR_GCKEN, |
| 73 | AT91_PMC_PCR_CMD); | 75 | gck->layout->cmd); |
| 74 | spin_unlock_irqrestore(gck->lock, flags); | 76 | spin_unlock_irqrestore(gck->lock, flags); |
| 75 | } | 77 | } |
| 76 | | 78 | |
| @@ -81,9 +83,9 @@ static int clk_generated_is_enabled(struct clk_hw *hw) · 4 unmodified lines |
| 81 | unsigned int status; | 83 | unsigned int status; |
| 82 | | 84 | |
| 83 | spin_lock_irqsave(gck->lock, flags); | 85 | spin_lock_irqsave(gck->lock, flags); |
| 84 | regmap_write(gck->regmap, AT91_PMC_PCR, | 86 | regmap_write(gck->regmap, gck->layout->offset, |
| 85 | (gck->id & AT91_PMC_PCR_PID_MASK)); | 87 | (gck->id & gck->layout->pid_mask)); |
| 86 | regmap_read(gck->regmap, AT91_PMC_PCR, &status); | 88 | regmap_read(gck->regmap, gck->layout->offset, &status); |
| 87 | spin_unlock_irqrestore(gck->lock, flags); | 89 | spin_unlock_irqrestore(gck->lock, flags); |
| 88 | | 90 | |
| 89 | return status & AT91_PMC_PCR_GCKEN ? 1 : 0; | 91 | return status & AT91_PMC_PCR_GCKEN ? 1 : 0; |
| @@ -259,19 +261,18 @@ static void clk_generated_startup(struct clk_generated *gck) · 169 unmodified lines |
| 259 | unsigned long flags; | 261 | unsigned long flags; |
| 260 | | 262 | |
| 261 | spin_lock_irqsave(gck->lock, flags); | 263 | spin_lock_irqsave(gck->lock, flags); |
| 262 | regmap_write(gck->regmap, AT91_PMC_PCR, | 264 | regmap_write(gck->regmap, gck->layout->offset, |
| 263 | (gck->id & AT91_PMC_PCR_PID_MASK)); | 265 | (gck->id & gck->layout->pid_mask)); |
| 264 | regmap_read(gck->regmap, AT91_PMC_PCR, &tmp); | 266 | regmap_read(gck->regmap, gck->layout->offset, &tmp); |
| 265 | spin_unlock_irqrestore(gck->lock, flags); | 267 | spin_unlock_irqrestore(gck->lock, flags); |
| 266 | | 268 | |
| 267 | gck->parent_id = (tmp & AT91_PMC_PCR_GCKCSS_MASK) | 269 | gck->parent_id = field_get(gck->layout->gckcss_mask, tmp); |
| 268 | >> AT91_PMC_PCR_GCKCSS_OFFSET; | 270 | gck->gckdiv = FIELD_GET(AT91_PMC_PCR_GCKDIV_MASK, tmp); |
| 269 | gck->gckdiv = (tmp & AT91_PMC_PCR_GCKDIV_MASK) | | |
| 270 | >> AT91_PMC_PCR_GCKDIV_OFFSET; | | |
| 271 | } | 271 | } |
| 272 | | 272 | |
| 273 | struct clk_hw * __init | 273 | struct clk_hw * __init |
| 274 | at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, | 274 | at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, |
| | 275 | const struct clk_pcr_layout *layout, |
| 275 | const char *name, const char **parent_names, | 276 | const char *name, const char **parent_names, |
| 276 | u8 num_parents, u8 id, bool pll_audio, | 277 | u8 num_parents, u8 id, bool pll_audio, |
| 277 | const struct clk_range *range) | 278 | const struct clk_range *range) |
| @@ -298,6 +299,7 @@ at91_clk_register_generated(struct regmap *regmap, spinlock_t *lock, · 20 unmodified lines |
| 298 | gck->lock = lock; | 299 | gck->lock = lock; |
| 299 | gck->range = *range; | 300 | gck->range = *range; |
| 300 | gck->audio_pll_allowed = pll_audio; | 301 | gck->audio_pll_allowed = pll_audio; |
| | 302 | gck->layout = layout; |
| 301 | | 303 | |
| 302 | clk_generated_startup(gck); | 304 | clk_generated_startup(gck); |
| 303 | hw = &gck->hw; | 305 | hw = &gck->hw; |