mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-20 11:13:58 +08:00
Atmel PWM driver update for 3.17
- move to the new PWM driver which uses PWM framework - remove 3 obsolete drivers (atmel-pwm-bl.c, leds-atmel-pwm.c and atmel_pwm.c) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQEcBAABAgAGBQJTvXI3AAoJEAf03oE53VmQeSQIAIwf5lrqiwZpQosBwJFEyKkZ yVCVK4VQDpGOqkltKTqw38Rm/q5RPOjjhQCkwWSFNSt0D1t3FhfMcmW+6eW4uOn7 9qNYaiWxWDJB7e/S5LWjX/j/dT/5cvp0NZbnrpaCuUbx17h1YOBaOrsqn98E9TN5 aGHxH9ODAG2K6YV67cObYOtDA2wMoLABucj/NcBQet7l1Dpn2JI42cSQT8ttYm2k nUTjuLB3Pz7q68BXR6M95MHWq5NITNxDjELFyg4igq8T7AkT8ijBBzVRYBoKnpmZ rpkbhIdcNPE+y5N+T1fkgSEQ2YTg5AK55WyYknMNHvXcfpNoFwKzWEjfPpCwBVc= =7+uj -----END PGP SIGNATURE----- Merge tag 'at91-drivers' of git://github.com/at91linux/linux-at91 into next/drivers Merge "at91: drivers for 3.17 #1" from Nicolas Ferre: "This update delayed to 3.17, is about replacing the existing calls to the older, non-standard drivers by the use of the newer "pwm-atmel" which takes advantage of the PWM framework. All concerned maintainer gave their acknowledgement to the relevant patches. At the end, it removes three obsolete drivers and the diffstat looks pretty nice as well." Atmel PWM driver update for 3.17 - move to the new PWM driver which uses PWM framework - remove 3 obsolete drivers (atmel-pwm-bl.c, leds-atmel-pwm.c and atmel_pwm.c) * tag 'at91-drivers' of git://github.com/at91linux/linux-at91: misc: atmel_pwm: remove obsolete driver leds: atmel-pwm: remove obsolete driver backlight: atmel-pwm-bl: remove obsolete driver avr32: update defconfig to use the generic PWM framework avr32: favr-32: use generic pwm_bl driver avr32: merisc: use generic leds_pwm driver avr32: MRMT: use generic leds_pwm driver avr32/at32ap: switch to the generic PWM framework PWM: atmel: allow building for AVR32 ARM: at91: remove useless at91_pwm_leds() ARM: at91: at91sam9rl: switch to generic PWM framework ARM: at91: sam9263ek: use generic leds_pwm driver ARM: at91: at91sam9263: switch to generic PWM framework ARM: at91: sam9m10g45ek: use generic leds_pwm driver ARM: at91: at91sam9g45: switch to generic PWM framework Signed-off-by: Olof Johansson <olof@lixom.net>
This commit is contained in:
commit
bde19a7e74
@ -199,6 +199,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
|
||||
CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
|
||||
CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9260.0", &twi_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "at91sam9rl-pwm", &pwm_clk),
|
||||
/* fake hclk clock */
|
||||
CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
|
||||
CLKDEV_CON_ID("pioA", &pioA_clk),
|
||||
|
@ -1131,9 +1131,7 @@ static void __init at91_add_device_watchdog(void) {}
|
||||
* PWM
|
||||
* --------------------------------------------------------------------*/
|
||||
|
||||
#if defined(CONFIG_ATMEL_PWM)
|
||||
static u32 pwm_mask;
|
||||
|
||||
#if IS_ENABLED(CONFIG_PWM_ATMEL)
|
||||
static struct resource pwm_resources[] = {
|
||||
[0] = {
|
||||
.start = AT91SAM9263_BASE_PWMC,
|
||||
@ -1148,11 +1146,8 @@ static struct resource pwm_resources[] = {
|
||||
};
|
||||
|
||||
static struct platform_device at91sam9263_pwm0_device = {
|
||||
.name = "atmel_pwm",
|
||||
.name = "at91sam9rl-pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_mask,
|
||||
},
|
||||
.resource = pwm_resources,
|
||||
.num_resources = ARRAY_SIZE(pwm_resources),
|
||||
};
|
||||
@ -1171,8 +1166,6 @@ void __init at91_add_device_pwm(u32 mask)
|
||||
if (mask & (1 << AT91_PWM3))
|
||||
at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
|
||||
|
||||
pwm_mask = mask;
|
||||
|
||||
platform_device_register(&at91sam9263_pwm0_device);
|
||||
}
|
||||
#else
|
||||
|
@ -251,6 +251,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
|
||||
CLKDEV_CON_DEV_ID(NULL, "atmel_sha", &aestdessha_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "atmel_tdes", &aestdessha_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "atmel_aes", &aestdessha_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "at91sam9rl-pwm", &pwm_clk),
|
||||
/* more usart lookup table for DT entries */
|
||||
CLKDEV_CON_DEV_ID("usart", "ffffee00.serial", &mck),
|
||||
CLKDEV_CON_DEV_ID("usart", "fff8c000.serial", &usart0_clk),
|
||||
|
@ -1334,9 +1334,7 @@ static void __init at91_add_device_watchdog(void) {}
|
||||
* PWM
|
||||
* --------------------------------------------------------------------*/
|
||||
|
||||
#if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
|
||||
static u32 pwm_mask;
|
||||
|
||||
#if IS_ENABLED(CONFIG_PWM_ATMEL)
|
||||
static struct resource pwm_resources[] = {
|
||||
[0] = {
|
||||
.start = AT91SAM9G45_BASE_PWMC,
|
||||
@ -1351,11 +1349,8 @@ static struct resource pwm_resources[] = {
|
||||
};
|
||||
|
||||
static struct platform_device at91sam9g45_pwm0_device = {
|
||||
.name = "atmel_pwm",
|
||||
.name = "at91sam9rl-pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_mask,
|
||||
},
|
||||
.resource = pwm_resources,
|
||||
.num_resources = ARRAY_SIZE(pwm_resources),
|
||||
};
|
||||
@ -1374,8 +1369,6 @@ void __init at91_add_device_pwm(u32 mask)
|
||||
if (mask & (1 << AT91_PWM3))
|
||||
at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
|
||||
|
||||
pwm_mask = mask;
|
||||
|
||||
platform_device_register(&at91sam9g45_pwm0_device);
|
||||
}
|
||||
#else
|
||||
|
@ -200,6 +200,7 @@ static struct clk_lookup periph_clocks_lookups[] = {
|
||||
CLKDEV_CON_DEV_ID("pclk", "fffc4000.ssc", &ssc1_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g20.0", &twi0_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g20.1", &twi1_clk),
|
||||
CLKDEV_CON_DEV_ID(NULL, "at91sam9rl-pwm", &pwm_clk),
|
||||
CLKDEV_CON_ID("pioA", &pioA_clk),
|
||||
CLKDEV_CON_ID("pioB", &pioB_clk),
|
||||
CLKDEV_CON_ID("pioC", &pioC_clk),
|
||||
|
@ -799,9 +799,7 @@ static void __init at91_add_device_watchdog(void) {}
|
||||
* PWM
|
||||
* --------------------------------------------------------------------*/
|
||||
|
||||
#if defined(CONFIG_ATMEL_PWM)
|
||||
static u32 pwm_mask;
|
||||
|
||||
#if IS_ENABLED(CONFIG_PWM_ATMEL)
|
||||
static struct resource pwm_resources[] = {
|
||||
[0] = {
|
||||
.start = AT91SAM9RL_BASE_PWMC,
|
||||
@ -816,11 +814,8 @@ static struct resource pwm_resources[] = {
|
||||
};
|
||||
|
||||
static struct platform_device at91sam9rl_pwm0_device = {
|
||||
.name = "atmel_pwm",
|
||||
.name = "at91sam9rl-pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_mask,
|
||||
},
|
||||
.resource = pwm_resources,
|
||||
.num_resources = ARRAY_SIZE(pwm_resources),
|
||||
};
|
||||
@ -839,8 +834,6 @@ void __init at91_add_device_pwm(u32 mask)
|
||||
if (mask & (1 << AT91_PWM3))
|
||||
at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
|
||||
|
||||
pwm_mask = mask;
|
||||
|
||||
platform_device_register(&at91sam9rl_pwm0_device);
|
||||
}
|
||||
#else
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include <linux/gpio_keys.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/pwm.h>
|
||||
#include <linux/leds_pwm.h>
|
||||
|
||||
#include <video/atmel_lcdc.h>
|
||||
|
||||
@ -369,22 +371,48 @@ static struct gpio_led ek_leds[] = {
|
||||
.name = "ds3",
|
||||
.gpio = AT91_PIN_PB7,
|
||||
.default_trigger = "heartbeat",
|
||||
},
|
||||
#if !IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
{
|
||||
.name = "ds1",
|
||||
.gpio = AT91_PIN_PB8,
|
||||
.active_low = 1,
|
||||
.default_trigger = "none",
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* PWM Leds
|
||||
*/
|
||||
static struct gpio_led ek_pwm_led[] = {
|
||||
/* For now only DS1 is PWM-driven (by pwm1) */
|
||||
{
|
||||
.name = "ds1",
|
||||
.gpio = 1, /* is PWM channel number */
|
||||
.active_low = 1,
|
||||
.default_trigger = "none",
|
||||
}
|
||||
static struct pwm_lookup pwm_lookup[] = {
|
||||
PWM_LOOKUP("at91sam9rl-pwm", 1, "leds_pwm", "ds1",
|
||||
5000, PWM_POLARITY_INVERSED),
|
||||
};
|
||||
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
static struct led_pwm pwm_leds[] = {
|
||||
{
|
||||
.name = "ds1",
|
||||
.max_brightness = 255,
|
||||
},
|
||||
};
|
||||
|
||||
static struct led_pwm_platform_data pwm_data = {
|
||||
.num_leds = ARRAY_SIZE(pwm_leds),
|
||||
.leds = pwm_leds,
|
||||
};
|
||||
|
||||
static struct platform_device leds_pwm = {
|
||||
.name = "leds_pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_data,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* CAN
|
||||
*/
|
||||
@ -403,6 +431,12 @@ static struct at91_can_data ek_can_data = {
|
||||
.transceiver_switch = sam9263ek_transceiver_switch,
|
||||
};
|
||||
|
||||
static struct platform_device *devices[] __initdata = {
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
&leds_pwm,
|
||||
#endif
|
||||
};
|
||||
|
||||
static void __init ek_board_init(void)
|
||||
{
|
||||
/* Serial */
|
||||
@ -437,9 +471,14 @@ static void __init ek_board_init(void)
|
||||
at91_add_device_ac97(&ek_ac97_data);
|
||||
/* LEDs */
|
||||
at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
|
||||
at91_pwm_leds(ek_pwm_led, ARRAY_SIZE(ek_pwm_led));
|
||||
pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
at91_add_device_pwm(1 << AT91_PWM1);
|
||||
#endif
|
||||
/* CAN */
|
||||
at91_add_device_can(&ek_can_data);
|
||||
/* Other platform devices */
|
||||
platform_add_devices(devices, ARRAY_SIZE(devices));
|
||||
}
|
||||
|
||||
MACHINE_START(AT91SAM9263EK, "Atmel AT91SAM9263-EK")
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include <linux/leds.h>
|
||||
#include <linux/atmel-mci.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/pwm.h>
|
||||
#include <linux/leds_pwm.h>
|
||||
|
||||
#include <linux/platform_data/at91_adc.h>
|
||||
|
||||
@ -416,7 +418,7 @@ static struct gpio_led ek_leds[] = {
|
||||
.active_low = 1,
|
||||
.default_trigger = "nand-disk",
|
||||
},
|
||||
#if !(defined(CONFIG_LEDS_ATMEL_PWM) || defined(CONFIG_LEDS_ATMEL_PWM_MODULE))
|
||||
#if !IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
{ /* "right" led, green, userled1, pwm1 */
|
||||
.name = "d7",
|
||||
.gpio = AT91_PIN_PD31,
|
||||
@ -430,22 +432,41 @@ static struct gpio_led ek_leds[] = {
|
||||
/*
|
||||
* PWM Leds
|
||||
*/
|
||||
static struct gpio_led ek_pwm_led[] = {
|
||||
#if defined(CONFIG_LEDS_ATMEL_PWM) || defined(CONFIG_LEDS_ATMEL_PWM_MODULE)
|
||||
{ /* "right" led, green, userled1, pwm1 */
|
||||
.name = "d7",
|
||||
.gpio = 1, /* is PWM channel number */
|
||||
.active_low = 1,
|
||||
.default_trigger = "none",
|
||||
},
|
||||
#endif
|
||||
static struct pwm_lookup pwm_lookup[] = {
|
||||
PWM_LOOKUP("at91sam9rl-pwm", 1, "leds_pwm", "d7",
|
||||
5000, PWM_POLARITY_INVERSED),
|
||||
};
|
||||
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
static struct led_pwm pwm_leds[] = {
|
||||
{ /* "right" led, green, userled1, pwm1 */
|
||||
.name = "d7",
|
||||
.max_brightness = 255,
|
||||
},
|
||||
};
|
||||
|
||||
static struct led_pwm_platform_data pwm_data = {
|
||||
.num_leds = ARRAY_SIZE(pwm_leds),
|
||||
.leds = pwm_leds,
|
||||
};
|
||||
|
||||
static struct platform_device leds_pwm = {
|
||||
.name = "leds_pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_data,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct platform_device *devices[] __initdata = {
|
||||
#if defined(CONFIG_SOC_CAMERA_OV2640) || \
|
||||
defined(CONFIG_SOC_CAMERA_OV2640_MODULE)
|
||||
&isi_ov2640,
|
||||
#endif
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
&leds_pwm,
|
||||
#endif
|
||||
};
|
||||
|
||||
static void __init ek_board_init(void)
|
||||
@ -486,7 +507,10 @@ static void __init ek_board_init(void)
|
||||
at91_add_device_ac97(&ek_ac97_data);
|
||||
/* LEDs */
|
||||
at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
|
||||
at91_pwm_leds(ek_pwm_led, ARRAY_SIZE(ek_pwm_led));
|
||||
pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
at91_add_device_pwm(1 << AT91_PWM1);
|
||||
#endif
|
||||
/* Other platform devices */
|
||||
platform_add_devices(devices, ARRAY_SIZE(devices));
|
||||
}
|
||||
|
@ -123,6 +123,5 @@ extern void __init at91_add_device_can(struct at91_can_data *data);
|
||||
|
||||
/* LEDs */
|
||||
extern void __init at91_gpio_leds(struct gpio_led *leds, int nr);
|
||||
extern void __init at91_pwm_leds(struct gpio_led *leds, int nr);
|
||||
|
||||
#endif
|
||||
|
@ -54,40 +54,3 @@ void __init at91_gpio_leds(struct gpio_led *leds, int nr)
|
||||
void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
|
||||
#endif
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
#if defined (CONFIG_LEDS_ATMEL_PWM)
|
||||
|
||||
/*
|
||||
* PWM Leds
|
||||
*/
|
||||
|
||||
static struct gpio_led_platform_data pwm_led_data;
|
||||
|
||||
static struct platform_device at91_pwm_leds_device = {
|
||||
.name = "leds-atmel-pwm",
|
||||
.id = -1,
|
||||
.dev.platform_data = &pwm_led_data,
|
||||
};
|
||||
|
||||
void __init at91_pwm_leds(struct gpio_led *leds, int nr)
|
||||
{
|
||||
int i;
|
||||
u32 pwm_mask = 0;
|
||||
|
||||
if (!nr)
|
||||
return;
|
||||
|
||||
for (i = 0; i < nr; i++)
|
||||
pwm_mask |= (1 << leds[i].gpio);
|
||||
|
||||
pwm_led_data.leds = leds;
|
||||
pwm_led_data.num_leds = nr;
|
||||
|
||||
at91_add_device_pwm(pwm_mask);
|
||||
platform_device_register(&at91_pwm_leds_device);
|
||||
}
|
||||
#else
|
||||
void __init at91_pwm_leds(struct gpio_led *leds, int nr){}
|
||||
#endif
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include <linux/types.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/pwm.h>
|
||||
#include <linux/leds_pwm.h>
|
||||
#include <linux/input.h>
|
||||
#include <linux/gpio_keys.h>
|
||||
#include <linux/atmel_serial.h>
|
||||
@ -155,21 +157,28 @@ static struct platform_device rmt_ts_device = {
|
||||
|
||||
#ifdef CONFIG_BOARD_MRMT_BL_PWM
|
||||
/* PWM LEDs: LCD Backlight, etc */
|
||||
static struct gpio_led rmt_pwm_led[] = {
|
||||
/* here the "gpio" is actually a PWM channel */
|
||||
{ .name = "backlight", .gpio = PWM_CH_BL, },
|
||||
static struct pwm_lookup pwm_lookup[] = {
|
||||
PWM_LOOKUP("at91sam9rl-pwm", PWM_CH_BL, "leds_pwm", "ds1",
|
||||
5000, PWM_POLARITY_INVERSED),
|
||||
};
|
||||
|
||||
static struct gpio_led_platform_data rmt_pwm_led_data = {
|
||||
.num_leds = ARRAY_SIZE(rmt_pwm_led),
|
||||
.leds = rmt_pwm_led,
|
||||
static struct led_pwm pwm_leds[] = {
|
||||
{
|
||||
.name = "backlight",
|
||||
.max_brightness = 255,
|
||||
},
|
||||
};
|
||||
|
||||
static struct platform_device rmt_pwm_led_dev = {
|
||||
.name = "leds-atmel-pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &rmt_pwm_led_data,
|
||||
static struct led_pwm_platform_data pwm_data = {
|
||||
.num_leds = ARRAY_SIZE(pwm_leds),
|
||||
.leds = pwm_leds,
|
||||
};
|
||||
|
||||
static struct platform_device leds_pwm = {
|
||||
.name = "leds_pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_data,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
@ -325,7 +334,8 @@ static int __init mrmt1_init(void)
|
||||
#ifdef CONFIG_BOARD_MRMT_BL_PWM
|
||||
/* Use PWM for Backlight controls */
|
||||
at32_add_device_pwm(1 << PWM_CH_BL);
|
||||
platform_device_register(&rmt_pwm_led_dev);
|
||||
pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
|
||||
platform_device_register(&leds_pwm);
|
||||
#else
|
||||
/* Backlight always on */
|
||||
udelay( 1 );
|
||||
|
@ -18,7 +18,10 @@
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/atmel-mci.h>
|
||||
#include <linux/atmel-pwm-bl.h>
|
||||
#include <linux/pwm.h>
|
||||
#include <linux/pwm_backlight.h>
|
||||
#include <linux/regulator/fixed.h>
|
||||
#include <linux/regulator/machine.h>
|
||||
#include <linux/spi/spi.h>
|
||||
#include <linux/spi/ads7846.h>
|
||||
|
||||
@ -33,6 +36,8 @@
|
||||
#include <mach/board.h>
|
||||
#include <mach/portmux.h>
|
||||
|
||||
#define PWM_BL_CH 2
|
||||
|
||||
/* Oscillator frequencies. These are board-specific */
|
||||
unsigned long at32_board_osc_rates[3] = {
|
||||
[0] = 32768, /* 32.768 kHz on RTC osc */
|
||||
@ -227,29 +232,36 @@ void __init favr32_setup_leds(void)
|
||||
platform_device_register(&favr32_led_dev);
|
||||
}
|
||||
|
||||
static struct atmel_pwm_bl_platform_data atmel_pwm_bl_pdata = {
|
||||
.pwm_channel = 2,
|
||||
.pwm_frequency = 200000,
|
||||
.pwm_compare_max = 345,
|
||||
.pwm_duty_max = 345,
|
||||
.pwm_duty_min = 90,
|
||||
.pwm_active_low = 1,
|
||||
.gpio_on = GPIO_PIN_PA(28),
|
||||
.on_active_low = 0,
|
||||
static struct pwm_lookup pwm_lookup[] = {
|
||||
PWM_LOOKUP("at91sam9rl-pwm", PWM_BL_CH, "pwm-backlight.0", NULL,
|
||||
5000, PWM_POLARITY_INVERSED),
|
||||
};
|
||||
|
||||
static struct platform_device atmel_pwm_bl_dev = {
|
||||
.name = "atmel-pwm-bl",
|
||||
.id = 0,
|
||||
.dev = {
|
||||
.platform_data = &atmel_pwm_bl_pdata,
|
||||
static struct regulator_consumer_supply fixed_power_consumers[] = {
|
||||
REGULATOR_SUPPLY("power", "pwm-backlight.0"),
|
||||
};
|
||||
|
||||
static struct platform_pwm_backlight_data pwm_bl_data = {
|
||||
.enable_gpio = GPIO_PIN_PA(28),
|
||||
.max_brightness = 255,
|
||||
.dft_brightness = 255,
|
||||
.lth_brightness = 50,
|
||||
};
|
||||
|
||||
static struct platform_device pwm_bl_device = {
|
||||
.name = "pwm-backlight",
|
||||
.dev = {
|
||||
.platform_data = &pwm_bl_data,
|
||||
},
|
||||
};
|
||||
|
||||
static void __init favr32_setup_atmel_pwm_bl(void)
|
||||
{
|
||||
platform_device_register(&atmel_pwm_bl_dev);
|
||||
at32_select_gpio(atmel_pwm_bl_pdata.gpio_on, 0);
|
||||
pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
|
||||
regulator_register_always_on(0, "fixed", fixed_power_consumers,
|
||||
ARRAY_SIZE(fixed_power_consumers), 3300000);
|
||||
platform_device_register(&pwm_bl_device);
|
||||
at32_select_gpio(pwm_bl_data.enable_gpio, 0);
|
||||
}
|
||||
|
||||
void __init setup_board(void)
|
||||
@ -339,7 +351,7 @@ static int __init favr32_init(void)
|
||||
|
||||
set_abdac_rate(at32_add_device_abdac(0, &abdac0_data));
|
||||
|
||||
at32_add_device_pwm(1 << atmel_pwm_bl_pdata.pwm_channel);
|
||||
at32_add_device_pwm(1 << PWM_BL_CH);
|
||||
at32_add_device_spi(1, spi1_board_info, ARRAY_SIZE(spi1_board_info));
|
||||
at32_add_device_mci(0, &mci0_data);
|
||||
at32_add_device_usba(0, NULL);
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <linux/irq.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/atmel-mci.h>
|
||||
#include <linux/pwm.h>
|
||||
#include <linux/leds_pwm.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
#include <asm/setup.h>
|
||||
@ -167,24 +169,29 @@ static struct i2c_board_info __initdata i2c_info[] = {
|
||||
},
|
||||
};
|
||||
|
||||
#ifdef CONFIG_LEDS_ATMEL_PWM
|
||||
static struct gpio_led stk_pwm_led[] = {
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
static struct pwm_lookup pwm_lookup[] = {
|
||||
PWM_LOOKUP("at91sam9rl-pwm", 0, "leds_pwm", "backlight",
|
||||
5000, PWM_POLARITY_NORMAL),
|
||||
};
|
||||
|
||||
static struct led_pwm pwm_leds[] = {
|
||||
{
|
||||
.name = "backlight",
|
||||
.gpio = 0, /* PWM channel 0 (LCD backlight) */
|
||||
.max_brightness = 255,
|
||||
},
|
||||
};
|
||||
|
||||
static struct gpio_led_platform_data stk_pwm_led_data = {
|
||||
.num_leds = ARRAY_SIZE(stk_pwm_led),
|
||||
.leds = stk_pwm_led,
|
||||
static struct led_pwm_platform_data pwm_data = {
|
||||
.num_leds = ARRAY_SIZE(pwm_leds),
|
||||
.leds = pwm_leds,
|
||||
};
|
||||
|
||||
static struct platform_device stk_pwm_led_dev = {
|
||||
.name = "leds-atmel-pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &stk_pwm_led_data,
|
||||
static struct platform_device leds_pwm = {
|
||||
.name = "leds_pwm",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = &pwm_data,
|
||||
},
|
||||
};
|
||||
#endif
|
||||
@ -278,9 +285,10 @@ static int __init merisc_init(void)
|
||||
|
||||
at32_add_device_mci(0, &mci0_data);
|
||||
|
||||
#ifdef CONFIG_LEDS_ATMEL_PWM
|
||||
#if IS_ENABLED(CONFIG_LEDS_PWM)
|
||||
pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
|
||||
at32_add_device_pwm((1 << 0) | (1 << 2));
|
||||
platform_device_register(&stk_pwm_led_dev);
|
||||
platform_device_register(&leds_pwm);
|
||||
#else
|
||||
at32_add_device_pwm((1 << 2));
|
||||
#endif
|
||||
|
@ -56,7 +56,6 @@ CONFIG_MTD_CFI_AMDSTD=y
|
||||
CONFIG_MTD_PHYSMAP=y
|
||||
CONFIG_MTD_DATAFLASH=y
|
||||
CONFIG_BLK_DEV_LOOP=y
|
||||
CONFIG_ATMEL_PWM=y
|
||||
CONFIG_NETDEVICES=y
|
||||
CONFIG_NET_ETHERNET=y
|
||||
CONFIG_MACB=y
|
||||
@ -104,8 +103,8 @@ CONFIG_MMC=y
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=y
|
||||
CONFIG_LEDS_GPIO=y
|
||||
CONFIG_LEDS_PWM=y
|
||||
CONFIG_LEDS_TRIGGERS=y
|
||||
CONFIG_LEDS_TRIGGER_TIMER=y
|
||||
CONFIG_LEDS_TRIGGER_HEARTBEAT=y
|
||||
@ -114,6 +113,8 @@ CONFIG_RTC_DRV_S35390A=m
|
||||
CONFIG_RTC_DRV_AT32AP700X=m
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_UIO=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=y
|
||||
CONFIG_EXT2_FS=y
|
||||
CONFIG_EXT2_FS_XATTR=y
|
||||
CONFIG_EXT3_FS=y
|
||||
|
@ -64,7 +64,6 @@ CONFIG_BLK_DEV_LOOP=m
|
||||
CONFIG_BLK_DEV_NBD=m
|
||||
CONFIG_BLK_DEV_RAM=m
|
||||
CONFIG_MISC_DEVICES=y
|
||||
CONFIG_ATMEL_PWM=m
|
||||
CONFIG_ATMEL_TCLIB=y
|
||||
CONFIG_ATMEL_SSC=m
|
||||
# CONFIG_SCSI_PROC_FS is not set
|
||||
@ -133,14 +132,16 @@ CONFIG_MMC_TEST=m
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=m
|
||||
CONFIG_LEDS_GPIO=m
|
||||
CONFIG_LEDS_PWM=m
|
||||
CONFIG_LEDS_TRIGGERS=y
|
||||
CONFIG_LEDS_TRIGGER_TIMER=m
|
||||
CONFIG_LEDS_TRIGGER_HEARTBEAT=m
|
||||
CONFIG_RTC_CLASS=y
|
||||
CONFIG_RTC_DRV_AT32AP700X=y
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=m
|
||||
CONFIG_EXT2_FS=y
|
||||
CONFIG_EXT3_FS=y
|
||||
# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
|
||||
|
@ -53,7 +53,6 @@ CONFIG_BLK_DEV_LOOP=m
|
||||
CONFIG_BLK_DEV_NBD=m
|
||||
CONFIG_BLK_DEV_RAM=m
|
||||
CONFIG_MISC_DEVICES=y
|
||||
CONFIG_ATMEL_PWM=m
|
||||
CONFIG_ATMEL_TCLIB=y
|
||||
CONFIG_ATMEL_SSC=m
|
||||
# CONFIG_SCSI_PROC_FS is not set
|
||||
@ -112,14 +111,16 @@ CONFIG_MMC_TEST=m
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=m
|
||||
CONFIG_LEDS_GPIO=m
|
||||
CONFIG_LEDS_PWM=m
|
||||
CONFIG_LEDS_TRIGGERS=y
|
||||
CONFIG_LEDS_TRIGGER_TIMER=m
|
||||
CONFIG_LEDS_TRIGGER_HEARTBEAT=m
|
||||
CONFIG_RTC_CLASS=y
|
||||
CONFIG_RTC_DRV_AT32AP700X=y
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=m
|
||||
CONFIG_EXT2_FS=y
|
||||
CONFIG_EXT3_FS=y
|
||||
# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
|
||||
|
@ -53,7 +53,6 @@ CONFIG_BLK_DEV_LOOP=m
|
||||
CONFIG_BLK_DEV_NBD=m
|
||||
CONFIG_BLK_DEV_RAM=m
|
||||
CONFIG_MISC_DEVICES=y
|
||||
CONFIG_ATMEL_PWM=m
|
||||
CONFIG_ATMEL_TCLIB=y
|
||||
CONFIG_ATMEL_SSC=m
|
||||
# CONFIG_SCSI_PROC_FS is not set
|
||||
@ -111,14 +110,16 @@ CONFIG_MMC_TEST=m
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=m
|
||||
CONFIG_LEDS_GPIO=m
|
||||
CONFIG_LEDS_PWM=m
|
||||
CONFIG_LEDS_TRIGGERS=y
|
||||
CONFIG_LEDS_TRIGGER_TIMER=m
|
||||
CONFIG_LEDS_TRIGGER_HEARTBEAT=m
|
||||
CONFIG_RTC_CLASS=y
|
||||
CONFIG_RTC_DRV_AT32AP700X=y
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=m
|
||||
CONFIG_EXT2_FS=y
|
||||
CONFIG_EXT3_FS=y
|
||||
# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
|
||||
|
@ -67,7 +67,6 @@ CONFIG_BLK_DEV_LOOP=m
|
||||
CONFIG_BLK_DEV_NBD=m
|
||||
CONFIG_BLK_DEV_RAM=m
|
||||
CONFIG_MISC_DEVICES=y
|
||||
CONFIG_ATMEL_PWM=m
|
||||
CONFIG_ATMEL_TCLIB=y
|
||||
CONFIG_ATMEL_SSC=m
|
||||
# CONFIG_SCSI_PROC_FS is not set
|
||||
@ -136,14 +135,16 @@ CONFIG_MMC_TEST=m
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=m
|
||||
CONFIG_LEDS_GPIO=m
|
||||
CONFIG_LEDS_PWM=m
|
||||
CONFIG_LEDS_TRIGGERS=y
|
||||
CONFIG_LEDS_TRIGGER_TIMER=m
|
||||
CONFIG_LEDS_TRIGGER_HEARTBEAT=m
|
||||
CONFIG_RTC_CLASS=y
|
||||
CONFIG_RTC_DRV_AT32AP700X=y
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=m
|
||||
CONFIG_EXT2_FS=y
|
||||
CONFIG_EXT3_FS=y
|
||||
# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
|
||||
|
@ -67,7 +67,6 @@ CONFIG_MTD_PHYSMAP=y
|
||||
CONFIG_BLK_DEV_LOOP=m
|
||||
CONFIG_BLK_DEV_NBD=m
|
||||
CONFIG_BLK_DEV_RAM=m
|
||||
CONFIG_ATMEL_PWM=m
|
||||
CONFIG_ATMEL_TCLIB=y
|
||||
CONFIG_ATMEL_SSC=m
|
||||
CONFIG_NETDEVICES=y
|
||||
@ -108,7 +107,7 @@ CONFIG_FB=y
|
||||
CONFIG_FB_ATMEL=y
|
||||
CONFIG_BACKLIGHT_LCD_SUPPORT=y
|
||||
# CONFIG_LCD_CLASS_DEVICE is not set
|
||||
CONFIG_BACKLIGHT_ATMEL_PWM=m
|
||||
CONFIG_BACKLIGHT_PWM=m
|
||||
CONFIG_SOUND=m
|
||||
CONFIG_SOUND_PRIME=m
|
||||
# CONFIG_HID_SUPPORT is not set
|
||||
@ -123,7 +122,6 @@ CONFIG_MMC=y
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=m
|
||||
CONFIG_LEDS_GPIO=y
|
||||
CONFIG_LEDS_TRIGGERS=y
|
||||
CONFIG_LEDS_TRIGGER_TIMER=y
|
||||
@ -132,6 +130,8 @@ CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
|
||||
CONFIG_RTC_CLASS=y
|
||||
CONFIG_RTC_DRV_AT32AP700X=y
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=y
|
||||
CONFIG_EXT2_FS=y
|
||||
CONFIG_EXT3_FS=y
|
||||
# CONFIG_EXT3_FS_XATTR is not set
|
||||
|
@ -55,7 +55,6 @@ CONFIG_MTD_ABSENT=y
|
||||
CONFIG_MTD_PHYSMAP=y
|
||||
CONFIG_MTD_BLOCK2MTD=y
|
||||
CONFIG_BLK_DEV_LOOP=y
|
||||
CONFIG_ATMEL_PWM=y
|
||||
CONFIG_ATMEL_SSC=y
|
||||
CONFIG_SCSI=y
|
||||
CONFIG_BLK_DEV_SD=y
|
||||
@ -103,12 +102,14 @@ CONFIG_MMC=y
|
||||
CONFIG_MMC_ATMELMCI=y
|
||||
CONFIG_NEW_LEDS=y
|
||||
CONFIG_LEDS_CLASS=y
|
||||
CONFIG_LEDS_ATMEL_PWM=y
|
||||
CONFIG_LEDS_PWM=y
|
||||
CONFIG_RTC_CLASS=y
|
||||
# CONFIG_RTC_HCTOSYS is not set
|
||||
CONFIG_RTC_DRV_PCF8563=y
|
||||
CONFIG_DMADEVICES=y
|
||||
CONFIG_UIO=y
|
||||
CONFIG_PWM=y
|
||||
CONFIG_PWM_ATMEL=m
|
||||
CONFIG_EXT2_FS=y
|
||||
# CONFIG_DNOTIFY is not set
|
||||
CONFIG_FUSE_FS=y
|
||||
|
@ -1553,7 +1553,7 @@ static struct resource atmel_pwm0_resource[] __initdata = {
|
||||
IRQ(24),
|
||||
};
|
||||
static struct clk atmel_pwm0_mck = {
|
||||
.name = "pwm_clk",
|
||||
.name = "at91sam9rl-pwm",
|
||||
.parent = &pbb_clk,
|
||||
.mode = pbb_clk_mode,
|
||||
.get_rate = pbb_clk_get_rate,
|
||||
@ -1568,7 +1568,7 @@ struct platform_device *__init at32_add_device_pwm(u32 mask)
|
||||
if (!mask)
|
||||
return NULL;
|
||||
|
||||
pdev = platform_device_alloc("atmel_pwm", 0);
|
||||
pdev = platform_device_alloc("at91sam9rl-pwm", 0);
|
||||
if (!pdev)
|
||||
return NULL;
|
||||
|
||||
@ -1576,9 +1576,6 @@ struct platform_device *__init at32_add_device_pwm(u32 mask)
|
||||
ARRAY_SIZE(atmel_pwm0_resource)))
|
||||
goto out_free_pdev;
|
||||
|
||||
if (platform_device_add_data(pdev, &mask, sizeof(mask)))
|
||||
goto out_free_pdev;
|
||||
|
||||
pin_mask = 0;
|
||||
if (mask & (1 << 0))
|
||||
pin_mask |= (1 << 28);
|
||||
|
@ -32,14 +32,6 @@ config LEDS_88PM860X
|
||||
This option enables support for on-chip LED drivers found on Marvell
|
||||
Semiconductor 88PM8606 PMIC.
|
||||
|
||||
config LEDS_ATMEL_PWM
|
||||
tristate "LED Support using Atmel PWM outputs"
|
||||
depends on LEDS_CLASS
|
||||
depends on ATMEL_PWM
|
||||
help
|
||||
This option enables support for LEDs driven using outputs
|
||||
of the dedicated PWM controller found on newer Atmel SOCs.
|
||||
|
||||
config LEDS_LM3530
|
||||
tristate "LCD Backlight driver for LM3530"
|
||||
depends on LEDS_CLASS
|
||||
|
@ -6,7 +6,6 @@ obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o
|
||||
|
||||
# LED Platform Drivers
|
||||
obj-$(CONFIG_LEDS_88PM860X) += leds-88pm860x.o
|
||||
obj-$(CONFIG_LEDS_ATMEL_PWM) += leds-atmel-pwm.o
|
||||
obj-$(CONFIG_LEDS_BD2802) += leds-bd2802.o
|
||||
obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o
|
||||
obj-$(CONFIG_LEDS_LM3530) += leds-lm3530.o
|
||||
|
@ -1,149 +0,0 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/leds.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/atmel_pwm.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
|
||||
struct pwmled {
|
||||
struct led_classdev cdev;
|
||||
struct pwm_channel pwmc;
|
||||
struct gpio_led *desc;
|
||||
u32 mult;
|
||||
u8 active_low;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* For simplicity, we use "brightness" as if it were a linear function
|
||||
* of PWM duty cycle. However, a logarithmic function of duty cycle is
|
||||
* probably a better match for perceived brightness: two is half as bright
|
||||
* as four, four is half as bright as eight, etc
|
||||
*/
|
||||
static void pwmled_brightness(struct led_classdev *cdev, enum led_brightness b)
|
||||
{
|
||||
struct pwmled *led;
|
||||
|
||||
/* update the duty cycle for the *next* period */
|
||||
led = container_of(cdev, struct pwmled, cdev);
|
||||
pwm_channel_writel(&led->pwmc, PWM_CUPD, led->mult * (unsigned) b);
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: we reuse the platform_data structure of GPIO leds,
|
||||
* but repurpose its "gpio" number as a PWM channel number.
|
||||
*/
|
||||
static int pwmled_probe(struct platform_device *pdev)
|
||||
{
|
||||
const struct gpio_led_platform_data *pdata;
|
||||
struct pwmled *leds;
|
||||
int i;
|
||||
int status;
|
||||
|
||||
pdata = dev_get_platdata(&pdev->dev);
|
||||
if (!pdata || pdata->num_leds < 1)
|
||||
return -ENODEV;
|
||||
|
||||
leds = devm_kzalloc(&pdev->dev, pdata->num_leds * sizeof(*leds),
|
||||
GFP_KERNEL);
|
||||
if (!leds)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < pdata->num_leds; i++) {
|
||||
struct pwmled *led = leds + i;
|
||||
const struct gpio_led *dat = pdata->leds + i;
|
||||
u32 tmp;
|
||||
|
||||
led->cdev.name = dat->name;
|
||||
led->cdev.brightness = LED_OFF;
|
||||
led->cdev.brightness_set = pwmled_brightness;
|
||||
led->cdev.default_trigger = dat->default_trigger;
|
||||
|
||||
led->active_low = dat->active_low;
|
||||
|
||||
status = pwm_channel_alloc(dat->gpio, &led->pwmc);
|
||||
if (status < 0)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Prescale clock by 2^x, so PWM counts in low MHz.
|
||||
* Start each cycle with the LED active, so increasing
|
||||
* the duty cycle gives us more time on (== brighter).
|
||||
*/
|
||||
tmp = 5;
|
||||
if (!led->active_low)
|
||||
tmp |= PWM_CPR_CPOL;
|
||||
pwm_channel_writel(&led->pwmc, PWM_CMR, tmp);
|
||||
|
||||
/*
|
||||
* Pick a period so PWM cycles at 100+ Hz; and a multiplier
|
||||
* for scaling duty cycle: brightness * mult.
|
||||
*/
|
||||
tmp = (led->pwmc.mck / (1 << 5)) / 100;
|
||||
tmp /= 255;
|
||||
led->mult = tmp;
|
||||
pwm_channel_writel(&led->pwmc, PWM_CDTY,
|
||||
led->cdev.brightness * 255);
|
||||
pwm_channel_writel(&led->pwmc, PWM_CPRD,
|
||||
LED_FULL * tmp);
|
||||
|
||||
pwm_channel_enable(&led->pwmc);
|
||||
|
||||
/* Hand it over to the LED framework */
|
||||
status = led_classdev_register(&pdev->dev, &led->cdev);
|
||||
if (status < 0) {
|
||||
pwm_channel_free(&led->pwmc);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, leds);
|
||||
return 0;
|
||||
|
||||
err:
|
||||
if (i > 0) {
|
||||
for (i = i - 1; i >= 0; i--) {
|
||||
led_classdev_unregister(&leds[i].cdev);
|
||||
pwm_channel_free(&leds[i].pwmc);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static int pwmled_remove(struct platform_device *pdev)
|
||||
{
|
||||
const struct gpio_led_platform_data *pdata;
|
||||
struct pwmled *leds;
|
||||
unsigned i;
|
||||
|
||||
pdata = dev_get_platdata(&pdev->dev);
|
||||
leds = platform_get_drvdata(pdev);
|
||||
|
||||
for (i = 0; i < pdata->num_leds; i++) {
|
||||
struct pwmled *led = leds + i;
|
||||
|
||||
led_classdev_unregister(&led->cdev);
|
||||
pwm_channel_free(&led->pwmc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver pwmled_driver = {
|
||||
.driver = {
|
||||
.name = "leds-atmel-pwm",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
/* REVISIT add suspend() and resume() methods */
|
||||
.probe = pwmled_probe,
|
||||
.remove = pwmled_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(pwmled_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Driver for LEDs with PWM-controlled brightness");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:leds-atmel-pwm");
|
@ -51,16 +51,6 @@ config AD525X_DPOT_SPI
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called ad525x_dpot-spi.
|
||||
|
||||
config ATMEL_PWM
|
||||
tristate "Atmel AT32/AT91 PWM support"
|
||||
depends on HAVE_CLK
|
||||
depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45
|
||||
help
|
||||
This option enables device driver support for the PWM channels
|
||||
on certain Atmel processors. Pulse Width Modulation is used for
|
||||
purposes including software controlled power-efficient backlights
|
||||
on LCD displays, motor control, and waveform generation.
|
||||
|
||||
config ATMEL_TCLIB
|
||||
bool "Atmel AT32/AT91 Timer/Counter Library"
|
||||
depends on (AVR32 || ARCH_AT91)
|
||||
|
@ -7,7 +7,6 @@ obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o
|
||||
obj-$(CONFIG_AD525X_DPOT_I2C) += ad525x_dpot-i2c.o
|
||||
obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o
|
||||
obj-$(CONFIG_INTEL_MID_PTI) += pti.o
|
||||
obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
|
||||
obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o
|
||||
obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o
|
||||
obj-$(CONFIG_BMP085) += bmp085.o
|
||||
|
@ -1,402 +0,0 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/atmel_pwm.h>
|
||||
|
||||
|
||||
/*
|
||||
* This is a simple driver for the PWM controller found in various newer
|
||||
* Atmel SOCs, including the AVR32 series and the AT91sam9263.
|
||||
*
|
||||
* Chips with current Linux ports have only 4 PWM channels, out of max 32.
|
||||
* AT32UC3A and AT32UC3B chips have 7 channels (but currently no Linux).
|
||||
* Docs are inconsistent about the width of the channel counter registers;
|
||||
* it's at least 16 bits, but several places say 20 bits.
|
||||
*/
|
||||
#define PWM_NCHAN 4 /* max 32 */
|
||||
|
||||
struct pwm {
|
||||
spinlock_t lock;
|
||||
struct platform_device *pdev;
|
||||
u32 mask;
|
||||
int irq;
|
||||
void __iomem *base;
|
||||
struct clk *clk;
|
||||
struct pwm_channel *channel[PWM_NCHAN];
|
||||
void (*handler[PWM_NCHAN])(struct pwm_channel *);
|
||||
};
|
||||
|
||||
|
||||
/* global PWM controller registers */
|
||||
#define PWM_MR 0x00
|
||||
#define PWM_ENA 0x04
|
||||
#define PWM_DIS 0x08
|
||||
#define PWM_SR 0x0c
|
||||
#define PWM_IER 0x10
|
||||
#define PWM_IDR 0x14
|
||||
#define PWM_IMR 0x18
|
||||
#define PWM_ISR 0x1c
|
||||
|
||||
static inline void pwm_writel(const struct pwm *p, unsigned offset, u32 val)
|
||||
{
|
||||
__raw_writel(val, p->base + offset);
|
||||
}
|
||||
|
||||
static inline u32 pwm_readl(const struct pwm *p, unsigned offset)
|
||||
{
|
||||
return __raw_readl(p->base + offset);
|
||||
}
|
||||
|
||||
static inline void __iomem *pwmc_regs(const struct pwm *p, int index)
|
||||
{
|
||||
return p->base + 0x200 + index * 0x20;
|
||||
}
|
||||
|
||||
static struct pwm *pwm;
|
||||
|
||||
static void pwm_dumpregs(struct pwm_channel *ch, char *tag)
|
||||
{
|
||||
struct device *dev = &pwm->pdev->dev;
|
||||
|
||||
dev_dbg(dev, "%s: mr %08x, sr %08x, imr %08x\n",
|
||||
tag,
|
||||
pwm_readl(pwm, PWM_MR),
|
||||
pwm_readl(pwm, PWM_SR),
|
||||
pwm_readl(pwm, PWM_IMR));
|
||||
dev_dbg(dev,
|
||||
"pwm ch%d - mr %08x, dty %u, prd %u, cnt %u\n",
|
||||
ch->index,
|
||||
pwm_channel_readl(ch, PWM_CMR),
|
||||
pwm_channel_readl(ch, PWM_CDTY),
|
||||
pwm_channel_readl(ch, PWM_CPRD),
|
||||
pwm_channel_readl(ch, PWM_CCNT));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pwm_channel_alloc - allocate an unused PWM channel
|
||||
* @index: identifies the channel
|
||||
* @ch: structure to be initialized
|
||||
*
|
||||
* Drivers allocate PWM channels according to the board's wiring, and
|
||||
* matching board-specific setup code. Returns zero or negative errno.
|
||||
*/
|
||||
int pwm_channel_alloc(int index, struct pwm_channel *ch)
|
||||
{
|
||||
unsigned long flags;
|
||||
int status = 0;
|
||||
|
||||
if (!pwm)
|
||||
return -EPROBE_DEFER;
|
||||
|
||||
if (!(pwm->mask & 1 << index))
|
||||
return -ENODEV;
|
||||
|
||||
if (index < 0 || index >= PWM_NCHAN || !ch)
|
||||
return -EINVAL;
|
||||
memset(ch, 0, sizeof *ch);
|
||||
|
||||
spin_lock_irqsave(&pwm->lock, flags);
|
||||
if (pwm->channel[index])
|
||||
status = -EBUSY;
|
||||
else {
|
||||
clk_enable(pwm->clk);
|
||||
|
||||
ch->regs = pwmc_regs(pwm, index);
|
||||
ch->index = index;
|
||||
|
||||
/* REVISIT: ap7000 seems to go 2x as fast as we expect!! */
|
||||
ch->mck = clk_get_rate(pwm->clk);
|
||||
|
||||
pwm->channel[index] = ch;
|
||||
pwm->handler[index] = NULL;
|
||||
|
||||
/* channel and irq are always disabled when we return */
|
||||
pwm_writel(pwm, PWM_DIS, 1 << index);
|
||||
pwm_writel(pwm, PWM_IDR, 1 << index);
|
||||
}
|
||||
spin_unlock_irqrestore(&pwm->lock, flags);
|
||||
return status;
|
||||
}
|
||||
EXPORT_SYMBOL(pwm_channel_alloc);
|
||||
|
||||
static int pwmcheck(struct pwm_channel *ch)
|
||||
{
|
||||
int index;
|
||||
|
||||
if (!pwm)
|
||||
return -ENODEV;
|
||||
if (!ch)
|
||||
return -EINVAL;
|
||||
index = ch->index;
|
||||
if (index < 0 || index >= PWM_NCHAN || pwm->channel[index] != ch)
|
||||
return -EINVAL;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* pwm_channel_free - release a previously allocated channel
|
||||
* @ch: the channel being released
|
||||
*
|
||||
* The channel is completely shut down (counter and IRQ disabled),
|
||||
* and made available for re-use. Returns zero, or negative errno.
|
||||
*/
|
||||
int pwm_channel_free(struct pwm_channel *ch)
|
||||
{
|
||||
unsigned long flags;
|
||||
int t;
|
||||
|
||||
spin_lock_irqsave(&pwm->lock, flags);
|
||||
t = pwmcheck(ch);
|
||||
if (t >= 0) {
|
||||
pwm->channel[t] = NULL;
|
||||
pwm->handler[t] = NULL;
|
||||
|
||||
/* channel and irq are always disabled when we return */
|
||||
pwm_writel(pwm, PWM_DIS, 1 << t);
|
||||
pwm_writel(pwm, PWM_IDR, 1 << t);
|
||||
|
||||
clk_disable(pwm->clk);
|
||||
t = 0;
|
||||
}
|
||||
spin_unlock_irqrestore(&pwm->lock, flags);
|
||||
return t;
|
||||
}
|
||||
EXPORT_SYMBOL(pwm_channel_free);
|
||||
|
||||
int __pwm_channel_onoff(struct pwm_channel *ch, int enabled)
|
||||
{
|
||||
unsigned long flags;
|
||||
int t;
|
||||
|
||||
/* OMITTED FUNCTIONALITY: starting several channels in synch */
|
||||
|
||||
spin_lock_irqsave(&pwm->lock, flags);
|
||||
t = pwmcheck(ch);
|
||||
if (t >= 0) {
|
||||
pwm_writel(pwm, enabled ? PWM_ENA : PWM_DIS, 1 << t);
|
||||
t = 0;
|
||||
pwm_dumpregs(ch, enabled ? "enable" : "disable");
|
||||
}
|
||||
spin_unlock_irqrestore(&pwm->lock, flags);
|
||||
|
||||
return t;
|
||||
}
|
||||
EXPORT_SYMBOL(__pwm_channel_onoff);
|
||||
|
||||
/**
|
||||
* pwm_clk_alloc - allocate and configure CLKA or CLKB
|
||||
* @prescale: from 0..10, the power of two used to divide MCK
|
||||
* @div: from 1..255, the linear divisor to use
|
||||
*
|
||||
* Returns PWM_CPR_CLKA, PWM_CPR_CLKB, or negative errno. The allocated
|
||||
* clock will run with a period of (2^prescale * div) / MCK, or twice as
|
||||
* long if center aligned PWM output is used. The clock must later be
|
||||
* deconfigured using pwm_clk_free().
|
||||
*/
|
||||
int pwm_clk_alloc(unsigned prescale, unsigned div)
|
||||
{
|
||||
unsigned long flags;
|
||||
u32 mr;
|
||||
u32 val = (prescale << 8) | div;
|
||||
int ret = -EBUSY;
|
||||
|
||||
if (prescale >= 10 || div == 0 || div > 255)
|
||||
return -EINVAL;
|
||||
|
||||
spin_lock_irqsave(&pwm->lock, flags);
|
||||
mr = pwm_readl(pwm, PWM_MR);
|
||||
if ((mr & 0xffff) == 0) {
|
||||
mr |= val;
|
||||
ret = PWM_CPR_CLKA;
|
||||
} else if ((mr & (0xffff << 16)) == 0) {
|
||||
mr |= val << 16;
|
||||
ret = PWM_CPR_CLKB;
|
||||
}
|
||||
if (ret > 0)
|
||||
pwm_writel(pwm, PWM_MR, mr);
|
||||
spin_unlock_irqrestore(&pwm->lock, flags);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(pwm_clk_alloc);
|
||||
|
||||
/**
|
||||
* pwm_clk_free - deconfigure and release CLKA or CLKB
|
||||
*
|
||||
* Reverses the effect of pwm_clk_alloc().
|
||||
*/
|
||||
void pwm_clk_free(unsigned clk)
|
||||
{
|
||||
unsigned long flags;
|
||||
u32 mr;
|
||||
|
||||
spin_lock_irqsave(&pwm->lock, flags);
|
||||
mr = pwm_readl(pwm, PWM_MR);
|
||||
if (clk == PWM_CPR_CLKA)
|
||||
pwm_writel(pwm, PWM_MR, mr & ~(0xffff << 0));
|
||||
if (clk == PWM_CPR_CLKB)
|
||||
pwm_writel(pwm, PWM_MR, mr & ~(0xffff << 16));
|
||||
spin_unlock_irqrestore(&pwm->lock, flags);
|
||||
}
|
||||
EXPORT_SYMBOL(pwm_clk_free);
|
||||
|
||||
/**
|
||||
* pwm_channel_handler - manage channel's IRQ handler
|
||||
* @ch: the channel
|
||||
* @handler: the handler to use, possibly NULL
|
||||
*
|
||||
* If the handler is non-null, the handler will be called after every
|
||||
* period of this PWM channel. If the handler is null, this channel
|
||||
* won't generate an IRQ.
|
||||
*/
|
||||
int pwm_channel_handler(struct pwm_channel *ch,
|
||||
void (*handler)(struct pwm_channel *ch))
|
||||
{
|
||||
unsigned long flags;
|
||||
int t;
|
||||
|
||||
spin_lock_irqsave(&pwm->lock, flags);
|
||||
t = pwmcheck(ch);
|
||||
if (t >= 0) {
|
||||
pwm->handler[t] = handler;
|
||||
pwm_writel(pwm, handler ? PWM_IER : PWM_IDR, 1 << t);
|
||||
t = 0;
|
||||
}
|
||||
spin_unlock_irqrestore(&pwm->lock, flags);
|
||||
|
||||
return t;
|
||||
}
|
||||
EXPORT_SYMBOL(pwm_channel_handler);
|
||||
|
||||
static irqreturn_t pwm_irq(int id, void *_pwm)
|
||||
{
|
||||
struct pwm *p = _pwm;
|
||||
irqreturn_t handled = IRQ_NONE;
|
||||
u32 irqstat;
|
||||
int index;
|
||||
|
||||
spin_lock(&p->lock);
|
||||
|
||||
/* ack irqs, then handle them */
|
||||
irqstat = pwm_readl(pwm, PWM_ISR);
|
||||
|
||||
while (irqstat) {
|
||||
struct pwm_channel *ch;
|
||||
void (*handler)(struct pwm_channel *ch);
|
||||
|
||||
index = ffs(irqstat) - 1;
|
||||
irqstat &= ~(1 << index);
|
||||
ch = pwm->channel[index];
|
||||
handler = pwm->handler[index];
|
||||
if (handler && ch) {
|
||||
spin_unlock(&p->lock);
|
||||
handler(ch);
|
||||
spin_lock(&p->lock);
|
||||
handled = IRQ_HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock(&p->lock);
|
||||
return handled;
|
||||
}
|
||||
|
||||
static int __init pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
int irq = platform_get_irq(pdev, 0);
|
||||
u32 *mp = pdev->dev.platform_data;
|
||||
struct pwm *p;
|
||||
int status = -EIO;
|
||||
|
||||
if (pwm)
|
||||
return -EBUSY;
|
||||
if (!r || irq < 0 || !mp || !*mp)
|
||||
return -ENODEV;
|
||||
if (*mp & ~((1<<PWM_NCHAN)-1)) {
|
||||
dev_warn(&pdev->dev, "mask 0x%x ... more than %d channels\n",
|
||||
*mp, PWM_NCHAN);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
p = kzalloc(sizeof(*p), GFP_KERNEL);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_init(&p->lock);
|
||||
p->pdev = pdev;
|
||||
p->mask = *mp;
|
||||
p->irq = irq;
|
||||
p->base = ioremap(r->start, resource_size(r));
|
||||
if (!p->base)
|
||||
goto fail;
|
||||
p->clk = clk_get(&pdev->dev, "pwm_clk");
|
||||
if (IS_ERR(p->clk)) {
|
||||
status = PTR_ERR(p->clk);
|
||||
p->clk = NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
status = request_irq(irq, pwm_irq, 0, pdev->name, p);
|
||||
if (status < 0)
|
||||
goto fail;
|
||||
|
||||
pwm = p;
|
||||
platform_set_drvdata(pdev, p);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (p->clk)
|
||||
clk_put(p->clk);
|
||||
if (p->base)
|
||||
iounmap(p->base);
|
||||
|
||||
kfree(p);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int __exit pwm_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct pwm *p = platform_get_drvdata(pdev);
|
||||
|
||||
if (p != pwm)
|
||||
return -EINVAL;
|
||||
|
||||
clk_enable(pwm->clk);
|
||||
pwm_writel(pwm, PWM_DIS, (1 << PWM_NCHAN) - 1);
|
||||
pwm_writel(pwm, PWM_IDR, (1 << PWM_NCHAN) - 1);
|
||||
clk_disable(pwm->clk);
|
||||
|
||||
pwm = NULL;
|
||||
|
||||
free_irq(p->irq, p);
|
||||
clk_put(p->clk);
|
||||
iounmap(p->base);
|
||||
kfree(p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver atmel_pwm_driver = {
|
||||
.driver = {
|
||||
.name = "atmel_pwm",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.remove = __exit_p(pwm_remove),
|
||||
|
||||
/* NOTE: PWM can keep running in AVR32 "idle" and "frozen" states;
|
||||
* and all AT91sam9263 states, albeit at reduced clock rate if
|
||||
* MCK becomes the slow clock (i.e. what Linux labels STR).
|
||||
*/
|
||||
};
|
||||
|
||||
module_platform_driver_probe(atmel_pwm_driver, pwm_probe);
|
||||
|
||||
MODULE_DESCRIPTION("Driver for AT32/AT91 PWM module");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:atmel_pwm");
|
@ -43,7 +43,7 @@ config PWM_AB8500
|
||||
|
||||
config PWM_ATMEL
|
||||
tristate "Atmel PWM support"
|
||||
depends on ARCH_AT91
|
||||
depends on ARCH_AT91 || AVR32
|
||||
help
|
||||
Generic PWM framework driver for Atmel SoC.
|
||||
|
||||
|
@ -178,17 +178,6 @@ config BACKLIGHT_ATMEL_LCDC
|
||||
If in doubt, it's safe to enable this option; it doesn't kick
|
||||
in unless the board's description says it's wired that way.
|
||||
|
||||
config BACKLIGHT_ATMEL_PWM
|
||||
tristate "Atmel PWM backlight control"
|
||||
depends on ATMEL_PWM
|
||||
help
|
||||
Say Y here if you want to use the PWM peripheral in Atmel AT91 and
|
||||
AVR32 devices. This driver will need additional platform data to know
|
||||
which PWM instance to use and how to configure it.
|
||||
|
||||
To compile this driver as a module, choose M here: the module will be
|
||||
called atmel-pwm-bl.
|
||||
|
||||
config BACKLIGHT_EP93XX
|
||||
tristate "Cirrus EP93xx Backlight Driver"
|
||||
depends on FB_EP93XX
|
||||
|
@ -25,7 +25,6 @@ obj-$(CONFIG_BACKLIGHT_ADP8860) += adp8860_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_ADP8870) += adp8870_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_APPLE) += apple_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_AS3711) += as3711_bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
|
||||
obj-$(CONFIG_BACKLIGHT_BD6107) += bd6107.o
|
||||
obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
|
||||
obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
|
||||
|
@ -1,223 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Atmel Corporation
|
||||
*
|
||||
* Backlight driver using Atmel PWM peripheral.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published by
|
||||
* the Free Software Foundation.
|
||||
*/
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/fb.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/backlight.h>
|
||||
#include <linux/atmel_pwm.h>
|
||||
#include <linux/atmel-pwm-bl.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
struct atmel_pwm_bl {
|
||||
const struct atmel_pwm_bl_platform_data *pdata;
|
||||
struct backlight_device *bldev;
|
||||
struct platform_device *pdev;
|
||||
struct pwm_channel pwmc;
|
||||
int gpio_on;
|
||||
};
|
||||
|
||||
static void atmel_pwm_bl_set_gpio_on(struct atmel_pwm_bl *pwmbl, int on)
|
||||
{
|
||||
if (!gpio_is_valid(pwmbl->gpio_on))
|
||||
return;
|
||||
|
||||
gpio_set_value(pwmbl->gpio_on, on ^ pwmbl->pdata->on_active_low);
|
||||
}
|
||||
|
||||
static int atmel_pwm_bl_set_intensity(struct backlight_device *bd)
|
||||
{
|
||||
struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
|
||||
int intensity = bd->props.brightness;
|
||||
int pwm_duty;
|
||||
|
||||
if (bd->props.power != FB_BLANK_UNBLANK)
|
||||
intensity = 0;
|
||||
if (bd->props.fb_blank != FB_BLANK_UNBLANK)
|
||||
intensity = 0;
|
||||
|
||||
if (pwmbl->pdata->pwm_active_low)
|
||||
pwm_duty = pwmbl->pdata->pwm_duty_min + intensity;
|
||||
else
|
||||
pwm_duty = pwmbl->pdata->pwm_duty_max - intensity;
|
||||
|
||||
if (pwm_duty > pwmbl->pdata->pwm_duty_max)
|
||||
pwm_duty = pwmbl->pdata->pwm_duty_max;
|
||||
if (pwm_duty < pwmbl->pdata->pwm_duty_min)
|
||||
pwm_duty = pwmbl->pdata->pwm_duty_min;
|
||||
|
||||
if (!intensity) {
|
||||
atmel_pwm_bl_set_gpio_on(pwmbl, 0);
|
||||
pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
|
||||
pwm_channel_disable(&pwmbl->pwmc);
|
||||
} else {
|
||||
pwm_channel_enable(&pwmbl->pwmc);
|
||||
pwm_channel_writel(&pwmbl->pwmc, PWM_CUPD, pwm_duty);
|
||||
atmel_pwm_bl_set_gpio_on(pwmbl, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int atmel_pwm_bl_get_intensity(struct backlight_device *bd)
|
||||
{
|
||||
struct atmel_pwm_bl *pwmbl = bl_get_data(bd);
|
||||
u32 cdty;
|
||||
u32 intensity;
|
||||
|
||||
cdty = pwm_channel_readl(&pwmbl->pwmc, PWM_CDTY);
|
||||
if (pwmbl->pdata->pwm_active_low)
|
||||
intensity = cdty - pwmbl->pdata->pwm_duty_min;
|
||||
else
|
||||
intensity = pwmbl->pdata->pwm_duty_max - cdty;
|
||||
|
||||
return intensity & 0xffff;
|
||||
}
|
||||
|
||||
static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
|
||||
{
|
||||
unsigned long pwm_rate = pwmbl->pwmc.mck;
|
||||
unsigned long prescale = DIV_ROUND_UP(pwm_rate,
|
||||
(pwmbl->pdata->pwm_frequency *
|
||||
pwmbl->pdata->pwm_compare_max)) - 1;
|
||||
|
||||
/*
|
||||
* Prescale must be power of two and maximum 0xf in size because of
|
||||
* hardware limit. PWM speed will be:
|
||||
* PWM module clock speed / (2 ^ prescale).
|
||||
*/
|
||||
prescale = fls(prescale);
|
||||
if (prescale > 0xf)
|
||||
prescale = 0xf;
|
||||
|
||||
pwm_channel_writel(&pwmbl->pwmc, PWM_CMR, prescale);
|
||||
pwm_channel_writel(&pwmbl->pwmc, PWM_CDTY,
|
||||
pwmbl->pdata->pwm_duty_min +
|
||||
pwmbl->bldev->props.brightness);
|
||||
pwm_channel_writel(&pwmbl->pwmc, PWM_CPRD,
|
||||
pwmbl->pdata->pwm_compare_max);
|
||||
|
||||
dev_info(&pwmbl->pdev->dev, "Atmel PWM backlight driver (%lu Hz)\n",
|
||||
pwmbl->pwmc.mck / pwmbl->pdata->pwm_compare_max /
|
||||
(1 << prescale));
|
||||
|
||||
return pwm_channel_enable(&pwmbl->pwmc);
|
||||
}
|
||||
|
||||
static const struct backlight_ops atmel_pwm_bl_ops = {
|
||||
.get_brightness = atmel_pwm_bl_get_intensity,
|
||||
.update_status = atmel_pwm_bl_set_intensity,
|
||||
};
|
||||
|
||||
static int atmel_pwm_bl_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct backlight_properties props;
|
||||
const struct atmel_pwm_bl_platform_data *pdata;
|
||||
struct backlight_device *bldev;
|
||||
struct atmel_pwm_bl *pwmbl;
|
||||
unsigned long flags;
|
||||
int retval;
|
||||
|
||||
pdata = dev_get_platdata(&pdev->dev);
|
||||
if (!pdata)
|
||||
return -ENODEV;
|
||||
|
||||
if (pdata->pwm_compare_max < pdata->pwm_duty_max ||
|
||||
pdata->pwm_duty_min > pdata->pwm_duty_max ||
|
||||
pdata->pwm_frequency == 0)
|
||||
return -EINVAL;
|
||||
|
||||
pwmbl = devm_kzalloc(&pdev->dev, sizeof(struct atmel_pwm_bl),
|
||||
GFP_KERNEL);
|
||||
if (!pwmbl)
|
||||
return -ENOMEM;
|
||||
|
||||
pwmbl->pdev = pdev;
|
||||
pwmbl->pdata = pdata;
|
||||
pwmbl->gpio_on = pdata->gpio_on;
|
||||
|
||||
retval = pwm_channel_alloc(pdata->pwm_channel, &pwmbl->pwmc);
|
||||
if (retval)
|
||||
return retval;
|
||||
|
||||
if (gpio_is_valid(pwmbl->gpio_on)) {
|
||||
/* Turn display off by default. */
|
||||
if (pdata->on_active_low)
|
||||
flags = GPIOF_OUT_INIT_HIGH;
|
||||
else
|
||||
flags = GPIOF_OUT_INIT_LOW;
|
||||
|
||||
retval = devm_gpio_request_one(&pdev->dev, pwmbl->gpio_on,
|
||||
flags, "gpio_atmel_pwm_bl");
|
||||
if (retval)
|
||||
goto err_free_pwm;
|
||||
}
|
||||
|
||||
memset(&props, 0, sizeof(struct backlight_properties));
|
||||
props.type = BACKLIGHT_RAW;
|
||||
props.max_brightness = pdata->pwm_duty_max - pdata->pwm_duty_min;
|
||||
bldev = devm_backlight_device_register(&pdev->dev, "atmel-pwm-bl",
|
||||
&pdev->dev, pwmbl, &atmel_pwm_bl_ops,
|
||||
&props);
|
||||
if (IS_ERR(bldev)) {
|
||||
retval = PTR_ERR(bldev);
|
||||
goto err_free_pwm;
|
||||
}
|
||||
|
||||
pwmbl->bldev = bldev;
|
||||
|
||||
platform_set_drvdata(pdev, pwmbl);
|
||||
|
||||
/* Power up the backlight by default at middle intesity. */
|
||||
bldev->props.power = FB_BLANK_UNBLANK;
|
||||
bldev->props.brightness = bldev->props.max_brightness / 2;
|
||||
|
||||
retval = atmel_pwm_bl_init_pwm(pwmbl);
|
||||
if (retval)
|
||||
goto err_free_pwm;
|
||||
|
||||
atmel_pwm_bl_set_intensity(bldev);
|
||||
|
||||
return 0;
|
||||
|
||||
err_free_pwm:
|
||||
pwm_channel_free(&pwmbl->pwmc);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int atmel_pwm_bl_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct atmel_pwm_bl *pwmbl = platform_get_drvdata(pdev);
|
||||
|
||||
atmel_pwm_bl_set_gpio_on(pwmbl, 0);
|
||||
pwm_channel_disable(&pwmbl->pwmc);
|
||||
pwm_channel_free(&pwmbl->pwmc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver atmel_pwm_bl_driver = {
|
||||
.driver = {
|
||||
.name = "atmel-pwm-bl",
|
||||
},
|
||||
/* REVISIT add suspend() and resume() */
|
||||
.probe = atmel_pwm_bl_probe,
|
||||
.remove = atmel_pwm_bl_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(atmel_pwm_bl_driver);
|
||||
|
||||
MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
|
||||
MODULE_DESCRIPTION("Atmel PWM backlight driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("platform:atmel-pwm-bl");
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Atmel Corporation
|
||||
*
|
||||
* Driver for the AT32AP700X PS/2 controller (PSIF).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __INCLUDE_ATMEL_PWM_BL_H
|
||||
#define __INCLUDE_ATMEL_PWM_BL_H
|
||||
|
||||
/**
|
||||
* struct atmel_pwm_bl_platform_data
|
||||
* @pwm_channel: which PWM channel in the PWM module to use.
|
||||
* @pwm_frequency: PWM frequency to generate, the driver will try to be as
|
||||
* close as the prescaler allows.
|
||||
* @pwm_compare_max: value to use in the PWM channel compare register.
|
||||
* @pwm_duty_max: maximum duty cycle value, must be less than or equal to
|
||||
* pwm_compare_max.
|
||||
* @pwm_duty_min: minimum duty cycle value, must be less than pwm_duty_max.
|
||||
* @pwm_active_low: set to one if the low part of the PWM signal increases the
|
||||
* brightness of the backlight.
|
||||
* @gpio_on: GPIO line to control the backlight on/off, set to -1 if not used.
|
||||
* @on_active_low: set to one if the on/off signal is on when GPIO is low.
|
||||
*
|
||||
* This struct must be added to the platform device in the board code. It is
|
||||
* used by the atmel-pwm-bl driver to setup the GPIO to control on/off and the
|
||||
* PWM device.
|
||||
*/
|
||||
struct atmel_pwm_bl_platform_data {
|
||||
unsigned int pwm_channel;
|
||||
unsigned int pwm_frequency;
|
||||
unsigned int pwm_compare_max;
|
||||
unsigned int pwm_duty_max;
|
||||
unsigned int pwm_duty_min;
|
||||
unsigned int pwm_active_low;
|
||||
int gpio_on;
|
||||
unsigned int on_active_low;
|
||||
};
|
||||
|
||||
#endif /* __INCLUDE_ATMEL_PWM_BL_H */
|
@ -1,70 +0,0 @@
|
||||
#ifndef __LINUX_ATMEL_PWM_H
|
||||
#define __LINUX_ATMEL_PWM_H
|
||||
|
||||
/**
|
||||
* struct pwm_channel - driver handle to a PWM channel
|
||||
* @regs: base of this channel's registers
|
||||
* @index: number of this channel (0..31)
|
||||
* @mck: base clock rate, which can be prescaled and maybe subdivided
|
||||
*
|
||||
* Drivers initialize a pwm_channel structure using pwm_channel_alloc().
|
||||
* Then they configure its clock rate (derived from MCK), alignment,
|
||||
* polarity, and duty cycle by writing directly to the channel registers,
|
||||
* before enabling the channel by calling pwm_channel_enable().
|
||||
*
|
||||
* After emitting a PWM signal for the desired length of time, drivers
|
||||
* may then pwm_channel_disable() or pwm_channel_free(). Both of these
|
||||
* disable the channel, but when it's freed the IRQ is deconfigured and
|
||||
* the channel must later be re-allocated and reconfigured.
|
||||
*
|
||||
* Note that if the period or duty cycle need to be changed while the
|
||||
* PWM channel is operating, drivers must use the PWM_CUPD double buffer
|
||||
* mechanism, either polling until they change or getting implicitly
|
||||
* notified through a once-per-period interrupt handler.
|
||||
*/
|
||||
struct pwm_channel {
|
||||
void __iomem *regs;
|
||||
unsigned index;
|
||||
unsigned long mck;
|
||||
};
|
||||
|
||||
extern int pwm_channel_alloc(int index, struct pwm_channel *ch);
|
||||
extern int pwm_channel_free(struct pwm_channel *ch);
|
||||
|
||||
extern int pwm_clk_alloc(unsigned prescale, unsigned div);
|
||||
extern void pwm_clk_free(unsigned clk);
|
||||
|
||||
extern int __pwm_channel_onoff(struct pwm_channel *ch, int enabled);
|
||||
|
||||
#define pwm_channel_enable(ch) __pwm_channel_onoff((ch), 1)
|
||||
#define pwm_channel_disable(ch) __pwm_channel_onoff((ch), 0)
|
||||
|
||||
/* periodic interrupts, mostly for CUPD changes to period or cycle */
|
||||
extern int pwm_channel_handler(struct pwm_channel *ch,
|
||||
void (*handler)(struct pwm_channel *ch));
|
||||
|
||||
/* per-channel registers (banked at pwm_channel->regs) */
|
||||
#define PWM_CMR 0x00 /* mode register */
|
||||
#define PWM_CPR_CPD (1 << 10) /* set: CUPD modifies period */
|
||||
#define PWM_CPR_CPOL (1 << 9) /* set: idle high */
|
||||
#define PWM_CPR_CALG (1 << 8) /* set: center align */
|
||||
#define PWM_CPR_CPRE (0xf << 0) /* mask: rate is mck/(2^pre) */
|
||||
#define PWM_CPR_CLKA (0xb << 0) /* rate CLKA */
|
||||
#define PWM_CPR_CLKB (0xc << 0) /* rate CLKB */
|
||||
#define PWM_CDTY 0x04 /* duty cycle (max of CPRD) */
|
||||
#define PWM_CPRD 0x08 /* period (count up from zero) */
|
||||
#define PWM_CCNT 0x0c /* counter (20 bits?) */
|
||||
#define PWM_CUPD 0x10 /* update CPRD (or CDTY) next period */
|
||||
|
||||
static inline void
|
||||
pwm_channel_writel(struct pwm_channel *pwmc, unsigned offset, u32 val)
|
||||
{
|
||||
__raw_writel(val, pwmc->regs + offset);
|
||||
}
|
||||
|
||||
static inline u32 pwm_channel_readl(struct pwm_channel *pwmc, unsigned offset)
|
||||
{
|
||||
return __raw_readl(pwmc->regs + offset);
|
||||
}
|
||||
|
||||
#endif /* __LINUX_ATMEL_PWM_H */
|
Loading…
Reference in New Issue
Block a user