18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/************************************************************************ 38c2ecf20Sopenharmony_ciFile : Clock H/w specific Information 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciAuthor: Pankaj Dev <pankaj.dev@st.com> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciCopyright (C) 2014 STMicroelectronics 88c2ecf20Sopenharmony_ci************************************************************************/ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef __CLKGEN_INFO_H 118c2ecf20Sopenharmony_ci#define __CLKGEN_INFO_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciextern spinlock_t clkgen_a9_lock; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct clkgen_field { 168c2ecf20Sopenharmony_ci unsigned int offset; 178c2ecf20Sopenharmony_ci unsigned int mask; 188c2ecf20Sopenharmony_ci unsigned int shift; 198c2ecf20Sopenharmony_ci}; 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistatic inline unsigned long clkgen_read(void __iomem *base, 228c2ecf20Sopenharmony_ci struct clkgen_field *field) 238c2ecf20Sopenharmony_ci{ 248c2ecf20Sopenharmony_ci return (readl(base + field->offset) >> field->shift) & field->mask; 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic inline void clkgen_write(void __iomem *base, struct clkgen_field *field, 298c2ecf20Sopenharmony_ci unsigned long val) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci writel((readl(base + field->offset) & 328c2ecf20Sopenharmony_ci ~(field->mask << field->shift)) | (val << field->shift), 338c2ecf20Sopenharmony_ci base + field->offset); 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci return; 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define CLKGEN_FIELD(_offset, _mask, _shift) { \ 398c2ecf20Sopenharmony_ci .offset = _offset, \ 408c2ecf20Sopenharmony_ci .mask = _mask, \ 418c2ecf20Sopenharmony_ci .shift = _shift, \ 428c2ecf20Sopenharmony_ci } 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#define CLKGEN_READ(pll, field) clkgen_read(pll->regs_base, \ 458c2ecf20Sopenharmony_ci &pll->data->field) 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define CLKGEN_WRITE(pll, field, val) clkgen_write(pll->regs_base, \ 488c2ecf20Sopenharmony_ci &pll->data->field, val) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#endif /*__CLKGEN_INFO_H*/ 518c2ecf20Sopenharmony_ci 52