Lines Matching refs:sfctemp

51 struct sfctemp {  struct
62 static void sfctemp_power_up(struct sfctemp *sfctemp) in sfctemp_power_up() argument
65 writel(SFCTEMP_PD, sfctemp->regs); in sfctemp_power_up()
68 writel(0, sfctemp->regs); in sfctemp_power_up()
73 writel(SFCTEMP_RSTN, sfctemp->regs); in sfctemp_power_up()
77 static void sfctemp_power_down(struct sfctemp *sfctemp) in sfctemp_power_down() argument
79 writel(SFCTEMP_PD, sfctemp->regs); in sfctemp_power_down()
82 static void sfctemp_run(struct sfctemp *sfctemp) in sfctemp_run() argument
84 writel(SFCTEMP_RSTN | SFCTEMP_RUN, sfctemp->regs); in sfctemp_run()
88 static void sfctemp_stop(struct sfctemp *sfctemp) in sfctemp_stop() argument
90 writel(SFCTEMP_RSTN, sfctemp->regs); in sfctemp_stop()
93 static int sfctemp_enable(struct sfctemp *sfctemp) in sfctemp_enable() argument
97 mutex_lock(&sfctemp->lock); in sfctemp_enable()
98 if (sfctemp->enabled) in sfctemp_enable()
101 ret = clk_prepare_enable(sfctemp->clk_bus); in sfctemp_enable()
104 ret = reset_control_deassert(sfctemp->rst_bus); in sfctemp_enable()
108 ret = clk_prepare_enable(sfctemp->clk_sense); in sfctemp_enable()
111 ret = reset_control_deassert(sfctemp->rst_sense); in sfctemp_enable()
115 sfctemp_power_up(sfctemp); in sfctemp_enable()
116 sfctemp_run(sfctemp); in sfctemp_enable()
117 sfctemp->enabled = true; in sfctemp_enable()
119 mutex_unlock(&sfctemp->lock); in sfctemp_enable()
123 clk_disable_unprepare(sfctemp->clk_sense); in sfctemp_enable()
125 reset_control_assert(sfctemp->rst_bus); in sfctemp_enable()
127 clk_disable_unprepare(sfctemp->clk_bus); in sfctemp_enable()
129 mutex_unlock(&sfctemp->lock); in sfctemp_enable()
133 static int sfctemp_disable(struct sfctemp *sfctemp) in sfctemp_disable() argument
135 mutex_lock(&sfctemp->lock); in sfctemp_disable()
136 if (!sfctemp->enabled) in sfctemp_disable()
139 sfctemp_stop(sfctemp); in sfctemp_disable()
140 sfctemp_power_down(sfctemp); in sfctemp_disable()
141 reset_control_assert(sfctemp->rst_sense); in sfctemp_disable()
142 clk_disable_unprepare(sfctemp->clk_sense); in sfctemp_disable()
143 reset_control_assert(sfctemp->rst_bus); in sfctemp_disable()
144 clk_disable_unprepare(sfctemp->clk_bus); in sfctemp_disable()
145 sfctemp->enabled = false; in sfctemp_disable()
147 mutex_unlock(&sfctemp->lock); in sfctemp_disable()
156 static int sfctemp_convert(struct sfctemp *sfctemp, long *val) in sfctemp_convert() argument
160 mutex_lock(&sfctemp->lock); in sfctemp_convert()
161 if (!sfctemp->enabled) { in sfctemp_convert()
167 *val = (long)((readl(sfctemp->regs) & SFCTEMP_DOUT_MSK) >> SFCTEMP_DOUT_POS) in sfctemp_convert()
172 mutex_unlock(&sfctemp->lock); in sfctemp_convert()
197 struct sfctemp *sfctemp = dev_get_drvdata(dev); in sfctemp_read() local
203 *val = sfctemp->enabled; in sfctemp_read()
206 return sfctemp_convert(sfctemp, val); in sfctemp_read()
218 struct sfctemp *sfctemp = dev_get_drvdata(dev); in sfctemp_write() local
225 return sfctemp_disable(sfctemp); in sfctemp_write()
227 return sfctemp_enable(sfctemp); in sfctemp_write()
258 struct sfctemp *sfctemp; in sfctemp_probe() local
261 sfctemp = devm_kzalloc(dev, sizeof(*sfctemp), GFP_KERNEL); in sfctemp_probe()
262 if (!sfctemp) in sfctemp_probe()
265 dev_set_drvdata(dev, sfctemp); in sfctemp_probe()
266 mutex_init(&sfctemp->lock); in sfctemp_probe()
268 sfctemp->regs = devm_platform_ioremap_resource(pdev, 0); in sfctemp_probe()
269 if (IS_ERR(sfctemp->regs)) in sfctemp_probe()
270 return PTR_ERR(sfctemp->regs); in sfctemp_probe()
272 sfctemp->clk_sense = devm_clk_get(dev, "sense"); in sfctemp_probe()
273 if (IS_ERR(sfctemp->clk_sense)) in sfctemp_probe()
274 return dev_err_probe(dev, PTR_ERR(sfctemp->clk_sense), in sfctemp_probe()
277 sfctemp->clk_bus = devm_clk_get(dev, "bus"); in sfctemp_probe()
278 if (IS_ERR(sfctemp->clk_bus)) in sfctemp_probe()
279 return dev_err_probe(dev, PTR_ERR(sfctemp->clk_bus), in sfctemp_probe()
282 sfctemp->rst_sense = devm_reset_control_get_exclusive(dev, "sense"); in sfctemp_probe()
283 if (IS_ERR(sfctemp->rst_sense)) in sfctemp_probe()
284 return dev_err_probe(dev, PTR_ERR(sfctemp->rst_sense), in sfctemp_probe()
287 sfctemp->rst_bus = devm_reset_control_get_exclusive(dev, "bus"); in sfctemp_probe()
288 if (IS_ERR(sfctemp->rst_bus)) in sfctemp_probe()
289 return dev_err_probe(dev, PTR_ERR(sfctemp->rst_bus), in sfctemp_probe()
292 ret = reset_control_assert(sfctemp->rst_sense); in sfctemp_probe()
296 ret = reset_control_assert(sfctemp->rst_bus); in sfctemp_probe()
300 ret = devm_add_action(dev, sfctemp_disable_action, sfctemp); in sfctemp_probe()
304 ret = sfctemp_enable(sfctemp); in sfctemp_probe()
308 hwmon_dev = devm_hwmon_device_register_with_info(dev, "sfctemp", sfctemp, in sfctemp_probe()