Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 *  NEC VR4100 series RTC platform device.
  4 *
  5 *  Copyright (C) 2007	Yoichi Yuasa <yuasa@linux-mips.org>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7#include <linux/errno.h>
  8#include <linux/init.h>
  9#include <linux/smp.h>
 10#include <linux/ioport.h>
 11#include <linux/platform_device.h>
 12
 13#include <asm/cpu.h>
 14#include <asm/vr41xx/irq.h>
 15
 16static struct resource rtc_type1_resource[] __initdata = {
 17	{
 18		.start	= 0x0b0000c0,
 19		.end	= 0x0b0000df,
 20		.flags	= IORESOURCE_MEM,
 21	},
 22	{
 23		.start	= 0x0b0001c0,
 24		.end	= 0x0b0001df,
 25		.flags	= IORESOURCE_MEM,
 26	},
 27	{
 28		.start	= ELAPSEDTIME_IRQ,
 29		.end	= ELAPSEDTIME_IRQ,
 30		.flags	= IORESOURCE_IRQ,
 31	},
 32	{
 33		.start	= RTCLONG1_IRQ,
 34		.end	= RTCLONG1_IRQ,
 35		.flags	= IORESOURCE_IRQ,
 36	},
 37};
 38
 39static struct resource rtc_type2_resource[] __initdata = {
 40	{
 41		.start	= 0x0f000100,
 42		.end	= 0x0f00011f,
 43		.flags	= IORESOURCE_MEM,
 44	},
 45	{
 46		.start	= 0x0f000120,
 47		.end	= 0x0f00013f,
 48		.flags	= IORESOURCE_MEM,
 49	},
 50	{
 51		.start	= ELAPSEDTIME_IRQ,
 52		.end	= ELAPSEDTIME_IRQ,
 53		.flags	= IORESOURCE_IRQ,
 54	},
 55	{
 56		.start	= RTCLONG1_IRQ,
 57		.end	= RTCLONG1_IRQ,
 58		.flags	= IORESOURCE_IRQ,
 59	},
 60};
 61
 62static int __init vr41xx_rtc_add(void)
 63{
 64	struct platform_device *pdev;
 65	struct resource *res;
 66	unsigned int num;
 67	int retval;
 68
 69	pdev = platform_device_alloc("RTC", -1);
 70	if (!pdev)
 71		return -ENOMEM;
 72
 73	switch (current_cpu_type()) {
 74	case CPU_VR4111:
 75	case CPU_VR4121:
 76		res = rtc_type1_resource;
 77		num = ARRAY_SIZE(rtc_type1_resource);
 78		break;
 79	case CPU_VR4122:
 80	case CPU_VR4131:
 81	case CPU_VR4133:
 82		res = rtc_type2_resource;
 83		num = ARRAY_SIZE(rtc_type2_resource);
 84		break;
 85	default:
 86		retval = -ENODEV;
 87		goto err_free_device;
 88	}
 89
 90	retval = platform_device_add_resources(pdev, res, num);
 91	if (retval)
 92		goto err_free_device;
 93
 94	retval = platform_device_add(pdev);
 95	if (retval)
 96		goto err_free_device;
 97
 98	return 0;
 99
100err_free_device:
101	platform_device_put(pdev);
102
103	return retval;
104}
105device_initcall(vr41xx_rtc_add);
v3.1
 
  1/*
  2 *  NEC VR4100 series RTC platform device.
  3 *
  4 *  Copyright (C) 2007  Yoichi Yuasa <yuasa@linux-mips.org>
  5 *
  6 *  This program is free software; you can redistribute it and/or modify
  7 *  it under the terms of the GNU General Public License as published by
  8 *  the Free Software Foundation; either version 2 of the License, or
  9 *  (at your option) any later version.
 10 *
 11 *  This program is distributed in the hope that it will be useful,
 12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 *  GNU General Public License for more details.
 15 *
 16 *  You should have received a copy of the GNU General Public License
 17 *  along with this program; if not, write to the Free Software
 18 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 19 */
 20#include <linux/errno.h>
 21#include <linux/init.h>
 
 22#include <linux/ioport.h>
 23#include <linux/platform_device.h>
 24
 25#include <asm/cpu.h>
 26#include <asm/vr41xx/irq.h>
 27
 28static struct resource rtc_type1_resource[] __initdata = {
 29	{
 30		.start	= 0x0b0000c0,
 31		.end	= 0x0b0000df,
 32		.flags	= IORESOURCE_MEM,
 33	},
 34	{
 35		.start	= 0x0b0001c0,
 36		.end	= 0x0b0001df,
 37		.flags	= IORESOURCE_MEM,
 38	},
 39	{
 40		.start	= ELAPSEDTIME_IRQ,
 41		.end	= ELAPSEDTIME_IRQ,
 42		.flags	= IORESOURCE_IRQ,
 43	},
 44	{
 45		.start	= RTCLONG1_IRQ,
 46		.end	= RTCLONG1_IRQ,
 47		.flags	= IORESOURCE_IRQ,
 48	},
 49};
 50
 51static struct resource rtc_type2_resource[] __initdata = {
 52	{
 53		.start	= 0x0f000100,
 54		.end	= 0x0f00011f,
 55		.flags	= IORESOURCE_MEM,
 56	},
 57	{
 58		.start	= 0x0f000120,
 59		.end	= 0x0f00013f,
 60		.flags	= IORESOURCE_MEM,
 61	},
 62	{
 63		.start	= ELAPSEDTIME_IRQ,
 64		.end	= ELAPSEDTIME_IRQ,
 65		.flags	= IORESOURCE_IRQ,
 66	},
 67	{
 68		.start	= RTCLONG1_IRQ,
 69		.end	= RTCLONG1_IRQ,
 70		.flags	= IORESOURCE_IRQ,
 71	},
 72};
 73
 74static int __init vr41xx_rtc_add(void)
 75{
 76	struct platform_device *pdev;
 77	struct resource *res;
 78	unsigned int num;
 79	int retval;
 80
 81	pdev = platform_device_alloc("RTC", -1);
 82	if (!pdev)
 83		return -ENOMEM;
 84
 85	switch (current_cpu_type()) {
 86	case CPU_VR4111:
 87	case CPU_VR4121:
 88		res = rtc_type1_resource;
 89		num = ARRAY_SIZE(rtc_type1_resource);
 90		break;
 91	case CPU_VR4122:
 92	case CPU_VR4131:
 93	case CPU_VR4133:
 94		res = rtc_type2_resource;
 95		num = ARRAY_SIZE(rtc_type2_resource);
 96		break;
 97	default:
 98		retval = -ENODEV;
 99		goto err_free_device;
100	}
101
102	retval = platform_device_add_resources(pdev, res, num);
103	if (retval)
104		goto err_free_device;
105
106	retval = platform_device_add(pdev);
107	if (retval)
108		goto err_free_device;
109
110	return 0;
111
112err_free_device:
113	platform_device_put(pdev);
114
115	return retval;
116}
117device_initcall(vr41xx_rtc_add);