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