1 /* 2 * Copyright (C) 2016 Atmel Corporation 3 * Wenyou.Yang <wenyou.yang@atmel.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <clk-uclass.h> 10 #include <dm/device.h> 11 #include <linux/io.h> 12 #include <mach/at91_pmc.h> 13 #include "pmc.h" 14 15 #define PERIPHERAL_ID_MIN 2 16 #define PERIPHERAL_ID_MAX 31 17 #define PERIPHERAL_MASK(id) (1 << ((id) & PERIPHERAL_ID_MAX)) 18 19 static int sam9x5_periph_clk_enable(struct clk *clk) 20 { 21 struct pmc_platdata *plat = dev_get_platdata(clk->dev); 22 struct at91_pmc *pmc = plat->reg_base; 23 24 if (clk->id < PERIPHERAL_ID_MIN) 25 return -1; 26 27 writel(clk->id & AT91_PMC_PCR_PID_MASK, &pmc->pcr); 28 setbits_le32(&pmc->pcr, AT91_PMC_PCR_CMD_WRITE | AT91_PMC_PCR_EN); 29 30 return 0; 31 } 32 33 static struct clk_ops sam9x5_periph_clk_ops = { 34 .enable = sam9x5_periph_clk_enable, 35 }; 36 37 static int sam9x5_periph_clk_bind(struct udevice *dev) 38 { 39 return at91_pmc_clk_node_bind(dev); 40 } 41 42 static int sam9x5_periph_clk_probe(struct udevice *dev) 43 { 44 return at91_pmc_core_probe(dev); 45 } 46 47 static const struct udevice_id sam9x5_periph_clk_match[] = { 48 { .compatible = "atmel,at91sam9x5-clk-peripheral" }, 49 {} 50 }; 51 52 U_BOOT_DRIVER(sam9x5_periph_clk) = { 53 .name = "sam9x5-periph-clk", 54 .id = UCLASS_CLK, 55 .of_match = sam9x5_periph_clk_match, 56 .bind = sam9x5_periph_clk_bind, 57 .probe = sam9x5_periph_clk_probe, 58 .platdata_auto_alloc_size = sizeof(struct pmc_platdata), 59 .ops = &sam9x5_periph_clk_ops, 60 }; 61