238staticint snvs_rtc_probe(struct platform_device *pdev)
239{
240struct snvs_rtc_data *data;
241struct resource *res;
242int ret;
243void __iomem *mmio;
244
245 data = devm_kzalloc(&pdev->dev,sizeof(*data), GFP_KERNEL);
246if(!data)
247return-ENOMEM;
248
249 data->regmap =
syscon_regmap_lookup_by_phandle(pdev->dev.of_node,"regmap");
250
251if(IS_ERR(data->regmap)){
252 dev_warn(&pdev->dev,"snvs rtc: you use old dts file,
please update it\n");
253 res = platform_get_resource(pdev, IORESOURCE_MEM,0);
254
255 mmio = devm_ioremap_resource(&pdev->dev, res);
256if(IS_ERR(mmio))
257return PTR_ERR(mmio);
258
259 data->regmap = devm_regmap_init_mmio(&pdev->dev, mmio,
&snvs_rtc_config);
260}else{
261 data->offset = SNVS_LPREGISTER_OFFSET;
262 of_property_read_u32(pdev->dev.of_node,"offset",
&data->offset);
263}
264
265if(!data->regmap){
266 dev_err(&pdev->dev,"Can't find snvs syscon\n");
267return-ENODEV;
268}
269
270 data->irq = platform_get_irq(pdev,0);
271if(data->irq <0)
272return data->irq;
......
285
286 platform_set_drvdata(pdev, data);
287
288/* Initialize glitch detect */
289 regmap_write(data->regmap, data->offset + SNVS_LPPGDR,
SNVS_LPPGDR_INIT);
290
291/* Clear interrupt status */
292 regmap_write(data->regmap, data->offset + SNVS_LPSR,
0xffffffff);
293
294/* Enable RTC */
295 snvs_rtc_enable(data, true);
296
297 device_init_wakeup(&pdev->dev, true);
298
299 ret = devm_request_irq(&pdev->dev, data->irq,
snvs_rtc_irq_handler,
300 IRQF_SHARED,"rtc alarm",&pdev->dev);
301if(ret){
302 dev_err(&pdev->dev,"failed to request irq %d: %d\n",
303 data->irq, ret);
304goto error_rtc_device_register;
305}
306
307 data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
308&snvs_rtc_ops, THIS_MODULE);
309if(IS_ERR(data->rtc)){
310 ret = PTR_ERR(data->rtc);
311 dev_err(&pdev->dev,"failed to register rtc: %d\n", ret);
312goto error_rtc_device_register;
313}
314
315return0;
316
317 error_rtc_device_register:
318if(data->clk)
319 clk_disable_unprepare(data->clk);
320
321return ret;
322}