Make the twl4030 RTC initialization follow the driver model better.
The platform device is created (if needed) as part of twl4030 setup
instead of as a board-specific thing, and fits properly into the
driver model tree.
The only minor glitch here is on boards using platform_data to pass
MSECURE initialization hooks to the RTC driver. The right solution
probably just removes that platform_data, and might even make Linux
follow the principle of "least privilege" (at the hardware level!)
instead of always holding this signal high.
Pending better handling of MSECURE, this patch just does what the
RTC init does, but earlier: MSECURE is always high, so the RTC time
and calendar registers can be updated (and presumably a bunch of
non-RTC privileged operations will be allowed too).
Yet to be done: set up the IRQ resource; make the rtc driver use
that IRQ resource; and properly issue wakeup alarms.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Tony Lindgren <tony@atomide.com>
#include <linux/clk.h>
#include <linux/spi/spi.h>
#include <linux/spi/ads7846.h>
-#include <linux/i2c/twl4030-rtc.h>
#include <mach/hardware.h>
#include <asm/mach-types.h>
},
};
-static int twl4030_rtc_init(void)
+static int __init msecure_init(void)
{
int ret = 0;
- ret = omap_request_gpio(TWL4030_MSECURE_GPIO);
+#ifdef CONFIG_RTC_DRV_TWL4030
+ ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
if (ret < 0) {
- printk(KERN_ERR "twl4030_rtc_init: can't reserve GPIO:%d !\n",
+ printk(KERN_ERR "msecure_init: can't reserve GPIO:%d !\n",
TWL4030_MSECURE_GPIO);
goto out;
}
* Make msecure line high in order to change the TWL4030 RTC time
* and calender registers.
*/
- omap_set_gpio_direction(TWL4030_MSECURE_GPIO, 0); /*dir out */
- omap_set_gpio_dataout(TWL4030_MSECURE_GPIO, 1);
+ gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
out:
- return ret;
-}
+#endif
-static void twl4030_rtc_exit(void)
-{
- omap_free_gpio(TWL4030_MSECURE_GPIO);
+ return ret;
}
-static struct twl4030rtc_platform_data sdp2430_twl4030rtc_data = {
- .init = &twl4030_rtc_init,
- .exit = &twl4030_rtc_exit,
-};
-
-static struct platform_device sdp2430_twl4030rtc_device = {
- .name = "twl4030_rtc",
- .id = -1,
- .dev = {
- .platform_data = &sdp2430_twl4030rtc_data,
- },
-};
-
static struct platform_device *sdp2430_devices[] __initdata = {
&sdp2430_smc91x_device,
&sdp2430_flash_device,
&sdp2430_kp_device,
&sdp2430_lcd_device,
- &sdp2430_twl4030rtc_device,
};
static void ads7846_dev_init(void)
omap_board_config_size = ARRAY_SIZE(sdp2430_config);
omap_serial_init();
+ msecure_init();
+
sdp2430_flash_init();
usb_musb_init();
#include <linux/workqueue.h>
#include <linux/err.h>
#include <linux/clk.h>
-#include <linux/i2c/twl4030.h>
#include <linux/spi/spi.h>
#include <linux/spi/ads7846.h>
+#include <linux/i2c/twl4030.h>
#include <mach/hardware.h>
#include <asm/mach-types.h>
static int ts_gpio;
-#ifdef CONFIG_RTC_DRV_TWL4030
-static int twl4030_rtc_init(void)
+static int __init msecure_init(void)
{
int ret = 0;
+#ifdef CONFIG_RTC_DRV_TWL4030
/* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
if (is_device_type_gp() && is_sil_rev_less_than(OMAP3430_REV_ES2_0)) {
u32 msecure_pad_config_reg = omap_ctrl_base_get() + 0xA3C;
int mux_mask = 0x04;
u16 tmp;
- ret = omap_request_gpio(TWL4030_MSECURE_GPIO);
+ ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
if (ret < 0) {
- printk(KERN_ERR "twl4030_rtc_init: can't"
+ printk(KERN_ERR "msecure_init: can't"
"reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
goto out;
}
* is low. Make msecure line high in order to change the
* TWL4030 RTC time and calender registers.
*/
- omap_set_gpio_direction(TWL4030_MSECURE_GPIO, 0);
-
tmp = omap_readw(msecure_pad_config_reg);
tmp &= 0xF8; /* To enable mux mode 03/04 = GPIO_RTC */
tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
omap_writew(tmp, msecure_pad_config_reg);
- omap_set_gpio_dataout(TWL4030_MSECURE_GPIO, 1);
+ gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
}
out:
+#endif
return ret;
}
-static void twl4030_rtc_exit(void)
-{
- if (is_device_type_gp() &&
- is_sil_rev_less_than(OMAP3430_REV_ES2_0)) {
- omap_free_gpio(TWL4030_MSECURE_GPIO);
- }
-}
-
-static struct twl4030rtc_platform_data sdp3430_twl4030rtc_data = {
- .init = &twl4030_rtc_init,
- .exit = &twl4030_rtc_exit,
-};
-
-static struct platform_device sdp3430_twl4030rtc_device = {
- .name = "twl4030_rtc",
- .id = -1,
- .dev = {
- .platform_data = &sdp3430_twl4030rtc_data,
- },
-};
-#endif
-
/**
* @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
*
&sdp3430_smc91x_device,
&sdp3430_kp_device,
&sdp3430_lcd_device,
-#ifdef CONFIG_RTC_DRV_TWL4030
- &sdp3430_twl4030rtc_device,
-#endif
};
static inline void __init sdp3430_init_smc91x(void)
ARRAY_SIZE(sdp3430_spi_board_info));
ads7846_dev_init();
sdp3430_flash_init();
+ msecure_init();
twl4030_bci_battery_init();
omap_serial_init();
usb_musb_init();
#include <linux/spi/spi.h>
#include <linux/spi/ads7846.h>
#include <linux/i2c/twl4030.h>
-#include <linux/i2c/twl4030-rtc.h>
#include <mach/hardware.h>
#include <asm/mach-types.h>
static int ts_gpio;
-#ifdef CONFIG_RTC_DRV_TWL4030
-static int twl4030_rtc_init(void)
+static int __init msecure_init(void)
{
int ret = 0;
+#ifdef CONFIG_RTC_DRV_TWL4030
/* 3430ES2.0 doesn't have msecure/gpio-22 line connected to T2 */
if (is_device_type_gp() && is_sil_rev_less_than(OMAP3430_REV_ES2_0)) {
u32 msecure_pad_config_reg = omap_ctrl_base_get() + 0xA3C;
int mux_mask = 0x04;
u16 tmp;
- ret = omap_request_gpio(TWL4030_MSECURE_GPIO);
+ ret = gpio_request(TWL4030_MSECURE_GPIO, "msecure");
if (ret < 0) {
- printk(KERN_ERR "twl4030_rtc_init: can't"
+ printk(KERN_ERR "msecure_init: can't"
"reserve GPIO:%d !\n", TWL4030_MSECURE_GPIO);
goto out;
}
* is low. Make msecure line high in order to change the
* TWL4030 RTC time and calender registers.
*/
- omap_set_gpio_direction(TWL4030_MSECURE_GPIO, 0);
tmp = omap_readw(msecure_pad_config_reg);
tmp &= 0xF8; /* To enable mux mode 03/04 = GPIO_RTC */
tmp |= mux_mask;/* To enable mux mode 03/04 = GPIO_RTC */
omap_writew(tmp, msecure_pad_config_reg);
- omap_set_gpio_dataout(TWL4030_MSECURE_GPIO, 1);
+ gpio_direction_output(TWL4030_MSECURE_GPIO, 1);
}
out:
+#endif
return ret;
}
-static void twl4030_rtc_exit(void)
-{
- omap_free_gpio(TWL4030_MSECURE_GPIO);
-}
-
-static struct twl4030rtc_platform_data ldp_twl4030rtc_data = {
- .init = &twl4030_rtc_init,
- .exit = &twl4030_rtc_exit,
-};
-
-static struct platform_device ldp_twl4030rtc_device = {
- .name = "twl4030_rtc",
- .id = -1,
- .dev = {
- .platform_data = &ldp_twl4030rtc_data,
- },
-};
-#endif
-
/**
* @brief ads7846_dev_init : Requests & sets GPIO line for pen-irq
*
};
static struct platform_device *ldp_devices[] __initdata = {
-#ifdef CONFIG_RTC_DRV_TWL4030
- &ldp_twl4030rtc_device,
-#endif
};
static void __init omap_ldp_init_irq(void)
ldp_spi_board_info[0].irq = OMAP_GPIO_IRQ(ts_gpio);
spi_register_board_info(ldp_spi_board_info,
ARRAY_SIZE(ldp_spi_board_info));
+ msecure_init();
ads7846_dev_init();
twl4030_bci_battery_init();
omap_serial_init();
omap_gpio_init();
}
-static struct platform_device omap3_beagle_twl4030rtc_device = {
- .name = "twl4030_rtc",
- .id = -1,
-};
-
static struct platform_device omap3_beagle_lcd_device = {
.name = "omap3beagle_lcd",
.id = -1,
static struct platform_device *omap3_beagle_devices[] __initdata = {
&omap3_beagle_lcd_device,
-#ifdef CONFIG_RTC_DRV_TWL4030
- &omap3_beagle_twl4030rtc_device,
-#endif
&leds_gpio,
&keys_gpio,
};
.ctrl_name = "internal",
};
-static struct platform_device omap3_evm_twl4030rtc_device = {
- .name = "twl4030_rtc",
- .id = -1,
-};
-
static void ads7846_dev_init(void)
{
if (omap_request_gpio(OMAP3_EVM_TS_GPIO) < 0)
static struct platform_device *omap3_evm_devices[] __initdata = {
&omap3_evm_lcd_device,
&omap3evm_kp_device,
-#ifdef CONFIG_RTC_DRV_TWL4030
- &omap3_evm_twl4030rtc_device,
-#endif
&omap3evm_smc911x_device,
};
#include <linux/random.h>
#include <linux/syscalls.h>
#include <linux/kthread.h>
+#include <linux/platform_device.h>
#include <linux/i2c.h>
#include <linux/i2c/twl4030.h>
return err;
}
+static int add_children(void)
+{
+ static bool children;
+
+ struct platform_device *pdev = NULL;
+ struct twl4030_client *twl = NULL;
+ int status = 0;
+
+ /* FIXME this doesn't yet set up platform_data for anything;
+ * it can't be available until this becomes a "new style"
+ * I2C driver. Similarly, a new style driver will know it
+ * didn't already initialize its children.
+ */
+
+ if (children)
+ return 0;
+
+#ifdef CONFIG_RTC_DRV_TWL4030
+ pdev = platform_device_alloc("twl4030_rtc", -1);
+ if (pdev) {
+ twl = &twl4030_modules[TWL4030_SLAVENUM_NUM3];
+ pdev->dev.parent = &twl->client.dev;
+ device_init_wakeup(&pdev->dev, 1);
+
+ /*
+ * FIXME add the relevant IRQ resource, and make the
+ * rtc driver use it instead of hard-wiring ...
+ *
+ * REVISIT platform_data here currently only supports
+ * setting up the "msecure" line ... which actually
+ * violates the "princple of least privilege", since
+ * it's effectively always in "high trust" mode.
+ *
+ * For now, expect equivalent treatment at board init:
+ * setting msecure high. Eventually, Linux might
+ * become more aware of those HW security concerns.
+ */
+
+ status = platform_device_add(pdev);
+ if (status < 0)
+ platform_device_put(pdev);
+ } else
+ status = -ENOMEM;
+#endif
+
+ children = true;
+ return status;
+}
+
/* adapter callback */
static int __init twl4030_attach_adapter(struct i2c_adapter *adapter)
{
}
twl_i2c_adapter++;
+ add_children();
+
/*
* Check if the PIH module is initialized, if yes, then init
* the T2 Interrupt subsystem