/* * Andestech ATCPIT100 timer driver * * (C) Copyright 2016 * Rick Chen, NDS32 Software Engineering, rick@andestech.com * * SPDX-License-Identifier: GPL-2.0+ */ #include #include #include #include #include DECLARE_GLOBAL_DATA_PTR; #define REG32_TMR(x) (*(u32 *) ((plat->regs) + (x>>2))) /* * Definition of register offsets */ /* ID and Revision Register */ #define ID_REV 0x0 /* Configuration Register */ #define CFG 0x10 /* Interrupt Enable Register */ #define INT_EN 0x14 #define CH_INT_EN(c , i) ((1<platdata; u32 val; val = ~(REG32_TMR(CH_CNT(1))+0xffffffff); *count = timer_conv_64(val); return 0; } static int atcpit_timer_probe(struct udevice *dev) { struct atcpit_timer_platdata *plat = dev->platdata; REG32_TMR(CH_REL(1)) = 0xffffffff; REG32_TMR(CH_CTL(1)) = APB_CLK|TMR_32; REG32_TMR(CH_EN) |= CH_TMR_EN(1 , 0); return 0; } static int atcpit_timer_ofdata_to_platdata(struct udevice *dev) { struct atcpit_timer_platdata *plat = dev_get_platdata(dev); plat->regs = map_physmem(devfdt_get_addr(dev) , 0x100 , MAP_NOCACHE); return 0; } static const struct timer_ops atcpit_timer_ops = { .get_count = atcpit_timer_get_count, }; static const struct udevice_id atcpit_timer_ids[] = { { .compatible = "andestech,atcpit100" }, {} }; U_BOOT_DRIVER(atcpit100_timer) = { .name = "atcpit100_timer", .id = UCLASS_TIMER, .of_match = atcpit_timer_ids, .ofdata_to_platdata = atcpit_timer_ofdata_to_platdata, .platdata_auto_alloc_size = sizeof(struct atcpit_timer_platdata), .probe = atcpit_timer_probe, .ops = &atcpit_timer_ops, .flags = DM_FLAG_PRE_RELOC, };