| .. | .. |
|---|
| 31 | 31 | * POSSIBILITY OF SUCH DAMAGE. |
|---|
| 32 | 32 | */ |
|---|
| 33 | 33 | |
|---|
| 34 | +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|---|
| 35 | + |
|---|
| 34 | 36 | #include <linux/dmi.h> |
|---|
| 35 | 37 | #include <linux/err.h> |
|---|
| 36 | 38 | #include <linux/init.h> |
|---|
| .. | .. |
|---|
| 46 | 48 | #define APU1_LEDOFF 0xC8 |
|---|
| 47 | 49 | #define APU1_NUM_GPIO 3 |
|---|
| 48 | 50 | #define APU1_IOSIZE sizeof(u8) |
|---|
| 49 | | - |
|---|
| 50 | | -#define APU2_FCH_ACPI_MMIO_BASE 0xFED80000 |
|---|
| 51 | | -#define APU2_FCH_GPIO_BASE (APU2_FCH_ACPI_MMIO_BASE + 0x1500) |
|---|
| 52 | | -#define APU2_GPIO_BIT_WRITE 22 |
|---|
| 53 | | -#define APU2_APU2_NUM_GPIO 4 |
|---|
| 54 | | -#define APU2_IOSIZE sizeof(u32) |
|---|
| 55 | 51 | |
|---|
| 56 | 52 | /* LED access parameters */ |
|---|
| 57 | 53 | struct apu_param { |
|---|
| .. | .. |
|---|
| 72 | 68 | unsigned long offset; /* for devm_ioremap */ |
|---|
| 73 | 69 | }; |
|---|
| 74 | 70 | |
|---|
| 75 | | -/* Supported platform types */ |
|---|
| 76 | | -enum apu_led_platform_types { |
|---|
| 77 | | - APU1_LED_PLATFORM, |
|---|
| 78 | | - APU2_LED_PLATFORM, |
|---|
| 79 | | -}; |
|---|
| 80 | | - |
|---|
| 81 | 71 | struct apu_led_pdata { |
|---|
| 82 | 72 | struct platform_device *pdev; |
|---|
| 83 | 73 | struct apu_led_priv *pled; |
|---|
| 84 | | - const struct apu_led_profile *profile; |
|---|
| 85 | | - enum apu_led_platform_types platform; |
|---|
| 86 | | - int num_led_instances; |
|---|
| 87 | | - int iosize; /* for devm_ioremap() */ |
|---|
| 88 | 74 | spinlock_t lock; |
|---|
| 89 | 75 | }; |
|---|
| 90 | 76 | |
|---|
| .. | .. |
|---|
| 96 | 82 | { "apu:green:3", LED_OFF, APU1_FCH_GPIO_BASE + 2 * APU1_IOSIZE }, |
|---|
| 97 | 83 | }; |
|---|
| 98 | 84 | |
|---|
| 99 | | -static const struct apu_led_profile apu2_led_profile[] = { |
|---|
| 100 | | - { "apu2:green:1", LED_ON, APU2_FCH_GPIO_BASE + 68 * APU2_IOSIZE }, |
|---|
| 101 | | - { "apu2:green:2", LED_OFF, APU2_FCH_GPIO_BASE + 69 * APU2_IOSIZE }, |
|---|
| 102 | | - { "apu2:green:3", LED_OFF, APU2_FCH_GPIO_BASE + 70 * APU2_IOSIZE }, |
|---|
| 103 | | -}; |
|---|
| 104 | | - |
|---|
| 105 | | -/* Same as apu2_led_profile, but with "3" in the LED names. */ |
|---|
| 106 | | -static const struct apu_led_profile apu3_led_profile[] = { |
|---|
| 107 | | - { "apu3:green:1", LED_ON, APU2_FCH_GPIO_BASE + 68 * APU2_IOSIZE }, |
|---|
| 108 | | - { "apu3:green:2", LED_OFF, APU2_FCH_GPIO_BASE + 69 * APU2_IOSIZE }, |
|---|
| 109 | | - { "apu3:green:3", LED_OFF, APU2_FCH_GPIO_BASE + 70 * APU2_IOSIZE }, |
|---|
| 110 | | -}; |
|---|
| 111 | | - |
|---|
| 112 | 85 | static const struct dmi_system_id apu_led_dmi_table[] __initconst = { |
|---|
| 113 | 86 | { |
|---|
| 114 | 87 | .ident = "apu", |
|---|
| 115 | 88 | .matches = { |
|---|
| 116 | 89 | DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 117 | 90 | DMI_MATCH(DMI_PRODUCT_NAME, "APU") |
|---|
| 118 | | - } |
|---|
| 119 | | - }, |
|---|
| 120 | | - /* PC Engines APU2 with "Legacy" bios < 4.0.8 */ |
|---|
| 121 | | - { |
|---|
| 122 | | - .ident = "apu2", |
|---|
| 123 | | - .matches = { |
|---|
| 124 | | - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 125 | | - DMI_MATCH(DMI_BOARD_NAME, "APU2") |
|---|
| 126 | | - } |
|---|
| 127 | | - }, |
|---|
| 128 | | - /* PC Engines APU2 with "Legacy" bios >= 4.0.8 */ |
|---|
| 129 | | - { |
|---|
| 130 | | - .ident = "apu2", |
|---|
| 131 | | - .matches = { |
|---|
| 132 | | - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 133 | | - DMI_MATCH(DMI_BOARD_NAME, "apu2") |
|---|
| 134 | | - } |
|---|
| 135 | | - }, |
|---|
| 136 | | - /* PC Engines APU2 with "Mainline" bios */ |
|---|
| 137 | | - { |
|---|
| 138 | | - .ident = "apu2", |
|---|
| 139 | | - .matches = { |
|---|
| 140 | | - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 141 | | - DMI_MATCH(DMI_BOARD_NAME, "PC Engines apu2") |
|---|
| 142 | | - } |
|---|
| 143 | | - }, |
|---|
| 144 | | - /* PC Engines APU3 with "Legacy" bios < 4.0.8 */ |
|---|
| 145 | | - { |
|---|
| 146 | | - .ident = "apu3", |
|---|
| 147 | | - .matches = { |
|---|
| 148 | | - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 149 | | - DMI_MATCH(DMI_BOARD_NAME, "APU3") |
|---|
| 150 | | - } |
|---|
| 151 | | - }, |
|---|
| 152 | | - /* PC Engines APU3 with "Legacy" bios >= 4.0.8 */ |
|---|
| 153 | | - { |
|---|
| 154 | | - .ident = "apu3", |
|---|
| 155 | | - .matches = { |
|---|
| 156 | | - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 157 | | - DMI_MATCH(DMI_BOARD_NAME, "apu3") |
|---|
| 158 | | - } |
|---|
| 159 | | - }, |
|---|
| 160 | | - /* PC Engines APU2 with "Mainline" bios */ |
|---|
| 161 | | - { |
|---|
| 162 | | - .ident = "apu3", |
|---|
| 163 | | - .matches = { |
|---|
| 164 | | - DMI_MATCH(DMI_SYS_VENDOR, "PC Engines"), |
|---|
| 165 | | - DMI_MATCH(DMI_BOARD_NAME, "PC Engines apu3") |
|---|
| 166 | 91 | } |
|---|
| 167 | 92 | }, |
|---|
| 168 | 93 | {} |
|---|
| .. | .. |
|---|
| 178 | 103 | spin_unlock(&apu_led->lock); |
|---|
| 179 | 104 | } |
|---|
| 180 | 105 | |
|---|
| 181 | | -static void apu2_led_brightness_set(struct led_classdev *led, enum led_brightness value) |
|---|
| 182 | | -{ |
|---|
| 183 | | - struct apu_led_priv *pled = cdev_to_priv(led); |
|---|
| 184 | | - u32 value_new; |
|---|
| 185 | | - |
|---|
| 186 | | - spin_lock(&apu_led->lock); |
|---|
| 187 | | - |
|---|
| 188 | | - value_new = ioread32(pled->param.addr); |
|---|
| 189 | | - |
|---|
| 190 | | - if (value) |
|---|
| 191 | | - value_new &= ~BIT(APU2_GPIO_BIT_WRITE); |
|---|
| 192 | | - else |
|---|
| 193 | | - value_new |= BIT(APU2_GPIO_BIT_WRITE); |
|---|
| 194 | | - |
|---|
| 195 | | - iowrite32(value_new, pled->param.addr); |
|---|
| 196 | | - |
|---|
| 197 | | - spin_unlock(&apu_led->lock); |
|---|
| 198 | | -} |
|---|
| 199 | | - |
|---|
| 200 | 106 | static int apu_led_config(struct device *dev, struct apu_led_pdata *apuld) |
|---|
| 201 | 107 | { |
|---|
| 202 | 108 | int i; |
|---|
| 203 | 109 | int err; |
|---|
| 204 | 110 | |
|---|
| 205 | 111 | apu_led->pled = devm_kcalloc(dev, |
|---|
| 206 | | - apu_led->num_led_instances, sizeof(struct apu_led_priv), |
|---|
| 112 | + ARRAY_SIZE(apu1_led_profile), sizeof(struct apu_led_priv), |
|---|
| 207 | 113 | GFP_KERNEL); |
|---|
| 208 | 114 | |
|---|
| 209 | 115 | if (!apu_led->pled) |
|---|
| 210 | 116 | return -ENOMEM; |
|---|
| 211 | 117 | |
|---|
| 212 | | - for (i = 0; i < apu_led->num_led_instances; i++) { |
|---|
| 118 | + for (i = 0; i < ARRAY_SIZE(apu1_led_profile); i++) { |
|---|
| 213 | 119 | struct apu_led_priv *pled = &apu_led->pled[i]; |
|---|
| 214 | 120 | struct led_classdev *led_cdev = &pled->cdev; |
|---|
| 215 | 121 | |
|---|
| 216 | | - led_cdev->name = apu_led->profile[i].name; |
|---|
| 217 | | - led_cdev->brightness = apu_led->profile[i].brightness; |
|---|
| 122 | + led_cdev->name = apu1_led_profile[i].name; |
|---|
| 123 | + led_cdev->brightness = apu1_led_profile[i].brightness; |
|---|
| 218 | 124 | led_cdev->max_brightness = 1; |
|---|
| 219 | 125 | led_cdev->flags = LED_CORE_SUSPENDRESUME; |
|---|
| 220 | | - if (apu_led->platform == APU1_LED_PLATFORM) |
|---|
| 221 | | - led_cdev->brightness_set = apu1_led_brightness_set; |
|---|
| 222 | | - else if (apu_led->platform == APU2_LED_PLATFORM) |
|---|
| 223 | | - led_cdev->brightness_set = apu2_led_brightness_set; |
|---|
| 126 | + led_cdev->brightness_set = apu1_led_brightness_set; |
|---|
| 224 | 127 | |
|---|
| 225 | 128 | pled->param.addr = devm_ioremap(dev, |
|---|
| 226 | | - apu_led->profile[i].offset, apu_led->iosize); |
|---|
| 129 | + apu1_led_profile[i].offset, APU1_IOSIZE); |
|---|
| 227 | 130 | if (!pled->param.addr) { |
|---|
| 228 | 131 | err = -ENOMEM; |
|---|
| 229 | 132 | goto error; |
|---|
| .. | .. |
|---|
| 233 | 136 | if (err) |
|---|
| 234 | 137 | goto error; |
|---|
| 235 | 138 | |
|---|
| 236 | | - led_cdev->brightness_set(led_cdev, apu_led->profile[i].brightness); |
|---|
| 139 | + apu1_led_brightness_set(led_cdev, apu1_led_profile[i].brightness); |
|---|
| 237 | 140 | } |
|---|
| 238 | 141 | |
|---|
| 239 | 142 | return 0; |
|---|
| .. | .. |
|---|
| 254 | 157 | |
|---|
| 255 | 158 | apu_led->pdev = pdev; |
|---|
| 256 | 159 | |
|---|
| 257 | | - if (dmi_match(DMI_PRODUCT_NAME, "APU")) { |
|---|
| 258 | | - apu_led->profile = apu1_led_profile; |
|---|
| 259 | | - apu_led->platform = APU1_LED_PLATFORM; |
|---|
| 260 | | - apu_led->num_led_instances = ARRAY_SIZE(apu1_led_profile); |
|---|
| 261 | | - apu_led->iosize = APU1_IOSIZE; |
|---|
| 262 | | - } else if (dmi_match(DMI_BOARD_NAME, "APU2") || |
|---|
| 263 | | - dmi_match(DMI_BOARD_NAME, "apu2") || |
|---|
| 264 | | - dmi_match(DMI_BOARD_NAME, "PC Engines apu2")) { |
|---|
| 265 | | - apu_led->profile = apu2_led_profile; |
|---|
| 266 | | - apu_led->platform = APU2_LED_PLATFORM; |
|---|
| 267 | | - apu_led->num_led_instances = ARRAY_SIZE(apu2_led_profile); |
|---|
| 268 | | - apu_led->iosize = APU2_IOSIZE; |
|---|
| 269 | | - } else if (dmi_match(DMI_BOARD_NAME, "APU3") || |
|---|
| 270 | | - dmi_match(DMI_BOARD_NAME, "apu3") || |
|---|
| 271 | | - dmi_match(DMI_BOARD_NAME, "PC Engines apu3")) { |
|---|
| 272 | | - apu_led->profile = apu3_led_profile; |
|---|
| 273 | | - /* Otherwise identical to APU2. */ |
|---|
| 274 | | - apu_led->platform = APU2_LED_PLATFORM; |
|---|
| 275 | | - apu_led->num_led_instances = ARRAY_SIZE(apu3_led_profile); |
|---|
| 276 | | - apu_led->iosize = APU2_IOSIZE; |
|---|
| 277 | | - } |
|---|
| 278 | | - |
|---|
| 279 | 160 | spin_lock_init(&apu_led->lock); |
|---|
| 280 | 161 | return apu_led_config(&pdev->dev, apu_led); |
|---|
| 281 | 162 | } |
|---|
| .. | .. |
|---|
| 291 | 172 | struct platform_device *pdev; |
|---|
| 292 | 173 | int err; |
|---|
| 293 | 174 | |
|---|
| 294 | | - if (!dmi_match(DMI_SYS_VENDOR, "PC Engines")) { |
|---|
| 295 | | - pr_err("No PC Engines board detected\n"); |
|---|
| 296 | | - return -ENODEV; |
|---|
| 297 | | - } |
|---|
| 298 | | - if (!(dmi_match(DMI_PRODUCT_NAME, "APU") || |
|---|
| 299 | | - dmi_match(DMI_PRODUCT_NAME, "APU2") || |
|---|
| 300 | | - dmi_match(DMI_PRODUCT_NAME, "apu2") || |
|---|
| 301 | | - dmi_match(DMI_PRODUCT_NAME, "PC Engines apu2") || |
|---|
| 302 | | - dmi_match(DMI_PRODUCT_NAME, "APU3") || |
|---|
| 303 | | - dmi_match(DMI_PRODUCT_NAME, "apu3") || |
|---|
| 304 | | - dmi_match(DMI_PRODUCT_NAME, "PC Engines apu3"))) { |
|---|
| 305 | | - pr_err("Unknown PC Engines board: %s\n", |
|---|
| 306 | | - dmi_get_system_info(DMI_PRODUCT_NAME)); |
|---|
| 175 | + if (!(dmi_match(DMI_SYS_VENDOR, "PC Engines") && |
|---|
| 176 | + dmi_match(DMI_PRODUCT_NAME, "APU"))) { |
|---|
| 177 | + pr_err("No PC Engines APUv1 board detected. For APUv2,3 support, enable CONFIG_PCENGINES_APU2\n"); |
|---|
| 307 | 178 | return -ENODEV; |
|---|
| 308 | 179 | } |
|---|
| 309 | 180 | |
|---|
| .. | .. |
|---|
| 326 | 197 | { |
|---|
| 327 | 198 | int i; |
|---|
| 328 | 199 | |
|---|
| 329 | | - for (i = 0; i < apu_led->num_led_instances; i++) |
|---|
| 200 | + for (i = 0; i < ARRAY_SIZE(apu1_led_profile); i++) |
|---|
| 330 | 201 | led_classdev_unregister(&apu_led->pled[i].cdev); |
|---|
| 331 | 202 | |
|---|
| 332 | 203 | platform_device_unregister(apu_led->pdev); |
|---|
| .. | .. |
|---|
| 337 | 208 | module_exit(apu_led_exit); |
|---|
| 338 | 209 | |
|---|
| 339 | 210 | MODULE_AUTHOR("Alan Mizrahi"); |
|---|
| 340 | | -MODULE_DESCRIPTION("PC Engines APU family LED driver"); |
|---|
| 211 | +MODULE_DESCRIPTION("PC Engines APU1 front LED driver"); |
|---|
| 341 | 212 | MODULE_LICENSE("GPL v2"); |
|---|
| 342 | 213 | MODULE_ALIAS("platform:leds_apu"); |
|---|